| 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; | |
| 389 typedef Variable GeneratorVariable; | 388 typedef Variable GeneratorVariable; |
| 390 typedef v8::internal::Zone Zone; | 389 typedef v8::internal::Zone Zone; |
| 391 | 390 |
| 392 typedef v8::internal::AstProperties AstProperties; | |
| 393 typedef Vector<VariableProxy*> ParameterIdentifierVector; | |
| 394 | |
| 395 // Return types for traversing functions. | 391 // Return types for traversing functions. |
| 396 typedef const AstRawString* Identifier; | 392 typedef const AstRawString* Identifier; |
| 397 typedef v8::internal::Expression* Expression; | 393 typedef v8::internal::Expression* Expression; |
| 398 typedef Yield* YieldExpression; | 394 typedef Yield* YieldExpression; |
| 399 typedef v8::internal::FunctionLiteral* FunctionLiteral; | 395 typedef v8::internal::FunctionLiteral* FunctionLiteral; |
| 400 typedef v8::internal::Literal* Literal; | 396 typedef v8::internal::Literal* Literal; |
| 401 typedef ObjectLiteral::Property* ObjectLiteralProperty; | 397 typedef ObjectLiteral::Property* ObjectLiteralProperty; |
| 402 typedef ZoneList<v8::internal::Expression*>* ExpressionList; | 398 typedef ZoneList<v8::internal::Expression*>* ExpressionList; |
| 403 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; | 399 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; |
| 404 typedef ZoneList<v8::internal::Statement*>* StatementList; | 400 typedef ZoneList<v8::internal::Statement*>* StatementList; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 419 | 415 |
| 420 template<typename FunctionState> | 416 template<typename FunctionState> |
| 421 static void TearDownFunctionState(FunctionState* function_state, Zone* zone) { | 417 static void TearDownFunctionState(FunctionState* function_state, Zone* zone) { |
| 422 if (function_state->outer_function_state_ != NULL) { | 418 if (function_state->outer_function_state_ != NULL) { |
| 423 zone->isolate()->set_ast_node_id(function_state->saved_ast_node_id_); | 419 zone->isolate()->set_ast_node_id(function_state->saved_ast_node_id_); |
| 424 } | 420 } |
| 425 } | 421 } |
| 426 | 422 |
| 427 // Helper functions for recursive descent. | 423 // Helper functions for recursive descent. |
| 428 bool IsEvalOrArguments(const AstRawString* identifier) const; | 424 bool IsEvalOrArguments(const AstRawString* identifier) const; |
| 429 V8_INLINE bool IsFutureStrictReserved(const AstRawString* identifier) const; | |
| 430 | 425 |
| 431 // Returns true if the expression is of type "this.foo". | 426 // Returns true if the expression is of type "this.foo". |
| 432 static bool IsThisProperty(Expression* expression); | 427 static bool IsThisProperty(Expression* expression); |
| 433 | 428 |
| 434 static bool IsIdentifier(Expression* expression); | 429 static bool IsIdentifier(Expression* expression); |
| 435 | 430 |
| 436 static const AstRawString* AsIdentifier(Expression* expression) { | 431 static const AstRawString* AsIdentifier(Expression* expression) { |
| 437 ASSERT(IsIdentifier(expression)); | 432 ASSERT(IsIdentifier(expression)); |
| 438 return expression->AsVariableProxy()->raw_name(); | 433 return expression->AsVariableProxy()->raw_name(); |
| 439 } | 434 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 const AstRawString* arg, | 528 const AstRawString* arg, |
| 534 bool is_reference_error = false); | 529 bool is_reference_error = false); |
| 535 | 530 |
| 536 // "null" return type creators. | 531 // "null" return type creators. |
| 537 static const AstRawString* EmptyIdentifier() { | 532 static const AstRawString* EmptyIdentifier() { |
| 538 return NULL; | 533 return NULL; |
| 539 } | 534 } |
| 540 static Expression* EmptyExpression() { | 535 static Expression* EmptyExpression() { |
| 541 return NULL; | 536 return NULL; |
| 542 } | 537 } |
| 543 static Expression* EmptyArrowParamList() { return NULL; } | |
| 544 static Literal* EmptyLiteral() { | 538 static Literal* EmptyLiteral() { |
| 545 return NULL; | 539 return NULL; |
| 546 } | 540 } |
| 547 | |
| 548 // Used in error return values. | 541 // Used in error return values. |
| 549 static ZoneList<Expression*>* NullExpressionList() { | 542 static ZoneList<Expression*>* NullExpressionList() { |
| 550 return NULL; | 543 return NULL; |
| 551 } | 544 } |
| 552 | 545 |
| 553 // Non-NULL empty string. | |
| 554 V8_INLINE const AstRawString* EmptyIdentifierString(); | |
| 555 | |
| 556 // Odd-ball literal creators. | 546 // Odd-ball literal creators. |
| 557 Literal* GetLiteralTheHole(int position, | 547 Literal* GetLiteralTheHole(int position, |
| 558 AstNodeFactory<AstConstructionVisitor>* factory); | 548 AstNodeFactory<AstConstructionVisitor>* factory); |
| 559 | 549 |
| 560 // Producing data during the recursive descent. | 550 // Producing data during the recursive descent. |
| 561 const AstRawString* GetSymbol(Scanner* scanner); | 551 const AstRawString* GetSymbol(Scanner* scanner); |
| 562 const AstRawString* GetNextSymbol(Scanner* scanner); | 552 const AstRawString* GetNextSymbol(Scanner* scanner); |
| 563 | 553 |
| 564 Expression* ThisExpression(Scope* scope, | 554 Expression* ThisExpression(Scope* scope, |
| 565 AstNodeFactory<AstConstructionVisitor>* factory); | 555 AstNodeFactory<AstConstructionVisitor>* factory); |
| 566 Literal* ExpressionFromLiteral( | 556 Literal* ExpressionFromLiteral( |
| 567 Token::Value token, int pos, Scanner* scanner, | 557 Token::Value token, int pos, Scanner* scanner, |
| 568 AstNodeFactory<AstConstructionVisitor>* factory); | 558 AstNodeFactory<AstConstructionVisitor>* factory); |
| 569 Expression* ExpressionFromIdentifier( | 559 Expression* ExpressionFromIdentifier( |
| 570 const AstRawString* name, int pos, Scope* scope, | 560 const AstRawString* name, int pos, Scope* scope, |
| 571 AstNodeFactory<AstConstructionVisitor>* factory); | 561 AstNodeFactory<AstConstructionVisitor>* factory); |
| 572 Expression* ExpressionFromString( | 562 Expression* ExpressionFromString( |
| 573 int pos, Scanner* scanner, | 563 int pos, Scanner* scanner, |
| 574 AstNodeFactory<AstConstructionVisitor>* factory); | 564 AstNodeFactory<AstConstructionVisitor>* factory); |
| 575 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { | 565 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { |
| 576 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); | 566 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); |
| 577 } | 567 } |
| 578 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { | 568 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { |
| 579 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); | 569 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); |
| 580 } | 570 } |
| 581 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { | 571 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { |
| 582 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); | 572 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); |
| 583 } | 573 } |
| 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(); | |
| 590 | 574 |
| 591 // Temporary glue; these functions will move to ParserBase. | 575 // Temporary glue; these functions will move to ParserBase. |
| 592 Expression* ParseV8Intrinsic(bool* ok); | 576 Expression* ParseV8Intrinsic(bool* ok); |
| 593 FunctionLiteral* ParseFunctionLiteral( | 577 FunctionLiteral* ParseFunctionLiteral( |
| 594 const AstRawString* name, | 578 const AstRawString* name, |
| 595 Scanner::Location function_name_location, | 579 Scanner::Location function_name_location, |
| 596 bool name_is_strict_reserved, | 580 bool name_is_strict_reserved, |
| 597 bool is_generator, | 581 bool is_generator, |
| 598 int function_token_position, | 582 int function_token_position, |
| 599 FunctionLiteral::FunctionType type, | 583 FunctionLiteral::FunctionType type, |
| 600 FunctionLiteral::ArityRestriction arity_restriction, | 584 FunctionLiteral::ArityRestriction arity_restriction, |
| 601 bool* ok); | 585 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); | |
| 610 | 586 |
| 611 private: | 587 private: |
| 612 Parser* parser_; | 588 Parser* parser_; |
| 613 }; | 589 }; |
| 614 | 590 |
| 615 | 591 |
| 616 class Parser : public ParserBase<ParserTraits> { | 592 class Parser : public ParserBase<ParserTraits> { |
| 617 public: | 593 public: |
| 618 explicit Parser(CompilationInfo* info); | 594 explicit Parser(CompilationInfo* info); |
| 619 ~Parser() { | 595 ~Parser() { |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 844 Scanner::Location pending_error_location_; | 820 Scanner::Location pending_error_location_; |
| 845 const char* pending_error_message_; | 821 const char* pending_error_message_; |
| 846 const AstRawString* pending_error_arg_; | 822 const AstRawString* pending_error_arg_; |
| 847 const char* pending_error_char_arg_; | 823 const char* pending_error_char_arg_; |
| 848 bool pending_error_is_reference_error_; | 824 bool pending_error_is_reference_error_; |
| 849 | 825 |
| 850 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; | 826 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; |
| 851 }; | 827 }; |
| 852 | 828 |
| 853 | 829 |
| 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 | |
| 898 // Support for handling complex values (array and object literals) that | 830 // Support for handling complex values (array and object literals) that |
| 899 // can be fully handled at compile time. | 831 // can be fully handled at compile time. |
| 900 class CompileTimeValue: public AllStatic { | 832 class CompileTimeValue: public AllStatic { |
| 901 public: | 833 public: |
| 902 enum LiteralType { | 834 enum LiteralType { |
| 903 OBJECT_LITERAL_FAST_ELEMENTS, | 835 OBJECT_LITERAL_FAST_ELEMENTS, |
| 904 OBJECT_LITERAL_SLOW_ELEMENTS, | 836 OBJECT_LITERAL_SLOW_ELEMENTS, |
| 905 ARRAY_LITERAL | 837 ARRAY_LITERAL |
| 906 }; | 838 }; |
| 907 | 839 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 919 private: | 851 private: |
| 920 static const int kLiteralTypeSlot = 0; | 852 static const int kLiteralTypeSlot = 0; |
| 921 static const int kElementsSlot = 1; | 853 static const int kElementsSlot = 1; |
| 922 | 854 |
| 923 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 855 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 924 }; | 856 }; |
| 925 | 857 |
| 926 } } // namespace v8::internal | 858 } } // namespace v8::internal |
| 927 | 859 |
| 928 #endif // V8_PARSER_H_ | 860 #endif // V8_PARSER_H_ |
| OLD | NEW |