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

Side by Side Diff: src/parser.h

Issue 133443009: A64: Synchronize with r17441. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: 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 | « src/optimizing-compiler-thread.cc ('k') | 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 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 bool is_scanned_for_captures_; 418 bool is_scanned_for_captures_;
419 bool failed_; 419 bool failed_;
420 }; 420 };
421 421
422 // ---------------------------------------------------------------------------- 422 // ----------------------------------------------------------------------------
423 // JAVASCRIPT PARSING 423 // JAVASCRIPT PARSING
424 424
425 // Forward declaration. 425 // Forward declaration.
426 class SingletonLogger; 426 class SingletonLogger;
427 427
428 class Parser BASE_EMBEDDED { 428 class Parser : public ParserBase {
429 public: 429 public:
430 explicit Parser(CompilationInfo* info); 430 explicit Parser(CompilationInfo* info);
431 ~Parser() { 431 ~Parser() {
432 delete reusable_preparser_; 432 delete reusable_preparser_;
433 reusable_preparser_ = NULL; 433 reusable_preparser_ = NULL;
434 } 434 }
435 435
436 bool allow_natives_syntax() const { return allow_natives_syntax_; }
437 bool allow_lazy() const { return allow_lazy_; }
438 bool allow_modules() { return scanner().HarmonyModules(); }
439 bool allow_harmony_scoping() { return scanner().HarmonyScoping(); }
440 bool allow_generators() const { return allow_generators_; }
441 bool allow_for_of() const { return allow_for_of_; }
442 bool allow_harmony_numeric_literals() {
443 return scanner().HarmonyNumericLiterals();
444 }
445
446 void set_allow_natives_syntax(bool allow) { allow_natives_syntax_ = allow; }
447 void set_allow_lazy(bool allow) { allow_lazy_ = allow; }
448 void set_allow_modules(bool allow) { scanner().SetHarmonyModules(allow); }
449 void set_allow_harmony_scoping(bool allow) {
450 scanner().SetHarmonyScoping(allow);
451 }
452 void set_allow_generators(bool allow) { allow_generators_ = allow; }
453 void set_allow_for_of(bool allow) { allow_for_of_ = allow; }
454 void set_allow_harmony_numeric_literals(bool allow) {
455 scanner().SetHarmonyNumericLiterals(allow);
456 }
457
458 // Parses the source code represented by the compilation info and sets its 436 // Parses the source code represented by the compilation info and sets its
459 // function literal. Returns false (and deallocates any allocated AST 437 // function literal. Returns false (and deallocates any allocated AST
460 // nodes) if parsing failed. 438 // nodes) if parsing failed.
461 static bool Parse(CompilationInfo* info) { return Parser(info).Parse(); } 439 static bool Parse(CompilationInfo* info) { return Parser(info).Parse(); }
462 bool Parse(); 440 bool Parse();
463 441
464 void ReportMessageAt(Scanner::Location loc,
465 const char* message,
466 Vector<const char*> args);
467 void ReportMessageAt(Scanner::Location loc,
468 const char* message,
469 Vector<Handle<String> > args);
470
471 private: 442 private:
472 static const int kMaxNumFunctionLocals = 131071; // 2^17-1 443 static const int kMaxNumFunctionLocals = 131071; // 2^17-1
473 444
474 enum Mode { 445 enum Mode {
475 PARSE_LAZILY, 446 PARSE_LAZILY,
476 PARSE_EAGERLY 447 PARSE_EAGERLY
477 }; 448 };
478 449
479 enum VariableDeclarationContext { 450 enum VariableDeclarationContext {
480 kModuleElement, 451 kModuleElement,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 548
578 // Called by ParseProgram after setting up the scanner. 549 // Called by ParseProgram after setting up the scanner.
579 FunctionLiteral* DoParseProgram(CompilationInfo* info, 550 FunctionLiteral* DoParseProgram(CompilationInfo* info,
580 Handle<String> source); 551 Handle<String> source);
581 552
582 // Report syntax error 553 // Report syntax error
583 void ReportUnexpectedToken(Token::Value token); 554 void ReportUnexpectedToken(Token::Value token);
584 void ReportInvalidPreparseData(Handle<String> name, bool* ok); 555 void ReportInvalidPreparseData(Handle<String> name, bool* ok);
585 void ReportMessage(const char* message, Vector<const char*> args); 556 void ReportMessage(const char* message, Vector<const char*> args);
586 void ReportMessage(const char* message, Vector<Handle<String> > args); 557 void ReportMessage(const char* message, Vector<Handle<String> > args);
558 void ReportMessageAt(Scanner::Location location, const char* type) {
559 ReportMessageAt(location, type, Vector<const char*>::empty());
560 }
561 void ReportMessageAt(Scanner::Location loc,
562 const char* message,
563 Vector<const char*> args);
564 void ReportMessageAt(Scanner::Location loc,
565 const char* message,
566 Vector<Handle<String> > args);
587 567
588 void set_pre_parse_data(ScriptDataImpl *data) { 568 void set_pre_parse_data(ScriptDataImpl *data) {
589 pre_parse_data_ = data; 569 pre_parse_data_ = data;
590 symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone()); 570 symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone());
591 } 571 }
592 572
593 bool inside_with() const { return top_scope_->inside_with(); } 573 bool inside_with() const { return top_scope_->inside_with(); }
594 Scanner& scanner() { return scanner_; } 574 Scanner& scanner() { return scanner_; }
595 Mode mode() const { return mode_; } 575 Mode mode() const { return mode_; }
596 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } 576 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; }
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 Expression* ParsePostfixExpression(bool* ok); 644 Expression* ParsePostfixExpression(bool* ok);
665 Expression* ParseLeftHandSideExpression(bool* ok); 645 Expression* ParseLeftHandSideExpression(bool* ok);
666 Expression* ParseNewExpression(bool* ok); 646 Expression* ParseNewExpression(bool* ok);
667 Expression* ParseMemberExpression(bool* ok); 647 Expression* ParseMemberExpression(bool* ok);
668 Expression* ParseNewPrefix(PositionStack* stack, bool* ok); 648 Expression* ParseNewPrefix(PositionStack* stack, bool* ok);
669 Expression* ParseMemberWithNewPrefixesExpression(PositionStack* stack, 649 Expression* ParseMemberWithNewPrefixesExpression(PositionStack* stack,
670 bool* ok); 650 bool* ok);
671 Expression* ParsePrimaryExpression(bool* ok); 651 Expression* ParsePrimaryExpression(bool* ok);
672 Expression* ParseArrayLiteral(bool* ok); 652 Expression* ParseArrayLiteral(bool* ok);
673 Expression* ParseObjectLiteral(bool* ok); 653 Expression* ParseObjectLiteral(bool* ok);
674 ObjectLiteral::Property* ParseObjectLiteralGetSet(bool is_getter, bool* ok);
675 Expression* ParseRegExpLiteral(bool seen_equal, bool* ok); 654 Expression* ParseRegExpLiteral(bool seen_equal, bool* ok);
676 655
677 // Populate the constant properties fixed array for a materialized object 656 // Populate the constant properties fixed array for a materialized object
678 // literal. 657 // literal.
679 void BuildObjectLiteralConstantProperties( 658 void BuildObjectLiteralConstantProperties(
680 ZoneList<ObjectLiteral::Property*>* properties, 659 ZoneList<ObjectLiteral::Property*>* properties,
681 Handle<FixedArray> constants, 660 Handle<FixedArray> constants,
682 bool* is_simple, 661 bool* is_simple,
683 bool* fast_elements, 662 bool* fast_elements,
684 int* depth, 663 int* depth,
(...skipping 19 matching lines...) Expand all
704 bool name_is_reserved, 683 bool name_is_reserved,
705 bool is_generator, 684 bool is_generator,
706 int function_token_position, 685 int function_token_position,
707 FunctionLiteral::FunctionType type, 686 FunctionLiteral::FunctionType type,
708 bool* ok); 687 bool* ok);
709 688
710 689
711 // Magical syntax support. 690 // Magical syntax support.
712 Expression* ParseV8Intrinsic(bool* ok); 691 Expression* ParseV8Intrinsic(bool* ok);
713 692
714 INLINE(Token::Value peek()) {
715 if (stack_overflow_) return Token::ILLEGAL;
716 return scanner().peek();
717 }
718
719 INLINE(Token::Value Next()) {
720 // BUG 1215673: Find a thread safe way to set a stack limit in
721 // pre-parse mode. Otherwise, we cannot safely pre-parse from other
722 // threads.
723 if (stack_overflow_) {
724 return Token::ILLEGAL;
725 }
726 if (StackLimitCheck(isolate()).HasOverflowed()) {
727 // Any further calls to Next or peek will return the illegal token.
728 // The current call must return the next token, which might already
729 // have been peek'ed.
730 stack_overflow_ = true;
731 }
732 return scanner().Next();
733 }
734
735 bool is_generator() const { return current_function_state_->is_generator(); } 693 bool is_generator() const { return current_function_state_->is_generator(); }
736 694
737 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode); 695 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode);
738 696
739 bool peek_any_identifier();
740
741 INLINE(void Consume(Token::Value token));
742 void Expect(Token::Value token, bool* ok);
743 bool Check(Token::Value token);
744 void ExpectSemicolon(bool* ok);
745 bool CheckContextualKeyword(Vector<const char> keyword);
746 void ExpectContextualKeyword(Vector<const char> keyword, bool* ok);
747
748 Handle<String> LiteralString(PretenureFlag tenured) { 697 Handle<String> LiteralString(PretenureFlag tenured) {
749 if (scanner().is_literal_ascii()) { 698 if (scanner().is_literal_ascii()) {
750 return isolate_->factory()->NewStringFromAscii( 699 return isolate_->factory()->NewStringFromAscii(
751 scanner().literal_ascii_string(), tenured); 700 scanner().literal_ascii_string(), tenured);
752 } else { 701 } else {
753 return isolate_->factory()->NewStringFromTwoByte( 702 return isolate_->factory()->NewStringFromTwoByte(
754 scanner().literal_utf16_string(), tenured); 703 scanner().literal_utf16_string(), tenured);
755 } 704 }
756 } 705 }
757 706
758 Handle<String> NextLiteralString(PretenureFlag tenured) { 707 Handle<String> NextLiteralString(PretenureFlag tenured) {
759 if (scanner().is_next_literal_ascii()) { 708 if (scanner().is_next_literal_ascii()) {
760 return isolate_->factory()->NewStringFromAscii( 709 return isolate_->factory()->NewStringFromAscii(
761 scanner().next_literal_ascii_string(), tenured); 710 scanner().next_literal_ascii_string(), tenured);
762 } else { 711 } else {
763 return isolate_->factory()->NewStringFromTwoByte( 712 return isolate_->factory()->NewStringFromTwoByte(
764 scanner().next_literal_utf16_string(), tenured); 713 scanner().next_literal_utf16_string(), tenured);
765 } 714 }
766 } 715 }
767 716
768 Handle<String> GetSymbol(); 717 Handle<String> GetSymbol();
769 718
770 // Get odd-ball literals. 719 // Get odd-ball literals.
771 Literal* GetLiteralUndefined(); 720 Literal* GetLiteralUndefined(int position);
772 Literal* GetLiteralTheHole(); 721 Literal* GetLiteralTheHole(int position);
773 722
774 Handle<String> ParseIdentifier(bool* ok); 723 Handle<String> ParseIdentifier(bool* ok);
775 Handle<String> ParseIdentifierOrStrictReservedWord( 724 Handle<String> ParseIdentifierOrStrictReservedWord(
776 bool* is_strict_reserved, bool* ok); 725 bool* is_strict_reserved, bool* ok);
777 Handle<String> ParseIdentifierName(bool* ok); 726 Handle<String> ParseIdentifierName(bool* ok);
778 Handle<String> ParseIdentifierNameOrGetOrSet(bool* is_get, 727 Handle<String> ParseIdentifierNameOrGetOrSet(bool* is_get,
779 bool* is_set, 728 bool* is_set,
780 bool* ok); 729 bool* ok);
781 730
782 // Determine if the expression is a variable proxy and mark it as being used 731 // Determine if the expression is a variable proxy and mark it as being used
783 // in an assignment or with a increment/decrement operator. This is currently 732 // in an assignment or with a increment/decrement operator. This is currently
784 // used on for the statically checking assignments to harmony const bindings. 733 // used on for the statically checking assignments to harmony const bindings.
785 void MarkAsLValue(Expression* expression); 734 void MarkAsLValue(Expression* expression);
786 735
787 // Strict mode validation of LValue expressions 736 // Strict mode validation of LValue expressions
788 void CheckStrictModeLValue(Expression* expression, 737 void CheckStrictModeLValue(Expression* expression,
789 const char* error, 738 const char* error,
790 bool* ok); 739 bool* ok);
791 740
792 // Strict mode octal literal validation.
793 void CheckOctalLiteral(int beg_pos, int end_pos, bool* ok);
794
795 // For harmony block scoping mode: Check if the scope has conflicting var/let 741 // For harmony block scoping mode: Check if the scope has conflicting var/let
796 // declarations from different scopes. It covers for example 742 // declarations from different scopes. It covers for example
797 // 743 //
798 // function f() { { { var x; } let x; } } 744 // function f() { { { var x; } let x; } }
799 // function g() { { var x; let x; } } 745 // function g() { { var x; let x; } }
800 // 746 //
801 // The var declarations are hoisted to the function scope, but originate from 747 // The var declarations are hoisted to the function scope, but originate from
802 // a scope where the name has also been let bound or the var declaration is 748 // a scope where the name has also been let bound or the var declaration is
803 // hoisted over such a scope. 749 // hoisted over such a scope.
804 void CheckConflictingVarDeclarations(Scope* scope, bool* ok); 750 void CheckConflictingVarDeclarations(Scope* scope, bool* ok);
(...skipping 30 matching lines...) Expand all
835 // type. Both arguments must be non-null (in the handle sense). 781 // type. Both arguments must be non-null (in the handle sense).
836 Expression* NewThrowTypeError(Handle<String> type, 782 Expression* NewThrowTypeError(Handle<String> type,
837 Handle<Object> first, 783 Handle<Object> first,
838 Handle<Object> second); 784 Handle<Object> second);
839 785
840 // Generic AST generator for throwing errors from compiled code. 786 // Generic AST generator for throwing errors from compiled code.
841 Expression* NewThrowError(Handle<String> constructor, 787 Expression* NewThrowError(Handle<String> constructor,
842 Handle<String> type, 788 Handle<String> type,
843 Vector< Handle<Object> > arguments); 789 Vector< Handle<Object> > arguments);
844 790
845 preparser::PreParser::PreParseResult LazyParseFunctionLiteral( 791 PreParser::PreParseResult LazyParseFunctionLiteral(
846 SingletonLogger* logger); 792 SingletonLogger* logger);
847 793
848 AstNodeFactory<AstConstructionVisitor>* factory() { 794 AstNodeFactory<AstConstructionVisitor>* factory() {
849 return current_function_state_->factory(); 795 return current_function_state_->factory();
850 } 796 }
851 797
852 Isolate* isolate_; 798 Isolate* isolate_;
853 ZoneList<Handle<String> > symbol_cache_; 799 ZoneList<Handle<String> > symbol_cache_;
854 800
855 Handle<Script> script_; 801 Handle<Script> script_;
856 Scanner scanner_; 802 Scanner scanner_;
857 preparser::PreParser* reusable_preparser_; 803 PreParser* reusable_preparser_;
858 Scope* top_scope_; 804 Scope* top_scope_;
859 Scope* original_scope_; // for ES5 function declarations in sloppy eval 805 Scope* original_scope_; // for ES5 function declarations in sloppy eval
860 FunctionState* current_function_state_; 806 FunctionState* current_function_state_;
861 Target* target_stack_; // for break, continue statements 807 Target* target_stack_; // for break, continue statements
862 v8::Extension* extension_; 808 v8::Extension* extension_;
863 ScriptDataImpl* pre_parse_data_; 809 ScriptDataImpl* pre_parse_data_;
864 FuncNameInferrer* fni_; 810 FuncNameInferrer* fni_;
865 811
866 Mode mode_; 812 Mode mode_;
867 bool allow_natives_syntax_;
868 bool allow_lazy_;
869 bool allow_generators_;
870 bool allow_for_of_;
871 bool stack_overflow_;
872 // If true, the next (and immediately following) function literal is 813 // If true, the next (and immediately following) function literal is
873 // preceded by a parenthesis. 814 // preceded by a parenthesis.
874 // Heuristically that means that the function will be called immediately, 815 // Heuristically that means that the function will be called immediately,
875 // so never lazily compile it. 816 // so never lazily compile it.
876 bool parenthesized_function_; 817 bool parenthesized_function_;
877 818
878 Zone* zone_; 819 Zone* zone_;
879 CompilationInfo* info_; 820 CompilationInfo* info_;
880 friend class BlockState; 821 friend class BlockState;
881 friend class FunctionState; 822 friend class FunctionState;
(...skipping 24 matching lines...) Expand all
906 private: 847 private:
907 static const int kLiteralTypeSlot = 0; 848 static const int kLiteralTypeSlot = 0;
908 static const int kElementsSlot = 1; 849 static const int kElementsSlot = 1;
909 850
910 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 851 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
911 }; 852 };
912 853
913 } } // namespace v8::internal 854 } } // namespace v8::internal
914 855
915 #endif // V8_PARSER_H_ 856 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/optimizing-compiler-thread.cc ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698