]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - contrib/llvm/tools/clang/include/clang/Basic/LangOptions.h
Copy head to stable/9 as part of 9.0-RELEASE release cycle.
[FreeBSD/stable/9.git] / contrib / llvm / tools / clang / include / clang / Basic / LangOptions.h
1 //===--- LangOptions.h - C Language Family Language Options -----*- 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 //  This file defines the LangOptions interface.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_CLANG_LANGOPTIONS_H
15 #define LLVM_CLANG_LANGOPTIONS_H
16
17 #include <string>
18 #include "clang/Basic/Visibility.h"
19
20 namespace clang {
21
22 /// LangOptions - This class keeps track of the various options that can be
23 /// enabled, which controls the dialect of C that is accepted.
24 class LangOptions {
25 public:
26   unsigned Trigraphs         : 1;  // Trigraphs in source files.
27   unsigned BCPLComment       : 1;  // BCPL-style '//' comments.
28   unsigned Bool              : 1;  // 'bool', 'true', 'false' keywords.
29   unsigned DollarIdents      : 1;  // '$' allowed in identifiers.
30   unsigned AsmPreprocessor   : 1;  // Preprocessor in asm mode.
31   unsigned GNUMode           : 1;  // True in gnu99 mode false in c99 mode (etc)
32   unsigned GNUKeywords       : 1;  // True if GNU-only keywords are allowed
33   unsigned ImplicitInt       : 1;  // C89 implicit 'int'.
34   unsigned Digraphs          : 1;  // C94, C99 and C++
35   unsigned HexFloats         : 1;  // C99 Hexadecimal float constants.
36   unsigned C99               : 1;  // C99 Support
37   unsigned C1X               : 1;  // C1X Support
38   unsigned Microsoft         : 1;  // Microsoft extensions.
39   unsigned Borland           : 1;  // Borland extensions.
40   unsigned CPlusPlus         : 1;  // C++ Support
41   unsigned CPlusPlus0x       : 1;  // C++0x Support
42   unsigned CXXOperatorNames  : 1;  // Treat C++ operator names as keywords.
43
44   unsigned ObjC1             : 1;  // Objective-C 1 support enabled.
45   unsigned ObjC2             : 1;  // Objective-C 2 support enabled.
46   unsigned ObjCNonFragileABI : 1;  // Objective-C modern abi enabled
47   unsigned ObjCNonFragileABI2 : 1;  // Objective-C enhanced modern abi enabled
48   unsigned ObjCDefaultSynthProperties : 1; // Objective-C auto-synthesized properties.
49   unsigned ObjCInferRelatedResultType : 1; // Infer Objective-C related return
50                                            // types
51   unsigned AppleKext         : 1;  // Allow apple kext features.
52
53   unsigned PascalStrings     : 1;  // Allow Pascal strings
54   unsigned WritableStrings   : 1;  // Allow writable strings
55   unsigned ConstStrings      : 1;  // Add const qualifier to strings (-Wwrite-strings)
56   unsigned LaxVectorConversions : 1;
57   unsigned AltiVec           : 1;  // Support AltiVec-style vector initializers.
58   unsigned Exceptions        : 1;  // Support exception handling.
59   unsigned ObjCExceptions    : 1;  // Support Objective-C exceptions.
60   unsigned CXXExceptions     : 1;  // Support C++ exceptions.
61   unsigned SjLjExceptions    : 1;  // Use setjmp-longjump exception handling.
62   unsigned TraditionalCPP    : 1; /// Enable some traditional CPP emulation.
63   unsigned RTTI              : 1;  // Support RTTI information.
64
65   unsigned MSBitfields       : 1; // MS-compatible structure layout
66   unsigned NeXTRuntime       : 1; // Use NeXT runtime.
67   unsigned Freestanding      : 1; // Freestanding implementation
68   unsigned FormatExtensions  : 1; // FreeBSD format extensions (-fformat-extensions)
69   unsigned NoBuiltin         : 1; // Do not use builtin functions (-fno-builtin)
70
71   unsigned ThreadsafeStatics : 1; // Whether static initializers are protected
72                                   // by locks.
73   unsigned POSIXThreads      : 1; // Compiling with POSIX thread support
74                                   // (-pthread)
75   unsigned Blocks            : 1; // block extension to C
76   unsigned EmitAllDecls      : 1; // Emit all declarations, even if
77                                   // they are unused.
78   unsigned MathErrno         : 1; // Math functions must respect errno
79                                   // (modulo the platform support).
80
81   unsigned HeinousExtensions : 1; // Extensions that we really don't like and
82                                   // may be ripped out at any time.
83
84   unsigned Optimize          : 1; // Whether __OPTIMIZE__ should be defined.
85   unsigned OptimizeSize      : 1; // Whether __OPTIMIZE_SIZE__ should be
86                                   // defined.
87   unsigned Static            : 1; // Should __STATIC__ be defined (as
88                                   // opposed to __DYNAMIC__).
89   unsigned PICLevel          : 2; // The value for __PIC__, if non-zero.
90
91   unsigned GNUInline         : 1; // Should GNU inline semantics be
92                                   // used (instead of C99 semantics).
93   unsigned NoInline          : 1; // Should __NO_INLINE__ be defined.
94
95   unsigned Deprecated        : 1; // Should __DEPRECATED be defined.
96
97   unsigned ObjCGCBitmapPrint : 1; // Enable printing of gc's bitmap layout
98                                   // for __weak/__strong ivars.
99
100   unsigned AccessControl     : 1; // Whether C++ access control should
101                                   // be enabled.
102   unsigned CharIsSigned      : 1; // Whether char is a signed or unsigned type
103   unsigned ShortWChar        : 1; // Force wchar_t to be unsigned short int.
104
105   unsigned ShortEnums        : 1; // The enum type will be equivalent to the
106                                   // smallest integer type with enough room.
107
108   unsigned OpenCL            : 1; // OpenCL C99 language extensions.
109   unsigned CUDA              : 1; // CUDA C++ language extensions.
110
111   unsigned AssumeSaneOperatorNew : 1; // Whether to add __attribute__((malloc))
112                                       // to the declaration of C++'s new
113                                       // operators
114   unsigned ElideConstructors : 1; // Whether C++ copy constructors should be
115                                   // elided if possible.
116   unsigned CatchUndefined    : 1; // Generate code to check for undefined ops.
117   unsigned DumpRecordLayouts : 1; /// Dump the layout of IRgen'd records.
118   unsigned DumpVTableLayouts : 1; /// Dump the layouts of emitted vtables.
119   unsigned NoConstantCFStrings : 1;  // Do not do CF strings
120   unsigned InlineVisibilityHidden : 1; // Whether inline C++ methods have
121                                        // hidden visibility by default.
122   unsigned ParseUnknownAnytype: 1; /// Let the user write __unknown_anytype.
123   unsigned DebuggerSupport : 1;   /// Do things that only make sense when
124                                   /// supporting a debugger
125
126   unsigned SpellChecking : 1; // Whether to perform spell-checking for error
127                               // recovery.
128   unsigned SinglePrecisionConstants : 1; // Whether to treat double-precision
129                                          // floating point constants as
130                                          // single precision constants.
131   unsigned FastRelaxedMath : 1; // OpenCL fast relaxed math (on its own,
132                                 // defines __FAST_RELAXED_MATH__).
133   unsigned DefaultFPContract : 1; // Default setting for FP_CONTRACT
134   // FIXME: This is just a temporary option, for testing purposes.
135   unsigned NoBitFieldTypeAlign : 1;
136   unsigned ObjCAutoRefCount : 1; // Objective C automated reference counting
137   unsigned ObjCRuntimeHasWeak : 1; // The ARC runtime supports __weak
138   unsigned ObjCInferRelatedReturnType : 1; // Infer Objective-C related return
139                                            // types
140   unsigned FakeAddressSpaceMap : 1; // Use a fake address space map, for
141                                     // testing languages such as OpenCL.
142
143   unsigned MRTD : 1;            // -mrtd calling convention
144   unsigned DelayedTemplateParsing : 1;  // Delayed template parsing
145
146 private:
147   // We declare multibit enums as unsigned because MSVC insists on making enums
148   // signed.  Set/Query these values using accessors.
149   unsigned GC : 2;                // Objective-C Garbage Collection modes.
150   unsigned SymbolVisibility  : 3; // Symbol's visibility.
151   unsigned StackProtector    : 2; // Whether stack protectors are on.
152   unsigned SignedOverflowBehavior : 2; // How to handle signed integer overflow.
153
154 public:
155   unsigned InstantiationDepth;    // Maximum template instantiation depth.
156   unsigned NumLargeByValueCopy;   // Warn if parameter/return value is larger
157                                   // in bytes than this setting. 0 is no check.
158
159   // Version of Microsoft Visual C/C++ we are pretending to be. This is
160   // temporary until we support all MS extensions used in Windows SDK and stdlib
161   // headers. Sets _MSC_VER.
162   unsigned MSCVersion;
163
164   std::string ObjCConstantStringClass;
165
166   enum GCMode { NonGC, GCOnly, HybridGC };
167   enum StackProtectorMode { SSPOff, SSPOn, SSPReq };
168
169   enum SignedOverflowBehaviorTy {
170     SOB_Undefined,  // Default C standard behavior.
171     SOB_Defined,    // -fwrapv
172     SOB_Trapping    // -ftrapv
173   };
174   /// The name of the handler function to be called when -ftrapv is specified.
175   /// If none is specified, abort (GCC-compatible behaviour).
176   std::string OverflowHandler;
177
178   LangOptions() {
179     Trigraphs = BCPLComment = Bool = DollarIdents = AsmPreprocessor = 0;
180     GNUMode = GNUKeywords = ImplicitInt = Digraphs = 0;
181     HexFloats = 0;
182     ObjCAutoRefCount = 0;
183     ObjCRuntimeHasWeak = 0;
184     ObjCInferRelatedReturnType = 0;
185     GC = ObjC1 = ObjC2 = ObjCNonFragileABI = ObjCNonFragileABI2 = 0;
186     AppleKext = 0;
187     ObjCDefaultSynthProperties = 0;
188     ObjCInferRelatedResultType = 1;
189     NoConstantCFStrings = 0; InlineVisibilityHidden = 0;
190     C99 = C1X = Microsoft = Borland = CPlusPlus = CPlusPlus0x = 0;
191     CXXOperatorNames = PascalStrings = WritableStrings = ConstStrings = 0;
192     Exceptions = ObjCExceptions = CXXExceptions = SjLjExceptions = 0;
193     TraditionalCPP = Freestanding = NoBuiltin = 0;
194     MSBitfields = 0;
195     NeXTRuntime = 1;
196     RTTI = 1;
197     LaxVectorConversions = 1;
198     HeinousExtensions = 0;
199     AltiVec = OpenCL = CUDA = StackProtector = 0;
200
201     SymbolVisibility = (unsigned) DefaultVisibility;
202
203     ThreadsafeStatics = 1;
204     POSIXThreads = 0;
205     Blocks = 0;
206     EmitAllDecls = 0;
207     MathErrno = 1;
208     SignedOverflowBehavior = SOB_Undefined;
209
210     AssumeSaneOperatorNew = 1;
211     AccessControl = 1;
212     ElideConstructors = 1;
213
214     SignedOverflowBehavior = 0;
215     ObjCGCBitmapPrint = 0;
216
217     InstantiationDepth = 1024;
218
219     NumLargeByValueCopy = 0;
220     MSCVersion = 0;
221     
222     Optimize = 0;
223     OptimizeSize = 0;
224
225     Static = 0;
226     PICLevel = 0;
227
228     GNUInline = 0;
229     NoInline = 0;
230
231     Deprecated = 0;
232
233     CharIsSigned = 1;
234     ShortWChar = 0;
235     ShortEnums = 0;
236     CatchUndefined = 0;
237     DumpRecordLayouts = 0;
238     DumpVTableLayouts = 0;
239     SpellChecking = 1;
240     SinglePrecisionConstants = 0;
241     FastRelaxedMath = 0;
242     DefaultFPContract = 0;
243     NoBitFieldTypeAlign = 0;
244     FakeAddressSpaceMap = 0;
245     MRTD = 0;
246     DelayedTemplateParsing = 0;
247     ParseUnknownAnytype = DebuggerSupport = 0;
248   }
249
250   GCMode getGCMode() const { return (GCMode) GC; }
251   void setGCMode(GCMode m) { GC = (unsigned) m; }
252
253   StackProtectorMode getStackProtectorMode() const {
254     return static_cast<StackProtectorMode>(StackProtector);
255   }
256   void setStackProtectorMode(StackProtectorMode m) {
257     StackProtector = static_cast<unsigned>(m);
258   }
259
260   Visibility getVisibilityMode() const {
261     return (Visibility) SymbolVisibility;
262   }
263   void setVisibilityMode(Visibility v) { SymbolVisibility = (unsigned) v; }
264
265   SignedOverflowBehaviorTy getSignedOverflowBehavior() const {
266     return (SignedOverflowBehaviorTy)SignedOverflowBehavior;
267   }
268   void setSignedOverflowBehavior(SignedOverflowBehaviorTy V) {
269     SignedOverflowBehavior = (unsigned)V;
270   }
271
272   bool isSignedOverflowDefined() const {
273     return getSignedOverflowBehavior() == SOB_Defined;
274   }
275 };
276
277 /// Floating point control options
278 class FPOptions {
279 public:
280   unsigned fp_contract : 1;
281
282   FPOptions() : fp_contract(0) {}
283
284   FPOptions(const LangOptions &LangOpts) :
285     fp_contract(LangOpts.DefaultFPContract) {}
286 };
287
288 /// OpenCL volatile options
289 class OpenCLOptions {
290 public:
291 #define OPENCLEXT(nm)  unsigned nm : 1;
292 #include "clang/Basic/OpenCLExtensions.def"
293
294   OpenCLOptions() {
295 #define OPENCLEXT(nm)   nm = 0;
296 #include "clang/Basic/OpenCLExtensions.def"
297   }
298 };
299
300 }  // end namespace clang
301
302 #endif