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