Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(432)

Side by Side Diff: src/parser.h

Issue 148293011: Refactor scope and function state tracking in (Pre)Parser. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/parser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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
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 792
789 Zone* zone_; 793 Zone* zone_;
790 CompilationInfo* info_; 794 CompilationInfo* info_;
791 friend class BlockState;
792 friend class FunctionState;
793 }; 795 };
794 796
795 797
796 // Support for handling complex values (array and object literals) that 798 // Support for handling complex values (array and object literals) that
797 // can be fully handled at compile time. 799 // can be fully handled at compile time.
798 class CompileTimeValue: public AllStatic { 800 class CompileTimeValue: public AllStatic {
799 public: 801 public:
800 enum LiteralType { 802 enum LiteralType {
801 OBJECT_LITERAL_FAST_ELEMENTS, 803 OBJECT_LITERAL_FAST_ELEMENTS,
802 OBJECT_LITERAL_SLOW_ELEMENTS, 804 OBJECT_LITERAL_SLOW_ELEMENTS,
(...skipping 14 matching lines...) Expand all
817 private: 819 private:
818 static const int kLiteralTypeSlot = 0; 820 static const int kLiteralTypeSlot = 0;
819 static const int kElementsSlot = 1; 821 static const int kElementsSlot = 1;
820 822
821 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 823 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
822 }; 824 };
823 825
824 } } // namespace v8::internal 826 } } // namespace v8::internal
825 827
826 #endif // V8_PARSER_H_ 828 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « no previous file | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698