| 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 574 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 585 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); | 585 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); |
| 586 V8_INLINE void SkipLazyFunctionBody(const AstRawString* name, | 586 V8_INLINE void SkipLazyFunctionBody(const AstRawString* name, |
| 587 int* materialized_literal_count, | 587 int* materialized_literal_count, |
| 588 int* expected_property_count, bool* ok); | 588 int* expected_property_count, bool* ok); |
| 589 V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody( | 589 V8_INLINE ZoneList<Statement*>* ParseEagerFunctionBody( |
| 590 const AstRawString* name, int pos, Variable* fvar, | 590 const AstRawString* name, int pos, Variable* fvar, |
| 591 Token::Value fvar_init_op, bool is_generator, bool* ok); | 591 Token::Value fvar_init_op, bool is_generator, bool* ok); |
| 592 V8_INLINE void CheckConflictingVarDeclarations(v8::internal::Scope* scope, | 592 V8_INLINE void CheckConflictingVarDeclarations(v8::internal::Scope* scope, |
| 593 bool* ok); | 593 bool* ok); |
| 594 | 594 |
| 595 class TemplateLiteral : public ZoneObject { |
| 596 public: |
| 597 TemplateLiteral(Zone* zone, int pos) |
| 598 : cooked_(8, zone), |
| 599 raw_(8, zone), |
| 600 expressions_(8, zone), |
| 601 pos_(pos) {} |
| 602 |
| 603 const ZoneList<Expression*>* cooked() const { return &cooked_; } |
| 604 const ZoneList<Expression*>* raw() const { return &raw_; } |
| 605 const ZoneList<Expression*>* expressions() const { return &expressions_; } |
| 606 int position() const { return pos_; } |
| 607 |
| 608 void AddTemplateSpan(Literal* cooked, Literal* raw, Zone* zone) { |
| 609 DCHECK_NOT_NULL(cooked); |
| 610 DCHECK_NOT_NULL(raw); |
| 611 cooked_.Add(cooked, zone); |
| 612 raw_.Add(raw, zone); |
| 613 } |
| 614 |
| 615 void AddExpression(Expression* expression, Zone* zone) { |
| 616 DCHECK_NOT_NULL(expression); |
| 617 expressions_.Add(expression, zone); |
| 618 } |
| 619 |
| 620 private: |
| 621 ZoneList<Expression*> cooked_; |
| 622 ZoneList<Expression*> raw_; |
| 623 ZoneList<Expression*> expressions_; |
| 624 int pos_; |
| 625 }; |
| 626 |
| 627 typedef TemplateLiteral* TemplateLiteralState; |
| 628 |
| 629 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos); |
| 630 V8_INLINE void AddTemplateSpan(TemplateLiteralState* state); |
| 631 V8_INLINE void AddTemplateExpression(TemplateLiteralState* state, |
| 632 Expression* expression); |
| 633 V8_INLINE Expression* CloseTemplateLiteral(TemplateLiteralState* state, |
| 634 int start, Expression* tag); |
| 635 V8_INLINE Expression* NoTemplateTag() { return NULL; } |
| 636 |
| 595 private: | 637 private: |
| 596 Parser* parser_; | 638 Parser* parser_; |
| 597 }; | 639 }; |
| 598 | 640 |
| 599 | 641 |
| 600 class Parser : public ParserBase<ParserTraits> { | 642 class Parser : public ParserBase<ParserTraits> { |
| 601 public: | 643 public: |
| 602 // Note that the hash seed in ParseInfo must be the hash seed from the | 644 // Note that the hash seed in ParseInfo must be the hash seed from the |
| 603 // Isolate's heap, otherwise the heap will be in an inconsistent state once | 645 // Isolate's heap, otherwise the heap will be in an inconsistent state once |
| 604 // the strings created by the Parser are internalized. | 646 // the strings created by the Parser are internalized. |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 816 | 858 |
| 817 // Consumes the ending }. | 859 // Consumes the ending }. |
| 818 ZoneList<Statement*>* ParseEagerFunctionBody( | 860 ZoneList<Statement*>* ParseEagerFunctionBody( |
| 819 const AstRawString* function_name, int pos, Variable* fvar, | 861 const AstRawString* function_name, int pos, Variable* fvar, |
| 820 Token::Value fvar_init_op, bool is_generator, bool* ok); | 862 Token::Value fvar_init_op, bool is_generator, bool* ok); |
| 821 | 863 |
| 822 void HandleSourceURLComments(); | 864 void HandleSourceURLComments(); |
| 823 | 865 |
| 824 void ThrowPendingError(); | 866 void ThrowPendingError(); |
| 825 | 867 |
| 868 TemplateLiteralState OpenTemplateLiteral(int pos); |
| 869 void AddTemplateSpan(TemplateLiteralState* state); |
| 870 void AddTemplateExpression(TemplateLiteralState* state, |
| 871 Expression* expression); |
| 872 Expression* CloseTemplateLiteral(TemplateLiteralState* state, |
| 873 int start, Expression* tag); |
| 826 Scanner scanner_; | 874 Scanner scanner_; |
| 827 PreParser* reusable_preparser_; | 875 PreParser* reusable_preparser_; |
| 828 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 876 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
| 829 Target* target_stack_; // for break, continue statements | 877 Target* target_stack_; // for break, continue statements |
| 830 ParseData* cached_parse_data_; | 878 ParseData* cached_parse_data_; |
| 831 | 879 |
| 832 CompilationInfo* info_; | 880 CompilationInfo* info_; |
| 833 | 881 |
| 834 // Pending errors. | 882 // Pending errors. |
| 835 bool has_pending_error_; | 883 bool has_pending_error_; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 915 // Get the elements array of a compile time value returned by GetValue(). | 963 // Get the elements array of a compile time value returned by GetValue(). |
| 916 static Handle<FixedArray> GetElements(Handle<FixedArray> value); | 964 static Handle<FixedArray> GetElements(Handle<FixedArray> value); |
| 917 | 965 |
| 918 private: | 966 private: |
| 919 static const int kLiteralTypeSlot = 0; | 967 static const int kLiteralTypeSlot = 0; |
| 920 static const int kElementsSlot = 1; | 968 static const int kElementsSlot = 1; |
| 921 | 969 |
| 922 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 970 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 923 }; | 971 }; |
| 924 | 972 |
| 973 ParserTraits::TemplateLiteralState ParserTraits::OpenTemplateLiteral(int pos) { |
| 974 return parser_->OpenTemplateLiteral(pos); |
| 975 } |
| 976 |
| 977 void ParserTraits::AddTemplateSpan(TemplateLiteralState* state) { |
| 978 parser_->AddTemplateSpan(state); |
| 979 } |
| 980 void ParserTraits::AddTemplateExpression(TemplateLiteralState* state, |
| 981 Expression* expression) { |
| 982 parser_->AddTemplateExpression(state, expression); |
| 983 } |
| 984 Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state, |
| 985 int start, Expression* tag) { |
| 986 return parser_->CloseTemplateLiteral(state, start, tag); |
| 987 } |
| 925 } } // namespace v8::internal | 988 } } // namespace v8::internal |
| 926 | 989 |
| 927 #endif // V8_PARSER_H_ | 990 #endif // V8_PARSER_H_ |
| OLD | NEW |