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

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: What "git cl format" produces Created 6 years, 5 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') | no next file with comments »
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 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 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 const AstRawString* arg, 533 const AstRawString* arg,
529 bool is_reference_error = false); 534 bool is_reference_error = false);
530 535
531 // "null" return type creators. 536 // "null" return type creators.
532 static const AstRawString* EmptyIdentifier() { 537 static const AstRawString* EmptyIdentifier() {
533 return NULL; 538 return NULL;
534 } 539 }
535 static Expression* EmptyExpression() { 540 static Expression* EmptyExpression() {
536 return NULL; 541 return NULL;
537 } 542 }
543 static Expression* EmptyArrowParamList() { return NULL; }
538 static Literal* EmptyLiteral() { 544 static Literal* EmptyLiteral() {
539 return NULL; 545 return NULL;
540 } 546 }
547
541 // Used in error return values. 548 // Used in error return values.
542 static ZoneList<Expression*>* NullExpressionList() { 549 static ZoneList<Expression*>* NullExpressionList() {
543 return NULL; 550 return NULL;
544 } 551 }
545 552
553 // Non-NULL empty string.
554 V8_INLINE const AstRawString* EmptyIdentifierString();
555
546 // Odd-ball literal creators. 556 // Odd-ball literal creators.
547 Literal* GetLiteralTheHole(int position, 557 Literal* GetLiteralTheHole(int position,
548 AstNodeFactory<AstConstructionVisitor>* factory); 558 AstNodeFactory<AstConstructionVisitor>* factory);
549 559
550 // Producing data during the recursive descent. 560 // Producing data during the recursive descent.
551 const AstRawString* GetSymbol(Scanner* scanner); 561 const AstRawString* GetSymbol(Scanner* scanner);
552 const AstRawString* GetNextSymbol(Scanner* scanner); 562 const AstRawString* GetNextSymbol(Scanner* scanner);
553 563
554 Expression* ThisExpression(Scope* scope, 564 Expression* ThisExpression(Scope* scope,
555 AstNodeFactory<AstConstructionVisitor>* factory); 565 AstNodeFactory<AstConstructionVisitor>* factory);
556 Literal* ExpressionFromLiteral( 566 Literal* ExpressionFromLiteral(
557 Token::Value token, int pos, Scanner* scanner, 567 Token::Value token, int pos, Scanner* scanner,
558 AstNodeFactory<AstConstructionVisitor>* factory); 568 AstNodeFactory<AstConstructionVisitor>* factory);
559 Expression* ExpressionFromIdentifier( 569 Expression* ExpressionFromIdentifier(
560 const AstRawString* name, int pos, Scope* scope, 570 const AstRawString* name, int pos, Scope* scope,
561 AstNodeFactory<AstConstructionVisitor>* factory); 571 AstNodeFactory<AstConstructionVisitor>* factory);
562 Expression* ExpressionFromString( 572 Expression* ExpressionFromString(
563 int pos, Scanner* scanner, 573 int pos, Scanner* scanner,
564 AstNodeFactory<AstConstructionVisitor>* factory); 574 AstNodeFactory<AstConstructionVisitor>* factory);
565 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { 575 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) {
566 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); 576 return new(zone) ZoneList<v8::internal::Expression*>(size, zone);
567 } 577 }
568 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { 578 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) {
569 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); 579 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone);
570 } 580 }
571 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { 581 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) {
572 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); 582 return new(zone) ZoneList<v8::internal::Statement*>(size, zone);
573 } 583 }
584 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type);
585
586 // Utility functions
587 Vector<VariableProxy*> ParameterListFromExpression(Expression* expression,
588 bool* ok);
589 V8_INLINE AstValueFactory* ast_value_factory();
574 590
575 // Temporary glue; these functions will move to ParserBase. 591 // Temporary glue; these functions will move to ParserBase.
576 Expression* ParseV8Intrinsic(bool* ok); 592 Expression* ParseV8Intrinsic(bool* ok);
577 FunctionLiteral* ParseFunctionLiteral( 593 FunctionLiteral* ParseFunctionLiteral(
578 const AstRawString* name, 594 const AstRawString* name,
579 Scanner::Location function_name_location, 595 Scanner::Location function_name_location,
580 bool name_is_strict_reserved, 596 bool name_is_strict_reserved,
581 bool is_generator, 597 bool is_generator,
582 int function_token_position, 598 int function_token_position,
583 FunctionLiteral::FunctionType type, 599 FunctionLiteral::FunctionType type,
584 FunctionLiteral::ArityRestriction arity_restriction, 600 FunctionLiteral::ArityRestriction arity_restriction,
585 bool* ok); 601 bool* ok);
602 V8_INLINE void SkipLazyFunctionBody(const AstRawString* name,
603 int* materialized_literal_count,
604 int* expected_property_count, bool* ok);
605 V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody(
606 const AstRawString* name, int pos, Variable* fvar,
607 Token::Value fvar_init_op, bool is_generator, bool* ok);
608 V8_INLINE void CheckConflictingVarDeclarations(v8::internal::Scope* scope,
609 bool* ok);
586 610
587 private: 611 private:
588 Parser* parser_; 612 Parser* parser_;
589 }; 613 };
590 614
591 615
592 class Parser : public ParserBase<ParserTraits> { 616 class Parser : public ParserBase<ParserTraits> {
593 public: 617 public:
594 explicit Parser(CompilationInfo* info); 618 explicit Parser(CompilationInfo* info);
595 ~Parser() { 619 ~Parser() {
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 Scanner::Location pending_error_location_; 844 Scanner::Location pending_error_location_;
821 const char* pending_error_message_; 845 const char* pending_error_message_;
822 const AstRawString* pending_error_arg_; 846 const AstRawString* pending_error_arg_;
823 const char* pending_error_char_arg_; 847 const char* pending_error_char_arg_;
824 bool pending_error_is_reference_error_; 848 bool pending_error_is_reference_error_;
825 849
826 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; 850 int use_counts_[v8::Isolate::kUseCounterFeatureCount];
827 }; 851 };
828 852
829 853
854 bool ParserTraits::IsFutureStrictReserved(
855 const AstRawString* identifier) const {
856 return identifier->IsOneByteEqualTo("yield") ||
857 parser_->scanner()->IdentifierIsFutureStrictReserved(identifier);
858 }
859
860
861 Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type) {
862 return parser_->NewScope(parent_scope, scope_type);
863 }
864
865
866 const AstRawString* ParserTraits::EmptyIdentifierString() {
867 return parser_->ast_value_factory_->empty_string();
868 }
869
870
871 void ParserTraits::SkipLazyFunctionBody(const AstRawString* function_name,
872 int* materialized_literal_count,
873 int* expected_property_count,
874 bool* ok) {
875 return parser_->SkipLazyFunctionBody(
876 function_name, materialized_literal_count, expected_property_count, ok);
877 }
878
879
880 ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody(
881 const AstRawString* name, int pos, Variable* fvar,
882 Token::Value fvar_init_op, bool is_generator, bool* ok) {
883 return parser_->ParseEagerFunctionBody(name, pos, fvar, fvar_init_op,
884 is_generator, ok);
885 }
886
887 void ParserTraits::CheckConflictingVarDeclarations(v8::internal::Scope* scope,
888 bool* ok) {
889 parser_->CheckConflictingVarDeclarations(scope, ok);
890 }
891
892
893 AstValueFactory* ParserTraits::ast_value_factory() {
894 return parser_->ast_value_factory_;
895 }
896
897
830 // Support for handling complex values (array and object literals) that 898 // Support for handling complex values (array and object literals) that
831 // can be fully handled at compile time. 899 // can be fully handled at compile time.
832 class CompileTimeValue: public AllStatic { 900 class CompileTimeValue: public AllStatic {
833 public: 901 public:
834 enum LiteralType { 902 enum LiteralType {
835 OBJECT_LITERAL_FAST_ELEMENTS, 903 OBJECT_LITERAL_FAST_ELEMENTS,
836 OBJECT_LITERAL_SLOW_ELEMENTS, 904 OBJECT_LITERAL_SLOW_ELEMENTS,
837 ARRAY_LITERAL 905 ARRAY_LITERAL
838 }; 906 };
839 907
(...skipping 11 matching lines...) Expand all
851 private: 919 private:
852 static const int kLiteralTypeSlot = 0; 920 static const int kLiteralTypeSlot = 0;
853 static const int kElementsSlot = 1; 921 static const int kElementsSlot = 1;
854 922
855 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 923 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
856 }; 924 };
857 925
858 } } // namespace v8::internal 926 } } // namespace v8::internal
859 927
860 #endif // V8_PARSER_H_ 928 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/messages.js ('k') | src/parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698