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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 public: | 69 public: |
70 enum { | 70 enum { |
71 kStartPositionIndex, | 71 kStartPositionIndex, |
72 kEndPositionIndex, | 72 kEndPositionIndex, |
73 kLiteralCountIndex, | 73 kLiteralCountIndex, |
74 kPropertyCountIndex, | 74 kPropertyCountIndex, |
75 kLanguageModeIndex, | 75 kLanguageModeIndex, |
76 kSize | 76 kSize |
77 }; | 77 }; |
78 | 78 |
79 explicit FunctionEntry(Vector<unsigned> backing) : backing_(backing) { } | 79 explicit FunctionEntry(Vector<unsigned> backing) |
80 FunctionEntry() { } | 80 : backing_(backing) { } |
| 81 |
| 82 FunctionEntry() : backing_() { } |
81 | 83 |
82 int start_pos() { return backing_[kStartPositionIndex]; } | 84 int start_pos() { return backing_[kStartPositionIndex]; } |
83 int end_pos() { return backing_[kEndPositionIndex]; } | 85 int end_pos() { return backing_[kEndPositionIndex]; } |
84 int literal_count() { return backing_[kLiteralCountIndex]; } | 86 int literal_count() { return backing_[kLiteralCountIndex]; } |
85 int property_count() { return backing_[kPropertyCountIndex]; } | 87 int property_count() { return backing_[kPropertyCountIndex]; } |
86 LanguageMode language_mode() { | 88 LanguageMode language_mode() { |
87 ASSERT(backing_[kLanguageModeIndex] == CLASSIC_MODE || | 89 ASSERT(backing_[kLanguageModeIndex] == CLASSIC_MODE || |
88 backing_[kLanguageModeIndex] == STRICT_MODE || | 90 backing_[kLanguageModeIndex] == STRICT_MODE || |
89 backing_[kLanguageModeIndex] == EXTENDED_MODE); | 91 backing_[kLanguageModeIndex] == EXTENDED_MODE); |
90 return static_cast<LanguageMode>(backing_[kLanguageModeIndex]); | 92 return static_cast<LanguageMode>(backing_[kLanguageModeIndex]); |
91 } | 93 } |
92 | 94 |
93 bool is_valid() { return !backing_.is_empty(); } | 95 bool is_valid() { return !backing_.is_empty(); } |
94 | 96 |
95 private: | 97 private: |
96 Vector<unsigned> backing_; | 98 Vector<unsigned> backing_; |
| 99 bool owns_data_; |
97 }; | 100 }; |
98 | 101 |
99 | 102 |
100 class ScriptDataImpl : public ScriptData { | 103 class ScriptDataImpl : public ScriptData { |
101 public: | 104 public: |
102 explicit ScriptDataImpl(Vector<unsigned> store) | 105 explicit ScriptDataImpl(Vector<unsigned> store) |
103 : store_(store), | 106 : store_(store), |
104 owns_store_(true) { } | 107 owns_store_(true) { } |
105 | 108 |
106 // Create an empty ScriptDataImpl that is guaranteed to not satisfy | 109 // Create an empty ScriptDataImpl that is guaranteed to not satisfy |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 | 162 |
160 friend class ScriptData; | 163 friend class ScriptData; |
161 }; | 164 }; |
162 | 165 |
163 | 166 |
164 class ParserApi { | 167 class ParserApi { |
165 public: | 168 public: |
166 // Parses the source code represented by the compilation info and sets its | 169 // Parses the source code represented by the compilation info and sets its |
167 // function literal. Returns false (and deallocates any allocated AST | 170 // function literal. Returns false (and deallocates any allocated AST |
168 // nodes) if parsing failed. | 171 // nodes) if parsing failed. |
169 static bool Parse(CompilationInfo* info); | 172 static bool Parse(CompilationInfo* info, int flags); |
170 | 173 |
171 // Generic preparser generating full preparse data. | 174 // Generic preparser generating full preparse data. |
172 static ScriptDataImpl* PreParse(UC16CharacterStream* source, | 175 static ScriptDataImpl* PreParse(UC16CharacterStream* source, |
173 v8::Extension* extension, | 176 v8::Extension* extension, |
174 int flags); | 177 int flags); |
175 | 178 |
176 // Preparser that only does preprocessing that makes sense if only used | 179 // Preparser that only does preprocessing that makes sense if only used |
177 // immediately after. | 180 // immediately after. |
178 static ScriptDataImpl* PartialPreParse(UC16CharacterStream* source, | 181 static ScriptDataImpl* PartialPreParse(UC16CharacterStream* source, |
179 v8::Extension* extension, | 182 v8::Extension* extension, |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
415 bool multiline_; | 418 bool multiline_; |
416 bool simple_; | 419 bool simple_; |
417 bool contains_anchor_; | 420 bool contains_anchor_; |
418 bool is_scanned_for_captures_; | 421 bool is_scanned_for_captures_; |
419 bool failed_; | 422 bool failed_; |
420 }; | 423 }; |
421 | 424 |
422 // ---------------------------------------------------------------------------- | 425 // ---------------------------------------------------------------------------- |
423 // JAVASCRIPT PARSING | 426 // JAVASCRIPT PARSING |
424 | 427 |
| 428 // Forward declaration. |
| 429 class SingletonLogger; |
| 430 |
425 class Parser { | 431 class Parser { |
426 public: | 432 public: |
427 Parser(Handle<Script> script, | 433 Parser(Handle<Script> script, |
428 bool allow_natives_syntax, | 434 int parsing_flags, // Combination of ParsingFlags |
429 v8::Extension* extension, | 435 v8::Extension* extension, |
430 ScriptDataImpl* pre_data); | 436 ScriptDataImpl* pre_data); |
431 virtual ~Parser() { } | 437 virtual ~Parser() { |
| 438 if (reusable_preparser_ != NULL) { |
| 439 delete reusable_preparser_; |
| 440 } |
| 441 } |
432 | 442 |
433 // Returns NULL if parsing failed. | 443 // Returns NULL if parsing failed. |
434 FunctionLiteral* ParseProgram(CompilationInfo* info); | 444 FunctionLiteral* ParseProgram(CompilationInfo* info); |
435 FunctionLiteral* ParseLazy(CompilationInfo* info); | 445 FunctionLiteral* ParseLazy(CompilationInfo* info); |
436 | 446 |
437 void ReportMessageAt(Scanner::Location loc, | 447 void ReportMessageAt(Scanner::Location loc, |
438 const char* message, | 448 const char* message, |
439 Vector<const char*> args); | 449 Vector<const char*> args); |
440 void ReportMessageAt(Scanner::Location loc, | 450 void ReportMessageAt(Scanner::Location loc, |
441 const char* message, | 451 const char* message, |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 // type. Both arguments must be non-null (in the handle sense). | 731 // type. Both arguments must be non-null (in the handle sense). |
722 Expression* NewThrowTypeError(Handle<String> type, | 732 Expression* NewThrowTypeError(Handle<String> type, |
723 Handle<Object> first, | 733 Handle<Object> first, |
724 Handle<Object> second); | 734 Handle<Object> second); |
725 | 735 |
726 // Generic AST generator for throwing errors from compiled code. | 736 // Generic AST generator for throwing errors from compiled code. |
727 Expression* NewThrowError(Handle<String> constructor, | 737 Expression* NewThrowError(Handle<String> constructor, |
728 Handle<String> type, | 738 Handle<String> type, |
729 Vector< Handle<Object> > arguments); | 739 Vector< Handle<Object> > arguments); |
730 | 740 |
| 741 preparser::PreParser::PreParseResult LazyParseFunctionLiteral( |
| 742 SingletonLogger* logger); |
| 743 |
731 Isolate* isolate_; | 744 Isolate* isolate_; |
732 ZoneList<Handle<String> > symbol_cache_; | 745 ZoneList<Handle<String> > symbol_cache_; |
733 | 746 |
734 Handle<Script> script_; | 747 Handle<Script> script_; |
735 Scanner scanner_; | 748 Scanner scanner_; |
736 | 749 preparser::PreParser* reusable_preparser_; |
737 Scope* top_scope_; | 750 Scope* top_scope_; |
738 FunctionState* current_function_state_; | 751 FunctionState* current_function_state_; |
739 Target* target_stack_; // for break, continue statements | 752 Target* target_stack_; // for break, continue statements |
740 v8::Extension* extension_; | 753 v8::Extension* extension_; |
741 ScriptDataImpl* pre_data_; | 754 ScriptDataImpl* pre_data_; |
742 FuncNameInferrer* fni_; | 755 FuncNameInferrer* fni_; |
743 | 756 |
744 Mode mode_; | 757 Mode mode_; |
745 bool allow_natives_syntax_; | 758 bool allow_natives_syntax_; |
| 759 bool allow_lazy_; |
746 bool stack_overflow_; | 760 bool stack_overflow_; |
747 // If true, the next (and immediately following) function literal is | 761 // If true, the next (and immediately following) function literal is |
748 // preceded by a parenthesis. | 762 // preceded by a parenthesis. |
749 // Heuristically that means that the function will be called immediately, | 763 // Heuristically that means that the function will be called immediately, |
750 // so never lazily compile it. | 764 // so never lazily compile it. |
751 bool parenthesized_function_; | 765 bool parenthesized_function_; |
752 | 766 |
753 friend class BlockState; | 767 friend class BlockState; |
754 friend class FunctionState; | 768 friend class FunctionState; |
755 }; | 769 }; |
(...skipping 25 matching lines...) Expand all Loading... |
781 private: | 795 private: |
782 static const int kTypeSlot = 0; | 796 static const int kTypeSlot = 0; |
783 static const int kElementsSlot = 1; | 797 static const int kElementsSlot = 1; |
784 | 798 |
785 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 799 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
786 }; | 800 }; |
787 | 801 |
788 } } // namespace v8::internal | 802 } } // namespace v8::internal |
789 | 803 |
790 #endif // V8_PARSER_H_ | 804 #endif // V8_PARSER_H_ |
OLD | NEW |