| 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_PREPARSER_H | 5 #ifndef V8_PARSING_PREPARSER_H |
| 6 #define V8_PARSING_PREPARSER_H | 6 #define V8_PARSING_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/ast/scopes.h" | 8 #include "src/ast/scopes.h" |
| 9 #include "src/parsing/parser-base.h" | 9 #include "src/parsing/parser-base.h" |
| 10 | 10 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 kEvalIdentifier, | 105 kEvalIdentifier, |
| 106 kArgumentsIdentifier, | 106 kArgumentsIdentifier, |
| 107 kUndefinedIdentifier, | 107 kUndefinedIdentifier, |
| 108 kPrototypeIdentifier, | 108 kPrototypeIdentifier, |
| 109 kConstructorIdentifier, | 109 kConstructorIdentifier, |
| 110 kEnumIdentifier, | 110 kEnumIdentifier, |
| 111 kAwaitIdentifier, | 111 kAwaitIdentifier, |
| 112 kAsyncIdentifier | 112 kAsyncIdentifier |
| 113 }; | 113 }; |
| 114 | 114 |
| 115 explicit PreParserIdentifier(Type type) : type_(type) {} | 115 explicit PreParserIdentifier(Type type) : type_(type), string_(nullptr) {} |
| 116 Type type_; | 116 Type type_; |
| 117 | 117 // Only non-nullptr when PreParser.track_unresolved_variables_ is true. |
| 118 const AstRawString* string_; |
| 118 friend class PreParserExpression; | 119 friend class PreParserExpression; |
| 120 friend class PreParser; |
| 119 }; | 121 }; |
| 120 | 122 |
| 121 | 123 |
| 122 class PreParserExpression { | 124 class PreParserExpression { |
| 123 public: | 125 public: |
| 124 PreParserExpression() : code_(TypeField::encode(kEmpty)) {} | 126 PreParserExpression() : code_(TypeField::encode(kEmpty)) {} |
| 125 | 127 |
| 126 static PreParserExpression Empty() { return PreParserExpression(); } | 128 static PreParserExpression Empty() { return PreParserExpression(); } |
| 127 | 129 |
| 128 static PreParserExpression Default() { | 130 static PreParserExpression Default() { |
| (...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 749 enum PreParseResult { | 751 enum PreParseResult { |
| 750 kPreParseStackOverflow, | 752 kPreParseStackOverflow, |
| 751 kPreParseAbort, | 753 kPreParseAbort, |
| 752 kPreParseSuccess | 754 kPreParseSuccess |
| 753 }; | 755 }; |
| 754 | 756 |
| 755 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory, | 757 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory, |
| 756 ParserRecorder* log, uintptr_t stack_limit) | 758 ParserRecorder* log, uintptr_t stack_limit) |
| 757 : ParserBase<PreParser>(zone, scanner, stack_limit, NULL, | 759 : ParserBase<PreParser>(zone, scanner, stack_limit, NULL, |
| 758 ast_value_factory, log), | 760 ast_value_factory, log), |
| 759 use_counts_(nullptr) {} | 761 use_counts_(nullptr), |
| 762 track_unresolved_variables_(false) {} |
| 760 | 763 |
| 761 // Pre-parse the program from the character stream; returns true on | 764 // Pre-parse the program from the character stream; returns true on |
| 762 // success (even if parsing failed, the pre-parse data successfully | 765 // success (even if parsing failed, the pre-parse data successfully |
| 763 // captured the syntax error), and false if a stack-overflow happened | 766 // captured the syntax error), and false if a stack-overflow happened |
| 764 // during parsing. | 767 // during parsing. |
| 765 PreParseResult PreParseProgram(int* materialized_literals = 0, | 768 PreParseResult PreParseProgram(int* materialized_literals = 0, |
| 766 bool is_module = false) { | 769 bool is_module = false) { |
| 767 DCHECK_NULL(scope_state_); | 770 DCHECK_NULL(scope_state_); |
| 768 DeclarationScope* scope = NewScriptScope(); | 771 DeclarationScope* scope = NewScriptScope(); |
| 769 | 772 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 795 } | 798 } |
| 796 | 799 |
| 797 // Parses a single function literal, from the opening parentheses before | 800 // Parses a single function literal, from the opening parentheses before |
| 798 // parameters to the closing brace after the body. | 801 // parameters to the closing brace after the body. |
| 799 // Returns a FunctionEntry describing the body of the function in enough | 802 // Returns a FunctionEntry describing the body of the function in enough |
| 800 // detail that it can be lazily compiled. | 803 // detail that it can be lazily compiled. |
| 801 // The scanner is expected to have matched the "function" or "function*" | 804 // The scanner is expected to have matched the "function" or "function*" |
| 802 // keyword and parameters, and have consumed the initial '{'. | 805 // keyword and parameters, and have consumed the initial '{'. |
| 803 // At return, unless an error occurred, the scanner is positioned before the | 806 // At return, unless an error occurred, the scanner is positioned before the |
| 804 // the final '}'. | 807 // the final '}'. |
| 805 PreParseResult PreParseLazyFunction(LanguageMode language_mode, | 808 PreParseResult PreParseLazyFunction(FunctionKind kind, |
| 806 FunctionKind kind, | 809 DeclarationScope* function_scope, |
| 807 bool has_simple_parameters, | |
| 808 bool parsing_module, ParserRecorder* log, | 810 bool parsing_module, ParserRecorder* log, |
| 811 bool track_unresolved_variables, |
| 809 bool may_abort, int* use_counts); | 812 bool may_abort, int* use_counts); |
| 810 | 813 |
| 811 private: | 814 private: |
| 812 // These types form an algebra over syntactic categories that is just | 815 // These types form an algebra over syntactic categories that is just |
| 813 // rich enough to let us recognize and propagate the constructs that | 816 // rich enough to let us recognize and propagate the constructs that |
| 814 // are either being counted in the preparser data, or is important | 817 // are either being counted in the preparser data, or is important |
| 815 // to throw the correct syntax error exceptions. | 818 // to throw the correct syntax error exceptions. |
| 816 | 819 |
| 817 // All ParseXXX functions take as the last argument an *ok parameter | 820 // All ParseXXX functions take as the last argument an *ok parameter |
| 818 // which is set to false if parsing failed; it is unchanged otherwise. | 821 // which is set to false if parsing failed; it is unchanged otherwise. |
| 819 // By making the 'exception handling' explicit, we are forced to check | 822 // By making the 'exception handling' explicit, we are forced to check |
| 820 // for failure at the call sites. | 823 // for failure at the call sites. |
| 821 Statement ParseFunctionDeclaration(bool* ok); | 824 Statement ParseFunctionDeclaration(bool* ok); |
| 822 Statement ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, | 825 Statement ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, |
| 823 bool default_export, bool* ok); | 826 bool default_export, bool* ok); |
| 824 Expression ParseAsyncFunctionExpression(bool* ok); | 827 Expression ParseAsyncFunctionExpression(bool* ok); |
| 825 Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names, | 828 Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
| 826 bool default_export, bool* ok); | 829 bool default_export, bool* ok); |
| 827 Statement ParseForStatement(ZoneList<const AstRawString*>* labels, bool* ok); | 830 Statement ParseForStatement(ZoneList<const AstRawString*>* labels, bool* ok); |
| 828 Statement ParseTryStatement(bool* ok); | 831 Statement ParseTryStatement(bool* ok); |
| 829 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 832 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
| 830 Expression ParseObjectLiteral(bool* ok); | 833 Expression ParseObjectLiteral(bool* ok); |
| 831 | 834 |
| 832 V8_INLINE PreParserStatementList ParseEagerFunctionBody( | 835 V8_INLINE PreParserStatementList ParseEagerFunctionBody( |
| 833 PreParserIdentifier function_name, int pos, | 836 PreParserIdentifier function_name, int pos, |
| 834 const PreParserFormalParameters& parameters, FunctionKind kind, | 837 const PreParserFormalParameters& parameters, FunctionKind kind, |
| 835 FunctionLiteral::FunctionType function_type, bool* ok); | 838 FunctionLiteral::FunctionType function_type, bool* ok); |
| 836 | 839 |
| 837 V8_INLINE LazyParsingResult | 840 V8_INLINE LazyParsingResult SkipLazyFunctionBody( |
| 838 SkipLazyFunctionBody(int* materialized_literal_count, | 841 int* materialized_literal_count, int* expected_property_count, |
| 839 int* expected_property_count, bool may_abort, bool* ok) { | 842 bool track_unresolved_variables, bool may_abort, bool* ok) { |
| 840 UNREACHABLE(); | 843 UNREACHABLE(); |
| 841 return kLazyParsingComplete; | 844 return kLazyParsingComplete; |
| 842 } | 845 } |
| 843 Expression ParseFunctionLiteral( | 846 Expression ParseFunctionLiteral( |
| 844 Identifier name, Scanner::Location function_name_location, | 847 Identifier name, Scanner::Location function_name_location, |
| 845 FunctionNameValidity function_name_validity, FunctionKind kind, | 848 FunctionNameValidity function_name_validity, FunctionKind kind, |
| 846 int function_token_pos, FunctionLiteral::FunctionType function_type, | 849 int function_token_pos, FunctionLiteral::FunctionType function_type, |
| 847 LanguageMode language_mode, bool* ok); | 850 LanguageMode language_mode, bool* ok); |
| 848 LazyParsingResult ParseLazyFunctionLiteralBody(bool may_abort, bool* ok); | 851 LazyParsingResult ParseLazyFunctionLiteralBody(bool may_abort, bool* ok); |
| 849 | 852 |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1237 | 1240 |
| 1238 V8_INLINE PreParserExpression FunctionSentExpression(int pos) { | 1241 V8_INLINE PreParserExpression FunctionSentExpression(int pos) { |
| 1239 return PreParserExpression::Default(); | 1242 return PreParserExpression::Default(); |
| 1240 } | 1243 } |
| 1241 | 1244 |
| 1242 V8_INLINE PreParserExpression ExpressionFromLiteral(Token::Value token, | 1245 V8_INLINE PreParserExpression ExpressionFromLiteral(Token::Value token, |
| 1243 int pos) { | 1246 int pos) { |
| 1244 return PreParserExpression::Default(); | 1247 return PreParserExpression::Default(); |
| 1245 } | 1248 } |
| 1246 | 1249 |
| 1247 V8_INLINE PreParserExpression ExpressionFromIdentifier( | 1250 PreParserExpression ExpressionFromIdentifier( |
| 1248 PreParserIdentifier name, int start_position, int end_position, | 1251 PreParserIdentifier name, int start_position, int end_position, |
| 1249 InferName infer = InferName::kYes) { | 1252 InferName infer = InferName::kYes); |
| 1250 return PreParserExpression::FromIdentifier(name); | |
| 1251 } | |
| 1252 | 1253 |
| 1253 V8_INLINE PreParserExpression ExpressionFromString(int pos) { | 1254 V8_INLINE PreParserExpression ExpressionFromString(int pos) { |
| 1254 if (scanner()->UnescapedLiteralMatches("use strict", 10)) { | 1255 if (scanner()->UnescapedLiteralMatches("use strict", 10)) { |
| 1255 return PreParserExpression::UseStrictStringLiteral(); | 1256 return PreParserExpression::UseStrictStringLiteral(); |
| 1256 } | 1257 } |
| 1257 return PreParserExpression::StringLiteral(); | 1258 return PreParserExpression::StringLiteral(); |
| 1258 } | 1259 } |
| 1259 | 1260 |
| 1260 V8_INLINE PreParserExpressionList NewExpressionList(int size) const { | 1261 V8_INLINE PreParserExpressionList NewExpressionList(int size) const { |
| 1261 return PreParserExpressionList(); | 1262 return PreParserExpressionList(); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1356 return function_state_->non_patterns_to_rewrite(); | 1357 return function_state_->non_patterns_to_rewrite(); |
| 1357 } | 1358 } |
| 1358 | 1359 |
| 1359 V8_INLINE void CountUsage(v8::Isolate::UseCounterFeature feature) { | 1360 V8_INLINE void CountUsage(v8::Isolate::UseCounterFeature feature) { |
| 1360 if (use_counts_ != nullptr) ++use_counts_[feature]; | 1361 if (use_counts_ != nullptr) ++use_counts_[feature]; |
| 1361 } | 1362 } |
| 1362 | 1363 |
| 1363 // Preparser's private field members. | 1364 // Preparser's private field members. |
| 1364 | 1365 |
| 1365 int* use_counts_; | 1366 int* use_counts_; |
| 1367 bool track_unresolved_variables_; |
| 1366 }; | 1368 }; |
| 1367 | 1369 |
| 1368 PreParserExpression PreParser::SpreadCall(PreParserExpression function, | 1370 PreParserExpression PreParser::SpreadCall(PreParserExpression function, |
| 1369 PreParserExpressionList args, | 1371 PreParserExpressionList args, |
| 1370 int pos) { | 1372 int pos) { |
| 1371 return factory()->NewCall(function, args, pos); | 1373 return factory()->NewCall(function, args, pos); |
| 1372 } | 1374 } |
| 1373 | 1375 |
| 1374 PreParserExpression PreParser::SpreadCallNew(PreParserExpression function, | 1376 PreParserExpression PreParser::SpreadCallNew(PreParserExpression function, |
| 1375 PreParserExpressionList args, | 1377 PreParserExpressionList args, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1406 function_state_->NextMaterializedLiteralIndex(); | 1408 function_state_->NextMaterializedLiteralIndex(); |
| 1407 function_state_->NextMaterializedLiteralIndex(); | 1409 function_state_->NextMaterializedLiteralIndex(); |
| 1408 } | 1410 } |
| 1409 return EmptyExpression(); | 1411 return EmptyExpression(); |
| 1410 } | 1412 } |
| 1411 | 1413 |
| 1412 } // namespace internal | 1414 } // namespace internal |
| 1413 } // namespace v8 | 1415 } // namespace v8 |
| 1414 | 1416 |
| 1415 #endif // V8_PARSING_PREPARSER_H | 1417 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |