| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 bool allow_natives_syntax = (flags & i::kAllowNativesSyntax) != 0; | 145 bool allow_natives_syntax = (flags & i::kAllowNativesSyntax) != 0; |
| 146 bool allow_modules = (flags & i::kAllowModules) != 0; | 146 bool allow_modules = (flags & i::kAllowModules) != 0; |
| 147 return PreParser(scanner, log, stack_limit, allow_lazy, | 147 return PreParser(scanner, log, stack_limit, allow_lazy, |
| 148 allow_natives_syntax, allow_modules).PreParse(); | 148 allow_natives_syntax, allow_modules).PreParse(); |
| 149 } | 149 } |
| 150 | 150 |
| 151 // Parses a single function literal, from the opening parentheses before | 151 // Parses a single function literal, from the opening parentheses before |
| 152 // parameters to the closing brace after the body. | 152 // parameters to the closing brace after the body. |
| 153 // Returns a FunctionEntry describing the body of the function in enough | 153 // Returns a FunctionEntry describing the body of the function in enough |
| 154 // detail that it can be lazily compiled. | 154 // detail that it can be lazily compiled. |
| 155 // The scanner is expected to have matched the "function" keyword and | 155 // The scanner is expected to have matched the "function" or "function*" |
| 156 // parameters, and have consumed the initial '{'. | 156 // keyword and parameters, and have consumed the initial '{'. |
| 157 // At return, unless an error occurred, the scanner is positioned before the | 157 // At return, unless an error occurred, the scanner is positioned before the |
| 158 // the final '}'. | 158 // the final '}'. |
| 159 PreParseResult PreParseLazyFunction(i::LanguageMode mode, | 159 PreParseResult PreParseLazyFunction(i::LanguageMode mode, |
| 160 bool is_generator, |
| 160 i::ParserRecorder* log); | 161 i::ParserRecorder* log); |
| 161 | 162 |
| 162 private: | 163 private: |
| 163 // Used to detect duplicates in object literals. Each of the values | 164 // Used to detect duplicates in object literals. Each of the values |
| 164 // kGetterProperty, kSetterProperty and kValueProperty represents | 165 // kGetterProperty, kSetterProperty and kValueProperty represents |
| 165 // a type of object literal property. When parsing a property, its | 166 // a type of object literal property. When parsing a property, its |
| 166 // type value is stored in the DuplicateFinder for the property name. | 167 // type value is stored in the DuplicateFinder for the property name. |
| 167 // Values are chosen so that having intersection bits means the there is | 168 // Values are chosen so that having intersection bits means the there is |
| 168 // an incompatibility. | 169 // an incompatibility. |
| 169 // I.e., you can add a getter to a property that already has a setter, since | 170 // I.e., you can add a getter to a property that already has a setter, since |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } | 234 } |
| 234 static Identifier Arguments() { | 235 static Identifier Arguments() { |
| 235 return Identifier(kArgumentsIdentifier); | 236 return Identifier(kArgumentsIdentifier); |
| 236 } | 237 } |
| 237 static Identifier FutureReserved() { | 238 static Identifier FutureReserved() { |
| 238 return Identifier(kFutureReservedIdentifier); | 239 return Identifier(kFutureReservedIdentifier); |
| 239 } | 240 } |
| 240 static Identifier FutureStrictReserved() { | 241 static Identifier FutureStrictReserved() { |
| 241 return Identifier(kFutureStrictReservedIdentifier); | 242 return Identifier(kFutureStrictReservedIdentifier); |
| 242 } | 243 } |
| 244 static Identifier Yield() { |
| 245 return Identifier(kFutureStrictReservedIdentifier); |
| 246 } |
| 243 bool IsEval() { return type_ == kEvalIdentifier; } | 247 bool IsEval() { return type_ == kEvalIdentifier; } |
| 244 bool IsArguments() { return type_ == kArgumentsIdentifier; } | 248 bool IsArguments() { return type_ == kArgumentsIdentifier; } |
| 245 bool IsEvalOrArguments() { return type_ >= kEvalIdentifier; } | 249 bool IsEvalOrArguments() { return type_ >= kEvalIdentifier; } |
| 250 bool IsYield() { return type_ == kYieldIdentifier; } |
| 246 bool IsFutureReserved() { return type_ == kFutureReservedIdentifier; } | 251 bool IsFutureReserved() { return type_ == kFutureReservedIdentifier; } |
| 247 bool IsFutureStrictReserved() { | 252 bool IsFutureStrictReserved() { |
| 248 return type_ == kFutureStrictReservedIdentifier; | 253 return type_ == kFutureStrictReservedIdentifier; |
| 249 } | 254 } |
| 250 bool IsValidStrictVariable() { return type_ == kUnknownIdentifier; } | 255 bool IsValidStrictVariable() { return type_ == kUnknownIdentifier; } |
| 251 | 256 |
| 252 private: | 257 private: |
| 253 enum Type { | 258 enum Type { |
| 254 kUnknownIdentifier, | 259 kUnknownIdentifier, |
| 255 kFutureReservedIdentifier, | 260 kFutureReservedIdentifier, |
| 256 kFutureStrictReservedIdentifier, | 261 kFutureStrictReservedIdentifier, |
| 262 kYieldIdentifier, |
| 257 kEvalIdentifier, | 263 kEvalIdentifier, |
| 258 kArgumentsIdentifier | 264 kArgumentsIdentifier |
| 259 }; | 265 }; |
| 260 explicit Identifier(Type type) : type_(type) { } | 266 explicit Identifier(Type type) : type_(type) { } |
| 261 Type type_; | 267 Type type_; |
| 262 | 268 |
| 263 friend class Expression; | 269 friend class Expression; |
| 264 }; | 270 }; |
| 265 | 271 |
| 266 // Bits 0 and 1 are used to identify the type of expression: | 272 // Bits 0 and 1 are used to identify the type of expression: |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 340 bool IsStrictFunction() { | 346 bool IsStrictFunction() { |
| 341 return code_ == kStrictFunctionExpression; | 347 return code_ == kStrictFunctionExpression; |
| 342 } | 348 } |
| 343 | 349 |
| 344 Expression Parenthesize() { | 350 Expression Parenthesize() { |
| 345 int type = code_ & 3; | 351 int type = code_ & 3; |
| 346 if (type != 0) { | 352 if (type != 0) { |
| 347 // Identifiers and string literals can be parenthesized. | 353 // Identifiers and string literals can be parenthesized. |
| 348 // They no longer work as labels or directive prologues, | 354 // They no longer work as labels or directive prologues, |
| 349 // but are still recognized in other contexts. | 355 // but are still recognized in other contexts. |
| 350 return Expression(code_ | kParentesizedExpressionFlag); | 356 return Expression(code_ | kParenthesizedExpressionFlag); |
| 351 } | 357 } |
| 352 // For other types of expressions, it's not important to remember | 358 // For other types of expressions, it's not important to remember |
| 353 // the parentheses. | 359 // the parentheses. |
| 354 return *this; | 360 return *this; |
| 355 } | 361 } |
| 356 | 362 |
| 357 private: | 363 private: |
| 358 // First two/three bits are used as flags. | 364 // First two/three bits are used as flags. |
| 359 // Bit 0 and 1 represent identifiers or strings literals, and are | 365 // Bit 0 and 1 represent identifiers or strings literals, and are |
| 360 // mutually exclusive, but can both be absent. | 366 // mutually exclusive, but can both be absent. |
| 361 // If bit 0 or 1 are set, bit 2 marks that the expression has | 367 // If bit 0 or 1 are set, bit 2 marks that the expression has |
| 362 // been wrapped in parentheses (a string literal can no longer | 368 // been wrapped in parentheses (a string literal can no longer |
| 363 // be a directive prologue, and an identifier can no longer be | 369 // be a directive prologue, and an identifier can no longer be |
| 364 // a label. | 370 // a label. |
| 365 enum { | 371 enum { |
| 366 kUnknownExpression = 0, | 372 kUnknownExpression = 0, |
| 367 // Identifiers | 373 // Identifiers |
| 368 kIdentifierFlag = 1, // Used to detect labels. | 374 kIdentifierFlag = 1, // Used to detect labels. |
| 369 kIdentifierShift = 3, | 375 kIdentifierShift = 3, |
| 370 | 376 |
| 371 kStringLiteralFlag = 2, // Used to detect directive prologue. | 377 kStringLiteralFlag = 2, // Used to detect directive prologue. |
| 372 kUnknownStringLiteral = kStringLiteralFlag, | 378 kUnknownStringLiteral = kStringLiteralFlag, |
| 373 kUseStrictString = kStringLiteralFlag | 8, | 379 kUseStrictString = kStringLiteralFlag | 8, |
| 374 kStringLiteralMask = kUseStrictString, | 380 kStringLiteralMask = kUseStrictString, |
| 375 | 381 |
| 376 kParentesizedExpressionFlag = 4, // Only if identifier or string literal. | 382 // Only if identifier or string literal. |
| 383 kParenthesizedExpressionFlag = 4, |
| 377 | 384 |
| 378 // Below here applies if neither identifier nor string literal. | 385 // Below here applies if neither identifier nor string literal. |
| 379 kThisExpression = 4, | 386 kThisExpression = 4, |
| 380 kThisPropertyExpression = 8, | 387 kThisPropertyExpression = 8, |
| 381 kStrictFunctionExpression = 12 | 388 kStrictFunctionExpression = 12 |
| 382 }; | 389 }; |
| 383 | 390 |
| 384 explicit Expression(int expression_code) : code_(expression_code) { } | 391 explicit Expression(int expression_code) : code_(expression_code) { } |
| 385 | 392 |
| 386 int code_; | 393 int code_; |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 class Scope { | 451 class Scope { |
| 445 public: | 452 public: |
| 446 Scope(Scope** variable, ScopeType type) | 453 Scope(Scope** variable, ScopeType type) |
| 447 : variable_(variable), | 454 : variable_(variable), |
| 448 prev_(*variable), | 455 prev_(*variable), |
| 449 type_(type), | 456 type_(type), |
| 450 materialized_literal_count_(0), | 457 materialized_literal_count_(0), |
| 451 expected_properties_(0), | 458 expected_properties_(0), |
| 452 with_nesting_count_(0), | 459 with_nesting_count_(0), |
| 453 language_mode_( | 460 language_mode_( |
| 454 (prev_ != NULL) ? prev_->language_mode() : i::CLASSIC_MODE) { | 461 (prev_ != NULL) ? prev_->language_mode() : i::CLASSIC_MODE), |
| 462 is_generator_(false) { |
| 455 *variable = this; | 463 *variable = this; |
| 456 } | 464 } |
| 457 ~Scope() { *variable_ = prev_; } | 465 ~Scope() { *variable_ = prev_; } |
| 458 void NextMaterializedLiteralIndex() { materialized_literal_count_++; } | 466 void NextMaterializedLiteralIndex() { materialized_literal_count_++; } |
| 459 void AddProperty() { expected_properties_++; } | 467 void AddProperty() { expected_properties_++; } |
| 460 ScopeType type() { return type_; } | 468 ScopeType type() { return type_; } |
| 461 int expected_properties() { return expected_properties_; } | 469 int expected_properties() { return expected_properties_; } |
| 462 int materialized_literal_count() { return materialized_literal_count_; } | 470 int materialized_literal_count() { return materialized_literal_count_; } |
| 463 bool IsInsideWith() { return with_nesting_count_ != 0; } | 471 bool IsInsideWith() { return with_nesting_count_ != 0; } |
| 472 bool is_generator() { return is_generator_; } |
| 473 void set_is_generator(bool is_generator) { is_generator_ = is_generator; } |
| 464 bool is_classic_mode() { | 474 bool is_classic_mode() { |
| 465 return language_mode_ == i::CLASSIC_MODE; | 475 return language_mode_ == i::CLASSIC_MODE; |
| 466 } | 476 } |
| 467 i::LanguageMode language_mode() { | 477 i::LanguageMode language_mode() { |
| 468 return language_mode_; | 478 return language_mode_; |
| 469 } | 479 } |
| 470 void set_language_mode(i::LanguageMode language_mode) { | 480 void set_language_mode(i::LanguageMode language_mode) { |
| 471 language_mode_ = language_mode; | 481 language_mode_ = language_mode; |
| 472 } | 482 } |
| 473 | 483 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 485 }; | 495 }; |
| 486 | 496 |
| 487 private: | 497 private: |
| 488 Scope** const variable_; | 498 Scope** const variable_; |
| 489 Scope* const prev_; | 499 Scope* const prev_; |
| 490 const ScopeType type_; | 500 const ScopeType type_; |
| 491 int materialized_literal_count_; | 501 int materialized_literal_count_; |
| 492 int expected_properties_; | 502 int expected_properties_; |
| 493 int with_nesting_count_; | 503 int with_nesting_count_; |
| 494 i::LanguageMode language_mode_; | 504 i::LanguageMode language_mode_; |
| 505 bool is_generator_; |
| 495 }; | 506 }; |
| 496 | 507 |
| 497 // Preparse the program. Only called in PreParseProgram after creating | 508 // Preparse the program. Only called in PreParseProgram after creating |
| 498 // the instance. | 509 // the instance. |
| 499 PreParseResult PreParse() { | 510 PreParseResult PreParse() { |
| 500 Scope top_scope(&scope_, kTopLevelScope); | 511 Scope top_scope(&scope_, kTopLevelScope); |
| 501 bool ok = true; | 512 bool ok = true; |
| 502 int start_position = scanner_->peek_location().beg_pos; | 513 int start_position = scanner_->peek_location().beg_pos; |
| 503 ParseSourceElements(i::Token::EOS, &ok); | 514 ParseSourceElements(i::Token::EOS, &ok); |
| 504 if (stack_overflow_) return kPreParseStackOverflow; | 515 if (stack_overflow_) return kPreParseStackOverflow; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 Statement ParseSwitchStatement(bool* ok); | 561 Statement ParseSwitchStatement(bool* ok); |
| 551 Statement ParseDoWhileStatement(bool* ok); | 562 Statement ParseDoWhileStatement(bool* ok); |
| 552 Statement ParseWhileStatement(bool* ok); | 563 Statement ParseWhileStatement(bool* ok); |
| 553 Statement ParseForStatement(bool* ok); | 564 Statement ParseForStatement(bool* ok); |
| 554 Statement ParseThrowStatement(bool* ok); | 565 Statement ParseThrowStatement(bool* ok); |
| 555 Statement ParseTryStatement(bool* ok); | 566 Statement ParseTryStatement(bool* ok); |
| 556 Statement ParseDebuggerStatement(bool* ok); | 567 Statement ParseDebuggerStatement(bool* ok); |
| 557 | 568 |
| 558 Expression ParseExpression(bool accept_IN, bool* ok); | 569 Expression ParseExpression(bool accept_IN, bool* ok); |
| 559 Expression ParseAssignmentExpression(bool accept_IN, bool* ok); | 570 Expression ParseAssignmentExpression(bool accept_IN, bool* ok); |
| 571 Expression ParseYieldExpression(bool* ok); |
| 560 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 572 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
| 561 Expression ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 573 Expression ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
| 562 Expression ParseUnaryExpression(bool* ok); | 574 Expression ParseUnaryExpression(bool* ok); |
| 563 Expression ParsePostfixExpression(bool* ok); | 575 Expression ParsePostfixExpression(bool* ok); |
| 564 Expression ParseLeftHandSideExpression(bool* ok); | 576 Expression ParseLeftHandSideExpression(bool* ok); |
| 565 Expression ParseNewExpression(bool* ok); | 577 Expression ParseNewExpression(bool* ok); |
| 566 Expression ParseMemberExpression(bool* ok); | 578 Expression ParseMemberExpression(bool* ok); |
| 567 Expression ParseMemberWithNewPrefixesExpression(unsigned new_count, bool* ok); | 579 Expression ParseMemberWithNewPrefixesExpression(unsigned new_count, bool* ok); |
| 568 Expression ParsePrimaryExpression(bool* ok); | 580 Expression ParsePrimaryExpression(bool* ok); |
| 569 Expression ParseArrayLiteral(bool* ok); | 581 Expression ParseArrayLiteral(bool* ok); |
| 570 Expression ParseObjectLiteral(bool* ok); | 582 Expression ParseObjectLiteral(bool* ok); |
| 571 Expression ParseRegExpLiteral(bool seen_equal, bool* ok); | 583 Expression ParseRegExpLiteral(bool seen_equal, bool* ok); |
| 572 Expression ParseV8Intrinsic(bool* ok); | 584 Expression ParseV8Intrinsic(bool* ok); |
| 573 | 585 |
| 574 Arguments ParseArguments(bool* ok); | 586 Arguments ParseArguments(bool* ok); |
| 575 Expression ParseFunctionLiteral(bool* ok); | 587 Expression ParseFunctionLiteral(bool is_generator, bool* ok); |
| 576 void ParseLazyFunctionLiteralBody(bool* ok); | 588 void ParseLazyFunctionLiteralBody(bool* ok); |
| 577 | 589 |
| 578 Identifier ParseIdentifier(bool* ok); | 590 Identifier ParseIdentifier(bool* ok); |
| 579 Identifier ParseIdentifierName(bool* ok); | 591 Identifier ParseIdentifierName(bool* ok); |
| 580 Identifier ParseIdentifierNameOrGetOrSet(bool* is_get, | 592 Identifier ParseIdentifierNameOrGetOrSet(bool* is_get, |
| 581 bool* is_set, | 593 bool* is_set, |
| 582 bool* ok); | 594 bool* ok); |
| 583 | 595 |
| 584 // Logs the currently parsed literal as a symbol in the preparser data. | 596 // Logs the currently parsed literal as a symbol in the preparser data. |
| 585 void LogSymbol(); | 597 void LogSymbol(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 663 bool stack_overflow_; | 675 bool stack_overflow_; |
| 664 bool allow_lazy_; | 676 bool allow_lazy_; |
| 665 bool allow_modules_; | 677 bool allow_modules_; |
| 666 bool allow_natives_syntax_; | 678 bool allow_natives_syntax_; |
| 667 bool parenthesized_function_; | 679 bool parenthesized_function_; |
| 668 bool harmony_scoping_; | 680 bool harmony_scoping_; |
| 669 }; | 681 }; |
| 670 } } // v8::preparser | 682 } } // v8::preparser |
| 671 | 683 |
| 672 #endif // V8_PREPARSER_H | 684 #endif // V8_PREPARSER_H |
| OLD | NEW |