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

Side by Side Diff: src/ast.h

Issue 679943004: Remove AstConstructionVisitor/AstNullVisitor (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 1 month 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | src/ast.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_AST_H_ 5 #ifndef V8_AST_H_
6 #define V8_AST_H_ 6 #define V8_AST_H_
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/assembler.h" 10 #include "src/assembler.h"
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 V(SuperReference) \ 98 V(SuperReference) \
99 V(CaseClause) 99 V(CaseClause)
100 100
101 #define AST_NODE_LIST(V) \ 101 #define AST_NODE_LIST(V) \
102 DECLARATION_NODE_LIST(V) \ 102 DECLARATION_NODE_LIST(V) \
103 MODULE_NODE_LIST(V) \ 103 MODULE_NODE_LIST(V) \
104 STATEMENT_NODE_LIST(V) \ 104 STATEMENT_NODE_LIST(V) \
105 EXPRESSION_NODE_LIST(V) 105 EXPRESSION_NODE_LIST(V)
106 106
107 // Forward declarations 107 // Forward declarations
108 class AstConstructionVisitor; 108 class AstNodeFactory;
109 template<class> class AstNodeFactory;
110 class AstVisitor; 109 class AstVisitor;
111 class Declaration; 110 class Declaration;
112 class Module; 111 class Module;
113 class BreakableStatement; 112 class BreakableStatement;
114 class Expression; 113 class Expression;
115 class IterationStatement; 114 class IterationStatement;
116 class MaterializedLiteral; 115 class MaterializedLiteral;
117 class Statement; 116 class Statement;
118 class TargetCollector; 117 class TargetCollector;
119 class TypeFeedbackOracle; 118 class TypeFeedbackOracle;
(...skipping 15 matching lines...) Expand all
135 AST_NODE_LIST(DEF_FORWARD_DECLARATION) 134 AST_NODE_LIST(DEF_FORWARD_DECLARATION)
136 #undef DEF_FORWARD_DECLARATION 135 #undef DEF_FORWARD_DECLARATION
137 136
138 137
139 // Typedef only introduced to avoid unreadable code. 138 // Typedef only introduced to avoid unreadable code.
140 // Please do appreciate the required space in "> >". 139 // Please do appreciate the required space in "> >".
141 typedef ZoneList<Handle<String> > ZoneStringList; 140 typedef ZoneList<Handle<String> > ZoneStringList;
142 typedef ZoneList<Handle<Object> > ZoneObjectList; 141 typedef ZoneList<Handle<Object> > ZoneObjectList;
143 142
144 143
145 #define DECLARE_NODE_TYPE(type) \ 144 #define DECLARE_NODE_TYPE(type) \
146 virtual void Accept(AstVisitor* v) OVERRIDE; \ 145 virtual void Accept(AstVisitor* v) OVERRIDE; \
147 virtual AstNode::NodeType node_type() const FINAL OVERRIDE { \ 146 virtual AstNode::NodeType node_type() const FINAL OVERRIDE { \
148 return AstNode::k##type; \ 147 return AstNode::k##type; \
149 } \ 148 } \
150 template<class> friend class AstNodeFactory; 149 friend class AstNodeFactory;
151 150
152 151
153 enum AstPropertiesFlag { 152 enum AstPropertiesFlag {
154 kDontSelfOptimize, 153 kDontSelfOptimize,
155 kDontSoftInline, 154 kDontSoftInline,
156 kDontCache 155 kDontCache
157 }; 156 };
158 157
159 158
160 class FeedbackVectorRequirements { 159 class FeedbackVectorRequirements {
(...skipping 1343 matching lines...) Expand 10 before | Expand all | Expand 10 after
1504 void RecordTypeFeedback(TypeFeedbackOracle* oracle); 1503 void RecordTypeFeedback(TypeFeedbackOracle* oracle);
1505 bool IsMonomorphic() { return !receiver_type_.is_null(); } 1504 bool IsMonomorphic() { return !receiver_type_.is_null(); }
1506 Handle<Map> GetReceiverType() { return receiver_type_; } 1505 Handle<Map> GetReceiverType() { return receiver_type_; }
1507 1506
1508 bool IsCompileTimeValue(); 1507 bool IsCompileTimeValue();
1509 1508
1510 void set_emit_store(bool emit_store); 1509 void set_emit_store(bool emit_store);
1511 bool emit_store(); 1510 bool emit_store();
1512 1511
1513 protected: 1512 protected:
1514 template<class> friend class AstNodeFactory; 1513 friend class AstNodeFactory;
1515 1514
1516 ObjectLiteralProperty(Zone* zone, bool is_getter, FunctionLiteral* value, 1515 ObjectLiteralProperty(Zone* zone, bool is_getter, FunctionLiteral* value,
1517 bool is_static); 1516 bool is_static);
1518 void set_key(Literal* key) { key_ = key; } 1517 void set_key(Literal* key) { key_ = key; }
1519 1518
1520 private: 1519 private:
1521 Literal* key_; 1520 Literal* key_;
1522 Expression* value_; 1521 Expression* value_;
1523 Kind kind_; 1522 Kind kind_;
1524 bool emit_store_; 1523 bool emit_store_;
(...skipping 763 matching lines...) Expand 10 before | Expand all | Expand 10 after
2288 } 2287 }
2289 void set_is_uninitialized(bool b) { is_uninitialized_ = b; } 2288 void set_is_uninitialized(bool b) { is_uninitialized_ = b; }
2290 void set_key_type(IcCheckType key_type) { key_type_ = key_type; } 2289 void set_key_type(IcCheckType key_type) { key_type_ = key_type; }
2291 void set_store_mode(KeyedAccessStoreMode mode) { store_mode_ = mode; } 2290 void set_store_mode(KeyedAccessStoreMode mode) { store_mode_ = mode; }
2292 2291
2293 protected: 2292 protected:
2294 Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value, 2293 Assignment(Zone* zone, Token::Value op, Expression* target, Expression* value,
2295 int pos); 2294 int pos);
2296 static int parent_num_ids() { return Expression::num_ids(); } 2295 static int parent_num_ids() { return Expression::num_ids(); }
2297 2296
2298 template <class Visitor>
2299 void Init(AstNodeFactory<Visitor>* factory) {
2300 DCHECK(Token::IsAssignmentOp(op_));
2301 if (is_compound()) {
2302 binary_operation_ = factory->NewBinaryOperation(
2303 binary_op(), target_, value_, position() + 1);
2304 }
2305 }
2306
2307 private: 2297 private:
2308 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 2298 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
2309 2299
2310 bool is_uninitialized_ : 1; 2300 bool is_uninitialized_ : 1;
2311 IcCheckType key_type_ : 1; 2301 IcCheckType key_type_ : 1;
2312 KeyedAccessStoreMode store_mode_ : 5; // Windows treats as signed, 2302 KeyedAccessStoreMode store_mode_ : 5; // Windows treats as signed,
2313 // must have extra bit. 2303 // must have extra bit.
2314 Token::Value op_; 2304 Token::Value op_;
2315 Expression* target_; 2305 Expression* target_;
2316 Expression* value_; 2306 Expression* value_;
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
3115 stack_overflow_ = false; \ 3105 stack_overflow_ = false; \
3116 } \ 3106 } \
3117 Zone* zone() { return zone_; } \ 3107 Zone* zone() { return zone_; } \
3118 Isolate* isolate() { return zone_->isolate(); } \ 3108 Isolate* isolate() { return zone_->isolate(); } \
3119 \ 3109 \
3120 Zone* zone_; \ 3110 Zone* zone_; \
3121 bool stack_overflow_ 3111 bool stack_overflow_
3122 3112
3123 3113
3124 // ---------------------------------------------------------------------------- 3114 // ----------------------------------------------------------------------------
3125 // Construction time visitor.
3126
3127 class AstConstructionVisitor BASE_EMBEDDED {
3128 public:
3129 AstConstructionVisitor() {}
3130
3131 private:
3132 template<class> friend class AstNodeFactory;
3133
3134 // Node visitors.
3135 #define DEF_VISIT(type) \
3136 void Visit##type(type* node);
3137 AST_NODE_LIST(DEF_VISIT)
3138 #undef DEF_VISIT
3139 };
3140
3141
3142 class AstNullVisitor BASE_EMBEDDED {
3143 public:
3144 // Node visitors.
3145 #define DEF_VISIT(type) \
3146 void Visit##type(type* node) {}
3147 AST_NODE_LIST(DEF_VISIT)
3148 #undef DEF_VISIT
3149 };
3150
3151
3152
3153 // ----------------------------------------------------------------------------
3154 // AstNode factory 3115 // AstNode factory
3155 3116
3156 template<class Visitor>
3157 class AstNodeFactory FINAL BASE_EMBEDDED { 3117 class AstNodeFactory FINAL BASE_EMBEDDED {
3158 public: 3118 public:
3159 explicit AstNodeFactory(AstValueFactory* ast_value_factory) 3119 explicit AstNodeFactory(AstValueFactory* ast_value_factory)
3160 : zone_(ast_value_factory->zone()), 3120 : zone_(ast_value_factory->zone()),
3161 ast_value_factory_(ast_value_factory) {} 3121 ast_value_factory_(ast_value_factory) {}
3162 3122
3163 Visitor* visitor() { return &visitor_; }
3164
3165 #define VISIT_AND_RETURN(NodeType, node) \
3166 visitor_.Visit##NodeType((node)); \
3167 return node;
3168
3169 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy, 3123 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
3170 VariableMode mode, 3124 VariableMode mode,
3171 Scope* scope, 3125 Scope* scope,
3172 int pos) { 3126 int pos) {
3173 VariableDeclaration* decl = 3127 return new (zone_) VariableDeclaration(zone_, proxy, mode, scope, pos);
3174 new(zone_) VariableDeclaration(zone_, proxy, mode, scope, pos);
3175 VISIT_AND_RETURN(VariableDeclaration, decl)
3176 } 3128 }
3177 3129
3178 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy, 3130 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy,
3179 VariableMode mode, 3131 VariableMode mode,
3180 FunctionLiteral* fun, 3132 FunctionLiteral* fun,
3181 Scope* scope, 3133 Scope* scope,
3182 int pos) { 3134 int pos) {
3183 FunctionDeclaration* decl = 3135 return new (zone_) FunctionDeclaration(zone_, proxy, mode, fun, scope, pos);
3184 new(zone_) FunctionDeclaration(zone_, proxy, mode, fun, scope, pos);
3185 VISIT_AND_RETURN(FunctionDeclaration, decl)
3186 } 3136 }
3187 3137
3188 ModuleDeclaration* NewModuleDeclaration(VariableProxy* proxy, 3138 ModuleDeclaration* NewModuleDeclaration(VariableProxy* proxy,
3189 Module* module, 3139 Module* module,
3190 Scope* scope, 3140 Scope* scope,
3191 int pos) { 3141 int pos) {
3192 ModuleDeclaration* decl = 3142 return new (zone_) ModuleDeclaration(zone_, proxy, module, scope, pos);
3193 new(zone_) ModuleDeclaration(zone_, proxy, module, scope, pos);
3194 VISIT_AND_RETURN(ModuleDeclaration, decl)
3195 } 3143 }
3196 3144
3197 ImportDeclaration* NewImportDeclaration(VariableProxy* proxy, 3145 ImportDeclaration* NewImportDeclaration(VariableProxy* proxy,
3198 Module* module, 3146 Module* module,
3199 Scope* scope, 3147 Scope* scope,
3200 int pos) { 3148 int pos) {
3201 ImportDeclaration* decl = 3149 return new (zone_) ImportDeclaration(zone_, proxy, module, scope, pos);
3202 new(zone_) ImportDeclaration(zone_, proxy, module, scope, pos);
3203 VISIT_AND_RETURN(ImportDeclaration, decl)
3204 } 3150 }
3205 3151
3206 ExportDeclaration* NewExportDeclaration(VariableProxy* proxy, 3152 ExportDeclaration* NewExportDeclaration(VariableProxy* proxy,
3207 Scope* scope, 3153 Scope* scope,
3208 int pos) { 3154 int pos) {
3209 ExportDeclaration* decl = 3155 return new (zone_) ExportDeclaration(zone_, proxy, scope, pos);
3210 new(zone_) ExportDeclaration(zone_, proxy, scope, pos);
3211 VISIT_AND_RETURN(ExportDeclaration, decl)
3212 } 3156 }
3213 3157
3214 ModuleLiteral* NewModuleLiteral(Block* body, Interface* interface, int pos) { 3158 ModuleLiteral* NewModuleLiteral(Block* body, Interface* interface, int pos) {
3215 ModuleLiteral* module = 3159 return new (zone_) ModuleLiteral(zone_, body, interface, pos);
3216 new(zone_) ModuleLiteral(zone_, body, interface, pos);
3217 VISIT_AND_RETURN(ModuleLiteral, module)
3218 } 3160 }
3219 3161
3220 ModuleVariable* NewModuleVariable(VariableProxy* proxy, int pos) { 3162 ModuleVariable* NewModuleVariable(VariableProxy* proxy, int pos) {
3221 ModuleVariable* module = new(zone_) ModuleVariable(zone_, proxy, pos); 3163 return new (zone_) ModuleVariable(zone_, proxy, pos);
3222 VISIT_AND_RETURN(ModuleVariable, module)
3223 } 3164 }
3224 3165
3225 ModulePath* NewModulePath(Module* origin, const AstRawString* name, int pos) { 3166 ModulePath* NewModulePath(Module* origin, const AstRawString* name, int pos) {
3226 ModulePath* module = new (zone_) ModulePath(zone_, origin, name, pos); 3167 return new (zone_) ModulePath(zone_, origin, name, pos);
3227 VISIT_AND_RETURN(ModulePath, module)
3228 } 3168 }
3229 3169
3230 ModuleUrl* NewModuleUrl(Handle<String> url, int pos) { 3170 ModuleUrl* NewModuleUrl(Handle<String> url, int pos) {
3231 ModuleUrl* module = new(zone_) ModuleUrl(zone_, url, pos); 3171 return new (zone_) ModuleUrl(zone_, url, pos);
3232 VISIT_AND_RETURN(ModuleUrl, module)
3233 } 3172 }
3234 3173
3235 Block* NewBlock(ZoneList<const AstRawString*>* labels, 3174 Block* NewBlock(ZoneList<const AstRawString*>* labels,
3236 int capacity, 3175 int capacity,
3237 bool is_initializer_block, 3176 bool is_initializer_block,
3238 int pos) { 3177 int pos) {
3239 Block* block = 3178 return new (zone_)
3240 new (zone_) Block(zone_, labels, capacity, is_initializer_block, pos); 3179 Block(zone_, labels, capacity, is_initializer_block, pos);
3241 VISIT_AND_RETURN(Block, block)
3242 } 3180 }
3243 3181
3244 #define STATEMENT_WITH_LABELS(NodeType) \ 3182 #define STATEMENT_WITH_LABELS(NodeType) \
3245 NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \ 3183 NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \
3246 NodeType* stmt = new (zone_) NodeType(zone_, labels, pos); \ 3184 return new (zone_) NodeType(zone_, labels, pos); \
3247 VISIT_AND_RETURN(NodeType, stmt); \
3248 } 3185 }
3249 STATEMENT_WITH_LABELS(DoWhileStatement) 3186 STATEMENT_WITH_LABELS(DoWhileStatement)
3250 STATEMENT_WITH_LABELS(WhileStatement) 3187 STATEMENT_WITH_LABELS(WhileStatement)
3251 STATEMENT_WITH_LABELS(ForStatement) 3188 STATEMENT_WITH_LABELS(ForStatement)
3252 STATEMENT_WITH_LABELS(SwitchStatement) 3189 STATEMENT_WITH_LABELS(SwitchStatement)
3253 #undef STATEMENT_WITH_LABELS 3190 #undef STATEMENT_WITH_LABELS
3254 3191
3255 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode, 3192 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode,
3256 ZoneList<const AstRawString*>* labels, 3193 ZoneList<const AstRawString*>* labels,
3257 int pos) { 3194 int pos) {
3258 switch (visit_mode) { 3195 switch (visit_mode) {
3259 case ForEachStatement::ENUMERATE: { 3196 case ForEachStatement::ENUMERATE: {
3260 ForInStatement* stmt = new (zone_) ForInStatement(zone_, labels, pos); 3197 return new (zone_) ForInStatement(zone_, labels, pos);
3261 VISIT_AND_RETURN(ForInStatement, stmt);
3262 } 3198 }
3263 case ForEachStatement::ITERATE: { 3199 case ForEachStatement::ITERATE: {
3264 ForOfStatement* stmt = new (zone_) ForOfStatement(zone_, labels, pos); 3200 return new (zone_) ForOfStatement(zone_, labels, pos);
3265 VISIT_AND_RETURN(ForOfStatement, stmt);
3266 } 3201 }
3267 } 3202 }
3268 UNREACHABLE(); 3203 UNREACHABLE();
3269 return NULL; 3204 return NULL;
3270 } 3205 }
3271 3206
3272 ModuleStatement* NewModuleStatement( 3207 ModuleStatement* NewModuleStatement(
3273 VariableProxy* proxy, Block* body, int pos) { 3208 VariableProxy* proxy, Block* body, int pos) {
3274 ModuleStatement* stmt = new(zone_) ModuleStatement(zone_, proxy, body, pos); 3209 return new (zone_) ModuleStatement(zone_, proxy, body, pos);
3275 VISIT_AND_RETURN(ModuleStatement, stmt)
3276 } 3210 }
3277 3211
3278 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) { 3212 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) {
3279 ExpressionStatement* stmt = 3213 return new (zone_) ExpressionStatement(zone_, expression, pos);
3280 new(zone_) ExpressionStatement(zone_, expression, pos);
3281 VISIT_AND_RETURN(ExpressionStatement, stmt)
3282 } 3214 }
3283 3215
3284 ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) { 3216 ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) {
3285 ContinueStatement* stmt = new(zone_) ContinueStatement(zone_, target, pos); 3217 return new (zone_) ContinueStatement(zone_, target, pos);
3286 VISIT_AND_RETURN(ContinueStatement, stmt)
3287 } 3218 }
3288 3219
3289 BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) { 3220 BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) {
3290 BreakStatement* stmt = new(zone_) BreakStatement(zone_, target, pos); 3221 return new (zone_) BreakStatement(zone_, target, pos);
3291 VISIT_AND_RETURN(BreakStatement, stmt)
3292 } 3222 }
3293 3223
3294 ReturnStatement* NewReturnStatement(Expression* expression, int pos) { 3224 ReturnStatement* NewReturnStatement(Expression* expression, int pos) {
3295 ReturnStatement* stmt = new(zone_) ReturnStatement(zone_, expression, pos); 3225 return new (zone_) ReturnStatement(zone_, expression, pos);
3296 VISIT_AND_RETURN(ReturnStatement, stmt)
3297 } 3226 }
3298 3227
3299 WithStatement* NewWithStatement(Scope* scope, 3228 WithStatement* NewWithStatement(Scope* scope,
3300 Expression* expression, 3229 Expression* expression,
3301 Statement* statement, 3230 Statement* statement,
3302 int pos) { 3231 int pos) {
3303 WithStatement* stmt = new(zone_) WithStatement( 3232 return new (zone_) WithStatement(zone_, scope, expression, statement, pos);
3304 zone_, scope, expression, statement, pos);
3305 VISIT_AND_RETURN(WithStatement, stmt)
3306 } 3233 }
3307 3234
3308 IfStatement* NewIfStatement(Expression* condition, 3235 IfStatement* NewIfStatement(Expression* condition,
3309 Statement* then_statement, 3236 Statement* then_statement,
3310 Statement* else_statement, 3237 Statement* else_statement,
3311 int pos) { 3238 int pos) {
3312 IfStatement* stmt = new (zone_) 3239 return new (zone_)
3313 IfStatement(zone_, condition, then_statement, else_statement, pos); 3240 IfStatement(zone_, condition, then_statement, else_statement, pos);
3314 VISIT_AND_RETURN(IfStatement, stmt)
3315 } 3241 }
3316 3242
3317 TryCatchStatement* NewTryCatchStatement(int index, 3243 TryCatchStatement* NewTryCatchStatement(int index,
3318 Block* try_block, 3244 Block* try_block,
3319 Scope* scope, 3245 Scope* scope,
3320 Variable* variable, 3246 Variable* variable,
3321 Block* catch_block, 3247 Block* catch_block,
3322 int pos) { 3248 int pos) {
3323 TryCatchStatement* stmt = new(zone_) TryCatchStatement( 3249 return new (zone_) TryCatchStatement(zone_, index, try_block, scope,
3324 zone_, index, try_block, scope, variable, catch_block, pos); 3250 variable, catch_block, pos);
3325 VISIT_AND_RETURN(TryCatchStatement, stmt)
3326 } 3251 }
3327 3252
3328 TryFinallyStatement* NewTryFinallyStatement(int index, 3253 TryFinallyStatement* NewTryFinallyStatement(int index,
3329 Block* try_block, 3254 Block* try_block,
3330 Block* finally_block, 3255 Block* finally_block,
3331 int pos) { 3256 int pos) {
3332 TryFinallyStatement* stmt = new(zone_) TryFinallyStatement( 3257 return new (zone_)
3333 zone_, index, try_block, finally_block, pos); 3258 TryFinallyStatement(zone_, index, try_block, finally_block, pos);
3334 VISIT_AND_RETURN(TryFinallyStatement, stmt)
3335 } 3259 }
3336 3260
3337 DebuggerStatement* NewDebuggerStatement(int pos) { 3261 DebuggerStatement* NewDebuggerStatement(int pos) {
3338 DebuggerStatement* stmt = new (zone_) DebuggerStatement(zone_, pos); 3262 return new (zone_) DebuggerStatement(zone_, pos);
3339 VISIT_AND_RETURN(DebuggerStatement, stmt)
3340 } 3263 }
3341 3264
3342 EmptyStatement* NewEmptyStatement(int pos) { 3265 EmptyStatement* NewEmptyStatement(int pos) {
3343 return new(zone_) EmptyStatement(zone_, pos); 3266 return new(zone_) EmptyStatement(zone_, pos);
3344 } 3267 }
3345 3268
3346 CaseClause* NewCaseClause( 3269 CaseClause* NewCaseClause(
3347 Expression* label, ZoneList<Statement*>* statements, int pos) { 3270 Expression* label, ZoneList<Statement*>* statements, int pos) {
3348 CaseClause* clause = new (zone_) CaseClause(zone_, label, statements, pos); 3271 return new (zone_) CaseClause(zone_, label, statements, pos);
3349 VISIT_AND_RETURN(CaseClause, clause)
3350 } 3272 }
3351 3273
3352 Literal* NewStringLiteral(const AstRawString* string, int pos) { 3274 Literal* NewStringLiteral(const AstRawString* string, int pos) {
3353 Literal* lit = 3275 return new (zone_)
3354 new (zone_) Literal(zone_, ast_value_factory_->NewString(string), pos); 3276 Literal(zone_, ast_value_factory_->NewString(string), pos);
3355 VISIT_AND_RETURN(Literal, lit)
3356 } 3277 }
3357 3278
3358 // A JavaScript symbol (ECMA-262 edition 6). 3279 // A JavaScript symbol (ECMA-262 edition 6).
3359 Literal* NewSymbolLiteral(const char* name, int pos) { 3280 Literal* NewSymbolLiteral(const char* name, int pos) {
3360 Literal* lit = 3281 return new (zone_) Literal(zone_, ast_value_factory_->NewSymbol(name), pos);
3361 new (zone_) Literal(zone_, ast_value_factory_->NewSymbol(name), pos);
3362 VISIT_AND_RETURN(Literal, lit)
3363 } 3282 }
3364 3283
3365 Literal* NewNumberLiteral(double number, int pos) { 3284 Literal* NewNumberLiteral(double number, int pos) {
3366 Literal* lit = 3285 return new (zone_)
3367 new (zone_) Literal(zone_, ast_value_factory_->NewNumber(number), pos); 3286 Literal(zone_, ast_value_factory_->NewNumber(number), pos);
3368 VISIT_AND_RETURN(Literal, lit)
3369 } 3287 }
3370 3288
3371 Literal* NewSmiLiteral(int number, int pos) { 3289 Literal* NewSmiLiteral(int number, int pos) {
3372 Literal* lit = 3290 return new (zone_) Literal(zone_, ast_value_factory_->NewSmi(number), pos);
3373 new (zone_) Literal(zone_, ast_value_factory_->NewSmi(number), pos);
3374 VISIT_AND_RETURN(Literal, lit)
3375 } 3291 }
3376 3292
3377 Literal* NewBooleanLiteral(bool b, int pos) { 3293 Literal* NewBooleanLiteral(bool b, int pos) {
3378 Literal* lit = 3294 return new (zone_) Literal(zone_, ast_value_factory_->NewBoolean(b), pos);
3379 new (zone_) Literal(zone_, ast_value_factory_->NewBoolean(b), pos);
3380 VISIT_AND_RETURN(Literal, lit)
3381 } 3295 }
3382 3296
3383 Literal* NewStringListLiteral(ZoneList<const AstRawString*>* strings, 3297 Literal* NewStringListLiteral(ZoneList<const AstRawString*>* strings,
3384 int pos) { 3298 int pos) {
3385 Literal* lit = new (zone_) 3299 return new (zone_)
3386 Literal(zone_, ast_value_factory_->NewStringList(strings), pos); 3300 Literal(zone_, ast_value_factory_->NewStringList(strings), pos);
3387 VISIT_AND_RETURN(Literal, lit)
3388 } 3301 }
3389 3302
3390 Literal* NewNullLiteral(int pos) { 3303 Literal* NewNullLiteral(int pos) {
3391 Literal* lit = 3304 return new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos);
3392 new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos);
3393 VISIT_AND_RETURN(Literal, lit)
3394 } 3305 }
3395 3306
3396 Literal* NewUndefinedLiteral(int pos) { 3307 Literal* NewUndefinedLiteral(int pos) {
3397 Literal* lit = 3308 return new (zone_) Literal(zone_, ast_value_factory_->NewUndefined(), pos);
3398 new (zone_) Literal(zone_, ast_value_factory_->NewUndefined(), pos);
3399 VISIT_AND_RETURN(Literal, lit)
3400 } 3309 }
3401 3310
3402 Literal* NewTheHoleLiteral(int pos) { 3311 Literal* NewTheHoleLiteral(int pos) {
3403 Literal* lit = 3312 return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos);
3404 new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos);
3405 VISIT_AND_RETURN(Literal, lit)
3406 } 3313 }
3407 3314
3408 ObjectLiteral* NewObjectLiteral( 3315 ObjectLiteral* NewObjectLiteral(
3409 ZoneList<ObjectLiteral::Property*>* properties, 3316 ZoneList<ObjectLiteral::Property*>* properties,
3410 int literal_index, 3317 int literal_index,
3411 int boilerplate_properties, 3318 int boilerplate_properties,
3412 bool has_function, 3319 bool has_function,
3413 int pos) { 3320 int pos) {
3414 ObjectLiteral* lit = 3321 return new (zone_) ObjectLiteral(zone_, properties, literal_index,
3415 new (zone_) ObjectLiteral(zone_, properties, literal_index, 3322 boilerplate_properties, has_function, pos);
3416 boilerplate_properties, has_function, pos);
3417 VISIT_AND_RETURN(ObjectLiteral, lit)
3418 } 3323 }
3419 3324
3420 ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key, 3325 ObjectLiteral::Property* NewObjectLiteralProperty(Literal* key,
3421 Expression* value, 3326 Expression* value,
3422 bool is_static) { 3327 bool is_static) {
3423 return new (zone_) ObjectLiteral::Property(zone_, ast_value_factory_, key, 3328 return new (zone_) ObjectLiteral::Property(zone_, ast_value_factory_, key,
3424 value, is_static); 3329 value, is_static);
3425 } 3330 }
3426 3331
3427 ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter, 3332 ObjectLiteral::Property* NewObjectLiteralProperty(bool is_getter,
3428 FunctionLiteral* value, 3333 FunctionLiteral* value,
3429 int pos, bool is_static) { 3334 int pos, bool is_static) {
3430 ObjectLiteral::Property* prop = 3335 ObjectLiteral::Property* prop =
3431 new (zone_) ObjectLiteral::Property(zone_, is_getter, value, is_static); 3336 new (zone_) ObjectLiteral::Property(zone_, is_getter, value, is_static);
3432 prop->set_key(NewStringLiteral(value->raw_name(), pos)); 3337 prop->set_key(NewStringLiteral(value->raw_name(), pos));
3433 return prop; // Not an AST node, will not be visited. 3338 return prop;
3434 } 3339 }
3435 3340
3436 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, 3341 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern,
3437 const AstRawString* flags, 3342 const AstRawString* flags,
3438 int literal_index, 3343 int literal_index,
3439 int pos) { 3344 int pos) {
3440 RegExpLiteral* lit = 3345 return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos);
3441 new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos);
3442 VISIT_AND_RETURN(RegExpLiteral, lit);
3443 } 3346 }
3444 3347
3445 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, 3348 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values,
3446 int literal_index, 3349 int literal_index,
3447 int pos) { 3350 int pos) {
3448 ArrayLiteral* lit = 3351 return new (zone_) ArrayLiteral(zone_, values, literal_index, pos);
3449 new (zone_) ArrayLiteral(zone_, values, literal_index, pos);
3450 VISIT_AND_RETURN(ArrayLiteral, lit)
3451 } 3352 }
3452 3353
3453 VariableProxy* NewVariableProxy(Variable* var, 3354 VariableProxy* NewVariableProxy(Variable* var,
3454 int pos = RelocInfo::kNoPosition) { 3355 int pos = RelocInfo::kNoPosition) {
3455 VariableProxy* proxy = new (zone_) VariableProxy(zone_, var, pos); 3356 return new (zone_) VariableProxy(zone_, var, pos);
3456 VISIT_AND_RETURN(VariableProxy, proxy)
3457 } 3357 }
3458 3358
3459 VariableProxy* NewVariableProxy(const AstRawString* name, 3359 VariableProxy* NewVariableProxy(const AstRawString* name,
3460 bool is_this, 3360 bool is_this,
3461 Interface* interface = Interface::NewValue(), 3361 Interface* interface = Interface::NewValue(),
3462 int position = RelocInfo::kNoPosition) { 3362 int position = RelocInfo::kNoPosition) {
3463 VariableProxy* proxy = 3363 return new (zone_) VariableProxy(zone_, name, is_this, interface, position);
3464 new (zone_) VariableProxy(zone_, name, is_this, interface, position);
3465 VISIT_AND_RETURN(VariableProxy, proxy)
3466 } 3364 }
3467 3365
3468 Property* NewProperty(Expression* obj, Expression* key, int pos) { 3366 Property* NewProperty(Expression* obj, Expression* key, int pos) {
3469 Property* prop = new (zone_) Property(zone_, obj, key, pos); 3367 return new (zone_) Property(zone_, obj, key, pos);
3470 VISIT_AND_RETURN(Property, prop)
3471 } 3368 }
3472 3369
3473 Call* NewCall(Expression* expression, 3370 Call* NewCall(Expression* expression,
3474 ZoneList<Expression*>* arguments, 3371 ZoneList<Expression*>* arguments,
3475 int pos) { 3372 int pos) {
3476 Call* call = new (zone_) Call(zone_, expression, arguments, pos); 3373 return new (zone_) Call(zone_, expression, arguments, pos);
3477 VISIT_AND_RETURN(Call, call)
3478 } 3374 }
3479 3375
3480 CallNew* NewCallNew(Expression* expression, 3376 CallNew* NewCallNew(Expression* expression,
3481 ZoneList<Expression*>* arguments, 3377 ZoneList<Expression*>* arguments,
3482 int pos) { 3378 int pos) {
3483 CallNew* call = new (zone_) CallNew(zone_, expression, arguments, pos); 3379 return new (zone_) CallNew(zone_, expression, arguments, pos);
3484 VISIT_AND_RETURN(CallNew, call)
3485 } 3380 }
3486 3381
3487 CallRuntime* NewCallRuntime(const AstRawString* name, 3382 CallRuntime* NewCallRuntime(const AstRawString* name,
3488 const Runtime::Function* function, 3383 const Runtime::Function* function,
3489 ZoneList<Expression*>* arguments, 3384 ZoneList<Expression*>* arguments,
3490 int pos) { 3385 int pos) {
3491 CallRuntime* call = 3386 return new (zone_) CallRuntime(zone_, name, function, arguments, pos);
3492 new (zone_) CallRuntime(zone_, name, function, arguments, pos);
3493 VISIT_AND_RETURN(CallRuntime, call)
3494 } 3387 }
3495 3388
3496 UnaryOperation* NewUnaryOperation(Token::Value op, 3389 UnaryOperation* NewUnaryOperation(Token::Value op,
3497 Expression* expression, 3390 Expression* expression,
3498 int pos) { 3391 int pos) {
3499 UnaryOperation* node = 3392 return new (zone_) UnaryOperation(zone_, op, expression, pos);
3500 new (zone_) UnaryOperation(zone_, op, expression, pos);
3501 VISIT_AND_RETURN(UnaryOperation, node)
3502 } 3393 }
3503 3394
3504 BinaryOperation* NewBinaryOperation(Token::Value op, 3395 BinaryOperation* NewBinaryOperation(Token::Value op,
3505 Expression* left, 3396 Expression* left,
3506 Expression* right, 3397 Expression* right,
3507 int pos) { 3398 int pos) {
3508 BinaryOperation* node = 3399 return new (zone_) BinaryOperation(zone_, op, left, right, pos);
3509 new (zone_) BinaryOperation(zone_, op, left, right, pos);
3510 VISIT_AND_RETURN(BinaryOperation, node)
3511 } 3400 }
3512 3401
3513 CountOperation* NewCountOperation(Token::Value op, 3402 CountOperation* NewCountOperation(Token::Value op,
3514 bool is_prefix, 3403 bool is_prefix,
3515 Expression* expr, 3404 Expression* expr,
3516 int pos) { 3405 int pos) {
3517 CountOperation* node = 3406 return new (zone_) CountOperation(zone_, op, is_prefix, expr, pos);
3518 new (zone_) CountOperation(zone_, op, is_prefix, expr, pos);
3519 VISIT_AND_RETURN(CountOperation, node)
3520 } 3407 }
3521 3408
3522 CompareOperation* NewCompareOperation(Token::Value op, 3409 CompareOperation* NewCompareOperation(Token::Value op,
3523 Expression* left, 3410 Expression* left,
3524 Expression* right, 3411 Expression* right,
3525 int pos) { 3412 int pos) {
3526 CompareOperation* node = 3413 return new (zone_) CompareOperation(zone_, op, left, right, pos);
3527 new (zone_) CompareOperation(zone_, op, left, right, pos);
3528 VISIT_AND_RETURN(CompareOperation, node)
3529 } 3414 }
3530 3415
3531 Conditional* NewConditional(Expression* condition, 3416 Conditional* NewConditional(Expression* condition,
3532 Expression* then_expression, 3417 Expression* then_expression,
3533 Expression* else_expression, 3418 Expression* else_expression,
3534 int position) { 3419 int position) {
3535 Conditional* cond = new (zone_) Conditional( 3420 return new (zone_) Conditional(zone_, condition, then_expression,
3536 zone_, condition, then_expression, else_expression, position); 3421 else_expression, position);
3537 VISIT_AND_RETURN(Conditional, cond)
3538 } 3422 }
3539 3423
3540 Assignment* NewAssignment(Token::Value op, 3424 Assignment* NewAssignment(Token::Value op,
3541 Expression* target, 3425 Expression* target,
3542 Expression* value, 3426 Expression* value,
3543 int pos) { 3427 int pos) {
3428 DCHECK(Token::IsAssignmentOp(op));
3544 Assignment* assign = new (zone_) Assignment(zone_, op, target, value, pos); 3429 Assignment* assign = new (zone_) Assignment(zone_, op, target, value, pos);
3545 assign->Init(this); 3430 if (assign->is_compound()) {
3546 VISIT_AND_RETURN(Assignment, assign) 3431 assign->binary_operation_ =
3432 NewBinaryOperation(assign->binary_op(), target, value, pos + 1);
3433 }
3434 return assign;
3547 } 3435 }
3548 3436
3549 Yield* NewYield(Expression *generator_object, 3437 Yield* NewYield(Expression *generator_object,
3550 Expression* expression, 3438 Expression* expression,
3551 Yield::Kind yield_kind, 3439 Yield::Kind yield_kind,
3552 int pos) { 3440 int pos) {
3553 if (!expression) expression = NewUndefinedLiteral(pos); 3441 if (!expression) expression = NewUndefinedLiteral(pos);
3554 Yield* yield = 3442 return new (zone_)
3555 new (zone_) Yield(zone_, generator_object, expression, yield_kind, pos); 3443 Yield(zone_, generator_object, expression, yield_kind, pos);
3556 VISIT_AND_RETURN(Yield, yield)
3557 } 3444 }
3558 3445
3559 Throw* NewThrow(Expression* exception, int pos) { 3446 Throw* NewThrow(Expression* exception, int pos) {
3560 Throw* t = new (zone_) Throw(zone_, exception, pos); 3447 return new (zone_) Throw(zone_, exception, pos);
3561 VISIT_AND_RETURN(Throw, t)
3562 } 3448 }
3563 3449
3564 FunctionLiteral* NewFunctionLiteral( 3450 FunctionLiteral* NewFunctionLiteral(
3565 const AstRawString* name, AstValueFactory* ast_value_factory, 3451 const AstRawString* name, AstValueFactory* ast_value_factory,
3566 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count, 3452 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count,
3567 int expected_property_count, int handler_count, int parameter_count, 3453 int expected_property_count, int handler_count, int parameter_count,
3568 FunctionLiteral::ParameterFlag has_duplicate_parameters, 3454 FunctionLiteral::ParameterFlag has_duplicate_parameters,
3569 FunctionLiteral::FunctionType function_type, 3455 FunctionLiteral::FunctionType function_type,
3570 FunctionLiteral::IsFunctionFlag is_function, 3456 FunctionLiteral::IsFunctionFlag is_function,
3571 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, 3457 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind,
3572 int position) { 3458 int position) {
3573 FunctionLiteral* lit = new (zone_) FunctionLiteral( 3459 return new (zone_) FunctionLiteral(
3574 zone_, name, ast_value_factory, scope, body, materialized_literal_count, 3460 zone_, name, ast_value_factory, scope, body, materialized_literal_count,
3575 expected_property_count, handler_count, parameter_count, function_type, 3461 expected_property_count, handler_count, parameter_count, function_type,
3576 has_duplicate_parameters, is_function, is_parenthesized, kind, 3462 has_duplicate_parameters, is_function, is_parenthesized, kind,
3577 position); 3463 position);
3578 // Top-level literal doesn't count for the AST's properties.
3579 if (is_function == FunctionLiteral::kIsFunction) {
3580 visitor_.VisitFunctionLiteral(lit);
3581 }
3582 return lit;
3583 } 3464 }
3584 3465
3585 ClassLiteral* NewClassLiteral(const AstRawString* name, Expression* extends, 3466 ClassLiteral* NewClassLiteral(const AstRawString* name, Expression* extends,
3586 Expression* constructor, 3467 Expression* constructor,
3587 ZoneList<ObjectLiteral::Property*>* properties, 3468 ZoneList<ObjectLiteral::Property*>* properties,
3588 int start_position, int end_position) { 3469 int start_position, int end_position) {
3589 ClassLiteral* lit = 3470 return new (zone_) ClassLiteral(zone_, name, extends, constructor,
3590 new (zone_) ClassLiteral(zone_, name, extends, constructor, properties, 3471 properties, start_position, end_position);
3591 start_position, end_position);
3592 VISIT_AND_RETURN(ClassLiteral, lit)
3593 } 3472 }
3594 3473
3595 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, 3474 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
3596 v8::Extension* extension, 3475 v8::Extension* extension,
3597 int pos) { 3476 int pos) {
3598 NativeFunctionLiteral* lit = 3477 return new (zone_) NativeFunctionLiteral(zone_, name, extension, pos);
3599 new (zone_) NativeFunctionLiteral(zone_, name, extension, pos);
3600 VISIT_AND_RETURN(NativeFunctionLiteral, lit)
3601 } 3478 }
3602 3479
3603 ThisFunction* NewThisFunction(int pos) { 3480 ThisFunction* NewThisFunction(int pos) {
3604 ThisFunction* fun = new (zone_) ThisFunction(zone_, pos); 3481 return new (zone_) ThisFunction(zone_, pos);
3605 VISIT_AND_RETURN(ThisFunction, fun)
3606 } 3482 }
3607 3483
3608 SuperReference* NewSuperReference(VariableProxy* this_var, int pos) { 3484 SuperReference* NewSuperReference(VariableProxy* this_var, int pos) {
3609 SuperReference* super = new (zone_) SuperReference(zone_, this_var, pos); 3485 return new (zone_) SuperReference(zone_, this_var, pos);
3610 VISIT_AND_RETURN(SuperReference, super);
3611 } 3486 }
3612 3487
3613 #undef VISIT_AND_RETURN
3614
3615 private: 3488 private:
3616 Zone* zone_; 3489 Zone* zone_;
3617 Visitor visitor_;
3618 AstValueFactory* ast_value_factory_; 3490 AstValueFactory* ast_value_factory_;
3619 }; 3491 };
3620 3492
3621 3493
3622 } } // namespace v8::internal 3494 } } // namespace v8::internal
3623 3495
3624 #endif // V8_AST_H_ 3496 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698