| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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() { |
| 544 return NULL; |
| 545 } |
| 538 static Literal* EmptyLiteral() { | 546 static Literal* EmptyLiteral() { |
| 539 return NULL; | 547 return NULL; |
| 540 } | 548 } |
| 549 |
| 541 // Used in error return values. | 550 // Used in error return values. |
| 542 static ZoneList<Expression*>* NullExpressionList() { | 551 static ZoneList<Expression*>* NullExpressionList() { |
| 543 return NULL; | 552 return NULL; |
| 544 } | 553 } |
| 545 | 554 |
| 555 // Non-NULL empty string. |
| 556 V8_INLINE const AstRawString* EmptyIdentifierString(); |
| 557 |
| 546 // Odd-ball literal creators. | 558 // Odd-ball literal creators. |
| 547 Literal* GetLiteralTheHole(int position, | 559 Literal* GetLiteralTheHole(int position, |
| 548 AstNodeFactory<AstConstructionVisitor>* factory); | 560 AstNodeFactory<AstConstructionVisitor>* factory); |
| 549 | 561 |
| 550 // Producing data during the recursive descent. | 562 // Producing data during the recursive descent. |
| 551 const AstRawString* GetSymbol(Scanner* scanner); | 563 const AstRawString* GetSymbol(Scanner* scanner); |
| 552 const AstRawString* GetNextSymbol(Scanner* scanner); | 564 const AstRawString* GetNextSymbol(Scanner* scanner); |
| 553 | 565 |
| 554 Expression* ThisExpression(Scope* scope, | 566 Expression* ThisExpression(Scope* scope, |
| 555 AstNodeFactory<AstConstructionVisitor>* factory); | 567 AstNodeFactory<AstConstructionVisitor>* factory); |
| 556 Literal* ExpressionFromLiteral( | 568 Literal* ExpressionFromLiteral( |
| 557 Token::Value token, int pos, Scanner* scanner, | 569 Token::Value token, int pos, Scanner* scanner, |
| 558 AstNodeFactory<AstConstructionVisitor>* factory); | 570 AstNodeFactory<AstConstructionVisitor>* factory); |
| 559 Expression* ExpressionFromIdentifier( | 571 Expression* ExpressionFromIdentifier( |
| 560 const AstRawString* name, int pos, Scope* scope, | 572 const AstRawString* name, int pos, Scope* scope, |
| 561 AstNodeFactory<AstConstructionVisitor>* factory); | 573 AstNodeFactory<AstConstructionVisitor>* factory); |
| 562 Expression* ExpressionFromString( | 574 Expression* ExpressionFromString( |
| 563 int pos, Scanner* scanner, | 575 int pos, Scanner* scanner, |
| 564 AstNodeFactory<AstConstructionVisitor>* factory); | 576 AstNodeFactory<AstConstructionVisitor>* factory); |
| 565 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { | 577 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { |
| 566 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); | 578 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); |
| 567 } | 579 } |
| 568 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { | 580 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { |
| 569 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); | 581 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); |
| 570 } | 582 } |
| 571 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { | 583 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { |
| 572 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); | 584 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); |
| 573 } | 585 } |
| 586 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type); |
| 587 |
| 588 // Utility functions |
| 589 Vector<VariableProxy*> ParameterListFromExpression( |
| 590 Expression* expression, bool* ok); |
| 591 V8_INLINE AstValueFactory* ast_value_factory(); |
| 574 | 592 |
| 575 // Temporary glue; these functions will move to ParserBase. | 593 // Temporary glue; these functions will move to ParserBase. |
| 576 Expression* ParseV8Intrinsic(bool* ok); | 594 Expression* ParseV8Intrinsic(bool* ok); |
| 577 FunctionLiteral* ParseFunctionLiteral( | 595 FunctionLiteral* ParseFunctionLiteral( |
| 578 const AstRawString* name, | 596 const AstRawString* name, |
| 579 Scanner::Location function_name_location, | 597 Scanner::Location function_name_location, |
| 580 bool name_is_strict_reserved, | 598 bool name_is_strict_reserved, |
| 581 bool is_generator, | 599 bool is_generator, |
| 582 int function_token_position, | 600 int function_token_position, |
| 583 FunctionLiteral::FunctionType type, | 601 FunctionLiteral::FunctionType type, |
| 584 FunctionLiteral::ArityRestriction arity_restriction, | 602 FunctionLiteral::ArityRestriction arity_restriction, |
| 585 bool* ok); | 603 bool* ok); |
| 604 V8_INLINE void SkipLazyFunctionBody( |
| 605 const AstRawString* name, |
| 606 int* materialized_literal_count, |
| 607 int* expected_property_count, |
| 608 bool* ok); |
| 609 V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody( |
| 610 const AstRawString* name, |
| 611 int pos, |
| 612 Variable* fvar, |
| 613 Token::Value fvar_init_op, |
| 614 bool is_generator, |
| 615 bool* ok); |
| 616 V8_INLINE void CheckConflictingVarDeclarations( |
| 617 v8::internal::Scope* scope, |
| 618 bool* ok); |
| 586 | 619 |
| 587 private: | 620 private: |
| 588 Parser* parser_; | 621 Parser* parser_; |
| 589 }; | 622 }; |
| 590 | 623 |
| 591 | 624 |
| 592 class Parser : public ParserBase<ParserTraits> { | 625 class Parser : public ParserBase<ParserTraits> { |
| 593 public: | 626 public: |
| 594 explicit Parser(CompilationInfo* info); | 627 explicit Parser(CompilationInfo* info); |
| 595 ~Parser() { | 628 ~Parser() { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 Scanner::Location pending_error_location_; | 853 Scanner::Location pending_error_location_; |
| 821 const char* pending_error_message_; | 854 const char* pending_error_message_; |
| 822 const AstRawString* pending_error_arg_; | 855 const AstRawString* pending_error_arg_; |
| 823 const char* pending_error_char_arg_; | 856 const char* pending_error_char_arg_; |
| 824 bool pending_error_is_reference_error_; | 857 bool pending_error_is_reference_error_; |
| 825 | 858 |
| 826 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; | 859 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; |
| 827 }; | 860 }; |
| 828 | 861 |
| 829 | 862 |
| 863 bool ParserTraits::IsFutureStrictReserved( |
| 864 const AstRawString* identifier) const { |
| 865 return identifier->IsOneByteEqualTo("yield") || |
| 866 parser_->scanner()->IdentifierIsFutureStrictReserved(identifier); |
| 867 } |
| 868 |
| 869 |
| 870 Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type) { |
| 871 return parser_->NewScope(parent_scope, scope_type); |
| 872 } |
| 873 |
| 874 |
| 875 const AstRawString* ParserTraits::EmptyIdentifierString() { |
| 876 return parser_->ast_value_factory_->empty_string(); |
| 877 } |
| 878 |
| 879 |
| 880 void ParserTraits::SkipLazyFunctionBody( |
| 881 const AstRawString* function_name, |
| 882 int* materialized_literal_count, |
| 883 int* expected_property_count, |
| 884 bool* ok) { |
| 885 return parser_->SkipLazyFunctionBody(function_name, |
| 886 materialized_literal_count, expected_property_count, ok); |
| 887 } |
| 888 |
| 889 |
| 890 ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody( |
| 891 const AstRawString* name, |
| 892 int pos, |
| 893 Variable* fvar, |
| 894 Token::Value fvar_init_op, |
| 895 bool is_generator, |
| 896 bool* ok) { |
| 897 return parser_->ParseEagerFunctionBody(name, pos, |
| 898 fvar, fvar_init_op, is_generator, ok); |
| 899 } |
| 900 |
| 901 void ParserTraits::CheckConflictingVarDeclarations( |
| 902 v8::internal::Scope* scope, bool* ok) { |
| 903 parser_->CheckConflictingVarDeclarations(scope, ok); |
| 904 } |
| 905 |
| 906 |
| 907 AstValueFactory* ParserTraits::ast_value_factory() { |
| 908 return parser_->ast_value_factory_; |
| 909 } |
| 910 |
| 911 |
| 830 // Support for handling complex values (array and object literals) that | 912 // Support for handling complex values (array and object literals) that |
| 831 // can be fully handled at compile time. | 913 // can be fully handled at compile time. |
| 832 class CompileTimeValue: public AllStatic { | 914 class CompileTimeValue: public AllStatic { |
| 833 public: | 915 public: |
| 834 enum LiteralType { | 916 enum LiteralType { |
| 835 OBJECT_LITERAL_FAST_ELEMENTS, | 917 OBJECT_LITERAL_FAST_ELEMENTS, |
| 836 OBJECT_LITERAL_SLOW_ELEMENTS, | 918 OBJECT_LITERAL_SLOW_ELEMENTS, |
| 837 ARRAY_LITERAL | 919 ARRAY_LITERAL |
| 838 }; | 920 }; |
| 839 | 921 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 851 private: | 933 private: |
| 852 static const int kLiteralTypeSlot = 0; | 934 static const int kLiteralTypeSlot = 0; |
| 853 static const int kElementsSlot = 1; | 935 static const int kElementsSlot = 1; |
| 854 | 936 |
| 855 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 937 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 856 }; | 938 }; |
| 857 | 939 |
| 858 } } // namespace v8::internal | 940 } } // namespace v8::internal |
| 859 | 941 |
| 860 #endif // V8_PARSER_H_ | 942 #endif // V8_PARSER_H_ |
| OLD | NEW |