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

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: Extra parens in parameter lists now recognized, no longer segfaults on "()" 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/objects-inl.h ('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 "allocation.h" 8 #include "allocation.h"
9 #include "ast.h" 9 #include "ast.h"
10 #include "compiler.h" // For CachedDataMode 10 #include "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;
marja 2014/05/26 12:46:06 Why is this needed?
marja 2014/05/26 12:48:33 Ahh, nothing, I see we discussed scopes before. :)
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 Handle<String> Identifier; 396 typedef Handle<String> 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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 static bool IsArrayIndex(Handle<String> string, uint32_t* index) { 444 static bool IsArrayIndex(Handle<String> string, uint32_t* index) {
441 return !string.is_null() && string->AsArrayIndex(index); 445 return !string.is_null() && string->AsArrayIndex(index);
442 } 446 }
443 447
444 // Functions for encapsulating the differences between parsing and preparsing; 448 // Functions for encapsulating the differences between parsing and preparsing;
445 // operations interleaved with the recursive descent. 449 // operations interleaved with the recursive descent.
446 static void PushLiteralName(FuncNameInferrer* fni, Handle<String> id) { 450 static void PushLiteralName(FuncNameInferrer* fni, Handle<String> id) {
447 fni->PushLiteralName(id); 451 fni->PushLiteralName(id);
448 } 452 }
449 void PushPropertyName(FuncNameInferrer* fni, Expression* expression); 453 void PushPropertyName(FuncNameInferrer* fni, Expression* expression);
454 static void InferFunctionName(FuncNameInferrer* fni,
455 FunctionLiteral* func_to_infer) {
456 fni->AddFunction(func_to_infer);
457 }
450 458
451 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( 459 static void CheckFunctionLiteralInsideTopLevelObjectLiteral(
452 Scope* scope, Expression* value, bool* has_function) { 460 Scope* scope, Expression* value, bool* has_function) {
453 if (scope->DeclarationScope()->is_global_scope() && 461 if (scope->DeclarationScope()->is_global_scope() &&
454 value->AsFunctionLiteral() != NULL) { 462 value->AsFunctionLiteral() != NULL) {
455 *has_function = true; 463 *has_function = true;
456 value->AsFunctionLiteral()->set_pretenure(); 464 value->AsFunctionLiteral()->set_pretenure();
457 } 465 }
458 } 466 }
459 467
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 // "null" return type creators. 536 // "null" return type creators.
529 static Handle<String> EmptyIdentifier() { 537 static Handle<String> EmptyIdentifier() {
530 return Handle<String>(); 538 return Handle<String>();
531 } 539 }
532 static Expression* EmptyExpression() { 540 static Expression* EmptyExpression() {
533 return NULL; 541 return NULL;
534 } 542 }
535 static Literal* EmptyLiteral() { 543 static Literal* EmptyLiteral() {
536 return NULL; 544 return NULL;
537 } 545 }
546
538 // Used in error return values. 547 // Used in error return values.
539 static ZoneList<Expression*>* NullExpressionList() { 548 static ZoneList<Expression*>* NullExpressionList() {
540 return NULL; 549 return NULL;
541 } 550 }
542 551
552 // Non-"null" empty string.
553 V8_INLINE Handle<String> EmptyIdentifierString();
554
543 // Odd-ball literal creators. 555 // Odd-ball literal creators.
544 Literal* GetLiteralTheHole(int position, 556 Literal* GetLiteralTheHole(int position,
545 AstNodeFactory<AstConstructionVisitor>* factory); 557 AstNodeFactory<AstConstructionVisitor>* factory);
546 558
547 // Producing data during the recursive descent. 559 // Producing data during the recursive descent.
548 Handle<String> GetSymbol(Scanner* scanner = NULL); 560 Handle<String> GetSymbol(Scanner* scanner = NULL);
549 Handle<String> NextLiteralString(Scanner* scanner, 561 Handle<String> NextLiteralString(Scanner* scanner,
550 PretenureFlag tenured); 562 PretenureFlag tenured);
551 Expression* ThisExpression(Scope* scope, 563 Expression* ThisExpression(Scope* scope,
552 AstNodeFactory<AstConstructionVisitor>* factory); 564 AstNodeFactory<AstConstructionVisitor>* factory,
565 int pos = RelocInfo::kNoPosition);
553 Literal* ExpressionFromLiteral( 566 Literal* ExpressionFromLiteral(
554 Token::Value token, int pos, Scanner* scanner, 567 Token::Value token, int pos, Scanner* scanner,
555 AstNodeFactory<AstConstructionVisitor>* factory); 568 AstNodeFactory<AstConstructionVisitor>* factory);
556 Expression* ExpressionFromIdentifier( 569 Expression* ExpressionFromIdentifier(
557 Handle<String> name, int pos, Scope* scope, 570 Handle<String> name, int pos, Scope* scope,
558 AstNodeFactory<AstConstructionVisitor>* factory); 571 AstNodeFactory<AstConstructionVisitor>* factory);
559 Expression* ExpressionFromString( 572 Expression* ExpressionFromString(
560 int pos, Scanner* scanner, 573 int pos, Scanner* scanner,
561 AstNodeFactory<AstConstructionVisitor>* factory); 574 AstNodeFactory<AstConstructionVisitor>* factory);
562 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { 575 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) {
563 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); 576 return new(zone) ZoneList<v8::internal::Expression*>(size, zone);
564 } 577 }
565 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { 578 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) {
566 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); 579 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone);
567 } 580 }
568 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { 581 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) {
569 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); 582 return new(zone) ZoneList<v8::internal::Statement*>(size, zone);
570 } 583 }
584 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type);
585
586 // Utility functions
587 Vector<VariableProxy*> ParameterListFromExpression(
588 Expression* expression, bool* ok);
589 void InferFunctionName(FunctionLiteral* func_to_infer);
571 590
572 // Temporary glue; these functions will move to ParserBase. 591 // Temporary glue; these functions will move to ParserBase.
573 Expression* ParseV8Intrinsic(bool* ok); 592 Expression* ParseV8Intrinsic(bool* ok);
574 FunctionLiteral* ParseFunctionLiteral( 593 FunctionLiteral* ParseFunctionLiteral(
575 Handle<String> name, 594 Handle<String> name,
576 Scanner::Location function_name_location, 595 Scanner::Location function_name_location,
577 bool name_is_strict_reserved, 596 bool name_is_strict_reserved,
578 bool is_generator, 597 bool is_generator,
579 int function_token_position, 598 int function_token_position,
580 FunctionLiteral::FunctionType type, 599 FunctionLiteral::FunctionType type,
581 bool* ok); 600 bool* ok);
601 V8_INLINE void SkipLazyFunctionBody(
602 Handle<String> function_name,
603 int* materialized_literal_count,
604 int* expected_property_count,
605 bool* ok);
606 V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody(
607 Handle<String> function_name,
608 int pos,
609 Variable* fvar,
610 Token::Value fvar_init_op,
611 bool is_generator,
612 bool* ok);
613 V8_INLINE void CheckConflictingVarDeclarations(
614 v8::internal::Scope* scope,
615 bool* ok);
582 616
583 private: 617 private:
584 Parser* parser_; 618 Parser* parser_;
585 }; 619 };
586 620
587 621
588 class Parser : public ParserBase<ParserTraits> { 622 class Parser : public ParserBase<ParserTraits> {
589 public: 623 public:
590 explicit Parser(CompilationInfo* info); 624 explicit Parser(CompilationInfo* info);
591 ~Parser() { 625 ~Parser() {
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 VariableMode mode, 790 VariableMode mode,
757 Interface* interface); 791 Interface* interface);
758 void Declare(Declaration* declaration, bool resolve, bool* ok); 792 void Declare(Declaration* declaration, bool resolve, bool* ok);
759 793
760 bool TargetStackContainsLabel(Handle<String> label); 794 bool TargetStackContainsLabel(Handle<String> label);
761 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok); 795 BreakableStatement* LookupBreakTarget(Handle<String> label, bool* ok);
762 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok); 796 IterationStatement* LookupContinueTarget(Handle<String> label, bool* ok);
763 797
764 void RegisterTargetUse(Label* target, Target* stop); 798 void RegisterTargetUse(Label* target, Target* stop);
765 799
800 Vector<VariableProxy*> ParameterListFromExpression(Expression* expression,
801 bool* ok);
802
766 // Factory methods. 803 // Factory methods.
767 804
768 Scope* NewScope(Scope* parent, ScopeType type); 805 Scope* NewScope(Scope* parent, ScopeType type);
769 806
770 // Skip over a lazy function, either using cached data if we have it, or 807 // Skip over a lazy function, either using cached data if we have it, or
771 // by parsing the function with PreParser. Consumes the ending }. 808 // by parsing the function with PreParser. Consumes the ending }.
772 void SkipLazyFunctionBody(Handle<String> function_name, 809 void SkipLazyFunctionBody(Handle<String> function_name,
773 int* materialized_literal_count, 810 int* materialized_literal_count,
774 int* expected_property_count, 811 int* expected_property_count,
775 bool* ok); 812 bool* ok);
(...skipping 26 matching lines...) Expand all
802 // Pending errors. 839 // Pending errors.
803 bool has_pending_error_; 840 bool has_pending_error_;
804 Scanner::Location pending_error_location_; 841 Scanner::Location pending_error_location_;
805 const char* pending_error_message_; 842 const char* pending_error_message_;
806 MaybeHandle<String> pending_error_arg_; 843 MaybeHandle<String> pending_error_arg_;
807 const char* pending_error_char_arg_; 844 const char* pending_error_char_arg_;
808 bool pending_error_is_reference_error_; 845 bool pending_error_is_reference_error_;
809 }; 846 };
810 847
811 848
849 Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type) {
850 return parser_->NewScope(parent_scope, scope_type);
851 }
852
853
854 Handle<String> ParserTraits::EmptyIdentifierString() {
855 return parser_->isolate()->factory()->empty_string();
856 }
857
858
859 void ParserTraits::SkipLazyFunctionBody(
860 Handle<String> function_name,
861 int* materialized_literal_count,
862 int* expected_property_count,
863 bool* ok) {
864 return parser_->SkipLazyFunctionBody(function_name,
865 materialized_literal_count, expected_property_count, ok);
866 }
867
868
869 ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody(
870 Handle<String> function_name,
871 int pos,
872 Variable* fvar,
873 Token::Value fvar_init_op,
874 bool is_generator,
875 bool* ok) {
876 return parser_->ParseEagerFunctionBody(function_name, pos,
877 fvar, fvar_init_op, is_generator, ok);
878 }
879
880 void ParserTraits::CheckConflictingVarDeclarations(
881 v8::internal::Scope* scope, bool* ok) {
882 parser_->CheckConflictingVarDeclarations(scope, ok);
883 }
884
812 // Support for handling complex values (array and object literals) that 885 // Support for handling complex values (array and object literals) that
813 // can be fully handled at compile time. 886 // can be fully handled at compile time.
814 class CompileTimeValue: public AllStatic { 887 class CompileTimeValue: public AllStatic {
815 public: 888 public:
816 enum LiteralType { 889 enum LiteralType {
817 OBJECT_LITERAL_FAST_ELEMENTS, 890 OBJECT_LITERAL_FAST_ELEMENTS,
818 OBJECT_LITERAL_SLOW_ELEMENTS, 891 OBJECT_LITERAL_SLOW_ELEMENTS,
819 ARRAY_LITERAL 892 ARRAY_LITERAL
820 }; 893 };
821 894
(...skipping 11 matching lines...) Expand all
833 private: 906 private:
834 static const int kLiteralTypeSlot = 0; 907 static const int kLiteralTypeSlot = 0;
835 static const int kElementsSlot = 1; 908 static const int kElementsSlot = 1;
836 909
837 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 910 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
838 }; 911 };
839 912
840 } } // namespace v8::internal 913 } } // namespace v8::internal
841 914
842 #endif // V8_PARSER_H_ 915 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | src/parser.cc » ('j') | src/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698