source: webkit/trunk/JavaScriptCore/kjs/lexer.h@ 34757

Last change on this file since 34757 was 34607, checked in by [email protected], 17 years ago

Reviewed by Geoff Garen.

Make Identifier construction use an explicitly passed IdentifierTable.

No change on SunSpider total.

  • Property svn:eol-style set to native
File size: 4.3 KB
Line 
1// -*- c-basic-offset: 2 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten ([email protected])
5 * Copyright (C) 2007 Apple Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public License
18 * along with this library; see the file COPYING.LIB. If not, write to
19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23
24#ifndef Lexer_h
25#define Lexer_h
26
27#include "lookup.h"
28#include "ustring.h"
29#include <wtf/Vector.h>
30#include "SourceRange.h"
31
32namespace KJS {
33
34 class Identifier;
35 class RegExp;
36
37 class Lexer : Noncopyable {
38 public:
39 void setCode(int startingLineNumber, PassRefPtr<SourceProvider> source);
40 int lex(void* lvalp, void* llocp);
41
42 int lineNo() const { return yylineno; }
43
44 bool prevTerminator() const { return terminator; }
45
46 enum State { Start,
47 IdentifierOrKeyword,
48 Identifier,
49 InIdentifierOrKeyword,
50 InIdentifier,
51 InIdentifierStartUnicodeEscapeStart,
52 InIdentifierStartUnicodeEscape,
53 InIdentifierPartUnicodeEscapeStart,
54 InIdentifierPartUnicodeEscape,
55 InSingleLineComment,
56 InMultiLineComment,
57 InNum,
58 InNum0,
59 InHex,
60 InOctal,
61 InDecimal,
62 InExponentIndicator,
63 InExponent,
64 Hex,
65 Octal,
66 Number,
67 String,
68 Eof,
69 InString,
70 InEscapeSequence,
71 InHexEscape,
72 InUnicodeEscape,
73 Other,
74 Bad };
75
76 bool scanRegExp();
77 const UString& pattern() const { return m_pattern; }
78 const UString& flags() const { return m_flags; }
79
80 static unsigned char convertHex(int);
81 static unsigned char convertHex(int c1, int c2);
82 static UChar convertUnicode(int c1, int c2, int c3, int c4);
83 static bool isIdentStart(int);
84 static bool isIdentPart(int);
85 static bool isHexDigit(int);
86
87 bool sawError() const { return error; }
88
89 void clear();
90 SourceRange sourceRange(int openBrace, int closeBrace) { return SourceRange(m_source, openBrace + 1, closeBrace); }
91
92 private:
93 friend struct JSGlobalData;
94 Lexer(JSGlobalData*);
95 ~Lexer();
96
97 int yylineno;
98 bool done;
99 Vector<char> m_buffer8;
100 Vector<UChar> m_buffer16;
101 bool terminator;
102 bool restrKeyword;
103 // encountered delimiter like "'" and "}" on last run
104 bool delimited;
105 bool skipLF;
106 bool skipCR;
107 bool eatNextIdentifier;
108 int stackToken;
109 int lastToken;
110
111 State state;
112 void setDone(State);
113 unsigned int pos;
114 void shift(unsigned int p);
115 void nextLine();
116 int lookupKeyword(const char *);
117
118 bool isWhiteSpace() const;
119 bool isLineTerminator();
120 static bool isOctalDigit(int);
121
122 int matchPunctuator(int& charPos, int c1, int c2, int c3, int c4);
123 static unsigned short singleEscape(unsigned short);
124 static unsigned short convertOctal(int c1, int c2, int c3);
125
126 void record8(int);
127 void record16(int);
128 void record16(UChar);
129
130 KJS::Identifier* makeIdentifier(const Vector<UChar>& buffer);
131 UString* makeUString(const Vector<UChar>& buffer);
132
133 RefPtr<SourceProvider> m_source;
134 const UChar* code;
135 unsigned int length;
136 int yycolumn;
137 int atLineStart;
138 bool error;
139
140 // current and following unicode characters (int to allow for -1 for end-of-file marker)
141 int current, next1, next2, next3;
142
143 Vector<UString*> m_strings;
144 Vector<KJS::Identifier*> m_identifiers;
145
146 JSGlobalData* m_globalData;
147
148 UString m_pattern;
149 UString m_flags;
150
151 const HashTable mainTable;
152 };
153
154} // namespace KJS
155
156#endif // Lexer_h
Note: See TracBrowser for help on using the repository browser.