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 struct TemplateLiteralState { |
| 596 TemplateLiteralState() : spans_(NULL), expressions_(NULL) {} |
| 597 ZoneList<const AstTemplateSpan*>* spans_; |
| 598 ZoneList<Expression*>* expressions_; |
| 599 }; |
| 600 |
| 601 V8_INLINE TemplateLiteralState OpenTemplateLiteral() { |
| 602 return TemplateLiteralState(); |
| 603 } |
| 604 V8_INLINE void AddTemplateSpan(TemplateLiteralState* state); |
| 605 V8_INLINE void AddTemplateExpression(TemplateLiteralState* state, |
| 606 Expression* expression); |
| 607 V8_INLINE Expression* CloseTemplateLiteral(TemplateLiteralState* state, |
| 608 int pos); |
| 609 |
595 private: | 610 private: |
596 Parser* parser_; | 611 Parser* parser_; |
597 }; | 612 }; |
598 | 613 |
599 | 614 |
600 class Parser : public ParserBase<ParserTraits> { | 615 class Parser : public ParserBase<ParserTraits> { |
601 public: | 616 public: |
602 // Note that the hash seed in ParseInfo must be the hash seed from the | 617 // 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 | 618 // Isolate's heap, otherwise the heap will be in an inconsistent state once |
604 // the strings created by the Parser are internalized. | 619 // the strings created by the Parser are internalized. |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
816 | 831 |
817 // Consumes the ending }. | 832 // Consumes the ending }. |
818 ZoneList<Statement*>* ParseEagerFunctionBody( | 833 ZoneList<Statement*>* ParseEagerFunctionBody( |
819 const AstRawString* function_name, int pos, Variable* fvar, | 834 const AstRawString* function_name, int pos, Variable* fvar, |
820 Token::Value fvar_init_op, bool is_generator, bool* ok); | 835 Token::Value fvar_init_op, bool is_generator, bool* ok); |
821 | 836 |
822 void HandleSourceURLComments(); | 837 void HandleSourceURLComments(); |
823 | 838 |
824 void ThrowPendingError(); | 839 void ThrowPendingError(); |
825 | 840 |
| 841 void AddTemplateSpan(TemplateLiteralState* state); |
| 842 void AddTemplateExpression(TemplateLiteralState* state, |
| 843 Expression* expression); |
| 844 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int pos); |
| 845 |
826 Scanner scanner_; | 846 Scanner scanner_; |
827 PreParser* reusable_preparser_; | 847 PreParser* reusable_preparser_; |
828 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 848 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
829 Target* target_stack_; // for break, continue statements | 849 Target* target_stack_; // for break, continue statements |
830 ParseData* cached_parse_data_; | 850 ParseData* cached_parse_data_; |
831 | 851 |
832 CompilationInfo* info_; | 852 CompilationInfo* info_; |
833 | 853 |
834 // Pending errors. | 854 // Pending errors. |
835 bool has_pending_error_; | 855 bool has_pending_error_; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
916 // Get the elements array of a compile time value returned by GetValue(). | 936 // Get the elements array of a compile time value returned by GetValue(). |
917 static Handle<FixedArray> GetElements(Handle<FixedArray> value); | 937 static Handle<FixedArray> GetElements(Handle<FixedArray> value); |
918 | 938 |
919 private: | 939 private: |
920 static const int kLiteralTypeSlot = 0; | 940 static const int kLiteralTypeSlot = 0; |
921 static const int kElementsSlot = 1; | 941 static const int kElementsSlot = 1; |
922 | 942 |
923 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 943 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
924 }; | 944 }; |
925 | 945 |
| 946 void ParserTraits::AddTemplateSpan(TemplateLiteralState* state) { |
| 947 parser_->AddTemplateSpan(state); |
| 948 } |
| 949 void ParserTraits::AddTemplateExpression(TemplateLiteralState* state, |
| 950 Expression* expression) { |
| 951 parser_->AddTemplateExpression(state, expression); |
| 952 } |
| 953 Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state, |
| 954 int pos) { |
| 955 return parser_->CloseTemplateLiteral(state, pos); |
| 956 } |
926 } } // namespace v8::internal | 957 } } // namespace v8::internal |
927 | 958 |
928 #endif // V8_PARSER_H_ | 959 #endif // V8_PARSER_H_ |
OLD | NEW |