| 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/hashmap.h" | 10 #include "src/hashmap.h" |
| (...skipping 1201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1212 V8_INLINE PreParserExpression ParseDoExpression(bool* ok); | 1212 V8_INLINE PreParserExpression ParseDoExpression(bool* ok); |
| 1213 PreParserExpression ParseFunctionLiteral( | 1213 PreParserExpression ParseFunctionLiteral( |
| 1214 PreParserIdentifier name, Scanner::Location function_name_location, | 1214 PreParserIdentifier name, Scanner::Location function_name_location, |
| 1215 FunctionNameValidity function_name_validity, FunctionKind kind, | 1215 FunctionNameValidity function_name_validity, FunctionKind kind, |
| 1216 int function_token_position, FunctionLiteral::FunctionType type, | 1216 int function_token_position, FunctionLiteral::FunctionType type, |
| 1217 LanguageMode language_mode, typesystem::TypeFlags type_flags, bool* ok); | 1217 LanguageMode language_mode, typesystem::TypeFlags type_flags, bool* ok); |
| 1218 | 1218 |
| 1219 PreParserExpression ParseClassLiteral(PreParserIdentifier name, | 1219 PreParserExpression ParseClassLiteral(PreParserIdentifier name, |
| 1220 Scanner::Location class_name_location, | 1220 Scanner::Location class_name_location, |
| 1221 bool name_is_strict_reserved, int pos, | 1221 bool name_is_strict_reserved, int pos, |
| 1222 bool* ok); | 1222 bool ambient, bool* ok); |
| 1223 | 1223 |
| 1224 PreParserExpressionList PrepareSpreadArguments(PreParserExpressionList list) { | 1224 PreParserExpressionList PrepareSpreadArguments(PreParserExpressionList list) { |
| 1225 return list; | 1225 return list; |
| 1226 } | 1226 } |
| 1227 | 1227 |
| 1228 inline void MaterializeUnspreadArgumentsLiterals(int count); | 1228 inline void MaterializeUnspreadArgumentsLiterals(int count); |
| 1229 | 1229 |
| 1230 inline PreParserExpression SpreadCall(PreParserExpression function, | 1230 inline PreParserExpression SpreadCall(PreParserExpression function, |
| 1231 PreParserExpressionList args, int pos); | 1231 PreParserExpressionList args, int pos); |
| 1232 | 1232 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1303 // success (even if parsing failed, the pre-parse data successfully | 1303 // success (even if parsing failed, the pre-parse data successfully |
| 1304 // captured the syntax error), and false if a stack-overflow happened | 1304 // captured the syntax error), and false if a stack-overflow happened |
| 1305 // during parsing. | 1305 // during parsing. |
| 1306 PreParseResult PreParseProgram(int* materialized_literals = 0) { | 1306 PreParseResult PreParseProgram(int* materialized_literals = 0) { |
| 1307 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); | 1307 Scope* scope = NewScope(scope_, SCRIPT_SCOPE); |
| 1308 PreParserFactory factory(NULL); | 1308 PreParserFactory factory(NULL); |
| 1309 FunctionState top_scope(&function_state_, &scope_, scope, kNormalFunction, | 1309 FunctionState top_scope(&function_state_, &scope_, scope, kNormalFunction, |
| 1310 &factory); | 1310 &factory); |
| 1311 bool ok = true; | 1311 bool ok = true; |
| 1312 int start_position = scanner()->peek_location().beg_pos; | 1312 int start_position = scanner()->peek_location().beg_pos; |
| 1313 ParseStatementList(Token::EOS, &ok); | 1313 ParseStatementList(Token::EOS, true, &ok); |
| 1314 if (stack_overflow()) return kPreParseStackOverflow; | 1314 if (stack_overflow()) return kPreParseStackOverflow; |
| 1315 if (!ok) { | 1315 if (!ok) { |
| 1316 ReportUnexpectedToken(scanner()->current_token()); | 1316 ReportUnexpectedToken(scanner()->current_token()); |
| 1317 } else if (is_strict(scope_->language_mode())) { | 1317 } else if (is_strict(scope_->language_mode())) { |
| 1318 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, | 1318 CheckStrictOctalLiteral(start_position, scanner()->location().end_pos, |
| 1319 &ok); | 1319 &ok); |
| 1320 } | 1320 } |
| 1321 if (materialized_literals) { | 1321 if (materialized_literals) { |
| 1322 *materialized_literals = function_state_->materialized_literal_count(); | 1322 *materialized_literals = function_state_->materialized_literal_count(); |
| 1323 } | 1323 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1343 | 1343 |
| 1344 // These types form an algebra over syntactic categories that is just | 1344 // These types form an algebra over syntactic categories that is just |
| 1345 // rich enough to let us recognize and propagate the constructs that | 1345 // rich enough to let us recognize and propagate the constructs that |
| 1346 // are either being counted in the preparser data, or is important | 1346 // are either being counted in the preparser data, or is important |
| 1347 // to throw the correct syntax error exceptions. | 1347 // to throw the correct syntax error exceptions. |
| 1348 | 1348 |
| 1349 // All ParseXXX functions take as the last argument an *ok parameter | 1349 // All ParseXXX functions take as the last argument an *ok parameter |
| 1350 // which is set to false if parsing failed; it is unchanged otherwise. | 1350 // which is set to false if parsing failed; it is unchanged otherwise. |
| 1351 // By making the 'exception handling' explicit, we are forced to check | 1351 // By making the 'exception handling' explicit, we are forced to check |
| 1352 // for failure at the call sites. | 1352 // for failure at the call sites. |
| 1353 Statement ParseStatementListItem(bool* ok); | 1353 Statement ParseStatementListItem(bool top_level, bool* ok); |
| 1354 void ParseStatementList(int end_token, bool* ok, | 1354 void ParseStatementList(int end_token, bool top_level, bool* ok, |
| 1355 Scanner::BookmarkScope* bookmark = nullptr); | 1355 Scanner::BookmarkScope* bookmark = nullptr); |
| 1356 Statement ParseStatement(AllowLabelledFunctionStatement allow_function, | 1356 Statement ParseStatement(AllowLabelledFunctionStatement allow_function, |
| 1357 bool* ok); | 1357 bool* ok); |
| 1358 Statement ParseSubStatement(AllowLabelledFunctionStatement allow_function, | 1358 Statement ParseSubStatement(AllowLabelledFunctionStatement allow_function, |
| 1359 bool* ok); | 1359 bool* ok); |
| 1360 Statement ParseScopedStatement(bool legacy, bool* ok); | 1360 Statement ParseScopedStatement(bool legacy, bool* ok); |
| 1361 Statement ParseFunctionDeclaration(bool* ok); | 1361 Statement ParseFunctionDeclaration(bool ambient, bool* ok); |
| 1362 Statement ParseClassDeclaration(bool* ok); | 1362 Statement ParseClassDeclaration(bool ambient, bool* ok); |
| 1363 Statement ParseBlock(bool* ok); | 1363 Statement ParseBlock(bool* ok); |
| 1364 Statement ParseVariableStatement(VariableDeclarationContext var_context, | 1364 Statement ParseVariableStatement(VariableDeclarationContext var_context, |
| 1365 bool* ok); | 1365 bool ambient, bool* ok); |
| 1366 Statement ParseVariableDeclarations(VariableDeclarationContext var_context, | 1366 Statement ParseVariableDeclarations(VariableDeclarationContext var_context, |
| 1367 int* num_decl, bool* is_lexical, | 1367 int* num_decl, bool* is_lexical, |
| 1368 bool* is_binding_pattern, | 1368 bool* is_binding_pattern, |
| 1369 Scanner::Location* first_initializer_loc, | 1369 Scanner::Location* first_initializer_loc, |
| 1370 Scanner::Location* bindings_loc, | 1370 Scanner::Location* bindings_loc, |
| 1371 bool* ok); | 1371 bool ambient, bool* ok); |
| 1372 Statement ParseExpressionOrLabelledStatement( | 1372 Statement ParseExpressionOrLabelledStatement( |
| 1373 AllowLabelledFunctionStatement allow_function, bool* ok); | 1373 AllowLabelledFunctionStatement allow_function, bool* ok); |
| 1374 Statement ParseIfStatement(bool* ok); | 1374 Statement ParseIfStatement(bool* ok); |
| 1375 Statement ParseContinueStatement(bool* ok); | 1375 Statement ParseContinueStatement(bool* ok); |
| 1376 Statement ParseBreakStatement(bool* ok); | 1376 Statement ParseBreakStatement(bool* ok); |
| 1377 Statement ParseReturnStatement(bool* ok); | 1377 Statement ParseReturnStatement(bool* ok); |
| 1378 Statement ParseWithStatement(bool* ok); | 1378 Statement ParseWithStatement(bool* ok); |
| 1379 Statement ParseSwitchStatement(bool* ok); | 1379 Statement ParseSwitchStatement(bool* ok); |
| 1380 Statement ParseDoWhileStatement(bool* ok); | 1380 Statement ParseDoWhileStatement(bool* ok); |
| 1381 Statement ParseWhileStatement(bool* ok); | 1381 Statement ParseWhileStatement(bool* ok); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1401 FunctionKind kind, int function_token_pos, | 1401 FunctionKind kind, int function_token_pos, |
| 1402 FunctionLiteral::FunctionType function_type, | 1402 FunctionLiteral::FunctionType function_type, |
| 1403 LanguageMode language_mode, | 1403 LanguageMode language_mode, |
| 1404 typesystem::TypeFlags type_flags, bool* ok); | 1404 typesystem::TypeFlags type_flags, bool* ok); |
| 1405 void ParseLazyFunctionLiteralBody(bool* ok, | 1405 void ParseLazyFunctionLiteralBody(bool* ok, |
| 1406 Scanner::BookmarkScope* bookmark = nullptr); | 1406 Scanner::BookmarkScope* bookmark = nullptr); |
| 1407 | 1407 |
| 1408 PreParserExpression ParseClassLiteral(PreParserIdentifier name, | 1408 PreParserExpression ParseClassLiteral(PreParserIdentifier name, |
| 1409 Scanner::Location class_name_location, | 1409 Scanner::Location class_name_location, |
| 1410 bool name_is_strict_reserved, int pos, | 1410 bool name_is_strict_reserved, int pos, |
| 1411 bool* ok); | 1411 bool ambient, bool* ok); |
| 1412 }; | 1412 }; |
| 1413 | 1413 |
| 1414 | 1414 |
| 1415 void PreParserTraits::MaterializeTemplateCallsiteLiterals() { | 1415 void PreParserTraits::MaterializeTemplateCallsiteLiterals() { |
| 1416 pre_parser_->function_state_->NextMaterializedLiteralIndex(); | 1416 pre_parser_->function_state_->NextMaterializedLiteralIndex(); |
| 1417 pre_parser_->function_state_->NextMaterializedLiteralIndex(); | 1417 pre_parser_->function_state_->NextMaterializedLiteralIndex(); |
| 1418 } | 1418 } |
| 1419 | 1419 |
| 1420 | 1420 |
| 1421 void PreParserTraits::MaterializeUnspreadArgumentsLiterals(int count) { | 1421 void PreParserTraits::MaterializeUnspreadArgumentsLiterals(int count) { |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1478 int pos) { | 1478 int pos) { |
| 1479 return PreParserExpression::Default(); | 1479 return PreParserExpression::Default(); |
| 1480 } | 1480 } |
| 1481 | 1481 |
| 1482 PreParserStatementList PreParser::ParseEagerFunctionBody( | 1482 PreParserStatementList PreParser::ParseEagerFunctionBody( |
| 1483 PreParserIdentifier function_name, int pos, | 1483 PreParserIdentifier function_name, int pos, |
| 1484 const PreParserFormalParameters& parameters, FunctionKind kind, | 1484 const PreParserFormalParameters& parameters, FunctionKind kind, |
| 1485 FunctionLiteral::FunctionType function_type, bool* ok) { | 1485 FunctionLiteral::FunctionType function_type, bool* ok) { |
| 1486 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); | 1486 ParsingModeScope parsing_mode(this, PARSE_EAGERLY); |
| 1487 | 1487 |
| 1488 ParseStatementList(Token::RBRACE, ok); | 1488 ParseStatementList(Token::RBRACE, false, ok); |
| 1489 if (!*ok) return PreParserStatementList(); | 1489 if (!*ok) return PreParserStatementList(); |
| 1490 | 1490 |
| 1491 Expect(Token::RBRACE, ok); | 1491 Expect(Token::RBRACE, ok); |
| 1492 return PreParserStatementList(); | 1492 return PreParserStatementList(); |
| 1493 } | 1493 } |
| 1494 | 1494 |
| 1495 | 1495 |
| 1496 PreParserStatementList PreParserTraits::ParseEagerFunctionBody( | 1496 PreParserStatementList PreParserTraits::ParseEagerFunctionBody( |
| 1497 PreParserIdentifier function_name, int pos, | 1497 PreParserIdentifier function_name, int pos, |
| 1498 const PreParserFormalParameters& parameters, FunctionKind kind, | 1498 const PreParserFormalParameters& parameters, FunctionKind kind, |
| 1499 FunctionLiteral::FunctionType function_type, bool* ok) { | 1499 FunctionLiteral::FunctionType function_type, bool* ok) { |
| 1500 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, | 1500 return pre_parser_->ParseEagerFunctionBody(function_name, pos, parameters, |
| 1501 kind, function_type, ok); | 1501 kind, function_type, ok); |
| 1502 } | 1502 } |
| 1503 | 1503 |
| 1504 } // namespace internal | 1504 } // namespace internal |
| 1505 } // namespace v8 | 1505 } // namespace v8 |
| 1506 | 1506 |
| 1507 #endif // V8_PARSING_PREPARSER_H | 1507 #endif // V8_PARSING_PREPARSER_H |
| OLD | NEW |