Skip to content

AST: Move up getBase() to TypeRepr to allow more generic access. NFC #9086

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions include/swift/AST/TypeRepr.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class alignas(8) TypeRepr {

static bool classof(const TypeRepr *T) { return true; }

TypeRepr *getBase() const;

/// Walk this type representation.
TypeRepr *walk(ASTWalker &walker);
TypeRepr *walk(ASTWalker &&walker) {
Expand Down Expand Up @@ -463,7 +465,6 @@ class ArrayTypeRepr : public TypeRepr {
ArrayTypeRepr(TypeRepr *Base, SourceRange Brackets)
: TypeRepr(TypeReprKind::Array), Base(Base), Brackets(Brackets) { }

TypeRepr *getBase() const { return Base; }
SourceRange getBrackets() const { return Brackets; }

static bool classof(const TypeRepr *T) {
Expand Down Expand Up @@ -524,7 +525,6 @@ class OptionalTypeRepr : public TypeRepr {
: TypeRepr(TypeReprKind::Optional), Base(Base), QuestionLoc(Question) {
}

TypeRepr *getBase() const { return Base; }
SourceLoc getQuestionLoc() const { return QuestionLoc; }

static bool classof(const TypeRepr *T) {
Expand Down Expand Up @@ -557,7 +557,6 @@ class ImplicitlyUnwrappedOptionalTypeRepr : public TypeRepr {
Base(Base),
ExclamationLoc(Exclamation) {}

TypeRepr *getBase() const { return Base; }
SourceLoc getExclamationLoc() const { return ExclamationLoc; }

static bool classof(const TypeRepr *T) {
Expand Down Expand Up @@ -767,7 +766,6 @@ class MetatypeTypeRepr : public TypeRepr {
: TypeRepr(TypeReprKind::Metatype), Base(Base), MetaLoc(MetaLoc) {
}

TypeRepr *getBase() const { return Base; }
SourceLoc getMetaLoc() const { return MetaLoc; }

static bool classof(const TypeRepr *T) {
Expand Down Expand Up @@ -796,7 +794,6 @@ class ProtocolTypeRepr : public TypeRepr {
: TypeRepr(TypeReprKind::Protocol), Base(Base), ProtocolLoc(ProtocolLoc) {
}

TypeRepr *getBase() const { return Base; }
SourceLoc getProtocolLoc() const { return ProtocolLoc; }

static bool classof(const TypeRepr *T) {
Expand Down Expand Up @@ -824,8 +821,7 @@ class InOutTypeRepr : public TypeRepr {
InOutTypeRepr(TypeRepr *Base, SourceLoc InOutLoc)
: TypeRepr(TypeReprKind::InOut), Base(Base), InOutLoc(InOutLoc) {
}

TypeRepr *getBase() const { return Base; }

SourceLoc getInOutLoc() const { return InOutLoc; }

static bool classof(const TypeRepr *T) {
Expand Down
19 changes: 19 additions & 0 deletions lib/AST/TypeRepr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,25 @@ void *TypeRepr::operator new(size_t Bytes, const ASTContext &C,
return C.Allocate(Bytes, Alignment);
}

TypeRepr* TypeRepr::getBase() const {
switch(getKind()) {
case TypeReprKind::Array:
return static_cast<const ArrayTypeRepr*>(this)->Base;
case TypeReprKind::ImplicitlyUnwrappedOptional:
return static_cast<const ImplicitlyUnwrappedOptionalTypeRepr*>(this)->Base;
case TypeReprKind::Optional:
return static_cast<const OptionalTypeRepr*>(this)->Base;
case TypeReprKind::Metatype:
return static_cast<const MetatypeTypeRepr*>(this)->Base;
case TypeReprKind::Protocol:
return static_cast<const ProtocolTypeRepr*>(this)->Base;
case TypeReprKind::InOut:
return static_cast<const InOutTypeRepr*>(this)->Base;
default:
llvm_unreachable("baseless type repr kind!");
}
}

Identifier ComponentIdentTypeRepr::getIdentifier() const {
if (IdOrDecl.is<Identifier>())
return IdOrDecl.get<Identifier>();
Expand Down