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