| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 13 matching lines...) Expand all Loading... |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 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 "scanner.h" | 33 #include "scanner.h" |
| 34 #include "scopes.h" |
| 34 | 35 |
| 35 namespace v8 { | 36 namespace v8 { |
| 36 namespace internal { | 37 namespace internal { |
| 37 | 38 |
| 38 class CompilationInfo; | 39 class CompilationInfo; |
| 39 class FuncNameInferrer; | 40 class FuncNameInferrer; |
| 40 class ParserFactory; | |
| 41 class ParserLog; | 41 class ParserLog; |
| 42 class PositionStack; | 42 class PositionStack; |
| 43 class Target; | 43 class Target; |
| 44 class TemporaryScope; | 44 class TemporaryScope; |
| 45 | 45 |
| 46 template <typename T> class ZoneListWrapper; | 46 template <typename T> class ZoneListWrapper; |
| 47 | 47 |
| 48 | 48 |
| 49 class ParserMessage : public Malloced { | 49 class ParserMessage : public Malloced { |
| 50 public: | 50 public: |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 reinterpret_cast<intptr_t>(backing_store) % sizeof(unsigned))); | 170 reinterpret_cast<intptr_t>(backing_store) % sizeof(unsigned))); |
| 171 } | 171 } |
| 172 | 172 |
| 173 // Read strings written by ParserRecorder::WriteString. | 173 // Read strings written by ParserRecorder::WriteString. |
| 174 static const char* ReadString(unsigned* start, int* chars); | 174 static const char* ReadString(unsigned* start, int* chars); |
| 175 | 175 |
| 176 friend class ScriptData; | 176 friend class ScriptData; |
| 177 }; | 177 }; |
| 178 | 178 |
| 179 | 179 |
| 180 class ParserLog BASE_EMBEDDED { | |
| 181 public: | |
| 182 virtual ~ParserLog() { } | |
| 183 | |
| 184 // Records the occurrence of a function. | |
| 185 virtual void LogFunction(int start, int end, int literals, int properties) {} | |
| 186 // Records the occurrence of a symbol in the source. The vector holds the | |
| 187 // UTF-8 encoded symbol content. | |
| 188 virtual void LogSymbol(int start, Vector<const char> symbol) {} | |
| 189 // Records the occurrence of a symbol in the source. The symbol pointer | |
| 190 // points to the UTF-8 encoded symbol content. | |
| 191 virtual void LogSymbol(int start, const char* symbol, int length) {} | |
| 192 // Return the current position in the function entry log. | |
| 193 virtual int function_position() { return 0; } | |
| 194 // Return the current position in the symbol entry log. | |
| 195 // Notice: Functions and symbols are currently logged separately. | |
| 196 virtual int symbol_position() { return 0; } | |
| 197 // Return the number of distinct symbols logged. | |
| 198 virtual int symbol_ids() { return 0; } | |
| 199 // Pauses recording. The Log-functions above will do nothing during pausing. | |
| 200 // Pauses can be nested. | |
| 201 virtual void PauseRecording() {} | |
| 202 // Ends a recording pause. | |
| 203 virtual void ResumeRecording() {} | |
| 204 // Extracts a representation of the logged data that can be used by | |
| 205 // ScriptData. | |
| 206 virtual Vector<unsigned> ExtractData() { | |
| 207 return Vector<unsigned>(); | |
| 208 }; | |
| 209 }; | |
| 210 | |
| 211 | |
| 212 // Record only functions. | 180 // Record only functions. |
| 213 class PartialParserRecorder: public ParserLog { | 181 class PartialParserRecorder { |
| 214 public: | 182 public: |
| 215 PartialParserRecorder(); | 183 PartialParserRecorder(); |
| 216 | 184 |
| 217 virtual void LogFunction(int start, int end, int literals, int properties) { | 185 void LogFunction(int start, int end, int literals, int properties) { |
| 218 function_store_.Add(start); | 186 function_store_.Add(start); |
| 219 function_store_.Add(end); | 187 function_store_.Add(end); |
| 220 function_store_.Add(literals); | 188 function_store_.Add(literals); |
| 221 function_store_.Add(properties); | 189 function_store_.Add(properties); |
| 222 } | 190 } |
| 223 | 191 |
| 192 void LogSymbol(int start, const char* symbol, int length) { } |
| 193 |
| 224 // Logs an error message and marks the log as containing an error. | 194 // Logs an error message and marks the log as containing an error. |
| 225 // Further logging will be ignored, and ExtractData will return a vector | 195 // Further logging will be ignored, and ExtractData will return a vector |
| 226 // representing the error only. | 196 // representing the error only. |
| 227 void LogMessage(int start, | 197 void LogMessage(int start, |
| 228 int end, | 198 int end, |
| 229 const char* message, | 199 const char* message, |
| 230 const char* argument_opt) { | 200 const char* argument_opt) { |
| 231 Scanner::Location location(start, end); | 201 Scanner::Location location(start, end); |
| 232 Vector<const char*> arguments; | 202 Vector<const char*> arguments; |
| 233 if (argument_opt != NULL) { | 203 if (argument_opt != NULL) { |
| 234 arguments = Vector<const char*>(&argument_opt, 1); | 204 arguments = Vector<const char*>(&argument_opt, 1); |
| 235 } | 205 } |
| 236 this->LogMessage(location, message, arguments); | 206 this->LogMessage(location, message, arguments); |
| 237 } | 207 } |
| 238 | 208 |
| 239 virtual int function_position() { return function_store_.size(); } | 209 int function_position() { return function_store_.size(); } |
| 240 | 210 |
| 241 virtual void LogMessage(Scanner::Location loc, | 211 void LogMessage(Scanner::Location loc, |
| 242 const char* message, | 212 const char* message, |
| 243 Vector<const char*> args); | 213 Vector<const char*> args); |
| 244 | 214 |
| 245 virtual Vector<unsigned> ExtractData(); | 215 Vector<unsigned> ExtractData(); |
| 246 | 216 |
| 247 virtual void PauseRecording() { | 217 void PauseRecording() { |
| 248 pause_count_++; | 218 pause_count_++; |
| 249 is_recording_ = false; | 219 is_recording_ = false; |
| 250 } | 220 } |
| 251 | 221 |
| 252 virtual void ResumeRecording() { | 222 void ResumeRecording() { |
| 253 ASSERT(pause_count_ > 0); | 223 ASSERT(pause_count_ > 0); |
| 254 if (--pause_count_ == 0) is_recording_ = !has_error(); | 224 if (--pause_count_ == 0) is_recording_ = !has_error(); |
| 255 } | 225 } |
| 256 | 226 |
| 227 int symbol_position() { return 0; } |
| 228 int symbol_ids() { return 0; } |
| 229 |
| 257 protected: | 230 protected: |
| 258 bool has_error() { | 231 bool has_error() { |
| 259 return static_cast<bool>(preamble_[ScriptDataImpl::kHasErrorOffset]); | 232 return static_cast<bool>(preamble_[ScriptDataImpl::kHasErrorOffset]); |
| 260 } | 233 } |
| 261 | 234 |
| 262 bool is_recording() { | 235 bool is_recording() { |
| 263 return is_recording_; | 236 return is_recording_; |
| 264 } | 237 } |
| 265 | 238 |
| 266 void WriteString(Vector<const char> str); | 239 void WriteString(Vector<const char> str); |
| 267 | 240 |
| 268 Collector<unsigned> function_store_; | 241 Collector<unsigned> function_store_; |
| 269 unsigned preamble_[ScriptDataImpl::kHeaderSize]; | 242 unsigned preamble_[ScriptDataImpl::kHeaderSize]; |
| 270 bool is_recording_; | 243 bool is_recording_; |
| 271 int pause_count_; | 244 int pause_count_; |
| 272 | 245 |
| 273 #ifdef DEBUG | 246 #ifdef DEBUG |
| 274 int prev_start_; | 247 int prev_start_; |
| 275 #endif | 248 #endif |
| 276 }; | 249 }; |
| 277 | 250 |
| 278 | 251 |
| 279 // Record both functions and symbols. | 252 // Record both functions and symbols. |
| 280 class CompleteParserRecorder: public PartialParserRecorder { | 253 class CompleteParserRecorder: public PartialParserRecorder { |
| 281 public: | 254 public: |
| 282 CompleteParserRecorder(); | 255 CompleteParserRecorder(); |
| 283 | 256 |
| 284 virtual void LogSymbol(int start, Vector<const char> literal); | 257 void LogSymbol(int start, Vector<const char> literal); |
| 285 | 258 |
| 286 virtual void LogSymbol(int start, const char* symbol, int length) { | 259 void LogSymbol(int start, const char* symbol, int length) { |
| 287 LogSymbol(start, Vector<const char>(symbol, length)); | 260 LogSymbol(start, Vector<const char>(symbol, length)); |
| 288 } | 261 } |
| 289 | 262 |
| 290 virtual Vector<unsigned> ExtractData(); | 263 Vector<unsigned> ExtractData(); |
| 291 | 264 |
| 292 virtual int symbol_position() { return symbol_store_.size(); } | 265 int symbol_position() { return symbol_store_.size(); } |
| 293 virtual int symbol_ids() { return symbol_id_; } | 266 int symbol_ids() { return symbol_id_; } |
| 294 | 267 |
| 295 private: | 268 private: |
| 296 static int vector_hash(Vector<const char> string) { | 269 static int vector_hash(Vector<const char> string) { |
| 297 int hash = 0; | 270 int hash = 0; |
| 298 for (int i = 0; i < string.length(); i++) { | 271 for (int i = 0; i < string.length(); i++) { |
| 299 int c = string[i]; | 272 int c = string[i]; |
| 300 hash += c; | 273 hash += c; |
| 301 hash += (hash << 10); | 274 hash += (hash << 10); |
| 302 hash ^= (hash >> 6); | 275 hash ^= (hash >> 6); |
| 303 } | 276 } |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 unibrow::CharacterStream* stream, | 308 unibrow::CharacterStream* stream, |
| 336 v8::Extension* extension); | 309 v8::Extension* extension); |
| 337 | 310 |
| 338 // Preparser that only does preprocessing that makes sense if only used | 311 // Preparser that only does preprocessing that makes sense if only used |
| 339 // immediately after. | 312 // immediately after. |
| 340 static ScriptDataImpl* PartialPreParse(Handle<String> source, | 313 static ScriptDataImpl* PartialPreParse(Handle<String> source, |
| 341 unibrow::CharacterStream* stream, | 314 unibrow::CharacterStream* stream, |
| 342 v8::Extension* extension); | 315 v8::Extension* extension); |
| 343 }; | 316 }; |
| 344 | 317 |
| 318 // ---------------------------------------------------------------------------- |
| 319 // REGEXP PARSING |
| 345 | 320 |
| 346 // A BuffferedZoneList is an automatically growing list, just like (and backed | 321 // A BuffferedZoneList is an automatically growing list, just like (and backed |
| 347 // by) a ZoneList, that is optimized for the case of adding and removing | 322 // by) a ZoneList, that is optimized for the case of adding and removing |
| 348 // a single element. The last element added is stored outside the backing list, | 323 // a single element. The last element added is stored outside the backing list, |
| 349 // and if no more than one element is ever added, the ZoneList isn't even | 324 // and if no more than one element is ever added, the ZoneList isn't even |
| 350 // allocated. | 325 // allocated. |
| 351 // Elements must not be NULL pointers. | 326 // Elements must not be NULL pointers. |
| 352 template <typename T, int initial_size> | 327 template <typename T, int initial_size> |
| 353 class BufferedZoneList { | 328 class BufferedZoneList { |
| 354 public: | 329 public: |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 550 // Stored disjunction's capture index (if any). | 525 // Stored disjunction's capture index (if any). |
| 551 int disjunction_capture_index_; | 526 int disjunction_capture_index_; |
| 552 }; | 527 }; |
| 553 | 528 |
| 554 uc32 current() { return current_; } | 529 uc32 current() { return current_; } |
| 555 bool has_more() { return has_more_; } | 530 bool has_more() { return has_more_; } |
| 556 bool has_next() { return next_pos_ < in()->length(); } | 531 bool has_next() { return next_pos_ < in()->length(); } |
| 557 uc32 Next(); | 532 uc32 Next(); |
| 558 FlatStringReader* in() { return in_; } | 533 FlatStringReader* in() { return in_; } |
| 559 void ScanForCaptures(); | 534 void ScanForCaptures(); |
| 535 |
| 536 Handle<String>* error_; |
| 537 ZoneList<RegExpCapture*>* captures_; |
| 538 FlatStringReader* in_; |
| 560 uc32 current_; | 539 uc32 current_; |
| 540 int next_pos_; |
| 541 // The capture count is only valid after we have scanned for captures. |
| 542 int capture_count_; |
| 561 bool has_more_; | 543 bool has_more_; |
| 562 bool multiline_; | 544 bool multiline_; |
| 563 int next_pos_; | |
| 564 FlatStringReader* in_; | |
| 565 Handle<String>* error_; | |
| 566 bool simple_; | 545 bool simple_; |
| 567 bool contains_anchor_; | 546 bool contains_anchor_; |
| 568 ZoneList<RegExpCapture*>* captures_; | |
| 569 bool is_scanned_for_captures_; | 547 bool is_scanned_for_captures_; |
| 570 // The capture count is only valid after we have scanned for captures. | |
| 571 int capture_count_; | |
| 572 bool failed_; | 548 bool failed_; |
| 573 }; | 549 }; |
| 574 | 550 |
| 551 // ---------------------------------------------------------------------------- |
| 552 // JAVASCRIPT PARSING |
| 575 | 553 |
| 576 class Parser { | 554 class Parser { |
| 577 public: | 555 public: |
| 578 Parser(Handle<Script> script, bool allow_natives_syntax, | 556 Parser(Handle<Script> script, |
| 579 v8::Extension* extension, ParserMode is_pre_parsing, | 557 bool allow_natives_syntax, |
| 580 ParserFactory* factory, ParserLog* log, ScriptDataImpl* pre_data); | 558 v8::Extension* extension, |
| 559 ScriptDataImpl* pre_data); |
| 581 virtual ~Parser() { } | 560 virtual ~Parser() { } |
| 582 | 561 |
| 583 void ReportMessage(const char* message, Vector<const char*> args); | |
| 584 virtual void ReportMessageAt(Scanner::Location loc, | |
| 585 const char* message, | |
| 586 Vector<const char*> args) = 0; | |
| 587 | |
| 588 | |
| 589 // Returns NULL if parsing failed. | 562 // Returns NULL if parsing failed. |
| 590 FunctionLiteral* ParseProgram(Handle<String> source, | 563 FunctionLiteral* ParseProgram(Handle<String> source, |
| 591 bool in_global_context); | 564 bool in_global_context); |
| 565 |
| 592 FunctionLiteral* ParseLazy(Handle<SharedFunctionInfo> info); | 566 FunctionLiteral* ParseLazy(Handle<SharedFunctionInfo> info); |
| 593 | 567 |
| 594 // The minimum number of contiguous assignment that will | 568 void ReportMessageAt(Scanner::Location loc, |
| 595 // be treated as an initialization block. Benchmarks show that | 569 const char* message, |
| 596 // the overhead exceeds the savings below this limit. | 570 Vector<const char*> args); |
| 597 static const int kMinInitializationBlock = 3; | |
| 598 | 571 |
| 599 protected: | 572 protected: |
| 600 | |
| 601 enum Mode { | 573 enum Mode { |
| 602 PARSE_LAZILY, | 574 PARSE_LAZILY, |
| 603 PARSE_EAGERLY | 575 PARSE_EAGERLY |
| 604 }; | 576 }; |
| 605 | 577 |
| 606 // Report syntax error | 578 // Report syntax error |
| 607 void ReportUnexpectedToken(Token::Value token); | 579 void ReportUnexpectedToken(Token::Value token); |
| 608 void ReportInvalidPreparseData(Handle<String> name, bool* ok); | 580 void ReportInvalidPreparseData(Handle<String> name, bool* ok); |
| 609 | 581 void ReportMessage(const char* message, Vector<const char*> args); |
| 610 Handle<Script> script_; | |
| 611 Scanner scanner_; | |
| 612 | |
| 613 Scope* top_scope_; | |
| 614 int with_nesting_level_; | |
| 615 | |
| 616 TemporaryScope* temp_scope_; | |
| 617 Mode mode_; | |
| 618 | |
| 619 Target* target_stack_; // for break, continue statements | |
| 620 bool allow_natives_syntax_; | |
| 621 v8::Extension* extension_; | |
| 622 ParserFactory* factory_; | |
| 623 ParserLog* log_; | |
| 624 bool is_pre_parsing_; | |
| 625 ScriptDataImpl* pre_data_; | |
| 626 FuncNameInferrer* fni_; | |
| 627 | 582 |
| 628 bool inside_with() const { return with_nesting_level_ > 0; } | 583 bool inside_with() const { return with_nesting_level_ > 0; } |
| 629 ParserFactory* factory() const { return factory_; } | |
| 630 ParserLog* log() const { return log_; } | |
| 631 Scanner& scanner() { return scanner_; } | 584 Scanner& scanner() { return scanner_; } |
| 632 Mode mode() const { return mode_; } | 585 Mode mode() const { return mode_; } |
| 633 ScriptDataImpl* pre_data() const { return pre_data_; } | 586 ScriptDataImpl* pre_data() const { return pre_data_; } |
| 634 | 587 |
| 635 // All ParseXXX functions take as the last argument an *ok parameter | 588 // All ParseXXX functions take as the last argument an *ok parameter |
| 636 // which is set to false if parsing failed; it is unchanged otherwise. | 589 // which is set to false if parsing failed; it is unchanged otherwise. |
| 637 // By making the 'exception handling' explicit, we are forced to check | 590 // By making the 'exception handling' explicit, we are forced to check |
| 638 // for failure at the call sites. | 591 // for failure at the call sites. |
| 639 void* ParseSourceElements(ZoneListWrapper<Statement>* processor, | 592 void* ParseSourceElements(ZoneList<Statement*>* processor, |
| 640 int end_token, bool* ok); | 593 int end_token, bool* ok); |
| 641 Statement* ParseStatement(ZoneStringList* labels, bool* ok); | 594 Statement* ParseStatement(ZoneStringList* labels, bool* ok); |
| 642 Statement* ParseFunctionDeclaration(bool* ok); | 595 Statement* ParseFunctionDeclaration(bool* ok); |
| 643 Statement* ParseNativeDeclaration(bool* ok); | 596 Statement* ParseNativeDeclaration(bool* ok); |
| 644 Block* ParseBlock(ZoneStringList* labels, bool* ok); | 597 Block* ParseBlock(ZoneStringList* labels, bool* ok); |
| 645 Block* ParseVariableStatement(bool* ok); | 598 Block* ParseVariableStatement(bool* ok); |
| 646 Block* ParseVariableDeclarations(bool accept_IN, Expression** var, bool* ok); | 599 Block* ParseVariableDeclarations(bool accept_IN, Expression** var, bool* ok); |
| 647 Statement* ParseExpressionOrLabelledStatement(ZoneStringList* labels, | 600 Statement* ParseExpressionOrLabelledStatement(ZoneStringList* labels, |
| 648 bool* ok); | 601 bool* ok); |
| 649 IfStatement* ParseIfStatement(ZoneStringList* labels, bool* ok); | 602 IfStatement* ParseIfStatement(ZoneStringList* labels, bool* ok); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 Literal* GetLiteralTheHole(); | 695 Literal* GetLiteralTheHole(); |
| 743 Literal* GetLiteralNumber(double value); | 696 Literal* GetLiteralNumber(double value); |
| 744 | 697 |
| 745 Handle<String> ParseIdentifier(bool* ok); | 698 Handle<String> ParseIdentifier(bool* ok); |
| 746 Handle<String> ParseIdentifierName(bool* ok); | 699 Handle<String> ParseIdentifierName(bool* ok); |
| 747 Handle<String> ParseIdentifierOrGetOrSet(bool* is_get, | 700 Handle<String> ParseIdentifierOrGetOrSet(bool* is_get, |
| 748 bool* is_set, | 701 bool* is_set, |
| 749 bool* ok); | 702 bool* ok); |
| 750 | 703 |
| 751 // Parser support | 704 // Parser support |
| 752 virtual VariableProxy* Declare(Handle<String> name, Variable::Mode mode, | 705 VariableProxy* Declare(Handle<String> name, Variable::Mode mode, |
| 753 FunctionLiteral* fun, | 706 FunctionLiteral* fun, |
| 754 bool resolve, | 707 bool resolve, |
| 755 bool* ok) = 0; | 708 bool* ok); |
| 756 | 709 |
| 757 bool TargetStackContainsLabel(Handle<String> label); | 710 bool TargetStackContainsLabel(Handle<String> label); |
| 758 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); | 711 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); |
| 759 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); | 712 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); |
| 760 | 713 |
| 761 void RegisterTargetUse(BreakTarget* target, Target* stop); | 714 void RegisterTargetUse(BreakTarget* target, Target* stop); |
| 762 | 715 |
| 716 // Factory methods. |
| 717 |
| 718 Statement* EmptyStatement() { |
| 719 static v8::internal::EmptyStatement empty; |
| 720 return ∅ |
| 721 } |
| 722 |
| 723 Scope* NewScope(Scope* parent, Scope::Type type, bool inside_with); |
| 724 |
| 725 Handle<String> LookupSymbol(int symbol_id, |
| 726 Vector<const char> string); |
| 727 |
| 728 Handle<String> LookupCachedSymbol(int symbol_id, |
| 729 Vector<const char> string); |
| 730 |
| 731 Expression* NewCall(Expression* expression, |
| 732 ZoneList<Expression*>* arguments, |
| 733 int pos) { |
| 734 return new Call(expression, arguments, pos); |
| 735 } |
| 736 |
| 737 |
| 763 // Create a number literal. | 738 // Create a number literal. |
| 764 Literal* NewNumberLiteral(double value); | 739 Literal* NewNumberLiteral(double value); |
| 765 | 740 |
| 766 // Generate AST node that throw a ReferenceError with the given type. | 741 // Generate AST node that throw a ReferenceError with the given type. |
| 767 Expression* NewThrowReferenceError(Handle<String> type); | 742 Expression* NewThrowReferenceError(Handle<String> type); |
| 768 | 743 |
| 769 // Generate AST node that throw a SyntaxError with the given | 744 // Generate AST node that throw a SyntaxError with the given |
| 770 // type. The first argument may be null (in the handle sense) in | 745 // type. The first argument may be null (in the handle sense) in |
| 771 // which case no arguments are passed to the constructor. | 746 // which case no arguments are passed to the constructor. |
| 772 Expression* NewThrowSyntaxError(Handle<String> type, Handle<Object> first); | 747 Expression* NewThrowSyntaxError(Handle<String> type, Handle<Object> first); |
| 773 | 748 |
| 774 // Generate AST node that throw a TypeError with the given | 749 // Generate AST node that throw a TypeError with the given |
| 775 // type. Both arguments must be non-null (in the handle sense). | 750 // type. Both arguments must be non-null (in the handle sense). |
| 776 Expression* NewThrowTypeError(Handle<String> type, | 751 Expression* NewThrowTypeError(Handle<String> type, |
| 777 Handle<Object> first, | 752 Handle<Object> first, |
| 778 Handle<Object> second); | 753 Handle<Object> second); |
| 779 | 754 |
| 780 // Generic AST generator for throwing errors from compiled code. | 755 // Generic AST generator for throwing errors from compiled code. |
| 781 Expression* NewThrowError(Handle<String> constructor, | 756 Expression* NewThrowError(Handle<String> constructor, |
| 782 Handle<String> type, | 757 Handle<String> type, |
| 783 Vector< Handle<Object> > arguments); | 758 Vector< Handle<Object> > arguments); |
| 759 |
| 760 ZoneList<Handle<String> > symbol_cache_; |
| 761 |
| 762 Handle<Script> script_; |
| 763 Scanner scanner_; |
| 764 |
| 765 Scope* top_scope_; |
| 766 int with_nesting_level_; |
| 767 |
| 768 TemporaryScope* temp_scope_; |
| 769 Mode mode_; |
| 770 |
| 771 Target* target_stack_; // for break, continue statements |
| 772 bool allow_natives_syntax_; |
| 773 v8::Extension* extension_; |
| 774 bool is_pre_parsing_; |
| 775 ScriptDataImpl* pre_data_; |
| 776 FuncNameInferrer* fni_; |
| 784 }; | 777 }; |
| 785 | 778 |
| 786 | 779 |
| 787 // Support for handling complex values (array and object literals) that | 780 // Support for handling complex values (array and object literals) that |
| 788 // can be fully handled at compile time. | 781 // can be fully handled at compile time. |
| 789 class CompileTimeValue: public AllStatic { | 782 class CompileTimeValue: public AllStatic { |
| 790 public: | 783 public: |
| 791 enum Type { | 784 enum Type { |
| 792 OBJECT_LITERAL_FAST_ELEMENTS, | 785 OBJECT_LITERAL_FAST_ELEMENTS, |
| 793 OBJECT_LITERAL_SLOW_ELEMENTS, | 786 OBJECT_LITERAL_SLOW_ELEMENTS, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 808 static Handle<FixedArray> GetElements(Handle<FixedArray> value); | 801 static Handle<FixedArray> GetElements(Handle<FixedArray> value); |
| 809 | 802 |
| 810 private: | 803 private: |
| 811 static const int kTypeSlot = 0; | 804 static const int kTypeSlot = 0; |
| 812 static const int kElementsSlot = 1; | 805 static const int kElementsSlot = 1; |
| 813 | 806 |
| 814 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 807 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 815 }; | 808 }; |
| 816 | 809 |
| 817 | 810 |
| 811 // ---------------------------------------------------------------------------- |
| 812 // JSON PARSING |
| 813 |
| 818 // JSON is a subset of JavaScript, as specified in, e.g., the ECMAScript 5 | 814 // JSON is a subset of JavaScript, as specified in, e.g., the ECMAScript 5 |
| 819 // specification section 15.12.1 (and appendix A.8). | 815 // specification section 15.12.1 (and appendix A.8). |
| 820 // The grammar is given section 15.12.1.2 (and appendix A.8.2). | 816 // The grammar is given section 15.12.1.2 (and appendix A.8.2). |
| 821 class JsonParser BASE_EMBEDDED { | 817 class JsonParser BASE_EMBEDDED { |
| 822 public: | 818 public: |
| 823 // Parse JSON input as a single JSON value. | 819 // Parse JSON input as a single JSON value. |
| 824 // Returns null handle and sets exception if parsing failed. | 820 // Returns null handle and sets exception if parsing failed. |
| 825 static Handle<Object> Parse(Handle<String> source) { | 821 static Handle<Object> Parse(Handle<String> source) { |
| 826 return JsonParser().ParseJson(source); | 822 return JsonParser().ParseJson(source); |
| 827 } | 823 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 854 // return a null handle. Primarily for readability. | 850 // return a null handle. Primarily for readability. |
| 855 Handle<Object> ReportUnexpectedToken() { return Handle<Object>::null(); } | 851 Handle<Object> ReportUnexpectedToken() { return Handle<Object>::null(); } |
| 856 // Converts the currently parsed literal to a JavaScript String. | 852 // Converts the currently parsed literal to a JavaScript String. |
| 857 Handle<String> GetString(); | 853 Handle<String> GetString(); |
| 858 | 854 |
| 859 Scanner scanner_; | 855 Scanner scanner_; |
| 860 }; | 856 }; |
| 861 } } // namespace v8::internal | 857 } } // namespace v8::internal |
| 862 | 858 |
| 863 #endif // V8_PARSER_H_ | 859 #endif // V8_PARSER_H_ |
| OLD | NEW |