File tree Expand file tree Collapse file tree 8 files changed +34
-789
lines changed Expand file tree Collapse file tree 8 files changed +34
-789
lines changed Original file line number Diff line number Diff line change @@ -640,6 +640,14 @@ class ASTContext final {
640
640
// / if applicable.
641
641
const Decl *getSwiftDeclForExportedClangDecl (const clang::Decl *decl);
642
642
643
+ // / General conversion method from Swift types -> Clang types.
644
+ // /
645
+ // / HACK: This method is only intended to be called from a specific place in
646
+ // / IRGen. For converting function types, strongly prefer using one of the
647
+ // / other methods instead, instead of manually iterating over parameters
648
+ // / and results.
649
+ const clang::Type *getClangTypeForIRGen (Type ty);
650
+
643
651
// / Determine whether the given Swift type is representable in a
644
652
// / given foreign language.
645
653
ForeignRepresentationInfo
Original file line number Diff line number Diff line change 54
54
#include " swift/Subsystems.h"
55
55
#include " swift/Syntax/References.h"
56
56
#include " swift/Syntax/SyntaxArena.h"
57
+ #include " clang/AST/Type.h"
57
58
#include " llvm/ADT/DenseMap.h"
58
59
#include " llvm/ADT/Statistic.h"
59
60
#include " llvm/ADT/StringMap.h"
@@ -4589,6 +4590,10 @@ ASTContext::getSwiftDeclForExportedClangDecl(const clang::Decl *decl) {
4589
4590
return impl.Converter ->getSwiftDeclForExportedClangDecl (decl);
4590
4591
}
4591
4592
4593
+ const clang::Type *
4594
+ ASTContext::getClangTypeForIRGen (Type ty) {
4595
+ return getClangTypeConverter ().convert (ty).getTypePtrOrNull ();
4596
+ }
4592
4597
4593
4598
CanGenericSignature ASTContext::getSingleGenericParameterSignature () const {
4594
4599
if (auto theSig = getImpl ().SingleGenericParameterSignature )
Original file line number Diff line number Diff line change 12
12
//
13
13
// This file implements generation of Clang AST types from Swift AST types for
14
14
// types that are representable in Objective-C interfaces.
15
- // Large chunks of the code are lightly modified versions of the code in
16
- // IRGen/GenClangType.cpp (which should eventually go away), so make sure
17
- // to keep the two in sync.
18
- // The three major differences are that, in this file:
15
+ //
16
+ // The usage of ClangTypeConverter at the AST level means that we may
17
+ // encounter ill-formed types and/or sugared types. To avoid crashing and
18
+ // keeping sugar as much as possible (in case the generated Clang type needs
19
+ // to be surfaced to the user):
20
+ //
19
21
// 1. We fail gracefully instead of asserting/UB.
20
22
// 2. We try to keep clang sugar instead of discarding it.
21
- // 3. We use getAs instead of cast as we handle Swift types with sugar.
22
23
//
23
24
// ===----------------------------------------------------------------------===//
24
25
Original file line number Diff line number Diff line change @@ -94,6 +94,8 @@ class ClangTypeConverter :
94
94
SmallVectorImpl<clang::TemplateArgument> &templateArgs);
95
95
96
96
private:
97
+ friend ASTContext; // HACK: expose `convert` method to ASTContext
98
+
97
99
clang::QualType convert (Type type);
98
100
99
101
clang::QualType convertMemberType (NominalTypeDecl *DC,
You can’t perform that action at this time.
0 commit comments