| 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), string_(nullptr) {} | 115 explicit PreParserIdentifier(Type type) : type_(type) {} |
| 116 Type type_; | 116 Type type_; |
| 117 // Only non-nullptr when PreParser.track_unresolved_variables_ is true. | 117 |
| 118 const AstRawString* string_; | |
| 119 friend class PreParserExpression; | 118 friend class PreParserExpression; |
| 120 friend class PreParser; | |
| 121 }; | 119 }; |
| 122 | 120 |
| 123 | 121 |
| 124 class PreParserExpression { | 122 class PreParserExpression { |
| 125 public: | 123 public: |
| 126 PreParserExpression() : code_(TypeField::encode(kEmpty)) {} | 124 PreParserExpression() : code_(TypeField::encode(kEmpty)) {} |
| 127 | 125 |
| 128 static PreParserExpression Empty() { return PreParserExpression(); } | 126 static PreParserExpression Empty() { return PreParserExpression(); } |
| 129 | 127 |
| 130 static PreParserExpression Default() { | 128 static PreParserExpression Default() { |
| (...skipping 638 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 769 enum PreParseResult { | 767 enum PreParseResult { |
| 770 kPreParseStackOverflow, | 768 kPreParseStackOverflow, |
| 771 kPreParseAbort, | 769 kPreParseAbort, |
| 772 kPreParseSuccess | 770 kPreParseSuccess |
| 773 }; | 771 }; |
| 774 | 772 |
| 775 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory, | 773 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory, |
| 776 ParserRecorder* log, uintptr_t stack_limit) | 774 ParserRecorder* log, uintptr_t stack_limit) |
| 777 : ParserBase<PreParser>(zone, scanner, stack_limit, NULL, | 775 : ParserBase<PreParser>(zone, scanner, stack_limit, NULL, |
| 778 ast_value_factory, log), | 776 ast_value_factory, log), |
| 779 use_counts_(nullptr), | 777 use_counts_(nullptr) {} |
| 780 track_unresolved_variables_(false) {} | |
| 781 | 778 |
| 782 // Pre-parse the program from the character stream; returns true on | 779 // Pre-parse the program from the character stream; returns true on |
| 783 // success (even if parsing failed, the pre-parse data successfully | 780 // success (even if parsing failed, the pre-parse data successfully |
| 784 // captured the syntax error), and false if a stack-overflow happened | 781 // captured the syntax error), and false if a stack-overflow happened |
| 785 // during parsing. | 782 // during parsing. |
| 786 PreParseResult PreParseProgram(int* materialized_literals = 0, | 783 PreParseResult PreParseProgram(int* materialized_literals = 0, |
| 787 bool is_module = false) { | 784 bool is_module = false) { |
| 788 DCHECK_NULL(scope_state_); | 785 DCHECK_NULL(scope_state_); |
| 789 DeclarationScope* scope = NewScriptScope(); | 786 DeclarationScope* scope = NewScriptScope(); |
| 790 | 787 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 816 } | 813 } |
| 817 | 814 |
| 818 // Parses a single function literal, from the opening parentheses before | 815 // Parses a single function literal, from the opening parentheses before |
| 819 // parameters to the closing brace after the body. | 816 // parameters to the closing brace after the body. |
| 820 // Returns a FunctionEntry describing the body of the function in enough | 817 // Returns a FunctionEntry describing the body of the function in enough |
| 821 // detail that it can be lazily compiled. | 818 // detail that it can be lazily compiled. |
| 822 // The scanner is expected to have matched the "function" or "function*" | 819 // The scanner is expected to have matched the "function" or "function*" |
| 823 // keyword and parameters, and have consumed the initial '{'. | 820 // keyword and parameters, and have consumed the initial '{'. |
| 824 // At return, unless an error occurred, the scanner is positioned before the | 821 // At return, unless an error occurred, the scanner is positioned before the |
| 825 // the final '}'. | 822 // the final '}'. |
| 826 PreParseResult PreParseLazyFunction(FunctionKind kind, | 823 PreParseResult PreParseLazyFunction(LanguageMode language_mode, |
| 827 DeclarationScope* function_scope, | 824 FunctionKind kind, |
| 825 bool has_simple_parameters, |
| 828 bool parsing_module, ParserRecorder* log, | 826 bool parsing_module, ParserRecorder* log, |
| 829 bool track_unresolved_variables, | |
| 830 bool may_abort, int* use_counts); | 827 bool may_abort, int* use_counts); |
| 831 | 828 |
| 832 private: | 829 private: |
| 833 // These types form an algebra over syntactic categories that is just | 830 // These types form an algebra over syntactic categories that is just |
| 834 // rich enough to let us recognize and propagate the constructs that | 831 // rich enough to let us recognize and propagate the constructs that |
| 835 // are either being counted in the preparser data, or is important | 832 // are either being counted in the preparser data, or is important |
| 836 // to throw the correct syntax error exceptions. | 833 // to throw the correct syntax error exceptions. |
| 837 | 834 |
| 838 // All ParseXXX functions take as the last argument an *ok parameter | 835 // All ParseXXX functions take as the last argument an *ok parameter |
| 839 // which is set to false if parsing failed; it is unchanged otherwise. | 836 // which is set to false if parsing failed; it is unchanged otherwise. |
| 840 // By making the 'exception handling' explicit, we are forced to check | 837 // By making the 'exception handling' explicit, we are forced to check |
| 841 // for failure at the call sites. | 838 // for failure at the call sites. |
| 842 Statement ParseFunctionDeclaration(bool* ok); | 839 Statement ParseFunctionDeclaration(bool* ok); |
| 843 Statement ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, | 840 Statement ParseAsyncFunctionDeclaration(ZoneList<const AstRawString*>* names, |
| 844 bool default_export, bool* ok); | 841 bool default_export, bool* ok); |
| 845 Expression ParseAsyncFunctionExpression(bool* ok); | 842 Expression ParseAsyncFunctionExpression(bool* ok); |
| 846 Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names, | 843 Statement ParseClassDeclaration(ZoneList<const AstRawString*>* names, |
| 847 bool default_export, bool* ok); | 844 bool default_export, bool* ok); |
| 848 Expression ParseConditionalExpression(bool accept_IN, bool* ok); | 845 Expression ParseConditionalExpression(bool accept_IN, bool* ok); |
| 849 Expression ParseObjectLiteral(bool* ok); | 846 Expression ParseObjectLiteral(bool* ok); |
| 850 | 847 |
| 851 V8_INLINE PreParserStatementList ParseEagerFunctionBody( | 848 V8_INLINE PreParserStatementList ParseEagerFunctionBody( |
| 852 PreParserIdentifier function_name, int pos, | 849 PreParserIdentifier function_name, int pos, |
| 853 const PreParserFormalParameters& parameters, FunctionKind kind, | 850 const PreParserFormalParameters& parameters, FunctionKind kind, |
| 854 FunctionLiteral::FunctionType function_type, bool* ok); | 851 FunctionLiteral::FunctionType function_type, bool* ok); |
| 855 | 852 |
| 856 V8_INLINE LazyParsingResult SkipLazyFunctionBody( | 853 V8_INLINE LazyParsingResult |
| 857 int* materialized_literal_count, int* expected_property_count, | 854 SkipLazyFunctionBody(int* materialized_literal_count, |
| 858 bool track_unresolved_variables, bool may_abort, bool* ok) { | 855 int* expected_property_count, bool may_abort, bool* ok) { |
| 859 UNREACHABLE(); | 856 UNREACHABLE(); |
| 860 return kLazyParsingComplete; | 857 return kLazyParsingComplete; |
| 861 } | 858 } |
| 862 Expression ParseFunctionLiteral( | 859 Expression ParseFunctionLiteral( |
| 863 Identifier name, Scanner::Location function_name_location, | 860 Identifier name, Scanner::Location function_name_location, |
| 864 FunctionNameValidity function_name_validity, FunctionKind kind, | 861 FunctionNameValidity function_name_validity, FunctionKind kind, |
| 865 int function_token_pos, FunctionLiteral::FunctionType function_type, | 862 int function_token_pos, FunctionLiteral::FunctionType function_type, |
| 866 LanguageMode language_mode, bool* ok); | 863 LanguageMode language_mode, bool* ok); |
| 867 LazyParsingResult ParseLazyFunctionLiteralBody(bool may_abort, bool* ok); | 864 LazyParsingResult ParseLazyFunctionLiteralBody(bool may_abort, bool* ok); |
| 868 | 865 |
| (...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1300 | 1297 |
| 1301 V8_INLINE PreParserExpression FunctionSentExpression(int pos) { | 1298 V8_INLINE PreParserExpression FunctionSentExpression(int pos) { |
| 1302 return PreParserExpression::Default(); | 1299 return PreParserExpression::Default(); |
| 1303 } | 1300 } |
| 1304 | 1301 |
| 1305 V8_INLINE PreParserExpression ExpressionFromLiteral(Token::Value token, | 1302 V8_INLINE PreParserExpression ExpressionFromLiteral(Token::Value token, |
| 1306 int pos) { | 1303 int pos) { |
| 1307 return PreParserExpression::Default(); | 1304 return PreParserExpression::Default(); |
| 1308 } | 1305 } |
| 1309 | 1306 |
| 1310 PreParserExpression ExpressionFromIdentifier( | 1307 V8_INLINE PreParserExpression ExpressionFromIdentifier( |
| 1311 PreParserIdentifier name, int start_position, int end_position, | 1308 PreParserIdentifier name, int start_position, int end_position, |
| 1312 InferName infer = InferName::kYes); | 1309 InferName infer = InferName::kYes) { |
| 1310 return PreParserExpression::FromIdentifier(name); |
| 1311 } |
| 1313 | 1312 |
| 1314 V8_INLINE PreParserExpression ExpressionFromString(int pos) { | 1313 V8_INLINE PreParserExpression ExpressionFromString(int pos) { |
| 1315 if (scanner()->UnescapedLiteralMatches("use strict", 10)) { | 1314 if (scanner()->UnescapedLiteralMatches("use strict", 10)) { |
| 1316 return PreParserExpression::UseStrictStringLiteral(); | 1315 return PreParserExpression::UseStrictStringLiteral(); |
| 1317 } | 1316 } |
| 1318 return PreParserExpression::StringLiteral(); | 1317 return PreParserExpression::StringLiteral(); |
| 1319 } | 1318 } |
| 1320 | 1319 |
| 1321 V8_INLINE PreParserExpressionList NewExpressionList(int size) const { | 1320 V8_INLINE PreParserExpressionList NewExpressionList(int size) const { |
| 1322 return PreParserExpressionList(); | 1321 return PreParserExpressionList(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1411 return function_state_->non_patterns_to_rewrite(); | 1410 return function_state_->non_patterns_to_rewrite(); |
| 1412 } | 1411 } |
| 1413 | 1412 |
| 1414 V8_INLINE void CountUsage(v8::Isolate::UseCounterFeature feature) { | 1413 V8_INLINE void CountUsage(v8::Isolate::UseCounterFeature feature) { |
| 1415 if (use_counts_ != nullptr) ++use_counts_[feature]; | 1414 if (use_counts_ != nullptr) ++use_counts_[feature]; |
| 1416 } | 1415 } |
| 1417 | 1416 |
| 1418 // Preparser's private field members. | 1417 // Preparser's private field members. |
| 1419 | 1418 |
| 1420 int* use_counts_; | 1419 int* use_counts_; |
| 1421 bool track_unresolved_variables_; | |
| 1422 }; | 1420 }; |
| 1423 | 1421 |
| 1424 PreParserExpression PreParser::SpreadCall(PreParserExpression function, | 1422 PreParserExpression PreParser::SpreadCall(PreParserExpression function, |
| 1425 PreParserExpressionList args, | 1423 PreParserExpressionList args, |
| 1426 int pos) { | 1424 int pos) { |
| 1427 return factory()->NewCall(function, args, pos); | 1425 return factory()->NewCall(function, args, pos); |
| 1428 } | 1426 } |
| 1429 | 1427 |
| 1430 PreParserExpression PreParser::SpreadCallNew(PreParserExpression function, | 1428 PreParserExpression PreParser::SpreadCallNew(PreParserExpression function, |
| 1431 PreParserExpressionList args, | 1429 PreParserExpressionList args, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1462 function_state_->NextMaterializedLiteralIndex(); | 1460 function_state_->NextMaterializedLiteralIndex(); |
| 1463 function_state_->NextMaterializedLiteralIndex(); | 1461 function_state_->NextMaterializedLiteralIndex(); |
| 1464 } | 1462 } |
| 1465 return EmptyExpression(); | 1463 return EmptyExpression(); |
| 1466 } | 1464 } |
| 1467 | 1465 |
| 1468 } // namespace internal | 1466 } // namespace internal |
| 1469 } // namespace v8 | 1467 } // namespace v8 |
| 1470 | 1468 |
| 1471 #endif // V8_PARSING_PREPARSER_H | 1469 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |