Chromium Code Reviews| 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/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/assembler.h" | 10 #include "src/assembler.h" |
| (...skipping 2343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2354 enum IsFunctionFlag { | 2354 enum IsFunctionFlag { |
| 2355 kGlobalOrEval, | 2355 kGlobalOrEval, |
| 2356 kIsFunction | 2356 kIsFunction |
| 2357 }; | 2357 }; |
| 2358 | 2358 |
| 2359 enum IsParenthesizedFlag { | 2359 enum IsParenthesizedFlag { |
| 2360 kIsParenthesized, | 2360 kIsParenthesized, |
| 2361 kNotParenthesized | 2361 kNotParenthesized |
| 2362 }; | 2362 }; |
| 2363 | 2363 |
| 2364 enum KindFlag { | 2364 enum IsGeneratorFlag { kNotGenerator = 0, kIsGenerator = 1 }; |
|
arv (Not doing code reviews)
2014/08/20 22:08:29
I initially added kConciseMethod to this enum but
| |
| 2365 kNormalFunction, | 2365 |
| 2366 kArrowFunction, | 2366 enum IsArrowFlag { kNotArrow = 0, kIsArrow = 1 }; |
| 2367 kGeneratorFunction | 2367 |
| 2368 }; | 2368 enum IsConciseMethodFlag { kNotConciseMethod = 0, kIsConciseMethod = 1 }; |
| 2369 | 2369 |
| 2370 enum ArityRestriction { | 2370 enum ArityRestriction { |
| 2371 NORMAL_ARITY, | 2371 NORMAL_ARITY, |
| 2372 GETTER_ARITY, | 2372 GETTER_ARITY, |
| 2373 SETTER_ARITY | 2373 SETTER_ARITY |
| 2374 }; | 2374 }; |
| 2375 | 2375 |
| 2376 DECLARE_NODE_TYPE(FunctionLiteral) | 2376 DECLARE_NODE_TYPE(FunctionLiteral) |
| 2377 | 2377 |
| 2378 Handle<String> name() const { return raw_name_->string(); } | 2378 Handle<String> name() const { return raw_name_->string(); } |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2451 // - var x = function() { ... }(); | 2451 // - var x = function() { ... }(); |
| 2452 bool is_parenthesized() { | 2452 bool is_parenthesized() { |
| 2453 return IsParenthesized::decode(bitfield_) == kIsParenthesized; | 2453 return IsParenthesized::decode(bitfield_) == kIsParenthesized; |
| 2454 } | 2454 } |
| 2455 void set_parenthesized() { | 2455 void set_parenthesized() { |
| 2456 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized); | 2456 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized); |
| 2457 } | 2457 } |
| 2458 | 2458 |
| 2459 bool is_generator() { return IsGenerator::decode(bitfield_); } | 2459 bool is_generator() { return IsGenerator::decode(bitfield_); } |
| 2460 bool is_arrow() { return IsArrow::decode(bitfield_); } | 2460 bool is_arrow() { return IsArrow::decode(bitfield_); } |
| 2461 bool is_concise_method() { return IsConciseMethod::decode(bitfield_); } | |
| 2461 | 2462 |
| 2462 int ast_node_count() { return ast_properties_.node_count(); } | 2463 int ast_node_count() { return ast_properties_.node_count(); } |
| 2463 AstProperties::Flags* flags() { return ast_properties_.flags(); } | 2464 AstProperties::Flags* flags() { return ast_properties_.flags(); } |
| 2464 void set_ast_properties(AstProperties* ast_properties) { | 2465 void set_ast_properties(AstProperties* ast_properties) { |
| 2465 ast_properties_ = *ast_properties; | 2466 ast_properties_ = *ast_properties; |
| 2466 } | 2467 } |
| 2467 int slot_count() { | 2468 int slot_count() { |
| 2468 return ast_properties_.feedback_slots(); | 2469 return ast_properties_.feedback_slots(); |
| 2469 } | 2470 } |
| 2470 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } | 2471 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } |
| 2471 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } | 2472 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } |
| 2472 void set_dont_optimize_reason(BailoutReason reason) { | 2473 void set_dont_optimize_reason(BailoutReason reason) { |
| 2473 dont_optimize_reason_ = reason; | 2474 dont_optimize_reason_ = reason; |
| 2474 } | 2475 } |
| 2475 | 2476 |
| 2476 protected: | 2477 protected: |
| 2477 FunctionLiteral(Zone* zone, const AstRawString* name, | 2478 FunctionLiteral(Zone* zone, const AstRawString* name, |
| 2478 AstValueFactory* ast_value_factory, Scope* scope, | 2479 AstValueFactory* ast_value_factory, Scope* scope, |
| 2479 ZoneList<Statement*>* body, int materialized_literal_count, | 2480 ZoneList<Statement*>* body, int materialized_literal_count, |
| 2480 int expected_property_count, int handler_count, | 2481 int expected_property_count, int handler_count, |
| 2481 int parameter_count, FunctionType function_type, | 2482 int parameter_count, FunctionType function_type, |
| 2482 ParameterFlag has_duplicate_parameters, | 2483 ParameterFlag has_duplicate_parameters, |
| 2483 IsFunctionFlag is_function, | 2484 IsFunctionFlag is_function, |
| 2484 IsParenthesizedFlag is_parenthesized, KindFlag kind, | 2485 IsParenthesizedFlag is_parenthesized, |
| 2485 int position) | 2486 IsGeneratorFlag is_generator, IsArrowFlag is_arrow, |
| 2487 IsConciseMethodFlag is_concise_method, int position) | |
| 2486 : Expression(zone, position), | 2488 : Expression(zone, position), |
| 2487 raw_name_(name), | 2489 raw_name_(name), |
| 2488 scope_(scope), | 2490 scope_(scope), |
| 2489 body_(body), | 2491 body_(body), |
| 2490 raw_inferred_name_(ast_value_factory->empty_string()), | 2492 raw_inferred_name_(ast_value_factory->empty_string()), |
| 2491 dont_optimize_reason_(kNoReason), | 2493 dont_optimize_reason_(kNoReason), |
| 2492 materialized_literal_count_(materialized_literal_count), | 2494 materialized_literal_count_(materialized_literal_count), |
| 2493 expected_property_count_(expected_property_count), | 2495 expected_property_count_(expected_property_count), |
| 2494 handler_count_(handler_count), | 2496 handler_count_(handler_count), |
| 2495 parameter_count_(parameter_count), | 2497 parameter_count_(parameter_count), |
| 2496 function_token_position_(RelocInfo::kNoPosition) { | 2498 function_token_position_(RelocInfo::kNoPosition) { |
| 2497 bitfield_ = IsExpression::encode(function_type != DECLARATION) | | 2499 bitfield_ = IsExpression::encode(function_type != DECLARATION) | |
| 2498 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) | | 2500 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) | |
| 2499 Pretenure::encode(false) | | 2501 Pretenure::encode(false) | |
| 2500 HasDuplicateParameters::encode(has_duplicate_parameters) | | 2502 HasDuplicateParameters::encode(has_duplicate_parameters) | |
| 2501 IsFunction::encode(is_function) | | 2503 IsFunction::encode(is_function) | |
| 2502 IsParenthesized::encode(is_parenthesized) | | 2504 IsParenthesized::encode(is_parenthesized) | |
| 2503 IsGenerator::encode(kind == kGeneratorFunction) | | 2505 IsGenerator::encode(is_generator) | IsArrow::encode(is_arrow) | |
| 2504 IsArrow::encode(kind == kArrowFunction); | 2506 IsConciseMethod::encode(is_concise_method); |
| 2505 } | 2507 } |
| 2506 | 2508 |
| 2507 private: | 2509 private: |
| 2508 const AstRawString* raw_name_; | 2510 const AstRawString* raw_name_; |
| 2509 Handle<String> name_; | 2511 Handle<String> name_; |
| 2510 Handle<SharedFunctionInfo> shared_info_; | 2512 Handle<SharedFunctionInfo> shared_info_; |
| 2511 Scope* scope_; | 2513 Scope* scope_; |
| 2512 ZoneList<Statement*>* body_; | 2514 ZoneList<Statement*>* body_; |
| 2513 const AstString* raw_inferred_name_; | 2515 const AstString* raw_inferred_name_; |
| 2514 Handle<String> inferred_name_; | 2516 Handle<String> inferred_name_; |
| 2515 AstProperties ast_properties_; | 2517 AstProperties ast_properties_; |
| 2516 BailoutReason dont_optimize_reason_; | 2518 BailoutReason dont_optimize_reason_; |
| 2517 | 2519 |
| 2518 int materialized_literal_count_; | 2520 int materialized_literal_count_; |
| 2519 int expected_property_count_; | 2521 int expected_property_count_; |
| 2520 int handler_count_; | 2522 int handler_count_; |
| 2521 int parameter_count_; | 2523 int parameter_count_; |
| 2522 int function_token_position_; | 2524 int function_token_position_; |
| 2523 | 2525 |
| 2524 unsigned bitfield_; | 2526 unsigned bitfield_; |
| 2525 class IsExpression: public BitField<bool, 0, 1> {}; | 2527 class IsExpression: public BitField<bool, 0, 1> {}; |
| 2526 class IsAnonymous: public BitField<bool, 1, 1> {}; | 2528 class IsAnonymous: public BitField<bool, 1, 1> {}; |
| 2527 class Pretenure: public BitField<bool, 2, 1> {}; | 2529 class Pretenure: public BitField<bool, 2, 1> {}; |
| 2528 class HasDuplicateParameters: public BitField<ParameterFlag, 3, 1> {}; | 2530 class HasDuplicateParameters: public BitField<ParameterFlag, 3, 1> {}; |
| 2529 class IsFunction: public BitField<IsFunctionFlag, 4, 1> {}; | 2531 class IsFunction: public BitField<IsFunctionFlag, 4, 1> {}; |
| 2530 class IsParenthesized: public BitField<IsParenthesizedFlag, 5, 1> {}; | 2532 class IsParenthesized: public BitField<IsParenthesizedFlag, 5, 1> {}; |
| 2531 class IsGenerator : public BitField<bool, 6, 1> {}; | 2533 class IsGenerator : public BitField<bool, 6, 1> {}; |
| 2532 class IsArrow : public BitField<bool, 7, 1> {}; | 2534 class IsArrow : public BitField<bool, 7, 1> {}; |
| 2535 class IsConciseMethod : public BitField<bool, 8, 1> {}; | |
| 2533 }; | 2536 }; |
| 2534 | 2537 |
| 2535 | 2538 |
| 2536 class NativeFunctionLiteral V8_FINAL : public Expression { | 2539 class NativeFunctionLiteral V8_FINAL : public Expression { |
| 2537 public: | 2540 public: |
| 2538 DECLARE_NODE_TYPE(NativeFunctionLiteral) | 2541 DECLARE_NODE_TYPE(NativeFunctionLiteral) |
| 2539 | 2542 |
| 2540 Handle<String> name() const { return name_->string(); } | 2543 Handle<String> name() const { return name_->string(); } |
| 2541 v8::Extension* extension() const { return extension_; } | 2544 v8::Extension* extension() const { return extension_; } |
| 2542 | 2545 |
| (...skipping 920 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3463 } | 3466 } |
| 3464 | 3467 |
| 3465 FunctionLiteral* NewFunctionLiteral( | 3468 FunctionLiteral* NewFunctionLiteral( |
| 3466 const AstRawString* name, AstValueFactory* ast_value_factory, | 3469 const AstRawString* name, AstValueFactory* ast_value_factory, |
| 3467 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count, | 3470 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count, |
| 3468 int expected_property_count, int handler_count, int parameter_count, | 3471 int expected_property_count, int handler_count, int parameter_count, |
| 3469 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 3472 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
| 3470 FunctionLiteral::FunctionType function_type, | 3473 FunctionLiteral::FunctionType function_type, |
| 3471 FunctionLiteral::IsFunctionFlag is_function, | 3474 FunctionLiteral::IsFunctionFlag is_function, |
| 3472 FunctionLiteral::IsParenthesizedFlag is_parenthesized, | 3475 FunctionLiteral::IsParenthesizedFlag is_parenthesized, |
| 3473 FunctionLiteral::KindFlag kind, int position) { | 3476 FunctionLiteral::IsGeneratorFlag is_generator, |
| 3477 FunctionLiteral::IsArrowFlag is_arrow, | |
| 3478 FunctionLiteral::IsConciseMethodFlag is_concise_method, int position) { | |
| 3474 FunctionLiteral* lit = new (zone_) FunctionLiteral( | 3479 FunctionLiteral* lit = new (zone_) FunctionLiteral( |
| 3475 zone_, name, ast_value_factory, scope, body, materialized_literal_count, | 3480 zone_, name, ast_value_factory, scope, body, materialized_literal_count, |
| 3476 expected_property_count, handler_count, parameter_count, function_type, | 3481 expected_property_count, handler_count, parameter_count, function_type, |
| 3477 has_duplicate_parameters, is_function, is_parenthesized, kind, | 3482 has_duplicate_parameters, is_function, is_parenthesized, is_generator, |
| 3478 position); | 3483 is_arrow, is_concise_method, position); |
| 3479 // Top-level literal doesn't count for the AST's properties. | 3484 // Top-level literal doesn't count for the AST's properties. |
| 3480 if (is_function == FunctionLiteral::kIsFunction) { | 3485 if (is_function == FunctionLiteral::kIsFunction) { |
| 3481 visitor_.VisitFunctionLiteral(lit); | 3486 visitor_.VisitFunctionLiteral(lit); |
| 3482 } | 3487 } |
| 3483 return lit; | 3488 return lit; |
| 3484 } | 3489 } |
| 3485 | 3490 |
| 3486 NativeFunctionLiteral* NewNativeFunctionLiteral( | 3491 NativeFunctionLiteral* NewNativeFunctionLiteral( |
| 3487 const AstRawString* name, v8::Extension* extension, | 3492 const AstRawString* name, v8::Extension* extension, |
| 3488 int pos) { | 3493 int pos) { |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 3506 private: | 3511 private: |
| 3507 Zone* zone_; | 3512 Zone* zone_; |
| 3508 Visitor visitor_; | 3513 Visitor visitor_; |
| 3509 AstValueFactory* ast_value_factory_; | 3514 AstValueFactory* ast_value_factory_; |
| 3510 }; | 3515 }; |
| 3511 | 3516 |
| 3512 | 3517 |
| 3513 } } // namespace v8::internal | 3518 } } // namespace v8::internal |
| 3514 | 3519 |
| 3515 #endif // V8_AST_H_ | 3520 #endif // V8_AST_H_ |
| OLD | NEW |