Chromium Code Reviews| 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 lengths_(8, zone), | |
| 601 expressions_(8, zone), | |
| 602 pos_(pos) {} | |
| 603 | |
| 604 const ZoneList<Expression*>* cooked() const { return &cooked_; } | |
| 605 const ZoneList<int>* lengths() const { return &lengths_; } | |
| 606 const ZoneList<Expression*>* expressions() const { return &expressions_; } | |
| 607 int position() const { return pos_; } | |
| 608 | |
| 609 void AddTemplateSpan(Literal* cooked, int end, Zone* zone) { | |
| 610 DCHECK_NOT_NULL(cooked); | |
| 611 cooked_.Add(cooked, zone); | |
| 612 lengths_.Add(end - cooked->position(), 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<int> lengths_; | |
| 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, bool tail); | |
| 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 | |
| 596 private: | 637 private: |
| 597 Parser* parser_; | 638 Parser* parser_; |
| 598 }; | 639 }; |
| 599 | 640 |
| 600 | 641 |
| 601 class Parser : public ParserBase<ParserTraits> { | 642 class Parser : public ParserBase<ParserTraits> { |
| 602 public: | 643 public: |
| 603 // 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 |
| 604 // 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 |
| 605 // the strings created by the Parser are internalized. | 646 // the strings created by the Parser are internalized. |
| (...skipping 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 820 | 861 |
| 821 // Consumes the ending }. | 862 // Consumes the ending }. |
| 822 ZoneList<Statement*>* ParseEagerFunctionBody( | 863 ZoneList<Statement*>* ParseEagerFunctionBody( |
| 823 const AstRawString* function_name, int pos, Variable* fvar, | 864 const AstRawString* function_name, int pos, Variable* fvar, |
| 824 Token::Value fvar_init_op, bool is_generator, bool* ok); | 865 Token::Value fvar_init_op, bool is_generator, bool* ok); |
| 825 | 866 |
| 826 void HandleSourceURLComments(); | 867 void HandleSourceURLComments(); |
| 827 | 868 |
| 828 void ThrowPendingError(); | 869 void ThrowPendingError(); |
| 829 | 870 |
| 871 TemplateLiteralState OpenTemplateLiteral(int pos); | |
| 872 void AddTemplateSpan(TemplateLiteralState* state, bool tail); | |
| 873 void AddTemplateExpression(TemplateLiteralState* state, | |
| 874 Expression* expression); | |
| 875 Expression* CloseTemplateLiteral(TemplateLiteralState* state, | |
| 876 int start, Expression* tag); | |
| 830 Scanner scanner_; | 877 Scanner scanner_; |
| 831 PreParser* reusable_preparser_; | 878 PreParser* reusable_preparser_; |
| 832 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 879 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
| 833 Target* target_stack_; // for break, continue statements | 880 Target* target_stack_; // for break, continue statements |
| 834 ParseData* cached_parse_data_; | 881 ParseData* cached_parse_data_; |
| 835 | 882 |
| 836 CompilationInfo* info_; | 883 CompilationInfo* info_; |
| 837 | 884 |
| 838 // Pending errors. | 885 // Pending errors. |
| 839 bool has_pending_error_; | 886 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(). | 966 // Get the elements array of a compile time value returned by GetValue(). |
| 920 static Handle<FixedArray> GetElements(Handle<FixedArray> value); | 967 static Handle<FixedArray> GetElements(Handle<FixedArray> value); |
| 921 | 968 |
| 922 private: | 969 private: |
| 923 static const int kLiteralTypeSlot = 0; | 970 static const int kLiteralTypeSlot = 0; |
| 924 static const int kElementsSlot = 1; | 971 static const int kElementsSlot = 1; |
| 925 | 972 |
| 926 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 973 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
| 927 }; | 974 }; |
| 928 | 975 |
| 976 ParserTraits::TemplateLiteralState ParserTraits::OpenTemplateLiteral(int pos) { | |
|
arv (Not doing code reviews)
2014/11/11 17:15:15
nit: 2 empty lines between functions
| |
| 977 return parser_->OpenTemplateLiteral(pos); | |
| 978 } | |
| 979 | |
| 980 void ParserTraits::AddTemplateSpan(TemplateLiteralState* state, bool tail) { | |
| 981 parser_->AddTemplateSpan(state, tail); | |
| 982 } | |
| 983 void ParserTraits::AddTemplateExpression(TemplateLiteralState* state, | |
| 984 Expression* expression) { | |
| 985 parser_->AddTemplateExpression(state, expression); | |
| 986 } | |
| 987 Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state, | |
| 988 int start, Expression* tag) { | |
| 989 return parser_->CloseTemplateLiteral(state, start, tag); | |
| 990 } | |
| 929 } } // namespace v8::internal | 991 } } // namespace v8::internal |
| 930 | 992 |
| 931 #endif // V8_PARSER_H_ | 993 #endif // V8_PARSER_H_ |
| OLD | NEW |