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

Side by Side Diff: src/parser.h

Issue 27182002: Introduce ParserBase for common code between parser and pre-parser. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 2 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 | « no previous file | 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, 442 void ReportMessageAt(Scanner::Location loc,
465 const char* message, 443 const char* message,
466 Vector<const char*> args = Vector<const char*>::empty()); 444 Vector<const char*> args = Vector<const char*>::empty());
467 void ReportMessageAt(Scanner::Location loc, 445 void ReportMessageAt(Scanner::Location loc,
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 bool name_is_reserved, 683 bool name_is_reserved,
706 bool is_generator, 684 bool is_generator,
707 int function_token_position, 685 int function_token_position,
708 FunctionLiteral::FunctionType type, 686 FunctionLiteral::FunctionType type,
709 bool* ok); 687 bool* ok);
710 688
711 689
712 // Magical syntax support. 690 // Magical syntax support.
713 Expression* ParseV8Intrinsic(bool* ok); 691 Expression* ParseV8Intrinsic(bool* ok);
714 692
715 INLINE(Token::Value peek()) {
716 if (stack_overflow_) return Token::ILLEGAL;
717 return scanner().peek();
718 }
719
720 INLINE(Token::Value Next()) {
721 // BUG 1215673: Find a thread safe way to set a stack limit in
722 // pre-parse mode. Otherwise, we cannot safely pre-parse from other
723 // threads.
724 if (stack_overflow_) {
725 return Token::ILLEGAL;
726 }
727 if (StackLimitCheck(isolate()).HasOverflowed()) {
728 // Any further calls to Next or peek will return the illegal token.
729 // The current call must return the next token, which might already
730 // have been peek'ed.
731 stack_overflow_ = true;
732 }
733 return scanner().Next();
734 }
735
736 bool is_generator() const { return current_function_state_->is_generator(); } 693 bool is_generator() const { return current_function_state_->is_generator(); }
737 694
738 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode); 695 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode);
739 696
740 bool peek_any_identifier();
741
742 INLINE(void Consume(Token::Value token));
743 void Expect(Token::Value token, bool* ok);
744 bool Check(Token::Value token);
745 void ExpectSemicolon(bool* ok);
746 bool CheckContextualKeyword(Vector<const char> keyword); 697 bool CheckContextualKeyword(Vector<const char> keyword);
747 void ExpectContextualKeyword(Vector<const char> keyword, bool* ok); 698 void ExpectContextualKeyword(Vector<const char> keyword, bool* ok);
748 699
749 Handle<String> LiteralString(PretenureFlag tenured) { 700 Handle<String> LiteralString(PretenureFlag tenured) {
750 if (scanner().is_literal_ascii()) { 701 if (scanner().is_literal_ascii()) {
751 return isolate_->factory()->NewStringFromAscii( 702 return isolate_->factory()->NewStringFromAscii(
752 scanner().literal_ascii_string(), tenured); 703 scanner().literal_ascii_string(), tenured);
753 } else { 704 } else {
754 return isolate_->factory()->NewStringFromTwoByte( 705 return isolate_->factory()->NewStringFromTwoByte(
755 scanner().literal_utf16_string(), tenured); 706 scanner().literal_utf16_string(), tenured);
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 PreParser* reusable_preparser_; 809 PreParser* reusable_preparser_;
859 Scope* top_scope_; 810 Scope* top_scope_;
860 Scope* original_scope_; // for ES5 function declarations in sloppy eval 811 Scope* original_scope_; // for ES5 function declarations in sloppy eval
861 FunctionState* current_function_state_; 812 FunctionState* current_function_state_;
862 Target* target_stack_; // for break, continue statements 813 Target* target_stack_; // for break, continue statements
863 v8::Extension* extension_; 814 v8::Extension* extension_;
864 ScriptDataImpl* pre_parse_data_; 815 ScriptDataImpl* pre_parse_data_;
865 FuncNameInferrer* fni_; 816 FuncNameInferrer* fni_;
866 817
867 Mode mode_; 818 Mode mode_;
868 bool allow_natives_syntax_;
869 bool allow_lazy_;
870 bool allow_generators_;
871 bool allow_for_of_;
872 bool stack_overflow_;
873 // If true, the next (and immediately following) function literal is 819 // If true, the next (and immediately following) function literal is
874 // preceded by a parenthesis. 820 // preceded by a parenthesis.
875 // Heuristically that means that the function will be called immediately, 821 // Heuristically that means that the function will be called immediately,
876 // so never lazily compile it. 822 // so never lazily compile it.
877 bool parenthesized_function_; 823 bool parenthesized_function_;
878 824
879 Zone* zone_; 825 Zone* zone_;
880 CompilationInfo* info_; 826 CompilationInfo* info_;
881 friend class BlockState; 827 friend class BlockState;
882 friend class FunctionState; 828 friend class FunctionState;
(...skipping 25 matching lines...) Expand all
908 private: 854 private:
909 static const int kLiteralTypeSlot = 0; 855 static const int kLiteralTypeSlot = 0;
910 static const int kElementsSlot = 1; 856 static const int kElementsSlot = 1;
911 857
912 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 858 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
913 }; 859 };
914 860
915 } } // namespace v8::internal 861 } } // namespace v8::internal
916 862
917 #endif // V8_PARSER_H_ 863 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « no previous file | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698