OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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_PARSING_PREPARSE_DATA_H_ | 5 #ifndef V8_PARSING_PREPARSE_DATA_H_ |
6 #define V8_PARSING_PREPARSE_DATA_H_ | 6 #define V8_PARSING_PREPARSE_DATA_H_ |
7 | 7 |
8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
9 #include "src/base/hashmap.h" | 9 #include "src/base/hashmap.h" |
10 #include "src/collector.h" | 10 #include "src/collector.h" |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 private: | 40 private: |
41 bool owns_data_ : 1; | 41 bool owns_data_ : 1; |
42 bool rejected_ : 1; | 42 bool rejected_ : 1; |
43 const byte* data_; | 43 const byte* data_; |
44 int length_; | 44 int length_; |
45 | 45 |
46 DISALLOW_COPY_AND_ASSIGN(ScriptData); | 46 DISALLOW_COPY_AND_ASSIGN(ScriptData); |
47 }; | 47 }; |
48 | 48 |
49 // Abstract interface for preparse data recorder. | 49 class PreParserLogger final { |
50 class ParserRecorder { | |
51 public: | 50 public: |
52 ParserRecorder() { } | 51 PreParserLogger() |
53 virtual ~ParserRecorder() { } | |
54 | |
55 // Logs the scope and some details of a function literal in the source. | |
56 virtual void LogFunction(int start, int end, int num_parameters, | |
57 int function_length, bool has_duplicate_parameters, | |
58 int literals, int properties, | |
59 LanguageMode language_mode, bool uses_super_property, | |
60 bool calls_eval) = 0; | |
61 | |
62 // Logs an error message and marks the log as containing an error. | |
63 // Further logging will be ignored, and ExtractData will return a vector | |
64 // representing the error only. | |
65 virtual void LogMessage(int start, int end, MessageTemplate::Template message, | |
66 const char* argument_opt, | |
67 ParseErrorType error_type) = 0; | |
68 | |
69 private: | |
70 DISALLOW_COPY_AND_ASSIGN(ParserRecorder); | |
71 }; | |
72 | |
73 | |
74 class SingletonLogger : public ParserRecorder { | |
75 public: | |
76 SingletonLogger() | |
77 : has_error_(false), | 52 : has_error_(false), |
78 start_(-1), | 53 start_(-1), |
79 end_(-1), | 54 end_(-1), |
80 num_parameters_(-1), | 55 num_parameters_(-1), |
81 function_length_(-1), | 56 function_length_(-1), |
82 has_duplicate_parameters_(false), | 57 has_duplicate_parameters_(false), |
83 error_type_(kSyntaxError) {} | 58 error_type_(kSyntaxError) {} |
84 virtual ~SingletonLogger() {} | |
85 | 59 |
86 void Reset() { has_error_ = false; } | 60 void LogFunction(int end, int num_parameters, int function_length, |
87 | 61 bool has_duplicate_parameters, int literals, |
88 virtual void LogFunction(int start, int end, int num_parameters, | 62 int properties) { |
89 int function_length, bool has_duplicate_parameters, | |
90 int literals, int properties, | |
91 LanguageMode language_mode, bool uses_super_property, | |
92 bool calls_eval) { | |
93 DCHECK(!has_error_); | 63 DCHECK(!has_error_); |
94 // Check that we only log at most one function. | |
95 DCHECK(start_ == -1 && end_ == -1); | |
96 start_ = start; | |
97 end_ = end; | 64 end_ = end; |
98 num_parameters_ = num_parameters; | 65 num_parameters_ = num_parameters; |
99 function_length_ = function_length; | 66 function_length_ = function_length; |
100 has_duplicate_parameters_ = has_duplicate_parameters; | 67 has_duplicate_parameters_ = has_duplicate_parameters; |
101 literals_ = literals; | 68 literals_ = literals; |
102 properties_ = properties; | 69 properties_ = properties; |
103 language_mode_ = language_mode; | |
104 uses_super_property_ = uses_super_property; | |
105 calls_eval_ = calls_eval; | |
106 } | 70 } |
107 | 71 |
108 // Logs an error message and marks the log as containing an error. | 72 // Logs an error message and marks the log as containing an error. |
109 // Further logging will be ignored, and ExtractData will return a vector | 73 // Further logging will be ignored, and ExtractData will return a vector |
110 // representing the error only. | 74 // representing the error only. |
111 virtual void LogMessage(int start, int end, MessageTemplate::Template message, | 75 void LogMessage(int start, int end, MessageTemplate::Template message, |
112 const char* argument_opt, ParseErrorType error_type) { | 76 const char* argument_opt, ParseErrorType error_type) { |
113 if (has_error_) return; | 77 if (has_error_) return; |
114 has_error_ = true; | 78 has_error_ = true; |
115 start_ = start; | 79 start_ = start; |
116 end_ = end; | 80 end_ = end; |
117 message_ = message; | 81 message_ = message; |
118 argument_opt_ = argument_opt; | 82 argument_opt_ = argument_opt; |
119 error_type_ = error_type; | 83 error_type_ = error_type; |
120 } | 84 } |
121 | 85 |
122 bool has_error() const { return has_error_; } | 86 bool has_error() const { return has_error_; } |
(...skipping 13 matching lines...) Expand all Loading... |
136 return has_duplicate_parameters_; | 100 return has_duplicate_parameters_; |
137 } | 101 } |
138 int literals() const { | 102 int literals() const { |
139 DCHECK(!has_error_); | 103 DCHECK(!has_error_); |
140 return literals_; | 104 return literals_; |
141 } | 105 } |
142 int properties() const { | 106 int properties() const { |
143 DCHECK(!has_error_); | 107 DCHECK(!has_error_); |
144 return properties_; | 108 return properties_; |
145 } | 109 } |
146 LanguageMode language_mode() const { | |
147 DCHECK(!has_error_); | |
148 return language_mode_; | |
149 } | |
150 bool uses_super_property() const { | |
151 DCHECK(!has_error_); | |
152 return uses_super_property_; | |
153 } | |
154 bool calls_eval() const { | |
155 DCHECK(!has_error_); | |
156 return calls_eval_; | |
157 } | |
158 ParseErrorType error_type() const { | 110 ParseErrorType error_type() const { |
159 DCHECK(has_error_); | 111 DCHECK(has_error_); |
160 return error_type_; | 112 return error_type_; |
161 } | 113 } |
162 MessageTemplate::Template message() { | 114 MessageTemplate::Template message() { |
163 DCHECK(has_error_); | 115 DCHECK(has_error_); |
164 return message_; | 116 return message_; |
165 } | 117 } |
166 const char* argument_opt() const { | 118 const char* argument_opt() const { |
167 DCHECK(has_error_); | 119 DCHECK(has_error_); |
168 return argument_opt_; | 120 return argument_opt_; |
169 } | 121 } |
170 | 122 |
171 private: | 123 private: |
172 bool has_error_; | 124 bool has_error_; |
173 int start_; | 125 int start_; |
174 int end_; | 126 int end_; |
175 // For function entries. | 127 // For function entries. |
176 int num_parameters_; | 128 int num_parameters_; |
177 int function_length_; | 129 int function_length_; |
178 bool has_duplicate_parameters_; | 130 bool has_duplicate_parameters_; |
179 int literals_; | 131 int literals_; |
180 int properties_; | 132 int properties_; |
181 LanguageMode language_mode_; | |
182 bool uses_super_property_; | |
183 bool calls_eval_; | |
184 // For error messages. | 133 // For error messages. |
185 MessageTemplate::Template message_; | 134 MessageTemplate::Template message_; |
186 const char* argument_opt_; | 135 const char* argument_opt_; |
187 ParseErrorType error_type_; | 136 ParseErrorType error_type_; |
188 }; | 137 }; |
189 | 138 |
190 | 139 class ParserLogger final { |
191 class CompleteParserRecorder : public ParserRecorder { | |
192 public: | 140 public: |
193 struct Key { | 141 struct Key { |
194 bool is_one_byte; | 142 bool is_one_byte; |
195 Vector<const byte> literal_bytes; | 143 Vector<const byte> literal_bytes; |
196 }; | 144 }; |
197 | 145 |
198 CompleteParserRecorder(); | 146 ParserLogger(); |
199 virtual ~CompleteParserRecorder() {} | |
200 | 147 |
201 virtual void LogFunction(int start, int end, int num_parameters, | 148 void LogFunction(int start, int end, int num_parameters, int function_length, |
202 int function_length, bool has_duplicate_parameters, | 149 bool has_duplicate_parameters, int literals, int properties, |
203 int literals, int properties, | 150 LanguageMode language_mode, bool uses_super_property, |
204 LanguageMode language_mode, bool uses_super_property, | 151 bool calls_eval); |
205 bool calls_eval); | |
206 | 152 |
207 // Logs an error message and marks the log as containing an error. | 153 // Logs an error message and marks the log as containing an error. |
208 // Further logging will be ignored, and ExtractData will return a vector | 154 // Further logging will be ignored, and ExtractData will return a vector |
209 // representing the error only. | 155 // representing the error only. |
210 virtual void LogMessage(int start, int end, MessageTemplate::Template message, | 156 void LogMessage(int start, int end, MessageTemplate::Template message, |
211 const char* argument_opt, ParseErrorType error_type); | 157 const char* argument_opt, ParseErrorType error_type); |
212 ScriptData* GetScriptData(); | 158 ScriptData* GetScriptData(); |
213 | 159 |
214 bool HasError() { | 160 bool HasError() { |
215 return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]); | 161 return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]); |
216 } | 162 } |
217 Vector<unsigned> ErrorMessageData() { | 163 Vector<unsigned> ErrorMessageData() { |
218 DCHECK(HasError()); | 164 DCHECK(HasError()); |
219 return function_store_.ToVector(); | 165 return function_store_.ToVector(); |
220 } | 166 } |
221 | 167 |
222 private: | 168 private: |
223 void WriteString(Vector<const char> str); | 169 void WriteString(Vector<const char> str); |
224 | 170 |
225 Collector<unsigned> function_store_; | 171 Collector<unsigned> function_store_; |
226 unsigned preamble_[PreparseDataConstants::kHeaderSize]; | 172 unsigned preamble_[PreparseDataConstants::kHeaderSize]; |
227 | 173 |
228 #ifdef DEBUG | 174 #ifdef DEBUG |
229 int prev_start_; | 175 int prev_start_; |
230 #endif | 176 #endif |
231 }; | 177 }; |
232 | 178 |
233 | 179 |
234 } // namespace internal | 180 } // namespace internal |
235 } // namespace v8. | 181 } // namespace v8. |
236 | 182 |
237 #endif // V8_PARSING_PREPARSE_DATA_H_ | 183 #endif // V8_PARSING_PREPARSE_DATA_H_ |
OLD | NEW |