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

Side by Side Diff: src/parser.h

Issue 27206002: Unify several checking methods 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 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
432 delete reusable_preparser_; 432 delete reusable_preparser_;
433 reusable_preparser_ = NULL; 433 reusable_preparser_ = NULL;
434 } 434 }
435 435
436 // 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
437 // function literal. Returns false (and deallocates any allocated AST 437 // function literal. Returns false (and deallocates any allocated AST
438 // nodes) if parsing failed. 438 // nodes) if parsing failed.
439 static bool Parse(CompilationInfo* info) { return Parser(info).Parse(); } 439 static bool Parse(CompilationInfo* info) { return Parser(info).Parse(); }
440 bool Parse(); 440 bool Parse();
441 441
442 void ReportMessageAt(Scanner::Location loc,
443 const char* message,
444 Vector<const char*> args = Vector<const char*>::empty());
445 void ReportMessageAt(Scanner::Location loc,
446 const char* message,
447 Vector<Handle<String> > args);
448
449 private: 442 private:
450 static const int kMaxNumFunctionLocals = 131071; // 2^17-1 443 static const int kMaxNumFunctionLocals = 131071; // 2^17-1
451 444
452 enum Mode { 445 enum Mode {
453 PARSE_LAZILY, 446 PARSE_LAZILY,
454 PARSE_EAGERLY 447 PARSE_EAGERLY
455 }; 448 };
456 449
457 enum VariableDeclarationContext { 450 enum VariableDeclarationContext {
458 kModuleElement, 451 kModuleElement,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 548
556 // Called by ParseProgram after setting up the scanner. 549 // Called by ParseProgram after setting up the scanner.
557 FunctionLiteral* DoParseProgram(CompilationInfo* info, 550 FunctionLiteral* DoParseProgram(CompilationInfo* info,
558 Handle<String> source); 551 Handle<String> source);
559 552
560 // Report syntax error 553 // Report syntax error
561 void ReportUnexpectedToken(Token::Value token); 554 void ReportUnexpectedToken(Token::Value token);
562 void ReportInvalidPreparseData(Handle<String> name, bool* ok); 555 void ReportInvalidPreparseData(Handle<String> name, bool* ok);
563 void ReportMessage(const char* message, Vector<const char*> args); 556 void ReportMessage(const char* message, Vector<const char*> args);
564 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);
565 567
566 void set_pre_parse_data(ScriptDataImpl *data) { 568 void set_pre_parse_data(ScriptDataImpl *data) {
567 pre_parse_data_ = data; 569 pre_parse_data_ = data;
568 symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone()); 570 symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone());
569 } 571 }
570 572
571 bool inside_with() const { return top_scope_->inside_with(); } 573 bool inside_with() const { return top_scope_->inside_with(); }
572 Scanner& scanner() { return scanner_; } 574 Scanner& scanner() { return scanner_; }
573 int position() { return scanner_.location().beg_pos; }
574 int peek_position() { return scanner_.peek_location().beg_pos; }
575 Mode mode() const { return mode_; } 575 Mode mode() const { return mode_; }
576 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; } 576 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; }
577 bool is_extended_mode() { 577 bool is_extended_mode() {
578 ASSERT(top_scope_ != NULL); 578 ASSERT(top_scope_ != NULL);
579 return top_scope_->is_extended_mode(); 579 return top_scope_->is_extended_mode();
580 } 580 }
581 Scope* DeclarationScope(VariableMode mode) { 581 Scope* DeclarationScope(VariableMode mode) {
582 return IsLexicalVariableMode(mode) 582 return IsLexicalVariableMode(mode)
583 ? top_scope_ : top_scope_->DeclarationScope(); 583 ? top_scope_ : top_scope_->DeclarationScope();
584 } 584 }
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 bool* ok); 687 bool* ok);
688 688
689 689
690 // Magical syntax support. 690 // Magical syntax support.
691 Expression* ParseV8Intrinsic(bool* ok); 691 Expression* ParseV8Intrinsic(bool* ok);
692 692
693 bool is_generator() const { return current_function_state_->is_generator(); } 693 bool is_generator() const { return current_function_state_->is_generator(); }
694 694
695 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode); 695 bool CheckInOrOf(bool accept_OF, ForEachStatement::VisitMode* visit_mode);
696 696
697 bool CheckContextualKeyword(Vector<const char> keyword);
698 void ExpectContextualKeyword(Vector<const char> keyword, bool* ok);
699
700 Handle<String> LiteralString(PretenureFlag tenured) { 697 Handle<String> LiteralString(PretenureFlag tenured) {
701 if (scanner().is_literal_ascii()) { 698 if (scanner().is_literal_ascii()) {
702 return isolate_->factory()->NewStringFromAscii( 699 return isolate_->factory()->NewStringFromAscii(
703 scanner().literal_ascii_string(), tenured); 700 scanner().literal_ascii_string(), tenured);
704 } else { 701 } else {
705 return isolate_->factory()->NewStringFromTwoByte( 702 return isolate_->factory()->NewStringFromTwoByte(
706 scanner().literal_utf16_string(), tenured); 703 scanner().literal_utf16_string(), tenured);
707 } 704 }
708 } 705 }
709 706
(...skipping 24 matching lines...) Expand all
734 // 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
735 // 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
736 // used on for the statically checking assignments to harmony const bindings. 733 // used on for the statically checking assignments to harmony const bindings.
737 void MarkAsLValue(Expression* expression); 734 void MarkAsLValue(Expression* expression);
738 735
739 // Strict mode validation of LValue expressions 736 // Strict mode validation of LValue expressions
740 void CheckStrictModeLValue(Expression* expression, 737 void CheckStrictModeLValue(Expression* expression,
741 const char* error, 738 const char* error,
742 bool* ok); 739 bool* ok);
743 740
744 // Strict mode octal literal validation.
745 void CheckOctalLiteral(int beg_pos, int end_pos, bool* ok);
746
747 // 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
748 // declarations from different scopes. It covers for example 742 // declarations from different scopes. It covers for example
749 // 743 //
750 // function f() { { { var x; } let x; } } 744 // function f() { { { var x; } let x; } }
751 // function g() { { var x; let x; } } 745 // function g() { { var x; let x; } }
752 // 746 //
753 // 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
754 // 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
755 // hoisted over such a scope. 749 // hoisted over such a scope.
756 void CheckConflictingVarDeclarations(Scope* scope, bool* ok); 750 void CheckConflictingVarDeclarations(Scope* scope, bool* ok);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 // If true, the next (and immediately following) function literal is 813 // If true, the next (and immediately following) function literal is
820 // preceded by a parenthesis. 814 // preceded by a parenthesis.
821 // Heuristically that means that the function will be called immediately, 815 // Heuristically that means that the function will be called immediately,
822 // so never lazily compile it. 816 // so never lazily compile it.
823 bool parenthesized_function_; 817 bool parenthesized_function_;
824 818
825 Zone* zone_; 819 Zone* zone_;
826 CompilationInfo* info_; 820 CompilationInfo* info_;
827 friend class BlockState; 821 friend class BlockState;
828 friend class FunctionState; 822 friend class FunctionState;
829 friend class ObjectLiteralChecker<Parser>;
830 }; 823 };
831 824
832 825
833 // Support for handling complex values (array and object literals) that 826 // Support for handling complex values (array and object literals) that
834 // can be fully handled at compile time. 827 // can be fully handled at compile time.
835 class CompileTimeValue: public AllStatic { 828 class CompileTimeValue: public AllStatic {
836 public: 829 public:
837 enum LiteralType { 830 enum LiteralType {
838 OBJECT_LITERAL_FAST_ELEMENTS, 831 OBJECT_LITERAL_FAST_ELEMENTS,
839 OBJECT_LITERAL_SLOW_ELEMENTS, 832 OBJECT_LITERAL_SLOW_ELEMENTS,
(...skipping 14 matching lines...) Expand all
854 private: 847 private:
855 static const int kLiteralTypeSlot = 0; 848 static const int kLiteralTypeSlot = 0;
856 static const int kElementsSlot = 1; 849 static const int kElementsSlot = 1;
857 850
858 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 851 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
859 }; 852 };
860 853
861 } } // namespace v8::internal 854 } } // namespace v8::internal
862 855
863 #endif // V8_PARSER_H_ 856 #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