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

Side by Side Diff: src/parser.h

Issue 13450007: Refactor parser mode configuration for correctness (Closed) Base URL: git://github.com/v8/v8.git@master
Patch Set: Created 7 years, 8 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
« no previous file with comments | « src/liveedit.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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 reinterpret_cast<intptr_t>(backing_store) % sizeof(unsigned))); 156 reinterpret_cast<intptr_t>(backing_store) % sizeof(unsigned)));
157 } 157 }
158 158
159 // Read strings written by ParserRecorder::WriteString. 159 // Read strings written by ParserRecorder::WriteString.
160 static const char* ReadString(unsigned* start, int* chars); 160 static const char* ReadString(unsigned* start, int* chars);
161 161
162 friend class ScriptData; 162 friend class ScriptData;
163 }; 163 };
164 164
165 165
166 class ParserApi { 166 class PreParserApi {
167 public: 167 public:
168 // Parses the source code represented by the compilation info and sets its 168 // Pre-parse a character stream and return full preparse data.
169 // function literal. Returns false (and deallocates any allocated AST 169 //
170 // nodes) if parsing failed. 170 // This interface is here instead of in preparser.h because it instantiates a
171 static bool Parse(CompilationInfo* info, int flags); 171 // preparser recorder object that is suited to the parser's purposes. Also,
172 172 // the preparser doesn't know about ScriptDataImpl.
173 // Generic preparser generating full preparse data.
174 static ScriptDataImpl* PreParse(Utf16CharacterStream* source); 173 static ScriptDataImpl* PreParse(Utf16CharacterStream* source);
175 }; 174 };
176 175
176
177 // ---------------------------------------------------------------------------- 177 // ----------------------------------------------------------------------------
178 // REGEXP PARSING 178 // REGEXP PARSING
179 179
180 // A BufferedZoneList is an automatically growing list, just like (and backed 180 // A BufferedZoneList is an automatically growing list, just like (and backed
181 // by) a ZoneList, that is optimized for the case of adding and removing 181 // by) a ZoneList, that is optimized for the case of adding and removing
182 // a single element. The last element added is stored outside the backing list, 182 // a single element. The last element added is stored outside the backing list,
183 // and if no more than one element is ever added, the ZoneList isn't even 183 // and if no more than one element is ever added, the ZoneList isn't even
184 // allocated. 184 // allocated.
185 // Elements must not be NULL pointers. 185 // Elements must not be NULL pointers.
186 template <typename T, int initial_size> 186 template <typename T, int initial_size>
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 }; 418 };
419 419
420 // ---------------------------------------------------------------------------- 420 // ----------------------------------------------------------------------------
421 // JAVASCRIPT PARSING 421 // JAVASCRIPT PARSING
422 422
423 // Forward declaration. 423 // Forward declaration.
424 class SingletonLogger; 424 class SingletonLogger;
425 425
426 class Parser { 426 class Parser {
427 public: 427 public:
428 Parser(CompilationInfo* info, 428 explicit Parser(CompilationInfo* info);
429 int parsing_flags, // Combination of ParsingFlags
430 v8::Extension* extension,
431 ScriptDataImpl* pre_data);
432 virtual ~Parser() { 429 virtual ~Parser() {
433 delete reusable_preparser_; 430 delete reusable_preparser_;
434 reusable_preparser_ = NULL; 431 reusable_preparser_ = NULL;
435 } 432 }
436 433
434 bool allow_natives_syntax() const { return allow_natives_syntax_; }
435 bool allow_lazy() const { return allow_lazy_; }
436 bool allow_modules() { return scanner().HarmonyModules(); }
437 bool allow_harmony_scoping() { return scanner().HarmonyScoping(); }
438 bool allow_generators() const { return allow_generators_; }
439
440 void set_allow_natives_syntax(bool allow) { allow_natives_syntax_ = allow; }
441 void set_allow_lazy(bool allow) { allow_lazy_ = allow; }
442 void set_allow_modules(bool allow) { scanner().SetHarmonyModules(allow); }
443 void set_allow_harmony_scoping(bool allow) {
444 scanner().SetHarmonyScoping(allow);
445 }
446 void set_allow_generators(bool allow) { allow_generators_ = allow; }
447
448 // Parses the source code represented by the compilation info and sets its
449 // function literal. Returns false (and deallocates any allocated AST
450 // nodes) if parsing failed.
451 static bool Parse(CompilationInfo* info) { return Parser(info).Parse(); }
452 bool Parse();
453
437 // Returns NULL if parsing failed. 454 // Returns NULL if parsing failed.
438 FunctionLiteral* ParseProgram(); 455 FunctionLiteral* ParseProgram();
439 FunctionLiteral* ParseLazy();
440 456
441 void ReportMessageAt(Scanner::Location loc, 457 void ReportMessageAt(Scanner::Location loc,
442 const char* message, 458 const char* message,
443 Vector<const char*> args); 459 Vector<const char*> args);
444 void ReportMessageAt(Scanner::Location loc, 460 void ReportMessageAt(Scanner::Location loc,
445 const char* message, 461 const char* message,
446 Vector<Handle<String> > args); 462 Vector<Handle<String> > args);
447 463
448 private: 464 private:
449 static const int kMaxNumFunctionLocals = 131071; // 2^17-1 465 static const int kMaxNumFunctionLocals = 131071; // 2^17-1
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 } 559 }
544 ~ParsingModeScope() { 560 ~ParsingModeScope() {
545 parser_->mode_ = old_mode_; 561 parser_->mode_ = old_mode_;
546 } 562 }
547 563
548 private: 564 private:
549 Parser* parser_; 565 Parser* parser_;
550 Mode old_mode_; 566 Mode old_mode_;
551 }; 567 };
552 568
569 FunctionLiteral* ParseLazy();
553 FunctionLiteral* ParseLazy(Utf16CharacterStream* source, 570 FunctionLiteral* ParseLazy(Utf16CharacterStream* source,
554 ZoneScope* zone_scope); 571 ZoneScope* zone_scope);
555 572
556 Isolate* isolate() { return isolate_; } 573 Isolate* isolate() { return isolate_; }
557 Zone* zone() const { return zone_; } 574 Zone* zone() const { return zone_; }
558 CompilationInfo* info() const { return info_; } 575 CompilationInfo* info() const { return info_; }
559 576
560 // Called by ParseProgram after setting up the scanner. 577 // Called by ParseProgram after setting up the scanner.
561 FunctionLiteral* DoParseProgram(CompilationInfo* info, 578 FunctionLiteral* DoParseProgram(CompilationInfo* info,
562 Handle<String> source, 579 Handle<String> source,
563 ZoneScope* zone_scope); 580 ZoneScope* zone_scope);
564 581
565 // Report syntax error 582 // Report syntax error
566 void ReportUnexpectedToken(Token::Value token); 583 void ReportUnexpectedToken(Token::Value token);
567 void ReportInvalidPreparseData(Handle<String> name, bool* ok); 584 void ReportInvalidPreparseData(Handle<String> name, bool* ok);
568 void ReportMessage(const char* message, Vector<const char*> args); 585 void ReportMessage(const char* message, Vector<const char*> args);
569 void ReportMessage(const char* message, Vector<Handle<String> > args); 586 void ReportMessage(const char* message, Vector<Handle<String> > args);
570 587
588 void set_pre_parse_data(ScriptDataImpl *data) {
589 pre_parse_data_ = data;
590 symbol_cache_.Initialize(data ? data->symbol_count() : 0, zone());
591 }
592
571 bool inside_with() const { return top_scope_->inside_with(); } 593 bool inside_with() const { return top_scope_->inside_with(); }
572 Scanner& scanner() { return scanner_; } 594 Scanner& scanner() { return scanner_; }
573 Mode mode() const { return mode_; } 595 Mode mode() const { return mode_; }
574 ScriptDataImpl* pre_data() const { return pre_data_; } 596 ScriptDataImpl* pre_parse_data() const { return pre_parse_data_; }
575 bool is_extended_mode() { 597 bool is_extended_mode() {
576 ASSERT(top_scope_ != NULL); 598 ASSERT(top_scope_ != NULL);
577 return top_scope_->is_extended_mode(); 599 return top_scope_->is_extended_mode();
578 } 600 }
579 Scope* DeclarationScope(VariableMode mode) { 601 Scope* DeclarationScope(VariableMode mode) {
580 return IsLexicalVariableMode(mode) 602 return IsLexicalVariableMode(mode)
581 ? top_scope_ : top_scope_->DeclarationScope(); 603 ? top_scope_ : top_scope_->DeclarationScope();
582 } 604 }
583 605
584 // Check if the given string is 'eval' or 'arguments'. 606 // Check if the given string is 'eval' or 'arguments'.
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 Isolate* isolate_; 848 Isolate* isolate_;
827 ZoneList<Handle<String> > symbol_cache_; 849 ZoneList<Handle<String> > symbol_cache_;
828 850
829 Handle<Script> script_; 851 Handle<Script> script_;
830 Scanner scanner_; 852 Scanner scanner_;
831 preparser::PreParser* reusable_preparser_; 853 preparser::PreParser* reusable_preparser_;
832 Scope* top_scope_; 854 Scope* top_scope_;
833 FunctionState* current_function_state_; 855 FunctionState* current_function_state_;
834 Target* target_stack_; // for break, continue statements 856 Target* target_stack_; // for break, continue statements
835 v8::Extension* extension_; 857 v8::Extension* extension_;
836 ScriptDataImpl* pre_data_; 858 ScriptDataImpl* pre_parse_data_;
837 FuncNameInferrer* fni_; 859 FuncNameInferrer* fni_;
838 860
839 Mode mode_; 861 Mode mode_;
840 bool allow_natives_syntax_; 862 bool allow_natives_syntax_;
841 bool allow_lazy_; 863 bool allow_lazy_;
842 bool allow_modules_; 864 bool allow_generators_;
843 bool stack_overflow_; 865 bool stack_overflow_;
844 // If true, the next (and immediately following) function literal is 866 // If true, the next (and immediately following) function literal is
845 // preceded by a parenthesis. 867 // preceded by a parenthesis.
846 // Heuristically that means that the function will be called immediately, 868 // Heuristically that means that the function will be called immediately,
847 // so never lazily compile it. 869 // so never lazily compile it.
848 bool parenthesized_function_; 870 bool parenthesized_function_;
849 871
850 Zone* zone_; 872 Zone* zone_;
851 CompilationInfo* info_; 873 CompilationInfo* info_;
852 friend class BlockState; 874 friend class BlockState;
(...skipping 27 matching lines...) Expand all
880 private: 902 private:
881 static const int kTypeSlot = 0; 903 static const int kTypeSlot = 0;
882 static const int kElementsSlot = 1; 904 static const int kElementsSlot = 1;
883 905
884 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 906 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
885 }; 907 };
886 908
887 } } // namespace v8::internal 909 } } // namespace v8::internal
888 910
889 #endif // V8_PARSER_H_ 911 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/liveedit.cc ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698