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 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
491 // If a list of variable declarations includes any initializers. | 491 // If a list of variable declarations includes any initializers. |
492 enum VariableDeclarationProperties { | 492 enum VariableDeclarationProperties { |
493 kHasInitializers, | 493 kHasInitializers, |
494 kHasNoInitializers | 494 kHasNoInitializers |
495 }; | 495 }; |
496 | 496 |
497 class BlockState; | 497 class BlockState; |
498 | 498 |
499 class FunctionState BASE_EMBEDDED { | 499 class FunctionState BASE_EMBEDDED { |
500 public: | 500 public: |
501 FunctionState(Parser* parser, Scope* scope); | 501 FunctionState(FunctionState** function_state_stack, |
| 502 Scope** scope_stack, Scope* scope, |
| 503 Zone* zone); |
502 ~FunctionState(); | 504 ~FunctionState(); |
503 | 505 |
504 int NextMaterializedLiteralIndex() { | 506 int NextMaterializedLiteralIndex() { |
505 return next_materialized_literal_index_++; | 507 return next_materialized_literal_index_++; |
506 } | 508 } |
507 int materialized_literal_count() { | 509 int materialized_literal_count() { |
508 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; | 510 return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; |
509 } | 511 } |
510 | 512 |
511 int NextHandlerIndex() { return next_handler_index_++; } | 513 int NextHandlerIndex() { return next_handler_index_++; } |
(...skipping 26 matching lines...) Expand all Loading... |
538 int next_handler_index_; | 540 int next_handler_index_; |
539 | 541 |
540 // Properties count estimation. | 542 // Properties count estimation. |
541 int expected_property_count_; | 543 int expected_property_count_; |
542 | 544 |
543 // For generators, the variable that holds the generator object. This | 545 // For generators, the variable that holds the generator object. This |
544 // variable is used by yield expressions and return statements. NULL | 546 // variable is used by yield expressions and return statements. NULL |
545 // indicates that this function is not a generator. | 547 // indicates that this function is not a generator. |
546 Variable* generator_object_variable_; | 548 Variable* generator_object_variable_; |
547 | 549 |
548 Parser* parser_; | 550 FunctionState** function_state_stack_; |
549 FunctionState* outer_function_state_; | 551 FunctionState* outer_function_state_; |
| 552 Scope** scope_stack_; |
550 Scope* outer_scope_; | 553 Scope* outer_scope_; |
| 554 Isolate* isolate_; |
551 int saved_ast_node_id_; | 555 int saved_ast_node_id_; |
552 AstNodeFactory<AstConstructionVisitor> factory_; | 556 AstNodeFactory<AstConstructionVisitor> factory_; |
553 }; | 557 }; |
554 | 558 |
555 class ParsingModeScope BASE_EMBEDDED { | 559 class ParsingModeScope BASE_EMBEDDED { |
556 public: | 560 public: |
557 ParsingModeScope(Parser* parser, Mode mode) | 561 ParsingModeScope(Parser* parser, Mode mode) |
558 : parser_(parser), | 562 : parser_(parser), |
559 old_mode_(parser->mode()) { | 563 old_mode_(parser->mode()) { |
560 parser_->mode_ = mode; | 564 parser_->mode_ = mode; |
(...skipping 22 matching lines...) Expand all Loading... |
583 Handle<String> source); | 587 Handle<String> source); |
584 | 588 |
585 // Report syntax error | 589 // Report syntax error |
586 void ReportInvalidPreparseData(Handle<String> name, bool* ok); | 590 void ReportInvalidPreparseData(Handle<String> name, bool* ok); |
587 | 591 |
588 void set_pre_parse_data(ScriptDataImpl *data) { | 592 void set_pre_parse_data(ScriptDataImpl *data) { |
589 pre_parse_data_ = data; | 593 pre_parse_data_ = data; |
590 symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone()); | 594 symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone()); |
591 } | 595 } |
592 | 596 |
593 bool inside_with() const { return top_scope_->inside_with(); } | 597 bool inside_with() const { return scope_->inside_with(); } |
594 Scanner& scanner() { return scanner_; } | 598 Scanner& scanner() { return scanner_; } |
595 Mode mode() const { return mode_; } | 599 Mode mode() const { return mode_; } |
596 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } | 600 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } |
597 bool is_extended_mode() { | 601 bool is_extended_mode() { |
598 ASSERT(top_scope_ != NULL); | 602 ASSERT(scope_ != NULL); |
599 return top_scope_->is_extended_mode(); | 603 return scope_->is_extended_mode(); |
600 } | 604 } |
601 Scope* DeclarationScope(VariableMode mode) { | 605 Scope* DeclarationScope(VariableMode mode) { |
602 return IsLexicalVariableMode(mode) | 606 return IsLexicalVariableMode(mode) |
603 ? top_scope_ : top_scope_->DeclarationScope(); | 607 ? scope_ : scope_->DeclarationScope(); |
604 } | 608 } |
605 | 609 |
606 // All ParseXXX functions take as the last argument an *ok parameter | 610 // All ParseXXX functions take as the last argument an *ok parameter |
607 // which is set to false if parsing failed; it is unchanged otherwise. | 611 // which is set to false if parsing failed; it is unchanged otherwise. |
608 // By making the 'exception handling' explicit, we are forced to check | 612 // By making the 'exception handling' explicit, we are forced to check |
609 // for failure at the call sites. | 613 // for failure at the call sites. |
610 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, | 614 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, |
611 bool is_eval, bool is_global, bool* ok); | 615 bool is_eval, bool is_global, bool* ok); |
612 Statement* ParseModuleElement(ZoneStringList* labels, bool* ok); | 616 Statement* ParseModuleElement(ZoneStringList* labels, bool* ok); |
613 Statement* ParseModuleDeclaration(ZoneStringList* names, bool* ok); | 617 Statement* ParseModuleDeclaration(ZoneStringList* names, bool* ok); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
760 | 764 |
761 // Generic AST generator for throwing errors from compiled code. | 765 // Generic AST generator for throwing errors from compiled code. |
762 Expression* NewThrowError(Handle<String> constructor, | 766 Expression* NewThrowError(Handle<String> constructor, |
763 Handle<String> type, | 767 Handle<String> type, |
764 Vector< Handle<Object> > arguments); | 768 Vector< Handle<Object> > arguments); |
765 | 769 |
766 PreParser::PreParseResult LazyParseFunctionLiteral( | 770 PreParser::PreParseResult LazyParseFunctionLiteral( |
767 SingletonLogger* logger); | 771 SingletonLogger* logger); |
768 | 772 |
769 AstNodeFactory<AstConstructionVisitor>* factory() { | 773 AstNodeFactory<AstConstructionVisitor>* factory() { |
770 return current_function_state_->factory(); | 774 return function_state_->factory(); |
771 } | 775 } |
772 | 776 |
773 Isolate* isolate_; | 777 Isolate* isolate_; |
774 ZoneList<Handle<String> > symbol_cache_; | 778 ZoneList<Handle<String> > symbol_cache_; |
775 | 779 |
776 Handle<Script> script_; | 780 Handle<Script> script_; |
777 Scanner scanner_; | 781 Scanner scanner_; |
778 PreParser* reusable_preparser_; | 782 PreParser* reusable_preparser_; |
779 Scope* top_scope_; | 783 Scope* scope_; // Scope stack. |
780 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 784 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
781 FunctionState* current_function_state_; | 785 FunctionState* function_state_; // Function state stack. |
782 Target* target_stack_; // for break, continue statements | 786 Target* target_stack_; // for break, continue statements |
783 v8::Extension* extension_; | 787 v8::Extension* extension_; |
784 ScriptDataImpl* pre_parse_data_; | 788 ScriptDataImpl* pre_parse_data_; |
785 FuncNameInferrer* fni_; | 789 FuncNameInferrer* fni_; |
786 | 790 |
787 Mode mode_; | 791 Mode mode_; |
788 // If true, the next (and immediately following) function literal is | 792 // If true, the next (and immediately following) function literal is |
789 // preceded by a parenthesis. | 793 // preceded by a parenthesis. |
790 // Heuristically that means that the function will be called immediately, | 794 // Heuristically that means that the function will be called immediately, |
791 // so never lazily compile it. | 795 // so never lazily compile it. |
792 bool parenthesized_function_; | 796 bool parenthesized_function_; |
793 | 797 |
794 Zone* zone_; | 798 Zone* zone_; |
795 CompilationInfo* info_; | 799 CompilationInfo* info_; |
796 friend class BlockState; | |
797 friend class FunctionState; | |
798 }; | 800 }; |
799 | 801 |
800 | 802 |
801 // Support for handling complex values (array and object literals) that | 803 // Support for handling complex values (array and object literals) that |
802 // can be fully handled at compile time. | 804 // can be fully handled at compile time. |
803 class CompileTimeValue: public AllStatic { | 805 class CompileTimeValue: public AllStatic { |
804 public: | 806 public: |
805 enum LiteralType { | 807 enum LiteralType { |
806 OBJECT_LITERAL_FAST_ELEMENTS, | 808 OBJECT_LITERAL_FAST_ELEMENTS, |
807 OBJECT_LITERAL_SLOW_ELEMENTS, | 809 OBJECT_LITERAL_SLOW_ELEMENTS, |
(...skipping 14 matching lines...) Expand all Loading... |
822 private: | 824 private: |
823 static const int kLiteralTypeSlot = 0; | 825 static const int kLiteralTypeSlot = 0; |
824 static const int kElementsSlot = 1; | 826 static const int kElementsSlot = 1; |
825 | 827 |
826 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 828 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
827 }; | 829 }; |
828 | 830 |
829 } } // namespace v8::internal | 831 } } // namespace v8::internal |
830 | 832 |
831 #endif // V8_PARSER_H_ | 833 #endif // V8_PARSER_H_ |
OLD | NEW |