Skip to content

Commit e65a1fb

Browse files
committed
PrintAsClang: Intro and use getKnownType for C compatibility
1 parent d5b3132 commit e65a1fb

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,6 +2289,14 @@ class DeclAndTypePrinter::Implementation
22892289
return false;
22902290
}
22912291

2292+
std::optional<PrimitiveTypeMapping::ClangTypeInfo>
2293+
getKnownType(const TypeDecl *typeDecl) {
2294+
if (outputLang == OutputLanguageMode::C)
2295+
return owningPrinter.typeMapping.getKnownCTypeInfo(typeDecl);
2296+
2297+
return owningPrinter.typeMapping.getKnownObjCTypeInfo(typeDecl);
2298+
}
2299+
22922300
/// If \p typeDecl is one of the standard library types used to map in Clang
22932301
/// primitives and basic types, print out the appropriate spelling and
22942302
/// return true.
@@ -2297,8 +2305,7 @@ class DeclAndTypePrinter::Implementation
22972305
/// for interfacing with C and Objective-C.
22982306
bool printIfKnownSimpleType(const TypeDecl *typeDecl,
22992307
std::optional<OptionalTypeKind> optionalKind) {
2300-
auto knownTypeInfo =
2301-
owningPrinter.typeMapping.getKnownObjCTypeInfo(typeDecl);
2308+
auto knownTypeInfo = getKnownType(typeDecl);
23022309
if (!knownTypeInfo)
23032310
return false;
23042311
os << knownTypeInfo->name;

lib/PrintAsClang/OutputLanguageMode.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
namespace swift {
1717

18-
enum class OutputLanguageMode { ObjC, Cxx };
18+
enum class OutputLanguageMode { ObjC, Cxx, C };
1919

2020
} // end namespace swift
2121

0 commit comments

Comments
 (0)