| 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_PARSING_PARSER_H_ | 5 #ifndef V8_PARSING_PARSER_H_ |
| 6 #define V8_PARSING_PARSER_H_ | 6 #define V8_PARSING_PARSER_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
| 10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
| (...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 public: | 328 public: |
| 329 struct Type { | 329 struct Type { |
| 330 // TODO(marja): To be removed. The Traits object should contain all the data | 330 // TODO(marja): To be removed. The Traits object should contain all the data |
| 331 // it needs. | 331 // it needs. |
| 332 typedef v8::internal::Parser* Parser; | 332 typedef v8::internal::Parser* Parser; |
| 333 | 333 |
| 334 typedef Variable GeneratorVariable; | 334 typedef Variable GeneratorVariable; |
| 335 | 335 |
| 336 typedef v8::internal::AstProperties AstProperties; | 336 typedef v8::internal::AstProperties AstProperties; |
| 337 | 337 |
| 338 typedef v8::internal::ExpressionClassifier<ParserTraits> | |
| 339 ExpressionClassifier; | |
| 340 | |
| 341 // Return types for traversing functions. | 338 // Return types for traversing functions. |
| 342 typedef const AstRawString* Identifier; | 339 typedef const AstRawString* Identifier; |
| 343 typedef v8::internal::Expression* Expression; | 340 typedef v8::internal::Expression* Expression; |
| 344 typedef Yield* YieldExpression; | 341 typedef Yield* YieldExpression; |
| 345 typedef v8::internal::FunctionLiteral* FunctionLiteral; | 342 typedef v8::internal::FunctionLiteral* FunctionLiteral; |
| 346 typedef v8::internal::ClassLiteral* ClassLiteral; | 343 typedef v8::internal::ClassLiteral* ClassLiteral; |
| 347 typedef v8::internal::Literal* Literal; | 344 typedef v8::internal::Literal* Literal; |
| 348 typedef ObjectLiteral::Property* ObjectLiteralProperty; | 345 typedef ObjectLiteral::Property* ObjectLiteralProperty; |
| 349 typedef ZoneList<v8::internal::Expression*>* ExpressionList; | 346 typedef ZoneList<v8::internal::Expression*>* ExpressionList; |
| 350 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; | 347 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 545 | 542 |
| 546 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, | 543 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, |
| 547 FunctionKind kind = kNormalFunction); | 544 FunctionKind kind = kNormalFunction); |
| 548 | 545 |
| 549 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, | 546 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, |
| 550 Expression* pattern, | 547 Expression* pattern, |
| 551 Expression* initializer, | 548 Expression* initializer, |
| 552 int initializer_end_position, bool is_rest); | 549 int initializer_end_position, bool is_rest); |
| 553 V8_INLINE void DeclareFormalParameter( | 550 V8_INLINE void DeclareFormalParameter( |
| 554 Scope* scope, const ParserFormalParameters::Parameter& parameter, | 551 Scope* scope, const ParserFormalParameters::Parameter& parameter, |
| 555 Type::ExpressionClassifier* classifier); | 552 ExpressionClassifier* classifier); |
| 556 void ParseArrowFunctionFormalParameters(ParserFormalParameters* parameters, | 553 void ParseArrowFunctionFormalParameters(ParserFormalParameters* parameters, |
| 557 Expression* params, | 554 Expression* params, |
| 558 const Scanner::Location& params_loc, | 555 const Scanner::Location& params_loc, |
| 559 bool* ok); | 556 bool* ok); |
| 560 void ParseArrowFunctionFormalParameterList( | 557 void ParseArrowFunctionFormalParameterList( |
| 561 ParserFormalParameters* parameters, Expression* params, | 558 ParserFormalParameters* parameters, Expression* params, |
| 562 const Scanner::Location& params_loc, | 559 const Scanner::Location& params_loc, |
| 563 Scanner::Location* duplicate_loc, bool* ok); | 560 Scanner::Location* duplicate_loc, bool* ok); |
| 564 | 561 |
| 565 V8_INLINE DoExpression* ParseDoExpression(bool* ok); | 562 V8_INLINE DoExpression* ParseDoExpression(bool* ok); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 int pos); | 636 int pos); |
| 640 V8_INLINE Expression* SpreadCallNew(Expression* function, | 637 V8_INLINE Expression* SpreadCallNew(Expression* function, |
| 641 ZoneList<v8::internal::Expression*>* args, | 638 ZoneList<v8::internal::Expression*>* args, |
| 642 int pos); | 639 int pos); |
| 643 | 640 |
| 644 // Rewrite all DestructuringAssignments in the current FunctionState. | 641 // Rewrite all DestructuringAssignments in the current FunctionState. |
| 645 V8_INLINE void RewriteDestructuringAssignments(); | 642 V8_INLINE void RewriteDestructuringAssignments(); |
| 646 | 643 |
| 647 V8_INLINE void QueueDestructuringAssignmentForRewriting( | 644 V8_INLINE void QueueDestructuringAssignmentForRewriting( |
| 648 Expression* assignment); | 645 Expression* assignment); |
| 649 V8_INLINE void QueueNonPatternForRewriting(Expression* expr); | |
| 650 | 646 |
| 651 void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property, | 647 void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property, |
| 652 const AstRawString* name); | 648 const AstRawString* name); |
| 653 | 649 |
| 654 void SetFunctionNameFromIdentifierRef(Expression* value, | 650 void SetFunctionNameFromIdentifierRef(Expression* value, |
| 655 Expression* identifier); | 651 Expression* identifier); |
| 656 | 652 |
| 657 // Rewrite expressions that are not used as patterns | 653 // Rewrite expressions that are not used as patterns |
| 658 V8_INLINE void RewriteNonPattern(Type::ExpressionClassifier* classifier, | 654 V8_INLINE Expression* RewriteNonPattern( |
| 659 bool* ok); | 655 Expression* expr, const ExpressionClassifier* classifier, bool* ok); |
| 660 | 656 V8_INLINE ObjectLiteralProperty* RewriteNonPatternObjectLiteralProperty( |
| 661 V8_INLINE Zone* zone() const; | 657 ObjectLiteralProperty* property, const ExpressionClassifier* classifier, |
| 662 | 658 bool* ok); |
| 663 V8_INLINE ZoneList<Expression*>* GetNonPatternList() const; | |
| 664 | 659 |
| 665 Expression* RewriteYieldStar( | 660 Expression* RewriteYieldStar( |
| 666 Expression* generator, Expression* expression, int pos); | 661 Expression* generator, Expression* expression, int pos); |
| 667 | 662 |
| 668 private: | 663 private: |
| 669 Parser* parser_; | 664 Parser* parser_; |
| 670 | 665 |
| 671 void BuildIteratorClose( | 666 void BuildIteratorClose( |
| 672 ZoneList<Statement*>* statements, Variable* iterator, | 667 ZoneList<Statement*>* statements, Variable* iterator, |
| 673 Expression* input, Variable* output); | 668 Expression* input, Variable* output); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 Scanner::Location bindings_loc; | 805 Scanner::Location bindings_loc; |
| 811 }; | 806 }; |
| 812 | 807 |
| 813 class PatternRewriter : private AstVisitor { | 808 class PatternRewriter : private AstVisitor { |
| 814 public: | 809 public: |
| 815 static void DeclareAndInitializeVariables( | 810 static void DeclareAndInitializeVariables( |
| 816 Block* block, const DeclarationDescriptor* declaration_descriptor, | 811 Block* block, const DeclarationDescriptor* declaration_descriptor, |
| 817 const DeclarationParsingResult::Declaration* declaration, | 812 const DeclarationParsingResult::Declaration* declaration, |
| 818 ZoneList<const AstRawString*>* names, bool* ok); | 813 ZoneList<const AstRawString*>* names, bool* ok); |
| 819 | 814 |
| 820 static void RewriteDestructuringAssignment(Parser* parser, | 815 static void RewriteDestructuringAssignment( |
| 821 RewritableExpression* expr, | 816 Parser* parser, RewritableAssignmentExpression* expr, Scope* Scope); |
| 822 Scope* Scope); | |
| 823 | 817 |
| 824 static Expression* RewriteDestructuringAssignment(Parser* parser, | 818 static Expression* RewriteDestructuringAssignment(Parser* parser, |
| 825 Assignment* assignment, | 819 Assignment* assignment, |
| 826 Scope* scope); | 820 Scope* scope); |
| 827 | 821 |
| 828 void set_initializer_position(int pos) { initializer_position_ = pos; } | 822 void set_initializer_position(int pos) { initializer_position_ = pos; } |
| 829 | 823 |
| 830 private: | 824 private: |
| 831 PatternRewriter() {} | 825 PatternRewriter() {} |
| 832 | 826 |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1028 ZoneList<v8::internal::Expression*>* args, int pos); | 1022 ZoneList<v8::internal::Expression*>* args, int pos); |
| 1029 | 1023 |
| 1030 void SetLanguageMode(Scope* scope, LanguageMode mode); | 1024 void SetLanguageMode(Scope* scope, LanguageMode mode); |
| 1031 void RaiseLanguageMode(LanguageMode mode); | 1025 void RaiseLanguageMode(LanguageMode mode); |
| 1032 | 1026 |
| 1033 V8_INLINE void RewriteDestructuringAssignments(); | 1027 V8_INLINE void RewriteDestructuringAssignments(); |
| 1034 | 1028 |
| 1035 friend class NonPatternRewriter; | 1029 friend class NonPatternRewriter; |
| 1036 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit); | 1030 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit); |
| 1037 | 1031 |
| 1038 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok); | 1032 V8_INLINE Expression* RewriteNonPattern( |
| 1033 Expression* expr, const ExpressionClassifier* classifier, bool* ok); |
| 1034 V8_INLINE ObjectLiteralProperty* RewriteNonPatternObjectLiteralProperty( |
| 1035 ObjectLiteralProperty* property, const ExpressionClassifier* classifier, |
| 1036 bool* ok); |
| 1039 | 1037 |
| 1040 friend class InitializerRewriter; | 1038 friend class InitializerRewriter; |
| 1041 void RewriteParameterInitializer(Expression* expr, Scope* scope); | 1039 void RewriteParameterInitializer(Expression* expr, Scope* scope); |
| 1042 | 1040 |
| 1043 Scanner scanner_; | 1041 Scanner scanner_; |
| 1044 PreParser* reusable_preparser_; | 1042 PreParser* reusable_preparser_; |
| 1045 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 1043 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
| 1046 Target* target_stack_; // for break, continue statements | 1044 Target* target_stack_; // for break, continue statements |
| 1047 ScriptCompiler::CompileOptions compile_options_; | 1045 ScriptCompiler::CompileOptions compile_options_; |
| 1048 ParseData* cached_parse_data_; | 1046 ParseData* cached_parse_data_; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 : parser_->ast_value_factory()->empty_string(); | 1177 : parser_->ast_value_factory()->empty_string(); |
| 1180 parameters->params.Add( | 1178 parameters->params.Add( |
| 1181 ParserFormalParameters::Parameter(name, pattern, initializer, | 1179 ParserFormalParameters::Parameter(name, pattern, initializer, |
| 1182 initializer_end_position, is_rest), | 1180 initializer_end_position, is_rest), |
| 1183 parameters->scope->zone()); | 1181 parameters->scope->zone()); |
| 1184 } | 1182 } |
| 1185 | 1183 |
| 1186 | 1184 |
| 1187 void ParserTraits::DeclareFormalParameter( | 1185 void ParserTraits::DeclareFormalParameter( |
| 1188 Scope* scope, const ParserFormalParameters::Parameter& parameter, | 1186 Scope* scope, const ParserFormalParameters::Parameter& parameter, |
| 1189 Type::ExpressionClassifier* classifier) { | 1187 ExpressionClassifier* classifier) { |
| 1190 bool is_duplicate = false; | 1188 bool is_duplicate = false; |
| 1191 bool is_simple = classifier->is_simple_parameter_list(); | 1189 bool is_simple = classifier->is_simple_parameter_list(); |
| 1192 auto name = is_simple || parameter.is_rest | 1190 auto name = is_simple || parameter.is_rest |
| 1193 ? parameter.name | 1191 ? parameter.name |
| 1194 : parser_->ast_value_factory()->empty_string(); | 1192 : parser_->ast_value_factory()->empty_string(); |
| 1195 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; | 1193 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; |
| 1196 if (!is_simple) scope->SetHasNonSimpleParameters(); | 1194 if (!is_simple) scope->SetHasNonSimpleParameters(); |
| 1197 bool is_optional = parameter.initializer != nullptr; | 1195 bool is_optional = parameter.initializer != nullptr; |
| 1198 Variable* var = scope->DeclareParameter( | 1196 Variable* var = scope->DeclareParameter( |
| 1199 name, mode, is_optional, parameter.is_rest, &is_duplicate); | 1197 name, mode, is_optional, parameter.is_rest, &is_duplicate); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1226 | 1224 |
| 1227 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { | 1225 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { |
| 1228 return parser_->ParseDoExpression(ok); | 1226 return parser_->ParseDoExpression(ok); |
| 1229 } | 1227 } |
| 1230 | 1228 |
| 1231 | 1229 |
| 1232 } // namespace internal | 1230 } // namespace internal |
| 1233 } // namespace v8 | 1231 } // namespace v8 |
| 1234 | 1232 |
| 1235 #endif // V8_PARSING_PARSER_H_ | 1233 #endif // V8_PARSING_PARSER_H_ |
| OLD | NEW |