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