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 Vector<VariableProxy*> ParameterListFromExpression(Expression* expression, |
| 554 bool* ok); |
| 555 V8_INLINE AstValueFactory* ast_value_factory(); |
540 | 556 |
541 // Temporary glue; these functions will move to ParserBase. | 557 // Temporary glue; these functions will move to ParserBase. |
542 Expression* ParseV8Intrinsic(bool* ok); | 558 Expression* ParseV8Intrinsic(bool* ok); |
543 FunctionLiteral* ParseFunctionLiteral( | 559 FunctionLiteral* ParseFunctionLiteral( |
544 const AstRawString* name, | 560 const AstRawString* name, |
545 Scanner::Location function_name_location, | 561 Scanner::Location function_name_location, |
546 bool name_is_strict_reserved, | 562 bool name_is_strict_reserved, |
547 bool is_generator, | 563 bool is_generator, |
548 int function_token_position, | 564 int function_token_position, |
549 FunctionLiteral::FunctionType type, | 565 FunctionLiteral::FunctionType type, |
550 FunctionLiteral::ArityRestriction arity_restriction, | 566 FunctionLiteral::ArityRestriction arity_restriction, |
551 bool* ok); | 567 bool* ok); |
| 568 V8_INLINE void SkipLazyFunctionBody(const AstRawString* name, |
| 569 int* materialized_literal_count, |
| 570 int* expected_property_count, bool* ok); |
| 571 V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody( |
| 572 const AstRawString* name, int pos, Variable* fvar, |
| 573 Token::Value fvar_init_op, bool is_generator, bool* ok); |
| 574 V8_INLINE void CheckConflictingVarDeclarations(v8::internal::Scope* scope, |
| 575 bool* ok); |
552 | 576 |
553 private: | 577 private: |
554 Parser* parser_; | 578 Parser* parser_; |
555 }; | 579 }; |
556 | 580 |
557 | 581 |
558 class Parser : public ParserBase<ParserTraits> { | 582 class Parser : public ParserBase<ParserTraits> { |
559 public: | 583 public: |
560 explicit Parser(CompilationInfo* info); | 584 explicit Parser(CompilationInfo* info); |
561 ~Parser() { | 585 ~Parser() { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 Scanner::Location pending_error_location_; | 799 Scanner::Location pending_error_location_; |
776 const char* pending_error_message_; | 800 const char* pending_error_message_; |
777 const AstRawString* pending_error_arg_; | 801 const AstRawString* pending_error_arg_; |
778 const char* pending_error_char_arg_; | 802 const char* pending_error_char_arg_; |
779 bool pending_error_is_reference_error_; | 803 bool pending_error_is_reference_error_; |
780 | 804 |
781 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; | 805 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; |
782 }; | 806 }; |
783 | 807 |
784 | 808 |
| 809 bool ParserTraits::IsFutureStrictReserved( |
| 810 const AstRawString* identifier) const { |
| 811 return identifier->IsOneByteEqualTo("yield") || |
| 812 parser_->scanner()->IdentifierIsFutureStrictReserved(identifier); |
| 813 } |
| 814 |
| 815 |
| 816 Scope* ParserTraits::NewScope(Scope* parent_scope, ScopeType scope_type) { |
| 817 return parser_->NewScope(parent_scope, scope_type); |
| 818 } |
| 819 |
| 820 |
| 821 const AstRawString* ParserTraits::EmptyIdentifierString() { |
| 822 return parser_->ast_value_factory_->empty_string(); |
| 823 } |
| 824 |
| 825 |
| 826 void ParserTraits::SkipLazyFunctionBody(const AstRawString* function_name, |
| 827 int* materialized_literal_count, |
| 828 int* expected_property_count, |
| 829 bool* ok) { |
| 830 return parser_->SkipLazyFunctionBody( |
| 831 function_name, materialized_literal_count, expected_property_count, ok); |
| 832 } |
| 833 |
| 834 |
| 835 ZoneList<Statement*>* ParserTraits::ParseEagerFunctionBody( |
| 836 const AstRawString* name, int pos, Variable* fvar, |
| 837 Token::Value fvar_init_op, bool is_generator, bool* ok) { |
| 838 return parser_->ParseEagerFunctionBody(name, pos, fvar, fvar_init_op, |
| 839 is_generator, ok); |
| 840 } |
| 841 |
| 842 void ParserTraits::CheckConflictingVarDeclarations(v8::internal::Scope* scope, |
| 843 bool* ok) { |
| 844 parser_->CheckConflictingVarDeclarations(scope, ok); |
| 845 } |
| 846 |
| 847 |
| 848 AstValueFactory* ParserTraits::ast_value_factory() { |
| 849 return parser_->ast_value_factory_; |
| 850 } |
| 851 |
| 852 |
785 // Support for handling complex values (array and object literals) that | 853 // Support for handling complex values (array and object literals) that |
786 // can be fully handled at compile time. | 854 // can be fully handled at compile time. |
787 class CompileTimeValue: public AllStatic { | 855 class CompileTimeValue: public AllStatic { |
788 public: | 856 public: |
789 enum LiteralType { | 857 enum LiteralType { |
790 OBJECT_LITERAL_FAST_ELEMENTS, | 858 OBJECT_LITERAL_FAST_ELEMENTS, |
791 OBJECT_LITERAL_SLOW_ELEMENTS, | 859 OBJECT_LITERAL_SLOW_ELEMENTS, |
792 ARRAY_LITERAL | 860 ARRAY_LITERAL |
793 }; | 861 }; |
794 | 862 |
(...skipping 11 matching lines...) Expand all Loading... |
806 private: | 874 private: |
807 static const int kLiteralTypeSlot = 0; | 875 static const int kLiteralTypeSlot = 0; |
808 static const int kElementsSlot = 1; | 876 static const int kElementsSlot = 1; |
809 | 877 |
810 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 878 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
811 }; | 879 }; |
812 | 880 |
813 } } // namespace v8::internal | 881 } } // namespace v8::internal |
814 | 882 |
815 #endif // V8_PARSER_H_ | 883 #endif // V8_PARSER_H_ |
OLD | NEW |