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

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: Rebased against https://chromium.googlesource.com/v8/v8.git/master 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/preparser.h » ('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 568 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 Token::Value fvar_init_op, bool is_generator, bool* ok); 579 Token::Value fvar_init_op, bool is_generator, bool* ok);
580 580
581 ClassLiteral* ParseClassLiteral(const AstRawString* name, 581 ClassLiteral* ParseClassLiteral(const AstRawString* name,
582 Scanner::Location class_name_location, 582 Scanner::Location class_name_location,
583 bool name_is_strict_reserved, int pos, 583 bool name_is_strict_reserved, int pos,
584 bool* ok); 584 bool* ok);
585 585
586 V8_INLINE void CheckConflictingVarDeclarations(v8::internal::Scope* scope, 586 V8_INLINE void CheckConflictingVarDeclarations(v8::internal::Scope* scope,
587 bool* ok); 587 bool* ok);
588 588
589 class TemplateLiteral : public ZoneObject {
590 public:
591 TemplateLiteral(Zone* zone, int pos)
592 : cooked_(8, zone),
593 lengths_(8, zone),
594 expressions_(8, zone),
595 pos_(pos) {}
596
597 const ZoneList<Expression*>* cooked() const { return &cooked_; }
598 const ZoneList<int>* lengths() const { return &lengths_; }
599 const ZoneList<Expression*>* expressions() const { return &expressions_; }
600 int position() const { return pos_; }
601
602 void AddTemplateSpan(Literal* cooked, int end, Zone* zone) {
603 DCHECK_NOT_NULL(cooked);
604 cooked_.Add(cooked, zone);
605 lengths_.Add(end - cooked->position(), zone);
606 }
607
608 void AddExpression(Expression* expression, Zone* zone) {
609 DCHECK_NOT_NULL(expression);
610 expressions_.Add(expression, zone);
611 }
612
613 private:
614 ZoneList<Expression*> cooked_;
615 ZoneList<int> lengths_;
616 ZoneList<Expression*> expressions_;
617 int pos_;
618 };
619
620 typedef TemplateLiteral* TemplateLiteralState;
621
622 V8_INLINE TemplateLiteralState OpenTemplateLiteral(int pos);
623 V8_INLINE void AddTemplateSpan(TemplateLiteralState* state, bool tail);
624 V8_INLINE void AddTemplateExpression(TemplateLiteralState* state,
625 Expression* expression);
626 V8_INLINE Expression* CloseTemplateLiteral(TemplateLiteralState* state,
627 int start, Expression* tag);
628 V8_INLINE Expression* NoTemplateTag() { return NULL; }
629
589 private: 630 private:
590 Parser* parser_; 631 Parser* parser_;
591 }; 632 };
592 633
593 634
594 class Parser : public ParserBase<ParserTraits> { 635 class Parser : public ParserBase<ParserTraits> {
595 public: 636 public:
596 // Note that the hash seed in ParseInfo must be the hash seed from the 637 // Note that the hash seed in ParseInfo must be the hash seed from the
597 // Isolate's heap, otherwise the heap will be in an inconsistent state once 638 // Isolate's heap, otherwise the heap will be in an inconsistent state once
598 // the strings created by the Parser are internalized. 639 // the strings created by the Parser are internalized.
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
819 860
820 // Consumes the ending }. 861 // Consumes the ending }.
821 ZoneList<Statement*>* ParseEagerFunctionBody( 862 ZoneList<Statement*>* ParseEagerFunctionBody(
822 const AstRawString* function_name, int pos, Variable* fvar, 863 const AstRawString* function_name, int pos, Variable* fvar,
823 Token::Value fvar_init_op, bool is_generator, bool* ok); 864 Token::Value fvar_init_op, bool is_generator, bool* ok);
824 865
825 void HandleSourceURLComments(); 866 void HandleSourceURLComments();
826 867
827 void ThrowPendingError(); 868 void ThrowPendingError();
828 869
870 TemplateLiteralState OpenTemplateLiteral(int pos);
871 void AddTemplateSpan(TemplateLiteralState* state, bool tail);
872 void AddTemplateExpression(TemplateLiteralState* state,
873 Expression* expression);
874 Expression* CloseTemplateLiteral(TemplateLiteralState* state, int start,
875 Expression* tag);
876 ZoneList<Expression*>* TemplateRawStrings(const TemplateLiteral* lit);
829 Scanner scanner_; 877 Scanner scanner_;
830 PreParser* reusable_preparser_; 878 PreParser* reusable_preparser_;
831 Scope* original_scope_; // for ES5 function declarations in sloppy eval 879 Scope* original_scope_; // for ES5 function declarations in sloppy eval
832 Target* target_stack_; // for break, continue statements 880 Target* target_stack_; // for break, continue statements
833 ParseData* cached_parse_data_; 881 ParseData* cached_parse_data_;
834 882
835 CompilationInfo* info_; 883 CompilationInfo* info_;
836 884
837 // Pending errors. 885 // Pending errors.
838 bool has_pending_error_; 886 bool has_pending_error_;
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
918 // 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().
919 static Handle<FixedArray> GetElements(Handle<FixedArray> value); 967 static Handle<FixedArray> GetElements(Handle<FixedArray> value);
920 968
921 private: 969 private:
922 static const int kLiteralTypeSlot = 0; 970 static const int kLiteralTypeSlot = 0;
923 static const int kElementsSlot = 1; 971 static const int kElementsSlot = 1;
924 972
925 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); 973 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue);
926 }; 974 };
927 975
976
977 ParserTraits::TemplateLiteralState ParserTraits::OpenTemplateLiteral(int pos) {
978 return parser_->OpenTemplateLiteral(pos);
979 }
980
981
982 void ParserTraits::AddTemplateSpan(TemplateLiteralState* state, bool tail) {
983 parser_->AddTemplateSpan(state, tail);
984 }
985
986
987 void ParserTraits::AddTemplateExpression(TemplateLiteralState* state,
988 Expression* expression) {
989 parser_->AddTemplateExpression(state, expression);
990 }
991
992
993 Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state,
994 int start, Expression* tag) {
995 return parser_->CloseTemplateLiteral(state, start, tag);
996 }
928 } } // namespace v8::internal 997 } } // namespace v8::internal
929 998
930 #endif // V8_PARSER_H_ 999 #endif // V8_PARSER_H_
OLDNEW
« no previous file with comments | « src/messages.js ('k') | src/parser.cc » ('j') | src/preparser.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698