Skip to content

Track Clang function types in the AST #27479

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 8 commits into from
Dec 4, 2019
14 changes: 14 additions & 0 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "swift/AST/Identifier.h"
#include "swift/AST/SearchPathOptions.h"
#include "swift/AST/Type.h"
#include "swift/AST/Types.h"
#include "swift/AST/TypeAlignments.h"
#include "swift/Basic/LangOptions.h"
#include "swift/Basic/Malloc.h"
Expand Down Expand Up @@ -557,6 +558,19 @@ class ASTContext final {
Type getBridgedToObjC(const DeclContext *dc, Type type,
Type *bridgedValueType = nullptr) const;

/// Get the Clang type corresponding to a Swift function type.
///
/// \param params The function parameters.
/// \param resultTy The Swift result type.
/// \param incompleteExtInfo Used to convey escaping and throwing
/// information, in case it is needed.
/// \param trueRep The actual calling convention, which must be C-compatible.
/// The calling convention in \p incompleteExtInfo is ignored.
const clang::Type *
getClangFunctionType(ArrayRef<AnyFunctionType::Param> params, Type resultTy,
const FunctionType::ExtInfo incompleteExtInfo,
FunctionTypeRepresentation trueRep);

/// Determine whether the given Swift type is representable in a
/// given foreign language.
ForeignRepresentationInfo
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/ClangModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class ASTContext;
class CompilerInstance;
class Preprocessor;
class Sema;
class TargetInfo;
} // namespace clang

namespace swift {
Expand All @@ -46,6 +47,7 @@ class ClangModuleLoader : public ModuleLoader {
using ModuleLoader::ModuleLoader;

public:
virtual clang::TargetInfo &getTargetInfo() const = 0;
virtual clang::ASTContext &getClangASTContext() const = 0;
virtual clang::Preprocessor &getClangPreprocessor() const = 0;
virtual clang::Sema &getClangSema() const = 0;
Expand Down
36 changes: 36 additions & 0 deletions include/swift/AST/ClangSwiftTypeCorrespondence.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//=- ClangSwiftTypeCorrespondence.h - Relations between Clang & Swift types -=//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2019 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
//
//===----------------------------------------------------------------------===//
//
// This file describes some common relations between Clang types and Swift
// types that are need by the ClangTypeConverter and parts of ClangImporter.
//
// Since ClangTypeConverter is an implementation detail, ClangImporter should
// not depend on ClangTypeConverter.h.
//
//===----------------------------------------------------------------------===//

#ifndef SWIFT_AST_CLANG_SWIFT_TYPE_CORRESPONDENCE_H
#define SWIFT_AST_CLANG_SWIFT_TYPE_CORRESPONDENCE_H

namespace clang {
class Type;
}

namespace swift {
/// Checks whether a Clang type can be imported as a Swift Optional type.
///
/// For example, a `const uint8_t *` could be imported as
/// `Optional<UnsafePointer<UInt8>>`.
bool canImportAsOptional(const clang::Type *type);
}

#endif /* SWIFT_AST_CLANG_SWIFT_TYPE_CORRESPONDENCE_H */
Loading