| 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/bailout-reason.h" | 9 #include "src/bailout-reason.h" |
| 10 #include "src/base/hashmap.h" | 10 #include "src/base/hashmap.h" |
| (...skipping 1019 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 : ParserBase<PreParserTraits>(zone, scanner, stack_limit, NULL, | 1030 : ParserBase<PreParserTraits>(zone, scanner, stack_limit, NULL, |
| 1031 ast_value_factory, log, this), | 1031 ast_value_factory, log, this), |
| 1032 use_counts_(nullptr) {} | 1032 use_counts_(nullptr) {} |
| 1033 | 1033 |
| 1034 // Pre-parse the program from the character stream; returns true on | 1034 // Pre-parse the program from the character stream; returns true on |
| 1035 // success (even if parsing failed, the pre-parse data successfully | 1035 // success (even if parsing failed, the pre-parse data successfully |
| 1036 // captured the syntax error), and false if a stack-overflow happened | 1036 // captured the syntax error), and false if a stack-overflow happened |
| 1037 // during parsing. | 1037 // during parsing. |
| 1038 PreParseResult PreParseProgram(int* materialized_literals = 0, | 1038 PreParseResult PreParseProgram(int* materialized_literals = 0, |
| 1039 bool is_module = false) { | 1039 bool is_module = false) { |
| 1040 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); | 1040 DCHECK_NULL(scope_state_); |
| 1041 Scope* scope = NewScope(nullptr, SCRIPT_SCOPE); |
| 1041 | 1042 |
| 1042 // ModuleDeclarationInstantiation for Source Text Module Records creates a | 1043 // ModuleDeclarationInstantiation for Source Text Module Records creates a |
| 1043 // new Module Environment Record whose outer lexical environment record is | 1044 // new Module Environment Record whose outer lexical environment record is |
| 1044 // the global scope. | 1045 // the global scope. |
| 1045 if (is_module) { | 1046 if (is_module) { |
| 1046 scope = NewScope(scope, MODULE_SCOPE); | 1047 scope = NewScope(scope, MODULE_SCOPE); |
| 1047 } | 1048 } |
| 1048 | 1049 |
| 1049 PreParserFactory factory(NULL); | 1050 PreParserFactory factory(nullptr); |
| 1050 FunctionState top_scope(&function_state_, &scope_, scope, kNormalFunction, | 1051 FunctionState top_scope(&function_state_, &scope_state_, scope, |
| 1051 &factory); | 1052 kNormalFunction, &factory); |
| 1052 bool ok = true; | 1053 bool ok = true; |
| 1053 int start_position = scanner()->peek_location().beg_pos; | 1054 int start_position = scanner()->peek_location().beg_pos; |
| 1054 parsing_module_ = is_module; | 1055 parsing_module_ = is_module; |
| 1055 ParseStatementList(Token::EOS, &ok); | 1056 ParseStatementList(Token::EOS, &ok); |
| 1056 if (stack_overflow()) return kPreParseStackOverflow; | 1057 if (stack_overflow()) return kPreParseStackOverflow; |
| 1057 if (!ok) { | 1058 if (!ok) { |
| 1058 ReportUnexpectedToken(scanner()->current_token()); | 1059 ReportUnexpectedToken(scanner()->current_token()); |
| 1059 } else if (is_strict(scope_->language_mode())) { | 1060 } else if (is_strict(this->scope()->language_mode())) { |
| 1060 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, | 1061 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, |
| 1061 &ok); | 1062 &ok); |
| 1062 CheckDecimalLiteralWithLeadingZero(use_counts_, start_position, | 1063 CheckDecimalLiteralWithLeadingZero(use_counts_, start_position, |
| 1063 scanner()->location().end_pos); | 1064 scanner()->location().end_pos); |
| 1064 } | 1065 } |
| 1065 if (materialized_literals) { | 1066 if (materialized_literals) { |
| 1066 *materialized_literals = function_state_->materialized_literal_count(); | 1067 *materialized_literals = function_state_->materialized_literal_count(); |
| 1067 } | 1068 } |
| 1068 return kPreParseSuccess; | 1069 return kPreParseSuccess; |
| 1069 } | 1070 } |
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1238 PreParserExpression generator, PreParserExpression expression, int pos) { | 1239 PreParserExpression generator, PreParserExpression expression, int pos) { |
| 1239 return PreParserExpression::Default(); | 1240 return PreParserExpression::Default(); |
| 1240 } | 1241 } |
| 1241 | 1242 |
| 1242 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1243 PreParserStatementList PreParser::ParseEagerFunctionBody( |
| 1243 PreParserIdentifier function_name, int pos, | 1244 PreParserIdentifier function_name, int pos, |
| 1244 const PreParserFormalParameters& parameters, FunctionKind kind, | 1245 const PreParserFormalParameters& parameters, FunctionKind kind, |
| 1245 FunctionLiteral::FunctionType function_type, bool* ok) { | 1246 FunctionLiteral::FunctionType function_type, bool* ok) { |
| 1246 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 1247 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
| 1247 | 1248 |
| 1248 Scope* inner_scope = scope_; | 1249 Scope* inner_scope = scope(); |
| 1249 if (!parameters.is_simple) inner_scope = NewScope(scope_, BLOCK_SCOPE); | 1250 if (!parameters.is_simple) inner_scope = NewScope(scope(), BLOCK_SCOPE); |
| 1250 | 1251 |
| 1251 { | 1252 { |
| 1252 BlockState block_state(&scope_, inner_scope); | 1253 BlockState block_state(&scope_state_, inner_scope); |
| 1253 ParseStatementList(Token::RBRACE, ok); | 1254 ParseStatementList(Token::RBRACE, ok); |
| 1254 if (!*ok) return PreParserStatementList(); | 1255 if (!*ok) return PreParserStatementList(); |
| 1255 } | 1256 } |
| 1256 | 1257 |
| 1257 Expect(Token::RBRACE, ok); | 1258 Expect(Token::RBRACE, ok); |
| 1258 return PreParserStatementList(); | 1259 return PreParserStatementList(); |
| 1259 } | 1260 } |
| 1260 | 1261 |
| 1261 | 1262 |
| 1262 PreParserStatementList PreParserTraits::ParseEagerFunctionBody( | 1263 PreParserStatementList PreParserTraits::ParseEagerFunctionBody( |
| 1263 PreParserIdentifier function_name, int pos, | 1264 PreParserIdentifier function_name, int pos, |
| 1264 const PreParserFormalParameters& parameters, FunctionKind kind, | 1265 const PreParserFormalParameters& parameters, FunctionKind kind, |
| 1265 FunctionLiteral::FunctionType function_type, bool* ok) { | 1266 FunctionLiteral::FunctionType function_type, bool* ok) { |
| 1266 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, | 1267 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, |
| 1267 kind, function_type, ok); | 1268 kind, function_type, ok); |
| 1268 } | 1269 } |
| 1269 | 1270 |
| 1270 } // namespace internal | 1271 } // namespace internal |
| 1271 } // namespace v8 | 1272 } // namespace v8 |
| 1272 | 1273 |
| 1273 #endif // V8_PARSING_PREPARSER_H | 1274 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |