| 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 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 typedef PreParserExpression Expression; | 831 typedef PreParserExpression Expression; |
| 832 typedef PreParserStatement Statement; | 832 typedef PreParserStatement Statement; |
| 833 | 833 |
| 834 enum PreParseResult { | 834 enum PreParseResult { |
| 835 kPreParseStackOverflow, | 835 kPreParseStackOverflow, |
| 836 kPreParseAbort, | 836 kPreParseAbort, |
| 837 kPreParseSuccess | 837 kPreParseSuccess |
| 838 }; | 838 }; |
| 839 | 839 |
| 840 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory, | 840 PreParser(Zone* zone, Scanner* scanner, AstValueFactory* ast_value_factory, |
| 841 ParserRecorder* log, uintptr_t stack_limit) | 841 uintptr_t stack_limit) |
| 842 : ParserBase<PreParser>(zone, scanner, stack_limit, NULL, | 842 : ParserBase<PreParser>(zone, scanner, stack_limit, nullptr, |
| 843 ast_value_factory, log), | 843 ast_value_factory), |
| 844 use_counts_(nullptr), | 844 use_counts_(nullptr), |
| 845 track_unresolved_variables_(false) {} | 845 track_unresolved_variables_(false) {} |
| 846 | 846 |
| 847 SingletonLogger* logger() { return &log_; } |
| 848 |
| 847 // Pre-parse the program from the character stream; returns true on | 849 // Pre-parse the program from the character stream; returns true on |
| 848 // success (even if parsing failed, the pre-parse data successfully | 850 // success (even if parsing failed, the pre-parse data successfully |
| 849 // captured the syntax error), and false if a stack-overflow happened | 851 // captured the syntax error), and false if a stack-overflow happened |
| 850 // during parsing. | 852 // during parsing. |
| 851 PreParseResult PreParseProgram(int* materialized_literals = 0, | 853 PreParseResult PreParseProgram(int* materialized_literals = 0, |
| 852 bool is_module = false) { | 854 bool is_module = false) { |
| 853 DCHECK_NULL(scope_state_); | 855 DCHECK_NULL(scope_state_); |
| 854 DeclarationScope* scope = NewScriptScope(); | 856 DeclarationScope* scope = NewScriptScope(); |
| 855 | 857 |
| 856 // ModuleDeclarationInstantiation for Source Text Module Records creates a | 858 // ModuleDeclarationInstantiation for Source Text Module Records creates a |
| (...skipping 25 matching lines...) Expand all Loading... |
| 882 // Parses a single function literal, from the opening parentheses before | 884 // Parses a single function literal, from the opening parentheses before |
| 883 // parameters to the closing brace after the body. | 885 // parameters to the closing brace after the body. |
| 884 // Returns a FunctionEntry describing the body of the function in enough | 886 // Returns a FunctionEntry describing the body of the function in enough |
| 885 // detail that it can be lazily compiled. | 887 // detail that it can be lazily compiled. |
| 886 // The scanner is expected to have matched the "function" or "function*" | 888 // The scanner is expected to have matched the "function" or "function*" |
| 887 // keyword and parameters, and have consumed the initial '{'. | 889 // keyword and parameters, and have consumed the initial '{'. |
| 888 // At return, unless an error occurred, the scanner is positioned before the | 890 // At return, unless an error occurred, the scanner is positioned before the |
| 889 // the final '}'. | 891 // the final '}'. |
| 890 PreParseResult PreParseFunction(FunctionKind kind, | 892 PreParseResult PreParseFunction(FunctionKind kind, |
| 891 DeclarationScope* function_scope, | 893 DeclarationScope* function_scope, |
| 892 bool parsing_module, SingletonLogger* log, | 894 bool parsing_module, |
| 893 bool track_unresolved_variables, | 895 bool track_unresolved_variables, |
| 894 bool may_abort, int* use_counts); | 896 bool may_abort, int* use_counts); |
| 895 | 897 |
| 896 private: | 898 private: |
| 897 // These types form an algebra over syntactic categories that is just | 899 // These types form an algebra over syntactic categories that is just |
| 898 // rich enough to let us recognize and propagate the constructs that | 900 // rich enough to let us recognize and propagate the constructs that |
| 899 // are either being counted in the preparser data, or is important | 901 // are either being counted in the preparser data, or is important |
| 900 // to throw the correct syntax error exceptions. | 902 // to throw the correct syntax error exceptions. |
| 901 | 903 |
| 902 // All ParseXXX functions take as the last argument an *ok parameter | 904 // All ParseXXX functions take as the last argument an *ok parameter |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 V8_INLINE PreParserExpression NewThrowTypeError( | 1263 V8_INLINE PreParserExpression NewThrowTypeError( |
| 1262 MessageTemplate::Template message, PreParserIdentifier arg, int pos) { | 1264 MessageTemplate::Template message, PreParserIdentifier arg, int pos) { |
| 1263 return PreParserExpression::Default(); | 1265 return PreParserExpression::Default(); |
| 1264 } | 1266 } |
| 1265 | 1267 |
| 1266 // Reporting errors. | 1268 // Reporting errors. |
| 1267 V8_INLINE void ReportMessageAt(Scanner::Location source_location, | 1269 V8_INLINE void ReportMessageAt(Scanner::Location source_location, |
| 1268 MessageTemplate::Template message, | 1270 MessageTemplate::Template message, |
| 1269 const char* arg = NULL, | 1271 const char* arg = NULL, |
| 1270 ParseErrorType error_type = kSyntaxError) { | 1272 ParseErrorType error_type = kSyntaxError) { |
| 1271 log_->LogMessage(source_location.beg_pos, source_location.end_pos, message, | 1273 log_.LogMessage(source_location.beg_pos, source_location.end_pos, message, |
| 1272 arg, error_type); | 1274 arg, error_type); |
| 1273 } | 1275 } |
| 1274 | 1276 |
| 1275 V8_INLINE void ReportMessageAt(Scanner::Location source_location, | 1277 V8_INLINE void ReportMessageAt(Scanner::Location source_location, |
| 1276 MessageTemplate::Template message, | 1278 MessageTemplate::Template message, |
| 1277 PreParserIdentifier arg, | 1279 PreParserIdentifier arg, |
| 1278 ParseErrorType error_type = kSyntaxError) { | 1280 ParseErrorType error_type = kSyntaxError) { |
| 1279 UNREACHABLE(); | 1281 UNREACHABLE(); |
| 1280 } | 1282 } |
| 1281 | 1283 |
| 1282 // "null" return type creators. | 1284 // "null" return type creators. |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1495 } | 1497 } |
| 1496 | 1498 |
| 1497 V8_INLINE void CountUsage(v8::Isolate::UseCounterFeature feature) { | 1499 V8_INLINE void CountUsage(v8::Isolate::UseCounterFeature feature) { |
| 1498 if (use_counts_ != nullptr) ++use_counts_[feature]; | 1500 if (use_counts_ != nullptr) ++use_counts_[feature]; |
| 1499 } | 1501 } |
| 1500 | 1502 |
| 1501 // Preparser's private field members. | 1503 // Preparser's private field members. |
| 1502 | 1504 |
| 1503 int* use_counts_; | 1505 int* use_counts_; |
| 1504 bool track_unresolved_variables_; | 1506 bool track_unresolved_variables_; |
| 1507 SingletonLogger log_; |
| 1505 }; | 1508 }; |
| 1506 | 1509 |
| 1507 PreParserExpression PreParser::SpreadCall(PreParserExpression function, | 1510 PreParserExpression PreParser::SpreadCall(PreParserExpression function, |
| 1508 PreParserExpressionList args, | 1511 PreParserExpressionList args, |
| 1509 int pos) { | 1512 int pos) { |
| 1510 return factory()->NewCall(function, args, pos); | 1513 return factory()->NewCall(function, args, pos); |
| 1511 } | 1514 } |
| 1512 | 1515 |
| 1513 PreParserExpression PreParser::SpreadCallNew(PreParserExpression function, | 1516 PreParserExpression PreParser::SpreadCallNew(PreParserExpression function, |
| 1514 PreParserExpressionList args, | 1517 PreParserExpressionList args, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1545 function_state_->NextMaterializedLiteralIndex(); | 1548 function_state_->NextMaterializedLiteralIndex(); |
| 1546 function_state_->NextMaterializedLiteralIndex(); | 1549 function_state_->NextMaterializedLiteralIndex(); |
| 1547 } | 1550 } |
| 1548 return EmptyExpression(); | 1551 return EmptyExpression(); |
| 1549 } | 1552 } |
| 1550 | 1553 |
| 1551 } // namespace internal | 1554 } // namespace internal |
| 1552 } // namespace v8 | 1555 } // namespace v8 |
| 1553 | 1556 |
| 1554 #endif // V8_PARSING_PREPARSER_H | 1557 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |