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

Side by Side Diff: src/parsing/parser.h

Issue 1702063002: Non-pattern rewriting revisited (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Fix a bug I introduced when rebasing Created 4 years, 10 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
« no previous file with comments | « src/parsing/expression-classifier.h ('k') | src/parsing/parser.cc » ('j') | 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_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
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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
542 545
543 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, 546 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type,
544 FunctionKind kind = kNormalFunction); 547 FunctionKind kind = kNormalFunction);
545 548
546 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters, 549 V8_INLINE void AddFormalParameter(ParserFormalParameters* parameters,
547 Expression* pattern, 550 Expression* pattern,
548 Expression* initializer, 551 Expression* initializer,
549 int initializer_end_position, bool is_rest); 552 int initializer_end_position, bool is_rest);
550 V8_INLINE void DeclareFormalParameter( 553 V8_INLINE void DeclareFormalParameter(
551 Scope* scope, const ParserFormalParameters::Parameter& parameter, 554 Scope* scope, const ParserFormalParameters::Parameter& parameter,
552 ExpressionClassifier* classifier); 555 Type::ExpressionClassifier* classifier);
553 void ParseArrowFunctionFormalParameters(ParserFormalParameters* parameters, 556 void ParseArrowFunctionFormalParameters(ParserFormalParameters* parameters,
554 Expression* params, 557 Expression* params,
555 const Scanner::Location& params_loc, 558 const Scanner::Location& params_loc,
556 bool* ok); 559 bool* ok);
557 void ParseArrowFunctionFormalParameterList( 560 void ParseArrowFunctionFormalParameterList(
558 ParserFormalParameters* parameters, Expression* params, 561 ParserFormalParameters* parameters, Expression* params,
559 const Scanner::Location& params_loc, 562 const Scanner::Location& params_loc,
560 Scanner::Location* duplicate_loc, bool* ok); 563 Scanner::Location* duplicate_loc, bool* ok);
561 564
562 V8_INLINE DoExpression* ParseDoExpression(bool* ok); 565 V8_INLINE DoExpression* ParseDoExpression(bool* ok);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 int pos); 639 int pos);
637 V8_INLINE Expression* SpreadCallNew(Expression* function, 640 V8_INLINE Expression* SpreadCallNew(Expression* function,
638 ZoneList<v8::internal::Expression*>* args, 641 ZoneList<v8::internal::Expression*>* args,
639 int pos); 642 int pos);
640 643
641 // Rewrite all DestructuringAssignments in the current FunctionState. 644 // Rewrite all DestructuringAssignments in the current FunctionState.
642 V8_INLINE void RewriteDestructuringAssignments(); 645 V8_INLINE void RewriteDestructuringAssignments();
643 646
644 V8_INLINE void QueueDestructuringAssignmentForRewriting( 647 V8_INLINE void QueueDestructuringAssignmentForRewriting(
645 Expression* assignment); 648 Expression* assignment);
649 V8_INLINE void QueueNonPatternForRewriting(Expression* expr);
646 650
647 void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property, 651 void SetFunctionNameFromPropertyName(ObjectLiteralProperty* property,
648 const AstRawString* name); 652 const AstRawString* name);
649 653
650 void SetFunctionNameFromIdentifierRef(Expression* value, 654 void SetFunctionNameFromIdentifierRef(Expression* value,
651 Expression* identifier); 655 Expression* identifier);
652 656
653 // Rewrite expressions that are not used as patterns 657 // Rewrite expressions that are not used as patterns
654 V8_INLINE Expression* RewriteNonPattern( 658 V8_INLINE void RewriteNonPattern(Type::ExpressionClassifier* classifier,
655 Expression* expr, const ExpressionClassifier* classifier, bool* ok); 659 bool* ok);
656 V8_INLINE ObjectLiteralProperty* RewriteNonPatternObjectLiteralProperty( 660
657 ObjectLiteralProperty* property, const ExpressionClassifier* classifier, 661 V8_INLINE Zone* zone() const;
658 bool* ok); 662
663 V8_INLINE ZoneList<Expression*>* GetNonPatternList() const;
659 664
660 Expression* RewriteYieldStar( 665 Expression* RewriteYieldStar(
661 Expression* generator, Expression* expression, int pos); 666 Expression* generator, Expression* expression, int pos);
662 667
663 private: 668 private:
664 Parser* parser_; 669 Parser* parser_;
665 670
666 void BuildIteratorClose( 671 void BuildIteratorClose(
667 ZoneList<Statement*>* statements, Variable* iterator, 672 ZoneList<Statement*>* statements, Variable* iterator,
668 Expression* input, Variable* output); 673 Expression* input, Variable* output);
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
805 Scanner::Location bindings_loc; 810 Scanner::Location bindings_loc;
806 }; 811 };
807 812
808 class PatternRewriter : private AstVisitor { 813 class PatternRewriter : private AstVisitor {
809 public: 814 public:
810 static void DeclareAndInitializeVariables( 815 static void DeclareAndInitializeVariables(
811 Block* block, const DeclarationDescriptor* declaration_descriptor, 816 Block* block, const DeclarationDescriptor* declaration_descriptor,
812 const DeclarationParsingResult::Declaration* declaration, 817 const DeclarationParsingResult::Declaration* declaration,
813 ZoneList<const AstRawString*>* names, bool* ok); 818 ZoneList<const AstRawString*>* names, bool* ok);
814 819
815 static void RewriteDestructuringAssignment( 820 static void RewriteDestructuringAssignment(Parser* parser,
816 Parser* parser, RewritableAssignmentExpression* expr, Scope* Scope); 821 RewritableExpression* expr,
822 Scope* Scope);
817 823
818 static Expression* RewriteDestructuringAssignment(Parser* parser, 824 static Expression* RewriteDestructuringAssignment(Parser* parser,
819 Assignment* assignment, 825 Assignment* assignment,
820 Scope* scope); 826 Scope* scope);
821 827
822 void set_initializer_position(int pos) { initializer_position_ = pos; } 828 void set_initializer_position(int pos) { initializer_position_ = pos; }
823 829
824 private: 830 private:
825 PatternRewriter() {} 831 PatternRewriter() {}
826 832
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1022 ZoneList<v8::internal::Expression*>* args, int pos); 1028 ZoneList<v8::internal::Expression*>* args, int pos);
1023 1029
1024 void SetLanguageMode(Scope* scope, LanguageMode mode); 1030 void SetLanguageMode(Scope* scope, LanguageMode mode);
1025 void RaiseLanguageMode(LanguageMode mode); 1031 void RaiseLanguageMode(LanguageMode mode);
1026 1032
1027 V8_INLINE void RewriteDestructuringAssignments(); 1033 V8_INLINE void RewriteDestructuringAssignments();
1028 1034
1029 friend class NonPatternRewriter; 1035 friend class NonPatternRewriter;
1030 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit); 1036 V8_INLINE Expression* RewriteSpreads(ArrayLiteral* lit);
1031 1037
1032 V8_INLINE Expression* RewriteNonPattern( 1038 V8_INLINE void RewriteNonPattern(ExpressionClassifier* classifier, bool* ok);
1033 Expression* expr, const ExpressionClassifier* classifier, bool* ok);
1034 V8_INLINE ObjectLiteralProperty* RewriteNonPatternObjectLiteralProperty(
1035 ObjectLiteralProperty* property, const ExpressionClassifier* classifier,
1036 bool* ok);
1037 1039
1038 friend class InitializerRewriter; 1040 friend class InitializerRewriter;
1039 void RewriteParameterInitializer(Expression* expr, Scope* scope); 1041 void RewriteParameterInitializer(Expression* expr, Scope* scope);
1040 1042
1041 Scanner scanner_; 1043 Scanner scanner_;
1042 PreParser* reusable_preparser_; 1044 PreParser* reusable_preparser_;
1043 Scope* original_scope_; // for ES5 function declarations in sloppy eval 1045 Scope* original_scope_; // for ES5 function declarations in sloppy eval
1044 Target* target_stack_; // for break, continue statements 1046 Target* target_stack_; // for break, continue statements
1045 ScriptCompiler::CompileOptions compile_options_; 1047 ScriptCompiler::CompileOptions compile_options_;
1046 ParseData* cached_parse_data_; 1048 ParseData* cached_parse_data_;
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 : parser_->ast_value_factory()->empty_string(); 1179 : parser_->ast_value_factory()->empty_string();
1178 parameters->params.Add( 1180 parameters->params.Add(
1179 ParserFormalParameters::Parameter(name, pattern, initializer, 1181 ParserFormalParameters::Parameter(name, pattern, initializer,
1180 initializer_end_position, is_rest), 1182 initializer_end_position, is_rest),
1181 parameters->scope->zone()); 1183 parameters->scope->zone());
1182 } 1184 }
1183 1185
1184 1186
1185 void ParserTraits::DeclareFormalParameter( 1187 void ParserTraits::DeclareFormalParameter(
1186 Scope* scope, const ParserFormalParameters::Parameter& parameter, 1188 Scope* scope, const ParserFormalParameters::Parameter& parameter,
1187 ExpressionClassifier* classifier) { 1189 Type::ExpressionClassifier* classifier) {
1188 bool is_duplicate = false; 1190 bool is_duplicate = false;
1189 bool is_simple = classifier->is_simple_parameter_list(); 1191 bool is_simple = classifier->is_simple_parameter_list();
1190 auto name = is_simple || parameter.is_rest 1192 auto name = is_simple || parameter.is_rest
1191 ? parameter.name 1193 ? parameter.name
1192 : parser_->ast_value_factory()->empty_string(); 1194 : parser_->ast_value_factory()->empty_string();
1193 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY; 1195 auto mode = is_simple || parameter.is_rest ? VAR : TEMPORARY;
1194 if (!is_simple) scope->SetHasNonSimpleParameters(); 1196 if (!is_simple) scope->SetHasNonSimpleParameters();
1195 bool is_optional = parameter.initializer != nullptr; 1197 bool is_optional = parameter.initializer != nullptr;
1196 Variable* var = scope->DeclareParameter( 1198 Variable* var = scope->DeclareParameter(
1197 name, mode, is_optional, parameter.is_rest, &is_duplicate); 1199 name, mode, is_optional, parameter.is_rest, &is_duplicate);
(...skipping 26 matching lines...) Expand all
1224 1226
1225 DoExpression* ParserTraits::ParseDoExpression(bool* ok) { 1227 DoExpression* ParserTraits::ParseDoExpression(bool* ok) {
1226 return parser_->ParseDoExpression(ok); 1228 return parser_->ParseDoExpression(ok);
1227 } 1229 }
1228 1230
1229 1231
1230 } // namespace internal 1232 } // namespace internal
1231 } // namespace v8 1233 } // namespace v8
1232 1234
1233 #endif // V8_PARSING_PARSER_H_ 1235 #endif // V8_PARSING_PARSER_H_
OLDNEW
« no previous file with comments | « src/parsing/expression-classifier.h ('k') | src/parsing/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698