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 1026 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 DCHECK_NULL(scope_state_); | 1040 DCHECK_NULL(scope_state_); |
1041 Scope* scope = NewScriptScope(); | 1041 Scope* scope = NewScriptScope(); |
1042 | 1042 |
1043 // ModuleDeclarationInstantiation for Source Text Module Records creates a | 1043 // ModuleDeclarationInstantiation for Source Text Module Records creates a |
1044 // new Module Environment Record whose outer lexical environment record is | 1044 // new Module Environment Record whose outer lexical environment record is |
1045 // the global scope. | 1045 // the global scope. |
1046 if (is_module) { | 1046 if (is_module) { |
1047 scope = NewScope(scope, MODULE_SCOPE); | 1047 scope = NewScopeWithParent(scope, MODULE_SCOPE); |
1048 } | 1048 } |
1049 | 1049 |
1050 PreParserFactory factory(nullptr); | 1050 PreParserFactory factory(nullptr); |
1051 FunctionState top_scope(&function_state_, &scope_state_, scope, | 1051 FunctionState top_scope(&function_state_, &scope_state_, scope, |
1052 kNormalFunction, &factory); | 1052 kNormalFunction, &factory); |
1053 bool ok = true; | 1053 bool ok = true; |
1054 int start_position = scanner()->peek_location().beg_pos; | 1054 int start_position = scanner()->peek_location().beg_pos; |
1055 parsing_module_ = is_module; | 1055 parsing_module_ = is_module; |
1056 ParseStatementList(Token::EOS, &ok); | 1056 ParseStatementList(Token::EOS, &ok); |
1057 if (stack_overflow()) return kPreParseStackOverflow; | 1057 if (stack_overflow()) return kPreParseStackOverflow; |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1240 return PreParserExpression::Default(); | 1240 return PreParserExpression::Default(); |
1241 } | 1241 } |
1242 | 1242 |
1243 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1243 PreParserStatementList PreParser::ParseEagerFunctionBody( |
1244 PreParserIdentifier function_name, int pos, | 1244 PreParserIdentifier function_name, int pos, |
1245 const PreParserFormalParameters& parameters, FunctionKind kind, | 1245 const PreParserFormalParameters& parameters, FunctionKind kind, |
1246 FunctionLiteral::FunctionType function_type, bool* ok) { | 1246 FunctionLiteral::FunctionType function_type, bool* ok) { |
1247 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 1247 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
1248 | 1248 |
1249 Scope* inner_scope = scope(); | 1249 Scope* inner_scope = scope(); |
1250 if (!parameters.is_simple) inner_scope = NewScope(scope(), BLOCK_SCOPE); | 1250 if (!parameters.is_simple) inner_scope = NewScope(BLOCK_SCOPE); |
1251 | 1251 |
1252 { | 1252 { |
1253 BlockState block_state(&scope_state_, inner_scope); | 1253 BlockState block_state(&scope_state_, inner_scope); |
1254 ParseStatementList(Token::RBRACE, ok); | 1254 ParseStatementList(Token::RBRACE, ok); |
1255 if (!*ok) return PreParserStatementList(); | 1255 if (!*ok) return PreParserStatementList(); |
1256 } | 1256 } |
1257 | 1257 |
1258 Expect(Token::RBRACE, ok); | 1258 Expect(Token::RBRACE, ok); |
1259 return PreParserStatementList(); | 1259 return PreParserStatementList(); |
1260 } | 1260 } |
1261 | 1261 |
1262 | 1262 |
1263 PreParserStatementList PreParserTraits::ParseEagerFunctionBody( | 1263 PreParserStatementList PreParserTraits::ParseEagerFunctionBody( |
1264 PreParserIdentifier function_name, int pos, | 1264 PreParserIdentifier function_name, int pos, |
1265 const PreParserFormalParameters& parameters, FunctionKind kind, | 1265 const PreParserFormalParameters& parameters, FunctionKind kind, |
1266 FunctionLiteral::FunctionType function_type, bool* ok) { | 1266 FunctionLiteral::FunctionType function_type, bool* ok) { |
1267 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, | 1267 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, |
1268 kind, function_type, ok); | 1268 kind, function_type, ok); |
1269 } | 1269 } |
1270 | 1270 |
1271 } // namespace internal | 1271 } // namespace internal |
1272 } // namespace v8 | 1272 } // namespace v8 |
1273 | 1273 |
1274 #endif // V8_PARSING_PREPARSER_H | 1274 #endif // V8_PARSING_PREPARSER_H |
OLD | NEW |