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