Skip to content

Commit e7be41d

Browse files
Merge pull request #27479 from varungandhi-apple/vg-track-clang-function-types
Track Clang function types in the AST
2 parents dc5f896 + ee18c00 commit e7be41d

30 files changed

+1421
-247
lines changed

include/swift/AST/ASTContext.h

+14
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "swift/AST/Identifier.h"
2323
#include "swift/AST/SearchPathOptions.h"
2424
#include "swift/AST/Type.h"
25+
#include "swift/AST/Types.h"
2526
#include "swift/AST/TypeAlignments.h"
2627
#include "swift/Basic/LangOptions.h"
2728
#include "swift/Basic/Malloc.h"
@@ -557,6 +558,19 @@ class ASTContext final {
557558
Type getBridgedToObjC(const DeclContext *dc, Type type,
558559
Type *bridgedValueType = nullptr) const;
559560

561+
/// Get the Clang type corresponding to a Swift function type.
562+
///
563+
/// \param params The function parameters.
564+
/// \param resultTy The Swift result type.
565+
/// \param incompleteExtInfo Used to convey escaping and throwing
566+
/// information, in case it is needed.
567+
/// \param trueRep The actual calling convention, which must be C-compatible.
568+
/// The calling convention in \p incompleteExtInfo is ignored.
569+
const clang::Type *
570+
getClangFunctionType(ArrayRef<AnyFunctionType::Param> params, Type resultTy,
571+
const FunctionType::ExtInfo incompleteExtInfo,
572+
FunctionTypeRepresentation trueRep);
573+
560574
/// Determine whether the given Swift type is representable in a
561575
/// given foreign language.
562576
ForeignRepresentationInfo

include/swift/AST/ClangModuleLoader.h

+2
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class ASTContext;
2020
class CompilerInstance;
2121
class Preprocessor;
2222
class Sema;
23+
class TargetInfo;
2324
} // namespace clang
2425

2526
namespace swift {
@@ -46,6 +47,7 @@ class ClangModuleLoader : public ModuleLoader {
4647
using ModuleLoader::ModuleLoader;
4748

4849
public:
50+
virtual clang::TargetInfo &getTargetInfo() const = 0;
4951
virtual clang::ASTContext &getClangASTContext() const = 0;
5052
virtual clang::Preprocessor &getClangPreprocessor() const = 0;
5153
virtual clang::Sema &getClangSema() const = 0;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
//=- ClangSwiftTypeCorrespondence.h - Relations between Clang & Swift types -=//
2+
//
3+
// This source file is part of the Swift.org open source project
4+
//
5+
// Copyright (c) 2019 Apple Inc. and the Swift project authors
6+
// Licensed under Apache License v2.0 with Runtime Library Exception
7+
//
8+
// See https://swift.org/LICENSE.txt for license information
9+
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
10+
//
11+
//===----------------------------------------------------------------------===//
12+
//
13+
// This file describes some common relations between Clang types and Swift
14+
// types that are need by the ClangTypeConverter and parts of ClangImporter.
15+
//
16+
// Since ClangTypeConverter is an implementation detail, ClangImporter should
17+
// not depend on ClangTypeConverter.h.
18+
//
19+
//===----------------------------------------------------------------------===//
20+
21+
#ifndef SWIFT_AST_CLANG_SWIFT_TYPE_CORRESPONDENCE_H
22+
#define SWIFT_AST_CLANG_SWIFT_TYPE_CORRESPONDENCE_H
23+
24+
namespace clang {
25+
class Type;
26+
}
27+
28+
namespace swift {
29+
/// Checks whether a Clang type can be imported as a Swift Optional type.
30+
///
31+
/// For example, a `const uint8_t *` could be imported as
32+
/// `Optional<UnsafePointer<UInt8>>`.
33+
bool canImportAsOptional(const clang::Type *type);
34+
}
35+
36+
#endif /* SWIFT_AST_CLANG_SWIFT_TYPE_CORRESPONDENCE_H */

0 commit comments

Comments
 (0)