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_H_ | 5 #ifndef V8_AST_H_ |
6 #define V8_AST_H_ | 6 #define V8_AST_H_ |
7 | 7 |
8 #include "src/assembler.h" | 8 #include "src/assembler.h" |
9 #include "src/ast-value-factory.h" | 9 #include "src/ast-value-factory.h" |
10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
(...skipping 3259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3270 Zone* zone_; \ | 3270 Zone* zone_; \ |
3271 bool stack_overflow_ | 3271 bool stack_overflow_ |
3272 | 3272 |
3273 | 3273 |
3274 // ---------------------------------------------------------------------------- | 3274 // ---------------------------------------------------------------------------- |
3275 // AstNode factory | 3275 // AstNode factory |
3276 | 3276 |
3277 class AstNodeFactory final BASE_EMBEDDED { | 3277 class AstNodeFactory final BASE_EMBEDDED { |
3278 public: | 3278 public: |
3279 explicit AstNodeFactory(AstValueFactory* ast_value_factory) | 3279 explicit AstNodeFactory(AstValueFactory* ast_value_factory) |
3280 : zone_(ast_value_factory->zone()), | 3280 : local_zone_(ast_value_factory->zone()), |
3281 parser_zone_(ast_value_factory->zone()), | |
3281 ast_value_factory_(ast_value_factory) {} | 3282 ast_value_factory_(ast_value_factory) {} |
3282 | 3283 |
3283 VariableDeclaration* NewVariableDeclaration( | 3284 VariableDeclaration* NewVariableDeclaration( |
3284 VariableProxy* proxy, VariableMode mode, Scope* scope, int pos, | 3285 VariableProxy* proxy, VariableMode mode, Scope* scope, int pos, |
3285 bool is_class_declaration = false, int declaration_group_start = -1) { | 3286 bool is_class_declaration = false, int declaration_group_start = -1) { |
3286 return new (zone_) | 3287 return new (parser_zone_) |
3287 VariableDeclaration(zone_, proxy, mode, scope, pos, | 3288 VariableDeclaration(parser_zone_, proxy, mode, scope, pos, |
3288 is_class_declaration, declaration_group_start); | 3289 is_class_declaration, declaration_group_start); |
3289 } | 3290 } |
3290 | 3291 |
3291 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy, | 3292 FunctionDeclaration* NewFunctionDeclaration(VariableProxy* proxy, |
3292 VariableMode mode, | 3293 VariableMode mode, |
3293 FunctionLiteral* fun, | 3294 FunctionLiteral* fun, |
3294 Scope* scope, | 3295 Scope* scope, |
3295 int pos) { | 3296 int pos) { |
3296 return new (zone_) FunctionDeclaration(zone_, proxy, mode, fun, scope, pos); | 3297 return new (parser_zone_) |
3298 FunctionDeclaration(parser_zone_, proxy, mode, fun, scope, pos); | |
3297 } | 3299 } |
3298 | 3300 |
3299 ImportDeclaration* NewImportDeclaration(VariableProxy* proxy, | 3301 ImportDeclaration* NewImportDeclaration(VariableProxy* proxy, |
3300 const AstRawString* import_name, | 3302 const AstRawString* import_name, |
3301 const AstRawString* module_specifier, | 3303 const AstRawString* module_specifier, |
3302 Scope* scope, int pos) { | 3304 Scope* scope, int pos) { |
3303 return new (zone_) ImportDeclaration(zone_, proxy, import_name, | 3305 return new (parser_zone_) ImportDeclaration( |
3304 module_specifier, scope, pos); | 3306 parser_zone_, proxy, import_name, module_specifier, scope, pos); |
3305 } | 3307 } |
3306 | 3308 |
3307 ExportDeclaration* NewExportDeclaration(VariableProxy* proxy, | 3309 ExportDeclaration* NewExportDeclaration(VariableProxy* proxy, |
3308 Scope* scope, | 3310 Scope* scope, |
3309 int pos) { | 3311 int pos) { |
3310 return new (zone_) ExportDeclaration(zone_, proxy, scope, pos); | 3312 return new (parser_zone_) |
3313 ExportDeclaration(parser_zone_, proxy, scope, pos); | |
3311 } | 3314 } |
3312 | 3315 |
3313 Block* NewBlock(ZoneList<const AstRawString*>* labels, int capacity, | 3316 Block* NewBlock(ZoneList<const AstRawString*>* labels, int capacity, |
3314 bool ignore_completion_value, int pos) { | 3317 bool ignore_completion_value, int pos) { |
3315 return new (zone_) | 3318 return new (local_zone_) |
3316 Block(zone_, labels, capacity, ignore_completion_value, pos); | 3319 Block(local_zone_, labels, capacity, ignore_completion_value, pos); |
3317 } | 3320 } |
3318 | 3321 |
3319 #define STATEMENT_WITH_LABELS(NodeType) \ | 3322 #define STATEMENT_WITH_LABELS(NodeType) \ |
3320 NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \ | 3323 NodeType* New##NodeType(ZoneList<const AstRawString*>* labels, int pos) { \ |
3321 return new (zone_) NodeType(zone_, labels, pos); \ | 3324 return new (local_zone_) NodeType(local_zone_, labels, pos); \ |
3322 } | 3325 } |
3323 STATEMENT_WITH_LABELS(DoWhileStatement) | 3326 STATEMENT_WITH_LABELS(DoWhileStatement) |
3324 STATEMENT_WITH_LABELS(WhileStatement) | 3327 STATEMENT_WITH_LABELS(WhileStatement) |
3325 STATEMENT_WITH_LABELS(ForStatement) | 3328 STATEMENT_WITH_LABELS(ForStatement) |
3326 STATEMENT_WITH_LABELS(SwitchStatement) | 3329 STATEMENT_WITH_LABELS(SwitchStatement) |
3327 #undef STATEMENT_WITH_LABELS | 3330 #undef STATEMENT_WITH_LABELS |
3328 | 3331 |
3329 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode, | 3332 ForEachStatement* NewForEachStatement(ForEachStatement::VisitMode visit_mode, |
3330 ZoneList<const AstRawString*>* labels, | 3333 ZoneList<const AstRawString*>* labels, |
3331 int pos) { | 3334 int pos) { |
3332 switch (visit_mode) { | 3335 switch (visit_mode) { |
3333 case ForEachStatement::ENUMERATE: { | 3336 case ForEachStatement::ENUMERATE: { |
3334 return new (zone_) ForInStatement(zone_, labels, pos); | 3337 return new (local_zone_) ForInStatement(local_zone_, labels, pos); |
3335 } | 3338 } |
3336 case ForEachStatement::ITERATE: { | 3339 case ForEachStatement::ITERATE: { |
3337 return new (zone_) ForOfStatement(zone_, labels, pos); | 3340 return new (local_zone_) ForOfStatement(local_zone_, labels, pos); |
3338 } | 3341 } |
3339 } | 3342 } |
3340 UNREACHABLE(); | 3343 UNREACHABLE(); |
3341 return NULL; | 3344 return NULL; |
3342 } | 3345 } |
3343 | 3346 |
3344 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) { | 3347 ExpressionStatement* NewExpressionStatement(Expression* expression, int pos) { |
3345 return new (zone_) ExpressionStatement(zone_, expression, pos); | 3348 return new (local_zone_) ExpressionStatement(local_zone_, expression, pos); |
3346 } | 3349 } |
3347 | 3350 |
3348 ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) { | 3351 ContinueStatement* NewContinueStatement(IterationStatement* target, int pos) { |
3349 return new (zone_) ContinueStatement(zone_, target, pos); | 3352 return new (local_zone_) ContinueStatement(local_zone_, target, pos); |
3350 } | 3353 } |
3351 | 3354 |
3352 BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) { | 3355 BreakStatement* NewBreakStatement(BreakableStatement* target, int pos) { |
3353 return new (zone_) BreakStatement(zone_, target, pos); | 3356 return new (local_zone_) BreakStatement(local_zone_, target, pos); |
3354 } | 3357 } |
3355 | 3358 |
3356 ReturnStatement* NewReturnStatement(Expression* expression, int pos) { | 3359 ReturnStatement* NewReturnStatement(Expression* expression, int pos) { |
3357 return new (zone_) ReturnStatement(zone_, expression, pos); | 3360 return new (local_zone_) ReturnStatement(local_zone_, expression, pos); |
3358 } | 3361 } |
3359 | 3362 |
3360 WithStatement* NewWithStatement(Scope* scope, | 3363 WithStatement* NewWithStatement(Scope* scope, |
3361 Expression* expression, | 3364 Expression* expression, |
3362 Statement* statement, | 3365 Statement* statement, |
3363 int pos) { | 3366 int pos) { |
3364 return new (zone_) WithStatement(zone_, scope, expression, statement, pos); | 3367 return new (local_zone_) |
3368 WithStatement(local_zone_, scope, expression, statement, pos); | |
3365 } | 3369 } |
3366 | 3370 |
3367 IfStatement* NewIfStatement(Expression* condition, | 3371 IfStatement* NewIfStatement(Expression* condition, |
3368 Statement* then_statement, | 3372 Statement* then_statement, |
3369 Statement* else_statement, | 3373 Statement* else_statement, |
3370 int pos) { | 3374 int pos) { |
3371 return new (zone_) | 3375 return new (local_zone_) IfStatement(local_zone_, condition, then_statement, |
3372 IfStatement(zone_, condition, then_statement, else_statement, pos); | 3376 else_statement, pos); |
3373 } | 3377 } |
3374 | 3378 |
3375 TryCatchStatement* NewTryCatchStatement(Block* try_block, Scope* scope, | 3379 TryCatchStatement* NewTryCatchStatement(Block* try_block, Scope* scope, |
3376 Variable* variable, | 3380 Variable* variable, |
3377 Block* catch_block, int pos) { | 3381 Block* catch_block, int pos) { |
3378 return new (zone_) | 3382 return new (local_zone_) TryCatchStatement(local_zone_, try_block, scope, |
3379 TryCatchStatement(zone_, try_block, scope, variable, catch_block, pos); | 3383 variable, catch_block, pos); |
3380 } | 3384 } |
3381 | 3385 |
3382 TryFinallyStatement* NewTryFinallyStatement(Block* try_block, | 3386 TryFinallyStatement* NewTryFinallyStatement(Block* try_block, |
3383 Block* finally_block, int pos) { | 3387 Block* finally_block, int pos) { |
3384 return new (zone_) | 3388 return new (local_zone_) |
3385 TryFinallyStatement(zone_, try_block, finally_block, pos); | 3389 TryFinallyStatement(local_zone_, try_block, finally_block, pos); |
3386 } | 3390 } |
3387 | 3391 |
3388 DebuggerStatement* NewDebuggerStatement(int pos) { | 3392 DebuggerStatement* NewDebuggerStatement(int pos) { |
3389 return new (zone_) DebuggerStatement(zone_, pos); | 3393 return new (local_zone_) DebuggerStatement(local_zone_, pos); |
3390 } | 3394 } |
3391 | 3395 |
3392 EmptyStatement* NewEmptyStatement(int pos) { | 3396 EmptyStatement* NewEmptyStatement(int pos) { |
3393 return new(zone_) EmptyStatement(zone_, pos); | 3397 return new (local_zone_) EmptyStatement(local_zone_, pos); |
3394 } | 3398 } |
3395 | 3399 |
3396 CaseClause* NewCaseClause( | 3400 CaseClause* NewCaseClause( |
3397 Expression* label, ZoneList<Statement*>* statements, int pos) { | 3401 Expression* label, ZoneList<Statement*>* statements, int pos) { |
3398 return new (zone_) CaseClause(zone_, label, statements, pos); | 3402 return new (local_zone_) CaseClause(local_zone_, label, statements, pos); |
3399 } | 3403 } |
3400 | 3404 |
3401 Literal* NewStringLiteral(const AstRawString* string, int pos) { | 3405 Literal* NewStringLiteral(const AstRawString* string, int pos) { |
3402 return new (zone_) | 3406 return new (local_zone_) |
3403 Literal(zone_, ast_value_factory_->NewString(string), pos); | 3407 Literal(local_zone_, ast_value_factory_->NewString(string), pos); |
3404 } | 3408 } |
3405 | 3409 |
3406 // A JavaScript symbol (ECMA-262 edition 6). | 3410 // A JavaScript symbol (ECMA-262 edition 6). |
3407 Literal* NewSymbolLiteral(const char* name, int pos) { | 3411 Literal* NewSymbolLiteral(const char* name, int pos) { |
3408 return new (zone_) Literal(zone_, ast_value_factory_->NewSymbol(name), pos); | 3412 return new (local_zone_) |
3413 Literal(local_zone_, ast_value_factory_->NewSymbol(name), pos); | |
3409 } | 3414 } |
3410 | 3415 |
3411 Literal* NewNumberLiteral(double number, int pos, bool with_dot = false) { | 3416 Literal* NewNumberLiteral(double number, int pos, bool with_dot = false) { |
3412 return new (zone_) | 3417 return new (local_zone_) Literal( |
3413 Literal(zone_, ast_value_factory_->NewNumber(number, with_dot), pos); | 3418 local_zone_, ast_value_factory_->NewNumber(number, with_dot), pos); |
3414 } | 3419 } |
3415 | 3420 |
3416 Literal* NewSmiLiteral(int number, int pos) { | 3421 Literal* NewSmiLiteral(int number, int pos) { |
3417 return new (zone_) Literal(zone_, ast_value_factory_->NewSmi(number), pos); | 3422 return new (local_zone_) |
3423 Literal(local_zone_, ast_value_factory_->NewSmi(number), pos); | |
3418 } | 3424 } |
3419 | 3425 |
3420 Literal* NewBooleanLiteral(bool b, int pos) { | 3426 Literal* NewBooleanLiteral(bool b, int pos) { |
3421 return new (zone_) Literal(zone_, ast_value_factory_->NewBoolean(b), pos); | 3427 return new (local_zone_) |
3428 Literal(local_zone_, ast_value_factory_->NewBoolean(b), pos); | |
3422 } | 3429 } |
3423 | 3430 |
3424 Literal* NewNullLiteral(int pos) { | 3431 Literal* NewNullLiteral(int pos) { |
3425 return new (zone_) Literal(zone_, ast_value_factory_->NewNull(), pos); | 3432 return new (local_zone_) |
3433 Literal(local_zone_, ast_value_factory_->NewNull(), pos); | |
3426 } | 3434 } |
3427 | 3435 |
3428 Literal* NewUndefinedLiteral(int pos) { | 3436 Literal* NewUndefinedLiteral(int pos) { |
3429 return new (zone_) Literal(zone_, ast_value_factory_->NewUndefined(), pos); | 3437 return new (local_zone_) |
3438 Literal(local_zone_, ast_value_factory_->NewUndefined(), pos); | |
3430 } | 3439 } |
3431 | 3440 |
3432 Literal* NewTheHoleLiteral(int pos) { | 3441 Literal* NewTheHoleLiteral(int pos) { |
3433 return new (zone_) Literal(zone_, ast_value_factory_->NewTheHole(), pos); | 3442 return new (local_zone_) |
3443 Literal(local_zone_, ast_value_factory_->NewTheHole(), pos); | |
3434 } | 3444 } |
3435 | 3445 |
3436 ObjectLiteral* NewObjectLiteral( | 3446 ObjectLiteral* NewObjectLiteral( |
3437 ZoneList<ObjectLiteral::Property*>* properties, | 3447 ZoneList<ObjectLiteral::Property*>* properties, |
3438 int literal_index, | 3448 int literal_index, |
3439 int boilerplate_properties, | 3449 int boilerplate_properties, |
3440 bool has_function, | 3450 bool has_function, |
3441 bool is_strong, | 3451 bool is_strong, |
3442 int pos) { | 3452 int pos) { |
3443 return new (zone_) ObjectLiteral(zone_, properties, literal_index, | 3453 return new (local_zone_) |
3444 boilerplate_properties, has_function, | 3454 ObjectLiteral(local_zone_, properties, literal_index, |
3445 is_strong, pos); | 3455 boilerplate_properties, has_function, is_strong, pos); |
3446 } | 3456 } |
3447 | 3457 |
3448 ObjectLiteral::Property* NewObjectLiteralProperty( | 3458 ObjectLiteral::Property* NewObjectLiteralProperty( |
3449 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, | 3459 Expression* key, Expression* value, ObjectLiteralProperty::Kind kind, |
3450 bool is_static, bool is_computed_name) { | 3460 bool is_static, bool is_computed_name) { |
3451 return new (zone_) | 3461 return new (local_zone_) |
3452 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name); | 3462 ObjectLiteral::Property(key, value, kind, is_static, is_computed_name); |
3453 } | 3463 } |
3454 | 3464 |
3455 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, | 3465 ObjectLiteral::Property* NewObjectLiteralProperty(Expression* key, |
3456 Expression* value, | 3466 Expression* value, |
3457 bool is_static, | 3467 bool is_static, |
3458 bool is_computed_name) { | 3468 bool is_computed_name) { |
3459 return new (zone_) ObjectLiteral::Property(ast_value_factory_, key, value, | 3469 return new (local_zone_) ObjectLiteral::Property( |
3460 is_static, is_computed_name); | 3470 ast_value_factory_, key, value, is_static, is_computed_name); |
3461 } | 3471 } |
3462 | 3472 |
3463 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, | 3473 RegExpLiteral* NewRegExpLiteral(const AstRawString* pattern, |
3464 const AstRawString* flags, | 3474 const AstRawString* flags, |
3465 int literal_index, | 3475 int literal_index, |
3466 bool is_strong, | 3476 bool is_strong, |
3467 int pos) { | 3477 int pos) { |
3468 return new (zone_) RegExpLiteral(zone_, pattern, flags, literal_index, | 3478 return new (local_zone_) RegExpLiteral(local_zone_, pattern, flags, |
3469 is_strong, pos); | 3479 literal_index, is_strong, pos); |
3470 } | 3480 } |
3471 | 3481 |
3472 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, | 3482 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, |
3473 int literal_index, | 3483 int literal_index, |
3474 bool is_strong, | 3484 bool is_strong, |
3475 int pos) { | 3485 int pos) { |
3476 return new (zone_) | 3486 return new (local_zone_) |
3477 ArrayLiteral(zone_, values, -1, literal_index, is_strong, pos); | 3487 ArrayLiteral(local_zone_, values, -1, literal_index, is_strong, pos); |
3478 } | 3488 } |
3479 | 3489 |
3480 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, | 3490 ArrayLiteral* NewArrayLiteral(ZoneList<Expression*>* values, |
3481 int first_spread_index, int literal_index, | 3491 int first_spread_index, int literal_index, |
3482 bool is_strong, int pos) { | 3492 bool is_strong, int pos) { |
3483 return new (zone_) ArrayLiteral(zone_, values, first_spread_index, | 3493 return new (local_zone_) ArrayLiteral( |
3484 literal_index, is_strong, pos); | 3494 local_zone_, values, first_spread_index, literal_index, is_strong, pos); |
3485 } | 3495 } |
3486 | 3496 |
3487 VariableProxy* NewVariableProxy(Variable* var, | 3497 VariableProxy* NewVariableProxy(Variable* var, |
3488 int start_position = RelocInfo::kNoPosition, | 3498 int start_position = RelocInfo::kNoPosition, |
3489 int end_position = RelocInfo::kNoPosition) { | 3499 int end_position = RelocInfo::kNoPosition) { |
3490 return new (zone_) VariableProxy(zone_, var, start_position, end_position); | 3500 return new (parser_zone_) |
3501 VariableProxy(parser_zone_, var, start_position, end_position); | |
3491 } | 3502 } |
3492 | 3503 |
3493 VariableProxy* NewVariableProxy(const AstRawString* name, | 3504 VariableProxy* NewVariableProxy(const AstRawString* name, |
3494 Variable::Kind variable_kind, | 3505 Variable::Kind variable_kind, |
3495 int start_position = RelocInfo::kNoPosition, | 3506 int start_position = RelocInfo::kNoPosition, |
3496 int end_position = RelocInfo::kNoPosition) { | 3507 int end_position = RelocInfo::kNoPosition) { |
3497 DCHECK_NOT_NULL(name); | 3508 DCHECK_NOT_NULL(name); |
3498 return new (zone_) | 3509 return new (parser_zone_) VariableProxy(parser_zone_, name, variable_kind, |
3499 VariableProxy(zone_, name, variable_kind, start_position, end_position); | 3510 start_position, end_position); |
3500 } | 3511 } |
3501 | 3512 |
3502 Property* NewProperty(Expression* obj, Expression* key, int pos) { | 3513 Property* NewProperty(Expression* obj, Expression* key, int pos) { |
3503 return new (zone_) Property(zone_, obj, key, pos); | 3514 return new (local_zone_) Property(local_zone_, obj, key, pos); |
3504 } | 3515 } |
3505 | 3516 |
3506 Call* NewCall(Expression* expression, | 3517 Call* NewCall(Expression* expression, |
3507 ZoneList<Expression*>* arguments, | 3518 ZoneList<Expression*>* arguments, |
3508 int pos) { | 3519 int pos) { |
3509 return new (zone_) Call(zone_, expression, arguments, pos); | 3520 return new (local_zone_) Call(local_zone_, expression, arguments, pos); |
3510 } | 3521 } |
3511 | 3522 |
3512 CallNew* NewCallNew(Expression* expression, | 3523 CallNew* NewCallNew(Expression* expression, |
3513 ZoneList<Expression*>* arguments, | 3524 ZoneList<Expression*>* arguments, |
3514 int pos) { | 3525 int pos) { |
3515 return new (zone_) CallNew(zone_, expression, arguments, pos); | 3526 return new (local_zone_) CallNew(local_zone_, expression, arguments, pos); |
3516 } | 3527 } |
3517 | 3528 |
3518 CallRuntime* NewCallRuntime(Runtime::FunctionId id, | 3529 CallRuntime* NewCallRuntime(Runtime::FunctionId id, |
3519 ZoneList<Expression*>* arguments, int pos) { | 3530 ZoneList<Expression*>* arguments, int pos) { |
3520 return new (zone_) | 3531 return new (local_zone_) |
3521 CallRuntime(zone_, Runtime::FunctionForId(id), arguments, pos); | 3532 CallRuntime(local_zone_, Runtime::FunctionForId(id), arguments, pos); |
3522 } | 3533 } |
3523 | 3534 |
3524 CallRuntime* NewCallRuntime(const Runtime::Function* function, | 3535 CallRuntime* NewCallRuntime(const Runtime::Function* function, |
3525 ZoneList<Expression*>* arguments, int pos) { | 3536 ZoneList<Expression*>* arguments, int pos) { |
3526 return new (zone_) CallRuntime(zone_, function, arguments, pos); | 3537 return new (local_zone_) CallRuntime(local_zone_, function, arguments, pos); |
3527 } | 3538 } |
3528 | 3539 |
3529 CallRuntime* NewCallRuntime(int context_index, | 3540 CallRuntime* NewCallRuntime(int context_index, |
3530 ZoneList<Expression*>* arguments, int pos) { | 3541 ZoneList<Expression*>* arguments, int pos) { |
3531 return new (zone_) CallRuntime(zone_, context_index, arguments, pos); | 3542 return new (local_zone_) |
3543 CallRuntime(local_zone_, context_index, arguments, pos); | |
3532 } | 3544 } |
3533 | 3545 |
3534 UnaryOperation* NewUnaryOperation(Token::Value op, | 3546 UnaryOperation* NewUnaryOperation(Token::Value op, |
3535 Expression* expression, | 3547 Expression* expression, |
3536 int pos) { | 3548 int pos) { |
3537 return new (zone_) UnaryOperation(zone_, op, expression, pos); | 3549 return new (local_zone_) UnaryOperation(local_zone_, op, expression, pos); |
3538 } | 3550 } |
3539 | 3551 |
3540 BinaryOperation* NewBinaryOperation(Token::Value op, | 3552 BinaryOperation* NewBinaryOperation(Token::Value op, |
3541 Expression* left, | 3553 Expression* left, |
3542 Expression* right, | 3554 Expression* right, |
3543 int pos) { | 3555 int pos) { |
3544 return new (zone_) BinaryOperation(zone_, op, left, right, pos); | 3556 return new (local_zone_) BinaryOperation(local_zone_, op, left, right, pos); |
3545 } | 3557 } |
3546 | 3558 |
3547 CountOperation* NewCountOperation(Token::Value op, | 3559 CountOperation* NewCountOperation(Token::Value op, |
3548 bool is_prefix, | 3560 bool is_prefix, |
3549 Expression* expr, | 3561 Expression* expr, |
3550 int pos) { | 3562 int pos) { |
3551 return new (zone_) CountOperation(zone_, op, is_prefix, expr, pos); | 3563 return new (local_zone_) |
3564 CountOperation(local_zone_, op, is_prefix, expr, pos); | |
3552 } | 3565 } |
3553 | 3566 |
3554 CompareOperation* NewCompareOperation(Token::Value op, | 3567 CompareOperation* NewCompareOperation(Token::Value op, |
3555 Expression* left, | 3568 Expression* left, |
3556 Expression* right, | 3569 Expression* right, |
3557 int pos) { | 3570 int pos) { |
3558 return new (zone_) CompareOperation(zone_, op, left, right, pos); | 3571 return new (local_zone_) |
3572 CompareOperation(local_zone_, op, left, right, pos); | |
3559 } | 3573 } |
3560 | 3574 |
3561 Spread* NewSpread(Expression* expression, int pos) { | 3575 Spread* NewSpread(Expression* expression, int pos) { |
3562 return new (zone_) Spread(zone_, expression, pos); | 3576 return new (local_zone_) Spread(local_zone_, expression, pos); |
3563 } | 3577 } |
3564 | 3578 |
3565 Conditional* NewConditional(Expression* condition, | 3579 Conditional* NewConditional(Expression* condition, |
3566 Expression* then_expression, | 3580 Expression* then_expression, |
3567 Expression* else_expression, | 3581 Expression* else_expression, |
3568 int position) { | 3582 int position) { |
3569 return new (zone_) Conditional(zone_, condition, then_expression, | 3583 return new (local_zone_) Conditional( |
3570 else_expression, position); | 3584 local_zone_, condition, then_expression, else_expression, position); |
3571 } | 3585 } |
3572 | 3586 |
3573 Assignment* NewAssignment(Token::Value op, | 3587 Assignment* NewAssignment(Token::Value op, |
3574 Expression* target, | 3588 Expression* target, |
3575 Expression* value, | 3589 Expression* value, |
3576 int pos) { | 3590 int pos) { |
3577 DCHECK(Token::IsAssignmentOp(op)); | 3591 DCHECK(Token::IsAssignmentOp(op)); |
3578 Assignment* assign = new (zone_) Assignment(zone_, op, target, value, pos); | 3592 Assignment* assign = |
3593 new (local_zone_) Assignment(local_zone_, op, target, value, pos); | |
3579 if (assign->is_compound()) { | 3594 if (assign->is_compound()) { |
3580 DCHECK(Token::IsAssignmentOp(op)); | 3595 DCHECK(Token::IsAssignmentOp(op)); |
3581 assign->binary_operation_ = | 3596 assign->binary_operation_ = |
3582 NewBinaryOperation(assign->binary_op(), target, value, pos + 1); | 3597 NewBinaryOperation(assign->binary_op(), target, value, pos + 1); |
3583 } | 3598 } |
3584 return assign; | 3599 return assign; |
3585 } | 3600 } |
3586 | 3601 |
3587 Yield* NewYield(Expression *generator_object, | 3602 Yield* NewYield(Expression *generator_object, |
3588 Expression* expression, | 3603 Expression* expression, |
3589 Yield::Kind yield_kind, | 3604 Yield::Kind yield_kind, |
3590 int pos) { | 3605 int pos) { |
3591 if (!expression) expression = NewUndefinedLiteral(pos); | 3606 if (!expression) expression = NewUndefinedLiteral(pos); |
3592 return new (zone_) | 3607 return new (local_zone_) |
3593 Yield(zone_, generator_object, expression, yield_kind, pos); | 3608 Yield(local_zone_, generator_object, expression, yield_kind, pos); |
3594 } | 3609 } |
3595 | 3610 |
3596 Throw* NewThrow(Expression* exception, int pos) { | 3611 Throw* NewThrow(Expression* exception, int pos) { |
3597 return new (zone_) Throw(zone_, exception, pos); | 3612 return new (local_zone_) Throw(local_zone_, exception, pos); |
3598 } | 3613 } |
3599 | 3614 |
3600 FunctionLiteral* NewFunctionLiteral( | 3615 FunctionLiteral* NewFunctionLiteral( |
3601 const AstRawString* name, AstValueFactory* ast_value_factory, | 3616 const AstRawString* name, AstValueFactory* ast_value_factory, |
3602 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count, | 3617 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count, |
3603 int expected_property_count, int parameter_count, | 3618 int expected_property_count, int parameter_count, |
3604 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 3619 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
3605 FunctionLiteral::FunctionType function_type, | 3620 FunctionLiteral::FunctionType function_type, |
3606 FunctionLiteral::IsFunctionFlag is_function, | 3621 FunctionLiteral::IsFunctionFlag is_function, |
3607 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, | 3622 FunctionLiteral::EagerCompileHint eager_compile_hint, FunctionKind kind, |
3608 int position) { | 3623 int position) { |
3609 return new (zone_) FunctionLiteral( | 3624 return new (parser_zone_) FunctionLiteral( |
3610 zone_, name, ast_value_factory, scope, body, materialized_literal_count, | 3625 parser_zone_, name, ast_value_factory, scope, body, |
3611 expected_property_count, parameter_count, function_type, | 3626 materialized_literal_count, expected_property_count, parameter_count, |
3612 has_duplicate_parameters, is_function, eager_compile_hint, kind, | 3627 function_type, has_duplicate_parameters, is_function, |
3613 position); | 3628 eager_compile_hint, kind, position); |
3614 } | 3629 } |
3615 | 3630 |
3616 ClassLiteral* NewClassLiteral(const AstRawString* name, Scope* scope, | 3631 ClassLiteral* NewClassLiteral(const AstRawString* name, Scope* scope, |
3617 VariableProxy* proxy, Expression* extends, | 3632 VariableProxy* proxy, Expression* extends, |
3618 FunctionLiteral* constructor, | 3633 FunctionLiteral* constructor, |
3619 ZoneList<ObjectLiteral::Property*>* properties, | 3634 ZoneList<ObjectLiteral::Property*>* properties, |
3620 int start_position, int end_position) { | 3635 int start_position, int end_position) { |
3621 return new (zone_) | 3636 return new (parser_zone_) |
3622 ClassLiteral(zone_, name, scope, proxy, extends, constructor, | 3637 ClassLiteral(parser_zone_, name, scope, proxy, extends, constructor, |
3623 properties, start_position, end_position); | 3638 properties, start_position, end_position); |
3624 } | 3639 } |
3625 | 3640 |
3626 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, | 3641 NativeFunctionLiteral* NewNativeFunctionLiteral(const AstRawString* name, |
3627 v8::Extension* extension, | 3642 v8::Extension* extension, |
3628 int pos) { | 3643 int pos) { |
3629 return new (zone_) NativeFunctionLiteral(zone_, name, extension, pos); | 3644 return new (parser_zone_) |
3645 NativeFunctionLiteral(parser_zone_, name, extension, pos); | |
3630 } | 3646 } |
3631 | 3647 |
3632 ThisFunction* NewThisFunction(int pos) { | 3648 ThisFunction* NewThisFunction(int pos) { |
3633 return new (zone_) ThisFunction(zone_, pos); | 3649 return new (local_zone_) ThisFunction(local_zone_, pos); |
3634 } | 3650 } |
3635 | 3651 |
3636 SuperPropertyReference* NewSuperPropertyReference(VariableProxy* this_var, | 3652 SuperPropertyReference* NewSuperPropertyReference(VariableProxy* this_var, |
3637 Expression* home_object, | 3653 Expression* home_object, |
3638 int pos) { | 3654 int pos) { |
3639 return new (zone_) | 3655 return new (parser_zone_) |
3640 SuperPropertyReference(zone_, this_var, home_object, pos); | 3656 SuperPropertyReference(parser_zone_, this_var, home_object, pos); |
3641 } | 3657 } |
3642 | 3658 |
3643 SuperCallReference* NewSuperCallReference(VariableProxy* this_var, | 3659 SuperCallReference* NewSuperCallReference(VariableProxy* this_var, |
3644 VariableProxy* new_target_var, | 3660 VariableProxy* new_target_var, |
3645 VariableProxy* this_function_var, | 3661 VariableProxy* this_function_var, |
3646 int pos) { | 3662 int pos) { |
3647 return new (zone_) SuperCallReference(zone_, this_var, new_target_var, | 3663 return new (parser_zone_) SuperCallReference( |
3648 this_function_var, pos); | 3664 parser_zone_, this_var, new_target_var, this_function_var, pos); |
3649 } | 3665 } |
3650 | 3666 |
3651 EmptyParentheses* NewEmptyParentheses(int pos) { | 3667 EmptyParentheses* NewEmptyParentheses(int pos) { |
3652 return new (zone_) EmptyParentheses(zone_, pos); | 3668 return new (local_zone_) EmptyParentheses(local_zone_, pos); |
3653 } | 3669 } |
3654 | 3670 |
3671 Zone* zone() const { return local_zone_; } | |
3672 | |
3673 // Handles use of temporary zones when parsing inner function bodies. | |
3674 class BodyScope { | |
3675 public: | |
3676 BodyScope(AstNodeFactory* factory, Zone* temp_zone, bool can_use_temp_zone) | |
3677 : factory_(factory), prev_zone_(factory->local_zone_) { | |
3678 if (can_use_temp_zone) { | |
3679 factory->local_zone_ = temp_zone; | |
3680 } | |
3681 } | |
3682 | |
3683 ~BodyScope() { factory_->local_zone_ = prev_zone_; } | |
3684 | |
3685 private: | |
3686 AstNodeFactory* factory_; | |
3687 Zone* prev_zone_; | |
3688 }; | |
3689 | |
3655 private: | 3690 private: |
3656 Zone* zone_; | 3691 // This zone may be deallocated upon returning from parsing a function body |
3692 // which we can guarantee is not going to be compiled or have its AST | |
3693 // inspected. | |
3694 // See ParseFunctionLiteral in parser.cc for preconditions. | |
3695 Zone* local_zone_; | |
3696 // HeapObjects which need to persist until scope analysis must be allocated in | |
Michael Starzinger
2015/09/10 14:06:36
nit: s/HeapObjects/Zone objects/ ... because HeapO
conradw
2015/09/10 14:15:55
Oops! Done.
| |
3697 // the parser-level zone. | |
3698 Zone* parser_zone_; | |
3657 AstValueFactory* ast_value_factory_; | 3699 AstValueFactory* ast_value_factory_; |
3658 }; | 3700 }; |
3659 | 3701 |
3660 | 3702 |
3661 } } // namespace v8::internal | 3703 } } // namespace v8::internal |
3662 | 3704 |
3663 #endif // V8_AST_H_ | 3705 #endif // V8_AST_H_ |
OLD | NEW |