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