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

Side by Side Diff: src/parser.h

Issue 1128043006: [destructuring] Adapting PatternRewriter to work in for-statements. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 7 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/ast.h ('k') | src/parser.cc » ('j') | src/parser.cc » ('J')
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_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 851 matching lines...) Expand 10 before | Expand all | Expand 10 after
862 bool Parse(ParseInfo* info); 862 bool Parse(ParseInfo* info);
863 void ParseOnBackground(ParseInfo* info); 863 void ParseOnBackground(ParseInfo* info);
864 864
865 // Handle errors detected during parsing, move statistics to Isolate, 865 // Handle errors detected during parsing, move statistics to Isolate,
866 // internalize strings (move them to the heap). 866 // internalize strings (move them to the heap).
867 void Internalize(Isolate* isolate, Handle<Script> script, bool error); 867 void Internalize(Isolate* isolate, Handle<Script> script, bool error);
868 void HandleSourceURLComments(Isolate* isolate, Handle<Script> script); 868 void HandleSourceURLComments(Isolate* isolate, Handle<Script> script);
869 869
870 private: 870 private:
871 friend class ParserTraits; 871 friend class ParserTraits;
872 class PatternRewriter;
873 872
874 // Limit the allowed number of local variables in a function. The hard limit 873 // Limit the allowed number of local variables in a function. The hard limit
875 // is that offsets computed by FullCodeGenerator::StackOperand and similar 874 // is that offsets computed by FullCodeGenerator::StackOperand and similar
876 // functions are ints, and they should not overflow. In addition, accessing 875 // functions are ints, and they should not overflow. In addition, accessing
877 // local variables creates user-controlled constants in the generated code, 876 // local variables creates user-controlled constants in the generated code,
878 // and we don't want too much user-controlled memory inside the code (this was 877 // and we don't want too much user-controlled memory inside the code (this was
879 // the reason why this limit was introduced in the first place; see 878 // the reason why this limit was introduced in the first place; see
880 // https://codereview.chromium.org/7003030/ ). 879 // https://codereview.chromium.org/7003030/ ).
881 static const int kMaxNumFunctionLocals = 4194303; // 2^22-1 880 static const int kMaxNumFunctionLocals = 4194303; // 2^22-1
882 881
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 bool* ok); 930 bool* ok);
932 Statement* ParseFunctionDeclaration(ZoneList<const AstRawString*>* names, 931 Statement* ParseFunctionDeclaration(ZoneList<const AstRawString*>* names,
933 bool* ok); 932 bool* ok);
934 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names, 933 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names,
935 bool* ok); 934 bool* ok);
936 Statement* ParseNativeDeclaration(bool* ok); 935 Statement* ParseNativeDeclaration(bool* ok);
937 Block* ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok); 936 Block* ParseBlock(ZoneList<const AstRawString*>* labels, bool* ok);
938 Block* ParseVariableStatement(VariableDeclarationContext var_context, 937 Block* ParseVariableStatement(VariableDeclarationContext var_context,
939 ZoneList<const AstRawString*>* names, 938 ZoneList<const AstRawString*>* names,
940 bool* ok); 939 bool* ok);
941 Block* ParseVariableDeclarations(VariableDeclarationContext var_context, 940
942 int* num_decl, 941 struct DeclarationDescriptor {
943 ZoneList<const AstRawString*>* names, 942 Parser* parser;
944 const AstRawString** out, 943 Scope* declaration_scope;
945 Scanner::Location* first_initializer_loc, 944 Scope* scope;
946 Scanner::Location* bindings_loc, bool* ok); 945 VariableMode mode;
946 bool is_const;
947 bool needs_init;
948 int pos;
949 Token::Value init_op;
950 };
951
952
953 class PatternRewriter : private AstVisitor {
954 public:
955 explicit PatternRewriter(Expression* pattern)
956 : pattern_(pattern),
957 initializer_position_(RelocInfo::kNoPosition),
958 state_(nullptr) {}
959
960 PatternRewriter()
961 : pattern_(nullptr),
962 initializer_position_(RelocInfo::kNoPosition),
963 state_(nullptr) {}
964
965 PatternRewriter(const PatternRewriter& other)
966 : AstVisitor(other),
967 pattern_(other.pattern_),
968 initializer_position_(other.initializer_position_),
969 state_(nullptr) {}
970
971 bool IsSingleVariableBinding() const;
972 const AstRawString* SingleName() const;
973
974 void DeclareAndInitializeVariables(Block* block,
975 const DeclarationDescriptor* decl,
976 Expression* value,
977 ZoneList<const AstRawString*>* names,
978 bool* ok);
979
980 void set_initializer_position(int pos) { initializer_position_ = pos; }
981
982 private:
983 // Group all state local to visting AST.
984 struct VisitorState {
985 Block* block;
986 const DeclarationDescriptor* decl;
987 ZoneList<const AstRawString*>* names;
988 Expression* current_value;
989 bool* ok;
990 };
991
992 #define DECLARE_VISIT(type) void Visit##type(v8::internal::type* node) override;
993 // Visiting functions for AST nodes make this an AstVisitor.
994 AST_NODE_LIST(DECLARE_VISIT)
995 #undef DECLARE_VISIT
996 virtual void Visit(AstNode* node) override;
997
998 void RecurseIntoSubpattern(AstNode* pattern, Expression* value) {
999 Expression* old_value = state_->current_value;
1000 state_->current_value = value;
1001 pattern->Accept(this);
1002 state_->current_value = old_value;
1003 }
1004
1005 AstNodeFactory* factory() const { return state_->decl->parser->factory(); }
1006 AstValueFactory* ast_value_factory() const {
1007 return state_->decl->parser->ast_value_factory();
1008 }
1009 bool inside_with() const { return state_->decl->parser->inside_with(); }
1010 Zone* zone() const { return state_->decl->parser->zone(); }
1011
1012 Expression* pattern_;
1013 int initializer_position_;
1014
1015 VisitorState* state_;
1016 };
1017
1018 struct DeclarationParsingResult {
1019 struct Declaration {
1020 Declaration(const PatternRewriter& p, Expression* initializer)
1021 : pattern(p), initializer(initializer) {}
1022
1023 PatternRewriter pattern;
1024 Expression* initializer;
1025 };
1026
1027 DeclarationParsingResult()
1028 : declarations(4),
1029 out(nullptr),
1030 first_initializer_loc(Scanner::Location::invalid()),
1031 bindings_loc(Scanner::Location::invalid()) {}
1032
1033 DeclarationDescriptor decl;
1034 List<Declaration> declarations;
1035 const AstRawString* out;
1036 Scanner::Location first_initializer_loc;
1037 Scanner::Location bindings_loc;
1038 };
1039
1040 void ParseVariableDeclarations(VariableDeclarationContext var_context,
1041 DeclarationParsingResult* parsing_result,
1042 bool* ok);
947 Statement* ParseExpressionOrLabelledStatement( 1043 Statement* ParseExpressionOrLabelledStatement(
948 ZoneList<const AstRawString*>* labels, bool* ok); 1044 ZoneList<const AstRawString*>* labels, bool* ok);
949 IfStatement* ParseIfStatement(ZoneList<const AstRawString*>* labels, 1045 IfStatement* ParseIfStatement(ZoneList<const AstRawString*>* labels,
950 bool* ok); 1046 bool* ok);
951 Statement* ParseContinueStatement(bool* ok); 1047 Statement* ParseContinueStatement(bool* ok);
952 Statement* ParseBreakStatement(ZoneList<const AstRawString*>* labels, 1048 Statement* ParseBreakStatement(ZoneList<const AstRawString*>* labels,
953 bool* ok); 1049 bool* ok);
954 Statement* ParseReturnStatement(bool* ok); 1050 Statement* ParseReturnStatement(bool* ok);
955 Statement* ParseWithStatement(ZoneList<const AstRawString*>* labels, 1051 Statement* ParseWithStatement(ZoneList<const AstRawString*>* labels,
956 bool* ok); 1052 bool* ok);
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 } 1275 }
1180 1276
1181 1277
1182 Expression* ParserTraits::SpreadCallNew( 1278 Expression* ParserTraits::SpreadCallNew(
1183 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) { 1279 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) {
1184 return parser_->SpreadCallNew(function, args, pos); 1280 return parser_->SpreadCallNew(function, args, pos);
1185 } 1281 }
1186 } } // namespace v8::internal 1282 } } // namespace v8::internal
1187 1283
1188 #endif // V8_PARSER_H_ 1284 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/ast.h ('k') | src/parser.cc » ('j') | src/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698