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

Side by Side Diff: src/ast.h

Issue 382893003: Implement basic code generation for arrow functions (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Test failures fixed, some minor corrections Created 6 years, 5 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 | « no previous file | src/compiler.cc » ('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 2282 matching lines...) Expand 10 before | Expand all | Expand 10 after
2293 enum IsFunctionFlag { 2293 enum IsFunctionFlag {
2294 kGlobalOrEval, 2294 kGlobalOrEval,
2295 kIsFunction 2295 kIsFunction
2296 }; 2296 };
2297 2297
2298 enum IsParenthesizedFlag { 2298 enum IsParenthesizedFlag {
2299 kIsParenthesized, 2299 kIsParenthesized,
2300 kNotParenthesized 2300 kNotParenthesized
2301 }; 2301 };
2302 2302
2303 enum IsGeneratorFlag { 2303 enum KindFlag {
2304 kIsGenerator, 2304 kNormalFunction,
2305 kNotGenerator 2305 kArrowFunction,
2306 kGeneratorFunction
2306 }; 2307 };
2307 2308
2308 enum ArityRestriction { 2309 enum ArityRestriction {
2309 NORMAL_ARITY, 2310 NORMAL_ARITY,
2310 GETTER_ARITY, 2311 GETTER_ARITY,
2311 SETTER_ARITY 2312 SETTER_ARITY
2312 }; 2313 };
2313 2314
2314 DECLARE_NODE_TYPE(FunctionLiteral) 2315 DECLARE_NODE_TYPE(FunctionLiteral)
2315 2316
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2387 // function will be called immediately: 2388 // function will be called immediately:
2388 // - (function() { ... })(); 2389 // - (function() { ... })();
2389 // - var x = function() { ... }(); 2390 // - var x = function() { ... }();
2390 bool is_parenthesized() { 2391 bool is_parenthesized() {
2391 return IsParenthesized::decode(bitfield_) == kIsParenthesized; 2392 return IsParenthesized::decode(bitfield_) == kIsParenthesized;
2392 } 2393 }
2393 void set_parenthesized() { 2394 void set_parenthesized() {
2394 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized); 2395 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized);
2395 } 2396 }
2396 2397
2397 bool is_generator() { 2398 bool is_generator() { return IsGenerator::decode(bitfield_); }
2398 return IsGenerator::decode(bitfield_) == kIsGenerator; 2399 bool is_arrow() { return IsArrow::decode(bitfield_); }
2399 }
2400 2400
2401 int ast_node_count() { return ast_properties_.node_count(); } 2401 int ast_node_count() { return ast_properties_.node_count(); }
2402 AstProperties::Flags* flags() { return ast_properties_.flags(); } 2402 AstProperties::Flags* flags() { return ast_properties_.flags(); }
2403 void set_ast_properties(AstProperties* ast_properties) { 2403 void set_ast_properties(AstProperties* ast_properties) {
2404 ast_properties_ = *ast_properties; 2404 ast_properties_ = *ast_properties;
2405 } 2405 }
2406 int slot_count() { 2406 int slot_count() {
2407 return ast_properties_.feedback_slots(); 2407 return ast_properties_.feedback_slots();
2408 } 2408 }
2409 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } 2409 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; }
2410 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } 2410 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; }
2411 void set_dont_optimize_reason(BailoutReason reason) { 2411 void set_dont_optimize_reason(BailoutReason reason) {
2412 dont_optimize_reason_ = reason; 2412 dont_optimize_reason_ = reason;
2413 } 2413 }
2414 2414
2415 protected: 2415 protected:
2416 FunctionLiteral(Zone* zone, 2416 FunctionLiteral(Zone* zone, const AstRawString* name,
2417 const AstRawString* name, 2417 AstValueFactory* ast_value_factory, Scope* scope,
2418 AstValueFactory* ast_value_factory, 2418 ZoneList<Statement*>* body, int materialized_literal_count,
2419 Scope* scope, 2419 int expected_property_count, int handler_count,
2420 ZoneList<Statement*>* body, 2420 int parameter_count, FunctionType function_type,
2421 int materialized_literal_count,
2422 int expected_property_count,
2423 int handler_count,
2424 int parameter_count,
2425 FunctionType function_type,
2426 ParameterFlag has_duplicate_parameters, 2421 ParameterFlag has_duplicate_parameters,
2427 IsFunctionFlag is_function, 2422 IsFunctionFlag is_function,
2428 IsParenthesizedFlag is_parenthesized, 2423 IsParenthesizedFlag is_parenthesized, KindFlag kind,
2429 IsGeneratorFlag is_generator,
2430 int position) 2424 int position)
2431 : Expression(zone, position), 2425 : Expression(zone, position),
2432 raw_name_(name), 2426 raw_name_(name),
2433 scope_(scope), 2427 scope_(scope),
2434 body_(body), 2428 body_(body),
2435 raw_inferred_name_(ast_value_factory->empty_string()), 2429 raw_inferred_name_(ast_value_factory->empty_string()),
2436 dont_optimize_reason_(kNoReason), 2430 dont_optimize_reason_(kNoReason),
2437 materialized_literal_count_(materialized_literal_count), 2431 materialized_literal_count_(materialized_literal_count),
2438 expected_property_count_(expected_property_count), 2432 expected_property_count_(expected_property_count),
2439 handler_count_(handler_count), 2433 handler_count_(handler_count),
2440 parameter_count_(parameter_count), 2434 parameter_count_(parameter_count),
2441 function_token_position_(RelocInfo::kNoPosition) { 2435 function_token_position_(RelocInfo::kNoPosition) {
2442 bitfield_ = 2436 bitfield_ = IsExpression::encode(function_type != DECLARATION) |
2443 IsExpression::encode(function_type != DECLARATION) | 2437 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) |
2444 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) | 2438 Pretenure::encode(false) |
2445 Pretenure::encode(false) | 2439 HasDuplicateParameters::encode(has_duplicate_parameters) |
2446 HasDuplicateParameters::encode(has_duplicate_parameters) | 2440 IsFunction::encode(is_function) |
2447 IsFunction::encode(is_function) | 2441 IsParenthesized::encode(is_parenthesized) |
2448 IsParenthesized::encode(is_parenthesized) | 2442 IsGenerator::encode(kind == kGeneratorFunction) |
2449 IsGenerator::encode(is_generator); 2443 IsArrow::encode(kind == kArrowFunction);
2450 } 2444 }
2451 2445
2452 private: 2446 private:
2453 const AstRawString* raw_name_; 2447 const AstRawString* raw_name_;
2454 Handle<String> name_; 2448 Handle<String> name_;
2455 Handle<SharedFunctionInfo> shared_info_; 2449 Handle<SharedFunctionInfo> shared_info_;
2456 Scope* scope_; 2450 Scope* scope_;
2457 ZoneList<Statement*>* body_; 2451 ZoneList<Statement*>* body_;
2458 const AstString* raw_inferred_name_; 2452 const AstString* raw_inferred_name_;
2459 Handle<String> inferred_name_; 2453 Handle<String> inferred_name_;
2460 AstProperties ast_properties_; 2454 AstProperties ast_properties_;
2461 BailoutReason dont_optimize_reason_; 2455 BailoutReason dont_optimize_reason_;
2462 2456
2463 int materialized_literal_count_; 2457 int materialized_literal_count_;
2464 int expected_property_count_; 2458 int expected_property_count_;
2465 int handler_count_; 2459 int handler_count_;
2466 int parameter_count_; 2460 int parameter_count_;
2467 int function_token_position_; 2461 int function_token_position_;
2468 2462
2469 unsigned bitfield_; 2463 unsigned bitfield_;
2470 class IsExpression: public BitField<bool, 0, 1> {}; 2464 class IsExpression: public BitField<bool, 0, 1> {};
2471 class IsAnonymous: public BitField<bool, 1, 1> {}; 2465 class IsAnonymous: public BitField<bool, 1, 1> {};
2472 class Pretenure: public BitField<bool, 2, 1> {}; 2466 class Pretenure: public BitField<bool, 2, 1> {};
2473 class HasDuplicateParameters: public BitField<ParameterFlag, 3, 1> {}; 2467 class HasDuplicateParameters: public BitField<ParameterFlag, 3, 1> {};
2474 class IsFunction: public BitField<IsFunctionFlag, 4, 1> {}; 2468 class IsFunction: public BitField<IsFunctionFlag, 4, 1> {};
2475 class IsParenthesized: public BitField<IsParenthesizedFlag, 5, 1> {}; 2469 class IsParenthesized: public BitField<IsParenthesizedFlag, 5, 1> {};
2476 class IsGenerator: public BitField<IsGeneratorFlag, 6, 1> {}; 2470 class IsGenerator : public BitField<bool, 6, 1> {};
2471 class IsArrow : public BitField<bool, 7, 1> {};
2477 }; 2472 };
2478 2473
2479 2474
2480 class NativeFunctionLiteral V8_FINAL : public Expression { 2475 class NativeFunctionLiteral V8_FINAL : public Expression {
2481 public: 2476 public:
2482 DECLARE_NODE_TYPE(NativeFunctionLiteral) 2477 DECLARE_NODE_TYPE(NativeFunctionLiteral)
2483 2478
2484 Handle<String> name() const { return name_->string(); } 2479 Handle<String> name() const { return name_->string(); }
2485 v8::Extension* extension() const { return extension_; } 2480 v8::Extension* extension() const { return extension_; }
2486 2481
(...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after
3381 zone_, generator_object, expression, yield_kind, pos); 3376 zone_, generator_object, expression, yield_kind, pos);
3382 VISIT_AND_RETURN(Yield, yield) 3377 VISIT_AND_RETURN(Yield, yield)
3383 } 3378 }
3384 3379
3385 Throw* NewThrow(Expression* exception, int pos) { 3380 Throw* NewThrow(Expression* exception, int pos) {
3386 Throw* t = new(zone_) Throw(zone_, exception, pos); 3381 Throw* t = new(zone_) Throw(zone_, exception, pos);
3387 VISIT_AND_RETURN(Throw, t) 3382 VISIT_AND_RETURN(Throw, t)
3388 } 3383 }
3389 3384
3390 FunctionLiteral* NewFunctionLiteral( 3385 FunctionLiteral* NewFunctionLiteral(
3391 const AstRawString* name, 3386 const AstRawString* name, AstValueFactory* ast_value_factory,
3392 AstValueFactory* ast_value_factory, 3387 Scope* scope, ZoneList<Statement*>* body, int materialized_literal_count,
3393 Scope* scope, 3388 int expected_property_count, int handler_count, int parameter_count,
3394 ZoneList<Statement*>* body,
3395 int materialized_literal_count,
3396 int expected_property_count,
3397 int handler_count,
3398 int parameter_count,
3399 FunctionLiteral::ParameterFlag has_duplicate_parameters, 3389 FunctionLiteral::ParameterFlag has_duplicate_parameters,
3400 FunctionLiteral::FunctionType function_type, 3390 FunctionLiteral::FunctionType function_type,
3401 FunctionLiteral::IsFunctionFlag is_function, 3391 FunctionLiteral::IsFunctionFlag is_function,
3402 FunctionLiteral::IsParenthesizedFlag is_parenthesized, 3392 FunctionLiteral::IsParenthesizedFlag is_parenthesized,
3403 FunctionLiteral::IsGeneratorFlag is_generator, 3393 FunctionLiteral::KindFlag kind, int position) {
3404 int position) { 3394 FunctionLiteral* lit = new (zone_) FunctionLiteral(
3405 FunctionLiteral* lit = new(zone_) FunctionLiteral( 3395 zone_, name, ast_value_factory, scope, body, materialized_literal_count,
3406 zone_, name, ast_value_factory, scope, body, 3396 expected_property_count, handler_count, parameter_count, function_type,
3407 materialized_literal_count, expected_property_count, handler_count, 3397 has_duplicate_parameters, is_function, is_parenthesized, kind,
3408 parameter_count, function_type, has_duplicate_parameters, is_function, 3398 position);
3409 is_parenthesized, is_generator, position);
3410 // Top-level literal doesn't count for the AST's properties. 3399 // Top-level literal doesn't count for the AST's properties.
3411 if (is_function == FunctionLiteral::kIsFunction) { 3400 if (is_function == FunctionLiteral::kIsFunction) {
3412 visitor_.VisitFunctionLiteral(lit); 3401 visitor_.VisitFunctionLiteral(lit);
3413 } 3402 }
3414 return lit; 3403 return lit;
3415 } 3404 }
3416 3405
3417 NativeFunctionLiteral* NewNativeFunctionLiteral( 3406 NativeFunctionLiteral* NewNativeFunctionLiteral(
3418 const AstRawString* name, v8::Extension* extension, 3407 const AstRawString* name, v8::Extension* extension,
3419 int pos) { 3408 int pos) {
(...skipping 12 matching lines...) Expand all
3432 private: 3421 private:
3433 Zone* zone_; 3422 Zone* zone_;
3434 Visitor visitor_; 3423 Visitor visitor_;
3435 AstValueFactory* ast_value_factory_; 3424 AstValueFactory* ast_value_factory_;
3436 }; 3425 };
3437 3426
3438 3427
3439 } } // namespace v8::internal 3428 } } // namespace v8::internal
3440 3429
3441 #endif // V8_AST_H_ 3430 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/compiler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698