Skip to content

Commit 98edf08

Browse files
committed
AST: Remove TypeRepr::clone()
1 parent 6303852 commit 98edf08

File tree

4 files changed

+0
-164
lines changed

4 files changed

+0
-164
lines changed

include/swift/AST/TypeLoc.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ class alignas(1 << TypeLocAlignInBits) TypeLoc {
6565
void setInvalidType(ASTContext &C);
6666
void setType(Type Ty);
6767

68-
TypeLoc clone(ASTContext &ctx) const;
69-
7068
friend llvm::hash_code hash_value(const TypeLoc &owner) {
7169
return llvm::hash_combine(owner.Ty.getPointer(), owner.TyR);
7270
}

include/swift/AST/TypeRepr.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,6 @@ class alignas(8) TypeRepr {
163163
void print(raw_ostream &OS, const PrintOptions &Opts = PrintOptions()) const;
164164
void print(ASTPrinter &Printer, const PrintOptions &Opts) const;
165165
SWIFT_DEBUG_DUMP;
166-
167-
/// Clone the given type representation.
168-
TypeRepr *clone(const ASTContext &ctx) const;
169166
};
170167

171168
/// A TypeRepr for a type with a syntax error. Can be used both as a

lib/AST/Type.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,6 @@ SourceRange TypeLoc::getSourceRange() const {
9090
return SourceRange();
9191
}
9292

93-
TypeLoc TypeLoc::clone(ASTContext &ctx) const {
94-
if (TyR) {
95-
return TypeLoc(TyR->clone(ctx), Ty);
96-
}
97-
return *this;
98-
}
99-
10093
SourceLoc TypeLoc::getLoc() const {
10194
if (TyR) return TyR->getLoc();
10295
return SourceLoc();

lib/AST/TypeRepr.cpp

Lines changed: 0 additions & 152 deletions
Original file line numberDiff line numberDiff line change
@@ -116,158 +116,6 @@ void TypeRepr::print(ASTPrinter &Printer, const PrintOptions &Opts) const {
116116
llvm_unreachable("unknown kind!");
117117
}
118118

119-
namespace {
120-
class CloneVisitor : public TypeReprVisitor<CloneVisitor, TypeRepr *> {
121-
const ASTContext &Ctx;
122-
123-
public:
124-
explicit CloneVisitor(const ASTContext &ctx) : Ctx(ctx) { }
125-
126-
#define TYPEREPR(CLASS, PARENT) \
127-
TypeRepr *visit##CLASS##TypeRepr(CLASS##TypeRepr* type);
128-
#include "swift/AST/TypeReprNodes.def"
129-
};
130-
} // end anonymous namespace
131-
132-
TypeRepr *CloneVisitor::visitErrorTypeRepr(ErrorTypeRepr *T) {
133-
return new (Ctx) ErrorTypeRepr(T->getSourceRange());
134-
}
135-
136-
TypeRepr *CloneVisitor::visitAttributedTypeRepr(AttributedTypeRepr *T) {
137-
return new (Ctx) AttributedTypeRepr(T->getAttrs(), visit(T->getTypeRepr()));
138-
}
139-
140-
TypeRepr *CloneVisitor::visitSimpleIdentTypeRepr(SimpleIdentTypeRepr *T) {
141-
return new (Ctx) SimpleIdentTypeRepr(T->getNameLoc(), T->getNameRef());
142-
}
143-
144-
TypeRepr *CloneVisitor::visitGenericIdentTypeRepr(GenericIdentTypeRepr *T) {
145-
// Clone the generic arguments.
146-
SmallVector<TypeRepr*, 8> genericArgs;
147-
genericArgs.reserve(T->getGenericArgs().size());
148-
for (auto &arg : T->getGenericArgs()) {
149-
genericArgs.push_back(visit(arg));
150-
}
151-
return GenericIdentTypeRepr::create(Ctx, T->getNameLoc(), T->getNameRef(),
152-
genericArgs, T->getAngleBrackets());
153-
}
154-
155-
TypeRepr *CloneVisitor::visitCompoundIdentTypeRepr(CompoundIdentTypeRepr *T) {
156-
// Clone the components.
157-
SmallVector<ComponentIdentTypeRepr*, 8> components;
158-
components.reserve(T->getComponents().size());
159-
for (auto &component : T->getComponents()) {
160-
components.push_back(cast<ComponentIdentTypeRepr>(visit(component)));
161-
}
162-
return CompoundIdentTypeRepr::create(Ctx, components);
163-
}
164-
165-
TypeRepr *CloneVisitor::visitFunctionTypeRepr(FunctionTypeRepr *T) {
166-
return new (Ctx) FunctionTypeRepr(
167-
/*FIXME: Clone?*/T->getGenericParams(),
168-
cast<TupleTypeRepr>(visit(T->getArgsTypeRepr())),
169-
T->getThrowsLoc(),
170-
T->getArrowLoc(),
171-
visit(T->getResultTypeRepr()));
172-
}
173-
174-
TypeRepr *CloneVisitor::visitArrayTypeRepr(ArrayTypeRepr *T) {
175-
return new (Ctx) ArrayTypeRepr(visit(T->getBase()), T->getBrackets());
176-
}
177-
178-
TypeRepr *CloneVisitor::visitDictionaryTypeRepr(DictionaryTypeRepr *T) {
179-
return new (Ctx) DictionaryTypeRepr(visit(T->getKey()), visit(T->getValue()),
180-
T->getColonLoc(), T->getBrackets());
181-
}
182-
183-
TypeRepr *CloneVisitor::visitOptionalTypeRepr(OptionalTypeRepr *T) {
184-
return new (Ctx) OptionalTypeRepr(visit(T->getBase()), T->getQuestionLoc());
185-
}
186-
187-
TypeRepr * CloneVisitor::visitImplicitlyUnwrappedOptionalTypeRepr(
188-
ImplicitlyUnwrappedOptionalTypeRepr *T) {
189-
return new (Ctx) ImplicitlyUnwrappedOptionalTypeRepr(visit(T->getBase()),
190-
T->getExclamationLoc());
191-
}
192-
193-
TypeRepr *CloneVisitor::visitTupleTypeRepr(TupleTypeRepr *T) {
194-
SmallVector<TupleTypeReprElement, 8> elements;
195-
elements.reserve(T->getNumElements());
196-
for (auto arg : T->getElements()) {
197-
arg.Type = visit(arg.Type);
198-
elements.push_back(arg);
199-
}
200-
return TupleTypeRepr::create(Ctx, elements,
201-
T->getParens(),
202-
T->getEllipsisLoc(),
203-
T->getEllipsisIndex());
204-
}
205-
206-
TypeRepr *CloneVisitor::visitCompositionTypeRepr(CompositionTypeRepr *T) {
207-
// Clone the protocols.
208-
SmallVector<TypeRepr*, 8> types;
209-
types.reserve(T->getTypes().size());
210-
for (auto &type : T->getTypes()) {
211-
types.push_back(cast<TypeRepr>(visit(type)));
212-
}
213-
214-
return CompositionTypeRepr::create(Ctx, types, T->getStartLoc(),
215-
T->getCompositionRange());
216-
}
217-
218-
TypeRepr *CloneVisitor::visitMetatypeTypeRepr(MetatypeTypeRepr *T) {
219-
return new (Ctx) MetatypeTypeRepr(visit(T->getBase()), T->getMetaLoc());
220-
}
221-
222-
TypeRepr *CloneVisitor::visitProtocolTypeRepr(ProtocolTypeRepr *T) {
223-
return new (Ctx) ProtocolTypeRepr(visit(T->getBase()), T->getProtocolLoc());
224-
}
225-
226-
TypeRepr *CloneVisitor::visitInOutTypeRepr(InOutTypeRepr *T) {
227-
return new (Ctx) InOutTypeRepr(visit(T->getBase()), T->getSpecifierLoc());
228-
}
229-
230-
TypeRepr *CloneVisitor::visitSharedTypeRepr(SharedTypeRepr *T) {
231-
return new (Ctx) SharedTypeRepr(visit(T->getBase()), T->getSpecifierLoc());
232-
}
233-
234-
TypeRepr *CloneVisitor::visitOwnedTypeRepr(OwnedTypeRepr *T) {
235-
return new (Ctx) OwnedTypeRepr(visit(T->getBase()), T->getSpecifierLoc());
236-
}
237-
238-
TypeRepr *CloneVisitor::visitFixedTypeRepr(FixedTypeRepr *T) {
239-
return new (Ctx) FixedTypeRepr(T->getType(), T->getLoc());
240-
}
241-
242-
TypeRepr *CloneVisitor::visitSILBoxTypeRepr(SILBoxTypeRepr *type) {
243-
SmallVector<SILBoxTypeRepr::Field, 4> cloneFields;
244-
SmallVector<TypeRepr *, 4> cloneArgs;
245-
246-
for (auto &field : type->getFields())
247-
cloneFields.push_back({field.getLoc(), field.isMutable(),
248-
visit(field.getFieldType())});
249-
for (auto *arg : type->getGenericArguments())
250-
cloneArgs.push_back(visit(arg));
251-
252-
return new (Ctx) SILBoxTypeRepr(/*FIXME: Clone?*/type->getGenericParams(),
253-
type->getLBraceLoc(),
254-
Ctx.AllocateCopy(cloneFields),
255-
type->getRBraceLoc(),
256-
type->getArgumentLAngleLoc(),
257-
Ctx.AllocateCopy(cloneArgs),
258-
type->getArgumentRAngleLoc());
259-
}
260-
261-
TypeRepr *CloneVisitor::visitOpaqueReturnTypeRepr(OpaqueReturnTypeRepr *type) {
262-
return new (Ctx) OpaqueReturnTypeRepr(type->getOpaqueLoc(),
263-
visit(type->getConstraint()));
264-
}
265-
266-
TypeRepr *TypeRepr::clone(const ASTContext &ctx) const {
267-
CloneVisitor visitor(ctx);
268-
return visitor.visit(const_cast<TypeRepr *>(this));
269-
}
270-
271119
void ErrorTypeRepr::printImpl(ASTPrinter &Printer,
272120
const PrintOptions &Opts) const {
273121
Printer << "<<error type>>";

0 commit comments

Comments
 (0)