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

Side by Side Diff: src/ast.h

Issue 160073006: Implement handling of arrow functions in the parser (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Extra parens in parameter lists now recognized, no longer segfaults on "()" Created 6 years, 7 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') | src/parser.h » ('J')
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 "v8.h" 8 #include "v8.h"
9 9
10 #include "assembler.h" 10 #include "assembler.h"
(...skipping 2269 matching lines...) Expand 10 before | Expand all | Expand 10 after
2280 enum IsFunctionFlag { 2280 enum IsFunctionFlag {
2281 kGlobalOrEval, 2281 kGlobalOrEval,
2282 kIsFunction 2282 kIsFunction
2283 }; 2283 };
2284 2284
2285 enum IsParenthesizedFlag { 2285 enum IsParenthesizedFlag {
2286 kIsParenthesized, 2286 kIsParenthesized,
2287 kNotParenthesized 2287 kNotParenthesized
2288 }; 2288 };
2289 2289
2290 enum IsGeneratorFlag { 2290 enum KindFlag {
2291 kIsGenerator, 2291 kNormalFunction,
2292 kNotGenerator 2292 kArrowFunction,
2293 kGeneratorFunction
2293 }; 2294 };
2294 2295
2295 DECLARE_NODE_TYPE(FunctionLiteral) 2296 DECLARE_NODE_TYPE(FunctionLiteral)
2296 2297
2297 Handle<String> name() const { return name_; } 2298 Handle<String> name() const { return name_; }
2298 Scope* scope() const { return scope_; } 2299 Scope* scope() const { return scope_; }
2299 ZoneList<Statement*>* body() const { return body_; } 2300 ZoneList<Statement*>* body() const { return body_; }
2300 void set_function_token_position(int pos) { function_token_position_ = pos; } 2301 void set_function_token_position(int pos) { function_token_position_ = pos; }
2301 int function_token_position() const { return function_token_position_; } 2302 int function_token_position() const { return function_token_position_; }
2302 int start_position() const; 2303 int start_position() const;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
2343 // function will be called immediately: 2344 // function will be called immediately:
2344 // - (function() { ... })(); 2345 // - (function() { ... })();
2345 // - var x = function() { ... }(); 2346 // - var x = function() { ... }();
2346 bool is_parenthesized() { 2347 bool is_parenthesized() {
2347 return IsParenthesized::decode(bitfield_) == kIsParenthesized; 2348 return IsParenthesized::decode(bitfield_) == kIsParenthesized;
2348 } 2349 }
2349 void set_parenthesized() { 2350 void set_parenthesized() {
2350 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized); 2351 bitfield_ = IsParenthesized::update(bitfield_, kIsParenthesized);
2351 } 2352 }
2352 2353
2353 bool is_generator() { 2354 bool is_generator() { return IsGenerator::decode(bitfield_); }
2354 return IsGenerator::decode(bitfield_) == kIsGenerator; 2355 bool is_arrow() { return IsArrow::decode(bitfield_); }
2355 }
2356 2356
2357 int ast_node_count() { return ast_properties_.node_count(); } 2357 int ast_node_count() { return ast_properties_.node_count(); }
2358 AstProperties::Flags* flags() { return ast_properties_.flags(); } 2358 AstProperties::Flags* flags() { return ast_properties_.flags(); }
2359 void set_ast_properties(AstProperties* ast_properties) { 2359 void set_ast_properties(AstProperties* ast_properties) {
2360 ast_properties_ = *ast_properties; 2360 ast_properties_ = *ast_properties;
2361 } 2361 }
2362 int slot_count() { 2362 int slot_count() {
2363 return ast_properties_.feedback_slots(); 2363 return ast_properties_.feedback_slots();
2364 } 2364 }
2365 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; } 2365 bool dont_optimize() { return dont_optimize_reason_ != kNoReason; }
2366 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; } 2366 BailoutReason dont_optimize_reason() { return dont_optimize_reason_; }
2367 void set_dont_optimize_reason(BailoutReason reason) { 2367 void set_dont_optimize_reason(BailoutReason reason) {
2368 dont_optimize_reason_ = reason; 2368 dont_optimize_reason_ = reason;
2369 } 2369 }
2370 2370
2371 protected: 2371 protected:
2372 FunctionLiteral(Zone* zone, 2372 FunctionLiteral(Zone* zone,
2373 Handle<String> name, 2373 Handle<String> name,
2374 Scope* scope, 2374 Scope* scope,
2375 ZoneList<Statement*>* body, 2375 ZoneList<Statement*>* body,
2376 int materialized_literal_count, 2376 int materialized_literal_count,
2377 int expected_property_count, 2377 int expected_property_count,
2378 int handler_count, 2378 int handler_count,
2379 int parameter_count, 2379 int parameter_count,
2380 FunctionType function_type, 2380 FunctionType function_type,
2381 ParameterFlag has_duplicate_parameters, 2381 ParameterFlag has_duplicate_parameters,
2382 IsFunctionFlag is_function, 2382 IsFunctionFlag is_function,
2383 IsParenthesizedFlag is_parenthesized, 2383 IsParenthesizedFlag is_parenthesized,
2384 IsGeneratorFlag is_generator, 2384 KindFlag kind,
2385 int position) 2385 int position)
2386 : Expression(zone, position), 2386 : Expression(zone, position),
2387 name_(name), 2387 name_(name),
2388 scope_(scope), 2388 scope_(scope),
2389 body_(body), 2389 body_(body),
2390 inferred_name_(zone->isolate()->factory()->empty_string()), 2390 inferred_name_(zone->isolate()->factory()->empty_string()),
2391 dont_optimize_reason_(kNoReason), 2391 dont_optimize_reason_(kNoReason),
2392 materialized_literal_count_(materialized_literal_count), 2392 materialized_literal_count_(materialized_literal_count),
2393 expected_property_count_(expected_property_count), 2393 expected_property_count_(expected_property_count),
2394 handler_count_(handler_count), 2394 handler_count_(handler_count),
2395 parameter_count_(parameter_count), 2395 parameter_count_(parameter_count),
2396 function_token_position_(RelocInfo::kNoPosition) { 2396 function_token_position_(RelocInfo::kNoPosition) {
2397 bitfield_ = 2397 bitfield_ =
2398 IsExpression::encode(function_type != DECLARATION) | 2398 IsExpression::encode(function_type != DECLARATION) |
2399 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) | 2399 IsAnonymous::encode(function_type == ANONYMOUS_EXPRESSION) |
2400 Pretenure::encode(false) | 2400 Pretenure::encode(false) |
2401 HasDuplicateParameters::encode(has_duplicate_parameters) | 2401 HasDuplicateParameters::encode(has_duplicate_parameters) |
2402 IsFunction::encode(is_function) | 2402 IsFunction::encode(is_function) |
2403 IsParenthesized::encode(is_parenthesized) | 2403 IsParenthesized::encode(is_parenthesized) |
2404 IsGenerator::encode(is_generator); 2404 IsGenerator::encode(kind == kGeneratorFunction) |
2405 IsArrow::encode(kind == kArrowFunction);
2405 } 2406 }
2406 2407
2407 private: 2408 private:
2408 Handle<String> name_; 2409 Handle<String> name_;
2409 Handle<SharedFunctionInfo> shared_info_; 2410 Handle<SharedFunctionInfo> shared_info_;
2410 Scope* scope_; 2411 Scope* scope_;
2411 ZoneList<Statement*>* body_; 2412 ZoneList<Statement*>* body_;
2412 Handle<String> inferred_name_; 2413 Handle<String> inferred_name_;
2413 AstProperties ast_properties_; 2414 AstProperties ast_properties_;
2414 BailoutReason dont_optimize_reason_; 2415 BailoutReason dont_optimize_reason_;
2415 2416
2416 int materialized_literal_count_; 2417 int materialized_literal_count_;
2417 int expected_property_count_; 2418 int expected_property_count_;
2418 int handler_count_; 2419 int handler_count_;
2419 int parameter_count_; 2420 int parameter_count_;
2420 int function_token_position_; 2421 int function_token_position_;
2421 2422
2422 unsigned bitfield_; 2423 unsigned bitfield_;
2423 class IsExpression: public BitField<bool, 0, 1> {}; 2424 class IsExpression: public BitField<bool, 0, 1> {};
2424 class IsAnonymous: public BitField<bool, 1, 1> {}; 2425 class IsAnonymous: public BitField<bool, 1, 1> {};
2425 class Pretenure: public BitField<bool, 2, 1> {}; 2426 class Pretenure: public BitField<bool, 2, 1> {};
2426 class HasDuplicateParameters: public BitField<ParameterFlag, 3, 1> {}; 2427 class HasDuplicateParameters: public BitField<ParameterFlag, 3, 1> {};
2427 class IsFunction: public BitField<IsFunctionFlag, 4, 1> {}; 2428 class IsFunction: public BitField<IsFunctionFlag, 4, 1> {};
2428 class IsParenthesized: public BitField<IsParenthesizedFlag, 5, 1> {}; 2429 class IsParenthesized: public BitField<IsParenthesizedFlag, 5, 1> {};
2429 class IsGenerator: public BitField<IsGeneratorFlag, 6, 1> {}; 2430 class IsGenerator: public BitField<bool, 6, 1> {};
2431 class IsArrow: public BitField<bool, 7, 1> {};
2430 }; 2432 };
2431 2433
2432 2434
2433 class NativeFunctionLiteral V8_FINAL : public Expression { 2435 class NativeFunctionLiteral V8_FINAL : public Expression {
2434 public: 2436 public:
2435 DECLARE_NODE_TYPE(NativeFunctionLiteral) 2437 DECLARE_NODE_TYPE(NativeFunctionLiteral)
2436 2438
2437 Handle<String> name() const { return name_; } 2439 Handle<String> name() const { return name_; }
2438 v8::Extension* extension() const { return extension_; } 2440 v8::Extension* extension() const { return extension_; }
2439 2441
(...skipping 856 matching lines...) Expand 10 before | Expand all | Expand 10 after
3296 Scope* scope, 3298 Scope* scope,
3297 ZoneList<Statement*>* body, 3299 ZoneList<Statement*>* body,
3298 int materialized_literal_count, 3300 int materialized_literal_count,
3299 int expected_property_count, 3301 int expected_property_count,
3300 int handler_count, 3302 int handler_count,
3301 int parameter_count, 3303 int parameter_count,
3302 FunctionLiteral::ParameterFlag has_duplicate_parameters, 3304 FunctionLiteral::ParameterFlag has_duplicate_parameters,
3303 FunctionLiteral::FunctionType function_type, 3305 FunctionLiteral::FunctionType function_type,
3304 FunctionLiteral::IsFunctionFlag is_function, 3306 FunctionLiteral::IsFunctionFlag is_function,
3305 FunctionLiteral::IsParenthesizedFlag is_parenthesized, 3307 FunctionLiteral::IsParenthesizedFlag is_parenthesized,
3306 FunctionLiteral::IsGeneratorFlag is_generator, 3308 FunctionLiteral::KindFlag kind,
3307 int position) { 3309 int position) {
3308 FunctionLiteral* lit = new(zone_) FunctionLiteral( 3310 FunctionLiteral* lit = new(zone_) FunctionLiteral(
3309 zone_, name, scope, body, 3311 zone_, name, scope, body,
3310 materialized_literal_count, expected_property_count, handler_count, 3312 materialized_literal_count, expected_property_count, handler_count,
3311 parameter_count, function_type, has_duplicate_parameters, is_function, 3313 parameter_count, function_type, has_duplicate_parameters, is_function,
3312 is_parenthesized, is_generator, position); 3314 is_parenthesized, kind, position);
3313 // Top-level literal doesn't count for the AST's properties. 3315 // Top-level literal doesn't count for the AST's properties.
3314 if (is_function == FunctionLiteral::kIsFunction) { 3316 if (is_function == FunctionLiteral::kIsFunction) {
3315 visitor_.VisitFunctionLiteral(lit); 3317 visitor_.VisitFunctionLiteral(lit);
3316 } 3318 }
3317 return lit; 3319 return lit;
3318 } 3320 }
3319 3321
3320 NativeFunctionLiteral* NewNativeFunctionLiteral( 3322 NativeFunctionLiteral* NewNativeFunctionLiteral(
3321 Handle<String> name, v8::Extension* extension, int pos) { 3323 Handle<String> name, v8::Extension* extension, int pos) {
3322 NativeFunctionLiteral* lit = 3324 NativeFunctionLiteral* lit =
(...skipping 10 matching lines...) Expand all
3333 3335
3334 private: 3336 private:
3335 Zone* zone_; 3337 Zone* zone_;
3336 Visitor visitor_; 3338 Visitor visitor_;
3337 }; 3339 };
3338 3340
3339 3341
3340 } } // namespace v8::internal 3342 } } // namespace v8::internal
3341 3343
3342 #endif // V8_AST_H_ 3344 #endif // V8_AST_H_
OLDNEW
« no previous file with comments | « no previous file | src/compiler.cc » ('j') | src/parser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698