| 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_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
| 6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/func-name-inferrer.h" | 10 #include "src/func-name-inferrer.h" |
| (...skipping 993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1004 } | 1004 } |
| 1005 PreParserExpression NewFunctionLiteral( | 1005 PreParserExpression NewFunctionLiteral( |
| 1006 PreParserIdentifier name, AstValueFactory* ast_value_factory, | 1006 PreParserIdentifier name, AstValueFactory* ast_value_factory, |
| 1007 const PreParserScope& scope, PreParserStatementList body, | 1007 const PreParserScope& scope, PreParserStatementList body, |
| 1008 int materialized_literal_count, int expected_property_count, | 1008 int materialized_literal_count, int expected_property_count, |
| 1009 int handler_count, int parameter_count, | 1009 int handler_count, int parameter_count, |
| 1010 FunctionLiteral::ParameterFlag has_duplicate_parameters, | 1010 FunctionLiteral::ParameterFlag has_duplicate_parameters, |
| 1011 FunctionLiteral::FunctionType function_type, | 1011 FunctionLiteral::FunctionType function_type, |
| 1012 FunctionLiteral::IsFunctionFlag is_function, | 1012 FunctionLiteral::IsFunctionFlag is_function, |
| 1013 FunctionLiteral::IsParenthesizedFlag is_parenthesized, | 1013 FunctionLiteral::IsParenthesizedFlag is_parenthesized, |
| 1014 FunctionLiteral::IsGeneratorFlag is_generator, int position) { | 1014 FunctionLiteral::KindFlag kind, int position) { |
| 1015 return PreParserExpression::Default(); | 1015 return PreParserExpression::Default(); |
| 1016 } | 1016 } |
| 1017 | 1017 |
| 1018 // Return the object itself as AstVisitor and implement the needed | 1018 // Return the object itself as AstVisitor and implement the needed |
| 1019 // dummy method right in this class. | 1019 // dummy method right in this class. |
| 1020 PreParserFactory* visitor() { return this; } | 1020 PreParserFactory* visitor() { return this; } |
| 1021 BailoutReason dont_optimize_reason() { return kNoReason; } | 1021 BailoutReason dont_optimize_reason() { return kNoReason; } |
| 1022 int* ast_properties() { | 1022 int* ast_properties() { |
| 1023 static int dummy = 42; | 1023 static int dummy = 42; |
| 1024 return &dummy; | 1024 return &dummy; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 // operations interleaved with the recursive descent. | 1106 // operations interleaved with the recursive descent. |
| 1107 static void PushLiteralName(FuncNameInferrer* fni, PreParserIdentifier id) { | 1107 static void PushLiteralName(FuncNameInferrer* fni, PreParserIdentifier id) { |
| 1108 // PreParser should not use FuncNameInferrer. | 1108 // PreParser should not use FuncNameInferrer. |
| 1109 UNREACHABLE(); | 1109 UNREACHABLE(); |
| 1110 } | 1110 } |
| 1111 static void PushPropertyName(FuncNameInferrer* fni, | 1111 static void PushPropertyName(FuncNameInferrer* fni, |
| 1112 PreParserExpression expression) { | 1112 PreParserExpression expression) { |
| 1113 // PreParser should not use FuncNameInferrer. | 1113 // PreParser should not use FuncNameInferrer. |
| 1114 UNREACHABLE(); | 1114 UNREACHABLE(); |
| 1115 } | 1115 } |
| 1116 static void InferFunctionName(FuncNameInferrer* fni, |
| 1117 PreParserExpression expression) { |
| 1118 // PreParser should not use FuncNameInferrer. |
| 1119 UNREACHABLE(); |
| 1120 } |
| 1116 | 1121 |
| 1117 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( | 1122 static void CheckFunctionLiteralInsideTopLevelObjectLiteral( |
| 1118 PreParserScope* scope, PreParserExpression value, bool* has_function) {} | 1123 PreParserScope* scope, PreParserExpression value, bool* has_function) {} |
| 1119 | 1124 |
| 1120 static void CheckAssigningFunctionLiteralToProperty( | 1125 static void CheckAssigningFunctionLiteralToProperty( |
| 1121 PreParserExpression left, PreParserExpression right) {} | 1126 PreParserExpression left, PreParserExpression right) {} |
| 1122 | 1127 |
| 1123 // PreParser doesn't need to keep track of eval calls. | 1128 // PreParser doesn't need to keep track of eval calls. |
| 1124 static void CheckPossibleEvalCall(PreParserExpression expression, | 1129 static void CheckPossibleEvalCall(PreParserExpression expression, |
| 1125 PreParserScope* scope) {} | 1130 PreParserScope* scope) {} |
| (...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2483 | 2488 |
| 2484 template <class Traits> | 2489 template <class Traits> |
| 2485 typename ParserBase<Traits>::ExpressionT | 2490 typename ParserBase<Traits>::ExpressionT |
| 2486 ParserBase<Traits>::ParseArrowFunctionLiteralBody( | 2491 ParserBase<Traits>::ParseArrowFunctionLiteralBody( |
| 2487 FunctionState* function_state, typename Traits::Type::ScopePtr scope, | 2492 FunctionState* function_state, typename Traits::Type::ScopePtr scope, |
| 2488 int num_parameters, const Scanner::Location& eval_args_error_loc, | 2493 int num_parameters, const Scanner::Location& eval_args_error_loc, |
| 2489 const Scanner::Location& dupe_error_loc, | 2494 const Scanner::Location& dupe_error_loc, |
| 2490 const Scanner::Location& reserved_loc, | 2495 const Scanner::Location& reserved_loc, |
| 2491 FunctionLiteral::IsParenthesizedFlag parenthesized, int start_pos, | 2496 FunctionLiteral::IsParenthesizedFlag parenthesized, int start_pos, |
| 2492 bool* ok) { | 2497 bool* ok) { |
| 2498 typename Traits::Type::StatementList body; |
| 2499 typename Traits::Type::AstProperties ast_properties; |
| 2500 FunctionLiteral::ParameterFlag duplicate_parameters = |
| 2501 dupe_error_loc.IsValid() ? FunctionLiteral::kHasDuplicateParameters |
| 2502 : FunctionLiteral::kNoDuplicateParameters; |
| 2503 BailoutReason dont_optimize_reason = kNoReason; |
| 2493 int materialized_literal_count = -1; | 2504 int materialized_literal_count = -1; |
| 2494 int expected_property_count = -1; | 2505 int expected_property_count = -1; |
| 2506 int handler_count = 0; |
| 2495 | 2507 |
| 2496 Expect(Token::ARROW, CHECK_OK); | 2508 Expect(Token::ARROW, CHECK_OK); |
| 2497 | 2509 |
| 2498 if (peek() == Token::LBRACE) { | 2510 if (peek() == Token::LBRACE) { |
| 2499 // Multiple statemente body | 2511 // Multiple statemente body |
| 2500 Consume(Token::LBRACE); | 2512 Consume(Token::LBRACE); |
| 2501 bool is_lazily_parsed = | 2513 bool is_lazily_parsed = |
| 2502 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); | 2514 (mode() == PARSE_LAZILY && scope_->AllowsLazyCompilation()); |
| 2503 if (is_lazily_parsed) { | 2515 if (is_lazily_parsed) { |
| 2504 this->SkipLazyFunctionBody(this->EmptyIdentifier(), | 2516 this->SkipLazyFunctionBody(this->EmptyIdentifier(), |
| 2505 &materialized_literal_count, | 2517 &materialized_literal_count, |
| 2506 &expected_property_count, CHECK_OK); | 2518 &expected_property_count, CHECK_OK); |
| 2507 } else { | 2519 } else { |
| 2508 this->ParseEagerFunctionBody(this->EmptyIdentifier(), | 2520 body = this->ParseEagerFunctionBody( |
| 2509 RelocInfo::kNoPosition, NULL, | 2521 this->EmptyIdentifier(), RelocInfo::kNoPosition, NULL, |
| 2510 Token::INIT_VAR, false, // Not a generator. | 2522 Token::INIT_VAR, false, // Not a generator. |
| 2511 CHECK_OK); | 2523 CHECK_OK); |
| 2524 materialized_literal_count = function_state->materialized_literal_count(); |
| 2525 expected_property_count = function_state->expected_property_count(); |
| 2526 handler_count = function_state->handler_count(); |
| 2512 } | 2527 } |
| 2513 } else { | 2528 } else { |
| 2514 // Single-expression body | 2529 // Single-expression body |
| 2515 ParseAssignmentExpression(true, CHECK_OK); | 2530 int pos = position(); |
| 2531 parenthesized_function_ = false; |
| 2532 ExpressionT expression = ParseAssignmentExpression(true, CHECK_OK); |
| 2533 body = this->NewStatementList(1, zone()); |
| 2534 body->Add(factory()->NewReturnStatement(expression, pos), zone()); |
| 2535 materialized_literal_count = function_state->materialized_literal_count(); |
| 2536 expected_property_count = function_state->expected_property_count(); |
| 2537 handler_count = function_state->handler_count(); |
| 2516 } | 2538 } |
| 2517 | 2539 |
| 2518 scope->set_start_position(start_pos); | 2540 scope->set_start_position(start_pos); |
| 2519 scope->set_end_position(scanner()->location().end_pos); | 2541 scope->set_end_position(scanner()->location().end_pos); |
| 2520 | 2542 |
| 2521 // Arrow function *parameter lists* are always checked as in strict mode. | 2543 // Arrow function *parameter lists* are always checked as in strict mode. |
| 2522 this->CheckStrictFunctionNameAndParameters( | 2544 this->CheckStrictFunctionNameAndParameters( |
| 2523 this->EmptyIdentifier(), false, Scanner::Location::invalid(), | 2545 this->EmptyIdentifier(), false, Scanner::Location::invalid(), |
| 2524 Scanner::Location::invalid(), dupe_error_loc, | 2546 Scanner::Location::invalid(), dupe_error_loc, |
| 2525 Scanner::Location::invalid(), CHECK_OK); | 2547 Scanner::Location::invalid(), CHECK_OK); |
| 2526 | 2548 |
| 2527 // Validate strict mode. | 2549 // Validate strict mode. |
| 2528 if (strict_mode() == STRICT) { | 2550 if (strict_mode() == STRICT) { |
| 2529 CheckOctalLiteral(start_pos, scanner()->location().end_pos, CHECK_OK); | 2551 CheckOctalLiteral(start_pos, scanner()->location().end_pos, CHECK_OK); |
| 2530 } | 2552 } |
| 2531 | 2553 |
| 2532 if (allow_harmony_scoping() && strict_mode() == STRICT) | 2554 if (allow_harmony_scoping() && strict_mode() == STRICT) |
| 2533 this->CheckConflictingVarDeclarations(scope, CHECK_OK); | 2555 this->CheckConflictingVarDeclarations(scope, CHECK_OK); |
| 2534 | 2556 |
| 2535 // TODO(aperez): Generate a proper FunctionLiteral instead of | 2557 ast_properties = *factory()->visitor()->ast_properties(); |
| 2536 // returning a dummy value. | 2558 dont_optimize_reason = factory()->visitor()->dont_optimize_reason(); |
| 2559 |
| 2537 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( | 2560 FunctionLiteralT function_literal = factory()->NewFunctionLiteral( |
| 2538 this->EmptyIdentifierString(), this->ast_value_factory(), scope, | 2561 this->EmptyIdentifierString(), this->ast_value_factory(), scope, body, |
| 2539 this->NewStatementList(0, zone()), 0, 0, 0, num_parameters, | 2562 materialized_literal_count, expected_property_count, handler_count, |
| 2540 FunctionLiteral::kNoDuplicateParameters, | 2563 num_parameters, duplicate_parameters, |
| 2541 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, | 2564 FunctionLiteral::ANONYMOUS_EXPRESSION, FunctionLiteral::kIsFunction, |
| 2542 FunctionLiteral::kNotParenthesized, FunctionLiteral::kNotGenerator, | 2565 parenthesized, FunctionLiteral::kArrowFunction, start_pos); |
| 2543 start_pos); | 2566 |
| 2544 function_literal->set_function_token_position(start_pos); | 2567 function_literal->set_function_token_position(start_pos); |
| 2568 function_literal->set_ast_properties(&ast_properties); |
| 2569 function_literal->set_dont_optimize_reason(dont_optimize_reason); |
| 2570 |
| 2571 if (fni_ != NULL) this->InferFunctionName(fni_, function_literal); |
| 2572 |
| 2545 return function_literal; | 2573 return function_literal; |
| 2546 } | 2574 } |
| 2547 | 2575 |
| 2548 | 2576 |
| 2549 template <typename Traits> | 2577 template <typename Traits> |
| 2550 typename ParserBase<Traits>::ExpressionT | 2578 typename ParserBase<Traits>::ExpressionT |
| 2551 ParserBase<Traits>::CheckAndRewriteReferenceExpression( | 2579 ParserBase<Traits>::CheckAndRewriteReferenceExpression( |
| 2552 ExpressionT expression, | 2580 ExpressionT expression, |
| 2553 Scanner::Location location, const char* message, bool* ok) { | 2581 Scanner::Location location, const char* message, bool* ok) { |
| 2554 if (strict_mode() == STRICT && this->IsIdentifier(expression) && | 2582 if (strict_mode() == STRICT && this->IsIdentifier(expression) && |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2602 parser()->ReportMessage("accessor_get_set"); | 2630 parser()->ReportMessage("accessor_get_set"); |
| 2603 } | 2631 } |
| 2604 *ok = false; | 2632 *ok = false; |
| 2605 } | 2633 } |
| 2606 } | 2634 } |
| 2607 | 2635 |
| 2608 | 2636 |
| 2609 } } // v8::internal | 2637 } } // v8::internal |
| 2610 | 2638 |
| 2611 #endif // V8_PREPARSER_H | 2639 #endif // V8_PREPARSER_H |
| OLD | NEW |