| OLD | NEW |
| 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 957 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 968 ZoneList<const AstRawString*>* names, | 968 ZoneList<const AstRawString*>* names, |
| 969 bool* ok); | 969 bool* ok); |
| 970 | 970 |
| 971 struct DeclarationDescriptor { | 971 struct DeclarationDescriptor { |
| 972 enum Kind { NORMAL, PARAMETER }; | 972 enum Kind { NORMAL, PARAMETER }; |
| 973 Parser* parser; | 973 Parser* parser; |
| 974 Scope* declaration_scope; | 974 Scope* declaration_scope; |
| 975 Scope* scope; | 975 Scope* scope; |
| 976 VariableMode mode; | 976 VariableMode mode; |
| 977 bool is_const; | 977 bool is_const; |
| 978 bool is_rest; |
| 978 bool needs_init; | 979 bool needs_init; |
| 979 int declaration_pos; | 980 int declaration_pos; |
| 980 int initialization_pos; | 981 int initialization_pos; |
| 981 Token::Value init_op; | 982 Token::Value init_op; |
| 982 Kind declaration_kind; | 983 Kind declaration_kind; |
| 983 }; | 984 }; |
| 984 | 985 |
| 985 struct DeclarationParsingResult { | 986 struct DeclarationParsingResult { |
| 986 struct Declaration { | 987 struct Declaration { |
| 987 Declaration(Expression* pattern, int initializer_position, | 988 Declaration(Expression* pattern, int initializer_position, |
| 988 Expression* initializer) | 989 Expression* initializer) |
| 989 : pattern(pattern), | 990 : pattern(pattern), |
| 990 initializer_position(initializer_position), | 991 initializer_position(initializer_position), |
| 991 initializer(initializer) {} | 992 initializer(initializer) {} |
| 992 | 993 |
| 993 Expression* pattern; | 994 Expression* pattern; |
| 994 int initializer_position; | 995 int initializer_position; |
| 995 Expression* initializer; | 996 Expression* initializer; |
| 997 bool is_rest = false; |
| 998 int rest_literal_index = 0; |
| 996 }; | 999 }; |
| 997 | 1000 |
| 998 DeclarationParsingResult() | 1001 DeclarationParsingResult() |
| 999 : declarations(4), | 1002 : declarations(4), |
| 1000 first_initializer_loc(Scanner::Location::invalid()), | 1003 first_initializer_loc(Scanner::Location::invalid()), |
| 1001 bindings_loc(Scanner::Location::invalid()) {} | 1004 bindings_loc(Scanner::Location::invalid()) {} |
| 1002 | 1005 |
| 1003 Block* BuildInitializationBlock(ZoneList<const AstRawString*>* names, | 1006 Block* BuildInitializationBlock(ZoneList<const AstRawString*>* names, |
| 1004 bool* ok); | 1007 bool* ok); |
| 1005 const AstRawString* SingleName() const; | 1008 const AstRawString* SingleName() const; |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1307 | 1310 |
| 1308 | 1311 |
| 1309 Expression* ParserTraits::SpreadCallNew( | 1312 Expression* ParserTraits::SpreadCallNew( |
| 1310 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) { | 1313 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) { |
| 1311 return parser_->SpreadCallNew(function, args, pos); | 1314 return parser_->SpreadCallNew(function, args, pos); |
| 1312 } | 1315 } |
| 1313 | 1316 |
| 1314 | 1317 |
| 1315 void ParserTraits::AddFormalParameter( | 1318 void ParserTraits::AddFormalParameter( |
| 1316 ParserFormalParameters* parameters, Expression* pattern, bool is_rest) { | 1319 ParserFormalParameters* parameters, Expression* pattern, bool is_rest) { |
| 1317 bool is_simple = pattern->IsVariableProxy(); | 1320 bool is_simple = !is_rest && pattern->IsVariableProxy(); |
| 1318 DCHECK(parser_->allow_harmony_destructuring() || | 1321 DCHECK((!is_rest || parser_->allow_harmony_rest_parameters()) || |
| 1319 parser_->allow_harmony_rest_parameters() || is_simple); | 1322 (!is_simple && parser_->allow_harmony_destructuring()) || is_simple); |
| 1320 const AstRawString* name = is_simple | 1323 const AstRawString* name = is_simple |
| 1321 ? pattern->AsVariableProxy()->raw_name() | 1324 ? pattern->AsVariableProxy()->raw_name() |
| 1322 : parser_->ast_value_factory()->empty_string(); | 1325 : parser_->ast_value_factory()->empty_string(); |
| 1323 parameters->params.Add( | 1326 parameters->params.Add( |
| 1324 ParserFormalParameters::Parameter(name, pattern, is_rest), | 1327 ParserFormalParameters::Parameter(name, pattern, is_rest), |
| 1325 parameters->scope->zone()); | 1328 parameters->scope->zone()); |
| 1326 } | 1329 } |
| 1327 | 1330 |
| 1328 | 1331 |
| 1329 void ParserTraits::DeclareFormalParameter( | 1332 void ParserTraits::DeclareFormalParameter( |
| 1330 Scope* scope, const ParserFormalParameters::Parameter& parameter, | 1333 Scope* scope, const ParserFormalParameters::Parameter& parameter, |
| 1331 bool is_simple, ExpressionClassifier* classifier) { | 1334 bool is_simple, ExpressionClassifier* classifier) { |
| 1332 bool is_duplicate = false; | 1335 bool is_duplicate = false; |
| 1333 // TODO(caitp): Remove special handling for rest once desugaring is in. | 1336 auto name = |
| 1334 auto name = is_simple || parameter.is_rest | 1337 is_simple ? parameter.name : parser_->ast_value_factory()->empty_string(); |
| 1335 ? parameter.name : parser_->ast_value_factory()->empty_string(); | 1338 auto mode = is_simple ? VAR : TEMPORARY; |
| 1336 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; | |
| 1337 Variable* var = | 1339 Variable* var = |
| 1338 scope->DeclareParameter(name, mode, parameter.is_rest, &is_duplicate); | 1340 scope->DeclareParameter(name, mode, parameter.is_rest, &is_duplicate); |
| 1339 if (is_duplicate) { | 1341 if (is_duplicate) { |
| 1340 classifier->RecordDuplicateFormalParameterError( | 1342 classifier->RecordDuplicateFormalParameterError( |
| 1341 parser_->scanner()->location()); | 1343 parser_->scanner()->location()); |
| 1342 } | 1344 } |
| 1343 if (is_sloppy(scope->language_mode())) { | 1345 if (is_sloppy(scope->language_mode())) { |
| 1344 // TODO(sigurds) Mark every parameter as maybe assigned. This is a | 1346 // TODO(sigurds) Mark every parameter as maybe assigned. This is a |
| 1345 // conservative approximation necessary to account for parameters | 1347 // conservative approximation necessary to account for parameters |
| 1346 // that are assigned via the arguments array. | 1348 // that are assigned via the arguments array. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1357 parser_->BuildParameterInitializationBlock(parameters, ok); | 1359 parser_->BuildParameterInitializationBlock(parameters, ok); |
| 1358 if (!*ok) return; | 1360 if (!*ok) return; |
| 1359 if (init_block != nullptr) { | 1361 if (init_block != nullptr) { |
| 1360 body->Add(init_block, parser_->zone()); | 1362 body->Add(init_block, parser_->zone()); |
| 1361 } | 1363 } |
| 1362 } | 1364 } |
| 1363 } | 1365 } |
| 1364 } } // namespace v8::internal | 1366 } } // namespace v8::internal |
| 1365 | 1367 |
| 1366 #endif // V8_PARSER_H_ | 1368 #endif // V8_PARSER_H_ |
| OLD | NEW |