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

Side by Side Diff: src/parsing/preparser.cc

Issue 2481163002: Assign unique IDs to FunctionLiterals (Closed)
Patch Set: updates Created 4 years 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
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 #include <cmath> 5 #include <cmath>
6 6
7 #include "src/allocation.h" 7 #include "src/allocation.h"
8 #include "src/base/logging.h" 8 #include "src/base/logging.h"
9 #include "src/conversions-inl.h" 9 #include "src/conversions-inl.h"
10 #include "src/conversions.h" 10 #include "src/conversions.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 85
86 PreParser::PreParseResult PreParser::PreParseFunction( 86 PreParser::PreParseResult PreParser::PreParseFunction(
87 FunctionKind kind, DeclarationScope* function_scope, bool parsing_module, 87 FunctionKind kind, DeclarationScope* function_scope, bool parsing_module,
88 bool is_inner_function, bool may_abort, int* use_counts) { 88 bool is_inner_function, bool may_abort, int* use_counts) {
89 DCHECK_EQ(FUNCTION_SCOPE, function_scope->scope_type()); 89 DCHECK_EQ(FUNCTION_SCOPE, function_scope->scope_type());
90 parsing_module_ = parsing_module; 90 parsing_module_ = parsing_module;
91 use_counts_ = use_counts; 91 use_counts_ = use_counts;
92 DCHECK(!track_unresolved_variables_); 92 DCHECK(!track_unresolved_variables_);
93 track_unresolved_variables_ = is_inner_function; 93 track_unresolved_variables_ = is_inner_function;
94 94
95 // In the preparser, we use the function literal ids to count how many
96 // FunctionLiterals were encountered. The PreParser doesn't actually persist
97 // FunctionLiterals, so there IDs don't matter.
98 ResetFunctionLiteralId();
99
95 // The caller passes the function_scope which is not yet inserted into the 100 // The caller passes the function_scope which is not yet inserted into the
96 // scope_state_. All scopes above the function_scope are ignored by the 101 // scope_state_. All scopes above the function_scope are ignored by the
97 // PreParser. 102 // PreParser.
98 DCHECK_NULL(scope_state_); 103 DCHECK_NULL(scope_state_);
99 FunctionState function_state(&function_state_, &scope_state_, function_scope); 104 FunctionState function_state(&function_state_, &scope_state_, function_scope);
100 // This indirection is needed so that we can use the CHECK_OK macros. 105 // This indirection is needed so that we can use the CHECK_OK macros.
101 bool ok_holder = true; 106 bool ok_holder = true;
102 bool* ok = &ok_holder; 107 bool* ok = &ok_holder;
103 108
104 PreParserFormalParameters formals(function_scope); 109 PreParserFormalParameters formals(function_scope);
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 runtime_call_stats_, 193 runtime_call_stats_,
189 counters[track_unresolved_variables_][parsing_on_main_thread_]); 194 counters[track_unresolved_variables_][parsing_on_main_thread_]);
190 195
191 // Parse function body. 196 // Parse function body.
192 PreParserStatementList body; 197 PreParserStatementList body;
193 DeclarationScope* function_scope = NewFunctionScope(kind); 198 DeclarationScope* function_scope = NewFunctionScope(kind);
194 function_scope->SetLanguageMode(language_mode); 199 function_scope->SetLanguageMode(language_mode);
195 FunctionState function_state(&function_state_, &scope_state_, function_scope); 200 FunctionState function_state(&function_state_, &scope_state_, function_scope);
196 DuplicateFinder duplicate_finder(scanner()->unicode_cache()); 201 DuplicateFinder duplicate_finder(scanner()->unicode_cache());
197 ExpressionClassifier formals_classifier(this, &duplicate_finder); 202 ExpressionClassifier formals_classifier(this, &duplicate_finder);
203 GetNextFunctionLiteralId();
198 204
199 Expect(Token::LPAREN, CHECK_OK); 205 Expect(Token::LPAREN, CHECK_OK);
200 int start_position = scanner()->location().beg_pos; 206 int start_position = scanner()->location().beg_pos;
201 function_scope->set_start_position(start_position); 207 function_scope->set_start_position(start_position);
202 PreParserFormalParameters formals(function_scope); 208 PreParserFormalParameters formals(function_scope);
203 ParseFormalParameterList(&formals, CHECK_OK); 209 ParseFormalParameterList(&formals, CHECK_OK);
204 Expect(Token::RPAREN, CHECK_OK); 210 Expect(Token::RPAREN, CHECK_OK);
205 int formals_end_position = scanner()->location().end_pos; 211 int formals_end_position = scanner()->location().end_pos;
206 212
207 CheckArityRestrictions(formals.arity, kind, formals.has_rest, start_position, 213 CheckArityRestrictions(formals.arity, kind, formals.has_rest, start_position,
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 bool may_abort, bool* ok) { 250 bool may_abort, bool* ok) {
245 PreParserStatementList body; 251 PreParserStatementList body;
246 LazyParsingResult result = ParseStatementList( 252 LazyParsingResult result = ParseStatementList(
247 body, Token::RBRACE, may_abort, CHECK_OK_VALUE(kLazyParsingComplete)); 253 body, Token::RBRACE, may_abort, CHECK_OK_VALUE(kLazyParsingComplete));
248 if (result == kLazyParsingAborted) return result; 254 if (result == kLazyParsingAborted) return result;
249 255
250 // Position right after terminal '}'. 256 // Position right after terminal '}'.
251 DCHECK_EQ(Token::RBRACE, scanner()->peek()); 257 DCHECK_EQ(Token::RBRACE, scanner()->peek());
252 int body_end = scanner()->peek_location().end_pos; 258 int body_end = scanner()->peek_location().end_pos;
253 DCHECK(this->scope()->is_function_scope()); 259 DCHECK(this->scope()->is_function_scope());
254 log_.LogFunction(body_end, formals->num_parameters(), 260 log_.LogFunction(
255 formals->function_length, has_duplicate_parameters, 261 body_end, formals->num_parameters(), formals->function_length,
256 function_state_->materialized_literal_count(), 262 has_duplicate_parameters, function_state_->materialized_literal_count(),
257 function_state_->expected_property_count()); 263 function_state_->expected_property_count(), GetLastFunctionLiteralId());
258 return kLazyParsingComplete; 264 return kLazyParsingComplete;
259 } 265 }
260 266
261 PreParserExpression PreParser::ExpressionFromIdentifier( 267 PreParserExpression PreParser::ExpressionFromIdentifier(
262 PreParserIdentifier name, int start_position, InferName infer) { 268 PreParserIdentifier name, int start_position, InferName infer) {
263 if (track_unresolved_variables_) { 269 if (track_unresolved_variables_) {
264 AstNodeFactory factory(ast_value_factory()); 270 AstNodeFactory factory(ast_value_factory());
265 // Setting the Zone is necessary because zone_ might be the temp Zone, and 271 // Setting the Zone is necessary because zone_ might be the temp Zone, and
266 // AstValueFactory doesn't know about it. 272 // AstValueFactory doesn't know about it.
267 factory.set_zone(zone()); 273 factory.set_zone(zone());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 } 306 }
301 } 307 }
302 } 308 }
303 309
304 #undef CHECK_OK 310 #undef CHECK_OK
305 #undef CHECK_OK_CUSTOM 311 #undef CHECK_OK_CUSTOM
306 312
307 313
308 } // namespace internal 314 } // namespace internal
309 } // namespace v8 315 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698