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