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

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: Version with parsing code only, tests into test-parsing.cc 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/parser.cc » ('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 bool* ok); 607 bool* ok);
608 V8_INLINE void SkipLazyFunctionBody(
609 const AstString* name,
610 int* materialized_literal_count,
611 int* expected_property_count,
612 bool* ok);
613 V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody(
614 const AstString* name,
615 int pos,
616 Variable* fvar,
617 Token::Value fvar_init_op,
618 bool is_generator,
619 bool* ok);
620 V8_INLINE void CheckConflictingVarDeclarations(
621 v8::internal::Scope* scope,
622 bool* ok);
586 623
587 private: 624 private:
588 Parser* parser_; 625 Parser* parser_;
589 }; 626 };
590 627
591 628
592 class Parser : public ParserBase<ParserTraits> { 629 class Parser : public ParserBase<ParserTraits> {
593 public: 630 public:
594 explicit Parser(CompilationInfo* info); 631 explicit Parser(CompilationInfo* info);
595 ~Parser() { 632 ~Parser() {
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
765 VariableMode mode, 802 VariableMode mode,
766 Interface* interface); 803 Interface* interface);
767 void Declare(Declaration* declaration, bool resolve, bool* ok); 804 void Declare(Declaration* declaration, bool resolve, bool* ok);
768 805
769 bool TargetStackContainsLabel(const AstString* label); 806 bool TargetStackContainsLabel(const AstString* label);
770 BreakableStatement* LookupBreakTarget(const AstString* label, bool* ok); 807 BreakableStatement* LookupBreakTarget(const AstString* label, bool* ok);
771 IterationStatement* LookupContinueTarget(const AstString* label, bool* ok); 808 IterationStatement* LookupContinueTarget(const AstString* label, bool* ok);
772 809
773 void RegisterTargetUse(Label* target, Target* stop); 810 void RegisterTargetUse(Label* target, Target* stop);
774 811
812 Vector<VariableProxy*> ParameterListFromExpression(Expression* expression,
813 bool* ok);
814
775 // Factory methods. 815 // Factory methods.
776 816
777 Scope* NewScope(Scope* parent, ScopeType type); 817 Scope* NewScope(Scope* parent, ScopeType type);
778 818
779 // Skip over a lazy function, either using cached data if we have it, or 819 // Skip over a lazy function, either using cached data if we have it, or
780 // by parsing the function with PreParser. Consumes the ending }. 820 // by parsing the function with PreParser. Consumes the ending }.
781 void SkipLazyFunctionBody(const AstString* function_name, 821 void SkipLazyFunctionBody(const AstString* function_name,
782 int* materialized_literal_count, 822 int* materialized_literal_count,
783 int* expected_property_count, 823 int* expected_property_count,
784 bool* ok); 824 bool* ok);
(...skipping 27 matching lines...) Expand all
812 // Pending errors. 852 // Pending errors.
813 bool has_pending_error_; 853 bool has_pending_error_;
814 Scanner::Location pending_error_location_; 854 Scanner::Location pending_error_location_;
815 const char* pending_error_message_; 855 const char* pending_error_message_;
816 const AstString* pending_error_arg_; 856 const AstString* pending_error_arg_;
817 const char* pending_error_char_arg_; 857 const char* pending_error_char_arg_;
818 bool pending_error_is_reference_error_; 858 bool pending_error_is_reference_error_;
819 }; 859 };
820 860
821 861
862 AstValueFactory* ParserTraits::ast_value_factory() {
863 return parser_->ast_value_factory_;
864 }
865
866
867 bool ParserTraits::IsFutureStrictReserved(const AstString* identifier) const {
868 return identifier->IsOneByteEqualTo("yield") ||
869 parser_->scanner()->IdentifierIsFutureStrictReserved(identifier);
870 }
871
872
873 Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type) {
874 return parser_->NewScope(parent_scope, scope_type);
875 }
876
877
878 const AstString* ParserTraits::EmptyIdentifierString() {
879 return parser_->ast_value_factory()->empty_string();
880 }
881
882
883 void ParserTraits::SkipLazyFunctionBody(
884 const AstString* function_name,
885 int* materialized_literal_count,
886 int* expected_property_count,
887 bool* ok) {
888 return parser_->SkipLazyFunctionBody(function_name,
889 materialized_literal_count, expected_property_count, ok);
890 }
891
892
893 ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody(
894 const AstString* name,
895 int pos,
896 Variable* fvar,
897 Token::Value fvar_init_op,
898 bool is_generator,
899 bool* ok) {
900 return parser_->ParseEagerFunctionBody(name, pos,
901 fvar, fvar_init_op, is_generator, ok);
902 }
903
904 void ParserTraits::CheckConflictingVarDeclarations(
905 v8::internal::Scope* scope, bool* ok) {
906 parser_->CheckConflictingVarDeclarations(scope, ok);
907 }
908
822 // Support for handling complex values (array and object literals) that 909 // Support for handling complex values (array and object literals) that
823 // can be fully handled at compile time. 910 // can be fully handled at compile time.
824 class CompileTimeValue: public AllStatic { 911 class CompileTimeValue: public AllStatic {
825 public: 912 public:
826 enum LiteralType { 913 enum LiteralType {
827 OBJECT_LITERAL_FAST_ELEMENTS, 914 OBJECT_LITERAL_FAST_ELEMENTS,
828 OBJECT_LITERAL_SLOW_ELEMENTS, 915 OBJECT_LITERAL_SLOW_ELEMENTS,
829 ARRAY_LITERAL 916 ARRAY_LITERAL
830 }; 917 };
831 918
(...skipping 11 matching lines...) Expand all
843 private: 930 private:
844 static const int kLiteralTypeSlot = 0; 931 static const int kLiteralTypeSlot = 0;
845 static const int kElementsSlot = 1; 932 static const int kElementsSlot = 1;
846 933
847 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 934 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
848 }; 935 };
849 936
850 } } // namespace v8::internal 937 } } // namespace v8::internal
851 938
852 #endif // V8_PARSER_H_ 939 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/messages.js ('k') | src/parser.cc » ('j') | src/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698