mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Sema: Type checking for C function pointers.
Since a function pointer doesn't carry any context, we can only form a C function pointer from a static reference to a global function or a context-free local function or closure. (Or maybe a static function applied to its metatype, but that's not handled here yet.) As a placeholder for a to-be-bikeshedded surface syntax, let the existing @cc(cdecl) attribute appear in source text when the -enable-c-function-pointers frontend flag is passed. Swift SVN r25308
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
#include "swift/AST/Decl.h"
|
||||
#include "swift/AST/Expr.h"
|
||||
#include "swift/AST/Types.h"
|
||||
#include "llvm/ADT/DenseMap.h"
|
||||
#include "llvm/ADT/PointerUnion.h"
|
||||
|
||||
namespace swift {
|
||||
@@ -27,6 +28,11 @@ class CaptureInfo;
|
||||
class AnyFunctionRef {
|
||||
PointerUnion<AbstractFunctionDecl *, AbstractClosureExpr *> TheFunction;
|
||||
|
||||
friend struct llvm::DenseMapInfo<AnyFunctionRef>;
|
||||
|
||||
AnyFunctionRef(decltype(TheFunction) TheFunction)
|
||||
: TheFunction(TheFunction) {}
|
||||
|
||||
public:
|
||||
AnyFunctionRef(AbstractFunctionDecl *AFD) : TheFunction(AFD) {
|
||||
assert(AFD && "should have a function");
|
||||
@@ -117,5 +123,29 @@ public:
|
||||
|
||||
} // namespace swift
|
||||
|
||||
namespace llvm {
|
||||
|
||||
template<>
|
||||
struct DenseMapInfo<swift::AnyFunctionRef> {
|
||||
using PointerUnion = decltype(swift::AnyFunctionRef::TheFunction);
|
||||
using PointerUnionTraits = DenseMapInfo<PointerUnion>;
|
||||
using AnyFunctionRef = swift::AnyFunctionRef;
|
||||
|
||||
static inline AnyFunctionRef getEmptyKey() {
|
||||
return AnyFunctionRef(PointerUnionTraits::getEmptyKey());
|
||||
}
|
||||
static inline AnyFunctionRef getTombstoneKey() {
|
||||
return AnyFunctionRef(PointerUnionTraits::getTombstoneKey());
|
||||
}
|
||||
static inline unsigned getHashValue(AnyFunctionRef ref) {
|
||||
return PointerUnionTraits::getHashValue(ref.TheFunction);
|
||||
}
|
||||
static bool isEqual(AnyFunctionRef a, AnyFunctionRef b) {
|
||||
return a.TheFunction == b.TheFunction;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // LLVM_SWIFT_AST_ANY_FUNCTION_REF_H
|
||||
|
||||
|
||||
Reference in New Issue
Block a user