]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Basic/ObjCRuntime.h
MFV: tcpdump 4.3.0.
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / clang / include / clang / Basic / ObjCRuntime.h
1 //===--- ObjCRuntime.h - Objective-C Runtime Configuration ------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 ///
10 /// \file
11 /// \brief Defines types useful for describing an Objective-C runtime.
12 ///
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CLANG_OBJCRUNTIME_H
16 #define LLVM_CLANG_OBJCRUNTIME_H
17
18 #include "clang/Basic/VersionTuple.h"
19 #include "llvm/ADT/Triple.h"
20 #include "llvm/Support/ErrorHandling.h"
21
22 namespace clang {
23
24 /// \brief The basic abstraction for the target Objective-C runtime.
25 class ObjCRuntime {
26 public:
27   /// \brief The basic Objective-C runtimes that we know about.
28   enum Kind {
29     /// 'macosx' is the Apple-provided NeXT-derived runtime on Mac OS
30     /// X platforms that use the non-fragile ABI; the version is a
31     /// release of that OS.
32     MacOSX,
33
34     /// 'macosx-fragile' is the Apple-provided NeXT-derived runtime on
35     /// Mac OS X platforms that use the fragile ABI; the version is a
36     /// release of that OS.
37     FragileMacOSX,
38
39     /// 'ios' is the Apple-provided NeXT-derived runtime on iOS or the iOS
40     /// simulator;  it is always non-fragile.  The version is a release
41     /// version of iOS.
42     iOS,
43
44     /// 'gcc' is the Objective-C runtime shipped with GCC, implementing a
45     /// fragile Objective-C ABI
46     GCC,
47
48     /// 'gnustep' is the modern non-fragile GNUstep runtime.
49     GNUstep,
50
51     /// 'objfw' is the Objective-C runtime included in ObjFW
52     ObjFW
53   };
54
55 private:
56   Kind TheKind;
57   VersionTuple Version;
58
59 public:
60   /// A bogus initialization of the runtime.
61   ObjCRuntime() : TheKind(MacOSX) {}
62
63   ObjCRuntime(Kind kind, const VersionTuple &version)
64     : TheKind(kind), Version(version) {}
65
66   void set(Kind kind, VersionTuple version) {
67     TheKind = kind;
68     Version = version;
69   }
70
71   Kind getKind() const { return TheKind; }
72   const VersionTuple &getVersion() const { return Version; }
73
74   /// \brief Does this runtime follow the set of implied behaviors for a
75   /// "non-fragile" ABI?
76   bool isNonFragile() const {
77     switch (getKind()) {
78     case FragileMacOSX: return false;
79     case GCC: return false;
80     case MacOSX: return true;
81     case GNUstep: return true;
82     case ObjFW: return false;
83     case iOS: return true;
84     }
85     llvm_unreachable("bad kind");
86   }
87
88   /// The inverse of isNonFragile():  does this runtime follow the set of
89   /// implied behaviors for a "fragile" ABI?
90   bool isFragile() const { return !isNonFragile(); }
91
92   /// The default dispatch mechanism to use for the specified architecture
93   bool isLegacyDispatchDefaultForArch(llvm::Triple::ArchType Arch) {
94     // The GNUstep runtime uses a newer dispatch method by default from
95     // version 1.6 onwards
96     if (getKind() == GNUstep && getVersion() >= VersionTuple(1, 6)) {
97       if (Arch == llvm::Triple::arm ||
98           Arch == llvm::Triple::x86 ||
99           Arch == llvm::Triple::x86_64)
100         return false;
101       // Mac runtimes use legacy dispatch everywhere except x86-64
102     } else if (isNeXTFamily() && isNonFragile())
103         return Arch != llvm::Triple::x86_64;
104     return true;
105   }
106
107   /// \brief Is this runtime basically of the GNUstep family of runtimes?
108   bool isGNUFamily() const {
109     switch (getKind()) {
110     case FragileMacOSX:
111     case MacOSX:
112     case iOS:
113       return false;
114     case GCC:
115     case GNUstep:
116     case ObjFW:
117       return true;
118     }
119     llvm_unreachable("bad kind");
120   }
121
122   /// \brief Is this runtime basically of the NeXT family of runtimes?
123   bool isNeXTFamily() const {
124     // For now, this is just the inverse of isGNUFamily(), but that's
125     // not inherently true.
126     return !isGNUFamily();
127   }
128
129   /// \brief Does this runtime natively provide the ARC entrypoints? 
130   ///
131   /// ARC cannot be directly supported on a platform that does not provide
132   /// these entrypoints, although it may be supportable via a stub
133   /// library.
134   bool hasARC() const {
135     switch (getKind()) {
136     case FragileMacOSX: return false;
137     case MacOSX: return getVersion() >= VersionTuple(10, 7);
138     case iOS: return getVersion() >= VersionTuple(5);
139
140     case GCC: return false;
141     case GNUstep: return getVersion() >= VersionTuple(1, 6);
142     case ObjFW: return false; // XXX: this will change soon
143     }
144     llvm_unreachable("bad kind");
145   }
146
147   /// \brief Does this runtime natively provide ARC-compliant 'weak'
148   /// entrypoints?
149   bool hasWeak() const {
150     // Right now, this is always equivalent to the ARC decision.
151     return hasARC();
152   }
153
154   /// \brief Does this runtime directly support the subscripting methods?
155   ///
156   /// This is really a property of the library, not the runtime.
157   bool hasSubscripting() const {
158     switch (getKind()) {
159     case FragileMacOSX: return false;
160     case MacOSX: return getVersion() >= VersionTuple(10, 8);
161     case iOS: return false;
162
163     // This is really a lie, because some implementations and versions
164     // of the runtime do not support ARC.  Probably -fgnu-runtime
165     // should imply a "maximal" runtime or something?
166     case GCC: return true;
167     case GNUstep: return true;
168     case ObjFW: return true;
169     }
170     llvm_unreachable("bad kind");
171   }
172
173   /// \brief Does this runtime allow sizeof or alignof on object types?
174   bool allowsSizeofAlignof() const {
175     return isFragile();
176   }
177
178   /// \brief Does this runtime allow pointer arithmetic on objects?
179   ///
180   /// This covers +, -, ++, --, and (if isSubscriptPointerArithmetic()
181   /// yields true) [].
182   bool allowsPointerArithmetic() const {
183     switch (getKind()) {
184     case FragileMacOSX:
185     case GCC:
186       return true;
187     case MacOSX:
188     case iOS:
189     case GNUstep:
190     case ObjFW:
191       return false;
192     }
193     llvm_unreachable("bad kind");
194   }
195
196   /// \brief Is subscripting pointer arithmetic?
197   bool isSubscriptPointerArithmetic() const {
198     return allowsPointerArithmetic();
199   }
200
201   /// \brief Does this runtime provide an objc_terminate function?
202   ///
203   /// This is used in handlers for exceptions during the unwind process;
204   /// without it, abort() must be used in pure ObjC files.
205   bool hasTerminate() const {
206     switch (getKind()) {
207     case FragileMacOSX: return getVersion() >= VersionTuple(10, 8);
208     case MacOSX: return getVersion() >= VersionTuple(10, 8);
209     case iOS: return getVersion() >= VersionTuple(5);
210     case GCC: return false;
211     case GNUstep: return false;
212     case ObjFW: return false;
213     }
214     llvm_unreachable("bad kind");
215   }
216
217   /// \brief Does this runtime support weakly importing classes?
218   bool hasWeakClassImport() const {
219     switch (getKind()) {
220     case MacOSX: return true;
221     case iOS: return true;
222     case FragileMacOSX: return false;
223     case GCC: return true;
224     case GNUstep: return true;
225     case ObjFW: return true;
226     }
227     llvm_unreachable("bad kind");
228   }
229   /// \brief Does this runtime use zero-cost exceptions?
230   bool hasUnwindExceptions() const {
231     switch (getKind()) {
232     case MacOSX: return true;
233     case iOS: return true;
234     case FragileMacOSX: return false;
235     case GCC: return true;
236     case GNUstep: return true;
237     case ObjFW: return true;
238     }
239     llvm_unreachable("bad kind");
240   }
241
242   /// \brief Try to parse an Objective-C runtime specification from the given
243   /// string.
244   ///
245   /// \return true on error.
246   bool tryParse(StringRef input);
247
248   std::string getAsString() const;
249
250   friend bool operator==(const ObjCRuntime &left, const ObjCRuntime &right) {
251     return left.getKind() == right.getKind() &&
252            left.getVersion() == right.getVersion();
253   }
254
255   friend bool operator!=(const ObjCRuntime &left, const ObjCRuntime &right) {
256     return !(left == right);
257   }
258 };
259
260 raw_ostream &operator<<(raw_ostream &out, const ObjCRuntime &value);
261
262 }  // end namespace clang
263
264 #endif