| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 15 matching lines...) Expand all Loading... |
| 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 "preparse-data-format.h" | 33 #include "preparse-data-format.h" |
| 34 #include "preparse-data.h" | 34 #include "preparse-data.h" |
| 35 #include "scopes.h" | 35 #include "scopes.h" |
| 36 #include "preparser.h" |
| 36 | 37 |
| 37 namespace v8 { | 38 namespace v8 { |
| 38 namespace internal { | 39 namespace internal { |
| 39 | 40 |
| 40 class CompilationInfo; | 41 class CompilationInfo; |
| 41 class FuncNameInferrer; | 42 class FuncNameInferrer; |
| 42 class ParserLog; | 43 class ParserLog; |
| 43 class PositionStack; | 44 class PositionStack; |
| 44 class Target; | 45 class Target; |
| 45 class LexicalScope; | 46 class LexicalScope; |
| 47 class SaveScope; |
| 46 | 48 |
| 47 template <typename T> class ZoneListWrapper; | 49 template <typename T> class ZoneListWrapper; |
| 48 | 50 |
| 49 | 51 |
| 50 class ParserMessage : public Malloced { | 52 class ParserMessage : public Malloced { |
| 51 public: | 53 public: |
| 52 ParserMessage(Scanner::Location loc, const char* message, | 54 ParserMessage(Scanner::Location loc, const char* message, |
| 53 Vector<const char*> args) | 55 Vector<const char*> args) |
| 54 : loc_(loc), | 56 : loc_(loc), |
| 55 message_(message), | 57 message_(message), |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 class ParserApi { | 159 class ParserApi { |
| 158 public: | 160 public: |
| 159 // Parses the source code represented by the compilation info and sets its | 161 // Parses the source code represented by the compilation info and sets its |
| 160 // function literal. Returns false (and deallocates any allocated AST | 162 // function literal. Returns false (and deallocates any allocated AST |
| 161 // nodes) if parsing failed. | 163 // nodes) if parsing failed. |
| 162 static bool Parse(CompilationInfo* info); | 164 static bool Parse(CompilationInfo* info); |
| 163 | 165 |
| 164 // Generic preparser generating full preparse data. | 166 // Generic preparser generating full preparse data. |
| 165 static ScriptDataImpl* PreParse(UC16CharacterStream* source, | 167 static ScriptDataImpl* PreParse(UC16CharacterStream* source, |
| 166 v8::Extension* extension, | 168 v8::Extension* extension, |
| 167 bool harmony_scoping); | 169 int flags); |
| 168 | 170 |
| 169 // Preparser that only does preprocessing that makes sense if only used | 171 // Preparser that only does preprocessing that makes sense if only used |
| 170 // immediately after. | 172 // immediately after. |
| 171 static ScriptDataImpl* PartialPreParse(UC16CharacterStream* source, | 173 static ScriptDataImpl* PartialPreParse(UC16CharacterStream* source, |
| 172 v8::Extension* extension, | 174 v8::Extension* extension, |
| 173 bool harmony_scoping); | 175 int flags); |
| 174 }; | 176 }; |
| 175 | 177 |
| 176 // ---------------------------------------------------------------------------- | 178 // ---------------------------------------------------------------------------- |
| 177 // REGEXP PARSING | 179 // REGEXP PARSING |
| 178 | 180 |
| 179 // A BuffferedZoneList is an automatically growing list, just like (and backed | 181 // A BuffferedZoneList is an automatically growing list, just like (and backed |
| 180 // by) a ZoneList, that is optimized for the case of adding and removing | 182 // by) a ZoneList, that is optimized for the case of adding and removing |
| 181 // a single element. The last element added is stored outside the backing list, | 183 // a single element. The last element added is stored outside the backing list, |
| 182 // and if no more than one element is ever added, the ZoneList isn't even | 184 // and if no more than one element is ever added, the ZoneList isn't even |
| 183 // allocated. | 185 // allocated. |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 452 PARSE_LAZILY, | 454 PARSE_LAZILY, |
| 453 PARSE_EAGERLY | 455 PARSE_EAGERLY |
| 454 }; | 456 }; |
| 455 | 457 |
| 456 enum VariableDeclarationContext { | 458 enum VariableDeclarationContext { |
| 457 kSourceElement, | 459 kSourceElement, |
| 458 kStatement, | 460 kStatement, |
| 459 kForStatement | 461 kForStatement |
| 460 }; | 462 }; |
| 461 | 463 |
| 464 // If a list of variable declarations includes any initializers. |
| 465 enum VariableDeclarationProperties { |
| 466 kHasInitializers, |
| 467 kHasNoInitializers |
| 468 }; |
| 469 |
| 462 Isolate* isolate() { return isolate_; } | 470 Isolate* isolate() { return isolate_; } |
| 463 Zone* zone() { return isolate_->zone(); } | 471 Zone* zone() { return isolate_->zone(); } |
| 464 | 472 |
| 465 // Called by ParseProgram after setting up the scanner. | 473 // Called by ParseProgram after setting up the scanner. |
| 466 FunctionLiteral* DoParseProgram(Handle<String> source, | 474 FunctionLiteral* DoParseProgram(Handle<String> source, |
| 467 bool in_global_context, | 475 bool in_global_context, |
| 468 StrictModeFlag strict_mode, | 476 StrictModeFlag strict_mode, |
| 469 ZoneScope* zone_scope); | 477 ZoneScope* zone_scope); |
| 470 | 478 |
| 471 // Report syntax error | 479 // Report syntax error |
| 472 void ReportUnexpectedToken(Token::Value token); | 480 void ReportUnexpectedToken(Token::Value token); |
| 473 void ReportInvalidPreparseData(Handle<String> name, bool* ok); | 481 void ReportInvalidPreparseData(Handle<String> name, bool* ok); |
| 474 void ReportMessage(const char* message, Vector<const char*> args); | 482 void ReportMessage(const char* message, Vector<const char*> args); |
| 475 | 483 |
| 476 bool inside_with() const { return with_nesting_level_ > 0; } | 484 bool inside_with() const { return top_scope_->inside_with(); } |
| 477 JavaScriptScanner& scanner() { return scanner_; } | 485 JavaScriptScanner& scanner() { return scanner_; } |
| 478 Mode mode() const { return mode_; } | 486 Mode mode() const { return mode_; } |
| 479 ScriptDataImpl* pre_data() const { return pre_data_; } | 487 ScriptDataImpl* pre_data() const { return pre_data_; } |
| 480 | 488 |
| 481 // Check if the given string is 'eval' or 'arguments'. | 489 // Check if the given string is 'eval' or 'arguments'. |
| 482 bool IsEvalOrArguments(Handle<String> string); | 490 bool IsEvalOrArguments(Handle<String> string); |
| 483 | 491 |
| 484 // All ParseXXX functions take as the last argument an *ok parameter | 492 // All ParseXXX functions take as the last argument an *ok parameter |
| 485 // which is set to false if parsing failed; it is unchanged otherwise. | 493 // which is set to false if parsing failed; it is unchanged otherwise. |
| 486 // By making the 'exception handling' explicit, we are forced to check | 494 // By making the 'exception handling' explicit, we are forced to check |
| 487 // for failure at the call sites. | 495 // for failure at the call sites. |
| 488 void* ParseSourceElements(ZoneList<Statement*>* processor, | 496 void* ParseSourceElements(ZoneList<Statement*>* processor, |
| 489 int end_token, bool* ok); | 497 int end_token, bool* ok); |
| 490 Statement* ParseSourceElement(ZoneStringList* labels, bool* ok); | 498 Statement* ParseSourceElement(ZoneStringList* labels, bool* ok); |
| 491 Statement* ParseStatement(ZoneStringList* labels, bool* ok); | 499 Statement* ParseStatement(ZoneStringList* labels, bool* ok); |
| 492 Statement* ParseFunctionDeclaration(bool* ok); | 500 Statement* ParseFunctionDeclaration(bool* ok); |
| 493 Statement* ParseNativeDeclaration(bool* ok); | 501 Statement* ParseNativeDeclaration(bool* ok); |
| 494 Block* ParseBlock(ZoneStringList* labels, bool* ok); | 502 Block* ParseBlock(ZoneStringList* labels, bool* ok); |
| 495 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok); | |
| 496 Block* ParseVariableStatement(VariableDeclarationContext var_context, | 503 Block* ParseVariableStatement(VariableDeclarationContext var_context, |
| 497 bool* ok); | 504 bool* ok); |
| 498 Block* ParseVariableDeclarations(VariableDeclarationContext var_context, | 505 Block* ParseVariableDeclarations(VariableDeclarationContext var_context, |
| 506 VariableDeclarationProperties* decl_props, |
| 499 Handle<String>* out, | 507 Handle<String>* out, |
| 500 bool* ok); | 508 bool* ok); |
| 501 Statement* ParseExpressionOrLabelledStatement(ZoneStringList* labels, | 509 Statement* ParseExpressionOrLabelledStatement(ZoneStringList* labels, |
| 502 bool* ok); | 510 bool* ok); |
| 503 IfStatement* ParseIfStatement(ZoneStringList* labels, bool* ok); | 511 IfStatement* ParseIfStatement(ZoneStringList* labels, bool* ok); |
| 504 Statement* ParseContinueStatement(bool* ok); | 512 Statement* ParseContinueStatement(bool* ok); |
| 505 Statement* ParseBreakStatement(ZoneStringList* labels, bool* ok); | 513 Statement* ParseBreakStatement(ZoneStringList* labels, bool* ok); |
| 506 Statement* ParseReturnStatement(bool* ok); | 514 Statement* ParseReturnStatement(bool* ok); |
| 507 Statement* ParseWithStatement(ZoneStringList* labels, bool* ok); | 515 Statement* ParseWithStatement(ZoneStringList* labels, bool* ok); |
| 508 CaseClause* ParseCaseClause(bool* default_seen_ptr, bool* ok); | 516 CaseClause* ParseCaseClause(bool* default_seen_ptr, bool* ok); |
| 509 SwitchStatement* ParseSwitchStatement(ZoneStringList* labels, bool* ok); | 517 SwitchStatement* ParseSwitchStatement(ZoneStringList* labels, bool* ok); |
| 510 DoWhileStatement* ParseDoWhileStatement(ZoneStringList* labels, bool* ok); | 518 DoWhileStatement* ParseDoWhileStatement(ZoneStringList* labels, bool* ok); |
| 511 WhileStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); | 519 WhileStatement* ParseWhileStatement(ZoneStringList* labels, bool* ok); |
| 512 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); | 520 Statement* ParseForStatement(ZoneStringList* labels, bool* ok); |
| 513 Statement* ParseThrowStatement(bool* ok); | 521 Statement* ParseThrowStatement(bool* ok); |
| 514 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); | 522 Expression* MakeCatchContext(Handle<String> id, VariableProxy* value); |
| 515 TryStatement* ParseTryStatement(bool* ok); | 523 TryStatement* ParseTryStatement(bool* ok); |
| 516 DebuggerStatement* ParseDebuggerStatement(bool* ok); | 524 DebuggerStatement* ParseDebuggerStatement(bool* ok); |
| 517 | 525 |
| 526 // Support for hamony block scoped bindings. |
| 527 Block* ParseScopedBlock(ZoneStringList* labels, bool* ok); |
| 528 |
| 518 Expression* ParseExpression(bool accept_IN, bool* ok); | 529 Expression* ParseExpression(bool accept_IN, bool* ok); |
| 519 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok); | 530 Expression* ParseAssignmentExpression(bool accept_IN, bool* ok); |
| 520 Expression* ParseConditionalExpression(bool accept_IN, bool* ok); | 531 Expression* ParseConditionalExpression(bool accept_IN, bool* ok); |
| 521 Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok); | 532 Expression* ParseBinaryExpression(int prec, bool accept_IN, bool* ok); |
| 522 Expression* ParseUnaryExpression(bool* ok); | 533 Expression* ParseUnaryExpression(bool* ok); |
| 523 Expression* ParsePostfixExpression(bool* ok); | 534 Expression* ParsePostfixExpression(bool* ok); |
| 524 Expression* ParseLeftHandSideExpression(bool* ok); | 535 Expression* ParseLeftHandSideExpression(bool* ok); |
| 525 Expression* ParseNewExpression(bool* ok); | 536 Expression* ParseNewExpression(bool* ok); |
| 526 Expression* ParseMemberExpression(bool* ok); | 537 Expression* ParseMemberExpression(bool* ok); |
| 527 Expression* ParseNewPrefix(PositionStack* stack, bool* ok); | 538 Expression* ParseNewPrefix(PositionStack* stack, bool* ok); |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 662 | 673 |
| 663 void RegisterTargetUse(Label* target, Target* stop); | 674 void RegisterTargetUse(Label* target, Target* stop); |
| 664 | 675 |
| 665 // Factory methods. | 676 // Factory methods. |
| 666 | 677 |
| 667 Statement* EmptyStatement() { | 678 Statement* EmptyStatement() { |
| 668 static v8::internal::EmptyStatement empty; | 679 static v8::internal::EmptyStatement empty; |
| 669 return ∅ | 680 return ∅ |
| 670 } | 681 } |
| 671 | 682 |
| 672 Scope* NewScope(Scope* parent, Scope::Type type, bool inside_with); | 683 Scope* NewScope(Scope* parent, ScopeType type); |
| 673 | 684 |
| 674 Handle<String> LookupSymbol(int symbol_id); | 685 Handle<String> LookupSymbol(int symbol_id); |
| 675 | 686 |
| 676 Handle<String> LookupCachedSymbol(int symbol_id); | 687 Handle<String> LookupCachedSymbol(int symbol_id); |
| 677 | 688 |
| 678 Expression* NewCall(Expression* expression, | 689 Expression* NewCall(Expression* expression, |
| 679 ZoneList<Expression*>* arguments, | 690 ZoneList<Expression*>* arguments, |
| 680 int pos) { | 691 int pos) { |
| 681 return new(zone()) Call(isolate(), expression, arguments, pos); | 692 return new(zone()) Call(isolate(), expression, arguments, pos); |
| 682 } | 693 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 707 Handle<String> type, | 718 Handle<String> type, |
| 708 Vector< Handle<Object> > arguments); | 719 Vector< Handle<Object> > arguments); |
| 709 | 720 |
| 710 Isolate* isolate_; | 721 Isolate* isolate_; |
| 711 ZoneList<Handle<String> > symbol_cache_; | 722 ZoneList<Handle<String> > symbol_cache_; |
| 712 | 723 |
| 713 Handle<Script> script_; | 724 Handle<Script> script_; |
| 714 JavaScriptScanner scanner_; | 725 JavaScriptScanner scanner_; |
| 715 | 726 |
| 716 Scope* top_scope_; | 727 Scope* top_scope_; |
| 717 int with_nesting_level_; | |
| 718 | 728 |
| 719 LexicalScope* lexical_scope_; | 729 LexicalScope* lexical_scope_; |
| 720 Mode mode_; | 730 Mode mode_; |
| 721 | 731 |
| 722 Target* target_stack_; // for break, continue statements | 732 Target* target_stack_; // for break, continue statements |
| 723 bool allow_natives_syntax_; | 733 bool allow_natives_syntax_; |
| 724 v8::Extension* extension_; | 734 v8::Extension* extension_; |
| 725 bool is_pre_parsing_; | 735 bool is_pre_parsing_; |
| 726 ScriptDataImpl* pre_data_; | 736 ScriptDataImpl* pre_data_; |
| 727 FuncNameInferrer* fni_; | 737 FuncNameInferrer* fni_; |
| 728 bool stack_overflow_; | 738 bool stack_overflow_; |
| 729 // If true, the next (and immediately following) function literal is | 739 // If true, the next (and immediately following) function literal is |
| 730 // preceded by a parenthesis. | 740 // preceded by a parenthesis. |
| 731 // Heuristically that means that the function will be called immediately, | 741 // Heuristically that means that the function will be called immediately, |
| 732 // so never lazily compile it. | 742 // so never lazily compile it. |
| 733 bool parenthesized_function_; | 743 bool parenthesized_function_; |
| 734 bool harmony_scoping_; | 744 bool harmony_scoping_; |
| 735 | 745 |
| 736 friend class LexicalScope; | 746 friend class LexicalScope; |
| 747 friend class SaveScope; |
| 737 }; | 748 }; |
| 738 | 749 |
| 739 | 750 |
| 740 // Support for handling complex values (array and object literals) that | 751 // Support for handling complex values (array and object literals) that |
| 741 // can be fully handled at compile time. | 752 // can be fully handled at compile time. |
| 742 class CompileTimeValue: public AllStatic { | 753 class CompileTimeValue: public AllStatic { |
| 743 public: | 754 public: |
| 744 enum Type { | 755 enum Type { |
| 745 OBJECT_LITERAL_FAST_ELEMENTS, | 756 OBJECT_LITERAL_FAST_ELEMENTS, |
| 746 OBJECT_LITERAL_SLOW_ELEMENTS, | 757 OBJECT_LITERAL_SLOW_ELEMENTS, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 763 private: | 774 private: |
| 764 static const int kTypeSlot = 0; | 775 static const int kTypeSlot = 0; |
| 765 static const int kElementsSlot = 1; | 776 static const int kElementsSlot = 1; |
| 766 | 777 |
| 767 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 778 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 768 }; | 779 }; |
| 769 | 780 |
| 770 } } // namespace v8::internal | 781 } } // namespace v8::internal |
| 771 | 782 |
| 772 #endif // V8_PARSER_H_ | 783 #endif // V8_PARSER_H_ |
| OLD | NEW |