Skip to content

Commit 5217ed4

Browse files
committed
Add _const to Swift declaration names of const types
1 parent a861fc1 commit 5217ed4

File tree

5 files changed

+44
-2
lines changed

5 files changed

+44
-2
lines changed

lib/ClangImporter/ClangClassTemplateNamePrinter.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ struct TemplateInstantiationNamePrinter
6363
return "_";
6464
}
6565

66+
std::string VisitElaboratedType(const clang::ElaboratedType *type) {
67+
clang::QualType qType = type->getNamedType();
68+
llvm::errs() << "\n=== VisitElaboratedType ===\n\n";
69+
if (qType.isConstQualified()) {
70+
// TODO need to visit something?
71+
return "_const";
72+
}
73+
return "";
74+
}
75+
6676
std::string VisitRecordType(const clang::RecordType *type) {
6777
auto tagDecl = type->getAsTagDecl();
6878
if (auto namedArg = dyn_cast_or_null<clang::NamedDecl>(tagDecl)) {
@@ -148,8 +158,12 @@ std::string swift::importer::printClassTemplateSpecializationName(
148158
// Use import name here so builtin types such as "int" map to their
149159
// Swift equivalent ("CInt").
150160
if (arg.getKind() == clang::TemplateArgument::Type) {
151-
auto ty = arg.getAsType().getTypePtr();
152-
buffer << templateNamePrinter.Visit(ty);
161+
auto ty = arg.getAsType();
162+
buffer << templateNamePrinter.Visit(ty.getTypePtr());
163+
// TODO
164+
if (ty.isConstQualified()) {
165+
buffer << "_const";
166+
}
153167
return;
154168
} else if (arg.getKind() == clang::TemplateArgument::Integral) {
155169
buffer << "_";

lib/ClangImporter/ClangDerivedConformances.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,8 @@ void swift::conformToCxxSpanIfNeeded(ClangImporter::Implementation &impl,
11561156
if (!isStdDecl(clangDecl, {"span"}))
11571157
return;
11581158

1159+
llvm::errs() << decl->getName() << '\n';
1160+
11591161
auto elementType = lookupDirectSingleWithoutExtensions<TypeAliasDecl>(
11601162
decl, ctx.getIdentifier("element_type"));
11611163
auto sizeType = lookupDirectSingleWithoutExtensions<TypeAliasDecl>(

test/Interop/Cxx/stdlib/Inputs/std-span.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
using Span = std::span<const int>;
99
using SpanOfString = std::span<const std::string>;
10+
using ComplexSpan = std::span<std::span<const int>>;
1011

1112
static int iarray[]{1, 2, 3};
1213
static std::string sarray[]{"", "ab", "abc"};

test/Interop/Cxx/templates/Inputs/class-template-with-primitive-argument.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,23 @@ struct MagicWrapper {
77
int getValuePlusArg(int arg) const { return t + arg; }
88
};
99

10+
template<class M>
11+
struct DoubleWrapper {
12+
M m;
13+
int getValuePlusArg(int arg) const { return m.getValuePlusArg(arg); }
14+
};
15+
1016
typedef MagicWrapper<int> WrappedMagicInt;
17+
typedef MagicWrapper<const int> WrappedMagicIntConst;
18+
typedef MagicWrapper<const long> WrappedMagicLongConst;
1119
typedef MagicWrapper<int*> WrappedMagicIntPtr;
1220
typedef MagicWrapper<const int*> WrappedMagicIntConstPtr;
1321
typedef MagicWrapper<int**> WrappedMagicIntPtrPtr;
1422

23+
typedef DoubleWrapper<MagicWrapper<int>> DoubleWrappedInt;
24+
typedef DoubleWrapper<MagicWrapper<const int>> DoubleWrappedIntConst;
25+
typedef DoubleWrapper<MagicWrapper<const long>> DoubleWrappedLongConst;
26+
typedef DoubleWrapper<MagicWrapper<int*>> DoubleWrappedIntPtr;
27+
typedef DoubleWrapper<MagicWrapper<const int*>> DoubleWrappedIntConstPtr;
28+
1529
#endif // TEST_INTEROP_CXX_TEMPLATES_INPUTS_CLASS_TEMPLATE_WITH_PRIMITIVE_ARGUMENT_H

test/Interop/Cxx/templates/class-template-with-primitive-argument-module-interface.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,18 @@
44
// CHECK: struct MagicWrapper<T> {
55
// CHECK: }
66

7+
// CHECK: struct DoubleWrapper<M> {
8+
// CHECK: }
9+
710
// CHECK: typealias WrappedMagicInt = MagicWrapper<CInt>
11+
// CHECK: typealias WrappedMagicIntConst = MagicWrapper<CInt_const>
12+
// CHECK: typealias WrappedMagicLongConst = MagicWrapper<CLong_const>
813
// CHECK: typealias WrappedMagicIntPtr = MagicWrapper<UnsafeMutablePointer<CInt>>
914
// CHECK: typealias WrappedMagicIntConstPtr = MagicWrapper<UnsafePointer<CInt>>
1015
// CHECK: typealias WrappedMagicIntPtrPtr = MagicWrapper<UnsafeMutablePointer<UnsafeMutablePointer<CInt>>>
16+
17+
// CHECK: typealias DoubleWrappedInt = DoubleWrapper<MagicWrapper<CInt>>
18+
// CHECK: typealias DoubleWrappedIntConst = DoubleWrapper<MagicWrapper<CInt_const>>
19+
// CHECK: typealias DoubleWrappedLongConst = DoubleWrapper<MagicWrapper<CLong_const>>
20+
// CHECK: typealias DoubleWrappedIntPtr = DoubleWrapper<MagicWrapper<UnsafeMutablePointer<CInt>>>
21+
// CHECK: typealias DoubleWrappedIntConstPtr = DoubleWrapper<MagicWrapper<UnsafePointer<CInt>>>

0 commit comments

Comments
 (0)