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

Side by Side Diff: src/parser.h

Issue 1272673003: [es6] Re-implement rest parameters via desugaring. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rebase + fix brokenness Created 5 years, 3 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
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_PARSER_H_ 5 #ifndef V8_PARSER_H_
6 #define V8_PARSER_H_ 6 #define V8_PARSER_H_
7 7
8 #include "src/allocation.h" 8 #include "src/allocation.h"
9 #include "src/ast.h" 9 #include "src/ast.h"
10 #include "src/compiler.h" // TODO(titzer): remove this include dependency 10 #include "src/compiler.h" // TODO(titzer): remove this include dependency
(...skipping 962 matching lines...) Expand 10 before | Expand all | Expand 10 after
973 bool* ok); 973 bool* ok);
974 974
975 struct DeclarationDescriptor { 975 struct DeclarationDescriptor {
976 enum Kind { NORMAL, PARAMETER }; 976 enum Kind { NORMAL, PARAMETER };
977 Parser* parser; 977 Parser* parser;
978 Scope* declaration_scope; 978 Scope* declaration_scope;
979 Scope* scope; 979 Scope* scope;
980 Scope* hoist_scope; 980 Scope* hoist_scope;
981 VariableMode mode; 981 VariableMode mode;
982 bool is_const; 982 bool is_const;
983 bool is_rest;
983 bool needs_init; 984 bool needs_init;
984 int declaration_pos; 985 int declaration_pos;
985 int initialization_pos; 986 int initialization_pos;
986 Token::Value init_op; 987 Token::Value init_op;
987 Kind declaration_kind; 988 Kind declaration_kind;
988 }; 989 };
989 990
990 struct DeclarationParsingResult { 991 struct DeclarationParsingResult {
991 struct Declaration { 992 struct Declaration {
992 Declaration(Expression* pattern, int initializer_position, 993 Declaration(Expression* pattern, int initializer_position,
993 Expression* initializer) 994 Expression* initializer)
994 : pattern(pattern), 995 : pattern(pattern),
995 initializer_position(initializer_position), 996 initializer_position(initializer_position),
996 initializer(initializer) {} 997 initializer(initializer) {}
997 998
998 Expression* pattern; 999 Expression* pattern;
999 int initializer_position; 1000 int initializer_position;
1000 Expression* initializer; 1001 Expression* initializer;
1002 bool is_rest = false;
adamk 2015/08/28 23:26:37 Does this compile? I think this and the below shou
caitp (gmail) 2015/08/28 23:58:01 Compiles with clang version 3.8.0 (trunk 242792),
adamk 2015/08/29 01:01:07 Huh, I may just be out of date. Feel free to leave
caitp (gmail) 2015/08/29 15:51:59 It turns out these members were unused anyways, so
1003 int rest_literal_index = 0;
1001 }; 1004 };
1002 1005
1003 DeclarationParsingResult() 1006 DeclarationParsingResult()
1004 : declarations(4), 1007 : declarations(4),
1005 first_initializer_loc(Scanner::Location::invalid()), 1008 first_initializer_loc(Scanner::Location::invalid()),
1006 bindings_loc(Scanner::Location::invalid()) {} 1009 bindings_loc(Scanner::Location::invalid()) {}
1007 1010
1008 Block* BuildInitializationBlock(ZoneList<const AstRawString*>* names, 1011 Block* BuildInitializationBlock(ZoneList<const AstRawString*>* names,
1009 bool* ok); 1012 bool* ok);
1010 const AstRawString* SingleName() const; 1013 const AstRawString* SingleName() const;
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
1331 ParserFormalParameters::Parameter(name, pattern, initializer, is_rest), 1334 ParserFormalParameters::Parameter(name, pattern, initializer, is_rest),
1332 parameters->scope->zone()); 1335 parameters->scope->zone());
1333 } 1336 }
1334 1337
1335 1338
1336 void ParserTraits::DeclareFormalParameter( 1339 void ParserTraits::DeclareFormalParameter(
1337 Scope* scope, const ParserFormalParameters::Parameter& parameter, 1340 Scope* scope, const ParserFormalParameters::Parameter& parameter,
1338 ExpressionClassifier* classifier) { 1341 ExpressionClassifier* classifier) {
1339 bool is_duplicate = false; 1342 bool is_duplicate = false;
1340 bool is_simple = classifier->is_simple_parameter_list(); 1343 bool is_simple = classifier->is_simple_parameter_list();
1341 // TODO(caitp): Remove special handling for rest once desugaring is in. 1344 auto name = parameter.name;
1342 auto name = is_simple || parameter.is_rest 1345 auto mode = is_simple ? VAR : TEMPORARY;
1343 ? parameter.name : parser_->ast_value_factory()->empty_string();
1344 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY;
1345 if (!is_simple) scope->SetHasNonSimpleParameters(); 1346 if (!is_simple) scope->SetHasNonSimpleParameters();
1346 bool is_optional = parameter.initializer != nullptr; 1347 bool is_optional = parameter.initializer != nullptr;
1347 Variable* var = scope->DeclareParameter( 1348 Variable* var = scope->DeclareParameter(
1348 name, mode, is_optional, parameter.is_rest, &is_duplicate); 1349 name, mode, is_optional, parameter.is_rest, &is_duplicate);
1349 if (is_duplicate) { 1350 if (is_duplicate) {
1350 classifier->RecordDuplicateFormalParameterError( 1351 classifier->RecordDuplicateFormalParameterError(
1351 parser_->scanner()->location()); 1352 parser_->scanner()->location());
1352 } 1353 }
1353 if (is_sloppy(scope->language_mode())) { 1354 if (is_sloppy(scope->language_mode())) {
1354 // TODO(sigurds) Mark every parameter as maybe assigned. This is a 1355 // TODO(sigurds) Mark every parameter as maybe assigned. This is a
(...skipping 12 matching lines...) Expand all
1367 parser_->BuildParameterInitializationBlock(parameters, ok); 1368 parser_->BuildParameterInitializationBlock(parameters, ok);
1368 if (!*ok) return; 1369 if (!*ok) return;
1369 if (init_block != nullptr) { 1370 if (init_block != nullptr) {
1370 body->Add(init_block, parser_->zone()); 1371 body->Add(init_block, parser_->zone());
1371 } 1372 }
1372 } 1373 }
1373 } 1374 }
1374 } } // namespace v8::internal 1375 } } // namespace v8::internal
1375 1376
1376 #endif // V8_PARSER_H_ 1377 #endif // V8_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698