| 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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 | 344 |
| 345 class ParserTraits { | 345 class ParserTraits { |
| 346 public: | 346 public: |
| 347 struct Type { | 347 struct Type { |
| 348 // TODO(marja): To be removed. The Traits object should contain all the data | 348 // TODO(marja): To be removed. The Traits object should contain all the data |
| 349 // it needs. | 349 // it needs. |
| 350 typedef v8::internal::Parser* Parser; | 350 typedef v8::internal::Parser* Parser; |
| 351 | 351 |
| 352 // Used by FunctionState and BlockState. | 352 // Used by FunctionState and BlockState. |
| 353 typedef v8::internal::Scope Scope; | 353 typedef v8::internal::Scope Scope; |
| 354 typedef v8::internal::Scope* ScopePtr; |
| 354 typedef Variable GeneratorVariable; | 355 typedef Variable GeneratorVariable; |
| 355 typedef v8::internal::Zone Zone; | 356 typedef v8::internal::Zone Zone; |
| 356 | 357 |
| 358 typedef v8::internal::AstProperties AstProperties; |
| 359 typedef Vector<VariableProxy*> ParameterIdentifierVector; |
| 360 |
| 357 // Return types for traversing functions. | 361 // Return types for traversing functions. |
| 358 typedef const AstRawString* Identifier; | 362 typedef const AstRawString* Identifier; |
| 359 typedef v8::internal::Expression* Expression; | 363 typedef v8::internal::Expression* Expression; |
| 360 typedef Yield* YieldExpression; | 364 typedef Yield* YieldExpression; |
| 361 typedef v8::internal::FunctionLiteral* FunctionLiteral; | 365 typedef v8::internal::FunctionLiteral* FunctionLiteral; |
| 362 typedef v8::internal::Literal* Literal; | 366 typedef v8::internal::Literal* Literal; |
| 363 typedef ObjectLiteral::Property* ObjectLiteralProperty; | 367 typedef ObjectLiteral::Property* ObjectLiteralProperty; |
| 364 typedef ZoneList<v8::internal::Expression*>* ExpressionList; | 368 typedef ZoneList<v8::internal::Expression*>* ExpressionList; |
| 365 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; | 369 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; |
| 366 typedef ZoneList<v8::internal::Statement*>* StatementList; | 370 typedef ZoneList<v8::internal::Statement*>* StatementList; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 381 | 385 |
| 382 template<typename FunctionState> | 386 template<typename FunctionState> |
| 383 static void TearDownFunctionState(FunctionState* function_state, Zone* zone) { | 387 static void TearDownFunctionState(FunctionState* function_state, Zone* zone) { |
| 384 if (function_state->outer_function_state_ != NULL) { | 388 if (function_state->outer_function_state_ != NULL) { |
| 385 zone->isolate()->set_ast_node_id(function_state->saved_ast_node_id_); | 389 zone->isolate()->set_ast_node_id(function_state->saved_ast_node_id_); |
| 386 } | 390 } |
| 387 } | 391 } |
| 388 | 392 |
| 389 // Helper functions for recursive descent. | 393 // Helper functions for recursive descent. |
| 390 bool IsEvalOrArguments(const AstRawString* identifier) const; | 394 bool IsEvalOrArguments(const AstRawString* identifier) const; |
| 395 V8_INLINE bool IsFutureStrictReserved(const AstRawString* identifier) const; |
| 391 | 396 |
| 392 // Returns true if the expression is of type "this.foo". | 397 // Returns true if the expression is of type "this.foo". |
| 393 static bool IsThisProperty(Expression* expression); | 398 static bool IsThisProperty(Expression* expression); |
| 394 | 399 |
| 395 static bool IsIdentifier(Expression* expression); | 400 static bool IsIdentifier(Expression* expression); |
| 396 | 401 |
| 397 static const AstRawString* AsIdentifier(Expression* expression) { | 402 static const AstRawString* AsIdentifier(Expression* expression) { |
| 398 ASSERT(IsIdentifier(expression)); | 403 ASSERT(IsIdentifier(expression)); |
| 399 return expression->AsVariableProxy()->raw_name(); | 404 return expression->AsVariableProxy()->raw_name(); |
| 400 } | 405 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 const AstRawString* arg, | 499 const AstRawString* arg, |
| 495 bool is_reference_error = false); | 500 bool is_reference_error = false); |
| 496 | 501 |
| 497 // "null" return type creators. | 502 // "null" return type creators. |
| 498 static const AstRawString* EmptyIdentifier() { | 503 static const AstRawString* EmptyIdentifier() { |
| 499 return NULL; | 504 return NULL; |
| 500 } | 505 } |
| 501 static Expression* EmptyExpression() { | 506 static Expression* EmptyExpression() { |
| 502 return NULL; | 507 return NULL; |
| 503 } | 508 } |
| 509 static Expression* EmptyArrowParamList() { return NULL; } |
| 504 static Literal* EmptyLiteral() { | 510 static Literal* EmptyLiteral() { |
| 505 return NULL; | 511 return NULL; |
| 506 } | 512 } |
| 513 |
| 507 // Used in error return values. | 514 // Used in error return values. |
| 508 static ZoneList<Expression*>* NullExpressionList() { | 515 static ZoneList<Expression*>* NullExpressionList() { |
| 509 return NULL; | 516 return NULL; |
| 510 } | 517 } |
| 511 | 518 |
| 519 // Non-NULL empty string. |
| 520 V8_INLINE const AstRawString* EmptyIdentifierString(); |
| 521 |
| 512 // Odd-ball literal creators. | 522 // Odd-ball literal creators. |
| 513 Literal* GetLiteralTheHole(int position, | 523 Literal* GetLiteralTheHole(int position, |
| 514 AstNodeFactory<AstConstructionVisitor>* factory); | 524 AstNodeFactory<AstConstructionVisitor>* factory); |
| 515 | 525 |
| 516 // Producing data during the recursive descent. | 526 // Producing data during the recursive descent. |
| 517 const AstRawString* GetSymbol(Scanner* scanner); | 527 const AstRawString* GetSymbol(Scanner* scanner); |
| 518 const AstRawString* GetNextSymbol(Scanner* scanner); | 528 const AstRawString* GetNextSymbol(Scanner* scanner); |
| 519 | 529 |
| 520 Expression* ThisExpression(Scope* scope, | 530 Expression* ThisExpression(Scope* scope, |
| 521 AstNodeFactory<AstConstructionVisitor>* factory); | 531 AstNodeFactory<AstConstructionVisitor>* factory); |
| 522 Literal* ExpressionFromLiteral( | 532 Literal* ExpressionFromLiteral( |
| 523 Token::Value token, int pos, Scanner* scanner, | 533 Token::Value token, int pos, Scanner* scanner, |
| 524 AstNodeFactory<AstConstructionVisitor>* factory); | 534 AstNodeFactory<AstConstructionVisitor>* factory); |
| 525 Expression* ExpressionFromIdentifier( | 535 Expression* ExpressionFromIdentifier( |
| 526 const AstRawString* name, int pos, Scope* scope, | 536 const AstRawString* name, int pos, Scope* scope, |
| 527 AstNodeFactory<AstConstructionVisitor>* factory); | 537 AstNodeFactory<AstConstructionVisitor>* factory); |
| 528 Expression* ExpressionFromString( | 538 Expression* ExpressionFromString( |
| 529 int pos, Scanner* scanner, | 539 int pos, Scanner* scanner, |
| 530 AstNodeFactory<AstConstructionVisitor>* factory); | 540 AstNodeFactory<AstConstructionVisitor>* factory); |
| 531 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { | 541 ZoneList<v8::internal::Expression*>* NewExpressionList(int size, Zone* zone) { |
| 532 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); | 542 return new(zone) ZoneList<v8::internal::Expression*>(size, zone); |
| 533 } | 543 } |
| 534 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { | 544 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { |
| 535 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); | 545 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); |
| 536 } | 546 } |
| 537 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { | 547 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { |
| 538 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); | 548 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); |
| 539 } | 549 } |
| 550 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type); |
| 551 |
| 552 // Utility functions |
| 553 int DeclareArrowParametersFromExpression(Expression* expression, Scope* scope, |
| 554 Scanner::Location* dupe_loc, |
| 555 bool* ok); |
| 556 V8_INLINE AstValueFactory* ast_value_factory(); |
| 540 | 557 |
| 541 // Temporary glue; these functions will move to ParserBase. | 558 // Temporary glue; these functions will move to ParserBase. |
| 542 Expression* ParseV8Intrinsic(bool* ok); | 559 Expression* ParseV8Intrinsic(bool* ok); |
| 543 FunctionLiteral* ParseFunctionLiteral( | 560 FunctionLiteral* ParseFunctionLiteral( |
| 544 const AstRawString* name, | 561 const AstRawString* name, |
| 545 Scanner::Location function_name_location, | 562 Scanner::Location function_name_location, |
| 546 bool name_is_strict_reserved, | 563 bool name_is_strict_reserved, |
| 547 bool is_generator, | 564 bool is_generator, |
| 548 int function_token_position, | 565 int function_token_position, |
| 549 FunctionLiteral::FunctionType type, | 566 FunctionLiteral::FunctionType type, |
| 550 FunctionLiteral::ArityRestriction arity_restriction, | 567 FunctionLiteral::ArityRestriction arity_restriction, |
| 551 bool* ok); | 568 bool* ok); |
| 569 V8_INLINE void SkipLazyFunctionBody(const AstRawString* name, |
| 570 int* materialized_literal_count, |
| 571 int* expected_property_count, bool* ok); |
| 572 V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody( |
| 573 const AstRawString* name, int pos, Variable* fvar, |
| 574 Token::Value fvar_init_op, bool is_generator, bool* ok); |
| 575 V8_INLINE void CheckConflictingVarDeclarations(v8::internal::Scope* scope, |
| 576 bool* ok); |
| 552 | 577 |
| 553 private: | 578 private: |
| 554 Parser* parser_; | 579 Parser* parser_; |
| 555 }; | 580 }; |
| 556 | 581 |
| 557 | 582 |
| 558 class Parser : public ParserBase<ParserTraits> { | 583 class Parser : public ParserBase<ParserTraits> { |
| 559 public: | 584 public: |
| 560 explicit Parser(CompilationInfo* info); | 585 explicit Parser(CompilationInfo* info); |
| 561 ~Parser() { | 586 ~Parser() { |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 Scanner::Location pending_error_location_; | 800 Scanner::Location pending_error_location_; |
| 776 const char* pending_error_message_; | 801 const char* pending_error_message_; |
| 777 const AstRawString* pending_error_arg_; | 802 const AstRawString* pending_error_arg_; |
| 778 const char* pending_error_char_arg_; | 803 const char* pending_error_char_arg_; |
| 779 bool pending_error_is_reference_error_; | 804 bool pending_error_is_reference_error_; |
| 780 | 805 |
| 781 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; | 806 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; |
| 782 }; | 807 }; |
| 783 | 808 |
| 784 | 809 |
| 810 bool ParserTraits::IsFutureStrictReserved( |
| 811 const AstRawString* identifier) const { |
| 812 return identifier->IsOneByteEqualTo("yield") || |
| 813 parser_->scanner()->IdentifierIsFutureStrictReserved(identifier); |
| 814 } |
| 815 |
| 816 |
| 817 Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type) { |
| 818 return parser_->NewScope(parent_scope, scope_type); |
| 819 } |
| 820 |
| 821 |
| 822 const AstRawString* ParserTraits::EmptyIdentifierString() { |
| 823 return parser_->ast_value_factory_->empty_string(); |
| 824 } |
| 825 |
| 826 |
| 827 void ParserTraits::SkipLazyFunctionBody(const AstRawString* function_name, |
| 828 int* materialized_literal_count, |
| 829 int* expected_property_count, |
| 830 bool* ok) { |
| 831 return parser_->SkipLazyFunctionBody( |
| 832 function_name, materialized_literal_count, expected_property_count, ok); |
| 833 } |
| 834 |
| 835 |
| 836 ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody( |
| 837 const AstRawString* name, int pos, Variable* fvar, |
| 838 Token::Value fvar_init_op, bool is_generator, bool* ok) { |
| 839 return parser_->ParseEagerFunctionBody(name, pos, fvar, fvar_init_op, |
| 840 is_generator, ok); |
| 841 } |
| 842 |
| 843 void ParserTraits::CheckConflictingVarDeclarations(v8::internal::Scope* scope, |
| 844 bool* ok) { |
| 845 parser_->CheckConflictingVarDeclarations(scope, ok); |
| 846 } |
| 847 |
| 848 |
| 849 AstValueFactory* ParserTraits::ast_value_factory() { |
| 850 return parser_->ast_value_factory_; |
| 851 } |
| 852 |
| 853 |
| 785 // Support for handling complex values (array and object literals) that | 854 // Support for handling complex values (array and object literals) that |
| 786 // can be fully handled at compile time. | 855 // can be fully handled at compile time. |
| 787 class CompileTimeValue: public AllStatic { | 856 class CompileTimeValue: public AllStatic { |
| 788 public: | 857 public: |
| 789 enum LiteralType { | 858 enum LiteralType { |
| 790 OBJECT_LITERAL_FAST_ELEMENTS, | 859 OBJECT_LITERAL_FAST_ELEMENTS, |
| 791 OBJECT_LITERAL_SLOW_ELEMENTS, | 860 OBJECT_LITERAL_SLOW_ELEMENTS, |
| 792 ARRAY_LITERAL | 861 ARRAY_LITERAL |
| 793 }; | 862 }; |
| 794 | 863 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 806 private: | 875 private: |
| 807 static const int kLiteralTypeSlot = 0; | 876 static const int kLiteralTypeSlot = 0; |
| 808 static const int kElementsSlot = 1; | 877 static const int kElementsSlot = 1; |
| 809 | 878 |
| 810 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 879 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 811 }; | 880 }; |
| 812 | 881 |
| 813 } } // namespace v8::internal | 882 } } // namespace v8::internal |
| 814 | 883 |
| 815 #endif // V8_PARSER_H_ | 884 #endif // V8_PARSER_H_ |
| OLD | NEW |