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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parsing/parser.cc ('k') | src/parsing/preparser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/parsing/parser-base.h
diff --git a/src/parsing/parser-base.h b/src/parsing/parser-base.h
index 89d760f22d3e3c1946b1cb8db50c987059b6b20f..678a4be8ab68ff2ce4b40809620fc207215d25a4 100644
--- a/src/parsing/parser-base.h
+++ b/src/parsing/parser-base.h
@@ -858,8 +858,10 @@ class ParserBase : public Traits {
typename TypeSystem::TypeParameters ParseTypeParameters(bool* ok);
typename TypeSystem::TypeList ParseTypeArguments(bool* ok);
IdentifierListT ParsePropertyNameList(bool* ok);
+ typename TypeSystem::Type ParseObjectType(bool* ok);
typename TypeSystem::TypeMember ParseTypeMember(bool* ok);
StatementT ParseTypeAliasDeclaration(int pos, bool* ok);
+ StatementT ParseInterfaceDeclaration(int pos, bool* ok);
typename TypeSystem::Type ValidateType(typename TypeSystem::Type type,
Scanner::Location location, bool* ok) {
@@ -3498,23 +3500,7 @@ ParserBase<Traits>::ParsePrimaryTypeOrParameterList(bool* ok) {
break;
}
case Token::LBRACE: {
- Consume(Token::LBRACE);
- typename TypeSystem::TypeMembers members = this->EmptyTypeMembers();
- bool valid_type = true, valid_binder = true;
- while (peek() != Token::RBRACE) {
- typename TypeSystem::TypeMember type_member =
- ParseTypeMember(CHECK_OK_TYPE);
- members->Add(type_member, zone());
- if (!type_member->IsValidType()) valid_type = false;
- if (!type_member->IsValidBindingIdentifierOrPattern())
- valid_binder = false;
- if (peek() != Token::RBRACE && !Check(Token::COMMA)) {
- ExpectSemicolon(CHECK_OK_TYPE);
- valid_binder = false; // Semicolons not allowed in valid binders.
- }
- }
- Consume(Token::RBRACE);
- type = factory()->NewObjectType(members, valid_type, valid_binder, pos);
+ type = ParseObjectType(CHECK_OK_TYPE);
break;
}
case Token::TYPEOF: {
@@ -3592,6 +3578,29 @@ ParserBase<Traits>::ParsePropertyNameList(bool* ok) {
template <typename Traits>
+typename ParserBase<Traits>::TypeSystem::Type
+ParserBase<Traits>::ParseObjectType(bool* ok) {
+ int pos = peek_position();
+ Expect(Token::LBRACE, CHECK_OK_TYPE);
+ typename TypeSystem::TypeMembers members = this->EmptyTypeMembers();
+ bool valid_type = true, valid_binder = true;
+ while (peek() != Token::RBRACE) {
+ typename TypeSystem::TypeMember type_member =
+ ParseTypeMember(CHECK_OK_TYPE);
+ members->Add(type_member, zone());
+ if (!type_member->IsValidType()) valid_type = false;
+ if (!type_member->IsValidBindingIdentifierOrPattern()) valid_binder = false;
+ if (peek() != Token::RBRACE && !Check(Token::COMMA)) {
+ ExpectSemicolon(CHECK_OK_TYPE);
+ valid_binder = false; // Semicolons not allowed in valid binders.
+ }
+ }
+ Consume(Token::RBRACE);
+ return factory()->NewObjectType(members, valid_type, valid_binder, pos);
+}
+
+
+template <typename Traits>
typename ParserBase<Traits>::TypeSystem::TypeMember
ParserBase<Traits>::ParseTypeMember(bool* ok) {
int pos = peek_position();
@@ -3703,6 +3712,49 @@ ParserBase<Traits>::ParseTypeAliasDeclaration(int pos, bool* ok) {
}
+template <typename Traits>
+typename ParserBase<Traits>::StatementT
+ParserBase<Traits>::ParseInterfaceDeclaration(int pos, bool* ok) {
+ // InterfaceDeclaration ::
+ // 'interface' BindingIdentifier [ TypeParameters ]
+ // [ InterfaceExtendsClause ] ObjectType ';'
+ // InterfaceExtendsClause ::
+ // 'extends' (TypeReference // ',')+
+ typename ParserBase<Traits>::StatementT empty =
+ factory()->NewEmptyStatement(pos);
+ IdentifierT name = ParseIdentifierName(ok);
+ if (!*ok) return empty;
+ // Parse optional type parameters.
+ typename TypeSystem::TypeParameters type_parameters =
+ this->NullTypeParameters();
+ if (peek() == Token::LT) {
+ type_parameters = ParseTypeParameters(ok);
+ if (!*ok) return empty;
+ }
+ // Parse optional extends clause.
+ typename TypeSystem::TypeList extends = this->NullTypeList();
+ if (Check(Token::EXTENDS)) {
+ extends = this->EmptyTypeList();
+ do {
+ typename TypeSystem::Type class_or_interface = ParseTypeReference(ok);
+ if (!*ok) return empty;
+ extends->Add(class_or_interface, zone());
+ } while (Check(Token::COMMA));
+ }
+ // Parse object type.
+ Scanner::Location type_location = scanner()->peek_location();
+ typename TypeSystem::Type type = ParseObjectType(ok);
+ if (!*ok) return empty;
+ type = ValidateType(type, type_location, ok);
+ if (!*ok) return empty;
+ USE(name); // TODO(nikolaos): really use them!
+ USE(type_parameters);
+ USE(extends);
+ USE(type);
+ return empty;
+}
+
+
#undef CHECK_OK
#undef CHECK_OK_CUSTOM
#undef CHECK_OK_TYPE
« 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