Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(203)

Side by Side Diff: src/parser.h

Issue 663683006: Implement ES6 Template Literals (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Clang-formatted Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/messages.js ('k') | src/parser.cc » ('j') | src/parser.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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, int start,
876 Expression* tag);
877 ZoneList<Expression*>* TemplateRawStrings(const TemplateLiteral* lit);
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
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
978 ParserTraits::TemplateLiteralState ParserTraits::OpenTemplateLiteral(int pos) {
979 return parser_->OpenTemplateLiteral(pos);
980 }
981
982
983 void ParserTraits::AddTemplateSpan(TemplateLiteralState* state, bool tail) {
984 parser_->AddTemplateSpan(state, tail);
985 }
986
987
988 void ParserTraits::AddTemplateExpression(TemplateLiteralState* state,
989 Expression* expression) {
990 parser_->AddTemplateExpression(state, expression);
991 }
992
993
994 Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state,
995 int start, Expression* tag) {
996 return parser_->CloseTemplateLiteral(state, start, tag);
997 }
929 } } // namespace v8::internal 998 } } // namespace v8::internal
930 999
931 #endif // V8_PARSER_H_ 1000 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/messages.js ('k') | src/parser.cc » ('j') | src/parser.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698