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.
124 unsigned SpellChecking : 1; // Whether to perform spell-checking for error
126 unsigned SinglePrecisionConstants : 1; // Whether to treat double-precision
127 // floating point constants as
128 // single precision constants.
129 unsigned FastRelaxedMath : 1; // OpenCL fast relaxed math (on its own,
130 // defines __FAST_RELAXED_MATH__).
131 unsigned DefaultFPContract : 1; // Default setting for FP_CONTRACT
132 // FIXME: This is just a temporary option, for testing purposes.
133 unsigned NoBitFieldTypeAlign : 1;
134 unsigned FakeAddressSpaceMap : 1; // Use a fake address space map, for
135 // testing languages such as OpenCL.
137 unsigned MRTD : 1; // -mrtd calling convention
138 unsigned DelayedTemplateParsing : 1; // Delayed template parsing
141 // We declare multibit enums as unsigned because MSVC insists on making enums
142 // signed. Set/Query these values using accessors.
143 unsigned GC : 2; // Objective-C Garbage Collection modes.
144 unsigned SymbolVisibility : 3; // Symbol's visibility.
145 unsigned StackProtector : 2; // Whether stack protectors are on.
146 unsigned SignedOverflowBehavior : 2; // How to handle signed integer overflow.
149 unsigned InstantiationDepth; // Maximum template instantiation depth.
150 unsigned NumLargeByValueCopy; // Warn if parameter/return value is larger
151 // in bytes than this setting. 0 is no check.
153 // Version of Microsoft Visual C/C++ we are pretending to be. This is
154 // temporary until we support all MS extensions used in Windows SDK and stdlib
155 // headers. Sets _MSC_VER.
158 std::string ObjCConstantStringClass;
160 enum GCMode { NonGC, GCOnly, HybridGC };
161 enum StackProtectorMode { SSPOff, SSPOn, SSPReq };
163 enum SignedOverflowBehaviorTy {
164 SOB_Undefined, // Default C standard behavior.
165 SOB_Defined, // -fwrapv
166 SOB_Trapping // -ftrapv
168 /// The name of the handler function to be called when -ftrapv is specified.
169 /// If none is specified, abort (GCC-compatible behaviour).
170 std::string OverflowHandler;
173 Trigraphs = BCPLComment = Bool = DollarIdents = AsmPreprocessor = 0;
174 GNUMode = GNUKeywords = ImplicitInt = Digraphs = 0;
176 GC = ObjC1 = ObjC2 = ObjCNonFragileABI = ObjCNonFragileABI2 = 0;
178 ObjCDefaultSynthProperties = 0;
179 ObjCInferRelatedResultType = 0;
180 NoConstantCFStrings = 0; InlineVisibilityHidden = 0;
181 C99 = C1X = Microsoft = Borland = CPlusPlus = CPlusPlus0x = 0;
182 CXXOperatorNames = PascalStrings = WritableStrings = ConstStrings = 0;
183 Exceptions = ObjCExceptions = CXXExceptions = SjLjExceptions = 0;
184 TraditionalCPP = Freestanding = NoBuiltin = 0;
188 LaxVectorConversions = 1;
189 HeinousExtensions = 0;
190 AltiVec = OpenCL = CUDA = StackProtector = 0;
192 SymbolVisibility = (unsigned) DefaultVisibility;
194 ThreadsafeStatics = 1;
199 SignedOverflowBehavior = SOB_Undefined;
201 AssumeSaneOperatorNew = 1;
203 ElideConstructors = 1;
205 SignedOverflowBehavior = 0;
206 ObjCGCBitmapPrint = 0;
208 InstantiationDepth = 1024;
210 NumLargeByValueCopy = 0;
228 DumpRecordLayouts = 0;
229 DumpVTableLayouts = 0;
231 SinglePrecisionConstants = 0;
233 DefaultFPContract = 0;
234 NoBitFieldTypeAlign = 0;
235 FakeAddressSpaceMap = 0;
237 DelayedTemplateParsing = 0;
238 ParseUnknownAnytype = 0;
241 GCMode getGCMode() const { return (GCMode) GC; }
242 void setGCMode(GCMode m) { GC = (unsigned) m; }
244 StackProtectorMode getStackProtectorMode() const {
245 return static_cast<StackProtectorMode>(StackProtector);
247 void setStackProtectorMode(StackProtectorMode m) {
248 StackProtector = static_cast<unsigned>(m);
251 Visibility getVisibilityMode() const {
252 return (Visibility) SymbolVisibility;
254 void setVisibilityMode(Visibility v) { SymbolVisibility = (unsigned) v; }
256 SignedOverflowBehaviorTy getSignedOverflowBehavior() const {
257 return (SignedOverflowBehaviorTy)SignedOverflowBehavior;
259 void setSignedOverflowBehavior(SignedOverflowBehaviorTy V) {
260 SignedOverflowBehavior = (unsigned)V;
263 bool isSignedOverflowDefined() const {
264 return getSignedOverflowBehavior() == SOB_Defined;
268 /// Floating point control options
271 unsigned fp_contract : 1;
273 FPOptions() : fp_contract(0) {}
275 FPOptions(const LangOptions &LangOpts) :
276 fp_contract(LangOpts.DefaultFPContract) {}
279 /// OpenCL volatile options
280 class OpenCLOptions {
282 #define OPENCLEXT(nm) unsigned nm : 1;
283 #include "clang/Basic/OpenCLExtensions.def"
286 #define OPENCLEXT(nm) nm = 0;
287 #include "clang/Basic/OpenCLExtensions.def"
291 } // end namespace clang