-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathTypeCheckObjC.h
132 lines (112 loc) · 4.38 KB
/
TypeCheckObjC.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
//===--- TypeCheckObjC.h - Type Checking for ObjC interop -------*- C++ -*-===//
//
// This source file is part of the Swift.org open source project
//
// Copyright (c) 2014 - 2017 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 provides utilities for type-checking interoperability with
// Objective-C.
//
//===----------------------------------------------------------------------===//
#ifndef SWIFT_SEMA_TYPE_CHECK_OBJC_H
#define SWIFT_SEMA_TYPE_CHECK_OBJC_H
#include "swift/AST/ForeignErrorConvention.h"
#include "llvm/ADT/Optional.h"
namespace swift {
class ASTContext;
class SubscriptDecl;
class TypeChecker;
class ValueDecl;
class VarDecl;
using llvm::Optional;
/// Describes the reason why are we trying to apply @objc to a declaration.
///
/// Should only affect diagnostics. If you change this enum, also change
/// the OBJC_ATTR_SELECT macro in DiagnosticsSema.def.
class ObjCReason {
public:
// The kind of reason.
enum Kind {
/// Has the '@cdecl' attribute.
ExplicitlyCDecl,
/// Has the 'dynamic' modifier.
ExplicitlyDynamic,
/// Has an explicit '@objc' attribute.
ExplicitlyObjC,
/// Has an explicit '@IBOutlet' attribute.
ExplicitlyIBOutlet,
/// Has an explicit '@IBAction' attribute.
ExplicitlyIBAction,
/// Has an explicit '@NSManaged' attribute.
ExplicitlyNSManaged,
/// Is a member of an @objc protocol.
MemberOfObjCProtocol,
/// Implicitly-introduced @objc.
ImplicitlyObjC,
/// Is an override of an @objc member.
OverridesObjC,
/// Is a witness to an @objc protocol requirement.
WitnessToObjC,
/// Has an explicit '@IBInspectable' attribute.
ExplicitlyIBInspectable,
/// Has an explicit '@GKInspectable' attribute.
ExplicitlyGKInspectable,
/// Is it a member of an @objc extension of a class.
MemberOfObjCExtension,
/// Is it a member of an @objcMembers class.
MemberOfObjCMembersClass,
/// A member of an Objective-C-defined class or subclass.
MemberOfObjCSubclass,
/// An accessor to a property.
Accessor,
};
private:
Kind kind;
/// When the kind is \c WitnessToObjC, the requirement being witnessed.
ValueDecl * decl = nullptr;
ObjCReason(Kind kind, ValueDecl *decl) : kind(kind), decl(decl) { }
public:
/// Implicit conversion from the trivial reason kinds.
ObjCReason(Kind kind) : kind(kind) {
assert(kind != WitnessToObjC && "Use ObjCReason::witnessToObjC()");
}
/// Retrieve the kind of requirement.
operator Kind() const { return kind; }
/// Form a reason specifying that we have a witness to the given @objc
/// requirement.
static ObjCReason witnessToObjC(ValueDecl *requirement) {
return ObjCReason(WitnessToObjC, requirement);
}
/// When the entity should be @objc because it is a witness to an @objc
/// requirement, retrieve the requirement.
ValueDecl *getObjCRequirement() const {
assert(kind == WitnessToObjC);
return decl;
}
};
/// Determine whether we should diagnose conflicts due to inferring @objc
/// with this particular reason.
bool shouldDiagnoseObjCReason(ObjCReason reason, ASTContext &ctx);
/// Return the %select discriminator for the OBJC_ATTR_SELECT macro used to
/// complain about the correct attribute during @objc inference.
unsigned getObjCDiagnosticAttrKind(ObjCReason reason);
/// Figure out if a declaration should be exported to Objective-C.
Optional<ObjCReason> shouldMarkAsObjC(TypeChecker &TC,
const ValueDecl *VD,
bool allowImplicit = false);
/// Record whether the given declaration is @objc, and why.
void markAsObjC(TypeChecker &TC, ValueDecl *D,
Optional<ObjCReason> isObjC,
Optional<ForeignErrorConvention> errorConvention = llvm::None);
/// Determine whether the given variable can be represented in Objective-C.
bool isRepresentableInObjC(const VarDecl *VD, ObjCReason Reason);
/// Determine whether the given subscript can be represented in Objective-C.
bool isRepresentableInObjC(const SubscriptDecl *SD, ObjCReason Reason);
} // end namespace swift
#endif // SWIFT_SEMA_TYPE_CHECK_OBJC_H