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 2307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2318 enum IsFunctionFlag { | 2318 enum IsFunctionFlag { |
2319 kGlobalOrEval, | 2319 kGlobalOrEval, |
2320 kIsFunction | 2320 kIsFunction |
2321 }; | 2321 }; |
2322 | 2322 |
2323 enum IsParenthesizedFlag { | 2323 enum IsParenthesizedFlag { |
2324 kIsParenthesized, | 2324 kIsParenthesized, |
2325 kNotParenthesized | 2325 kNotParenthesized |
2326 }; | 2326 }; |
2327 | 2327 |
2328 enum KindFlag { | |
2329 kNormalFunction, | |
2330 kArrowFunction, | |
2331 kGeneratorFunction | |
2332 }; | |
2333 | |
2334 enum ArityRestriction { | 2328 enum ArityRestriction { |
2335 NORMAL_ARITY, | 2329 NORMAL_ARITY, |
2336 GETTER_ARITY, | 2330 GETTER_ARITY, |
2337 SETTER_ARITY | 2331 SETTER_ARITY |
2338 }; | 2332 }; |
2339 | 2333 |
2340 DECLARE_NODE_TYPE(FunctionLiteral) | 2334 DECLARE_NODE_TYPE(FunctionLiteral) |
2341 | 2335 |
2342 Handle<String> name() const { return raw_name_->string(); } | 2336 Handle<String> name() const { return raw_name_->string(); } |
2343 const AstRawString* raw_name() const { return raw_name_; } | 2337 const AstRawString* raw_name() const { return raw_name_; } |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2413 // function will be called immediately: | 2407 // function will be called immediately: |
2414 // - (function() { ... })(); | 2408 // - (function() { ... })(); |
2415 // - var x = function() { ... }(); | 2409 // - var x = function() { ... }(); |
2416 bool is_parenthesized() { | 2410 bool is_parenthesized() { |
2417 return IsParenthesized::decode(bitfield_) == kIsParenthesized; | 2411 return IsParenthesized::decode(bitfield_) == kIsParenthesized; |
2418 } | 2412 } |
2419 void set_parenthesized() { | 2413 void set_parenthesized() { |
2420 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized); | 2414 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized); |
2421 } | 2415 } |
2422 | 2416 |
2423 bool is_generator() { return IsGenerator::decode(bitfield_); } | 2417 FunctionKind kind() { return FunctionKindBits::decode(bitfield_); } |
2424 bool is_arrow() { return IsArrow::decode(bitfield_); } | 2418 bool is_arrow() { |
| 2419 return IsArrowFunction(FunctionKindBits::decode(bitfield_)); |
| 2420 } |
| 2421 bool is_generator() { |
| 2422 return IsGeneratorFunction(FunctionKindBits::decode(bitfield_)); |
| 2423 } |
| 2424 bool is_concise_method() { |
| 2425 return IsConciseMethod(FunctionKindBits::decode(bitfield_)); |
| 2426 } |
2425 | 2427 |
2426 int ast_node_count() { return ast_properties_.node_count(); } | 2428 int ast_node_count() { return ast_properties_.node_count(); } |
2427 AstProperties::Flags* flags() { return ast_properties_.flags(); } | 2429 AstProperties::Flags* flags() { return ast_properties_.flags(); } |
2428 void set_ast_properties(AstProperties* ast_properties) { | 2430 void set_ast_properties(AstProperties* ast_properties) { |
2429 ast_properties_ = *ast_properties; | 2431 ast_properties_ = *ast_properties; |
2430 } | 2432 } |
2431 int slot_count() { | 2433 int slot_count() { |
2432 return ast_properties_.feedback_slots(); | 2434 return ast_properties_.feedback_slots(); |
2433 } | 2435 } |
2434 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } | 2436 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } |
2435 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } | 2437 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } |
2436 void set_dont_optimize_reason(BailoutReason reason) { | 2438 void set_dont_optimize_reason(BailoutReason reason) { |
2437 dont_optimize_reason_ = reason; | 2439 dont_optimize_reason_ = reason; |
2438 } | 2440 } |
2439 | 2441 |
2440 protected: | 2442 protected: |
2441 FunctionLiteral(Zone* zone, const AstRawString* name, | 2443 FunctionLiteral(Zone* zone, const AstRawString* name, |
2442 AstValueFactory* ast_value_factory, Scope* scope, | 2444 AstValueFactory* ast_value_factory, Scope* scope, |
2443 ZoneList<Statement*>* body, int materialized_literal_count, | 2445 ZoneList<Statement*>* body, int materialized_literal_count, |
2444 int expected_property_count, int handler_count, | 2446 int expected_property_count, int handler_count, |
2445 int parameter_count, FunctionType function_type, | 2447 int parameter_count, FunctionType function_type, |
2446 ParameterFlag has_duplicate_parameters, | 2448 ParameterFlag has_duplicate_parameters, |
2447 IsFunctionFlag is_function, | 2449 IsFunctionFlag is_function, |
2448 IsParenthesizedFlag is_parenthesized, KindFlag kind, | 2450 IsParenthesizedFlag is_parenthesized, FunctionKind kind, |
2449 int position, IdGen* id_gen) | 2451 int position, IdGen* id_gen) |
2450 : Expression(zone, position, id_gen), | 2452 : Expression(zone, position, id_gen), |
2451 raw_name_(name), | 2453 raw_name_(name), |
2452 scope_(scope), | 2454 scope_(scope), |
2453 body_(body), | 2455 body_(body), |
2454 raw_inferred_name_(ast_value_factory->empty_string()), | 2456 raw_inferred_name_(ast_value_factory->empty_string()), |
2455 dont_optimize_reason_(kNoReason), | 2457 dont_optimize_reason_(kNoReason), |
2456 materialized_literal_count_(materialized_literal_count), | 2458 materialized_literal_count_(materialized_literal_count), |
2457 expected_property_count_(expected_property_count), | 2459 expected_property_count_(expected_property_count), |
2458 handler_count_(handler_count), | 2460 handler_count_(handler_count), |
2459 parameter_count_(parameter_count), | 2461 parameter_count_(parameter_count), |
2460 function_token_position_(RelocInfo::kNoPosition) { | 2462 function_token_position_(RelocInfo::kNoPosition) { |
2461 bitfield_ = IsExpression::encode(function_type != DECLARATION) | | 2463 bitfield_ = IsExpression::encode(function_type != DECLARATION) | |
2462 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) | | 2464 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) | |
2463 Pretenure::encode(false) | | 2465 Pretenure::encode(false) | |
2464 HasDuplicateParameters::encode(has_duplicate_parameters) | | 2466 HasDuplicateParameters::encode(has_duplicate_parameters) | |
2465 IsFunction::encode(is_function) | | 2467 IsFunction::encode(is_function) | |
2466 IsParenthesized::encode(is_parenthesized) | | 2468 IsParenthesized::encode(is_parenthesized) | |
2467 IsGenerator::encode(kind == kGeneratorFunction) | | 2469 FunctionKindBits::encode(kind); |
2468 IsArrow::encode(kind == kArrowFunction); | 2470 DCHECK(IsValidFunctionKind(kind)); |
2469 } | 2471 } |
2470 | 2472 |
2471 private: | 2473 private: |
2472 const AstRawString* raw_name_; | 2474 const AstRawString* raw_name_; |
2473 Handle<String> name_; | 2475 Handle<String> name_; |
2474 Handle<SharedFunctionInfo> shared_info_; | 2476 Handle<SharedFunctionInfo> shared_info_; |
2475 Scope* scope_; | 2477 Scope* scope_; |
2476 ZoneList<Statement*>* body_; | 2478 ZoneList<Statement*>* body_; |
2477 const AstString* raw_inferred_name_; | 2479 const AstString* raw_inferred_name_; |
2478 Handle<String> inferred_name_; | 2480 Handle<String> inferred_name_; |
2479 AstProperties ast_properties_; | 2481 AstProperties ast_properties_; |
2480 BailoutReason dont_optimize_reason_; | 2482 BailoutReason dont_optimize_reason_; |
2481 | 2483 |
2482 int materialized_literal_count_; | 2484 int materialized_literal_count_; |
2483 int expected_property_count_; | 2485 int expected_property_count_; |
2484 int handler_count_; | 2486 int handler_count_; |
2485 int parameter_count_; | 2487 int parameter_count_; |
2486 int function_token_position_; | 2488 int function_token_position_; |
2487 | 2489 |
2488 unsigned bitfield_; | 2490 unsigned bitfield_; |
2489 class IsExpression: public BitField<bool, 0, 1> {}; | 2491 class IsExpression : public BitField<bool, 0, 1> {}; |
2490 class IsAnonymous: public BitField<bool, 1, 1> {}; | 2492 class IsAnonymous : public BitField<bool, 1, 1> {}; |
2491 class Pretenure: public BitField<bool, 2, 1> {}; | 2493 class Pretenure : public BitField<bool, 2, 1> {}; |
2492 class HasDuplicateParameters: public BitField<ParameterFlag, 3, 1> {}; | 2494 class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {}; |
2493 class IsFunction: public BitField<IsFunctionFlag, 4, 1> {}; | 2495 class IsFunction : public BitField<IsFunctionFlag, 4, 1> {}; |
2494 class IsParenthesized: public BitField<IsParenthesizedFlag, 5, 1> {}; | 2496 class IsParenthesized : public BitField<IsParenthesizedFlag, 5, 1> {}; |
2495 class IsGenerator : public BitField<bool, 6, 1> {}; | 2497 class FunctionKindBits : public BitField<FunctionKind, 6, 3> {}; |
2496 class IsArrow : public BitField<bool, 7, 1> {}; | |
2497 }; | 2498 }; |
2498 | 2499 |
2499 | 2500 |
2500 class NativeFunctionLiteral FINAL : public Expression { | 2501 class NativeFunctionLiteral FINAL : public Expression { |
2501 public: | 2502 public: |
2502 DECLARE_NODE_TYPE(NativeFunctionLiteral) | 2503 DECLARE_NODE_TYPE(NativeFunctionLiteral) |
2503 | 2504 |
2504 Handle<String> name() const { return name_->string(); } | 2505 Handle<String> name() const { return name_->string(); } |
2505 v8::Extension* extension() const { return extension_; } | 2506 v8::Extension* extension() const { return extension_; } |
2506 | 2507 |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3432 VISIT_AND_RETURN(Throw, t) | 3433 VISIT_AND_RETURN(Throw, t) |
3433 } | 3434 } |
3434 | 3435 |
3435 FunctionLiteral* NewFunctionLiteral( | 3436 FunctionLiteral* NewFunctionLiteral( |
3436 const AstRawString* name, AstValueFactory* ast_value_factory, | 3437 const AstRawString* name, AstValueFactory* ast_value_factory, |
3437 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count, | 3438 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count, |
3438 int expected_property_count, int handler_count, int parameter_count, | 3439 int expected_property_count, int handler_count, int parameter_count, |
3439 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 3440 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
3440 FunctionLiteral::FunctionType function_type, | 3441 FunctionLiteral::FunctionType function_type, |
3441 FunctionLiteral::IsFunctionFlag is_function, | 3442 FunctionLiteral::IsFunctionFlag is_function, |
3442 FunctionLiteral::IsParenthesizedFlag is_parenthesized, | 3443 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, |
3443 FunctionLiteral::KindFlag kind, int position) { | 3444 int position) { |
3444 FunctionLiteral* lit = new (zone_) FunctionLiteral( | 3445 FunctionLiteral* lit = new (zone_) FunctionLiteral( |
3445 zone_, name, ast_value_factory, scope, body, materialized_literal_count, | 3446 zone_, name, ast_value_factory, scope, body, materialized_literal_count, |
3446 expected_property_count, handler_count, parameter_count, function_type, | 3447 expected_property_count, handler_count, parameter_count, function_type, |
3447 has_duplicate_parameters, is_function, is_parenthesized, kind, position, | 3448 has_duplicate_parameters, is_function, is_parenthesized, kind, position, |
3448 id_gen_); | 3449 id_gen_); |
3449 // Top-level literal doesn't count for the AST's properties. | 3450 // Top-level literal doesn't count for the AST's properties. |
3450 if (is_function == FunctionLiteral::kIsFunction) { | 3451 if (is_function == FunctionLiteral::kIsFunction) { |
3451 visitor_.VisitFunctionLiteral(lit); | 3452 visitor_.VisitFunctionLiteral(lit); |
3452 } | 3453 } |
3453 return lit; | 3454 return lit; |
(...skipping 24 matching lines...) Expand all Loading... |
3478 Zone* zone_; | 3479 Zone* zone_; |
3479 Visitor visitor_; | 3480 Visitor visitor_; |
3480 AstValueFactory* ast_value_factory_; | 3481 AstValueFactory* ast_value_factory_; |
3481 AstNode::IdGen* id_gen_; | 3482 AstNode::IdGen* id_gen_; |
3482 }; | 3483 }; |
3483 | 3484 |
3484 | 3485 |
3485 } } // namespace v8::internal | 3486 } } // namespace v8::internal |
3486 | 3487 |
3487 #endif // V8_AST_H_ | 3488 #endif // V8_AST_H_ |
OLD | NEW |