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_PARSING_PARSER_H_ | 5 #ifndef V8_PARSING_PARSER_H_ |
6 #define V8_PARSING_PARSER_H_ | 6 #define V8_PARSING_PARSER_H_ |
7 | 7 |
8 #include "src/ast/ast.h" | 8 #include "src/ast/ast.h" |
9 #include "src/ast/scopes.h" | 9 #include "src/ast/scopes.h" |
10 #include "src/parsing/parser-base.h" | 10 #include "src/parsing/parser-base.h" |
11 #include "src/parsing/preparse-data.h" | 11 #include "src/parsing/preparse-data.h" |
12 #include "src/parsing/preparse-data-format.h" | 12 #include "src/parsing/preparse-data-format.h" |
13 #include "src/parsing/preparser.h" | 13 #include "src/parsing/preparser.h" |
14 #include "src/pending-compilation-error-handler.h" | 14 #include "src/pending-compilation-error-handler.h" |
15 | 15 |
16 namespace v8 { | 16 namespace v8 { |
17 | 17 |
18 class ScriptCompiler; | 18 class ScriptCompiler; |
19 | 19 |
20 namespace internal { | 20 namespace internal { |
21 | 21 |
22 class ParseInfo; | 22 class ParseInfo; |
23 class ScriptData; | 23 class ScriptData; |
24 class Target; | 24 class ParserTarget; |
25 class ParserTargetScope; | |
25 | 26 |
26 class FunctionEntry BASE_EMBEDDED { | 27 class FunctionEntry BASE_EMBEDDED { |
27 public: | 28 public: |
28 enum { | 29 enum { |
29 kStartPositionIndex, | 30 kStartPositionIndex, |
30 kEndPositionIndex, | 31 kEndPositionIndex, |
31 kLiteralCountIndex, | 32 kLiteralCountIndex, |
32 kPropertyCountIndex, | 33 kPropertyCountIndex, |
33 kLanguageModeIndex, | 34 kLanguageModeIndex, |
34 kUsesSuperPropertyIndex, | 35 kUsesSuperPropertyIndex, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 typedef Variable GeneratorVariable; | 146 typedef Variable GeneratorVariable; |
146 | 147 |
147 // Return types for traversing functions. | 148 // Return types for traversing functions. |
148 typedef const AstRawString* Identifier; | 149 typedef const AstRawString* Identifier; |
149 typedef v8::internal::Expression* Expression; | 150 typedef v8::internal::Expression* Expression; |
150 typedef v8::internal::FunctionLiteral* FunctionLiteral; | 151 typedef v8::internal::FunctionLiteral* FunctionLiteral; |
151 typedef ObjectLiteral::Property* ObjectLiteralProperty; | 152 typedef ObjectLiteral::Property* ObjectLiteralProperty; |
152 typedef ZoneList<v8::internal::Expression*>* ExpressionList; | 153 typedef ZoneList<v8::internal::Expression*>* ExpressionList; |
153 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; | 154 typedef ZoneList<ObjectLiteral::Property*>* PropertyList; |
154 typedef ParserFormalParameters FormalParameters; | 155 typedef ParserFormalParameters FormalParameters; |
156 typedef v8::internal::Statement* Statement; | |
155 typedef ZoneList<v8::internal::Statement*>* StatementList; | 157 typedef ZoneList<v8::internal::Statement*>* StatementList; |
156 typedef v8::internal::Block* Block; | 158 typedef v8::internal::Block* Block; |
157 | 159 |
158 // For constructing objects returned by the traversing functions. | 160 // For constructing objects returned by the traversing functions. |
159 typedef AstNodeFactory Factory; | 161 typedef AstNodeFactory Factory; |
162 | |
163 typedef ParserTarget Target; | |
164 typedef ParserTargetScope TargetScope; | |
160 }; | 165 }; |
161 | 166 |
162 class Parser : public ParserBase<Parser> { | 167 class Parser : public ParserBase<Parser> { |
163 public: | 168 public: |
164 explicit Parser(ParseInfo* info); | 169 explicit Parser(ParseInfo* info); |
165 ~Parser() { | 170 ~Parser() { |
166 delete reusable_preparser_; | 171 delete reusable_preparser_; |
167 reusable_preparser_ = NULL; | 172 reusable_preparser_ = NULL; |
168 delete cached_parse_data_; | 173 delete cached_parse_data_; |
169 cached_parse_data_ = NULL; | 174 cached_parse_data_ = NULL; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 cached_parse_data_ != NULL; | 241 cached_parse_data_ != NULL; |
237 } | 242 } |
238 bool produce_cached_parse_data() const { | 243 bool produce_cached_parse_data() const { |
239 return compile_options_ == ScriptCompiler::kProduceParserCache; | 244 return compile_options_ == ScriptCompiler::kProduceParserCache; |
240 } | 245 } |
241 | 246 |
242 // All ParseXXX functions take as the last argument an *ok parameter | 247 // All ParseXXX functions take as the last argument an *ok parameter |
243 // which is set to false if parsing failed; it is unchanged otherwise. | 248 // which is set to false if parsing failed; it is unchanged otherwise. |
244 // By making the 'exception handling' explicit, we are forced to check | 249 // By making the 'exception handling' explicit, we are forced to check |
245 // for failure at the call sites. | 250 // for failure at the call sites. |
246 void ParseStatementList(ZoneList<Statement*>* body, int end_token, bool* ok); | |
247 Statement* ParseStatementListItem(bool* ok); | |
248 void ParseModuleItemList(ZoneList<Statement*>* body, bool* ok); | 251 void ParseModuleItemList(ZoneList<Statement*>* body, bool* ok); |
249 Statement* ParseModuleItem(bool* ok); | 252 Statement* ParseModuleItem(bool* ok); |
250 const AstRawString* ParseModuleSpecifier(bool* ok); | 253 const AstRawString* ParseModuleSpecifier(bool* ok); |
251 void ParseImportDeclaration(bool* ok); | 254 void ParseImportDeclaration(bool* ok); |
252 Statement* ParseExportDeclaration(bool* ok); | 255 Statement* ParseExportDeclaration(bool* ok); |
253 Statement* ParseExportDefault(bool* ok); | 256 Statement* ParseExportDefault(bool* ok); |
254 void ParseExportClause(ZoneList<const AstRawString*>* export_names, | 257 void ParseExportClause(ZoneList<const AstRawString*>* export_names, |
255 ZoneList<Scanner::Location>* export_locations, | 258 ZoneList<Scanner::Location>* export_locations, |
256 ZoneList<const AstRawString*>* local_names, | 259 ZoneList<const AstRawString*>* local_names, |
257 Scanner::Location* reserved_loc, bool* ok); | 260 Scanner::Location* reserved_loc, bool* ok); |
258 struct NamedImport : public ZoneObject { | 261 struct NamedImport : public ZoneObject { |
259 const AstRawString* import_name; | 262 const AstRawString* import_name; |
260 const AstRawString* local_name; | 263 const AstRawString* local_name; |
261 const Scanner::Location location; | 264 const Scanner::Location location; |
262 NamedImport(const AstRawString* import_name, const AstRawString* local_name, | 265 NamedImport(const AstRawString* import_name, const AstRawString* local_name, |
263 Scanner::Location location) | 266 Scanner::Location location) |
264 : import_name(import_name), | 267 : import_name(import_name), |
265 local_name(local_name), | 268 local_name(local_name), |
266 location(location) {} | 269 location(location) {} |
267 }; | 270 }; |
268 ZoneList<const NamedImport*>* ParseNamedImports(int pos, bool* ok); | 271 ZoneList<const NamedImport*>* ParseNamedImports(int pos, bool* ok); |
269 Statement* ParseStatement(ZoneList<const AstRawString*>* labels, | |
270 AllowLabelledFunctionStatement allow_function, | |
271 bool* ok); | |
272 Statement* ParseSubStatement(ZoneList<const AstRawString*>* labels, | |
273 AllowLabelledFunctionStatement allow_function, | |
274 bool* ok); | |
275 Statement* ParseStatementAsUnlabelled(ZoneList<const AstRawString*>* labels, | |
276 bool* ok); | |
277 Statement* ParseFunctionDeclaration(bool* ok); | 272 Statement* ParseFunctionDeclaration(bool* ok); |
278 Statement* ParseHoistableDeclaration(ZoneList<const AstRawString*>* names, | 273 Statement* ParseHoistableDeclaration(ZoneList<const AstRawString*>* names, |
279 bool default_export, bool* ok); | 274 bool default_export, bool* ok); |
280 Statement* ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, | 275 Statement* ParseHoistableDeclaration(int pos, ParseFunctionFlags flags, |
281 ZoneList<const AstRawString*>* names, | 276 ZoneList<const AstRawString*>* names, |
282 bool default_export, bool* ok); | 277 bool default_export, bool* ok); |
283 Statement* ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, | 278 Statement* ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, |
284 bool default_export, bool* ok); | 279 bool default_export, bool* ok); |
285 Expression* ParseAsyncFunctionExpression(bool* ok); | 280 Expression* ParseAsyncFunctionExpression(bool* ok); |
286 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names, | 281 Statement* ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
573 FunctionBodyType::kSingleExpression, accept_IN, pos, ok); | 568 FunctionBodyType::kSingleExpression, accept_IN, pos, ok); |
574 } | 569 } |
575 | 570 |
576 ZoneList<Expression*>* PrepareSpreadArguments(ZoneList<Expression*>* list); | 571 ZoneList<Expression*>* PrepareSpreadArguments(ZoneList<Expression*>* list); |
577 Expression* SpreadCall(Expression* function, ZoneList<Expression*>* args, | 572 Expression* SpreadCall(Expression* function, ZoneList<Expression*>* args, |
578 int pos); | 573 int pos); |
579 Expression* SpreadCallNew(Expression* function, ZoneList<Expression*>* args, | 574 Expression* SpreadCallNew(Expression* function, ZoneList<Expression*>* args, |
580 int pos); | 575 int pos); |
581 | 576 |
582 void SetLanguageMode(Scope* scope, LanguageMode mode); | 577 void SetLanguageMode(Scope* scope, LanguageMode mode); |
583 void RaiseLanguageMode(LanguageMode mode); | 578 void SetAsmModule(); |
584 | 579 |
585 V8_INLINE void MarkCollectedTailCallExpressions(); | 580 V8_INLINE void MarkCollectedTailCallExpressions(); |
586 V8_INLINE void MarkTailPosition(Expression* expression); | 581 V8_INLINE void MarkTailPosition(Expression* expression); |
587 | 582 |
588 // Rewrite all DestructuringAssignments in the current FunctionState. | 583 // Rewrite all DestructuringAssignments in the current FunctionState. |
589 V8_INLINE void RewriteDestructuringAssignments(); | 584 V8_INLINE void RewriteDestructuringAssignments(); |
590 | 585 |
591 V8_INLINE Expression* RewriteExponentiation(Expression* left, | 586 V8_INLINE Expression* RewriteExponentiation(Expression* left, |
592 Expression* right, int pos); | 587 Expression* right, int pos); |
593 V8_INLINE Expression* RewriteAssignExponentiation(Expression* left, | 588 V8_INLINE Expression* RewriteAssignExponentiation(Expression* left, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
695 V8_INLINE static bool IsBoilerplateProperty( | 690 V8_INLINE static bool IsBoilerplateProperty( |
696 ObjectLiteral::Property* property) { | 691 ObjectLiteral::Property* property) { |
697 return ObjectLiteral::IsBoilerplateProperty(property); | 692 return ObjectLiteral::IsBoilerplateProperty(property); |
698 } | 693 } |
699 | 694 |
700 V8_INLINE static bool IsArrayIndex(const AstRawString* string, | 695 V8_INLINE static bool IsArrayIndex(const AstRawString* string, |
701 uint32_t* index) { | 696 uint32_t* index) { |
702 return string->AsArrayIndex(index); | 697 return string->AsArrayIndex(index); |
703 } | 698 } |
704 | 699 |
700 V8_INLINE bool IsUseStrictDirective(Statement* statement) const { | |
701 ExpressionStatement* e_stat = statement->AsExpressionStatement(); | |
702 if (e_stat == nullptr) return false; | |
703 Literal* literal = e_stat->expression()->AsLiteral(); | |
704 if (literal == nullptr || !literal->raw_value()->IsString()) return false; | |
705 return literal->raw_value()->AsString() == | |
706 ast_value_factory()->use_strict_string(); | |
707 } | |
708 | |
709 V8_INLINE bool IsUseAsmDirective(Statement* statement) const { | |
710 ExpressionStatement* e_stat = statement->AsExpressionStatement(); | |
711 if (e_stat == nullptr) return false; | |
712 Literal* literal = e_stat->expression()->AsLiteral(); | |
713 if (literal == nullptr || !literal->raw_value()->IsString()) return false; | |
714 return literal->raw_value()->AsString() == | |
715 ast_value_factory()->use_asm_string(); | |
marja
2016/09/05 08:14:33
Nit: these 2 functions are almost duplicate, the o
nickie
2016/09/05 11:29:31
Done. I merged both with IsStringLiteral.
| |
716 } | |
717 | |
718 V8_INLINE bool IsStringLiteral(Statement* statement) const { | |
719 ExpressionStatement* e_stat = statement->AsExpressionStatement(); | |
720 if (e_stat == nullptr) return false; | |
721 Literal* literal = e_stat->expression()->AsLiteral(); | |
722 if (literal == nullptr || !literal->raw_value()->IsString()) return false; | |
723 return true; | |
724 } | |
725 | |
705 V8_INLINE static Expression* GetPropertyValue( | 726 V8_INLINE static Expression* GetPropertyValue( |
706 ObjectLiteral::Property* property) { | 727 ObjectLiteral::Property* property) { |
707 return property->value(); | 728 return property->value(); |
708 } | 729 } |
709 | 730 |
710 // Functions for encapsulating the differences between parsing and preparsing; | 731 // Functions for encapsulating the differences between parsing and preparsing; |
711 // operations interleaved with the recursive descent. | 732 // operations interleaved with the recursive descent. |
712 V8_INLINE static void PushLiteralName(FuncNameInferrer* fni, | 733 V8_INLINE static void PushLiteralName(FuncNameInferrer* fni, |
713 const AstRawString* id) { | 734 const AstRawString* id) { |
714 fni->PushLiteralName(id); | 735 fni->PushLiteralName(id); |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
841 V8_INLINE static Block* NullBlock() { return nullptr; } | 862 V8_INLINE static Block* NullBlock() { return nullptr; } |
842 | 863 |
843 V8_INLINE static bool IsEmptyExpression(Expression* expr) { | 864 V8_INLINE static bool IsEmptyExpression(Expression* expr) { |
844 return expr == nullptr; | 865 return expr == nullptr; |
845 } | 866 } |
846 | 867 |
847 // Used in error return values. | 868 // Used in error return values. |
848 V8_INLINE static ZoneList<Expression*>* NullExpressionList() { | 869 V8_INLINE static ZoneList<Expression*>* NullExpressionList() { |
849 return nullptr; | 870 return nullptr; |
850 } | 871 } |
872 V8_INLINE static bool IsNullExpressionList(ZoneList<Expression*>* exprs) { | |
873 return exprs == nullptr; | |
874 } | |
851 V8_INLINE static ZoneList<Statement*>* NullStatementList() { return nullptr; } | 875 V8_INLINE static ZoneList<Statement*>* NullStatementList() { return nullptr; } |
876 V8_INLINE static bool IsNullStatementList(ZoneList<Statement*>* stmts) { | |
877 return stmts == nullptr; | |
878 } | |
879 V8_INLINE static Statement* NullStatement() { return nullptr; } | |
880 V8_INLINE bool IsNullOrEmptyStatement(Statement* stmt) { | |
881 return stmt == nullptr || stmt->IsEmpty(); | |
882 } | |
852 | 883 |
853 // Non-NULL empty string. | 884 // Non-NULL empty string. |
854 V8_INLINE const AstRawString* EmptyIdentifierString() const { | 885 V8_INLINE const AstRawString* EmptyIdentifierString() const { |
855 return ast_value_factory()->empty_string(); | 886 return ast_value_factory()->empty_string(); |
856 } | 887 } |
857 | 888 |
858 // Odd-ball literal creators. | 889 // Odd-ball literal creators. |
859 V8_INLINE Literal* GetLiteralTheHole(int position) { | 890 V8_INLINE Literal* GetLiteralTheHole(int position) { |
860 return factory()->NewTheHoleLiteral(kNoSourcePosition); | 891 return factory()->NewTheHoleLiteral(kNoSourcePosition); |
861 } | 892 } |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1003 | 1034 |
1004 V8_INLINE ZoneList<Expression*>* GetNonPatternList() const { | 1035 V8_INLINE ZoneList<Expression*>* GetNonPatternList() const { |
1005 return function_state_->non_patterns_to_rewrite(); | 1036 return function_state_->non_patterns_to_rewrite(); |
1006 } | 1037 } |
1007 | 1038 |
1008 // Parser's private field members. | 1039 // Parser's private field members. |
1009 | 1040 |
1010 Scanner scanner_; | 1041 Scanner scanner_; |
1011 PreParser* reusable_preparser_; | 1042 PreParser* reusable_preparser_; |
1012 Scope* original_scope_; // for ES5 function declarations in sloppy eval | 1043 Scope* original_scope_; // for ES5 function declarations in sloppy eval |
1013 Target* target_stack_; // for break, continue statements | 1044 |
1045 friend class ParserTarget; | |
1046 friend class ParserTargetScope; | |
1047 ParserTarget* target_stack_; // for break, continue statements | |
1048 | |
1014 ScriptCompiler::CompileOptions compile_options_; | 1049 ScriptCompiler::CompileOptions compile_options_; |
1015 ParseData* cached_parse_data_; | 1050 ParseData* cached_parse_data_; |
1016 | 1051 |
1017 PendingCompilationErrorHandler pending_error_handler_; | 1052 PendingCompilationErrorHandler pending_error_handler_; |
1018 | 1053 |
1019 // Other information which will be stored in Parser and moved to Isolate after | 1054 // Other information which will be stored in Parser and moved to Isolate after |
1020 // parsing. | 1055 // parsing. |
1021 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; | 1056 int use_counts_[v8::Isolate::kUseCounterFeatureCount]; |
1022 int total_preparse_skipped_; | 1057 int total_preparse_skipped_; |
1023 HistogramTimer* pre_parse_timer_; | 1058 HistogramTimer* pre_parse_timer_; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1055 static const int kLiteralTypeSlot = 0; | 1090 static const int kLiteralTypeSlot = 0; |
1056 static const int kElementsSlot = 1; | 1091 static const int kElementsSlot = 1; |
1057 | 1092 |
1058 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); | 1093 DISALLOW_IMPLICIT_CONSTRUCTORS(CompileTimeValue); |
1059 }; | 1094 }; |
1060 | 1095 |
1061 } // namespace internal | 1096 } // namespace internal |
1062 } // namespace v8 | 1097 } // namespace v8 |
1063 | 1098 |
1064 #endif // V8_PARSING_PARSER_H_ | 1099 #endif // V8_PARSING_PARSER_H_ |
OLD | NEW |