| 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 12 matching lines...) Expand all Loading... |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_PARSER_H_ | 28 #ifndef V8_PARSER_H_ |
| 29 #define V8_PARSER_H_ | 29 #define V8_PARSER_H_ |
| 30 | 30 |
| 31 #include "allocation.h" | 31 #include "allocation.h" |
| 32 #include "ast.h" | 32 #include "ast.h" |
| 33 #include "lexer/experimental-scanner.h" | |
| 34 #include "preparse-data-format.h" | 33 #include "preparse-data-format.h" |
| 35 #include "preparse-data.h" | 34 #include "preparse-data.h" |
| 36 #include "scopes.h" | 35 #include "scopes.h" |
| 37 #include "preparser.h" | 36 #include "preparser.h" |
| 38 | 37 |
| 39 namespace v8 { | 38 namespace v8 { |
| 40 namespace internal { | 39 namespace internal { |
| 41 | 40 |
| 42 class CompilationInfo; | 41 class CompilationInfo; |
| 43 class FuncNameInferrer; | 42 class FuncNameInferrer; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 virtual const char* Data(); | 96 virtual const char* Data(); |
| 98 virtual bool HasError(); | 97 virtual bool HasError(); |
| 99 | 98 |
| 100 void Initialize(); | 99 void Initialize(); |
| 101 void ReadNextSymbolPosition(); | 100 void ReadNextSymbolPosition(); |
| 102 | 101 |
| 103 FunctionEntry GetFunctionEntry(int start); | 102 FunctionEntry GetFunctionEntry(int start); |
| 104 int GetSymbolIdentifier(); | 103 int GetSymbolIdentifier(); |
| 105 bool SanityCheck(); | 104 bool SanityCheck(); |
| 106 | 105 |
| 107 ScannerBase::Location MessageLocation(); | 106 Scanner::Location MessageLocation(); |
| 108 const char* BuildMessage(); | 107 const char* BuildMessage(); |
| 109 Vector<const char*> BuildArgs(); | 108 Vector<const char*> BuildArgs(); |
| 110 | 109 |
| 111 int symbol_count() { | 110 int symbol_count() { |
| 112 return (store_.length() > PreparseDataConstants::kHeaderSize) | 111 return (store_.length() > PreparseDataConstants::kHeaderSize) |
| 113 ? store_[PreparseDataConstants::kSymbolCountOffset] | 112 ? store_[PreparseDataConstants::kSymbolCountOffset] |
| 114 : 0; | 113 : 0; |
| 115 } | 114 } |
| 116 // The following functions should only be called if SanityCheck has | 115 // The following functions should only be called if SanityCheck has |
| 117 // returned true. | 116 // returned true. |
| (...skipping 29 matching lines...) Expand all Loading... |
| 147 | 146 |
| 148 | 147 |
| 149 class PreParserApi { | 148 class PreParserApi { |
| 150 public: | 149 public: |
| 151 // Pre-parse a character stream and return full preparse data. | 150 // Pre-parse a character stream and return full preparse data. |
| 152 // | 151 // |
| 153 // This interface is here instead of in preparser.h because it instantiates a | 152 // This interface is here instead of in preparser.h because it instantiates a |
| 154 // preparser recorder object that is suited to the parser's purposes. Also, | 153 // preparser recorder object that is suited to the parser's purposes. Also, |
| 155 // the preparser doesn't know about ScriptDataImpl. | 154 // the preparser doesn't know about ScriptDataImpl. |
| 156 static ScriptDataImpl* PreParse(Isolate* isolate, | 155 static ScriptDataImpl* PreParse(Isolate* isolate, |
| 157 Handle<String> source); | 156 Utf16CharacterStream* source); |
| 158 }; | 157 }; |
| 159 | 158 |
| 160 | 159 |
| 161 // ---------------------------------------------------------------------------- | 160 // ---------------------------------------------------------------------------- |
| 162 // REGEXP PARSING | 161 // REGEXP PARSING |
| 163 | 162 |
| 164 // A BufferedZoneList is an automatically growing list, just like (and backed | 163 // A BufferedZoneList is an automatically growing list, just like (and backed |
| 165 // by) a ZoneList, that is optimized for the case of adding and removing | 164 // by) a ZoneList, that is optimized for the case of adding and removing |
| 166 // a single element. The last element added is stored outside the backing list, | 165 // a single element. The last element added is stored outside the backing list, |
| 167 // and if no more than one element is ever added, the ZoneList isn't even | 166 // and if no more than one element is ever added, the ZoneList isn't even |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 398 bool multiline_; | 397 bool multiline_; |
| 399 bool simple_; | 398 bool simple_; |
| 400 bool contains_anchor_; | 399 bool contains_anchor_; |
| 401 bool is_scanned_for_captures_; | 400 bool is_scanned_for_captures_; |
| 402 bool failed_; | 401 bool failed_; |
| 403 }; | 402 }; |
| 404 | 403 |
| 405 // ---------------------------------------------------------------------------- | 404 // ---------------------------------------------------------------------------- |
| 406 // JAVASCRIPT PARSING | 405 // JAVASCRIPT PARSING |
| 407 | 406 |
| 408 // Forward declaration. | 407 class Parser; |
| 409 class SingletonLogger; | 408 class SingletonLogger; |
| 410 | 409 |
| 411 class Parser : public ParserBase { | 410 class ParserTraits { |
| 411 public: |
| 412 struct Type { |
| 413 typedef v8::internal::Parser* Parser; |
| 414 |
| 415 // Types used by FunctionState and BlockState. |
| 416 typedef v8::internal::Scope Scope; |
| 417 typedef AstNodeFactory<AstConstructionVisitor> Factory; |
| 418 typedef Variable GeneratorVariable; |
| 419 typedef v8::internal::Zone Zone; |
| 420 |
| 421 // Return types for traversing functions. |
| 422 typedef Handle<String> Identifier; |
| 423 typedef v8::internal::Expression* Expression; |
| 424 typedef ZoneList<v8::internal::Expression*>* ExpressionList; |
| 425 }; |
| 426 |
| 427 explicit ParserTraits(Parser* parser) : parser_(parser) {} |
| 428 |
| 429 // Custom operations executed when FunctionStates are created and destructed. |
| 430 template<typename FunctionState> |
| 431 static void SetUpFunctionState(FunctionState* function_state, Zone* zone) { |
| 432 Isolate* isolate = zone->isolate(); |
| 433 function_state->isolate_ = isolate; |
| 434 function_state->saved_ast_node_id_ = isolate->ast_node_id(); |
| 435 isolate->set_ast_node_id(BailoutId::FirstUsable().ToInt()); |
| 436 } |
| 437 |
| 438 template<typename FunctionState> |
| 439 static void TearDownFunctionState(FunctionState* function_state) { |
| 440 if (function_state->outer_function_state_ != NULL) { |
| 441 function_state->isolate_->set_ast_node_id( |
| 442 function_state->saved_ast_node_id_); |
| 443 } |
| 444 } |
| 445 |
| 446 // Helper functions for recursive descent. |
| 447 bool IsEvalOrArguments(Handle<String> identifier) const; |
| 448 |
| 449 // Reporting errors. |
| 450 void ReportMessageAt(Scanner::Location source_location, |
| 451 const char* message, |
| 452 Vector<const char*> args); |
| 453 void ReportMessage(const char* message, Vector<Handle<String> > args); |
| 454 void ReportMessageAt(Scanner::Location source_location, |
| 455 const char* message, |
| 456 Vector<Handle<String> > args); |
| 457 |
| 458 // "null" return type creators. |
| 459 static Handle<String> EmptyIdentifier() { |
| 460 return Handle<String>(); |
| 461 } |
| 462 static Expression* EmptyExpression() { |
| 463 return NULL; |
| 464 } |
| 465 |
| 466 // Odd-ball literal creators. |
| 467 Literal* GetLiteralTheHole(int position, |
| 468 AstNodeFactory<AstConstructionVisitor>* factory); |
| 469 |
| 470 // Producing data during the recursive descent. |
| 471 Handle<String> GetSymbol(Scanner* scanner = NULL); |
| 472 Handle<String> NextLiteralString(Scanner* scanner, |
| 473 PretenureFlag tenured); |
| 474 Expression* ThisExpression(Scope* scope, |
| 475 AstNodeFactory<AstConstructionVisitor>* factory); |
| 476 Expression* ExpressionFromLiteral( |
| 477 Token::Value token, int pos, Scanner* scanner, |
| 478 AstNodeFactory<AstConstructionVisitor>* factory); |
| 479 Expression* ExpressionFromIdentifier( |
| 480 Handle<String> name, int pos, Scope* scope, |
| 481 AstNodeFactory<AstConstructionVisitor>* factory); |
| 482 Expression* ExpressionFromString( |
| 483 int pos, Scanner* scanner, |
| 484 AstNodeFactory<AstConstructionVisitor>* factory); |
| 485 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { |
| 486 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); |
| 487 } |
| 488 |
| 489 // Temporary glue; these functions will move to ParserBase. |
| 490 Expression* ParseObjectLiteral(bool* ok); |
| 491 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok); |
| 492 Expression* ParseV8Intrinsic(bool* ok); |
| 493 |
| 494 private: |
| 495 Parser* parser_; |
| 496 }; |
| 497 |
| 498 |
| 499 class Parser : public ParserBase<ParserTraits> { |
| 412 public: | 500 public: |
| 413 explicit Parser(CompilationInfo* info); | 501 explicit Parser(CompilationInfo* info); |
| 414 ~Parser() { | 502 ~Parser() { |
| 415 delete reusable_preparser_; | 503 delete reusable_preparser_; |
| 416 reusable_preparser_ = NULL; | 504 reusable_preparser_ = NULL; |
| 417 delete scanner_; | |
| 418 scanner_ = NULL; | |
| 419 } | 505 } |
| 420 | 506 |
| 421 // Parses the source code represented by the compilation info and sets its | 507 // Parses the source code represented by the compilation info and sets its |
| 422 // function literal. Returns false (and deallocates any allocated AST | 508 // function literal. Returns false (and deallocates any allocated AST |
| 423 // nodes) if parsing failed. | 509 // nodes) if parsing failed. |
| 424 static bool Parse(CompilationInfo* info, | 510 static bool Parse(CompilationInfo* info, |
| 425 bool allow_lazy = false) { | 511 bool allow_lazy = false) { |
| 426 Parser parser(info); | 512 Parser parser(info); |
| 427 parser.set_allow_lazy(allow_lazy); | 513 parser.set_allow_lazy(allow_lazy); |
| 428 return parser.Parse(); | 514 return parser.Parse(); |
| 429 } | 515 } |
| 430 bool Parse(); | 516 bool Parse(); |
| 431 | 517 |
| 432 private: | 518 private: |
| 519 friend class ParserTraits; |
| 520 |
| 433 static const int kMaxNumFunctionLocals = 131071; // 2^17-1 | 521 static const int kMaxNumFunctionLocals = 131071; // 2^17-1 |
| 434 | 522 |
| 435 enum Mode { | 523 enum Mode { |
| 436 PARSE_LAZILY, | 524 PARSE_LAZILY, |
| 437 PARSE_EAGERLY | 525 PARSE_EAGERLY |
| 438 }; | 526 }; |
| 439 | 527 |
| 440 enum VariableDeclarationContext { | 528 enum VariableDeclarationContext { |
| 441 kModuleElement, | 529 kModuleElement, |
| 442 kBlockElement, | 530 kBlockElement, |
| 443 kStatement, | 531 kStatement, |
| 444 kForStatement | 532 kForStatement |
| 445 }; | 533 }; |
| 446 | 534 |
| 447 // If a list of variable declarations includes any initializers. | 535 // If a list of variable declarations includes any initializers. |
| 448 enum VariableDeclarationProperties { | 536 enum VariableDeclarationProperties { |
| 449 kHasInitializers, | 537 kHasInitializers, |
| 450 kHasNoInitializers | 538 kHasNoInitializers |
| 451 }; | 539 }; |
| 452 | 540 |
| 453 class BlockState; | |
| 454 | |
| 455 class FunctionState BASE_EMBEDDED { | |
| 456 public: | |
| 457 FunctionState(Parser* parser, | |
| 458 Scope* scope, | |
| 459 Isolate* isolate); | |
| 460 ~FunctionState(); | |
| 461 | |
| 462 int NextMaterializedLiteralIndex() { | |
| 463 return next_materialized_literal_index_++; | |
| 464 } | |
| 465 int materialized_literal_count() { | |
| 466 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; | |
| 467 } | |
| 468 | |
| 469 int NextHandlerIndex() { return next_handler_index_++; } | |
| 470 int handler_count() { return next_handler_index_; } | |
| 471 | |
| 472 void AddProperty() { expected_property_count_++; } | |
| 473 int expected_property_count() { return expected_property_count_; } | |
| 474 | |
| 475 void set_generator_object_variable(Variable *variable) { | |
| 476 ASSERT(variable != NULL); | |
| 477 ASSERT(!is_generator()); | |
| 478 generator_object_variable_ = variable; | |
| 479 } | |
| 480 Variable* generator_object_variable() const { | |
| 481 return generator_object_variable_; | |
| 482 } | |
| 483 bool is_generator() const { | |
| 484 return generator_object_variable_ != NULL; | |
| 485 } | |
| 486 | |
| 487 AstNodeFactory<AstConstructionVisitor>* factory() { return &factory_; } | |
| 488 | |
| 489 private: | |
| 490 // Used to assign an index to each literal that needs materialization in | |
| 491 // the function. Includes regexp literals, and boilerplate for object and | |
| 492 // array literals. | |
| 493 int next_materialized_literal_index_; | |
| 494 | |
| 495 // Used to assign a per-function index to try and catch handlers. | |
| 496 int next_handler_index_; | |
| 497 | |
| 498 // Properties count estimation. | |
| 499 int expected_property_count_; | |
| 500 | |
| 501 // For generators, the variable that holds the generator object. This | |
| 502 // variable is used by yield expressions and return statements. NULL | |
| 503 // indicates that this function is not a generator. | |
| 504 Variable* generator_object_variable_; | |
| 505 | |
| 506 Parser* parser_; | |
| 507 FunctionState* outer_function_state_; | |
| 508 Scope* outer_scope_; | |
| 509 int saved_ast_node_id_; | |
| 510 AstNodeFactory<AstConstructionVisitor> factory_; | |
| 511 }; | |
| 512 | |
| 513 class ParsingModeScope BASE_EMBEDDED { | 541 class ParsingModeScope BASE_EMBEDDED { |
| 514 public: | 542 public: |
| 515 ParsingModeScope(Parser* parser, Mode mode) | 543 ParsingModeScope(Parser* parser, Mode mode) |
| 516 : parser_(parser), | 544 : parser_(parser), |
| 517 old_mode_(parser->mode()) { | 545 old_mode_(parser->mode()) { |
| 518 parser_->mode_ = mode; | 546 parser_->mode_ = mode; |
| 519 } | 547 } |
| 520 ~ParsingModeScope() { | 548 ~ParsingModeScope() { |
| 521 parser_->mode_ = old_mode_; | 549 parser_->mode_ = old_mode_; |
| 522 } | 550 } |
| 523 | 551 |
| 524 private: | 552 private: |
| 525 Parser* parser_; | 553 Parser* parser_; |
| 526 Mode old_mode_; | 554 Mode old_mode_; |
| 527 }; | 555 }; |
| 528 | 556 |
| 529 // Returns NULL if parsing failed. | 557 // Returns NULL if parsing failed. |
| 530 FunctionLiteral* ParseProgram(); | 558 FunctionLiteral* ParseProgram(); |
| 531 | 559 |
| 532 FunctionLiteral* ParseLazy(); | 560 FunctionLiteral* ParseLazy(); |
| 533 FunctionLiteral* ParseLazy(Handle<String> source, int start, int end); | 561 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); |
| 534 | 562 |
| 535 Isolate* isolate() { return isolate_; } | 563 Isolate* isolate() { return isolate_; } |
| 536 Zone* zone() const { return zone_; } | |
| 537 CompilationInfo* info() const { return info_; } | 564 CompilationInfo* info() const { return info_; } |
| 538 | 565 |
| 539 // Called by ParseProgram after setting up the scanner. | 566 // Called by ParseProgram after setting up the scanner. |
| 540 FunctionLiteral* DoParseProgram(CompilationInfo* info, | 567 FunctionLiteral* DoParseProgram(CompilationInfo* info, |
| 541 Handle<String> source); | 568 Handle<String> source); |
| 542 | 569 |
| 543 // Report syntax error | 570 // Report syntax error |
| 544 void ReportUnexpectedToken(Token::Value token); | |
| 545 void ReportInvalidPreparseData(Handle<String> name, bool* ok); | 571 void ReportInvalidPreparseData(Handle<String> name, bool* ok); |
| 546 void ReportMessage(const char* message, Vector<const char*> args); | |
| 547 void ReportMessage(const char* message, Vector<Handle<String> > args); | |
| 548 void ReportMessageAt(ScannerBase::Location location, const char* type) { | |
| 549 ReportMessageAt(location, type, Vector<const char*>::empty()); | |
| 550 } | |
| 551 void ReportMessageAt(ScannerBase::Location loc, | |
| 552 const char* message, | |
| 553 Vector<const char*> args); | |
| 554 void ReportMessageAt(ScannerBase::Location loc, | |
| 555 const char* message, | |
| 556 Vector<Handle<String> > args); | |
| 557 | 572 |
| 558 void set_pre_parse_data(ScriptDataImpl *data) { | 573 void set_pre_parse_data(ScriptDataImpl *data) { |
| 559 pre_parse_data_ = data; | 574 pre_parse_data_ = data; |
| 560 symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone()); | 575 symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone()); |
| 561 } | 576 } |
| 562 | 577 |
| 563 bool inside_with() const { return top_scope_->inside_with(); } | 578 bool inside_with() const { return scope_->inside_with(); } |
| 564 ScannerBase& scanner() { return *scanner_; } | |
| 565 Mode mode() const { return mode_; } | 579 Mode mode() const { return mode_; } |
| 566 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } | 580 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } |
| 567 bool is_extended_mode() { | 581 bool is_extended_mode() { |
| 568 ASSERT(top_scope_ != NULL); | 582 ASSERT(scope_ != NULL); |
| 569 return top_scope_->is_extended_mode(); | 583 return scope_->is_extended_mode(); |
| 570 } | 584 } |
| 571 Scope* DeclarationScope(VariableMode mode) { | 585 Scope* DeclarationScope(VariableMode mode) { |
| 572 return IsLexicalVariableMode(mode) | 586 return IsLexicalVariableMode(mode) |
| 573 ? top_scope_ : top_scope_->DeclarationScope(); | 587 ? scope_ : scope_->DeclarationScope(); |
| 574 } | 588 } |
| 575 | 589 |
| 576 // Check if the given string is 'eval' or 'arguments'. | |
| 577 bool IsEvalOrArguments(Handle<String> string); | |
| 578 | |
| 579 // All ParseXXX functions take as the last argument an *ok parameter | 590 // All ParseXXX functions take as the last argument an *ok parameter |
| 580 // which is set to false if parsing failed; it is unchanged otherwise. | 591 // which is set to false if parsing failed; it is unchanged otherwise. |
| 581 // By making the 'exception handling' explicit, we are forced to check | 592 // By making the 'exception handling' explicit, we are forced to check |
| 582 // for failure at the call sites. | 593 // for failure at the call sites. |
| 583 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, | 594 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, |
| 584 bool is_eval, bool is_global, bool* ok); | 595 bool is_eval, bool is_global, bool* ok); |
| 585 Statement* ParseModuleElement(ZoneStringList* labels, bool* ok); | 596 Statement* ParseModuleElement(ZoneStringList* labels, bool* ok); |
| 586 Statement* ParseModuleDeclaration(ZoneStringList* names, bool* ok); | 597 Statement* ParseModuleDeclaration(ZoneStringList* names, bool* ok); |
| 587 Module* ParseModule(bool* ok); | 598 Module* ParseModule(bool* ok); |
| 588 Module* ParseModuleLiteral(bool* ok); | 599 Module* ParseModuleLiteral(bool* ok); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 618 WhileStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); | 629 WhileStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); |
| 619 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); | 630 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); |
| 620 Statement* ParseThrowStatement(bool* ok); | 631 Statement* ParseThrowStatement(bool* ok); |
| 621 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); | 632 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); |
| 622 TryStatement* ParseTryStatement(bool* ok); | 633 TryStatement* ParseTryStatement(bool* ok); |
| 623 DebuggerStatement* ParseDebuggerStatement(bool* ok); | 634 DebuggerStatement* ParseDebuggerStatement(bool* ok); |
| 624 | 635 |
| 625 // Support for hamony block scoped bindings. | 636 // Support for hamony block scoped bindings. |
| 626 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok); | 637 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok); |
| 627 | 638 |
| 628 Expression* ParseExpression(bool accept_IN, bool* ok); | |
| 629 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok); | 639 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok); |
| 630 Expression* ParseYieldExpression(bool* ok); | 640 Expression* ParseYieldExpression(bool* ok); |
| 631 Expression* ParseConditionalExpression(bool accept_IN, bool* ok); | 641 Expression* ParseConditionalExpression(bool accept_IN, bool* ok); |
| 632 Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 642 Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
| 633 Expression* ParseUnaryExpression(bool* ok); | 643 Expression* ParseUnaryExpression(bool* ok); |
| 634 Expression* ParsePostfixExpression(bool* ok); | 644 Expression* ParsePostfixExpression(bool* ok); |
| 635 Expression* ParseLeftHandSideExpression(bool* ok); | 645 Expression* ParseLeftHandSideExpression(bool* ok); |
| 636 Expression* ParseNewExpression(bool* ok); | 646 Expression* ParseMemberWithNewPrefixesExpression(bool* ok); |
| 637 Expression* ParseMemberExpression(bool* ok); | 647 Expression* ParseMemberExpression(bool* ok); |
| 638 Expression* ParseNewPrefix(PositionStack* stack, bool* ok); | 648 Expression* ParseMemberExpressionContinuation(Expression* expression, |
| 639 Expression* ParseMemberWithNewPrefixesExpression(PositionStack* stack, | 649 bool* ok); |
| 640 bool* ok); | |
| 641 Expression* ParsePrimaryExpression(bool* ok); | |
| 642 Expression* ParseArrayLiteral(bool* ok); | |
| 643 Expression* ParseObjectLiteral(bool* ok); | 650 Expression* ParseObjectLiteral(bool* ok); |
| 644 Expression* ParseRegExpLiteral(bool seen_equal, bool* ok); | |
| 645 | 651 |
| 646 // Initialize the components of a for-in / for-of statement. | 652 // Initialize the components of a for-in / for-of statement. |
| 647 void InitializeForEachStatement(ForEachStatement* stmt, | 653 void InitializeForEachStatement(ForEachStatement* stmt, |
| 648 Expression* each, | 654 Expression* each, |
| 649 Expression* subject, | 655 Expression* subject, |
| 650 Statement* body); | 656 Statement* body); |
| 651 | 657 |
| 652 ZoneList<Expression*>* ParseArguments(bool* ok); | 658 ZoneList<Expression*>* ParseArguments(bool* ok); |
| 653 FunctionLiteral* ParseFunctionLiteral(Handle<String> var_name, | 659 FunctionLiteral* ParseFunctionLiteral( |
| 654 bool name_is_reserved, | 660 Handle<String> name, |
| 655 bool is_generator, | 661 Scanner::Location function_name_location, |
| 656 int function_token_position, | 662 bool name_is_strict_reserved, |
| 657 FunctionLiteral::FunctionType type, | 663 bool is_generator, |
| 658 bool* ok); | 664 int function_token_position, |
| 659 | 665 FunctionLiteral::FunctionType type, |
| 666 bool* ok); |
| 660 | 667 |
| 661 // Magical syntax support. | 668 // Magical syntax support. |
| 662 Expression* ParseV8Intrinsic(bool* ok); | 669 Expression* ParseV8Intrinsic(bool* ok); |
| 663 | 670 |
| 664 bool is_generator() const { return current_function_state_->is_generator(); } | |
| 665 | |
| 666 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode); | 671 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode); |
| 667 | 672 |
| 668 Handle<String> LiteralString(PretenureFlag tenured) { | 673 Handle<String> LiteralString(PretenureFlag tenured) { |
| 669 return scanner().GetLiteralString(tenured); | 674 if (scanner()->is_literal_ascii()) { |
| 675 return isolate_->factory()->NewStringFromAscii( |
| 676 scanner()->literal_ascii_string(), tenured); |
| 677 } else { |
| 678 return isolate_->factory()->NewStringFromTwoByte( |
| 679 scanner()->literal_utf16_string(), tenured); |
| 680 } |
| 670 } | 681 } |
| 671 | 682 |
| 672 Handle<String> NextLiteralString(PretenureFlag tenured) { | |
| 673 return scanner().GetNextLiteralString(tenured); | |
| 674 } | |
| 675 | |
| 676 Handle<String> GetSymbol(); | |
| 677 | |
| 678 // Get odd-ball literals. | 683 // Get odd-ball literals. |
| 679 Literal* GetLiteralUndefined(int position); | 684 Literal* GetLiteralUndefined(int position); |
| 680 Literal* GetLiteralTheHole(int position); | |
| 681 | |
| 682 Handle<String> ParseIdentifier(bool* ok); | |
| 683 Handle<String> ParseIdentifierOrStrictReservedWord( | |
| 684 bool* is_strict_reserved, bool* ok); | |
| 685 Handle<String> ParseIdentifierName(bool* ok); | |
| 686 Handle<String> ParseIdentifierNameOrGetOrSet(bool* is_get, | |
| 687 bool* is_set, | |
| 688 bool* ok); | |
| 689 | 685 |
| 690 // Determine if the expression is a variable proxy and mark it as being used | 686 // Determine if the expression is a variable proxy and mark it as being used |
| 691 // in an assignment or with a increment/decrement operator. This is currently | 687 // in an assignment or with a increment/decrement operator. This is currently |
| 692 // used on for the statically checking assignments to harmony const bindings. | 688 // used on for the statically checking assignments to harmony const bindings. |
| 693 void MarkAsLValue(Expression* expression); | 689 void MarkAsLValue(Expression* expression); |
| 694 | 690 |
| 695 // Strict mode validation of LValue expressions | 691 // Strict mode validation of LValue expressions |
| 696 void CheckStrictModeLValue(Expression* expression, | 692 void CheckStrictModeLValue(Expression* expression, |
| 697 const char* error, | |
| 698 bool* ok); | 693 bool* ok); |
| 699 | 694 |
| 700 // For harmony block scoping mode: Check if the scope has conflicting var/let | 695 // For harmony block scoping mode: Check if the scope has conflicting var/let |
| 701 // declarations from different scopes. It covers for example | 696 // declarations from different scopes. It covers for example |
| 702 // | 697 // |
| 703 // function f() { { { var x; } let x; } } | 698 // function f() { { { var x; } let x; } } |
| 704 // function g() { { var x; let x; } } | 699 // function g() { { var x; let x; } } |
| 705 // | 700 // |
| 706 // The var declarations are hoisted to the function scope, but originate from | 701 // The var declarations are hoisted to the function scope, but originate from |
| 707 // a scope where the name has also been let bound or the var declaration is | 702 // a scope where the name has also been let bound or the var declaration is |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 Handle<Object> second); | 738 Handle<Object> second); |
| 744 | 739 |
| 745 // Generic AST generator for throwing errors from compiled code. | 740 // Generic AST generator for throwing errors from compiled code. |
| 746 Expression* NewThrowError(Handle<String> constructor, | 741 Expression* NewThrowError(Handle<String> constructor, |
| 747 Handle<String> type, | 742 Handle<String> type, |
| 748 Vector< Handle<Object> > arguments); | 743 Vector< Handle<Object> > arguments); |
| 749 | 744 |
| 750 PreParser::PreParseResult LazyParseFunctionLiteral( | 745 PreParser::PreParseResult LazyParseFunctionLiteral( |
| 751 SingletonLogger* logger); | 746 SingletonLogger* logger); |
| 752 | 747 |
| 753 AstNodeFactory<AstConstructionVisitor>* factory() { | |
| 754 return current_function_state_->factory(); | |
| 755 } | |
| 756 | |
| 757 void SetScannerFlags(); | |
| 758 | |
| 759 Isolate* isolate_; | 748 Isolate* isolate_; |
| 760 ZoneList<Handle<String> > symbol_cache_; | 749 ZoneList<Handle<String> > symbol_cache_; |
| 761 | 750 |
| 762 Handle<Script> script_; | 751 Handle<Script> script_; |
| 752 Scanner scanner_; |
| 763 PreParser* reusable_preparser_; | 753 PreParser* reusable_preparser_; |
| 764 Scope* top_scope_; | |
| 765 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 754 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
| 766 FunctionState* current_function_state_; | |
| 767 Target* target_stack_; // for break, continue statements | 755 Target* target_stack_; // for break, continue statements |
| 768 v8::Extension* extension_; | |
| 769 ScriptDataImpl* pre_parse_data_; | 756 ScriptDataImpl* pre_parse_data_; |
| 770 FuncNameInferrer* fni_; | 757 FuncNameInferrer* fni_; |
| 771 | 758 |
| 772 Mode mode_; | 759 Mode mode_; |
| 773 // If true, the next (and immediately following) function literal is | |
| 774 // preceded by a parenthesis. | |
| 775 // Heuristically that means that the function will be called immediately, | |
| 776 // so never lazily compile it. | |
| 777 bool parenthesized_function_; | |
| 778 | 760 |
| 779 Zone* zone_; | |
| 780 CompilationInfo* info_; | 761 CompilationInfo* info_; |
| 781 friend class BlockState; | |
| 782 friend class FunctionState; | |
| 783 }; | 762 }; |
| 784 | 763 |
| 785 | 764 |
| 786 // Support for handling complex values (array and object literals) that | 765 // Support for handling complex values (array and object literals) that |
| 787 // can be fully handled at compile time. | 766 // can be fully handled at compile time. |
| 788 class CompileTimeValue: public AllStatic { | 767 class CompileTimeValue: public AllStatic { |
| 789 public: | 768 public: |
| 790 enum LiteralType { | 769 enum LiteralType { |
| 791 OBJECT_LITERAL_FAST_ELEMENTS, | 770 OBJECT_LITERAL_FAST_ELEMENTS, |
| 792 OBJECT_LITERAL_SLOW_ELEMENTS, | 771 OBJECT_LITERAL_SLOW_ELEMENTS, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 807 private: | 786 private: |
| 808 static const int kLiteralTypeSlot = 0; | 787 static const int kLiteralTypeSlot = 0; |
| 809 static const int kElementsSlot = 1; | 788 static const int kElementsSlot = 1; |
| 810 | 789 |
| 811 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 790 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 812 }; | 791 }; |
| 813 | 792 |
| 814 } } // namespace v8::internal | 793 } } // namespace v8::internal |
| 815 | 794 |
| 816 #endif // V8_PARSER_H_ | 795 #endif // V8_PARSER_H_ |
| OLD | NEW |