Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: src/ast.h

Issue 477263002: ES6: Add support for method shorthand in object literals (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/arm64/lithium-codegen-arm64.cc ('k') | src/code-stubs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 bool is_generator() { return IsGenerator::decode(bitfield_); }
2424 bool is_arrow() { return IsArrow::decode(bitfield_); } 2418 bool is_arrow() { return IsArrow::decode(bitfield_); }
2419 bool is_concise_method() { return IsConciseMethod::decode(bitfield_); }
2420 FunctionKind kind() {
2421 // TODO(arv): Update to handle concise generator methods.
2422 if (is_arrow()) return FunctionKind::kArrowFunction;
arv (Not doing code reviews) 2014/08/22 23:16:03 These are currently stored as a bitfield_. I could
2423 if (is_generator()) return FunctionKind::kGeneratorFunction;
2424 if (is_concise_method()) return FunctionKind::kConciseMethod;
2425 return FunctionKind::kNormalFunction;
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 IsGenerator::encode(kind == kGeneratorFunction) |
2468 IsArrow::encode(kind == kArrowFunction); 2470 IsArrow::encode(kind == kArrowFunction) |
2471 IsConciseMethod::encode(kind == kConciseMethod);
2472 DCHECK(!(is_arrow() && is_concise_method()));
2473 DCHECK(!(is_arrow() && is_generator()));
2469 } 2474 }
2470 2475
2471 private: 2476 private:
2472 const AstRawString* raw_name_; 2477 const AstRawString* raw_name_;
2473 Handle<String> name_; 2478 Handle<String> name_;
2474 Handle<SharedFunctionInfo> shared_info_; 2479 Handle<SharedFunctionInfo> shared_info_;
2475 Scope* scope_; 2480 Scope* scope_;
2476 ZoneList<Statement*>* body_; 2481 ZoneList<Statement*>* body_;
2477 const AstString* raw_inferred_name_; 2482 const AstString* raw_inferred_name_;
2478 Handle<String> inferred_name_; 2483 Handle<String> inferred_name_;
2479 AstProperties ast_properties_; 2484 AstProperties ast_properties_;
2480 BailoutReason dont_optimize_reason_; 2485 BailoutReason dont_optimize_reason_;
2481 2486
2482 int materialized_literal_count_; 2487 int materialized_literal_count_;
2483 int expected_property_count_; 2488 int expected_property_count_;
2484 int handler_count_; 2489 int handler_count_;
2485 int parameter_count_; 2490 int parameter_count_;
2486 int function_token_position_; 2491 int function_token_position_;
2487 2492
2488 unsigned bitfield_; 2493 unsigned bitfield_;
2489 class IsExpression: public BitField<bool, 0, 1> {}; 2494 class IsExpression: public BitField<bool, 0, 1> {};
2490 class IsAnonymous: public BitField<bool, 1, 1> {}; 2495 class IsAnonymous: public BitField<bool, 1, 1> {};
2491 class Pretenure: public BitField<bool, 2, 1> {}; 2496 class Pretenure: public BitField<bool, 2, 1> {};
2492 class HasDuplicateParameters: public BitField<ParameterFlag, 3, 1> {}; 2497 class HasDuplicateParameters: public BitField<ParameterFlag, 3, 1> {};
2493 class IsFunction: public BitField<IsFunctionFlag, 4, 1> {}; 2498 class IsFunction: public BitField<IsFunctionFlag, 4, 1> {};
2494 class IsParenthesized: public BitField<IsParenthesizedFlag, 5, 1> {}; 2499 class IsParenthesized: public BitField<IsParenthesizedFlag, 5, 1> {};
2495 class IsGenerator : public BitField<bool, 6, 1> {}; 2500 class IsGenerator : public BitField<bool, 6, 1> {};
2496 class IsArrow : public BitField<bool, 7, 1> {}; 2501 class IsArrow : public BitField<bool, 7, 1> {};
2502 class IsConciseMethod : public BitField<bool, 8, 1> {};
2497 }; 2503 };
2498 2504
2499 2505
2500 class NativeFunctionLiteral V8_FINAL : public Expression { 2506 class NativeFunctionLiteral V8_FINAL : public Expression {
2501 public: 2507 public:
2502 DECLARE_NODE_TYPE(NativeFunctionLiteral) 2508 DECLARE_NODE_TYPE(NativeFunctionLiteral)
2503 2509
2504 Handle<String> name() const { return name_->string(); } 2510 Handle<String> name() const { return name_->string(); }
2505 v8::Extension* extension() const { return extension_; } 2511 v8::Extension* extension() const { return extension_; }
2506 2512
(...skipping 925 matching lines...) Expand 10 before | Expand all | Expand 10 after
3432 VISIT_AND_RETURN(Throw, t) 3438 VISIT_AND_RETURN(Throw, t)
3433 } 3439 }
3434 3440
3435 FunctionLiteral* NewFunctionLiteral( 3441 FunctionLiteral* NewFunctionLiteral(
3436 const AstRawString* name, AstValueFactory* ast_value_factory, 3442 const AstRawString* name, AstValueFactory* ast_value_factory,
3437 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count, 3443 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count,
3438 int expected_property_count, int handler_count, int parameter_count, 3444 int expected_property_count, int handler_count, int parameter_count,
3439 FunctionLiteral::ParameterFlag has_duplicate_parameters, 3445 FunctionLiteral::ParameterFlag has_duplicate_parameters,
3440 FunctionLiteral::FunctionType function_type, 3446 FunctionLiteral::FunctionType function_type,
3441 FunctionLiteral::IsFunctionFlag is_function, 3447 FunctionLiteral::IsFunctionFlag is_function,
3442 FunctionLiteral::IsParenthesizedFlag is_parenthesized, 3448 FunctionLiteral::IsParenthesizedFlag is_parenthesized, FunctionKind kind,
3443 FunctionLiteral::KindFlag kind, int position) { 3449 int position) {
3444 FunctionLiteral* lit = new (zone_) FunctionLiteral( 3450 FunctionLiteral* lit = new (zone_) FunctionLiteral(
3445 zone_, name, ast_value_factory, scope, body, materialized_literal_count, 3451 zone_, name, ast_value_factory, scope, body, materialized_literal_count,
3446 expected_property_count, handler_count, parameter_count, function_type, 3452 expected_property_count, handler_count, parameter_count, function_type,
3447 has_duplicate_parameters, is_function, is_parenthesized, kind, position, 3453 has_duplicate_parameters, is_function, is_parenthesized, kind, position,
3448 id_gen_); 3454 id_gen_);
3449 // Top-level literal doesn't count for the AST's properties. 3455 // Top-level literal doesn't count for the AST's properties.
3450 if (is_function == FunctionLiteral::kIsFunction) { 3456 if (is_function == FunctionLiteral::kIsFunction) {
3451 visitor_.VisitFunctionLiteral(lit); 3457 visitor_.VisitFunctionLiteral(lit);
3452 } 3458 }
3453 return lit; 3459 return lit;
(...skipping 24 matching lines...) Expand all
3478 Zone* zone_; 3484 Zone* zone_;
3479 Visitor visitor_; 3485 Visitor visitor_;
3480 AstValueFactory* ast_value_factory_; 3486 AstValueFactory* ast_value_factory_;
3481 AstNode::IdGen* id_gen_; 3487 AstNode::IdGen* id_gen_;
3482 }; 3488 };
3483 3489
3484 3490
3485 } } // namespace v8::internal 3491 } } // namespace v8::internal
3486 3492
3487 #endif // V8_AST_H_ 3493 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « src/arm64/lithium-codegen-arm64.cc ('k') | src/code-stubs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698