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

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

Issue 2472063002: Preparse lazy function parameters (Closed)
Patch Set: IsArrowFunction 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/preparse-data.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 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
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 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 start_(-1),
79 end_(-1),
80 num_parameters_(-1),
81 function_length_(-1),
82 has_duplicate_parameters_(false),
83 error_type_(kSyntaxError) {}
76 virtual ~SingletonLogger() {} 84 virtual ~SingletonLogger() {}
77 85
78 void Reset() { has_error_ = false; } 86 void Reset() { has_error_ = false; }
79 87
80 virtual void LogFunction(int start, int end, int literals, int properties, 88 virtual void LogFunction(int start, int end, int num_parameters,
89 int function_length, bool has_duplicate_parameters,
90 int literals, int properties,
81 LanguageMode language_mode, bool uses_super_property, 91 LanguageMode language_mode, bool uses_super_property,
82 bool calls_eval) { 92 bool calls_eval) {
83 DCHECK(!has_error_); 93 DCHECK(!has_error_);
84 // Check that we only log at most one function. 94 // Check that we only log at most one function.
85 DCHECK(start_ == -1 && end_ == -1); 95 DCHECK(start_ == -1 && end_ == -1);
86 start_ = start; 96 start_ = start;
87 end_ = end; 97 end_ = end;
98 num_parameters_ = num_parameters;
99 function_length_ = function_length;
100 has_duplicate_parameters_ = has_duplicate_parameters;
88 literals_ = literals; 101 literals_ = literals;
89 properties_ = properties; 102 properties_ = properties;
90 language_mode_ = language_mode; 103 language_mode_ = language_mode;
91 uses_super_property_ = uses_super_property; 104 uses_super_property_ = uses_super_property;
92 calls_eval_ = calls_eval; 105 calls_eval_ = calls_eval;
93 } 106 }
94 107
95 // Logs an error message and marks the log as containing an error. 108 // Logs an error message and marks the log as containing an error.
96 // Further logging will be ignored, and ExtractData will return a vector 109 // Further logging will be ignored, and ExtractData will return a vector
97 // representing the error only. 110 // representing the error only.
98 virtual void LogMessage(int start, int end, MessageTemplate::Template message, 111 virtual void LogMessage(int start, int end, MessageTemplate::Template message,
99 const char* argument_opt, ParseErrorType error_type) { 112 const char* argument_opt, ParseErrorType error_type) {
100 if (has_error_) return; 113 if (has_error_) return;
101 has_error_ = true; 114 has_error_ = true;
102 start_ = start; 115 start_ = start;
103 end_ = end; 116 end_ = end;
104 message_ = message; 117 message_ = message;
105 argument_opt_ = argument_opt; 118 argument_opt_ = argument_opt;
106 error_type_ = error_type; 119 error_type_ = error_type;
107 } 120 }
108 121
109 bool has_error() const { return has_error_; } 122 bool has_error() const { return has_error_; }
110 123
111 int start() const { return start_; } 124 int start() const { return start_; }
112 int end() const { return end_; } 125 int end() const { return end_; }
126 int num_parameters() const {
127 DCHECK(!has_error_);
128 return num_parameters_;
129 }
130 int function_length() const {
131 DCHECK(!has_error_);
132 return function_length_;
133 }
134 bool has_duplicate_parameters() const {
135 DCHECK(!has_error_);
136 return has_duplicate_parameters_;
137 }
113 int literals() const { 138 int literals() const {
114 DCHECK(!has_error_); 139 DCHECK(!has_error_);
115 return literals_; 140 return literals_;
116 } 141 }
117 int properties() const { 142 int properties() const {
118 DCHECK(!has_error_); 143 DCHECK(!has_error_);
119 return properties_; 144 return properties_;
120 } 145 }
121 LanguageMode language_mode() const { 146 LanguageMode language_mode() const {
122 DCHECK(!has_error_); 147 DCHECK(!has_error_);
(...skipping 18 matching lines...) Expand all
141 const char* argument_opt() const { 166 const char* argument_opt() const {
142 DCHECK(has_error_); 167 DCHECK(has_error_);
143 return argument_opt_; 168 return argument_opt_;
144 } 169 }
145 170
146 private: 171 private:
147 bool has_error_; 172 bool has_error_;
148 int start_; 173 int start_;
149 int end_; 174 int end_;
150 // For function entries. 175 // For function entries.
176 int num_parameters_;
177 int function_length_;
178 bool has_duplicate_parameters_;
151 int literals_; 179 int literals_;
152 int properties_; 180 int properties_;
153 LanguageMode language_mode_; 181 LanguageMode language_mode_;
154 bool uses_super_property_; 182 bool uses_super_property_;
155 bool calls_eval_; 183 bool calls_eval_;
156 // For error messages. 184 // For error messages.
157 MessageTemplate::Template message_; 185 MessageTemplate::Template message_;
158 const char* argument_opt_; 186 const char* argument_opt_;
159 ParseErrorType error_type_; 187 ParseErrorType error_type_;
160 }; 188 };
161 189
162 190
163 class CompleteParserRecorder : public ParserRecorder { 191 class CompleteParserRecorder : public ParserRecorder {
164 public: 192 public:
165 struct Key { 193 struct Key {
166 bool is_one_byte; 194 bool is_one_byte;
167 Vector<const byte> literal_bytes; 195 Vector<const byte> literal_bytes;
168 }; 196 };
169 197
170 CompleteParserRecorder(); 198 CompleteParserRecorder();
171 virtual ~CompleteParserRecorder() {} 199 virtual ~CompleteParserRecorder() {}
172 200
173 virtual void LogFunction(int start, int end, int literals, int properties, 201 virtual void LogFunction(int start, int end, int num_parameters,
202 int function_length, bool has_duplicate_parameters,
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);
176 function_store_.Add(start);
177 function_store_.Add(end);
178 function_store_.Add(literals);
179 function_store_.Add(properties);
180 function_store_.Add(language_mode);
181 function_store_.Add(uses_super_property);
182 function_store_.Add(calls_eval);
183 }
184 206
185 // Logs an error message and marks the log as containing an error. 207 // Logs an error message and marks the log as containing an error.
186 // Further logging will be ignored, and ExtractData will return a vector 208 // Further logging will be ignored, and ExtractData will return a vector
187 // representing the error only. 209 // representing the error only.
188 virtual void LogMessage(int start, int end, MessageTemplate::Template message, 210 virtual void LogMessage(int start, int end, MessageTemplate::Template message,
189 const char* argument_opt, ParseErrorType error_type); 211 const char* argument_opt, ParseErrorType error_type);
190 ScriptData* GetScriptData(); 212 ScriptData* GetScriptData();
191 213
192 bool HasError() { 214 bool HasError() {
193 return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]); 215 return static_cast<bool>(preamble_[PreparseDataConstants::kHasErrorOffset]);
(...skipping 12 matching lines...) Expand all
206 #ifdef DEBUG 228 #ifdef DEBUG
207 int prev_start_; 229 int prev_start_;
208 #endif 230 #endif
209 }; 231 };
210 232
211 233
212 } // namespace internal 234 } // namespace internal
213 } // namespace v8. 235 } // namespace v8.
214 236
215 #endif // V8_PARSING_PREPARSE_DATA_H_ 237 #endif // V8_PARSING_PREPARSE_DATA_H_
OLDNEW
« no previous file with comments | « src/parsing/parser-base.h ('k') | src/parsing/preparse-data.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698