| 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_PARSER_BASE_H | 5 #ifndef V8_PARSING_PARSER_BASE_H |
| 6 #define V8_PARSING_PARSER_BASE_H | 6 #define V8_PARSING_PARSER_BASE_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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 public: | 81 public: |
| 82 // Shorten type names defined by Traits. | 82 // Shorten type names defined by Traits. |
| 83 typedef typename Traits::Type::Expression ExpressionT; | 83 typedef typename Traits::Type::Expression ExpressionT; |
| 84 typedef typename Traits::Type::Identifier IdentifierT; | 84 typedef typename Traits::Type::Identifier IdentifierT; |
| 85 typedef typename Traits::Type::IdentifierList IdentifierListT; | 85 typedef typename Traits::Type::IdentifierList IdentifierListT; |
| 86 typedef typename Traits::Type::FormalParameter FormalParameterT; | 86 typedef typename Traits::Type::FormalParameter FormalParameterT; |
| 87 typedef typename Traits::Type::FormalParameters FormalParametersT; | 87 typedef typename Traits::Type::FormalParameters FormalParametersT; |
| 88 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; | 88 typedef typename Traits::Type::FunctionLiteral FunctionLiteralT; |
| 89 typedef typename Traits::Type::Literal LiteralT; | 89 typedef typename Traits::Type::Literal LiteralT; |
| 90 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; | 90 typedef typename Traits::Type::ObjectLiteralProperty ObjectLiteralPropertyT; |
| 91 typedef typename Traits::Type::Statement StatementT; |
| 91 typedef typename Traits::Type::StatementList StatementListT; | 92 typedef typename Traits::Type::StatementList StatementListT; |
| 92 typedef typename Traits::Type::ExpressionClassifier ExpressionClassifier; | 93 typedef typename Traits::Type::ExpressionClassifier ExpressionClassifier; |
| 93 typedef typename Traits::Type::TypeSystem TypeSystem; | 94 typedef typename Traits::Type::TypeSystem TypeSystem; |
| 94 | 95 |
| 95 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, | 96 ParserBase(Zone* zone, Scanner* scanner, uintptr_t stack_limit, |
| 96 v8::Extension* extension, AstValueFactory* ast_value_factory, | 97 v8::Extension* extension, AstValueFactory* ast_value_factory, |
| 97 ParserRecorder* log, typename Traits::Type::Parser this_object) | 98 ParserRecorder* log, typename Traits::Type::Parser this_object) |
| 98 : Traits(this_object), | 99 : Traits(this_object), |
| 99 parenthesized_function_(false), | 100 parenthesized_function_(false), |
| 100 scope_(NULL), | 101 scope_(NULL), |
| (...skipping 744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 845 typename TypeSystem::Type ParseValidType(bool* ok); | 846 typename TypeSystem::Type ParseValidType(bool* ok); |
| 846 typename TypeSystem::Type ParseValidTypeOrStringLiteral(bool* ok); | 847 typename TypeSystem::Type ParseValidTypeOrStringLiteral(bool* ok); |
| 847 typename TypeSystem::Type ParseType(bool* ok); | 848 typename TypeSystem::Type ParseType(bool* ok); |
| 848 typename TypeSystem::Type ParseUnionOrIntersectionOrPrimaryType(bool* ok); | 849 typename TypeSystem::Type ParseUnionOrIntersectionOrPrimaryType(bool* ok); |
| 849 typename TypeSystem::Type ParseIntersectionOrPrimaryType(bool* ok); | 850 typename TypeSystem::Type ParseIntersectionOrPrimaryType(bool* ok); |
| 850 typename TypeSystem::Type ParsePrimaryTypeOrParameterList(bool* ok); | 851 typename TypeSystem::Type ParsePrimaryTypeOrParameterList(bool* ok); |
| 851 typename TypeSystem::TypeParameters ParseTypeParameters(bool* ok); | 852 typename TypeSystem::TypeParameters ParseTypeParameters(bool* ok); |
| 852 typename TypeSystem::TypeList ParseTypeArguments(bool* ok); | 853 typename TypeSystem::TypeList ParseTypeArguments(bool* ok); |
| 853 IdentifierListT ParsePropertyNameList(bool* ok); | 854 IdentifierListT ParsePropertyNameList(bool* ok); |
| 854 typename TypeSystem::TypeMember ParseTypeMember(bool* ok); | 855 typename TypeSystem::TypeMember ParseTypeMember(bool* ok); |
| 856 StatementT ParseTypeAliasDeclaration(int pos, bool* ok); |
| 855 | 857 |
| 856 typename TypeSystem::Type ValidateType(typename TypeSystem::Type type, | 858 typename TypeSystem::Type ValidateType(typename TypeSystem::Type type, |
| 857 Scanner::Location location, bool* ok) { | 859 Scanner::Location location, bool* ok) { |
| 858 typename TypeSystem::Type result = type->Uncover(ok); | 860 typename TypeSystem::Type result = type->Uncover(ok); |
| 859 if (*ok) { | 861 if (*ok) { |
| 860 if (!result->IsStringLiteralType()) return result; | 862 if (!result->IsStringLiteralType()) return result; |
| 861 *ok = false; | 863 *ok = false; |
| 862 } | 864 } |
| 863 ReportMessageAt(location, MessageTemplate::kInvalidType); | 865 ReportMessageAt(location, MessageTemplate::kInvalidType); |
| 864 return type; | 866 return type; |
| (...skipping 2726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3591 type = ParseType(CHECK_OK_CUSTOM(EmptyTypeMember)); | 3593 type = ParseType(CHECK_OK_CUSTOM(EmptyTypeMember)); |
| 3592 if (!type->IsValidType()) valid_type = false; | 3594 if (!type->IsValidType()) valid_type = false; |
| 3593 if (!type->IsValidBindingIdentifierOrPattern()) valid_binder = false; | 3595 if (!type->IsValidBindingIdentifierOrPattern()) valid_binder = false; |
| 3594 } | 3596 } |
| 3595 return factory()->NewTypeMember(property, optional, type_parameters, | 3597 return factory()->NewTypeMember(property, optional, type_parameters, |
| 3596 parameters, type, valid_type, valid_binder, | 3598 parameters, type, valid_type, valid_binder, |
| 3597 pos, has_new); | 3599 pos, has_new); |
| 3598 } | 3600 } |
| 3599 | 3601 |
| 3600 | 3602 |
| 3603 template <typename Traits> |
| 3604 typename ParserBase<Traits>::StatementT |
| 3605 ParserBase<Traits>::ParseTypeAliasDeclaration(int pos, bool* ok) { |
| 3606 // TypeAliasDeclaration :: |
| 3607 // 'type' BindingIdentifier [ TypeParameters ] '=' Type ';' |
| 3608 typename ParserBase<Traits>::StatementT empty = |
| 3609 factory()->NewEmptyStatement(pos); |
| 3610 IdentifierT name = ParseIdentifierName(ok); |
| 3611 if (!*ok) return empty; |
| 3612 // Parse optional type parameters. |
| 3613 typename TypeSystem::TypeParameters type_parameters = |
| 3614 this->NullTypeParameters(); |
| 3615 if (peek() == Token::LT) { |
| 3616 type_parameters = ParseTypeParameters(ok); |
| 3617 if (!*ok) return empty; |
| 3618 } |
| 3619 Expect(Token::ASSIGN, ok); |
| 3620 if (!*ok) return empty; |
| 3621 typename TypeSystem::Type type = ParseValidType(ok); |
| 3622 if (!*ok) return empty; |
| 3623 ExpectSemicolon(ok); |
| 3624 if (!*ok) return empty; |
| 3625 USE(name); // TODO(nikolaos): really use them! |
| 3626 USE(type_parameters); |
| 3627 USE(type); |
| 3628 return empty; |
| 3629 } |
| 3630 |
| 3631 |
| 3601 #undef CHECK_OK | 3632 #undef CHECK_OK |
| 3602 #undef CHECK_OK_CUSTOM | 3633 #undef CHECK_OK_CUSTOM |
| 3603 #undef CHECK_OK_TYPE | 3634 #undef CHECK_OK_TYPE |
| 3604 | 3635 |
| 3605 | 3636 |
| 3606 template <typename Traits> | 3637 template <typename Traits> |
| 3607 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( | 3638 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( |
| 3608 Token::Value property, PropertyKind type, bool is_static, bool is_generator, | 3639 Token::Value property, PropertyKind type, bool is_static, bool is_generator, |
| 3609 bool* ok) { | 3640 bool* ok) { |
| 3610 DCHECK(!is_static); | 3641 DCHECK(!is_static); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3655 has_seen_constructor_ = true; | 3686 has_seen_constructor_ = true; |
| 3656 return; | 3687 return; |
| 3657 } | 3688 } |
| 3658 } | 3689 } |
| 3659 | 3690 |
| 3660 | 3691 |
| 3661 } // namespace internal | 3692 } // namespace internal |
| 3662 } // namespace v8 | 3693 } // namespace v8 |
| 3663 | 3694 |
| 3664 #endif // V8_PARSING_PARSER_BASE_H | 3695 #endif // V8_PARSING_PARSER_BASE_H |
| OLD | NEW |