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 |
338 // Return types for traversing functions. | 341 // Return types for traversing functions. |
339 typedef const AstRawString* Identifier; | 342 typedef const AstRawString* Identifier; |
340 typedef v8::internal::Expression* Expression; | 343 typedef v8::internal::Expression* Expression; |
341 typedef Yield* YieldExpression; | 344 typedef Yield* YieldExpression; |
342 typedef v8::internal::FunctionLiteral* FunctionLiteral; | 345 typedef v8::internal::FunctionLiteral* FunctionLiteral; |
343 typedef v8::internal::ClassLiteral* ClassLiteral; | 346 typedef v8::internal::ClassLiteral* ClassLiteral; |
344 typedef v8::internal::Literal* Literal; | 347 typedef v8::internal::Literal* Literal; |
345 typedef ObjectLiteral::Property* ObjectLiteralProperty; | 348 typedef ObjectLiteral::Property* ObjectLiteralProperty; |
346 typedef ZoneList<v8::internal::Expression*>* ExpressionList; | 349 typedef ZoneList<v8::internal::Expression*>* ExpressionList; |
347 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; | 350 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
540 | 543 |
541 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, | 544 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, |
542 FunctionKind kind = kNormalFunction); | 545 FunctionKind kind = kNormalFunction); |
543 | 546 |
544 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, | 547 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, |
545 Expression* pattern, | 548 Expression* pattern, |
546 Expression* initializer, | 549 Expression* initializer, |
547 int initializer_end_position, bool is_rest); | 550 int initializer_end_position, bool is_rest); |
548 V8_INLINE void DeclareFormalParameter( | 551 V8_INLINE void DeclareFormalParameter( |
549 Scope* scope, const ParserFormalParameters::Parameter& parameter, | 552 Scope* scope, const ParserFormalParameters::Parameter& parameter, |
550 ExpressionClassifier* classifier); | 553 Type::ExpressionClassifier* classifier); |
551 void ParseArrowFunctionFormalParameters(ParserFormalParameters* parameters, | 554 void ParseArrowFunctionFormalParameters(ParserFormalParameters* parameters, |
552 Expression* params, | 555 Expression* params, |
553 const Scanner::Location& params_loc, | 556 const Scanner::Location& params_loc, |
554 bool* ok); | 557 bool* ok); |
555 void ParseArrowFunctionFormalParameterList( | 558 void ParseArrowFunctionFormalParameterList( |
556 ParserFormalParameters* parameters, Expression* params, | 559 ParserFormalParameters* parameters, Expression* params, |
557 const Scanner::Location& params_loc, | 560 const Scanner::Location& params_loc, |
558 Scanner::Location* duplicate_loc, bool* ok); | 561 Scanner::Location* duplicate_loc, bool* ok); |
559 | 562 |
560 V8_INLINE DoExpression* ParseDoExpression(bool* ok); | 563 V8_INLINE DoExpression* ParseDoExpression(bool* ok); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 int pos); | 638 int pos); |
636 V8_INLINE Expression* SpreadCallNew(Expression* function, | 639 V8_INLINE Expression* SpreadCallNew(Expression* function, |
637 ZoneList<v8::internal::Expression*>* args, | 640 ZoneList<v8::internal::Expression*>* args, |
638 int pos); | 641 int pos); |
639 | 642 |
640 // Rewrite all DestructuringAssignments in the current FunctionState. | 643 // Rewrite all DestructuringAssignments in the current FunctionState. |
641 V8_INLINE void RewriteDestructuringAssignments(); | 644 V8_INLINE void RewriteDestructuringAssignments(); |
642 | 645 |
643 V8_INLINE void QueueDestructuringAssignmentForRewriting( | 646 V8_INLINE void QueueDestructuringAssignmentForRewriting( |
644 Expression* assignment); | 647 Expression* assignment); |
| 648 V8_INLINE void QueueNonPatternForRewriting(Expression* expr); |
645 | 649 |
646 void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property, | 650 void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property, |
647 const AstRawString* name); | 651 const AstRawString* name); |
648 | 652 |
649 void SetFunctionNameFromIdentifierRef(Expression* value, | 653 void SetFunctionNameFromIdentifierRef(Expression* value, |
650 Expression* identifier); | 654 Expression* identifier); |
651 | 655 |
652 // Rewrite expressions that are not used as patterns | 656 // Rewrite expressions that are not used as patterns |
653 V8_INLINE Expression* RewriteNonPattern( | 657 V8_INLINE void RewriteNonPattern(Type::ExpressionClassifier* classifier, |
654 Expression* expr, const ExpressionClassifier* classifier, bool* ok); | 658 bool* ok); |
655 V8_INLINE ObjectLiteralProperty* RewriteNonPatternObjectLiteralProperty( | 659 |
656 ObjectLiteralProperty* property, const ExpressionClassifier* classifier, | 660 V8_INLINE Zone* zone() const; |
657 bool* ok); | 661 |
| 662 V8_INLINE ZoneList<Expression*>* GetNonPatternList() const; |
658 | 663 |
659 Expression* RewriteYieldStar( | 664 Expression* RewriteYieldStar( |
660 Expression* generator, Expression* expression, int pos); | 665 Expression* generator, Expression* expression, int pos); |
661 | 666 |
662 private: | 667 private: |
663 Parser* parser_; | 668 Parser* parser_; |
664 | 669 |
665 void BuildIteratorClose(ZoneList<Statement*>* statements, Variable* iterator, | 670 void BuildIteratorClose(ZoneList<Statement*>* statements, Variable* iterator, |
666 Maybe<Variable*> input, Maybe<Variable*> output); | 671 Maybe<Variable*> input, Maybe<Variable*> output); |
667 }; | 672 }; |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
800 Scanner::Location bindings_loc; | 805 Scanner::Location bindings_loc; |
801 }; | 806 }; |
802 | 807 |
803 class PatternRewriter : private AstVisitor { | 808 class PatternRewriter : private AstVisitor { |
804 public: | 809 public: |
805 static void DeclareAndInitializeVariables( | 810 static void DeclareAndInitializeVariables( |
806 Block* block, const DeclarationDescriptor* declaration_descriptor, | 811 Block* block, const DeclarationDescriptor* declaration_descriptor, |
807 const DeclarationParsingResult::Declaration* declaration, | 812 const DeclarationParsingResult::Declaration* declaration, |
808 ZoneList<const AstRawString*>* names, bool* ok); | 813 ZoneList<const AstRawString*>* names, bool* ok); |
809 | 814 |
810 static void RewriteDestructuringAssignment( | 815 static void RewriteDestructuringAssignment(Parser* parser, |
811 Parser* parser, RewritableAssignmentExpression* expr, Scope* Scope); | 816 RewritableExpression* expr, |
| 817 Scope* Scope); |
812 | 818 |
813 static Expression* RewriteDestructuringAssignment(Parser* parser, | 819 static Expression* RewriteDestructuringAssignment(Parser* parser, |
814 Assignment* assignment, | 820 Assignment* assignment, |
815 Scope* scope); | 821 Scope* scope); |
816 | 822 |
817 void set_initializer_position(int pos) { initializer_position_ = pos; } | 823 void set_initializer_position(int pos) { initializer_position_ = pos; } |
818 | 824 |
819 private: | 825 private: |
820 PatternRewriter() {} | 826 PatternRewriter() {} |
821 | 827 |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1018 ZoneList<v8::internal::Expression*>* args, int pos); | 1024 ZoneList<v8::internal::Expression*>* args, int pos); |
1019 | 1025 |
1020 void SetLanguageMode(Scope* scope, LanguageMode mode); | 1026 void SetLanguageMode(Scope* scope, LanguageMode mode); |
1021 void RaiseLanguageMode(LanguageMode mode); | 1027 void RaiseLanguageMode(LanguageMode mode); |
1022 | 1028 |
1023 V8_INLINE void RewriteDestructuringAssignments(); | 1029 V8_INLINE void RewriteDestructuringAssignments(); |
1024 | 1030 |
1025 friend class NonPatternRewriter; | 1031 friend class NonPatternRewriter; |
1026 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit); | 1032 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit); |
1027 | 1033 |
1028 V8_INLINE Expression* RewriteNonPattern( | 1034 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok); |
1029 Expression* expr, const ExpressionClassifier* classifier, bool* ok); | |
1030 V8_INLINE ObjectLiteralProperty* RewriteNonPatternObjectLiteralProperty( | |
1031 ObjectLiteralProperty* property, const ExpressionClassifier* classifier, | |
1032 bool* ok); | |
1033 | 1035 |
1034 friend class InitializerRewriter; | 1036 friend class InitializerRewriter; |
1035 void RewriteParameterInitializer(Expression* expr, Scope* scope); | 1037 void RewriteParameterInitializer(Expression* expr, Scope* scope); |
1036 | 1038 |
1037 Scanner scanner_; | 1039 Scanner scanner_; |
1038 PreParser* reusable_preparser_; | 1040 PreParser* reusable_preparser_; |
1039 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 1041 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
1040 Target* target_stack_; // for break, continue statements | 1042 Target* target_stack_; // for break, continue statements |
1041 ScriptCompiler::CompileOptions compile_options_; | 1043 ScriptCompiler::CompileOptions compile_options_; |
1042 ParseData* cached_parse_data_; | 1044 ParseData* cached_parse_data_; |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 : parser_->ast_value_factory()->empty_string(); | 1175 : parser_->ast_value_factory()->empty_string(); |
1174 parameters->params.Add( | 1176 parameters->params.Add( |
1175 ParserFormalParameters::Parameter(name, pattern, initializer, | 1177 ParserFormalParameters::Parameter(name, pattern, initializer, |
1176 initializer_end_position, is_rest), | 1178 initializer_end_position, is_rest), |
1177 parameters->scope->zone()); | 1179 parameters->scope->zone()); |
1178 } | 1180 } |
1179 | 1181 |
1180 | 1182 |
1181 void ParserTraits::DeclareFormalParameter( | 1183 void ParserTraits::DeclareFormalParameter( |
1182 Scope* scope, const ParserFormalParameters::Parameter& parameter, | 1184 Scope* scope, const ParserFormalParameters::Parameter& parameter, |
1183 ExpressionClassifier* classifier) { | 1185 Type::ExpressionClassifier* classifier) { |
1184 bool is_duplicate = false; | 1186 bool is_duplicate = false; |
1185 bool is_simple = classifier->is_simple_parameter_list(); | 1187 bool is_simple = classifier->is_simple_parameter_list(); |
1186 auto name = is_simple || parameter.is_rest | 1188 auto name = is_simple || parameter.is_rest |
1187 ? parameter.name | 1189 ? parameter.name |
1188 : parser_->ast_value_factory()->empty_string(); | 1190 : parser_->ast_value_factory()->empty_string(); |
1189 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; | 1191 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; |
1190 if (!is_simple) scope->SetHasNonSimpleParameters(); | 1192 if (!is_simple) scope->SetHasNonSimpleParameters(); |
1191 bool is_optional = parameter.initializer != nullptr; | 1193 bool is_optional = parameter.initializer != nullptr; |
1192 Variable* var = scope->DeclareParameter( | 1194 Variable* var = scope->DeclareParameter( |
1193 name, mode, is_optional, parameter.is_rest, &is_duplicate); | 1195 name, mode, is_optional, parameter.is_rest, &is_duplicate); |
(...skipping 26 matching lines...) Expand all Loading... |
1220 | 1222 |
1221 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { | 1223 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { |
1222 return parser_->ParseDoExpression(ok); | 1224 return parser_->ParseDoExpression(ok); |
1223 } | 1225 } |
1224 | 1226 |
1225 | 1227 |
1226 } // namespace internal | 1228 } // namespace internal |
1227 } // namespace v8 | 1229 } // namespace v8 |
1228 | 1230 |
1229 #endif // V8_PARSING_PARSER_H_ | 1231 #endif // V8_PARSING_PARSER_H_ |
OLD | NEW |