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 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
174 | 174 |
175 private: | 175 private: |
176 Flags flags_; | 176 Flags flags_; |
177 int node_count_; | 177 int node_count_; |
178 int feedback_slots_; | 178 int feedback_slots_; |
179 }; | 179 }; |
180 | 180 |
181 | 181 |
182 class AstNode: public ZoneObject { | 182 class AstNode: public ZoneObject { |
183 public: | 183 public: |
184 // For generating IDs for AstNodes. | 184 // For generating IDs for AstNodes. |
rossberg
2014/08/25 09:39:29
Please try to avoid rebasing while review is in pr
| |
185 class IdGen { | 185 class IdGen { |
186 public: | 186 public: |
187 explicit IdGen(int id = 0) : id_(id) {} | 187 explicit IdGen(int id = 0) : id_(id) {} |
188 | 188 |
189 int GetNextId() { return ReserveIdRange(1); } | 189 int GetNextId() { return ReserveIdRange(1); } |
190 int ReserveIdRange(int n) { | 190 int ReserveIdRange(int n) { |
191 int tmp = id_; | 191 int tmp = id_; |
192 id_ += n; | 192 id_ += n; |
193 return tmp; | 193 return tmp; |
194 } | 194 } |
(...skipping 2123 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 |
2417 FunctionKind kind() { return FunctionKindBits::decode(bitfield_); } | |
2418 bool is_arrow() { return IsArrow::decode(bitfield_); } | |
2423 bool is_generator() { return IsGenerator::decode(bitfield_); } | 2419 bool is_generator() { return IsGenerator::decode(bitfield_); } |
2424 bool is_arrow() { return IsArrow::decode(bitfield_); } | 2420 bool is_concise_method() { return IsConciseMethod::decode(bitfield_); } |
2425 | 2421 |
2426 int ast_node_count() { return ast_properties_.node_count(); } | 2422 int ast_node_count() { return ast_properties_.node_count(); } |
2427 AstProperties::Flags* flags() { return ast_properties_.flags(); } | 2423 AstProperties::Flags* flags() { return ast_properties_.flags(); } |
2428 void set_ast_properties(AstProperties* ast_properties) { | 2424 void set_ast_properties(AstProperties* ast_properties) { |
2429 ast_properties_ = *ast_properties; | 2425 ast_properties_ = *ast_properties; |
2430 } | 2426 } |
2431 int slot_count() { | 2427 int slot_count() { |
2432 return ast_properties_.feedback_slots(); | 2428 return ast_properties_.feedback_slots(); |
2433 } | 2429 } |
2434 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } | 2430 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } |
2435 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } | 2431 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } |
2436 void set_dont_optimize_reason(BailoutReason reason) { | 2432 void set_dont_optimize_reason(BailoutReason reason) { |
2437 dont_optimize_reason_ = reason; | 2433 dont_optimize_reason_ = reason; |
2438 } | 2434 } |
2439 | 2435 |
2440 protected: | 2436 protected: |
2441 FunctionLiteral(Zone* zone, const AstRawString* name, | 2437 FunctionLiteral(Zone* zone, const AstRawString* name, |
2442 AstValueFactory* ast_value_factory, Scope* scope, | 2438 AstValueFactory* ast_value_factory, Scope* scope, |
2443 ZoneList<Statement*>* body, int materialized_literal_count, | 2439 ZoneList<Statement*>* body, int materialized_literal_count, |
2444 int expected_property_count, int handler_count, | 2440 int expected_property_count, int handler_count, |
2445 int parameter_count, FunctionType function_type, | 2441 int parameter_count, FunctionType function_type, |
2446 ParameterFlag has_duplicate_parameters, | 2442 ParameterFlag has_duplicate_parameters, |
2447 IsFunctionFlag is_function, | 2443 IsFunctionFlag is_function, |
2448 IsParenthesizedFlag is_parenthesized, KindFlag kind, | 2444 IsParenthesizedFlag is_parenthesized, FunctionKind kind, |
2449 int position, IdGen* id_gen) | 2445 int position, IdGen* id_gen) |
2450 : Expression(zone, position, id_gen), | 2446 : Expression(zone, position, id_gen), |
2451 raw_name_(name), | 2447 raw_name_(name), |
2452 scope_(scope), | 2448 scope_(scope), |
2453 body_(body), | 2449 body_(body), |
2454 raw_inferred_name_(ast_value_factory->empty_string()), | 2450 raw_inferred_name_(ast_value_factory->empty_string()), |
2455 dont_optimize_reason_(kNoReason), | 2451 dont_optimize_reason_(kNoReason), |
2456 materialized_literal_count_(materialized_literal_count), | 2452 materialized_literal_count_(materialized_literal_count), |
2457 expected_property_count_(expected_property_count), | 2453 expected_property_count_(expected_property_count), |
2458 handler_count_(handler_count), | 2454 handler_count_(handler_count), |
2459 parameter_count_(parameter_count), | 2455 parameter_count_(parameter_count), |
2460 function_token_position_(RelocInfo::kNoPosition) { | 2456 function_token_position_(RelocInfo::kNoPosition) { |
2461 bitfield_ = IsExpression::encode(function_type != DECLARATION) | | 2457 bitfield_ = IsExpression::encode(function_type != DECLARATION) | |
2462 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) | | 2458 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) | |
2463 Pretenure::encode(false) | | 2459 Pretenure::encode(false) | |
2464 HasDuplicateParameters::encode(has_duplicate_parameters) | | 2460 HasDuplicateParameters::encode(has_duplicate_parameters) | |
2465 IsFunction::encode(is_function) | | 2461 IsFunction::encode(is_function) | |
2466 IsParenthesized::encode(is_parenthesized) | | 2462 IsParenthesized::encode(is_parenthesized) | |
2467 IsGenerator::encode(kind == kGeneratorFunction) | | 2463 FunctionKindBits::encode(kind); |
2468 IsArrow::encode(kind == kArrowFunction); | 2464 DCHECK(!(is_arrow() && is_concise_method())); |
rossberg
2014/08/25 09:39:29
Perhaps factor these conditions into a function Is
arv (Not doing code reviews)
2014/09/09 22:24:26
Done.
| |
2465 DCHECK(!(is_arrow() && is_generator())); | |
2469 } | 2466 } |
2470 | 2467 |
2471 private: | 2468 private: |
2472 const AstRawString* raw_name_; | 2469 const AstRawString* raw_name_; |
2473 Handle<String> name_; | 2470 Handle<String> name_; |
2474 Handle<SharedFunctionInfo> shared_info_; | 2471 Handle<SharedFunctionInfo> shared_info_; |
2475 Scope* scope_; | 2472 Scope* scope_; |
2476 ZoneList<Statement*>* body_; | 2473 ZoneList<Statement*>* body_; |
2477 const AstString* raw_inferred_name_; | 2474 const AstString* raw_inferred_name_; |
2478 Handle<String> inferred_name_; | 2475 Handle<String> inferred_name_; |
2479 AstProperties ast_properties_; | 2476 AstProperties ast_properties_; |
2480 BailoutReason dont_optimize_reason_; | 2477 BailoutReason dont_optimize_reason_; |
2481 | 2478 |
2482 int materialized_literal_count_; | 2479 int materialized_literal_count_; |
2483 int expected_property_count_; | 2480 int expected_property_count_; |
2484 int handler_count_; | 2481 int handler_count_; |
2485 int parameter_count_; | 2482 int parameter_count_; |
2486 int function_token_position_; | 2483 int function_token_position_; |
2487 | 2484 |
2488 unsigned bitfield_; | 2485 unsigned bitfield_; |
2489 class IsExpression: public BitField<bool, 0, 1> {}; | 2486 class IsExpression : public BitField<bool, 0, 1> {}; |
2490 class IsAnonymous: public BitField<bool, 1, 1> {}; | 2487 class IsAnonymous : public BitField<bool, 1, 1> {}; |
2491 class Pretenure: public BitField<bool, 2, 1> {}; | 2488 class Pretenure : public BitField<bool, 2, 1> {}; |
2492 class HasDuplicateParameters: public BitField<ParameterFlag, 3, 1> {}; | 2489 class HasDuplicateParameters : public BitField<ParameterFlag, 3, 1> {}; |
2493 class IsFunction: public BitField<IsFunctionFlag, 4, 1> {}; | 2490 class IsFunction : public BitField<IsFunctionFlag, 4, 1> {}; |
2494 class IsParenthesized: public BitField<IsParenthesizedFlag, 5, 1> {}; | 2491 class IsParenthesized : public BitField<IsParenthesizedFlag, 5, 1> {}; |
2495 class IsGenerator : public BitField<bool, 6, 1> {}; | 2492 class FunctionKindBits : public BitField<FunctionKind, 6, 3> {}; |
2496 class IsArrow : public BitField<bool, 7, 1> {}; | 2493 class IsArrow : public BitField<bool, 6, 1> {}; |
rossberg
2014/08/25 09:39:29
Please don't define overlapping bitfields. In part
arv (Not doing code reviews)
2014/09/02 14:42:48
Yes, it does have a tight coupling but it leads to
rossberg
2014/09/08 14:08:59
Yes. Just add some global helpers IsArrowKind, IsG
arv (Not doing code reviews)
2014/09/09 22:24:27
Done.
| |
2494 class IsGenerator : public BitField<bool, 7, 1> {}; | |
2495 class IsConciseMethod : public BitField<bool, 8, 1> {}; | |
2497 }; | 2496 }; |
2498 | 2497 |
2499 | 2498 |
2500 class NativeFunctionLiteral V8_FINAL : public Expression { | 2499 class NativeFunctionLiteral V8_FINAL : public Expression { |
2501 public: | 2500 public: |
2502 DECLARE_NODE_TYPE(NativeFunctionLiteral) | 2501 DECLARE_NODE_TYPE(NativeFunctionLiteral) |
2503 | 2502 |
2504 Handle<String> name() const { return name_->string(); } | 2503 Handle<String> name() const { return name_->string(); } |
2505 v8::Extension* extension() const { return extension_; } | 2504 v8::Extension* extension() const { return extension_; } |
2506 | 2505 |
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3432 VISIT_AND_RETURN(Throw, t) | 3431 VISIT_AND_RETURN(Throw, t) |
3433 } | 3432 } |
3434 | 3433 |
3435 FunctionLiteral* NewFunctionLiteral( | 3434 FunctionLiteral* NewFunctionLiteral( |
3436 const AstRawString* name, AstValueFactory* ast_value_factory, | 3435 const AstRawString* name, AstValueFactory* ast_value_factory, |
3437 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count, | 3436 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count, |
3438 int expected_property_count, int handler_count, int parameter_count, | 3437 int expected_property_count, int handler_count, int parameter_count, |
3439 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 3438 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
3440 FunctionLiteral::FunctionType function_type, | 3439 FunctionLiteral::FunctionType function_type, |
3441 FunctionLiteral::IsFunctionFlag is_function, | 3440 FunctionLiteral::IsFunctionFlag is_function, |
3442 FunctionLiteral::IsParenthesizedFlag is_parenthesized, | 3441 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind, |
3443 FunctionLiteral::KindFlag kind, int position) { | 3442 int position) { |
3444 FunctionLiteral* lit = new (zone_) FunctionLiteral( | 3443 FunctionLiteral* lit = new (zone_) FunctionLiteral( |
3445 zone_, name, ast_value_factory, scope, body, materialized_literal_count, | 3444 zone_, name, ast_value_factory, scope, body, materialized_literal_count, |
3446 expected_property_count, handler_count, parameter_count, function_type, | 3445 expected_property_count, handler_count, parameter_count, function_type, |
3447 has_duplicate_parameters, is_function, is_parenthesized, kind, position, | 3446 has_duplicate_parameters, is_function, is_parenthesized, kind, position, |
3448 id_gen_); | 3447 id_gen_); |
3449 // Top-level literal doesn't count for the AST's properties. | 3448 // Top-level literal doesn't count for the AST's properties. |
3450 if (is_function == FunctionLiteral::kIsFunction) { | 3449 if (is_function == FunctionLiteral::kIsFunction) { |
3451 visitor_.VisitFunctionLiteral(lit); | 3450 visitor_.VisitFunctionLiteral(lit); |
3452 } | 3451 } |
3453 return lit; | 3452 return lit; |
(...skipping 24 matching lines...) Expand all Loading... | |
3478 Zone* zone_; | 3477 Zone* zone_; |
3479 Visitor visitor_; | 3478 Visitor visitor_; |
3480 AstValueFactory* ast_value_factory_; | 3479 AstValueFactory* ast_value_factory_; |
3481 AstNode::IdGen* id_gen_; | 3480 AstNode::IdGen* id_gen_; |
3482 }; | 3481 }; |
3483 | 3482 |
3484 | 3483 |
3485 } } // namespace v8::internal | 3484 } } // namespace v8::internal |
3486 | 3485 |
3487 #endif // V8_AST_H_ | 3486 #endif // V8_AST_H_ |
OLD | NEW |