| 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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 bool ParseIntervalQuantifier(int* min_out, int* max_out); | 314 bool ParseIntervalQuantifier(int* min_out, int* max_out); |
| 315 | 315 |
| 316 // Parses and returns a single escaped character. The character | 316 // Parses and returns a single escaped character. The character |
| 317 // must not be 'b' or 'B' since they are usually handle specially. | 317 // must not be 'b' or 'B' since they are usually handle specially. |
| 318 uc32 ParseClassCharacterEscape(); | 318 uc32 ParseClassCharacterEscape(); |
| 319 | 319 |
| 320 // Checks whether the following is a length-digit hexadecimal number, | 320 // Checks whether the following is a length-digit hexadecimal number, |
| 321 // and sets the value if it is. | 321 // and sets the value if it is. |
| 322 bool ParseHexEscape(int length, uc32* value); | 322 bool ParseHexEscape(int length, uc32* value); |
| 323 | 323 |
| 324 uc32 ParseControlLetterEscape(); | |
| 325 uc32 ParseOctalLiteral(); | 324 uc32 ParseOctalLiteral(); |
| 326 | 325 |
| 327 // Tries to parse the input as a back reference. If successful it | 326 // Tries to parse the input as a back reference. If successful it |
| 328 // stores the result in the output parameter and returns true. If | 327 // stores the result in the output parameter and returns true. If |
| 329 // it fails it will push back the characters read so the same characters | 328 // it fails it will push back the characters read so the same characters |
| 330 // can be reparsed. | 329 // can be reparsed. |
| 331 bool ParseBackReferenceIndex(int* index_out); | 330 bool ParseBackReferenceIndex(int* index_out); |
| 332 | 331 |
| 333 CharacterRange ParseClassAtom(uc16* char_class); | 332 CharacterRange ParseClassAtom(uc16* char_class); |
| 334 RegExpTree* ReportError(Vector<const char> message); | 333 RegExpTree* ReportError(Vector<const char> message); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 417 class Parser { | 416 class Parser { |
| 418 public: | 417 public: |
| 419 Parser(Handle<Script> script, | 418 Parser(Handle<Script> script, |
| 420 bool allow_natives_syntax, | 419 bool allow_natives_syntax, |
| 421 v8::Extension* extension, | 420 v8::Extension* extension, |
| 422 ScriptDataImpl* pre_data); | 421 ScriptDataImpl* pre_data); |
| 423 virtual ~Parser() { } | 422 virtual ~Parser() { } |
| 424 | 423 |
| 425 // Returns NULL if parsing failed. | 424 // Returns NULL if parsing failed. |
| 426 FunctionLiteral* ParseProgram(Handle<String> source, | 425 FunctionLiteral* ParseProgram(Handle<String> source, |
| 427 bool in_global_context); | 426 bool in_global_context, |
| 427 StrictModeFlag strict_mode); |
| 428 | 428 |
| 429 FunctionLiteral* ParseLazy(Handle<SharedFunctionInfo> info); | 429 FunctionLiteral* ParseLazy(Handle<SharedFunctionInfo> info); |
| 430 | 430 |
| 431 void ReportMessageAt(Scanner::Location loc, | 431 void ReportMessageAt(Scanner::Location loc, |
| 432 const char* message, | 432 const char* message, |
| 433 Vector<const char*> args); | 433 Vector<const char*> args); |
| 434 void ReportMessageAt(Scanner::Location loc, |
| 435 const char* message, |
| 436 Vector<Handle<String> > args); |
| 434 | 437 |
| 435 protected: | 438 protected: |
| 439 // Limit on number of function parameters is chosen arbitrarily. |
| 440 // Code::Flags uses only the low 17 bits of num-parameters to |
| 441 // construct a hashable id, so if more than 2^17 are allowed, this |
| 442 // should be checked. |
| 443 static const int kMaxNumFunctionParameters = 32766; |
| 436 FunctionLiteral* ParseLazy(Handle<SharedFunctionInfo> info, | 444 FunctionLiteral* ParseLazy(Handle<SharedFunctionInfo> info, |
| 437 UC16CharacterStream* source, | 445 UC16CharacterStream* source, |
| 438 ZoneScope* zone_scope); | 446 ZoneScope* zone_scope); |
| 439 enum Mode { | 447 enum Mode { |
| 440 PARSE_LAZILY, | 448 PARSE_LAZILY, |
| 441 PARSE_EAGERLY | 449 PARSE_EAGERLY |
| 442 }; | 450 }; |
| 443 | 451 |
| 444 // Called by ParseProgram after setting up the scanner. | 452 // Called by ParseProgram after setting up the scanner. |
| 445 FunctionLiteral* DoParseProgram(Handle<String> source, | 453 FunctionLiteral* DoParseProgram(Handle<String> source, |
| 446 bool in_global_context, | 454 bool in_global_context, |
| 455 StrictModeFlag strict_mode, |
| 447 ZoneScope* zone_scope); | 456 ZoneScope* zone_scope); |
| 448 | 457 |
| 449 // Report syntax error | 458 // Report syntax error |
| 450 void ReportUnexpectedToken(Token::Value token); | 459 void ReportUnexpectedToken(Token::Value token); |
| 451 void ReportInvalidPreparseData(Handle<String> name, bool* ok); | 460 void ReportInvalidPreparseData(Handle<String> name, bool* ok); |
| 452 void ReportMessage(const char* message, Vector<const char*> args); | 461 void ReportMessage(const char* message, Vector<const char*> args); |
| 453 | 462 |
| 454 bool inside_with() const { return with_nesting_level_ > 0; } | 463 bool inside_with() const { return with_nesting_level_ > 0; } |
| 455 V8JavaScriptScanner& scanner() { return scanner_; } | 464 V8JavaScriptScanner& scanner() { return scanner_; } |
| 456 Mode mode() const { return mode_; } | 465 Mode mode() const { return mode_; } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 537 Handle<Object> GetBoilerplateValue(Expression* expression); | 546 Handle<Object> GetBoilerplateValue(Expression* expression); |
| 538 | 547 |
| 539 enum FunctionLiteralType { | 548 enum FunctionLiteralType { |
| 540 EXPRESSION, | 549 EXPRESSION, |
| 541 DECLARATION, | 550 DECLARATION, |
| 542 NESTED | 551 NESTED |
| 543 }; | 552 }; |
| 544 | 553 |
| 545 ZoneList<Expression*>* ParseArguments(bool* ok); | 554 ZoneList<Expression*>* ParseArguments(bool* ok); |
| 546 FunctionLiteral* ParseFunctionLiteral(Handle<String> var_name, | 555 FunctionLiteral* ParseFunctionLiteral(Handle<String> var_name, |
| 556 bool name_is_reserved, |
| 547 int function_token_position, | 557 int function_token_position, |
| 548 FunctionLiteralType type, | 558 FunctionLiteralType type, |
| 549 bool* ok); | 559 bool* ok); |
| 550 | 560 |
| 551 | 561 |
| 552 // Magical syntax support. | 562 // Magical syntax support. |
| 553 Expression* ParseV8Intrinsic(bool* ok); | 563 Expression* ParseV8Intrinsic(bool* ok); |
| 554 | 564 |
| 555 INLINE(Token::Value peek()) { | 565 INLINE(Token::Value peek()) { |
| 556 if (stack_overflow_) return Token::ILLEGAL; | 566 if (stack_overflow_) return Token::ILLEGAL; |
| 557 return scanner().peek(); | 567 return scanner().peek(); |
| 558 } | 568 } |
| 559 | 569 |
| 560 INLINE(Token::Value Next()) { | 570 INLINE(Token::Value Next()) { |
| 561 // BUG 1215673: Find a thread safe way to set a stack limit in | 571 // BUG 1215673: Find a thread safe way to set a stack limit in |
| 562 // pre-parse mode. Otherwise, we cannot safely pre-parse from other | 572 // pre-parse mode. Otherwise, we cannot safely pre-parse from other |
| 563 // threads. | 573 // threads. |
| 564 if (stack_overflow_) { | 574 if (stack_overflow_) { |
| 565 return Token::ILLEGAL; | 575 return Token::ILLEGAL; |
| 566 } | 576 } |
| 567 if (StackLimitCheck().HasOverflowed()) { | 577 if (StackLimitCheck().HasOverflowed()) { |
| 568 // Any further calls to Next or peek will return the illegal token. | 578 // Any further calls to Next or peek will return the illegal token. |
| 569 // The current call must return the next token, which might already | 579 // The current call must return the next token, which might already |
| 570 // have been peek'ed. | 580 // have been peek'ed. |
| 571 stack_overflow_ = true; | 581 stack_overflow_ = true; |
| 572 } | 582 } |
| 573 return scanner().Next(); | 583 return scanner().Next(); |
| 574 } | 584 } |
| 575 | 585 |
| 586 bool peek_any_identifier(); |
| 587 |
| 576 INLINE(void Consume(Token::Value token)); | 588 INLINE(void Consume(Token::Value token)); |
| 577 void Expect(Token::Value token, bool* ok); | 589 void Expect(Token::Value token, bool* ok); |
| 578 bool Check(Token::Value token); | 590 bool Check(Token::Value token); |
| 579 void ExpectSemicolon(bool* ok); | 591 void ExpectSemicolon(bool* ok); |
| 580 | 592 |
| 581 Handle<String> LiteralString(PretenureFlag tenured) { | 593 Handle<String> LiteralString(PretenureFlag tenured) { |
| 582 if (scanner().is_literal_ascii()) { | 594 if (scanner().is_literal_ascii()) { |
| 583 return Factory::NewStringFromAscii(scanner().literal_ascii_string(), | 595 return Factory::NewStringFromAscii(scanner().literal_ascii_string(), |
| 584 tenured); | 596 tenured); |
| 585 } else { | 597 } else { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 599 } | 611 } |
| 600 | 612 |
| 601 Handle<String> GetSymbol(bool* ok); | 613 Handle<String> GetSymbol(bool* ok); |
| 602 | 614 |
| 603 // Get odd-ball literals. | 615 // Get odd-ball literals. |
| 604 Literal* GetLiteralUndefined(); | 616 Literal* GetLiteralUndefined(); |
| 605 Literal* GetLiteralTheHole(); | 617 Literal* GetLiteralTheHole(); |
| 606 Literal* GetLiteralNumber(double value); | 618 Literal* GetLiteralNumber(double value); |
| 607 | 619 |
| 608 Handle<String> ParseIdentifier(bool* ok); | 620 Handle<String> ParseIdentifier(bool* ok); |
| 621 Handle<String> ParseIdentifierOrReservedWord(bool* is_reserved, bool* ok); |
| 609 Handle<String> ParseIdentifierName(bool* ok); | 622 Handle<String> ParseIdentifierName(bool* ok); |
| 610 Handle<String> ParseIdentifierOrGetOrSet(bool* is_get, | 623 Handle<String> ParseIdentifierOrGetOrSet(bool* is_get, |
| 611 bool* is_set, | 624 bool* is_set, |
| 612 bool* ok); | 625 bool* ok); |
| 613 | 626 |
| 627 // Strict mode validation of LValue expressions |
| 628 void CheckStrictModeLValue(Expression* expression, |
| 629 const char* error, |
| 630 bool* ok); |
| 631 |
| 632 // Strict mode octal literal validation. |
| 633 void CheckOctalLiteral(int beg_pos, int end_pos, bool* ok); |
| 634 |
| 614 // Parser support | 635 // Parser support |
| 615 VariableProxy* Declare(Handle<String> name, Variable::Mode mode, | 636 VariableProxy* Declare(Handle<String> name, Variable::Mode mode, |
| 616 FunctionLiteral* fun, | 637 FunctionLiteral* fun, |
| 617 bool resolve, | 638 bool resolve, |
| 618 bool* ok); | 639 bool* ok); |
| 619 | 640 |
| 620 bool TargetStackContainsLabel(Handle<String> label); | 641 bool TargetStackContainsLabel(Handle<String> label); |
| 621 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); | 642 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); |
| 622 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); | 643 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); |
| 623 | 644 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 TemporaryScope* temp_scope_; | 697 TemporaryScope* temp_scope_; |
| 677 Mode mode_; | 698 Mode mode_; |
| 678 | 699 |
| 679 Target* target_stack_; // for break, continue statements | 700 Target* target_stack_; // for break, continue statements |
| 680 bool allow_natives_syntax_; | 701 bool allow_natives_syntax_; |
| 681 v8::Extension* extension_; | 702 v8::Extension* extension_; |
| 682 bool is_pre_parsing_; | 703 bool is_pre_parsing_; |
| 683 ScriptDataImpl* pre_data_; | 704 ScriptDataImpl* pre_data_; |
| 684 FuncNameInferrer* fni_; | 705 FuncNameInferrer* fni_; |
| 685 bool stack_overflow_; | 706 bool stack_overflow_; |
| 707 // If true, the next (and immediately following) function literal is |
| 708 // preceded by a parenthesis. |
| 709 // Heuristically that means that the function will be called immediately, |
| 710 // so never lazily compile it. |
| 711 bool parenthesized_function_; |
| 686 }; | 712 }; |
| 687 | 713 |
| 688 | 714 |
| 689 // Support for handling complex values (array and object literals) that | 715 // Support for handling complex values (array and object literals) that |
| 690 // can be fully handled at compile time. | 716 // can be fully handled at compile time. |
| 691 class CompileTimeValue: public AllStatic { | 717 class CompileTimeValue: public AllStatic { |
| 692 public: | 718 public: |
| 693 enum Type { | 719 enum Type { |
| 694 OBJECT_LITERAL_FAST_ELEMENTS, | 720 OBJECT_LITERAL_FAST_ELEMENTS, |
| 695 OBJECT_LITERAL_SLOW_ELEMENTS, | 721 OBJECT_LITERAL_SLOW_ELEMENTS, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 Handle<Object> ReportUnexpectedToken() { return Handle<Object>::null(); } | 793 Handle<Object> ReportUnexpectedToken() { return Handle<Object>::null(); } |
| 768 // Converts the currently parsed literal to a JavaScript String. | 794 // Converts the currently parsed literal to a JavaScript String. |
| 769 Handle<String> GetString(); | 795 Handle<String> GetString(); |
| 770 | 796 |
| 771 JsonScanner scanner_; | 797 JsonScanner scanner_; |
| 772 bool stack_overflow_; | 798 bool stack_overflow_; |
| 773 }; | 799 }; |
| 774 } } // namespace v8::internal | 800 } } // namespace v8::internal |
| 775 | 801 |
| 776 #endif // V8_PARSER_H_ | 802 #endif // V8_PARSER_H_ |
| OLD | NEW |