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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 DISALLOW_COPY_AND_ASSIGN(ScriptData); | 46 DISALLOW_COPY_AND_ASSIGN(ScriptData); |
47 }; | 47 }; |
48 | 48 |
49 // Abstract interface for preparse data recorder. | 49 // Abstract interface for preparse data recorder. |
50 class ParserRecorder { | 50 class ParserRecorder { |
51 public: | 51 public: |
52 ParserRecorder() { } | 52 ParserRecorder() { } |
53 virtual ~ParserRecorder() { } | 53 virtual ~ParserRecorder() { } |
54 | 54 |
55 // Logs the scope and some details of a function literal in the source. | 55 // Logs the scope and some details of a function literal in the source. |
56 virtual void LogFunction(int start, int end, int literals, int properties, | 56 virtual void LogFunction(int key, int start, int end, int num_parameters, |
| 57 int function_length, bool has_duplicate_parameters, |
| 58 int literals, int properties, |
57 LanguageMode language_mode, bool uses_super_property, | 59 LanguageMode language_mode, bool uses_super_property, |
58 bool calls_eval) = 0; | 60 bool calls_eval) = 0; |
59 | 61 |
60 // Logs an error message and marks the log as containing an error. | 62 // Logs an error message and marks the log as containing an error. |
61 // Further logging will be ignored, and ExtractData will return a vector | 63 // Further logging will be ignored, and ExtractData will return a vector |
62 // representing the error only. | 64 // representing the error only. |
63 virtual void LogMessage(int start, int end, MessageTemplate::Template message, | 65 virtual void LogMessage(int start, int end, MessageTemplate::Template message, |
64 const char* argument_opt, | 66 const char* argument_opt, |
65 ParseErrorType error_type) = 0; | 67 ParseErrorType error_type) = 0; |
66 | 68 |
67 private: | 69 private: |
68 DISALLOW_COPY_AND_ASSIGN(ParserRecorder); | 70 DISALLOW_COPY_AND_ASSIGN(ParserRecorder); |
69 }; | 71 }; |
70 | 72 |
71 | 73 |
72 class SingletonLogger : public ParserRecorder { | 74 class SingletonLogger : public ParserRecorder { |
73 public: | 75 public: |
74 SingletonLogger() | 76 SingletonLogger() |
75 : has_error_(false), start_(-1), end_(-1), error_type_(kSyntaxError) {} | 77 : has_error_(false), |
| 78 key_(-1), |
| 79 start_(-1), |
| 80 end_(-1), |
| 81 num_parameters_(-1), |
| 82 function_length_(-1), |
| 83 has_duplicate_parameters_(false), |
| 84 error_type_(kSyntaxError) {} |
76 virtual ~SingletonLogger() {} | 85 virtual ~SingletonLogger() {} |
77 | 86 |
78 void Reset() { has_error_ = false; } | 87 void Reset() { has_error_ = false; } |
79 | 88 |
80 virtual void LogFunction(int start, int end, int literals, int properties, | 89 virtual void LogFunction(int key, int start, int end, int num_parameters, |
| 90 int function_length, bool has_duplicate_parameters, |
| 91 int literals, int properties, |
81 LanguageMode language_mode, bool uses_super_property, | 92 LanguageMode language_mode, bool uses_super_property, |
82 bool calls_eval) { | 93 bool calls_eval) { |
83 DCHECK(!has_error_); | 94 DCHECK(!has_error_); |
84 // Check that we only log at most one function. | 95 // Check that we only log at most one function. |
85 DCHECK(start_ == -1 && end_ == -1); | 96 DCHECK(start_ == -1 && end_ == -1); |
| 97 key_ = key; |
86 start_ = start; | 98 start_ = start; |
87 end_ = end; | 99 end_ = end; |
| 100 num_parameters_ = num_parameters; |
| 101 function_length_ = function_length; |
| 102 has_duplicate_parameters_ = has_duplicate_parameters; |
88 literals_ = literals; | 103 literals_ = literals; |
89 properties_ = properties; | 104 properties_ = properties; |
90 language_mode_ = language_mode; | 105 language_mode_ = language_mode; |
91 uses_super_property_ = uses_super_property; | 106 uses_super_property_ = uses_super_property; |
92 calls_eval_ = calls_eval; | 107 calls_eval_ = calls_eval; |
93 } | 108 } |
94 | 109 |
95 // Logs an error message and marks the log as containing an error. | 110 // Logs an error message and marks the log as containing an error. |
96 // Further logging will be ignored, and ExtractData will return a vector | 111 // Further logging will be ignored, and ExtractData will return a vector |
97 // representing the error only. | 112 // representing the error only. |
98 virtual void LogMessage(int start, int end, MessageTemplate::Template message, | 113 virtual void LogMessage(int start, int end, MessageTemplate::Template message, |
99 const char* argument_opt, ParseErrorType error_type) { | 114 const char* argument_opt, ParseErrorType error_type) { |
100 if (has_error_) return; | 115 if (has_error_) return; |
101 has_error_ = true; | 116 has_error_ = true; |
102 start_ = start; | 117 start_ = start; |
103 end_ = end; | 118 end_ = end; |
104 message_ = message; | 119 message_ = message; |
105 argument_opt_ = argument_opt; | 120 argument_opt_ = argument_opt; |
106 error_type_ = error_type; | 121 error_type_ = error_type; |
107 } | 122 } |
108 | 123 |
109 bool has_error() const { return has_error_; } | 124 bool has_error() const { return has_error_; } |
110 | 125 |
111 int start() const { return start_; } | 126 int start() const { return start_; } |
112 int end() const { return end_; } | 127 int end() const { return end_; } |
| 128 int num_parameters() const { |
| 129 DCHECK(!has_error_); |
| 130 return num_parameters_; |
| 131 } |
| 132 int function_length() const { |
| 133 DCHECK(!has_error_); |
| 134 return function_length_; |
| 135 } |
| 136 bool has_duplicate_parameters() const { |
| 137 DCHECK(!has_error_); |
| 138 return has_duplicate_parameters_; |
| 139 } |
113 int literals() const { | 140 int literals() const { |
114 DCHECK(!has_error_); | 141 DCHECK(!has_error_); |
115 return literals_; | 142 return literals_; |
116 } | 143 } |
117 int properties() const { | 144 int properties() const { |
118 DCHECK(!has_error_); | 145 DCHECK(!has_error_); |
119 return properties_; | 146 return properties_; |
120 } | 147 } |
121 LanguageMode language_mode() const { | 148 LanguageMode language_mode() const { |
122 DCHECK(!has_error_); | 149 DCHECK(!has_error_); |
(...skipping 15 matching lines...) Expand all Loading... |
138 DCHECK(has_error_); | 165 DCHECK(has_error_); |
139 return message_; | 166 return message_; |
140 } | 167 } |
141 const char* argument_opt() const { | 168 const char* argument_opt() const { |
142 DCHECK(has_error_); | 169 DCHECK(has_error_); |
143 return argument_opt_; | 170 return argument_opt_; |
144 } | 171 } |
145 | 172 |
146 private: | 173 private: |
147 bool has_error_; | 174 bool has_error_; |
| 175 int key_; |
148 int start_; | 176 int start_; |
149 int end_; | 177 int end_; |
150 // For function entries. | 178 // For function entries. |
| 179 int num_parameters_; |
| 180 int function_length_; |
| 181 bool has_duplicate_parameters_; |
151 int literals_; | 182 int literals_; |
152 int properties_; | 183 int properties_; |
153 LanguageMode language_mode_; | 184 LanguageMode language_mode_; |
154 bool uses_super_property_; | 185 bool uses_super_property_; |
155 bool calls_eval_; | 186 bool calls_eval_; |
156 // For error messages. | 187 // For error messages. |
157 MessageTemplate::Template message_; | 188 MessageTemplate::Template message_; |
158 const char* argument_opt_; | 189 const char* argument_opt_; |
159 ParseErrorType error_type_; | 190 ParseErrorType error_type_; |
160 }; | 191 }; |
161 | 192 |
162 | 193 |
163 class CompleteParserRecorder : public ParserRecorder { | 194 class CompleteParserRecorder : public ParserRecorder { |
164 public: | 195 public: |
165 struct Key { | 196 struct Key { |
166 bool is_one_byte; | 197 bool is_one_byte; |
167 Vector<const byte> literal_bytes; | 198 Vector<const byte> literal_bytes; |
168 }; | 199 }; |
169 | 200 |
170 CompleteParserRecorder(); | 201 CompleteParserRecorder(); |
171 virtual ~CompleteParserRecorder() {} | 202 virtual ~CompleteParserRecorder() {} |
172 | 203 |
173 virtual void LogFunction(int start, int end, int literals, int properties, | 204 virtual void LogFunction(int key, int start, int end, int num_parameters, |
| 205 int function_length, bool has_duplicate_parameters, |
| 206 int literals, int properties, |
174 LanguageMode language_mode, bool uses_super_property, | 207 LanguageMode language_mode, bool uses_super_property, |
175 bool calls_eval) { | 208 bool calls_eval) { |
| 209 function_store_.Add(key); |
176 function_store_.Add(start); | 210 function_store_.Add(start); |
177 function_store_.Add(end); | 211 function_store_.Add(end); |
| 212 function_store_.Add(num_parameters); |
| 213 function_store_.Add(function_length); |
| 214 function_store_.Add(has_duplicate_parameters); |
178 function_store_.Add(literals); | 215 function_store_.Add(literals); |
179 function_store_.Add(properties); | 216 function_store_.Add(properties); |
180 function_store_.Add(language_mode); | 217 function_store_.Add(language_mode); |
181 function_store_.Add(uses_super_property); | 218 function_store_.Add(uses_super_property); |
182 function_store_.Add(calls_eval); | 219 function_store_.Add(calls_eval); |
183 } | 220 } |
184 | 221 |
185 // Logs an error message and marks the log as containing an error. | 222 // Logs an error message and marks the log as containing an error. |
186 // Further logging will be ignored, and ExtractData will return a vector | 223 // Further logging will be ignored, and ExtractData will return a vector |
187 // representing the error only. | 224 // representing the error only. |
(...skipping 18 matching lines...) Expand all Loading... |
206 #ifdef DEBUG | 243 #ifdef DEBUG |
207 int prev_start_; | 244 int prev_start_; |
208 #endif | 245 #endif |
209 }; | 246 }; |
210 | 247 |
211 | 248 |
212 } // namespace internal | 249 } // namespace internal |
213 } // namespace v8. | 250 } // namespace v8. |
214 | 251 |
215 #endif // V8_PARSING_PREPARSE_DATA_H_ | 252 #endif // V8_PARSING_PREPARSE_DATA_H_ |
OLD | NEW |