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