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

Side by Side Diff: src/parsing/preparse-data.h

Issue 2474393003: [parser] Give preparser and parser independent loggers (Closed)
Patch Set: The function scope is used by the preparser, so we don't need to set flags again Created 4 years, 1 month 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/parsing/parser-base.h ('k') | src/parsing/preparser.h » ('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 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
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 SingletonLogger final {
marja 2016/11/04 14:59:57 Now the names make less sense than before, how abo
50 class ParserRecorder {
51 public:
52 ParserRecorder() { }
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: 50 public:
76 SingletonLogger() 51 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 Reset() { has_error_ = false; }
87 61
88 virtual void LogFunction(int start, int end, int num_parameters, 62 void LogFunction(int start, int end, int num_parameters, int function_length,
89 int function_length, bool has_duplicate_parameters, 63 bool has_duplicate_parameters, int literals, int properties,
90 int literals, int properties, 64 LanguageMode language_mode, bool uses_super_property,
91 LanguageMode language_mode, bool uses_super_property, 65 bool calls_eval) {
92 bool calls_eval) {
93 DCHECK(!has_error_); 66 DCHECK(!has_error_);
94 // Check that we only log at most one function. 67 // Make sure we never nest function logging.
95 DCHECK(start_ == -1 && end_ == -1); 68 DCHECK_LT(end_, start);
96 start_ = start; 69 start_ = start;
97 end_ = end; 70 end_ = end;
98 num_parameters_ = num_parameters; 71 num_parameters_ = num_parameters;
99 function_length_ = function_length; 72 function_length_ = function_length;
100 has_duplicate_parameters_ = has_duplicate_parameters; 73 has_duplicate_parameters_ = has_duplicate_parameters;
101 literals_ = literals; 74 literals_ = literals;
102 properties_ = properties; 75 properties_ = properties;
103 language_mode_ = language_mode; 76 language_mode_ = language_mode;
104 uses_super_property_ = uses_super_property; 77 uses_super_property_ = uses_super_property;
105 calls_eval_ = calls_eval; 78 calls_eval_ = calls_eval;
106 } 79 }
107 80
108 // Logs an error message and marks the log as containing an error. 81 // Logs an error message and marks the log as containing an error.
109 // Further logging will be ignored, and ExtractData will return a vector 82 // Further logging will be ignored, and ExtractData will return a vector
110 // representing the error only. 83 // representing the error only.
111 virtual void LogMessage(int start, int end, MessageTemplate::Template message, 84 void LogMessage(int start, int end, MessageTemplate::Template message,
112 const char* argument_opt, ParseErrorType error_type) { 85 const char* argument_opt, ParseErrorType error_type) {
113 if (has_error_) return; 86 if (has_error_) return;
114 has_error_ = true; 87 has_error_ = true;
115 start_ = start; 88 start_ = start;
116 end_ = end; 89 end_ = end;
117 message_ = message; 90 message_ = message;
118 argument_opt_ = argument_opt; 91 argument_opt_ = argument_opt;
119 error_type_ = error_type; 92 error_type_ = error_type;
120 } 93 }
121 94
122 bool has_error() const { return has_error_; } 95 bool has_error() const { return has_error_; }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 int properties_; 153 int properties_;
181 LanguageMode language_mode_; 154 LanguageMode language_mode_;
182 bool uses_super_property_; 155 bool uses_super_property_;
183 bool calls_eval_; 156 bool calls_eval_;
184 // For error messages. 157 // For error messages.
185 MessageTemplate::Template message_; 158 MessageTemplate::Template message_;
186 const char* argument_opt_; 159 const char* argument_opt_;
187 ParseErrorType error_type_; 160 ParseErrorType error_type_;
188 }; 161 };
189 162
190 163 class CompleteParserRecorder final {
191 class CompleteParserRecorder : public ParserRecorder {
192 public: 164 public:
193 struct Key { 165 struct Key {
194 bool is_one_byte; 166 bool is_one_byte;
195 Vector<const byte> literal_bytes; 167 Vector<const byte> literal_bytes;
196 }; 168 };
197 169
198 CompleteParserRecorder(); 170 CompleteParserRecorder();
199 virtual ~CompleteParserRecorder() {}
200 171
201 virtual void LogFunction(int start, int end, int num_parameters, 172 void LogFunction(int start, int end, int num_parameters, int function_length,
202 int function_length, bool has_duplicate_parameters, 173 bool has_duplicate_parameters, int literals, int properties,
203 int literals, int properties, 174 LanguageMode language_mode, bool uses_super_property,
204 LanguageMode language_mode, bool uses_super_property, 175 bool calls_eval);
205 bool calls_eval);
206 176
207 // Logs an error message and marks the log as containing an error. 177 // Logs an error message and marks the log as containing an error.
208 // Further logging will be ignored, and ExtractData will return a vector 178 // Further logging will be ignored, and ExtractData will return a vector
209 // representing the error only. 179 // representing the error only.
210 virtual void LogMessage(int start, int end, MessageTemplate::Template message, 180 void LogMessage(int start, int end, MessageTemplate::Template message,
211 const char* argument_opt, ParseErrorType error_type); 181 const char* argument_opt, ParseErrorType error_type);
212 ScriptData* GetScriptData(); 182 ScriptData* GetScriptData();
213 183
214 bool HasError() { 184 bool HasError() {
215 return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]); 185 return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]);
216 } 186 }
217 Vector<unsigned> ErrorMessageData() { 187 Vector<unsigned> ErrorMessageData() {
218 DCHECK(HasError()); 188 DCHECK(HasError());
219 return function_store_.ToVector(); 189 return function_store_.ToVector();
220 } 190 }
221 191
222 private: 192 private:
223 void WriteString(Vector<const char> str); 193 void WriteString(Vector<const char> str);
224 194
225 Collector<unsigned> function_store_; 195 Collector<unsigned> function_store_;
226 unsigned preamble_[PreparseDataConstants::kHeaderSize]; 196 unsigned preamble_[PreparseDataConstants::kHeaderSize];
227 197
228 #ifdef DEBUG 198 #ifdef DEBUG
229 int prev_start_; 199 int prev_start_;
230 #endif 200 #endif
231 }; 201 };
232 202
233 203
234 } // namespace internal 204 } // namespace internal
235 } // namespace v8. 205 } // namespace v8.
236 206
237 #endif // V8_PARSING_PREPARSE_DATA_H_ 207 #endif // V8_PARSING_PREPARSE_DATA_H_
OLDNEW
« no previous file with comments | « src/parsing/parser-base.h ('k') | src/parsing/preparser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698