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

Side by Side Diff: src/preparser.h

Issue 387633003: Avoid temporary Vectors for arrow function parameter lists (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 5 months 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 | Annotate | Revision Log
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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_PREPARSER_H 5 #ifndef V8_PREPARSER_H
6 #define V8_PREPARSER_H 6 #define V8_PREPARSER_H
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/func-name-inferrer.h" 10 #include "src/func-name-inferrer.h"
(...skipping 1231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 int* expected_property_count, bool* ok) { 1242 int* expected_property_count, bool* ok) {
1243 UNREACHABLE(); 1243 UNREACHABLE();
1244 } 1244 }
1245 1245
1246 V8_INLINE PreParserStatementList 1246 V8_INLINE PreParserStatementList
1247 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos, 1247 ParseEagerFunctionBody(PreParserIdentifier function_name, int pos,
1248 Variable* fvar, Token::Value fvar_init_op, 1248 Variable* fvar, Token::Value fvar_init_op,
1249 bool is_generator, bool* ok); 1249 bool is_generator, bool* ok);
1250 1250
1251 // Utility functions 1251 // Utility functions
1252 Vector<PreParserIdentifier> ParameterListFromExpression( 1252 unsigned DeclareArrowParametersFromExpression(PreParserExpression expression,
1253 PreParserExpression expression, bool* ok) { 1253 PreParserScope* scope,
1254 Scanner::Location* dupe_loc,
1255 bool* ok) {
1254 // TODO(aperez): Detect duplicated identifiers in paramlists. 1256 // TODO(aperez): Detect duplicated identifiers in paramlists.
1255 *ok = expression.IsValidArrowParamList(); 1257 *ok = expression.IsValidArrowParamList();
1256 return Vector<PreParserIdentifier>::empty(); 1258 return 0;
1257 } 1259 }
1258 1260
1259 static AstValueFactory* ast_value_factory() { return NULL; } 1261 static AstValueFactory* ast_value_factory() { return NULL; }
1260 1262
1261 void CheckConflictingVarDeclarations(PreParserScope scope, bool* ok) {} 1263 void CheckConflictingVarDeclarations(PreParserScope scope, bool* ok) {}
1262 1264
1263 // Temporary glue; these functions will move to ParserBase. 1265 // Temporary glue; these functions will move to ParserBase.
1264 PreParserExpression ParseV8Intrinsic(bool* ok); 1266 PreParserExpression ParseV8Intrinsic(bool* ok);
1265 PreParserExpression ParseFunctionLiteral( 1267 PreParserExpression ParseFunctionLiteral(
1266 PreParserIdentifier name, 1268 PreParserIdentifier name,
(...skipping 1162 matching lines...) Expand 10 before | Expand all | Expand 10 after
2429 } 2431 }
2430 ASSERT(false); 2432 ASSERT(false);
2431 return this->EmptyExpression(); 2433 return this->EmptyExpression();
2432 } 2434 }
2433 2435
2434 2436
2435 template <class Traits> 2437 template <class Traits>
2436 typename ParserBase<Traits>::ExpressionT ParserBase< 2438 typename ParserBase<Traits>::ExpressionT ParserBase<
2437 Traits>::ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast, 2439 Traits>::ParseArrowFunctionLiteral(int start_pos, ExpressionT params_ast,
2438 bool* ok) { 2440 bool* ok) {
2439 typename Traits::Type::ParameterIdentifierVector params =
2440 Traits::ParameterListFromExpression(params_ast, ok);
2441
2442 if (!*ok) {
2443 ReportMessageAt(Scanner::Location(start_pos, scanner()->location().beg_pos),
2444 "malformed_arrow_function_parameter_list");
2445 params.Dispose();
2446 return this->EmptyExpression();
2447 }
2448
2449 // TODO(aperez): Change this to use ARROW_SCOPE 2441 // TODO(aperez): Change this to use ARROW_SCOPE
2450 typename Traits::Type::ScopePtr scope = 2442 typename Traits::Type::ScopePtr scope =
2451 this->NewScope(scope_, FUNCTION_SCOPE); 2443 this->NewScope(scope_, FUNCTION_SCOPE);
2452 2444
2453 FunctionState function_state(&function_state_, &scope_, &scope, zone(), 2445 FunctionState function_state(&function_state_, &scope_, &scope, zone(),
2454 this->ast_value_factory()); 2446 this->ast_value_factory());
2455 Scanner::Location dupe_error_loc = Scanner::Location::invalid(); 2447 Scanner::Location dupe_error_loc = Scanner::Location::invalid();
2448 unsigned num_params = Traits::DeclareArrowParametersFromExpression(
2449 params_ast, scope_, &dupe_error_loc, ok);
2450 if (!*ok) {
2451 ReportMessageAt(Scanner::Location(start_pos, scanner()->location().beg_pos),
2452 "malformed_arrow_function_parameter_list");
2453 return this->EmptyExpression();
2454 }
2456 2455
2457 if (params.length() > Code::kMaxArguments) { 2456 if (num_params > Code::kMaxArguments) {
2458 ReportMessageAt(Scanner::Location(params_ast->position(), position()), 2457 ReportMessageAt(Scanner::Location(params_ast->position(), position()),
2459 "too_many_parameters"); 2458 "too_many_parameters");
2460 *ok = false; 2459 *ok = false;
2461 params.Dispose();
2462 return this->EmptyExpression(); 2460 return this->EmptyExpression();
2463 } 2461 }
2464 2462
2465 for (int i = 0; i < params.length(); ++i) {
2466 const IdentifierT param_name = params.at(i)->raw_name();
2467 if (!dupe_error_loc.IsValid() && scope_->IsDeclared(param_name)) {
2468 int param_pos = params.at(i)->position();
2469 dupe_error_loc =
2470 Scanner::Location(param_pos, param_pos + param_name->length());
2471 }
2472 scope_->DeclareParameter(param_name, VAR);
2473 }
2474
2475 ExpressionT expression = ParseArrowFunctionLiteralBody( 2463 ExpressionT expression = ParseArrowFunctionLiteralBody(
2476 &function_state, scope, params.length(), Scanner::Location::invalid(), 2464 &function_state, scope, num_params, Scanner::Location::invalid(),
2477 dupe_error_loc, Scanner::Location::invalid(), 2465 dupe_error_loc, Scanner::Location::invalid(),
2478 FunctionLiteral::kNotParenthesized, start_pos, CHECK_OK); 2466 FunctionLiteral::kNotParenthesized, start_pos, CHECK_OK);
2479 params.Dispose();
2480 return expression; 2467 return expression;
2481 } 2468 }
2482 2469
2483 2470
2484 template <class Traits> 2471 template <class Traits>
2485 typename ParserBase<Traits>::ExpressionT 2472 typename ParserBase<Traits>::ExpressionT
2486 ParserBase<Traits>::ParseArrowFunctionLiteralBody( 2473 ParserBase<Traits>::ParseArrowFunctionLiteralBody(
2487 FunctionState* function_state, typename Traits::Type::ScopePtr scope, 2474 FunctionState* function_state, typename Traits::Type::ScopePtr scope,
2488 int num_parameters, const Scanner::Location& eval_args_error_loc, 2475 int num_parameters, const Scanner::Location& eval_args_error_loc,
2489 const Scanner::Location& dupe_error_loc, 2476 const Scanner::Location& dupe_error_loc,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
2602 parser()->ReportMessage("accessor_get_set"); 2589 parser()->ReportMessage("accessor_get_set");
2603 } 2590 }
2604 *ok = false; 2591 *ok = false;
2605 } 2592 }
2606 } 2593 }
2607 2594
2608 2595
2609 } } // v8::internal 2596 } } // v8::internal
2610 2597
2611 #endif // V8_PREPARSER_H 2598 #endif // V8_PREPARSER_H
OLDNEW
« no previous file with comments | « src/parser.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698