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