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

Side by Side Diff: src/parser.h

Issue 376223002: Refactor ScriptData class for cached compile data. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 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
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_PARSER_H_ 5 #ifndef V8_PARSER_H_
6 #define V8_PARSER_H_ 6 #define V8_PARSER_H_
7 7
8 #include "src/allocation.h" 8 #include "src/allocation.h"
9 #include "src/ast.h" 9 #include "src/ast.h"
10 #include "src/compiler.h" // For CachedDataMode 10 #include "src/compiler.h" // For CachedDataMode
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 return static_cast<StrictMode>(backing_[kStrictModeIndex]); 52 return static_cast<StrictMode>(backing_[kStrictModeIndex]);
53 } 53 }
54 54
55 bool is_valid() { return !backing_.is_empty(); } 55 bool is_valid() { return !backing_.is_empty(); }
56 56
57 private: 57 private:
58 Vector<unsigned> backing_; 58 Vector<unsigned> backing_;
59 }; 59 };
60 60
61 61
62 class ScriptData { 62 // Wrapper around ScriptData to provide parser-specific functionality,
vogelheim 2014/07/09 17:23:36 super nitpick: '.' instead of ','.
Yang 2014/07/10 08:28:46 Done.
63 class ParseData {
63 public: 64 public:
64 explicit ScriptData(Vector<unsigned> store) 65 explicit ParseData(ScriptData* script_data) : script_data_(script_data) {
65 : store_(store), 66 CHECK(IsAligned(script_data->length(), sizeof(unsigned)));
66 owns_store_(true) { } 67 CHECK(Sanity());
67 68 }
68 ScriptData(Vector<unsigned> store, bool owns_store)
69 : store_(store),
70 owns_store_(owns_store) { }
71
72 // The created ScriptData won't take ownership of the data. If the alignment
73 // is not correct, this will copy the data (and the created ScriptData will
74 // take ownership of the copy).
75 static ScriptData* New(const char* data, int length, bool owns_store = false);
76
77 virtual ~ScriptData();
78 virtual int Length();
79 virtual const char* Data();
80 virtual bool HasError();
81
82 void Initialize(); 69 void Initialize();
83 void ReadNextSymbolPosition();
84
85 FunctionEntry GetFunctionEntry(int start); 70 FunctionEntry GetFunctionEntry(int start);
86 int GetSymbolIdentifier(); 71 int GetSymbolIdentifier();
87 bool SanityCheck(); 72 int FunctionCount();
88 73
89 Scanner::Location MessageLocation() const; 74 Scanner::Location MessageLocation() const;
90 bool IsReferenceError() const; 75 bool IsReferenceError() const;
91 const char* BuildMessage() const; 76 const char* BuildMessage();
92 const char* BuildArg() const; 77 const char* BuildArg();
78 bool HasError() const;
93 79
94 int function_count() { 80 unsigned* Data() const { // Writable data as unsigned int array.
95 int functions_size = 81 return reinterpret_cast<unsigned*>(const_cast<byte*>(script_data_->data()));
vogelheim 2014/07/09 17:23:36 Why is this a const method? (I guess one can defi
Yang 2014/07/10 08:28:46 Done.
96 static_cast<int>(store_[PreparseDataConstants::kFunctionsSizeOffset]);
97 if (functions_size < 0) return 0;
98 if (functions_size % FunctionEntry::kSize != 0) return 0;
99 return functions_size / FunctionEntry::kSize;
100 } 82 }
101 // The following functions should only be called if SanityCheck has
102 // returned true.
103 bool has_error() { return store_[PreparseDataConstants::kHasErrorOffset]; }
104 unsigned magic() { return store_[PreparseDataConstants::kMagicOffset]; }
105 unsigned version() { return store_[PreparseDataConstants::kVersionOffset]; }
106 83
107 private: 84 private:
108 // Disable copying and assigning; because of owns_store they won't be correct. 85 bool Sanity();
vogelheim 2014/07/09 17:23:36 nitpick: IsSane() ? (I can see how CHECK(Sanity()
Yang 2014/07/10 08:28:46 Done.
109 ScriptData(const ScriptData&); 86 unsigned Magic() const;
110 ScriptData& operator=(const ScriptData&); 87 unsigned Version() const;
111 88 int FunctionsSize() const;
112 friend class v8::ScriptCompiler;
113 Vector<unsigned> store_;
114 unsigned char* symbol_data_;
115 unsigned char* symbol_data_end_;
116 int function_index_;
117 bool owns_store_;
118
119 unsigned Read(int position) const; 89 unsigned Read(int position) const;
120 unsigned* ReadAddress(int position) const; 90 unsigned* ReadAddress(int position) const;
121 // Reads a number from the current symbols
122 int ReadNumber(byte** source); 91 int ReadNumber(byte** source);
92 const char* ReadString(unsigned* start, int* chars);
93 int Length() const { return script_data_->length() / sizeof(unsigned); }
vogelheim 2014/07/09 17:23:36 nitpick: round up?
Yang 2014/07/10 08:28:46 No need. Sanity check makes sure the length is a m
123 94
124 // Read strings written by ParserRecorder::WriteString. 95 ScriptData* script_data_;
125 static const char* ReadString(unsigned* start, int* chars); 96 byte* symbol_data_;
97 byte* symbol_data_end_;
98 int function_index_;
99
100 DISALLOW_COPY_AND_ASSIGN(ParseData);
126 }; 101 };
127 102
128
129 // ---------------------------------------------------------------------------- 103 // ----------------------------------------------------------------------------
130 // REGEXP PARSING 104 // REGEXP PARSING
131 105
132 // A BufferedZoneList is an automatically growing list, just like (and backed 106 // A BufferedZoneList is an automatically growing list, just like (and backed
133 // by) a ZoneList, that is optimized for the case of adding and removing 107 // by) a ZoneList, that is optimized for the case of adding and removing
134 // a single element. The last element added is stored outside the backing list, 108 // a single element. The last element added is stored outside the backing list,
135 // and if no more than one element is ever added, the ZoneList isn't even 109 // and if no more than one element is ever added, the ZoneList isn't even
136 // allocated. 110 // allocated.
137 // Elements must not be NULL pointers. 111 // Elements must not be NULL pointers.
138 template <typename T, int initial_size> 112 template <typename T, int initial_size>
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after
639 FunctionLiteral* ParseLazy(); 613 FunctionLiteral* ParseLazy();
640 FunctionLiteral* ParseLazy(Utf16CharacterStream* source); 614 FunctionLiteral* ParseLazy(Utf16CharacterStream* source);
641 615
642 Isolate* isolate() { return isolate_; } 616 Isolate* isolate() { return isolate_; }
643 CompilationInfo* info() const { return info_; } 617 CompilationInfo* info() const { return info_; }
644 618
645 // Called by ParseProgram after setting up the scanner. 619 // Called by ParseProgram after setting up the scanner.
646 FunctionLiteral* DoParseProgram(CompilationInfo* info, 620 FunctionLiteral* DoParseProgram(CompilationInfo* info,
647 Handle<String> source); 621 Handle<String> source);
648 622
649 // Report syntax error 623 void SetCachedData();
650 void ReportInvalidCachedData(const AstRawString* name, bool* ok);
651
652 void SetCachedData(ScriptData** data,
653 CachedDataMode cached_data_mode) {
654 cached_data_mode_ = cached_data_mode;
655 if (cached_data_mode == NO_CACHED_DATA) {
656 cached_data_ = NULL;
657 } else {
658 ASSERT(data != NULL);
659 cached_data_ = data;
660 }
661 }
662 624
663 bool inside_with() const { return scope_->inside_with(); } 625 bool inside_with() const { return scope_->inside_with(); }
664 ScriptData** cached_data() const { return cached_data_; } 626 CachedDataMode cached_data_mode() const { return info_->cached_data_mode(); }
665 CachedDataMode cached_data_mode() const { return cached_data_mode_; }
666 Scope* DeclarationScope(VariableMode mode) { 627 Scope* DeclarationScope(VariableMode mode) {
667 return IsLexicalVariableMode(mode) 628 return IsLexicalVariableMode(mode)
668 ? scope_ : scope_->DeclarationScope(); 629 ? scope_ : scope_->DeclarationScope();
669 } 630 }
670 631
671 // All ParseXXX functions take as the last argument an *ok parameter 632 // All ParseXXX functions take as the last argument an *ok parameter
672 // which is set to false if parsing failed; it is unchanged otherwise. 633 // which is set to false if parsing failed; it is unchanged otherwise.
673 // By making the 'exception handling' explicit, we are forced to check 634 // By making the 'exception handling' explicit, we are forced to check
674 // for failure at the call sites. 635 // for failure at the call sites.
675 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token, 636 void* ParseSourceElements(ZoneList<Statement*>* processor, int end_token,
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 763
803 void InternalizeUseCounts(); 764 void InternalizeUseCounts();
804 765
805 Isolate* isolate_; 766 Isolate* isolate_;
806 767
807 Handle<Script> script_; 768 Handle<Script> script_;
808 Scanner scanner_; 769 Scanner scanner_;
809 PreParser* reusable_preparser_; 770 PreParser* reusable_preparser_;
810 Scope* original_scope_; // for ES5 function declarations in sloppy eval 771 Scope* original_scope_; // for ES5 function declarations in sloppy eval
811 Target* target_stack_; // for break, continue statements 772 Target* target_stack_; // for break, continue statements
812 ScriptData** cached_data_; 773 ParseData* cached_parse_data_;
813 CachedDataMode cached_data_mode_; 774 CachedDataMode cached_data_mode_;
814 AstValueFactory* ast_value_factory_; 775 AstValueFactory* ast_value_factory_;
815 776
816 CompilationInfo* info_; 777 CompilationInfo* info_;
817 778
818 // Pending errors. 779 // Pending errors.
819 bool has_pending_error_; 780 bool has_pending_error_;
820 Scanner::Location pending_error_location_; 781 Scanner::Location pending_error_location_;
821 const char* pending_error_message_; 782 const char* pending_error_message_;
822 const AstRawString* pending_error_arg_; 783 const AstRawString* pending_error_arg_;
(...skipping 28 matching lines...) Expand all
851 private: 812 private:
852 static const int kLiteralTypeSlot = 0; 813 static const int kLiteralTypeSlot = 0;
853 static const int kElementsSlot = 1; 814 static const int kElementsSlot = 1;
854 815
855 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 816 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
856 }; 817 };
857 818
858 } } // namespace v8::internal 819 } } // namespace v8::internal
859 820
860 #endif // V8_PARSER_H_ 821 #endif // V8_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698