Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 1 | // Copyright 2011 the V8 project authors. All rights reserved. |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | |
| 28 | #ifndef V8_PREPARSER_H |
| 29 | #define V8_PREPARSER_H |
| 30 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 31 | namespace v8 { |
| 32 | namespace preparser { |
| 33 | |
| 34 | // Preparsing checks a JavaScript program and emits preparse-data that helps |
| 35 | // a later parsing to be faster. |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 36 | // See preparse-data-format.h for the data format. |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 37 | |
| 38 | // The PreParser checks that the syntax follows the grammar for JavaScript, |
| 39 | // and collects some information about the program along the way. |
| 40 | // The grammar check is only performed in order to understand the program |
| 41 | // sufficiently to deduce some information about it, that can be used |
| 42 | // to speed up later parsing. Finding errors is not the goal of pre-parsing, |
| 43 | // rather it is to speed up properly written and correct programs. |
| 44 | // That means that contextual checks (like a label being declared where |
| 45 | // it is used) are generally omitted. |
| 46 | |
| 47 | namespace i = v8::internal; |
| 48 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 49 | class PreParser { |
| 50 | public: |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 51 | enum PreParseResult { |
| 52 | kPreParseStackOverflow, |
| 53 | kPreParseSuccess |
| 54 | }; |
| 55 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 56 | ~PreParser() { } |
| 57 | |
| 58 | // Pre-parse the program from the character stream; returns true on |
| 59 | // success (even if parsing failed, the pre-parse data successfully |
| 60 | // captured the syntax error), and false if a stack-overflow happened |
| 61 | // during parsing. |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 62 | static PreParseResult PreParseProgram(i::JavaScriptScanner* scanner, |
| 63 | i::ParserRecorder* log, |
| 64 | bool allow_lazy, |
| 65 | uintptr_t stack_limit) { |
| 66 | return PreParser(scanner, log, stack_limit, allow_lazy).PreParse(); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | private: |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 70 | // These types form an algebra over syntactic categories that is just |
| 71 | // rich enough to let us recognize and propagate the constructs that |
| 72 | // are either being counted in the preparser data, or is important |
| 73 | // to throw the correct syntax error exceptions. |
| 74 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 75 | enum ScopeType { |
| 76 | kTopLevelScope, |
| 77 | kFunctionScope |
| 78 | }; |
| 79 | |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 80 | enum VariableDeclarationContext { |
| 81 | kSourceElement, |
| 82 | kStatement, |
| 83 | kForStatement |
| 84 | }; |
| 85 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 86 | class Expression; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 87 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 88 | class Identifier { |
| 89 | public: |
| 90 | static Identifier Default() { |
| 91 | return Identifier(kUnknownIdentifier); |
| 92 | } |
| 93 | static Identifier Eval() { |
| 94 | return Identifier(kEvalIdentifier); |
| 95 | } |
| 96 | static Identifier Arguments() { |
| 97 | return Identifier(kArgumentsIdentifier); |
| 98 | } |
| 99 | static Identifier FutureReserved() { |
| 100 | return Identifier(kFutureReservedIdentifier); |
| 101 | } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 102 | static Identifier FutureStrictReserved() { |
| 103 | return Identifier(kFutureStrictReservedIdentifier); |
| 104 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 105 | bool IsEval() { return type_ == kEvalIdentifier; } |
| 106 | bool IsArguments() { return type_ == kArgumentsIdentifier; } |
| 107 | bool IsEvalOrArguments() { return type_ >= kEvalIdentifier; } |
| 108 | bool IsFutureReserved() { return type_ == kFutureReservedIdentifier; } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 109 | bool IsFutureStrictReserved() { |
| 110 | return type_ == kFutureStrictReservedIdentifier; |
| 111 | } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 112 | bool IsValidStrictVariable() { return type_ == kUnknownIdentifier; } |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 113 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 114 | private: |
| 115 | enum Type { |
| 116 | kUnknownIdentifier, |
| 117 | kFutureReservedIdentifier, |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 118 | kFutureStrictReservedIdentifier, |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 119 | kEvalIdentifier, |
| 120 | kArgumentsIdentifier |
| 121 | }; |
| 122 | explicit Identifier(Type type) : type_(type) { } |
| 123 | Type type_; |
| 124 | |
| 125 | friend class Expression; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 126 | }; |
| 127 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 128 | // Bits 0 and 1 are used to identify the type of expression: |
| 129 | // If bit 0 is set, it's an identifier. |
| 130 | // if bit 1 is set, it's a string literal. |
| 131 | // If neither is set, it's no particular type, and both set isn't |
| 132 | // use yet. |
| 133 | // Bit 2 is used to mark the expression as being parenthesized, |
| 134 | // so "(foo)" isn't recognized as a pure identifier (and possible label). |
| 135 | class Expression { |
| 136 | public: |
| 137 | static Expression Default() { |
| 138 | return Expression(kUnknownExpression); |
| 139 | } |
| 140 | |
| 141 | static Expression FromIdentifier(Identifier id) { |
| 142 | return Expression(kIdentifierFlag | (id.type_ << kIdentifierShift)); |
| 143 | } |
| 144 | |
| 145 | static Expression StringLiteral() { |
| 146 | return Expression(kUnknownStringLiteral); |
| 147 | } |
| 148 | |
| 149 | static Expression UseStrictStringLiteral() { |
| 150 | return Expression(kUseStrictString); |
| 151 | } |
| 152 | |
| 153 | static Expression This() { |
| 154 | return Expression(kThisExpression); |
| 155 | } |
| 156 | |
| 157 | static Expression ThisProperty() { |
| 158 | return Expression(kThisPropertyExpression); |
| 159 | } |
| 160 | |
| 161 | static Expression StrictFunction() { |
| 162 | return Expression(kStrictFunctionExpression); |
| 163 | } |
| 164 | |
| 165 | bool IsIdentifier() { |
| 166 | return (code_ & kIdentifierFlag) != 0; |
| 167 | } |
| 168 | |
| 169 | // Only works corretly if it is actually an identifier expression. |
| 170 | PreParser::Identifier AsIdentifier() { |
| 171 | return PreParser::Identifier( |
| 172 | static_cast<PreParser::Identifier::Type>(code_ >> kIdentifierShift)); |
| 173 | } |
| 174 | |
| 175 | bool IsParenthesized() { |
| 176 | // If bit 0 or 1 is set, we interpret bit 2 as meaning parenthesized. |
| 177 | return (code_ & 7) > 4; |
| 178 | } |
| 179 | |
| 180 | bool IsRawIdentifier() { |
| 181 | return !IsParenthesized() && IsIdentifier(); |
| 182 | } |
| 183 | |
| 184 | bool IsStringLiteral() { return (code_ & kStringLiteralFlag) != 0; } |
| 185 | |
| 186 | bool IsRawStringLiteral() { |
| 187 | return !IsParenthesized() && IsStringLiteral(); |
| 188 | } |
| 189 | |
| 190 | bool IsUseStrictLiteral() { |
| 191 | return (code_ & kStringLiteralMask) == kUseStrictString; |
| 192 | } |
| 193 | |
| 194 | bool IsThis() { |
| 195 | return code_ == kThisExpression; |
| 196 | } |
| 197 | |
| 198 | bool IsThisProperty() { |
| 199 | return code_ == kThisPropertyExpression; |
| 200 | } |
| 201 | |
| 202 | bool IsStrictFunction() { |
| 203 | return code_ == kStrictFunctionExpression; |
| 204 | } |
| 205 | |
| 206 | Expression Parenthesize() { |
| 207 | int type = code_ & 3; |
| 208 | if (type != 0) { |
| 209 | // Identifiers and string literals can be parenthesized. |
| 210 | // They no longer work as labels or directive prologues, |
| 211 | // but are still recognized in other contexts. |
| 212 | return Expression(code_ | kParentesizedExpressionFlag); |
| 213 | } |
| 214 | // For other types of expressions, it's not important to remember |
| 215 | // the parentheses. |
| 216 | return *this; |
| 217 | } |
| 218 | |
| 219 | private: |
| 220 | // First two/three bits are used as flags. |
| 221 | // Bit 0 and 1 represent identifiers or strings literals, and are |
| 222 | // mutually exclusive, but can both be absent. |
| 223 | // If bit 0 or 1 are set, bit 2 marks that the expression has |
| 224 | // been wrapped in parentheses (a string literal can no longer |
| 225 | // be a directive prologue, and an identifier can no longer be |
| 226 | // a label. |
| 227 | enum { |
| 228 | kUnknownExpression = 0, |
| 229 | // Identifiers |
| 230 | kIdentifierFlag = 1, // Used to detect labels. |
| 231 | kIdentifierShift = 3, |
| 232 | |
| 233 | kStringLiteralFlag = 2, // Used to detect directive prologue. |
| 234 | kUnknownStringLiteral = kStringLiteralFlag, |
| 235 | kUseStrictString = kStringLiteralFlag | 8, |
| 236 | kStringLiteralMask = kUseStrictString, |
| 237 | |
| 238 | kParentesizedExpressionFlag = 4, // Only if identifier or string literal. |
| 239 | |
| 240 | // Below here applies if neither identifier nor string literal. |
| 241 | kThisExpression = 4, |
| 242 | kThisPropertyExpression = 8, |
| 243 | kStrictFunctionExpression = 12 |
| 244 | }; |
| 245 | |
| 246 | explicit Expression(int expression_code) : code_(expression_code) { } |
| 247 | |
| 248 | int code_; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 249 | }; |
| 250 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 251 | class Statement { |
| 252 | public: |
| 253 | static Statement Default() { |
| 254 | return Statement(kUnknownStatement); |
| 255 | } |
| 256 | |
| 257 | static Statement FunctionDeclaration() { |
| 258 | return Statement(kFunctionDeclaration); |
| 259 | } |
| 260 | |
| 261 | // Creates expression statement from expression. |
| 262 | // Preserves being an unparenthesized string literal, possibly |
| 263 | // "use strict". |
| 264 | static Statement ExpressionStatement(Expression expression) { |
| 265 | if (!expression.IsParenthesized()) { |
| 266 | if (expression.IsUseStrictLiteral()) { |
| 267 | return Statement(kUseStrictExpressionStatement); |
| 268 | } |
| 269 | if (expression.IsStringLiteral()) { |
| 270 | return Statement(kStringLiteralExpressionStatement); |
| 271 | } |
| 272 | } |
| 273 | return Default(); |
| 274 | } |
| 275 | |
| 276 | bool IsStringLiteral() { |
| 277 | return code_ != kUnknownStatement; |
| 278 | } |
| 279 | |
| 280 | bool IsUseStrictLiteral() { |
| 281 | return code_ == kUseStrictExpressionStatement; |
| 282 | } |
| 283 | |
| 284 | bool IsFunctionDeclaration() { |
| 285 | return code_ == kFunctionDeclaration; |
| 286 | } |
| 287 | |
| 288 | private: |
| 289 | enum Type { |
| 290 | kUnknownStatement, |
| 291 | kStringLiteralExpressionStatement, |
| 292 | kUseStrictExpressionStatement, |
| 293 | kFunctionDeclaration |
| 294 | }; |
| 295 | |
| 296 | explicit Statement(Type code) : code_(code) {} |
| 297 | Type code_; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 298 | }; |
| 299 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 300 | enum SourceElements { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 301 | kUnknownSourceElements |
| 302 | }; |
| 303 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 304 | typedef int Arguments; |
| 305 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 306 | class Scope { |
| 307 | public: |
| 308 | Scope(Scope** variable, ScopeType type) |
| 309 | : variable_(variable), |
| 310 | prev_(*variable), |
| 311 | type_(type), |
| 312 | materialized_literal_count_(0), |
| 313 | expected_properties_(0), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 314 | with_nesting_count_(0), |
| 315 | strict_((prev_ != NULL) && prev_->is_strict()) { |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 316 | *variable = this; |
| 317 | } |
| 318 | ~Scope() { *variable_ = prev_; } |
| 319 | void NextMaterializedLiteralIndex() { materialized_literal_count_++; } |
| 320 | void AddProperty() { expected_properties_++; } |
| 321 | ScopeType type() { return type_; } |
| 322 | int expected_properties() { return expected_properties_; } |
| 323 | int materialized_literal_count() { return materialized_literal_count_; } |
| 324 | bool IsInsideWith() { return with_nesting_count_ != 0; } |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 325 | bool is_strict() { return strict_; } |
| 326 | void set_strict() { strict_ = true; } |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 327 | void EnterWith() { with_nesting_count_++; } |
| 328 | void LeaveWith() { with_nesting_count_--; } |
| 329 | |
| 330 | private: |
| 331 | Scope** const variable_; |
| 332 | Scope* const prev_; |
| 333 | const ScopeType type_; |
| 334 | int materialized_literal_count_; |
| 335 | int expected_properties_; |
| 336 | int with_nesting_count_; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 337 | bool strict_; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 338 | }; |
| 339 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 340 | // Private constructor only used in PreParseProgram. |
| 341 | PreParser(i::JavaScriptScanner* scanner, |
| 342 | i::ParserRecorder* log, |
| 343 | uintptr_t stack_limit, |
| 344 | bool allow_lazy) |
| 345 | : scanner_(scanner), |
| 346 | log_(log), |
| 347 | scope_(NULL), |
| 348 | stack_limit_(stack_limit), |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 349 | strict_mode_violation_location_(i::Scanner::Location::invalid()), |
| 350 | strict_mode_violation_type_(NULL), |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 351 | stack_overflow_(false), |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 352 | allow_lazy_(true), |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 353 | parenthesized_function_(false), |
| 354 | harmony_block_scoping_(scanner->HarmonyBlockScoping()) { } |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 355 | |
| 356 | // Preparse the program. Only called in PreParseProgram after creating |
| 357 | // the instance. |
| 358 | PreParseResult PreParse() { |
| 359 | Scope top_scope(&scope_, kTopLevelScope); |
| 360 | bool ok = true; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 361 | int start_position = scanner_->peek_location().beg_pos; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 362 | ParseSourceElements(i::Token::EOS, &ok); |
| 363 | if (stack_overflow_) return kPreParseStackOverflow; |
| 364 | if (!ok) { |
| 365 | ReportUnexpectedToken(scanner_->current_token()); |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 366 | } else if (scope_->is_strict()) { |
| 367 | CheckOctalLiteral(start_position, scanner_->location().end_pos, &ok); |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 368 | } |
| 369 | return kPreParseSuccess; |
| 370 | } |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 371 | |
| 372 | // Report syntax error |
| 373 | void ReportUnexpectedToken(i::Token::Value token); |
| 374 | void ReportMessageAt(int start_pos, |
| 375 | int end_pos, |
| 376 | const char* type, |
| 377 | const char* name_opt) { |
| 378 | log_->LogMessage(start_pos, end_pos, type, name_opt); |
| 379 | } |
| 380 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 381 | void CheckOctalLiteral(int beg_pos, int end_pos, bool* ok); |
| 382 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 383 | // All ParseXXX functions take as the last argument an *ok parameter |
| 384 | // which is set to false if parsing failed; it is unchanged otherwise. |
| 385 | // By making the 'exception handling' explicit, we are forced to check |
| 386 | // for failure at the call sites. |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 387 | Statement ParseSourceElement(bool* ok); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 388 | SourceElements ParseSourceElements(int end_token, bool* ok); |
| 389 | Statement ParseStatement(bool* ok); |
| 390 | Statement ParseFunctionDeclaration(bool* ok); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 391 | Statement ParseBlock(bool* ok); |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 392 | Statement ParseVariableStatement(VariableDeclarationContext var_context, |
| 393 | bool* ok); |
| 394 | Statement ParseVariableDeclarations(VariableDeclarationContext var_context, |
| 395 | int* num_decl, |
| 396 | bool* ok); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 397 | Statement ParseExpressionOrLabelledStatement(bool* ok); |
| 398 | Statement ParseIfStatement(bool* ok); |
| 399 | Statement ParseContinueStatement(bool* ok); |
| 400 | Statement ParseBreakStatement(bool* ok); |
| 401 | Statement ParseReturnStatement(bool* ok); |
| 402 | Statement ParseWithStatement(bool* ok); |
| 403 | Statement ParseSwitchStatement(bool* ok); |
| 404 | Statement ParseDoWhileStatement(bool* ok); |
| 405 | Statement ParseWhileStatement(bool* ok); |
| 406 | Statement ParseForStatement(bool* ok); |
| 407 | Statement ParseThrowStatement(bool* ok); |
| 408 | Statement ParseTryStatement(bool* ok); |
| 409 | Statement ParseDebuggerStatement(bool* ok); |
| 410 | |
| 411 | Expression ParseExpression(bool accept_IN, bool* ok); |
| 412 | Expression ParseAssignmentExpression(bool accept_IN, bool* ok); |
| 413 | Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
| 414 | Expression ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
| 415 | Expression ParseUnaryExpression(bool* ok); |
| 416 | Expression ParsePostfixExpression(bool* ok); |
| 417 | Expression ParseLeftHandSideExpression(bool* ok); |
| 418 | Expression ParseNewExpression(bool* ok); |
| 419 | Expression ParseMemberExpression(bool* ok); |
| 420 | Expression ParseMemberWithNewPrefixesExpression(unsigned new_count, bool* ok); |
| 421 | Expression ParsePrimaryExpression(bool* ok); |
| 422 | Expression ParseArrayLiteral(bool* ok); |
| 423 | Expression ParseObjectLiteral(bool* ok); |
| 424 | Expression ParseRegExpLiteral(bool seen_equal, bool* ok); |
| 425 | Expression ParseV8Intrinsic(bool* ok); |
| 426 | |
| 427 | Arguments ParseArguments(bool* ok); |
| 428 | Expression ParseFunctionLiteral(bool* ok); |
| 429 | |
| 430 | Identifier ParseIdentifier(bool* ok); |
| 431 | Identifier ParseIdentifierName(bool* ok); |
Ben Murdoch | 3fb3ca8 | 2011-12-02 17:19:32 +0000 | [diff] [blame] | 432 | Identifier ParseIdentifierNameOrGetOrSet(bool* is_get, |
| 433 | bool* is_set, |
| 434 | bool* ok); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 435 | |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 436 | // Logs the currently parsed literal as a symbol in the preparser data. |
| 437 | void LogSymbol(); |
| 438 | // Log the currently parsed identifier. |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 439 | Identifier GetIdentifierSymbol(); |
Steve Block | 9fac840 | 2011-05-12 15:51:54 +0100 | [diff] [blame] | 440 | // Log the currently parsed string literal. |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 441 | Expression GetStringSymbol(); |
| 442 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 443 | i::Token::Value peek() { |
| 444 | if (stack_overflow_) return i::Token::ILLEGAL; |
| 445 | return scanner_->peek(); |
| 446 | } |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 447 | |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 448 | i::Token::Value Next() { |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 449 | if (stack_overflow_) return i::Token::ILLEGAL; |
| 450 | { |
| 451 | int marker; |
| 452 | if (reinterpret_cast<uintptr_t>(&marker) < stack_limit_) { |
| 453 | // Further calls to peek/Next will return illegal token. |
| 454 | // The current one will still be returned. It might already |
| 455 | // have been seen using peek. |
| 456 | stack_overflow_ = true; |
| 457 | } |
| 458 | } |
| 459 | return scanner_->Next(); |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 460 | } |
| 461 | |
Steve Block | 1e0659c | 2011-05-24 12:43:12 +0100 | [diff] [blame] | 462 | bool peek_any_identifier(); |
| 463 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 464 | void set_strict_mode() { |
| 465 | scope_->set_strict(); |
| 466 | } |
| 467 | |
| 468 | bool strict_mode() { return scope_->is_strict(); } |
| 469 | |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 470 | void Consume(i::Token::Value token) { Next(); } |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 471 | |
| 472 | void Expect(i::Token::Value token, bool* ok) { |
| 473 | if (Next() != token) { |
| 474 | *ok = false; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | bool Check(i::Token::Value token) { |
| 479 | i::Token::Value next = peek(); |
| 480 | if (next == token) { |
| 481 | Consume(next); |
| 482 | return true; |
| 483 | } |
| 484 | return false; |
| 485 | } |
| 486 | void ExpectSemicolon(bool* ok); |
| 487 | |
| 488 | static int Precedence(i::Token::Value tok, bool accept_IN); |
| 489 | |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 490 | void SetStrictModeViolation(i::Scanner::Location, |
| 491 | const char* type, |
| 492 | bool *ok); |
| 493 | |
| 494 | void CheckDelayedStrictModeViolation(int beg_pos, int end_pos, bool* ok); |
| 495 | |
| 496 | void StrictModeIdentifierViolation(i::Scanner::Location, |
| 497 | const char* eval_args_type, |
| 498 | Identifier identifier, |
| 499 | bool* ok); |
| 500 | |
Shimeng (Simon) Wang | 8a31eba | 2010-12-06 19:01:33 -0800 | [diff] [blame] | 501 | i::JavaScriptScanner* scanner_; |
| 502 | i::ParserRecorder* log_; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 503 | Scope* scope_; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 504 | uintptr_t stack_limit_; |
Ben Murdoch | 257744e | 2011-11-30 15:57:28 +0000 | [diff] [blame] | 505 | i::Scanner::Location strict_mode_violation_location_; |
| 506 | const char* strict_mode_violation_type_; |
Ben Murdoch | b0fe162 | 2011-05-05 13:52:32 +0100 | [diff] [blame] | 507 | bool stack_overflow_; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 508 | bool allow_lazy_; |
Ben Murdoch | b8e0da2 | 2011-05-16 14:20:40 +0100 | [diff] [blame] | 509 | bool parenthesized_function_; |
Ben Murdoch | 69a99ed | 2011-11-30 16:03:39 +0000 | [diff] [blame^] | 510 | bool harmony_block_scoping_; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 511 | }; |
Teng-Hui Zhu | 3e5fa29 | 2010-11-09 16:16:48 -0800 | [diff] [blame] | 512 | } } // v8::preparser |
| 513 | |
| 514 | #endif // V8_PREPARSER_H |