Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2011 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 |
| 11 // with the distribution. | 11 // with the distribution. |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 428 // Forward declaration. | 428 // Forward declaration. |
| 429 class SingletonLogger; | 429 class SingletonLogger; |
| 430 | 430 |
| 431 class Parser { | 431 class Parser { |
| 432 public: | 432 public: |
| 433 Parser(Handle<Script> script, | 433 Parser(Handle<Script> script, |
| 434 int parsing_flags, // Combination of ParsingFlags | 434 int parsing_flags, // Combination of ParsingFlags |
| 435 v8::Extension* extension, | 435 v8::Extension* extension, |
| 436 ScriptDataImpl* pre_data); | 436 ScriptDataImpl* pre_data); |
| 437 virtual ~Parser() { | 437 virtual ~Parser() { |
| 438 if (reusable_preparser_ != NULL) { | 438 delete reusable_preparser_; |
| 439 delete reusable_preparser_; | 439 reusable_preparser_ = NULL; |
| 440 } | 440 delete ast_node_factory_; |
| 441 ast_node_factory_ = NULL; | |
| 441 } | 442 } |
| 442 | 443 |
| 443 // Returns NULL if parsing failed. | 444 // Returns NULL if parsing failed. |
| 444 FunctionLiteral* ParseProgram(CompilationInfo* info); | 445 FunctionLiteral* ParseProgram(CompilationInfo* info); |
| 445 FunctionLiteral* ParseLazy(CompilationInfo* info); | 446 FunctionLiteral* ParseLazy(CompilationInfo* info); |
| 446 | 447 |
| 447 void ReportMessageAt(Scanner::Location loc, | 448 void ReportMessageAt(Scanner::Location loc, |
| 448 const char* message, | 449 const char* message, |
| 449 Vector<const char*> args); | 450 Vector<const char*> args); |
| 450 void ReportMessageAt(Scanner::Location loc, | 451 void ReportMessageAt(Scanner::Location loc, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 470 kForStatement | 471 kForStatement |
| 471 }; | 472 }; |
| 472 | 473 |
| 473 // If a list of variable declarations includes any initializers. | 474 // If a list of variable declarations includes any initializers. |
| 474 enum VariableDeclarationProperties { | 475 enum VariableDeclarationProperties { |
| 475 kHasInitializers, | 476 kHasInitializers, |
| 476 kHasNoInitializers | 477 kHasNoInitializers |
| 477 }; | 478 }; |
| 478 | 479 |
| 479 class BlockState; | 480 class BlockState; |
| 480 class FunctionState; | 481 |
| 482 class FunctionState BASE_EMBEDDED { | |
| 483 public: | |
| 484 FunctionState(Parser* parser, Scope* scope, Isolate* isolate); | |
| 485 ~FunctionState(); | |
| 486 | |
| 487 int NextMaterializedLiteralIndex() { | |
| 488 return next_materialized_literal_index_++; | |
| 489 } | |
| 490 int materialized_literal_count() { | |
| 491 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; | |
| 492 } | |
| 493 | |
| 494 int NextHandlerIndex() { return next_handler_index_++; } | |
| 495 int handler_count() { return next_handler_index_; } | |
| 496 | |
| 497 void SetThisPropertyAssignmentInfo( | |
| 498 bool only_simple_this_property_assignments, | |
| 499 Handle<FixedArray> this_property_assignments) { | |
| 500 only_simple_this_property_assignments_ = | |
| 501 only_simple_this_property_assignments; | |
| 502 this_property_assignments_ = this_property_assignments; | |
| 503 } | |
| 504 bool only_simple_this_property_assignments() { | |
| 505 return only_simple_this_property_assignments_; | |
| 506 } | |
| 507 Handle<FixedArray> this_property_assignments() { | |
| 508 return this_property_assignments_; | |
| 509 } | |
| 510 | |
| 511 void AddProperty() { expected_property_count_++; } | |
| 512 int expected_property_count() { return expected_property_count_; } | |
| 513 | |
| 514 private: | |
| 515 // Used to assign an index to each literal that needs materialization in | |
| 516 // the function. Includes regexp literals, and boilerplate for object and | |
| 517 // array literals. | |
| 518 int next_materialized_literal_index_; | |
| 519 | |
| 520 // Used to assign a per-function index to try and catch handlers. | |
| 521 int next_handler_index_; | |
| 522 | |
| 523 // Properties count estimation. | |
| 524 int expected_property_count_; | |
| 525 | |
| 526 // Keeps track of assignments to properties of this. Used for | |
| 527 // optimizing constructors. | |
| 528 bool only_simple_this_property_assignments_; | |
| 529 Handle<FixedArray> this_property_assignments_; | |
| 530 | |
| 531 Parser* parser_; | |
| 532 FunctionState* outer_function_state_; | |
| 533 Scope* outer_scope_; | |
| 534 unsigned saved_ast_node_id_; | |
| 535 }; | |
| 536 | |
| 537 | |
| 538 | |
| 481 | 539 |
| 482 FunctionLiteral* ParseLazy(CompilationInfo* info, | 540 FunctionLiteral* ParseLazy(CompilationInfo* info, |
| 483 UC16CharacterStream* source, | 541 UC16CharacterStream* source, |
| 484 ZoneScope* zone_scope); | 542 ZoneScope* zone_scope); |
| 485 | 543 |
| 486 Isolate* isolate() { return isolate_; } | 544 Isolate* isolate() { return isolate_; } |
| 487 Zone* zone() { return isolate_->zone(); } | 545 Zone* zone() { return isolate_->zone(); } |
| 488 | 546 |
| 489 // Called by ParseProgram after setting up the scanner. | 547 // Called by ParseProgram after setting up the scanner. |
| 490 FunctionLiteral* DoParseProgram(CompilationInfo* info, | 548 FunctionLiteral* DoParseProgram(CompilationInfo* info, |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 644 return isolate_->factory()->NewStringFromTwoByte( | 702 return isolate_->factory()->NewStringFromTwoByte( |
| 645 scanner().next_literal_uc16_string(), tenured); | 703 scanner().next_literal_uc16_string(), tenured); |
| 646 } | 704 } |
| 647 } | 705 } |
| 648 | 706 |
| 649 Handle<String> GetSymbol(bool* ok); | 707 Handle<String> GetSymbol(bool* ok); |
| 650 | 708 |
| 651 // Get odd-ball literals. | 709 // Get odd-ball literals. |
| 652 Literal* GetLiteralUndefined(); | 710 Literal* GetLiteralUndefined(); |
| 653 Literal* GetLiteralTheHole(); | 711 Literal* GetLiteralTheHole(); |
| 654 Literal* GetLiteralNumber(double value); | |
| 655 | 712 |
| 656 Handle<String> ParseIdentifier(bool* ok); | 713 Handle<String> ParseIdentifier(bool* ok); |
| 657 Handle<String> ParseIdentifierOrStrictReservedWord( | 714 Handle<String> ParseIdentifierOrStrictReservedWord( |
| 658 bool* is_strict_reserved, bool* ok); | 715 bool* is_strict_reserved, bool* ok); |
| 659 Handle<String> ParseIdentifierName(bool* ok); | 716 Handle<String> ParseIdentifierName(bool* ok); |
| 660 Handle<String> ParseIdentifierNameOrGetOrSet(bool* is_get, | 717 Handle<String> ParseIdentifierNameOrGetOrSet(bool* is_get, |
| 661 bool* is_set, | 718 bool* is_set, |
| 662 bool* ok); | 719 bool* ok); |
| 663 | 720 |
| 664 // Determine if the expression is a variable proxy and mark it as being used | 721 // Determine if the expression is a variable proxy and mark it as being used |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 692 bool* ok); | 749 bool* ok); |
| 693 | 750 |
| 694 bool TargetStackContainsLabel(Handle<String> label); | 751 bool TargetStackContainsLabel(Handle<String> label); |
| 695 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); | 752 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); |
| 696 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); | 753 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); |
| 697 | 754 |
| 698 void RegisterTargetUse(Label* target, Target* stop); | 755 void RegisterTargetUse(Label* target, Target* stop); |
| 699 | 756 |
| 700 // Factory methods. | 757 // Factory methods. |
| 701 | 758 |
| 702 Statement* EmptyStatement() { | |
| 703 static v8::internal::EmptyStatement* empty = | |
| 704 ::new v8::internal::EmptyStatement(); | |
| 705 return empty; | |
| 706 } | |
| 707 | |
| 708 Scope* NewScope(Scope* parent, ScopeType type); | 759 Scope* NewScope(Scope* parent, ScopeType type); |
| 709 | 760 |
| 710 Handle<String> LookupSymbol(int symbol_id); | 761 Handle<String> LookupSymbol(int symbol_id); |
| 711 | 762 |
| 712 Handle<String> LookupCachedSymbol(int symbol_id); | 763 Handle<String> LookupCachedSymbol(int symbol_id); |
| 713 | 764 |
| 714 Expression* NewCall(Expression* expression, | |
| 715 ZoneList<Expression*>* arguments, | |
| 716 int pos) { | |
| 717 return new(zone()) Call(isolate(), expression, arguments, pos); | |
| 718 } | |
| 719 | |
| 720 inline Literal* NewLiteral(Handle<Object> handle) { | |
| 721 return new(zone()) Literal(isolate(), handle); | |
| 722 } | |
| 723 | |
| 724 // Create a number literal. | |
| 725 Literal* NewNumberLiteral(double value); | |
| 726 | |
| 727 // Generate AST node that throw a ReferenceError with the given type. | 765 // Generate AST node that throw a ReferenceError with the given type. |
| 728 Expression* NewThrowReferenceError(Handle<String> type); | 766 Expression* NewThrowReferenceError(Handle<String> type); |
| 729 | 767 |
| 730 // Generate AST node that throw a SyntaxError with the given | 768 // Generate AST node that throw a SyntaxError with the given |
| 731 // type. The first argument may be null (in the handle sense) in | 769 // type. The first argument may be null (in the handle sense) in |
| 732 // which case no arguments are passed to the constructor. | 770 // which case no arguments are passed to the constructor. |
| 733 Expression* NewThrowSyntaxError(Handle<String> type, Handle<Object> first); | 771 Expression* NewThrowSyntaxError(Handle<String> type, Handle<Object> first); |
| 734 | 772 |
| 735 // Generate AST node that throw a TypeError with the given | 773 // Generate AST node that throw a TypeError with the given |
| 736 // type. Both arguments must be non-null (in the handle sense). | 774 // type. Both arguments must be non-null (in the handle sense). |
| 737 Expression* NewThrowTypeError(Handle<String> type, | 775 Expression* NewThrowTypeError(Handle<String> type, |
| 738 Handle<Object> first, | 776 Handle<Object> first, |
| 739 Handle<Object> second); | 777 Handle<Object> second); |
| 740 | 778 |
| 741 // Generic AST generator for throwing errors from compiled code. | 779 // Generic AST generator for throwing errors from compiled code. |
| 742 Expression* NewThrowError(Handle<String> constructor, | 780 Expression* NewThrowError(Handle<String> constructor, |
| 743 Handle<String> type, | 781 Handle<String> type, |
| 744 Vector< Handle<Object> > arguments); | 782 Vector< Handle<Object> > arguments); |
| 745 | 783 |
| 746 preparser::PreParser::PreParseResult LazyParseFunctionLiteral( | 784 preparser::PreParser::PreParseResult LazyParseFunctionLiteral( |
| 747 SingletonLogger* logger); | 785 SingletonLogger* logger); |
| 748 | 786 |
| 787 AstNodeFactory* factory() { return ast_node_factory_; } | |
| 788 | |
| 749 Isolate* isolate_; | 789 Isolate* isolate_; |
| 750 ZoneList<Handle<String> > symbol_cache_; | 790 ZoneList<Handle<String> > symbol_cache_; |
| 751 | 791 |
| 752 Handle<Script> script_; | 792 Handle<Script> script_; |
| 753 Scanner scanner_; | 793 Scanner scanner_; |
| 754 preparser::PreParser* reusable_preparser_; | 794 preparser::PreParser* reusable_preparser_; |
| 755 Scope* top_scope_; | 795 Scope* top_scope_; |
| 756 FunctionState* current_function_state_; | 796 FunctionState* current_function_state_; |
| 797 AstNodeFactory* ast_node_factory_; | |
|
fschneider
2012/01/30 12:10:35
Embedded instance
AstNodeFactory ast_node_factor
Jakob Kummerow
2012/02/01 14:46:09
Done.
| |
| 757 Target* target_stack_; // for break, continue statements | 798 Target* target_stack_; // for break, continue statements |
| 758 v8::Extension* extension_; | 799 v8::Extension* extension_; |
| 759 ScriptDataImpl* pre_data_; | 800 ScriptDataImpl* pre_data_; |
| 760 FuncNameInferrer* fni_; | 801 FuncNameInferrer* fni_; |
| 761 | 802 |
| 762 Mode mode_; | 803 Mode mode_; |
| 763 bool allow_natives_syntax_; | 804 bool allow_natives_syntax_; |
| 764 bool allow_lazy_; | 805 bool allow_lazy_; |
| 765 bool stack_overflow_; | 806 bool stack_overflow_; |
| 766 // If true, the next (and immediately following) function literal is | 807 // If true, the next (and immediately following) function literal is |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 800 private: | 841 private: |
| 801 static const int kTypeSlot = 0; | 842 static const int kTypeSlot = 0; |
| 802 static const int kElementsSlot = 1; | 843 static const int kElementsSlot = 1; |
| 803 | 844 |
| 804 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 845 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 805 }; | 846 }; |
| 806 | 847 |
| 807 } } // namespace v8::internal | 848 } } // namespace v8::internal |
| 808 | 849 |
| 809 #endif // V8_PARSER_H_ | 850 #endif // V8_PARSER_H_ |
| OLD | NEW |