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

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: Made tests more comprehensive 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
« no previous file with comments | « src/messages.js ('k') | src/parser.cc » ('j') | src/scanner.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_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 AstString* Identifier; 396 typedef const AstString* 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 AstString* identifier) const; 428 bool IsEvalOrArguments(const AstString* identifier) const;
429 V8_INLINE bool IsFutureStrictReserved(const AstString* 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 AstString* AsIdentifier(Expression* expression) { 436 static const AstString* 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 AstString* string, uint32_t* index) { 445 static bool IsArrayIndex(const AstString* 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 AstString* id) { 451 static void PushLiteralName(FuncNameInferrer* fni, const AstString* 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 int pos); 518 int pos);
510 519
511 // Generic AST generator for throwing errors from compiled code. 520 // Generic AST generator for throwing errors from compiled code.
512 Expression* NewThrowError( 521 Expression* NewThrowError(
513 const AstString* constructor, const char* type, 522 const AstString* constructor, const char* type,
514 const AstString* arg, int pos); 523 const AstString* arg, int pos);
515 524
516 // Reporting errors. 525 // Reporting errors.
517 void ReportMessageAt(Scanner::Location source_location, 526 void ReportMessageAt(Scanner::Location source_location,
518 const char* message, 527 const char* message,
519 const char* arg, 528 const char* arg = NULL,
520 bool is_reference_error = false); 529 bool is_reference_error = false);
521 void ReportMessage(const char* message, 530 void ReportMessage(const char* message,
522 const char* arg = NULL, 531 const char* arg = NULL,
523 bool is_reference_error = false); 532 bool is_reference_error = false);
524 void ReportMessage(const char* message, 533 void ReportMessage(const char* message,
525 const AstString* arg, 534 const AstString* arg,
526 bool is_reference_error = false); 535 bool is_reference_error = false);
527 void ReportMessageAt(Scanner::Location source_location, 536 void ReportMessageAt(Scanner::Location source_location,
528 const char* message, 537 const char* message,
529 const AstString* arg, 538 const AstString* 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 AstString* EmptyIdentifier() { 542 static const AstString* 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 }
539 static Literal* EmptyLiteral() { 548 static Literal* EmptyLiteral() {
540 return NULL; 549 return NULL;
541 } 550 }
551
542 // Used in error return values. 552 // Used in error return values.
543 static ZoneList<Expression*>* NullExpressionList() { 553 static ZoneList<Expression*>* NullExpressionList() {
544 return NULL; 554 return NULL;
545 } 555 }
546 556
557 // Non-"null" empty string.
558 V8_INLINE const AstString* EmptyIdentifierString();
559
547 // Odd-ball literal creators. 560 // Odd-ball literal creators.
548 Literal* GetLiteralTheHole(int position, 561 Literal* GetLiteralTheHole(int position,
549 AstNodeFactory<AstConstructionVisitor>* factory); 562 AstNodeFactory<AstConstructionVisitor>* factory);
550 563
551 // Producing data during the recursive descent. 564 // Producing data during the recursive descent.
552 const AstString* GetSymbol(Scanner* scanner); 565 const AstString* GetSymbol(Scanner* scanner);
553 const AstString* GetNextSymbol(Scanner* scanner); 566 const AstString* GetNextSymbol(Scanner* scanner);
554 567
555 Expression* ThisExpression(Scope* scope, 568 Expression* ThisExpression(Scope* scope,
556 AstNodeFactory<AstConstructionVisitor>* factory); 569 AstNodeFactory<AstConstructionVisitor>* factory,
570 int pos = RelocInfo::kNoPosition);
557 Literal* ExpressionFromLiteral( 571 Literal* ExpressionFromLiteral(
558 Token::Value token, int pos, Scanner* scanner, 572 Token::Value token, int pos, Scanner* scanner,
559 AstNodeFactory<AstConstructionVisitor>* factory); 573 AstNodeFactory<AstConstructionVisitor>* factory);
560 Expression* ExpressionFromIdentifier( 574 Expression* ExpressionFromIdentifier(
561 const AstString* name, int pos, Scope* scope, 575 const AstString* name, int pos, Scope* scope,
562 AstNodeFactory<AstConstructionVisitor>* factory); 576 AstNodeFactory<AstConstructionVisitor>* factory);
563 Expression* ExpressionFromString( 577 Expression* ExpressionFromString(
564 int pos, Scanner* scanner, 578 int pos, Scanner* scanner,
565 AstNodeFactory<AstConstructionVisitor>* factory); 579 AstNodeFactory<AstConstructionVisitor>* factory);
566 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { 580 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) {
567 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); 581 return new(zone) ZoneList<v8::internal::Expression*>(size, zone);
568 } 582 }
569 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { 583 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) {
570 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); 584 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone);
571 } 585 }
572 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { 586 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) {
573 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); 587 return new(zone) ZoneList<v8::internal::Statement*>(size, zone);
574 } 588 }
589 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type);
590
591 // Utility functions
592 Vector<VariableProxy*> ParameterListFromExpression(
593 Expression* expression, bool* ok);
594 void InferFunctionName(FunctionLiteral* func_to_infer);
595
596 V8_INLINE AstValueFactory* ast_value_factory();
575 597
576 // Temporary glue; these functions will move to ParserBase. 598 // Temporary glue; these functions will move to ParserBase.
577 Expression* ParseV8Intrinsic(bool* ok); 599 Expression* ParseV8Intrinsic(bool* ok);
578 FunctionLiteral* ParseFunctionLiteral( 600 FunctionLiteral* ParseFunctionLiteral(
579 const AstString* name, 601 const AstString* name,
580 Scanner::Location function_name_location, 602 Scanner::Location function_name_location,
581 bool name_is_strict_reserved, 603 bool name_is_strict_reserved,
582 bool is_generator, 604 bool is_generator,
583 int function_token_position, 605 int function_token_position,
584 FunctionLiteral::FunctionType type, 606 FunctionLiteral::FunctionType type,
585 FunctionLiteral::ArityRestriction arity_restriction, 607 FunctionLiteral::ArityRestriction arity_restriction,
586 bool* ok); 608 bool* ok);
609 V8_INLINE void SkipLazyFunctionBody(
610 const AstString* name,
611 int* materialized_literal_count,
612 int* expected_property_count,
613 bool* ok);
614 V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody(
615 const AstString* name,
616 int pos,
617 Variable* fvar,
618 Token::Value fvar_init_op,
619 bool is_generator,
620 bool* ok);
621 V8_INLINE void CheckConflictingVarDeclarations(
622 v8::internal::Scope* scope,
623 bool* ok);
587 624
588 private: 625 private:
589 Parser* parser_; 626 Parser* parser_;
590 }; 627 };
591 628
592 629
593 class Parser : public ParserBase<ParserTraits> { 630 class Parser : public ParserBase<ParserTraits> {
594 public: 631 public:
595 explicit Parser(CompilationInfo* info); 632 explicit Parser(CompilationInfo* info);
596 ~Parser() { 633 ~Parser() {
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 VariableMode mode, 804 VariableMode mode,
768 Interface* interface); 805 Interface* interface);
769 void Declare(Declaration* declaration, bool resolve, bool* ok); 806 void Declare(Declaration* declaration, bool resolve, bool* ok);
770 807
771 bool TargetStackContainsLabel(const AstString* label); 808 bool TargetStackContainsLabel(const AstString* label);
772 BreakableStatement* LookupBreakTarget(const AstString* label, bool* ok); 809 BreakableStatement* LookupBreakTarget(const AstString* label, bool* ok);
773 IterationStatement* LookupContinueTarget(const AstString* label, bool* ok); 810 IterationStatement* LookupContinueTarget(const AstString* label, bool* ok);
774 811
775 void RegisterTargetUse(Label* target, Target* stop); 812 void RegisterTargetUse(Label* target, Target* stop);
776 813
814 Vector<VariableProxy*> ParameterListFromExpression(Expression* expression,
815 bool* ok);
816
777 // Factory methods. 817 // Factory methods.
778 818
779 Scope* NewScope(Scope* parent, ScopeType type); 819 Scope* NewScope(Scope* parent, ScopeType type);
780 820
781 // Skip over a lazy function, either using cached data if we have it, or 821 // Skip over a lazy function, either using cached data if we have it, or
782 // by parsing the function with PreParser. Consumes the ending }. 822 // by parsing the function with PreParser. Consumes the ending }.
783 void SkipLazyFunctionBody(const AstString* function_name, 823 void SkipLazyFunctionBody(const AstString* function_name,
784 int* materialized_literal_count, 824 int* materialized_literal_count,
785 int* expected_property_count, 825 int* expected_property_count,
786 bool* ok); 826 bool* ok);
(...skipping 27 matching lines...) Expand all
814 // Pending errors. 854 // Pending errors.
815 bool has_pending_error_; 855 bool has_pending_error_;
816 Scanner::Location pending_error_location_; 856 Scanner::Location pending_error_location_;
817 const char* pending_error_message_; 857 const char* pending_error_message_;
818 const AstString* pending_error_arg_; 858 const AstString* pending_error_arg_;
819 const char* pending_error_char_arg_; 859 const char* pending_error_char_arg_;
820 bool pending_error_is_reference_error_; 860 bool pending_error_is_reference_error_;
821 }; 861 };
822 862
823 863
864 AstValueFactory* ParserTraits::ast_value_factory() {
865 return parser_->ast_value_factory_;
866 }
867
868
869 bool ParserTraits::IsFutureStrictReserved(const AstString* identifier) const {
870 return identifier->IsOneByteEqualTo("yield") ||
871 parser_->scanner()->IdentifierIsFutureStrictReserved(identifier);
872 }
873
874
875 Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type) {
876 return parser_->NewScope(parent_scope, scope_type);
877 }
878
879
880 const AstString* ParserTraits::EmptyIdentifierString() {
881 return parser_->ast_value_factory()->empty_string();
882 }
883
884
885 void ParserTraits::SkipLazyFunctionBody(
886 const AstString* function_name,
887 int* materialized_literal_count,
888 int* expected_property_count,
889 bool* ok) {
890 return parser_->SkipLazyFunctionBody(function_name,
891 materialized_literal_count, expected_property_count, ok);
892 }
893
894
895 ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody(
896 const AstString* name,
897 int pos,
898 Variable* fvar,
899 Token::Value fvar_init_op,
900 bool is_generator,
901 bool* ok) {
902 return parser_->ParseEagerFunctionBody(name, pos,
903 fvar, fvar_init_op, is_generator, ok);
904 }
905
906 void ParserTraits::CheckConflictingVarDeclarations(
907 v8::internal::Scope* scope, bool* ok) {
908 parser_->CheckConflictingVarDeclarations(scope, ok);
909 }
910
824 // Support for handling complex values (array and object literals) that 911 // Support for handling complex values (array and object literals) that
825 // can be fully handled at compile time. 912 // can be fully handled at compile time.
826 class CompileTimeValue: public AllStatic { 913 class CompileTimeValue: public AllStatic {
827 public: 914 public:
828 enum LiteralType { 915 enum LiteralType {
829 OBJECT_LITERAL_FAST_ELEMENTS, 916 OBJECT_LITERAL_FAST_ELEMENTS,
830 OBJECT_LITERAL_SLOW_ELEMENTS, 917 OBJECT_LITERAL_SLOW_ELEMENTS,
831 ARRAY_LITERAL 918 ARRAY_LITERAL
832 }; 919 };
833 920
(...skipping 11 matching lines...) Expand all
845 private: 932 private:
846 static const int kLiteralTypeSlot = 0; 933 static const int kLiteralTypeSlot = 0;
847 static const int kElementsSlot = 1; 934 static const int kElementsSlot = 1;
848 935
849 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 936 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
850 }; 937 };
851 938
852 } } // namespace v8::internal 939 } } // namespace v8::internal
853 940
854 #endif // V8_PARSER_H_ 941 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/messages.js ('k') | src/parser.cc » ('j') | src/scanner.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698