Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1390)

Side by Side Diff: src/parsing/parser-base.h

Issue 1849803002: Add parsing for interface declarations (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@types-1850663002-class-decl
Patch Set: Add more tests Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 840 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 typename TypeSystem::Type ParseValidType(bool* ok); 851 typename TypeSystem::Type ParseValidType(bool* ok);
852 typename TypeSystem::Type ParseValidTypeOrStringLiteral(bool* ok); 852 typename TypeSystem::Type ParseValidTypeOrStringLiteral(bool* ok);
853 typename TypeSystem::Type ParseType(bool* ok); 853 typename TypeSystem::Type ParseType(bool* ok);
854 typename TypeSystem::Type ParseUnionOrIntersectionOrPrimaryType(bool* ok); 854 typename TypeSystem::Type ParseUnionOrIntersectionOrPrimaryType(bool* ok);
855 typename TypeSystem::Type ParseIntersectionOrPrimaryType(bool* ok); 855 typename TypeSystem::Type ParseIntersectionOrPrimaryType(bool* ok);
856 typename TypeSystem::Type ParsePrimaryTypeOrParameterList(bool* ok); 856 typename TypeSystem::Type ParsePrimaryTypeOrParameterList(bool* ok);
857 typename TypeSystem::Type ParseTypeReference(bool* ok); 857 typename TypeSystem::Type ParseTypeReference(bool* ok);
858 typename TypeSystem::TypeParameters ParseTypeParameters(bool* ok); 858 typename TypeSystem::TypeParameters ParseTypeParameters(bool* ok);
859 typename TypeSystem::TypeList ParseTypeArguments(bool* ok); 859 typename TypeSystem::TypeList ParseTypeArguments(bool* ok);
860 IdentifierListT ParsePropertyNameList(bool* ok); 860 IdentifierListT ParsePropertyNameList(bool* ok);
861 typename TypeSystem::Type ParseObjectType(bool* ok);
861 typename TypeSystem::TypeMember ParseTypeMember(bool* ok); 862 typename TypeSystem::TypeMember ParseTypeMember(bool* ok);
862 StatementT ParseTypeAliasDeclaration(int pos, bool* ok); 863 StatementT ParseTypeAliasDeclaration(int pos, bool* ok);
864 StatementT ParseInterfaceDeclaration(int pos, bool* ok);
863 865
864 typename TypeSystem::Type ValidateType(typename TypeSystem::Type type, 866 typename TypeSystem::Type ValidateType(typename TypeSystem::Type type,
865 Scanner::Location location, bool* ok) { 867 Scanner::Location location, bool* ok) {
866 typename TypeSystem::Type result = type->Uncover(ok); 868 typename TypeSystem::Type result = type->Uncover(ok);
867 if (*ok) { 869 if (*ok) {
868 if (!result->IsStringLiteralType()) return result; 870 if (!result->IsStringLiteralType()) return result;
869 *ok = false; 871 *ok = false;
870 } 872 }
871 ReportMessageAt(location, MessageTemplate::kInvalidType); 873 ReportMessageAt(location, MessageTemplate::kInvalidType);
872 return type; 874 return type;
(...skipping 2618 matching lines...) Expand 10 before | Expand all | Expand 10 after
3491 trailing_comma = true; 3493 trailing_comma = true;
3492 } 3494 }
3493 } while (peek() != Token::RBRACK); 3495 } while (peek() != Token::RBRACK);
3494 } 3496 }
3495 Consume(Token::RBRACK); 3497 Consume(Token::RBRACK);
3496 type = factory()->NewTupleType(elements, valid_type && !trailing_comma, 3498 type = factory()->NewTupleType(elements, valid_type && !trailing_comma,
3497 valid_binder, spread, pos); 3499 valid_binder, spread, pos);
3498 break; 3500 break;
3499 } 3501 }
3500 case Token::LBRACE: { 3502 case Token::LBRACE: {
3501 Consume(Token::LBRACE); 3503 type = ParseObjectType(CHECK_OK_TYPE);
3502 typename TypeSystem::TypeMembers members = this->EmptyTypeMembers();
3503 bool valid_type = true, valid_binder = true;
3504 while (peek() != Token::RBRACE) {
3505 typename TypeSystem::TypeMember type_member =
3506 ParseTypeMember(CHECK_OK_TYPE);
3507 members->Add(type_member, zone());
3508 if (!type_member->IsValidType()) valid_type = false;
3509 if (!type_member->IsValidBindingIdentifierOrPattern())
3510 valid_binder = false;
3511 if (peek() != Token::RBRACE && !Check(Token::COMMA)) {
3512 ExpectSemicolon(CHECK_OK_TYPE);
3513 valid_binder = false; // Semicolons not allowed in valid binders.
3514 }
3515 }
3516 Consume(Token::RBRACE);
3517 type = factory()->NewObjectType(members, valid_type, valid_binder, pos);
3518 break; 3504 break;
3519 } 3505 }
3520 case Token::TYPEOF: { 3506 case Token::TYPEOF: {
3521 Consume(Token::TYPEOF); 3507 Consume(Token::TYPEOF);
3522 IdentifierT name = ParseIdentifierName(CHECK_OK_TYPE); 3508 IdentifierT name = ParseIdentifierName(CHECK_OK_TYPE);
3523 IdentifierListT property_names = this->NullIdentifierList(); 3509 IdentifierListT property_names = this->NullIdentifierList();
3524 if (peek() == Token::PERIOD) { // Braces required here. 3510 if (peek() == Token::PERIOD) { // Braces required here.
3525 property_names = ParsePropertyNameList(CHECK_OK_TYPE); 3511 property_names = ParsePropertyNameList(CHECK_OK_TYPE);
3526 } 3512 }
3527 type = factory()->NewQueryType(name, property_names, pos); 3513 type = factory()->NewQueryType(name, property_names, pos);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3585 do { 3571 do {
3586 IdentifierT property_name = 3572 IdentifierT property_name =
3587 ParseIdentifierName(CHECK_OK_CUSTOM(NullIdentifierList)); 3573 ParseIdentifierName(CHECK_OK_CUSTOM(NullIdentifierList));
3588 property_names->Add(property_name, zone()); 3574 property_names->Add(property_name, zone());
3589 } while (Check(Token::PERIOD)); 3575 } while (Check(Token::PERIOD));
3590 return property_names; 3576 return property_names;
3591 } 3577 }
3592 3578
3593 3579
3594 template <typename Traits> 3580 template <typename Traits>
3581 typename ParserBase<Traits>::TypeSystem::Type
3582 ParserBase<Traits>::ParseObjectType(bool* ok) {
3583 int pos = peek_position();
3584 Expect(Token::LBRACE, CHECK_OK_TYPE);
3585 typename TypeSystem::TypeMembers members = this->EmptyTypeMembers();
3586 bool valid_type = true, valid_binder = true;
3587 while (peek() != Token::RBRACE) {
3588 typename TypeSystem::TypeMember type_member =
3589 ParseTypeMember(CHECK_OK_TYPE);
3590 members->Add(type_member, zone());
3591 if (!type_member->IsValidType()) valid_type = false;
3592 if (!type_member->IsValidBindingIdentifierOrPattern()) valid_binder = false;
3593 if (peek() != Token::RBRACE && !Check(Token::COMMA)) {
3594 ExpectSemicolon(CHECK_OK_TYPE);
3595 valid_binder = false; // Semicolons not allowed in valid binders.
3596 }
3597 }
3598 Consume(Token::RBRACE);
3599 return factory()->NewObjectType(members, valid_type, valid_binder, pos);
3600 }
3601
3602
3603 template <typename Traits>
3595 typename ParserBase<Traits>::TypeSystem::TypeMember 3604 typename ParserBase<Traits>::TypeSystem::TypeMember
3596 ParserBase<Traits>::ParseTypeMember(bool* ok) { 3605 ParserBase<Traits>::ParseTypeMember(bool* ok) {
3597 int pos = peek_position(); 3606 int pos = peek_position();
3598 bool valid_type = true, valid_binder = false; 3607 bool valid_type = true, valid_binder = false;
3599 // Parse index signature. 3608 // Parse index signature.
3600 if (Check(Token::LBRACK)) { 3609 if (Check(Token::LBRACK)) {
3601 int property_pos = peek_position(); 3610 int property_pos = peek_position();
3602 IdentifierT property_name = 3611 IdentifierT property_name =
3603 ParseIdentifierName(CHECK_OK_CUSTOM(EmptyTypeMember)); 3612 ParseIdentifierName(CHECK_OK_CUSTOM(EmptyTypeMember));
3604 ExpressionT property = 3613 ExpressionT property =
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
3696 if (!*ok) return empty; 3705 if (!*ok) return empty;
3697 ExpectSemicolon(ok); 3706 ExpectSemicolon(ok);
3698 if (!*ok) return empty; 3707 if (!*ok) return empty;
3699 USE(name); // TODO(nikolaos): really use them! 3708 USE(name); // TODO(nikolaos): really use them!
3700 USE(type_parameters); 3709 USE(type_parameters);
3701 USE(type); 3710 USE(type);
3702 return empty; 3711 return empty;
3703 } 3712 }
3704 3713
3705 3714
3715 template <typename Traits>
3716 typename ParserBase<Traits>::StatementT
3717 ParserBase<Traits>::ParseInterfaceDeclaration(int pos, bool* ok) {
3718 // InterfaceDeclaration ::
3719 // 'interface' BindingIdentifier [ TypeParameters ]
3720 // [ InterfaceExtendsClause ] ObjectType ';'
3721 // InterfaceExtendsClause ::
3722 // 'extends' (TypeReference // ',')+
3723 typename ParserBase<Traits>::StatementT empty =
3724 factory()->NewEmptyStatement(pos);
3725 IdentifierT name = ParseIdentifierName(ok);
3726 if (!*ok) return empty;
3727 // Parse optional type parameters.
3728 typename TypeSystem::TypeParameters type_parameters =
3729 this->NullTypeParameters();
3730 if (peek() == Token::LT) {
3731 type_parameters = ParseTypeParameters(ok);
3732 if (!*ok) return empty;
3733 }
3734 // Parse optional extends clause.
3735 typename TypeSystem::TypeList extends = this->NullTypeList();
3736 if (Check(Token::EXTENDS)) {
3737 extends = this->EmptyTypeList();
3738 do {
3739 typename TypeSystem::Type class_or_interface = ParseTypeReference(ok);
3740 if (!*ok) return empty;
3741 extends->Add(class_or_interface, zone());
3742 } while (Check(Token::COMMA));
3743 }
3744 // Parse object type.
3745 Scanner::Location type_location = scanner()->peek_location();
3746 typename TypeSystem::Type type = ParseObjectType(ok);
3747 if (!*ok) return empty;
3748 type = ValidateType(type, type_location, ok);
3749 if (!*ok) return empty;
3750 USE(name); // TODO(nikolaos): really use them!
3751 USE(type_parameters);
3752 USE(extends);
3753 USE(type);
3754 return empty;
3755 }
3756
3757
3706 #undef CHECK_OK 3758 #undef CHECK_OK
3707 #undef CHECK_OK_CUSTOM 3759 #undef CHECK_OK_CUSTOM
3708 #undef CHECK_OK_TYPE 3760 #undef CHECK_OK_TYPE
3709 3761
3710 3762
3711 template <typename Traits> 3763 template <typename Traits>
3712 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty( 3764 void ParserBase<Traits>::ObjectLiteralChecker::CheckProperty(
3713 Token::Value property, PropertyKind type, bool is_static, bool is_generator, 3765 Token::Value property, PropertyKind type, bool is_static, bool is_generator,
3714 bool* ok) { 3766 bool* ok) {
3715 DCHECK(!is_static); 3767 DCHECK(!is_static);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
3760 has_seen_constructor_ = true; 3812 has_seen_constructor_ = true;
3761 return; 3813 return;
3762 } 3814 }
3763 } 3815 }
3764 3816
3765 3817
3766 } // namespace internal 3818 } // namespace internal
3767 } // namespace v8 3819 } // namespace v8
3768 3820
3769 #endif // V8_PARSING_PARSER_BASE_H 3821 #endif // V8_PARSING_PARSER_BASE_H
OLDNEW
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698