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

Side by Side Diff: src/parser.h

Issue 160073006: Implement handling of arrow functions in the parser (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Removed ParamListFinder Created 6 years, 6 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
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_PARSER_H_ 5 #ifndef V8_PARSER_H_
6 #define V8_PARSER_H_ 6 #define V8_PARSER_H_
7 7
8 #include "src/allocation.h" 8 #include "src/allocation.h"
9 #include "src/ast.h" 9 #include "src/ast.h"
10 #include "src/compiler.h" // For CachedDataMode 10 #include "src/compiler.h" // For CachedDataMode
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 378
379 class ParserTraits { 379 class ParserTraits {
380 public: 380 public:
381 struct Type { 381 struct Type {
382 // TODO(marja): To be removed. The Traits object should contain all the data 382 // TODO(marja): To be removed. The Traits object should contain all the data
383 // it needs. 383 // it needs.
384 typedef v8::internal::Parser* Parser; 384 typedef v8::internal::Parser* Parser;
385 385
386 // Used by FunctionState and BlockState. 386 // Used by FunctionState and BlockState.
387 typedef v8::internal::Scope Scope; 387 typedef v8::internal::Scope Scope;
388 typedef v8::internal::Scope* ScopePtr;
388 typedef Variable GeneratorVariable; 389 typedef Variable GeneratorVariable;
389 typedef v8::internal::Zone Zone; 390 typedef v8::internal::Zone Zone;
390 391
392 typedef v8::internal::AstProperties AstProperties;
393 typedef Vector<VariableProxy*> ParameterIdentifierVector;
394
391 // Return types for traversing functions. 395 // Return types for traversing functions.
392 typedef const AstRawString* Identifier; 396 typedef const AstRawString* Identifier;
393 typedef v8::internal::Expression* Expression; 397 typedef v8::internal::Expression* Expression;
394 typedef Yield* YieldExpression; 398 typedef Yield* YieldExpression;
395 typedef v8::internal::FunctionLiteral* FunctionLiteral; 399 typedef v8::internal::FunctionLiteral* FunctionLiteral;
396 typedef v8::internal::Literal* Literal; 400 typedef v8::internal::Literal* Literal;
397 typedef ObjectLiteral::Property* ObjectLiteralProperty; 401 typedef ObjectLiteral::Property* ObjectLiteralProperty;
398 typedef ZoneList<v8::internal::Expression*>* ExpressionList; 402 typedef ZoneList<v8::internal::Expression*>* ExpressionList;
399 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; 403 typedef ZoneList<ObjectLiteral::Property*>* PropertyList;
400 typedef ZoneList<v8::internal::Statement*>* StatementList; 404 typedef ZoneList<v8::internal::Statement*>* StatementList;
(...skipping 14 matching lines...) Expand all
415 419
416 template<typename FunctionState> 420 template<typename FunctionState>
417 static void TearDownFunctionState(FunctionState* function_state, Zone* zone) { 421 static void TearDownFunctionState(FunctionState* function_state, Zone* zone) {
418 if (function_state->outer_function_state_ != NULL) { 422 if (function_state->outer_function_state_ != NULL) {
419 zone->isolate()->set_ast_node_id(function_state->saved_ast_node_id_); 423 zone->isolate()->set_ast_node_id(function_state->saved_ast_node_id_);
420 } 424 }
421 } 425 }
422 426
423 // Helper functions for recursive descent. 427 // Helper functions for recursive descent.
424 bool IsEvalOrArguments(const AstRawString* identifier) const; 428 bool IsEvalOrArguments(const AstRawString* identifier) const;
429 V8_INLINE bool IsFutureStrictReserved(const AstRawString* identifier) const;
425 430
426 // Returns true if the expression is of type "this.foo". 431 // Returns true if the expression is of type "this.foo".
427 static bool IsThisProperty(Expression* expression); 432 static bool IsThisProperty(Expression* expression);
428 433
429 static bool IsIdentifier(Expression* expression); 434 static bool IsIdentifier(Expression* expression);
430 435
431 static const AstRawString* AsIdentifier(Expression* expression) { 436 static const AstRawString* AsIdentifier(Expression* expression) {
432 ASSERT(IsIdentifier(expression)); 437 ASSERT(IsIdentifier(expression));
433 return expression->AsVariableProxy()->raw_name(); 438 return expression->AsVariableProxy()->raw_name();
434 } 439 }
435 440
436 static bool IsBoilerplateProperty(ObjectLiteral::Property* property) { 441 static bool IsBoilerplateProperty(ObjectLiteral::Property* property) {
437 return ObjectLiteral::IsBoilerplateProperty(property); 442 return ObjectLiteral::IsBoilerplateProperty(property);
438 } 443 }
439 444
440 static bool IsArrayIndex(const AstRawString* string, uint32_t* index) { 445 static bool IsArrayIndex(const AstRawString* string, uint32_t* index) {
441 return string->AsArrayIndex(index); 446 return string->AsArrayIndex(index);
442 } 447 }
443 448
444 // Functions for encapsulating the differences between parsing and preparsing; 449 // Functions for encapsulating the differences between parsing and preparsing;
445 // operations interleaved with the recursive descent. 450 // operations interleaved with the recursive descent.
446 static void PushLiteralName(FuncNameInferrer* fni, const AstRawString* id) { 451 static void PushLiteralName(FuncNameInferrer* fni, const AstRawString* id) {
447 fni->PushLiteralName(id); 452 fni->PushLiteralName(id);
448 } 453 }
449 void PushPropertyName(FuncNameInferrer* fni, Expression* expression); 454 void PushPropertyName(FuncNameInferrer* fni, Expression* expression);
455 static void InferFunctionName(FuncNameInferrer* fni,
456 FunctionLiteral* func_to_infer) {
457 fni->AddFunction(func_to_infer);
458 }
450 459
451 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( 460 static void CheckFunctionLiteralInsideTopLevelObjectLiteral(
452 Scope* scope, Expression* value, bool* has_function) { 461 Scope* scope, Expression* value, bool* has_function) {
453 if (scope->DeclarationScope()->is_global_scope() && 462 if (scope->DeclarationScope()->is_global_scope() &&
454 value->AsFunctionLiteral() != NULL) { 463 value->AsFunctionLiteral() != NULL) {
455 *has_function = true; 464 *has_function = true;
456 value->AsFunctionLiteral()->set_pretenure(); 465 value->AsFunctionLiteral()->set_pretenure();
457 } 466 }
458 } 467 }
459 468
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 const AstRawString* arg, 538 const AstRawString* arg,
530 bool is_reference_error = false); 539 bool is_reference_error = false);
531 540
532 // "null" return type creators. 541 // "null" return type creators.
533 static const AstRawString* EmptyIdentifier() { 542 static const AstRawString* EmptyIdentifier() {
534 return NULL; 543 return NULL;
535 } 544 }
536 static Expression* EmptyExpression() { 545 static Expression* EmptyExpression() {
537 return NULL; 546 return NULL;
538 } 547 }
548 static Expression* EmptyArrowParamList() {
549 return NULL;
550 }
539 static Literal* EmptyLiteral() { 551 static Literal* EmptyLiteral() {
540 return NULL; 552 return NULL;
541 } 553 }
554
542 // Used in error return values. 555 // Used in error return values.
543 static ZoneList<Expression*>* NullExpressionList() { 556 static ZoneList<Expression*>* NullExpressionList() {
544 return NULL; 557 return NULL;
545 } 558 }
546 559
560 // Non-"null" empty string.
561 V8_INLINE Handle<String> EmptyIdentifierString();
marja 2014/06/26 14:38:13 Isn't this dead code?
562
547 // Odd-ball literal creators. 563 // Odd-ball literal creators.
548 Literal* GetLiteralTheHole(int position, 564 Literal* GetLiteralTheHole(int position,
549 AstNodeFactory<AstConstructionVisitor>* factory); 565 AstNodeFactory<AstConstructionVisitor>* factory);
550 566
551 // Producing data during the recursive descent. 567 // Producing data during the recursive descent.
552 const AstRawString* GetSymbol(Scanner* scanner); 568 const AstRawString* GetSymbol(Scanner* scanner);
553 const AstRawString* GetNextSymbol(Scanner* scanner); 569 const AstRawString* GetNextSymbol(Scanner* scanner);
554 570
555 Expression* ThisExpression(Scope* scope, 571 Expression* ThisExpression(Scope* scope,
556 AstNodeFactory<AstConstructionVisitor>* factory); 572 AstNodeFactory<AstConstructionVisitor>* factory,
573 int pos = RelocInfo::kNoPosition);
marja 2014/06/26 14:38:13 Why is the position needed?
557 Literal* ExpressionFromLiteral( 574 Literal* ExpressionFromLiteral(
558 Token::Value token, int pos, Scanner* scanner, 575 Token::Value token, int pos, Scanner* scanner,
559 AstNodeFactory<AstConstructionVisitor>* factory); 576 AstNodeFactory<AstConstructionVisitor>* factory);
560 Expression* ExpressionFromIdentifier( 577 Expression* ExpressionFromIdentifier(
561 const AstRawString* name, int pos, Scope* scope, 578 const AstRawString* name, int pos, Scope* scope,
562 AstNodeFactory<AstConstructionVisitor>* factory); 579 AstNodeFactory<AstConstructionVisitor>* factory);
563 Expression* ExpressionFromString( 580 Expression* ExpressionFromString(
564 int pos, Scanner* scanner, 581 int pos, Scanner* scanner,
565 AstNodeFactory<AstConstructionVisitor>* factory); 582 AstNodeFactory<AstConstructionVisitor>* factory);
566 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { 583 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) {
567 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); 584 return new(zone) ZoneList<v8::internal::Expression*>(size, zone);
568 } 585 }
569 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { 586 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) {
570 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); 587 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone);
571 } 588 }
572 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { 589 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) {
573 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); 590 return new(zone) ZoneList<v8::internal::Statement*>(size, zone);
574 } 591 }
592 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type);
593
594 // Utility functions
595 Vector<VariableProxy*> ParameterListFromExpression( Expression* expression);
marja 2014/06/26 14:38:13 Nit: extra space.
596 bool IsValidArrowFunctionParameterList(Expression* expression);
marja 2014/06/26 14:38:13 This function should go where the other IsThisAndT
597 void InferFunctionName(FunctionLiteral* func_to_infer);
marja 2014/06/26 14:38:13 Isn't this a stray definition?
598 V8_INLINE AstValueFactory* ast_value_factory();
575 599
576 // Temporary glue; these functions will move to ParserBase. 600 // Temporary glue; these functions will move to ParserBase.
577 Expression* ParseV8Intrinsic(bool* ok); 601 Expression* ParseV8Intrinsic(bool* ok);
578 FunctionLiteral* ParseFunctionLiteral( 602 FunctionLiteral* ParseFunctionLiteral(
579 const AstRawString* name, 603 const AstRawString* name,
580 Scanner::Location function_name_location, 604 Scanner::Location function_name_location,
581 bool name_is_strict_reserved, 605 bool name_is_strict_reserved,
582 bool is_generator, 606 bool is_generator,
583 int function_token_position, 607 int function_token_position,
584 FunctionLiteral::FunctionType type, 608 FunctionLiteral::FunctionType type,
585 FunctionLiteral::ArityRestriction arity_restriction, 609 FunctionLiteral::ArityRestriction arity_restriction,
586 bool* ok); 610 bool* ok);
611 V8_INLINE void SkipLazyFunctionBody(
612 const AstRawString* name,
613 int* materialized_literal_count,
614 int* expected_property_count,
615 bool* ok);
616 V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody(
617 const AstRawString* name,
618 int pos,
619 Variable* fvar,
620 Token::Value fvar_init_op,
621 bool is_generator,
622 bool* ok);
623 V8_INLINE void CheckConflictingVarDeclarations(
624 v8::internal::Scope* scope,
625 bool* ok);
587 626
588 private: 627 private:
589 Parser* parser_; 628 Parser* parser_;
590 }; 629 };
591 630
592 631
593 class Parser : public ParserBase<ParserTraits> { 632 class Parser : public ParserBase<ParserTraits> {
594 public: 633 public:
595 explicit Parser(CompilationInfo* info); 634 explicit Parser(CompilationInfo* info);
596 ~Parser() { 635 ~Parser() {
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 // Pending errors. 854 // Pending errors.
816 bool has_pending_error_; 855 bool has_pending_error_;
817 Scanner::Location pending_error_location_; 856 Scanner::Location pending_error_location_;
818 const char* pending_error_message_; 857 const char* pending_error_message_;
819 const AstRawString* pending_error_arg_; 858 const AstRawString* pending_error_arg_;
820 const char* pending_error_char_arg_; 859 const char* pending_error_char_arg_;
821 bool pending_error_is_reference_error_; 860 bool pending_error_is_reference_error_;
822 }; 861 };
823 862
824 863
864 bool ParserTraits::IsFutureStrictReserved(
865 const AstRawString* identifier) const {
866 return identifier->IsOneByteEqualTo("yield") ||
867 parser_->scanner()->IdentifierIsFutureStrictReserved(identifier);
868 }
869
870
871 Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type) {
872 return parser_->NewScope(parent_scope, scope_type);
873 }
874
875
876 Handle<String> ParserTraits::EmptyIdentifierString() {
877 return parser_->zone()->isolate()->factory()->empty_string();
878 }
879
880
881 void ParserTraits::SkipLazyFunctionBody(
882 const AstRawString* function_name,
883 int* materialized_literal_count,
884 int* expected_property_count,
885 bool* ok) {
886 return parser_->SkipLazyFunctionBody(function_name,
887 materialized_literal_count, expected_property_count, ok);
888 }
889
890
891 ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody(
892 const AstRawString* name,
893 int pos,
894 Variable* fvar,
895 Token::Value fvar_init_op,
896 bool is_generator,
897 bool* ok) {
898 return parser_->ParseEagerFunctionBody(name, pos,
899 fvar, fvar_init_op, is_generator, ok);
900 }
901
902 void ParserTraits::CheckConflictingVarDeclarations(
903 v8::internal::Scope* scope, bool* ok) {
904 parser_->CheckConflictingVarDeclarations(scope, ok);
905 }
906
907
908 AstValueFactory* ParserTraits::ast_value_factory() {
909 return parser_->ast_value_factory_;
910 }
911
912
825 // Support for handling complex values (array and object literals) that 913 // Support for handling complex values (array and object literals) that
826 // can be fully handled at compile time. 914 // can be fully handled at compile time.
827 class CompileTimeValue: public AllStatic { 915 class CompileTimeValue: public AllStatic {
828 public: 916 public:
829 enum LiteralType { 917 enum LiteralType {
830 OBJECT_LITERAL_FAST_ELEMENTS, 918 OBJECT_LITERAL_FAST_ELEMENTS,
831 OBJECT_LITERAL_SLOW_ELEMENTS, 919 OBJECT_LITERAL_SLOW_ELEMENTS,
832 ARRAY_LITERAL 920 ARRAY_LITERAL
833 }; 921 };
834 922
(...skipping 11 matching lines...) Expand all
846 private: 934 private:
847 static const int kLiteralTypeSlot = 0; 935 static const int kLiteralTypeSlot = 0;
848 static const int kElementsSlot = 1; 936 static const int kElementsSlot = 1;
849 937
850 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 938 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
851 }; 939 };
852 940
853 } } // namespace v8::internal 941 } } // namespace v8::internal
854 942
855 #endif // V8_PARSER_H_ 943 #endif // V8_PARSER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698