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

Side by Side Diff: src/ast/ast.h

Issue 2193793002: Put Scopes into temporary Zone (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased Created 4 years, 4 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 | « no previous file | src/ast/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_AST_H_ 5 #ifndef V8_AST_AST_H_
6 #define V8_AST_AST_H_ 6 #define V8_AST_AST_H_
7 7
8 #include "src/ast/ast-value-factory.h" 8 #include "src/ast/ast-value-factory.h"
9 #include "src/ast/modules.h" 9 #include "src/ast/modules.h"
10 #include "src/ast/variables.h" 10 #include "src/ast/variables.h"
(...skipping 1672 matching lines...) Expand 10 before | Expand all | Expand 10 after
1683 void set_next_unresolved(VariableProxy* next) { next_unresolved_ = next; } 1683 void set_next_unresolved(VariableProxy* next) { next_unresolved_ = next; }
1684 VariableProxy* next_unresolved() { return next_unresolved_; } 1684 VariableProxy* next_unresolved() { return next_unresolved_; }
1685 1685
1686 protected: 1686 protected:
1687 VariableProxy(Zone* zone, Variable* var, int start_position, 1687 VariableProxy(Zone* zone, Variable* var, int start_position,
1688 int end_position); 1688 int end_position);
1689 1689
1690 VariableProxy(Zone* zone, const AstRawString* name, 1690 VariableProxy(Zone* zone, const AstRawString* name,
1691 Variable::Kind variable_kind, int start_position, 1691 Variable::Kind variable_kind, int start_position,
1692 int end_position); 1692 int end_position);
1693 VariableProxy(Zone* zone, const VariableProxy* copy_from);
1693 static int parent_num_ids() { return Expression::num_ids(); } 1694 static int parent_num_ids() { return Expression::num_ids(); }
1694 int local_id(int n) const { return base_id() + parent_num_ids() + n; } 1695 int local_id(int n) const { return base_id() + parent_num_ids() + n; }
1695 1696
1696 class IsThisField : public BitField8<bool, 0, 1> {}; 1697 class IsThisField : public BitField8<bool, 0, 1> {};
1697 class IsAssignedField : public BitField8<bool, 1, 1> {}; 1698 class IsAssignedField : public BitField8<bool, 1, 1> {};
1698 class IsResolvedField : public BitField8<bool, 2, 1> {}; 1699 class IsResolvedField : public BitField8<bool, 2, 1> {};
1699 class IsNewTargetField : public BitField8<bool, 3, 1> {}; 1700 class IsNewTargetField : public BitField8<bool, 3, 1> {};
1700 1701
1701 // Start with 16-bit (or smaller) field, which should get packed together 1702 // Start with 16-bit (or smaller) field, which should get packed together
1702 // with Expression's trailing 16-bit field. 1703 // with Expression's trailing 16-bit field.
(...skipping 1333 matching lines...) Expand 10 before | Expand all | Expand 10 after
3036 AST_REWRITE(Type, _list->at(_index), _list->Set(_index, replacement)); \ 3037 AST_REWRITE(Type, _list->at(_index), _list->Set(_index, replacement)); \
3037 } while (false) 3038 } while (false)
3038 3039
3039 3040
3040 // ---------------------------------------------------------------------------- 3041 // ----------------------------------------------------------------------------
3041 // AstNode factory 3042 // AstNode factory
3042 3043
3043 class AstNodeFactory final BASE_EMBEDDED { 3044 class AstNodeFactory final BASE_EMBEDDED {
3044 public: 3045 public:
3045 explicit AstNodeFactory(AstValueFactory* ast_value_factory) 3046 explicit AstNodeFactory(AstValueFactory* ast_value_factory)
3046 : local_zone_(nullptr), 3047 : zone_(nullptr), ast_value_factory_(ast_value_factory) {
3047 parser_zone_(nullptr),
3048 ast_value_factory_(ast_value_factory) {
3049 if (ast_value_factory != nullptr) { 3048 if (ast_value_factory != nullptr) {
3050 local_zone_ = ast_value_factory->zone(); 3049 zone_ = ast_value_factory->zone();
3051 parser_zone_ = ast_value_factory->zone();
3052 } 3050 }
3053 } 3051 }
3054 3052
3055 AstValueFactory* ast_value_factory() const { return ast_value_factory_; } 3053 AstValueFactory* ast_value_factory() const { return ast_value_factory_; }
3056 void set_ast_value_factory(AstValueFactory* ast_value_factory) { 3054 void set_ast_value_factory(AstValueFactory* ast_value_factory) {
3057 ast_value_factory_ = ast_value_factory; 3055 ast_value_factory_ = ast_value_factory;
3058 local_zone_ = ast_value_factory->zone(); 3056 zone_ = ast_value_factory->zone();
3059 parser_zone_ = ast_value_factory->zone();
3060 } 3057 }
3061 3058
3062 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy, 3059 VariableDeclaration* NewVariableDeclaration(VariableProxy* proxy,
3063 VariableMode mode, Scope* scope, 3060 VariableMode mode, Scope* scope,
3064 int pos) { 3061 int pos) {
3065 return new (parser_zone_) 3062 return new (zone_) VariableDeclaration(zone_, proxy, mode, scope, pos);
3066 VariableDeclaration(parser_zone_, proxy, mode, scope, pos);
3067 } 3063 }
3068 3064
3069 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy, 3065 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy,
3070 VariableMode mode, 3066 VariableMode mode,
3071 FunctionLiteral* fun, 3067 FunctionLiteral* fun,
3072 Scope* scope, 3068 Scope* scope,
3073 int pos) { 3069 int pos) {
3074 return new (parser_zone_) 3070 return new (zone_) FunctionDeclaration(zone_, proxy, mode, fun, scope, pos);
3075 FunctionDeclaration(parser_zone_, proxy, mode, fun, scope, pos);
3076 } 3071 }
3077 3072
3078 Block* NewBlock(ZoneList<const AstRawString*>* labels, int capacity, 3073 Block* NewBlock(ZoneList<const AstRawString*>* labels, int capacity,
3079 bool ignore_completion_value, int pos) { 3074 bool ignore_completion_value, int pos) {
3080 return new (local_zone_) 3075 return new (zone_)
3081 Block(local_zone_, labels, capacity, ignore_completion_value, pos); 3076 Block(zone_, labels, capacity, ignore_completion_value, pos);
3082 } 3077 }
3083 3078
3084 #define STATEMENT_WITH_LABELS(NodeType) \ 3079 #define STATEMENT_WITH_LABELS(NodeType) \
3085 NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \ 3080 NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \
3086 return new (local_zone_) NodeType(local_zone_, labels, pos); \ 3081 return new (zone_) NodeType(zone_, labels, pos); \
3087 } 3082 }
3088 STATEMENT_WITH_LABELS(DoWhileStatement) 3083 STATEMENT_WITH_LABELS(DoWhileStatement)
3089 STATEMENT_WITH_LABELS(WhileStatement) 3084 STATEMENT_WITH_LABELS(WhileStatement)
3090 STATEMENT_WITH_LABELS(ForStatement) 3085 STATEMENT_WITH_LABELS(ForStatement)
3091 STATEMENT_WITH_LABELS(SwitchStatement) 3086 STATEMENT_WITH_LABELS(SwitchStatement)
3092 #undef STATEMENT_WITH_LABELS 3087 #undef STATEMENT_WITH_LABELS
3093 3088
3094 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode, 3089 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode,
3095 ZoneList<const AstRawString*>* labels, 3090 ZoneList<const AstRawString*>* labels,
3096 int pos) { 3091 int pos) {
3097 switch (visit_mode) { 3092 switch (visit_mode) {
3098 case ForEachStatement::ENUMERATE: { 3093 case ForEachStatement::ENUMERATE: {
3099 return new (local_zone_) ForInStatement(local_zone_, labels, pos); 3094 return new (zone_) ForInStatement(zone_, labels, pos);
3100 } 3095 }
3101 case ForEachStatement::ITERATE: { 3096 case ForEachStatement::ITERATE: {
3102 return new (local_zone_) ForOfStatement(local_zone_, labels, pos); 3097 return new (zone_) ForOfStatement(zone_, labels, pos);
3103 } 3098 }
3104 } 3099 }
3105 UNREACHABLE(); 3100 UNREACHABLE();
3106 return NULL; 3101 return NULL;
3107 } 3102 }
3108 3103
3109 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) { 3104 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) {
3110 return new (local_zone_) ExpressionStatement(local_zone_, expression, pos); 3105 return new (zone_) ExpressionStatement(zone_, expression, pos);
3111 } 3106 }
3112 3107
3113 ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) { 3108 ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) {
3114 return new (local_zone_) ContinueStatement(local_zone_, target, pos); 3109 return new (zone_) ContinueStatement(zone_, target, pos);
3115 } 3110 }
3116 3111
3117 BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) { 3112 BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) {
3118 return new (local_zone_) BreakStatement(local_zone_, target, pos); 3113 return new (zone_) BreakStatement(zone_, target, pos);
3119 } 3114 }
3120 3115
3121 ReturnStatement* NewReturnStatement(Expression* expression, int pos) { 3116 ReturnStatement* NewReturnStatement(Expression* expression, int pos) {
3122 return new (local_zone_) ReturnStatement(local_zone_, expression, pos); 3117 return new (zone_) ReturnStatement(zone_, expression, pos);
3123 } 3118 }
3124 3119
3125 WithStatement* NewWithStatement(Scope* scope, 3120 WithStatement* NewWithStatement(Scope* scope,
3126 Expression* expression, 3121 Expression* expression,
3127 Statement* statement, 3122 Statement* statement,
3128 int pos) { 3123 int pos) {
3129 return new (local_zone_) 3124 return new (zone_) WithStatement(zone_, scope, expression, statement, pos);
3130 WithStatement(local_zone_, scope, expression, statement, pos);
3131 } 3125 }
3132 3126
3133 IfStatement* NewIfStatement(Expression* condition, 3127 IfStatement* NewIfStatement(Expression* condition,
3134 Statement* then_statement, 3128 Statement* then_statement,
3135 Statement* else_statement, 3129 Statement* else_statement,
3136 int pos) { 3130 int pos) {
3137 return new (local_zone_) IfStatement(local_zone_, condition, then_statement, 3131 return new (zone_)
3138 else_statement, pos); 3132 IfStatement(zone_, condition, then_statement, else_statement, pos);
3139 } 3133 }
3140 3134
3141 TryCatchStatement* NewTryCatchStatement(Block* try_block, Scope* scope, 3135 TryCatchStatement* NewTryCatchStatement(Block* try_block, Scope* scope,
3142 Variable* variable, 3136 Variable* variable,
3143 Block* catch_block, int pos) { 3137 Block* catch_block, int pos) {
3144 return new (local_zone_) 3138 return new (zone_)
3145 TryCatchStatement(local_zone_, try_block, scope, variable, catch_block, 3139 TryCatchStatement(zone_, try_block, scope, variable, catch_block,
3146 HandlerTable::CAUGHT, pos); 3140 HandlerTable::CAUGHT, pos);
3147 } 3141 }
3148 3142
3149 TryCatchStatement* NewTryCatchStatementForReThrow(Block* try_block, 3143 TryCatchStatement* NewTryCatchStatementForReThrow(Block* try_block,
3150 Scope* scope, 3144 Scope* scope,
3151 Variable* variable, 3145 Variable* variable,
3152 Block* catch_block, 3146 Block* catch_block,
3153 int pos) { 3147 int pos) {
3154 return new (local_zone_) 3148 return new (zone_)
3155 TryCatchStatement(local_zone_, try_block, scope, variable, catch_block, 3149 TryCatchStatement(zone_, try_block, scope, variable, catch_block,
3156 HandlerTable::UNCAUGHT, pos); 3150 HandlerTable::UNCAUGHT, pos);
3157 } 3151 }
3158 3152
3159 TryCatchStatement* NewTryCatchStatementForPromiseReject(Block* try_block, 3153 TryCatchStatement* NewTryCatchStatementForPromiseReject(Block* try_block,
3160 Scope* scope, 3154 Scope* scope,
3161 Variable* variable, 3155 Variable* variable,
3162 Block* catch_block, 3156 Block* catch_block,
3163 int pos) { 3157 int pos) {
3164 return new (local_zone_) 3158 return new (zone_)
3165 TryCatchStatement(local_zone_, try_block, scope, variable, catch_block, 3159 TryCatchStatement(zone_, try_block, scope, variable, catch_block,
3166 HandlerTable::PROMISE, pos); 3160 HandlerTable::PROMISE, pos);
3167 } 3161 }
3168 3162
3169 TryFinallyStatement* NewTryFinallyStatement(Block* try_block, 3163 TryFinallyStatement* NewTryFinallyStatement(Block* try_block,
3170 Block* finally_block, int pos) { 3164 Block* finally_block, int pos) {
3171 return new (local_zone_) 3165 return new (zone_)
3172 TryFinallyStatement(local_zone_, try_block, finally_block, pos); 3166 TryFinallyStatement(zone_, try_block, finally_block, pos);
3173 } 3167 }
3174 3168
3175 DebuggerStatement* NewDebuggerStatement(int pos) { 3169 DebuggerStatement* NewDebuggerStatement(int pos) {
3176 return new (local_zone_) DebuggerStatement(local_zone_, pos); 3170 return new (zone_) DebuggerStatement(zone_, pos);
3177 } 3171 }
3178 3172
3179 EmptyStatement* NewEmptyStatement(int pos) { 3173 EmptyStatement* NewEmptyStatement(int pos) {
3180 return new (local_zone_) EmptyStatement(local_zone_, pos); 3174 return new (zone_) EmptyStatement(zone_, pos);
3181 } 3175 }
3182 3176
3183 SloppyBlockFunctionStatement* NewSloppyBlockFunctionStatement( 3177 SloppyBlockFunctionStatement* NewSloppyBlockFunctionStatement(
3184 Statement* statement, Scope* scope) { 3178 Statement* statement, Scope* scope) {
3185 return new (parser_zone_) 3179 return new (zone_) SloppyBlockFunctionStatement(zone_, statement, scope);
3186 SloppyBlockFunctionStatement(parser_zone_, statement, scope);
3187 } 3180 }
3188 3181
3189 CaseClause* NewCaseClause( 3182 CaseClause* NewCaseClause(
3190 Expression* label, ZoneList<Statement*>* statements, int pos) { 3183 Expression* label, ZoneList<Statement*>* statements, int pos) {
3191 return new (local_zone_) CaseClause(local_zone_, label, statements, pos); 3184 return new (zone_) CaseClause(zone_, label, statements, pos);
3192 } 3185 }
3193 3186
3194 Literal* NewStringLiteral(const AstRawString* string, int pos) { 3187 Literal* NewStringLiteral(const AstRawString* string, int pos) {
3195 return new (local_zone_) 3188 return new (zone_)
3196 Literal(local_zone_, ast_value_factory_->NewString(string), pos); 3189 Literal(zone_, ast_value_factory_->NewString(string), pos);
3197 } 3190 }
3198 3191
3199 // A JavaScript symbol (ECMA-262 edition 6). 3192 // A JavaScript symbol (ECMA-262 edition 6).
3200 Literal* NewSymbolLiteral(const char* name, int pos) { 3193 Literal* NewSymbolLiteral(const char* name, int pos) {
3201 return new (local_zone_) 3194 return new (zone_) Literal(zone_, ast_value_factory_->NewSymbol(name), pos);
3202 Literal(local_zone_, ast_value_factory_->NewSymbol(name), pos);
3203 } 3195 }
3204 3196
3205 Literal* NewNumberLiteral(double number, int pos, bool with_dot = false) { 3197 Literal* NewNumberLiteral(double number, int pos, bool with_dot = false) {
3206 return new (local_zone_) Literal( 3198 return new (zone_)
3207 local_zone_, ast_value_factory_->NewNumber(number, with_dot), pos); 3199 Literal(zone_, ast_value_factory_->NewNumber(number, with_dot), pos);
3208 } 3200 }
3209 3201
3210 Literal* NewSmiLiteral(int number, int pos) { 3202 Literal* NewSmiLiteral(int number, int pos) {
3211 return new (local_zone_) 3203 return new (zone_) Literal(zone_, ast_value_factory_->NewSmi(number), pos);
3212 Literal(local_zone_, ast_value_factory_->NewSmi(number), pos);
3213 } 3204 }
3214 3205
3215 Literal* NewBooleanLiteral(bool b, int pos) { 3206 Literal* NewBooleanLiteral(bool b, int pos) {
3216 return new (local_zone_) 3207 return new (zone_) Literal(zone_, ast_value_factory_->NewBoolean(b), pos);
3217 Literal(local_zone_, ast_value_factory_->NewBoolean(b), pos);
3218 } 3208 }
3219 3209
3220 Literal* NewNullLiteral(int pos) { 3210 Literal* NewNullLiteral(int pos) {
3221 return new (local_zone_) 3211 return new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos);
3222 Literal(local_zone_, ast_value_factory_->NewNull(), pos);
3223 } 3212 }
3224 3213
3225 Literal* NewUndefinedLiteral(int pos) { 3214 Literal* NewUndefinedLiteral(int pos) {
3226 return new (local_zone_) 3215 return new (zone_) Literal(zone_, ast_value_factory_->NewUndefined(), pos);
3227 Literal(local_zone_, ast_value_factory_->NewUndefined(), pos);
3228 } 3216 }
3229 3217
3230 Literal* NewTheHoleLiteral(int pos) { 3218 Literal* NewTheHoleLiteral(int pos) {
3231 return new (local_zone_) 3219 return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos);
3232 Literal(local_zone_, ast_value_factory_->NewTheHole(), pos);
3233 } 3220 }
3234 3221
3235 ObjectLiteral* NewObjectLiteral( 3222 ObjectLiteral* NewObjectLiteral(
3236 ZoneList<ObjectLiteral::Property*>* properties, int literal_index, 3223 ZoneList<ObjectLiteral::Property*>* properties, int literal_index,
3237 uint32_t boilerplate_properties, int pos) { 3224 uint32_t boilerplate_properties, int pos) {
3238 return new (local_zone_) ObjectLiteral( 3225 return new (zone_) ObjectLiteral(zone_, properties, literal_index,
3239 local_zone_, properties, literal_index, boilerplate_properties, pos); 3226 boilerplate_properties, pos);
3240 } 3227 }
3241 3228
3242 ObjectLiteral::Property* NewObjectLiteralProperty( 3229 ObjectLiteral::Property* NewObjectLiteralProperty(
3243 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, 3230 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind,
3244 bool is_static, bool is_computed_name) { 3231 bool is_static, bool is_computed_name) {
3245 return new (local_zone_) 3232 return new (zone_)
3246 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name); 3233 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name);
3247 } 3234 }
3248 3235
3249 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, 3236 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key,
3250 Expression* value, 3237 Expression* value,
3251 bool is_static, 3238 bool is_static,
3252 bool is_computed_name) { 3239 bool is_computed_name) {
3253 return new (local_zone_) ObjectLiteral::Property( 3240 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value,
3254 ast_value_factory_, key, value, is_static, is_computed_name); 3241 is_static, is_computed_name);
3255 } 3242 }
3256 3243
3257 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, int flags, 3244 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, int flags,
3258 int literal_index, int pos) { 3245 int literal_index, int pos) {
3259 return new (local_zone_) 3246 return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index, pos);
3260 RegExpLiteral(local_zone_, pattern, flags, literal_index, pos);
3261 } 3247 }
3262 3248
3263 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, 3249 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values,
3264 int literal_index, 3250 int literal_index,
3265 int pos) { 3251 int pos) {
3266 return new (local_zone_) 3252 return new (zone_) ArrayLiteral(zone_, values, -1, literal_index, pos);
3267 ArrayLiteral(local_zone_, values, -1, literal_index, pos);
3268 } 3253 }
3269 3254
3270 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, 3255 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values,
3271 int first_spread_index, int literal_index, 3256 int first_spread_index, int literal_index,
3272 int pos) { 3257 int pos) {
3273 return new (local_zone_) ArrayLiteral( 3258 return new (zone_)
3274 local_zone_, values, first_spread_index, literal_index, pos); 3259 ArrayLiteral(zone_, values, first_spread_index, literal_index, pos);
3275 } 3260 }
3276 3261
3277 VariableProxy* NewVariableProxy(Variable* var, 3262 VariableProxy* NewVariableProxy(Variable* var,
3278 int start_position = kNoSourcePosition, 3263 int start_position = kNoSourcePosition,
3279 int end_position = kNoSourcePosition) { 3264 int end_position = kNoSourcePosition) {
3280 return new (parser_zone_) 3265 return new (zone_) VariableProxy(zone_, var, start_position, end_position);
3281 VariableProxy(parser_zone_, var, start_position, end_position);
3282 } 3266 }
3283 3267
3284 VariableProxy* NewVariableProxy(const AstRawString* name, 3268 VariableProxy* NewVariableProxy(const AstRawString* name,
3285 Variable::Kind variable_kind, 3269 Variable::Kind variable_kind,
3286 int start_position = kNoSourcePosition, 3270 int start_position = kNoSourcePosition,
3287 int end_position = kNoSourcePosition) { 3271 int end_position = kNoSourcePosition) {
3288 DCHECK_NOT_NULL(name); 3272 DCHECK_NOT_NULL(name);
3289 return new (parser_zone_) VariableProxy(parser_zone_, name, variable_kind, 3273 return new (zone_)
3290 start_position, end_position); 3274 VariableProxy(zone_, name, variable_kind, start_position, end_position);
3275 }
3276
3277 // Recreates the VariableProxy in this Zone.
3278 VariableProxy* CopyVariableProxy(VariableProxy* proxy) {
3279 return new (zone_) VariableProxy(zone_, proxy);
3291 } 3280 }
3292 3281
3293 Property* NewProperty(Expression* obj, Expression* key, int pos) { 3282 Property* NewProperty(Expression* obj, Expression* key, int pos) {
3294 return new (local_zone_) Property(local_zone_, obj, key, pos); 3283 return new (zone_) Property(zone_, obj, key, pos);
3295 } 3284 }
3296 3285
3297 Call* NewCall(Expression* expression, 3286 Call* NewCall(Expression* expression,
3298 ZoneList<Expression*>* arguments, 3287 ZoneList<Expression*>* arguments,
3299 int pos) { 3288 int pos) {
3300 return new (local_zone_) Call(local_zone_, expression, arguments, pos); 3289 return new (zone_) Call(zone_, expression, arguments, pos);
3301 } 3290 }
3302 3291
3303 CallNew* NewCallNew(Expression* expression, 3292 CallNew* NewCallNew(Expression* expression,
3304 ZoneList<Expression*>* arguments, 3293 ZoneList<Expression*>* arguments,
3305 int pos) { 3294 int pos) {
3306 return new (local_zone_) CallNew(local_zone_, expression, arguments, pos); 3295 return new (zone_) CallNew(zone_, expression, arguments, pos);
3307 } 3296 }
3308 3297
3309 CallRuntime* NewCallRuntime(Runtime::FunctionId id, 3298 CallRuntime* NewCallRuntime(Runtime::FunctionId id,
3310 ZoneList<Expression*>* arguments, int pos) { 3299 ZoneList<Expression*>* arguments, int pos) {
3311 return new (local_zone_) 3300 return new (zone_)
3312 CallRuntime(local_zone_, Runtime::FunctionForId(id), arguments, pos); 3301 CallRuntime(zone_, Runtime::FunctionForId(id), arguments, pos);
3313 } 3302 }
3314 3303
3315 CallRuntime* NewCallRuntime(const Runtime::Function* function, 3304 CallRuntime* NewCallRuntime(const Runtime::Function* function,
3316 ZoneList<Expression*>* arguments, int pos) { 3305 ZoneList<Expression*>* arguments, int pos) {
3317 return new (local_zone_) CallRuntime(local_zone_, function, arguments, pos); 3306 return new (zone_) CallRuntime(zone_, function, arguments, pos);
3318 } 3307 }
3319 3308
3320 CallRuntime* NewCallRuntime(int context_index, 3309 CallRuntime* NewCallRuntime(int context_index,
3321 ZoneList<Expression*>* arguments, int pos) { 3310 ZoneList<Expression*>* arguments, int pos) {
3322 return new (local_zone_) 3311 return new (zone_) CallRuntime(zone_, context_index, arguments, pos);
3323 CallRuntime(local_zone_, context_index, arguments, pos);
3324 } 3312 }
3325 3313
3326 UnaryOperation* NewUnaryOperation(Token::Value op, 3314 UnaryOperation* NewUnaryOperation(Token::Value op,
3327 Expression* expression, 3315 Expression* expression,
3328 int pos) { 3316 int pos) {
3329 return new (local_zone_) UnaryOperation(local_zone_, op, expression, pos); 3317 return new (zone_) UnaryOperation(zone_, op, expression, pos);
3330 } 3318 }
3331 3319
3332 BinaryOperation* NewBinaryOperation(Token::Value op, 3320 BinaryOperation* NewBinaryOperation(Token::Value op,
3333 Expression* left, 3321 Expression* left,
3334 Expression* right, 3322 Expression* right,
3335 int pos) { 3323 int pos) {
3336 return new (local_zone_) BinaryOperation(local_zone_, op, left, right, pos); 3324 return new (zone_) BinaryOperation(zone_, op, left, right, pos);
3337 } 3325 }
3338 3326
3339 CountOperation* NewCountOperation(Token::Value op, 3327 CountOperation* NewCountOperation(Token::Value op,
3340 bool is_prefix, 3328 bool is_prefix,
3341 Expression* expr, 3329 Expression* expr,
3342 int pos) { 3330 int pos) {
3343 return new (local_zone_) 3331 return new (zone_) CountOperation(zone_, op, is_prefix, expr, pos);
3344 CountOperation(local_zone_, op, is_prefix, expr, pos);
3345 } 3332 }
3346 3333
3347 CompareOperation* NewCompareOperation(Token::Value op, 3334 CompareOperation* NewCompareOperation(Token::Value op,
3348 Expression* left, 3335 Expression* left,
3349 Expression* right, 3336 Expression* right,
3350 int pos) { 3337 int pos) {
3351 return new (local_zone_) 3338 return new (zone_) CompareOperation(zone_, op, left, right, pos);
3352 CompareOperation(local_zone_, op, left, right, pos);
3353 } 3339 }
3354 3340
3355 Spread* NewSpread(Expression* expression, int pos, int expr_pos) { 3341 Spread* NewSpread(Expression* expression, int pos, int expr_pos) {
3356 return new (local_zone_) Spread(local_zone_, expression, pos, expr_pos); 3342 return new (zone_) Spread(zone_, expression, pos, expr_pos);
3357 } 3343 }
3358 3344
3359 Conditional* NewConditional(Expression* condition, 3345 Conditional* NewConditional(Expression* condition,
3360 Expression* then_expression, 3346 Expression* then_expression,
3361 Expression* else_expression, 3347 Expression* else_expression,
3362 int position) { 3348 int position) {
3363 return new (local_zone_) Conditional( 3349 return new (zone_) Conditional(zone_, condition, then_expression,
3364 local_zone_, condition, then_expression, else_expression, position); 3350 else_expression, position);
3365 } 3351 }
3366 3352
3367 RewritableExpression* NewRewritableExpression(Expression* expression) { 3353 RewritableExpression* NewRewritableExpression(Expression* expression) {
3368 DCHECK_NOT_NULL(expression); 3354 DCHECK_NOT_NULL(expression);
3369 return new (local_zone_) RewritableExpression(local_zone_, expression); 3355 return new (zone_) RewritableExpression(zone_, expression);
3370 } 3356 }
3371 3357
3372 Assignment* NewAssignment(Token::Value op, 3358 Assignment* NewAssignment(Token::Value op,
3373 Expression* target, 3359 Expression* target,
3374 Expression* value, 3360 Expression* value,
3375 int pos) { 3361 int pos) {
3376 DCHECK(Token::IsAssignmentOp(op)); 3362 DCHECK(Token::IsAssignmentOp(op));
3377 Assignment* assign = 3363 Assignment* assign = new (zone_) Assignment(zone_, op, target, value, pos);
3378 new (local_zone_) Assignment(local_zone_, op, target, value, pos);
3379 if (assign->is_compound()) { 3364 if (assign->is_compound()) {
3380 DCHECK(Token::IsAssignmentOp(op)); 3365 DCHECK(Token::IsAssignmentOp(op));
3381 assign->binary_operation_ = 3366 assign->binary_operation_ =
3382 NewBinaryOperation(assign->binary_op(), target, value, pos + 1); 3367 NewBinaryOperation(assign->binary_op(), target, value, pos + 1);
3383 } 3368 }
3384 return assign; 3369 return assign;
3385 } 3370 }
3386 3371
3387 Yield* NewYield(Expression* generator_object, Expression* expression, int pos, 3372 Yield* NewYield(Expression* generator_object, Expression* expression, int pos,
3388 Yield::OnException on_exception) { 3373 Yield::OnException on_exception) {
3389 if (!expression) expression = NewUndefinedLiteral(pos); 3374 if (!expression) expression = NewUndefinedLiteral(pos);
3390 return new (local_zone_) 3375 return new (zone_)
3391 Yield(local_zone_, generator_object, expression, pos, on_exception); 3376 Yield(zone_, generator_object, expression, pos, on_exception);
3392 } 3377 }
3393 3378
3394 Throw* NewThrow(Expression* exception, int pos) { 3379 Throw* NewThrow(Expression* exception, int pos) {
3395 return new (local_zone_) Throw(local_zone_, exception, pos); 3380 return new (zone_) Throw(zone_, exception, pos);
3396 } 3381 }
3397 3382
3398 FunctionLiteral* NewFunctionLiteral( 3383 FunctionLiteral* NewFunctionLiteral(
3399 const AstRawString* name, Scope* scope, ZoneList<Statement*>* body, 3384 const AstRawString* name, Scope* scope, ZoneList<Statement*>* body,
3400 int materialized_literal_count, int expected_property_count, 3385 int materialized_literal_count, int expected_property_count,
3401 int parameter_count, 3386 int parameter_count,
3402 FunctionLiteral::ParameterFlag has_duplicate_parameters, 3387 FunctionLiteral::ParameterFlag has_duplicate_parameters,
3403 FunctionLiteral::FunctionType function_type, 3388 FunctionLiteral::FunctionType function_type,
3404 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, 3389 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind,
3405 int position) { 3390 int position) {
3406 return new (local_zone_) FunctionLiteral( 3391 return new (zone_) FunctionLiteral(
3407 local_zone_, name, ast_value_factory_, scope, body, 3392 zone_, name, ast_value_factory_, scope, body,
3408 materialized_literal_count, expected_property_count, parameter_count, 3393 materialized_literal_count, expected_property_count, parameter_count,
3409 function_type, has_duplicate_parameters, eager_compile_hint, kind, 3394 function_type, has_duplicate_parameters, eager_compile_hint, kind,
3410 position, true); 3395 position, true);
3411 } 3396 }
3412 3397
3413 // Creates a FunctionLiteral representing a top-level script, the 3398 // Creates a FunctionLiteral representing a top-level script, the
3414 // result of an eval (top-level or otherwise), or the result of calling 3399 // result of an eval (top-level or otherwise), or the result of calling
3415 // the Function constructor. 3400 // the Function constructor.
3416 FunctionLiteral* NewScriptOrEvalFunctionLiteral( 3401 FunctionLiteral* NewScriptOrEvalFunctionLiteral(
3417 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count, 3402 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count,
3418 int expected_property_count) { 3403 int expected_property_count) {
3419 return new (local_zone_) FunctionLiteral( 3404 return new (zone_) FunctionLiteral(
3420 local_zone_, ast_value_factory_->empty_string(), ast_value_factory_, 3405 zone_, ast_value_factory_->empty_string(), ast_value_factory_, scope,
3421 scope, body, materialized_literal_count, expected_property_count, 0, 3406 body, materialized_literal_count, expected_property_count, 0,
3422 FunctionLiteral::kAnonymousExpression, 3407 FunctionLiteral::kAnonymousExpression,
3423 FunctionLiteral::kNoDuplicateParameters, 3408 FunctionLiteral::kNoDuplicateParameters,
3424 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0, 3409 FunctionLiteral::kShouldLazyCompile, FunctionKind::kNormalFunction, 0,
3425 false); 3410 false);
3426 } 3411 }
3427 3412
3428 ClassLiteral* NewClassLiteral(VariableProxy* proxy, Expression* extends, 3413 ClassLiteral* NewClassLiteral(VariableProxy* proxy, Expression* extends,
3429 FunctionLiteral* constructor, 3414 FunctionLiteral* constructor,
3430 ZoneList<ObjectLiteral::Property*>* properties, 3415 ZoneList<ObjectLiteral::Property*>* properties,
3431 int start_position, int end_position) { 3416 int start_position, int end_position) {
3432 return new (local_zone_) 3417 return new (zone_) ClassLiteral(zone_, proxy, extends, constructor,
3433 ClassLiteral(local_zone_, proxy, extends, constructor, properties, 3418 properties, start_position, end_position);
3434 start_position, end_position);
3435 } 3419 }
3436 3420
3437 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, 3421 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name,
3438 v8::Extension* extension, 3422 v8::Extension* extension,
3439 int pos) { 3423 int pos) {
3440 return new (local_zone_) 3424 return new (zone_) NativeFunctionLiteral(zone_, name, extension, pos);
3441 NativeFunctionLiteral(local_zone_, name, extension, pos);
3442 } 3425 }
3443 3426
3444 DoExpression* NewDoExpression(Block* block, Variable* result_var, int pos) { 3427 DoExpression* NewDoExpression(Block* block, Variable* result_var, int pos) {
3445 VariableProxy* result = NewVariableProxy(result_var, pos); 3428 VariableProxy* result = NewVariableProxy(result_var, pos);
3446 return new (local_zone_) DoExpression(local_zone_, block, result, pos); 3429 return new (zone_) DoExpression(zone_, block, result, pos);
3447 } 3430 }
3448 3431
3449 ThisFunction* NewThisFunction(int pos) { 3432 ThisFunction* NewThisFunction(int pos) {
3450 return new (local_zone_) ThisFunction(local_zone_, pos); 3433 return new (zone_) ThisFunction(zone_, pos);
3451 } 3434 }
3452 3435
3453 SuperPropertyReference* NewSuperPropertyReference(VariableProxy* this_var, 3436 SuperPropertyReference* NewSuperPropertyReference(VariableProxy* this_var,
3454 Expression* home_object, 3437 Expression* home_object,
3455 int pos) { 3438 int pos) {
3456 return new (local_zone_) 3439 return new (zone_)
3457 SuperPropertyReference(local_zone_, this_var, home_object, pos); 3440 SuperPropertyReference(zone_, this_var, home_object, pos);
3458 } 3441 }
3459 3442
3460 SuperCallReference* NewSuperCallReference(VariableProxy* this_var, 3443 SuperCallReference* NewSuperCallReference(VariableProxy* this_var,
3461 VariableProxy* new_target_var, 3444 VariableProxy* new_target_var,
3462 VariableProxy* this_function_var, 3445 VariableProxy* this_function_var,
3463 int pos) { 3446 int pos) {
3464 return new (local_zone_) SuperCallReference( 3447 return new (zone_) SuperCallReference(zone_, this_var, new_target_var,
3465 local_zone_, this_var, new_target_var, this_function_var, pos); 3448 this_function_var, pos);
3466 } 3449 }
3467 3450
3468 EmptyParentheses* NewEmptyParentheses(int pos) { 3451 EmptyParentheses* NewEmptyParentheses(int pos) {
3469 return new (local_zone_) EmptyParentheses(local_zone_, pos); 3452 return new (zone_) EmptyParentheses(zone_, pos);
3470 } 3453 }
3471 3454
3472 Zone* zone() const { return local_zone_; } 3455 Zone* zone() const { return zone_; }
3456 void set_zone(Zone* zone) { zone_ = zone; }
3473 3457
3474 // Handles use of temporary zones when parsing inner function bodies. 3458 // Handles use of temporary zones when parsing inner function bodies.
3475 class BodyScope { 3459 class BodyScope {
3476 public: 3460 public:
3477 BodyScope(AstNodeFactory* factory, Zone* temp_zone, bool use_temp_zone) 3461 BodyScope(AstNodeFactory* factory, Zone* temp_zone, bool use_temp_zone)
3478 : factory_(factory), prev_zone_(factory->local_zone_) { 3462 : factory_(factory), prev_zone_(factory->zone_) {
3479 if (use_temp_zone) { 3463 if (use_temp_zone) {
3480 factory->local_zone_ = temp_zone; 3464 factory->zone_ = temp_zone;
3481 } 3465 }
3482 } 3466 }
3483 3467
3484 ~BodyScope() { factory_->local_zone_ = prev_zone_; } 3468 ~BodyScope() { factory_->zone_ = prev_zone_; }
3485 3469
3486 private: 3470 private:
3487 AstNodeFactory* factory_; 3471 AstNodeFactory* factory_;
3488 Zone* prev_zone_; 3472 Zone* prev_zone_;
3489 }; 3473 };
3490 3474
3491 private: 3475 private:
3492 // This zone may be deallocated upon returning from parsing a function body 3476 // This zone may be deallocated upon returning from parsing a function body
3493 // which we can guarantee is not going to be compiled or have its AST 3477 // which we can guarantee is not going to be compiled or have its AST
3494 // inspected. 3478 // inspected.
3495 // See ParseFunctionLiteral in parser.cc for preconditions. 3479 // See ParseFunctionLiteral in parser.cc for preconditions.
3496 Zone* local_zone_; 3480 Zone* zone_;
3497 // ZoneObjects which need to persist until scope analysis must be allocated in
3498 // the parser-level zone.
3499 Zone* parser_zone_;
3500 AstValueFactory* ast_value_factory_; 3481 AstValueFactory* ast_value_factory_;
3501 }; 3482 };
3502 3483
3503 3484
3504 // Type testing & conversion functions overridden by concrete subclasses. 3485 // Type testing & conversion functions overridden by concrete subclasses.
3505 // Inline functions for AstNode. 3486 // Inline functions for AstNode.
3506 3487
3507 #define DECLARE_NODE_FUNCTIONS(type) \ 3488 #define DECLARE_NODE_FUNCTIONS(type) \
3508 bool AstNode::Is##type() const { \ 3489 bool AstNode::Is##type() const { \
3509 NodeType mine = node_type(); \ 3490 NodeType mine = node_type(); \
(...skipping 28 matching lines...) Expand all
3538 : NULL; \ 3519 : NULL; \
3539 } 3520 }
3540 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS) 3521 AST_NODE_LIST(DECLARE_NODE_FUNCTIONS)
3541 #undef DECLARE_NODE_FUNCTIONS 3522 #undef DECLARE_NODE_FUNCTIONS
3542 3523
3543 3524
3544 } // namespace internal 3525 } // namespace internal
3545 } // namespace v8 3526 } // namespace v8
3546 3527
3547 #endif // V8_AST_AST_H_ 3528 #endif // V8_AST_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/ast/ast.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698