]> git.saurik.com Git - apple/javascriptcore.git/blob - parser/ParserTokens.h
JavaScriptCore-1218.tar.gz
[apple/javascriptcore.git] / parser / ParserTokens.h
1 /*
2 * Copyright (C) 2010, 2013 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #ifndef ParserTokens_h
27 #define ParserTokens_h
28
29 #include "ParserModes.h"
30 #include <limits.h>
31 #include <stdint.h>
32
33 namespace JSC {
34
35 class Identifier;
36
37 enum {
38 UnaryOpTokenFlag = 64,
39 KeywordTokenFlag = 128,
40 BinaryOpTokenPrecedenceShift = 8,
41 BinaryOpTokenAllowsInPrecedenceAdditionalShift = 4,
42 BinaryOpTokenPrecedenceMask = 15 << BinaryOpTokenPrecedenceShift,
43 ErrorTokenFlag = 1 << (BinaryOpTokenAllowsInPrecedenceAdditionalShift + BinaryOpTokenPrecedenceShift + 7),
44 UnterminatedErrorTokenFlag = ErrorTokenFlag << 1
45 };
46
47 #define BINARY_OP_PRECEDENCE(prec) (((prec) << BinaryOpTokenPrecedenceShift) | ((prec) << (BinaryOpTokenPrecedenceShift + BinaryOpTokenAllowsInPrecedenceAdditionalShift)))
48 #define IN_OP_PRECEDENCE(prec) ((prec) << (BinaryOpTokenPrecedenceShift + BinaryOpTokenAllowsInPrecedenceAdditionalShift))
49
50 enum JSTokenType {
51 NULLTOKEN = KeywordTokenFlag,
52 TRUETOKEN,
53 FALSETOKEN,
54 BREAK,
55 CASE,
56 DEFAULT,
57 FOR,
58 NEW,
59 VAR,
60 CONSTTOKEN,
61 CONTINUE,
62 FUNCTION,
63 RETURN,
64 IF,
65 THISTOKEN,
66 DO,
67 WHILE,
68 SWITCH,
69 WITH,
70 RESERVED,
71 RESERVED_IF_STRICT,
72 THROW,
73 TRY,
74 CATCH,
75 FINALLY,
76 DEBUGGER,
77 ELSE,
78 OPENBRACE = 0,
79 CLOSEBRACE,
80 OPENPAREN,
81 CLOSEPAREN,
82 OPENBRACKET,
83 CLOSEBRACKET,
84 COMMA,
85 QUESTION,
86 NUMBER,
87 IDENT,
88 STRING,
89 SEMICOLON,
90 COLON,
91 DOT,
92 EOFTOK,
93 EQUAL,
94 PLUSEQUAL,
95 MINUSEQUAL,
96 MULTEQUAL,
97 DIVEQUAL,
98 LSHIFTEQUAL,
99 RSHIFTEQUAL,
100 URSHIFTEQUAL,
101 ANDEQUAL,
102 MODEQUAL,
103 XOREQUAL,
104 OREQUAL,
105 LastUntaggedToken,
106
107 // Begin tagged tokens
108 PLUSPLUS = 0 | UnaryOpTokenFlag,
109 MINUSMINUS = 1 | UnaryOpTokenFlag,
110 EXCLAMATION = 2 | UnaryOpTokenFlag,
111 TILDE = 3 | UnaryOpTokenFlag,
112 AUTOPLUSPLUS = 4 | UnaryOpTokenFlag,
113 AUTOMINUSMINUS = 5 | UnaryOpTokenFlag,
114 TYPEOF = 6 | UnaryOpTokenFlag | KeywordTokenFlag,
115 VOIDTOKEN = 7 | UnaryOpTokenFlag | KeywordTokenFlag,
116 DELETETOKEN = 8 | UnaryOpTokenFlag | KeywordTokenFlag,
117 OR = 0 | BINARY_OP_PRECEDENCE(1),
118 AND = 1 | BINARY_OP_PRECEDENCE(2),
119 BITOR = 2 | BINARY_OP_PRECEDENCE(3),
120 BITXOR = 3 | BINARY_OP_PRECEDENCE(4),
121 BITAND = 4 | BINARY_OP_PRECEDENCE(5),
122 EQEQ = 5 | BINARY_OP_PRECEDENCE(6),
123 NE = 6 | BINARY_OP_PRECEDENCE(6),
124 STREQ = 7 | BINARY_OP_PRECEDENCE(6),
125 STRNEQ = 8 | BINARY_OP_PRECEDENCE(6),
126 LT = 9 | BINARY_OP_PRECEDENCE(7),
127 GT = 10 | BINARY_OP_PRECEDENCE(7),
128 LE = 11 | BINARY_OP_PRECEDENCE(7),
129 GE = 12 | BINARY_OP_PRECEDENCE(7),
130 INSTANCEOF = 13 | BINARY_OP_PRECEDENCE(7) | KeywordTokenFlag,
131 INTOKEN = 14 | IN_OP_PRECEDENCE(7) | KeywordTokenFlag,
132 LSHIFT = 15 | BINARY_OP_PRECEDENCE(8),
133 RSHIFT = 16 | BINARY_OP_PRECEDENCE(8),
134 URSHIFT = 17 | BINARY_OP_PRECEDENCE(8),
135 PLUS = 18 | BINARY_OP_PRECEDENCE(9) | UnaryOpTokenFlag,
136 MINUS = 19 | BINARY_OP_PRECEDENCE(9) | UnaryOpTokenFlag,
137 TIMES = 20 | BINARY_OP_PRECEDENCE(10),
138 DIVIDE = 21 | BINARY_OP_PRECEDENCE(10),
139 MOD = 22 | BINARY_OP_PRECEDENCE(10),
140 ERRORTOK = 0 | ErrorTokenFlag,
141 UNTERMINATED_IDENTIFIER_ESCAPE_ERRORTOK = 0 | ErrorTokenFlag | UnterminatedErrorTokenFlag,
142 INVALID_IDENTIFIER_ESCAPE_ERRORTOK = 1 | ErrorTokenFlag,
143 UNTERMINATED_IDENTIFIER_UNICODE_ESCAPE_ERRORTOK = 2 | ErrorTokenFlag | UnterminatedErrorTokenFlag,
144 INVALID_IDENTIFIER_UNICODE_ESCAPE_ERRORTOK = 3 | ErrorTokenFlag,
145 UNTERMINATED_MULTILINE_COMMENT_ERRORTOK = 4 | ErrorTokenFlag | UnterminatedErrorTokenFlag,
146 UNTERMINATED_NUMERIC_LITERAL_ERRORTOK = 5 | ErrorTokenFlag | UnterminatedErrorTokenFlag,
147 INVALID_OCTAL_NUMBER_ERRORTOK = 6 | ErrorTokenFlag | UnterminatedErrorTokenFlag,
148 INVALID_NUMERIC_LITERAL_ERRORTOK = 7 | ErrorTokenFlag,
149 UNTERMINATED_STRING_LITERAL_ERRORTOK = 8 | ErrorTokenFlag | UnterminatedErrorTokenFlag,
150 INVALID_STRING_LITERAL_ERRORTOK = 9 | ErrorTokenFlag,
151 };
152
153 union JSTokenData {
154 struct {
155 uint32_t line;
156 uint32_t offset;
157 uint32_t lineStartOffset;
158 };
159 double doubleValue;
160 const Identifier* ident;
161 };
162
163 struct JSTokenLocation {
164 JSTokenLocation() : line(0), lineStartOffset(0), startOffset(0) { }
165 JSTokenLocation(const JSTokenLocation& location)
166 {
167 line = location.line;
168 lineStartOffset = location.lineStartOffset;
169 startOffset = location.startOffset;
170 endOffset = location.endOffset;
171 }
172
173 int line;
174 unsigned lineStartOffset;
175 unsigned startOffset;
176 unsigned endOffset;
177 };
178
179 struct JSToken {
180 JSTokenType m_type;
181 JSTokenData m_data;
182 JSTokenLocation m_location;
183 };
184
185 } // namespace JSC
186
187 #endif // ParserTokens_h