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" // TODO(titzer): remove this include dependency | 10 #include "src/compiler.h" // TODO(titzer): remove this include dependency |
(...skipping 539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 // Return types for traversing functions. | 550 // Return types for traversing functions. |
551 typedef const AstRawString* Identifier; | 551 typedef const AstRawString* Identifier; |
552 typedef v8::internal::Expression* Expression; | 552 typedef v8::internal::Expression* Expression; |
553 typedef Yield* YieldExpression; | 553 typedef Yield* YieldExpression; |
554 typedef v8::internal::FunctionLiteral* FunctionLiteral; | 554 typedef v8::internal::FunctionLiteral* FunctionLiteral; |
555 typedef v8::internal::ClassLiteral* ClassLiteral; | 555 typedef v8::internal::ClassLiteral* ClassLiteral; |
556 typedef v8::internal::Literal* Literal; | 556 typedef v8::internal::Literal* Literal; |
557 typedef ObjectLiteral::Property* ObjectLiteralProperty; | 557 typedef ObjectLiteral::Property* ObjectLiteralProperty; |
558 typedef ZoneList<v8::internal::Expression*>* ExpressionList; | 558 typedef ZoneList<v8::internal::Expression*>* ExpressionList; |
559 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; | 559 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; |
| 560 typedef const v8::internal::AstRawString* FormalParameter; |
560 typedef ZoneList<v8::internal::Statement*>* StatementList; | 561 typedef ZoneList<v8::internal::Statement*>* StatementList; |
561 | 562 |
562 // For constructing objects returned by the traversing functions. | 563 // For constructing objects returned by the traversing functions. |
563 typedef AstNodeFactory Factory; | 564 typedef AstNodeFactory Factory; |
564 }; | 565 }; |
565 | 566 |
566 explicit ParserTraits(Parser* parser) : parser_(parser) {} | 567 explicit ParserTraits(Parser* parser) : parser_(parser) {} |
567 | 568 |
568 // Helper functions for recursive descent. | 569 // Helper functions for recursive descent. |
569 bool IsEval(const AstRawString* identifier) const; | 570 bool IsEval(const AstRawString* identifier) const; |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
687 const AstRawString* arg, | 688 const AstRawString* arg, |
688 ParseErrorType error_type = kSyntaxError); | 689 ParseErrorType error_type = kSyntaxError); |
689 | 690 |
690 // "null" return type creators. | 691 // "null" return type creators. |
691 static const AstRawString* EmptyIdentifier() { | 692 static const AstRawString* EmptyIdentifier() { |
692 return NULL; | 693 return NULL; |
693 } | 694 } |
694 static Expression* EmptyExpression() { | 695 static Expression* EmptyExpression() { |
695 return NULL; | 696 return NULL; |
696 } | 697 } |
697 static Expression* EmptyArrowParamList() { return NULL; } | |
698 static Literal* EmptyLiteral() { | 698 static Literal* EmptyLiteral() { |
699 return NULL; | 699 return NULL; |
700 } | 700 } |
701 static ObjectLiteralProperty* EmptyObjectLiteralProperty() { return NULL; } | 701 static ObjectLiteralProperty* EmptyObjectLiteralProperty() { return NULL; } |
702 static FunctionLiteral* EmptyFunctionLiteral() { return NULL; } | 702 static FunctionLiteral* EmptyFunctionLiteral() { return NULL; } |
703 | 703 |
704 // Used in error return values. | 704 // Used in error return values. |
705 static ZoneList<Expression*>* NullExpressionList() { | 705 static ZoneList<Expression*>* NullExpressionList() { |
706 return NULL; | 706 return NULL; |
707 } | 707 } |
| 708 static const AstRawString* EmptyFormalParameter() { return NULL; } |
708 | 709 |
709 // Non-NULL empty string. | 710 // Non-NULL empty string. |
710 V8_INLINE const AstRawString* EmptyIdentifierString(); | 711 V8_INLINE const AstRawString* EmptyIdentifierString(); |
711 | 712 |
712 // Odd-ball literal creators. | 713 // Odd-ball literal creators. |
713 Literal* GetLiteralTheHole(int position, AstNodeFactory* factory); | 714 Literal* GetLiteralTheHole(int position, AstNodeFactory* factory); |
714 | 715 |
715 // Producing data during the recursive descent. | 716 // Producing data during the recursive descent. |
716 const AstRawString* GetSymbol(Scanner* scanner); | 717 const AstRawString* GetSymbol(Scanner* scanner); |
717 const AstRawString* GetNextSymbol(Scanner* scanner); | 718 const AstRawString* GetNextSymbol(Scanner* scanner); |
(...skipping 18 matching lines...) Expand all Loading... |
736 } | 737 } |
737 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { | 738 ZoneList<ObjectLiteral::Property*>* NewPropertyList(int size, Zone* zone) { |
738 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); | 739 return new(zone) ZoneList<ObjectLiteral::Property*>(size, zone); |
739 } | 740 } |
740 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { | 741 ZoneList<v8::internal::Statement*>* NewStatementList(int size, Zone* zone) { |
741 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); | 742 return new(zone) ZoneList<v8::internal::Statement*>(size, zone); |
742 } | 743 } |
743 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, | 744 V8_INLINE Scope* NewScope(Scope* parent_scope, ScopeType scope_type, |
744 FunctionKind kind = kNormalFunction); | 745 FunctionKind kind = kNormalFunction); |
745 | 746 |
746 // Utility functions | 747 void DeclareFormalParameter(Scope* scope, const AstRawString* name, |
747 int DeclareArrowParametersFromExpression(Expression* expression, Scope* scope, | 748 bool is_rest) { |
748 Scanner::Location* undefined_loc, | 749 Variable* var = scope->DeclareParameter(name, VAR, is_rest); |
749 Scanner::Location* dupe_loc, | 750 if (is_sloppy(scope->language_mode())) { |
750 bool* ok); | 751 // TODO(sigurds) Mark every parameter as maybe assigned. This is a |
| 752 // conservative approximation necessary to account for parameters |
| 753 // that are assigned via the arguments array. |
| 754 var->set_maybe_assigned(); |
| 755 } |
| 756 } |
| 757 |
| 758 void DeclareArrowFunctionParameters(Scope* scope, Expression* expr, |
| 759 const Scanner::Location& params_loc, |
| 760 FormalParameterErrorLocations* error_locs, |
| 761 bool* ok); |
| 762 void ParseArrowFunctionFormalParameters( |
| 763 Scope* scope, Expression* params, const Scanner::Location& params_loc, |
| 764 FormalParameterErrorLocations* error_locs, bool* is_rest, bool* ok); |
751 | 765 |
752 // Temporary glue; these functions will move to ParserBase. | 766 // Temporary glue; these functions will move to ParserBase. |
753 Expression* ParseV8Intrinsic(bool* ok); | 767 Expression* ParseV8Intrinsic(bool* ok); |
754 FunctionLiteral* ParseFunctionLiteral( | 768 FunctionLiteral* ParseFunctionLiteral( |
755 const AstRawString* name, Scanner::Location function_name_location, | 769 const AstRawString* name, Scanner::Location function_name_location, |
756 bool name_is_strict_reserved, FunctionKind kind, | 770 bool name_is_strict_reserved, FunctionKind kind, |
757 int function_token_position, FunctionLiteral::FunctionType type, | 771 int function_token_position, FunctionLiteral::FunctionType type, |
758 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); | 772 FunctionLiteral::ArityRestriction arity_restriction, bool* ok); |
759 V8_INLINE void SkipLazyFunctionBody(const AstRawString* name, | 773 V8_INLINE void SkipLazyFunctionBody(const AstRawString* name, |
760 int* materialized_literal_count, | 774 int* materialized_literal_count, |
(...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1038 Expression* SpreadCallNew(Expression* function, | 1052 Expression* SpreadCallNew(Expression* function, |
1039 ZoneList<v8::internal::Expression*>* args, int pos); | 1053 ZoneList<v8::internal::Expression*>* args, int pos); |
1040 | 1054 |
1041 Scanner scanner_; | 1055 Scanner scanner_; |
1042 PreParser* reusable_preparser_; | 1056 PreParser* reusable_preparser_; |
1043 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 1057 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
1044 Target* target_stack_; // for break, continue statements | 1058 Target* target_stack_; // for break, continue statements |
1045 ScriptCompiler::CompileOptions compile_options_; | 1059 ScriptCompiler::CompileOptions compile_options_; |
1046 ParseData* cached_parse_data_; | 1060 ParseData* cached_parse_data_; |
1047 | 1061 |
1048 bool parsing_lazy_arrow_parameters_; // for lazily parsed arrow functions. | |
1049 | |
1050 PendingCompilationErrorHandler pending_error_handler_; | 1062 PendingCompilationErrorHandler pending_error_handler_; |
1051 | 1063 |
1052 // Other information which will be stored in Parser and moved to Isolate after | 1064 // Other information which will be stored in Parser and moved to Isolate after |
1053 // parsing. | 1065 // parsing. |
1054 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; | 1066 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; |
1055 int total_preparse_skipped_; | 1067 int total_preparse_skipped_; |
1056 HistogramTimer* pre_parse_timer_; | 1068 HistogramTimer* pre_parse_timer_; |
1057 | 1069 |
1058 bool parsing_on_main_thread_; | 1070 bool parsing_on_main_thread_; |
1059 }; | 1071 }; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 } | 1174 } |
1163 | 1175 |
1164 | 1176 |
1165 Expression* ParserTraits::SpreadCallNew( | 1177 Expression* ParserTraits::SpreadCallNew( |
1166 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) { | 1178 Expression* function, ZoneList<v8::internal::Expression*>* args, int pos) { |
1167 return parser_->SpreadCallNew(function, args, pos); | 1179 return parser_->SpreadCallNew(function, args, pos); |
1168 } | 1180 } |
1169 } } // namespace v8::internal | 1181 } } // namespace v8::internal |
1170 | 1182 |
1171 #endif // V8_PARSER_H_ | 1183 #endif // V8_PARSER_H_ |
OLD | NEW |