1 //===--- LangOptions.h - C Language Family Language Options -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines the LangOptions interface.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CLANG_LANGOPTIONS_H
15 #define LLVM_CLANG_LANGOPTIONS_H
18 #include "clang/Basic/Visibility.h"
22 /// LangOptions - This class keeps track of the various options that can be
23 /// enabled, which controls the dialect of C that is accepted.
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.
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
51 unsigned AppleKext : 1; // Allow apple kext features.
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.
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)
71 unsigned ThreadsafeStatics : 1; // Whether static initializers are protected
73 unsigned POSIXThreads : 1; // Compiling with POSIX thread support
75 unsigned Blocks : 1; // block extension to C
76 unsigned EmitAllDecls : 1; // Emit all declarations, even if
78 unsigned MathErrno : 1; // Math functions must respect errno
79 // (modulo the platform support).
81 unsigned HeinousExtensions : 1; // Extensions that we really don't like and
82 // may be ripped out at any time.
84 unsigned Optimize : 1; // Whether __OPTIMIZE__ should be defined.
85 unsigned OptimizeSize : 1; // Whether __OPTIMIZE_SIZE__ should be
87 unsigned Static : 1; // Should __STATIC__ be defined (as
88 // opposed to __DYNAMIC__).
89 unsigned PICLevel : 2; // The value for __PIC__, if non-zero.
91 unsigned GNUInline : 1; // Should GNU inline semantics be
92 // used (instead of C99 semantics).
93 unsigned NoInline : 1; // Should __NO_INLINE__ be defined.
95 unsigned Deprecated : 1; // Should __DEPRECATED be defined.
97 unsigned ObjCGCBitmapPrint : 1; // Enable printing of gc's bitmap layout
98 // for __weak/__strong ivars.
100 unsigned AccessControl : 1; // Whether C++ access control should
102 unsigned CharIsSigned : 1; // Whether char is a signed or unsigned type
103 unsigned ShortWChar : 1; // Force wchar_t to be unsigned short int.
105 unsigned ShortEnums : 1; // The enum type will be equivalent to the
106 // smallest integer type with enough room.
108 unsigned OpenCL : 1; // OpenCL C99 language extensions.
109 unsigned CUDA : 1; // CUDA C++ language extensions.
111 unsigned AssumeSaneOperatorNew : 1; // Whether to add __attribute__((malloc))
112 // to the declaration of C++'s new
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
126 unsigned SpellChecking : 1; // Whether to perform spell-checking for error
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
140 unsigned FakeAddressSpaceMap : 1; // Use a fake address space map, for
141 // testing languages such as OpenCL.
143 unsigned MRTD : 1; // -mrtd calling convention
144 unsigned DelayedTemplateParsing : 1; // Delayed template parsing
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.
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.
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.
164 std::string ObjCConstantStringClass;
166 enum GCMode { NonGC, GCOnly, HybridGC };
167 enum StackProtectorMode { SSPOff, SSPOn, SSPReq };
169 enum SignedOverflowBehaviorTy {
170 SOB_Undefined, // Default C standard behavior.
171 SOB_Defined, // -fwrapv
172 SOB_Trapping // -ftrapv
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;
179 Trigraphs = BCPLComment = Bool = DollarIdents = AsmPreprocessor = 0;
180 GNUMode = GNUKeywords = ImplicitInt = Digraphs = 0;
182 ObjCAutoRefCount = 0;
183 ObjCRuntimeHasWeak = 0;
184 ObjCInferRelatedReturnType = 0;
185 GC = ObjC1 = ObjC2 = ObjCNonFragileABI = ObjCNonFragileABI2 = 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;
197 LaxVectorConversions = 1;
198 HeinousExtensions = 0;
199 AltiVec = OpenCL = CUDA = StackProtector = 0;
201 SymbolVisibility = (unsigned) DefaultVisibility;
203 ThreadsafeStatics = 1;
208 SignedOverflowBehavior = SOB_Undefined;
210 AssumeSaneOperatorNew = 1;
212 ElideConstructors = 1;
214 SignedOverflowBehavior = 0;
215 ObjCGCBitmapPrint = 0;
217 InstantiationDepth = 1024;
219 NumLargeByValueCopy = 0;
237 DumpRecordLayouts = 0;
238 DumpVTableLayouts = 0;
240 SinglePrecisionConstants = 0;
242 DefaultFPContract = 0;
243 NoBitFieldTypeAlign = 0;
244 FakeAddressSpaceMap = 0;
246 DelayedTemplateParsing = 0;
247 ParseUnknownAnytype = DebuggerSupport = 0;
250 GCMode getGCMode() const { return (GCMode) GC; }
251 void setGCMode(GCMode m) { GC = (unsigned) m; }
253 StackProtectorMode getStackProtectorMode() const {
254 return static_cast<StackProtectorMode>(StackProtector);
256 void setStackProtectorMode(StackProtectorMode m) {
257 StackProtector = static_cast<unsigned>(m);
260 Visibility getVisibilityMode() const {
261 return (Visibility) SymbolVisibility;
263 void setVisibilityMode(Visibility v) { SymbolVisibility = (unsigned) v; }
265 SignedOverflowBehaviorTy getSignedOverflowBehavior() const {
266 return (SignedOverflowBehaviorTy)SignedOverflowBehavior;
268 void setSignedOverflowBehavior(SignedOverflowBehaviorTy V) {
269 SignedOverflowBehavior = (unsigned)V;
272 bool isSignedOverflowDefined() const {
273 return getSignedOverflowBehavior() == SOB_Defined;
277 /// Floating point control options
280 unsigned fp_contract : 1;
282 FPOptions() : fp_contract(0) {}
284 FPOptions(const LangOptions &LangOpts) :
285 fp_contract(LangOpts.DefaultFPContract) {}
288 /// OpenCL volatile options
289 class OpenCLOptions {
291 #define OPENCLEXT(nm) unsigned nm : 1;
292 #include "clang/Basic/OpenCLExtensions.def"
295 #define OPENCLEXT(nm) nm = 0;
296 #include "clang/Basic/OpenCLExtensions.def"
300 } // end namespace clang