]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/clang/include/clang/Basic/LangOptions.h
Upgrade to version 9.8.0-P4
[FreeBSD/FreeBSD.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
124   unsigned SpellChecking : 1; // Whether to perform spell-checking for error
125                               // recovery.
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.
136
137   unsigned MRTD : 1;            // -mrtd calling convention
138   unsigned DelayedTemplateParsing : 1;  // Delayed template parsing
139
140 private:
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.
147
148 public:
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.
152
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.
156   unsigned MSCVersion;
157
158   std::string ObjCConstantStringClass;
159
160   enum GCMode { NonGC, GCOnly, HybridGC };
161   enum StackProtectorMode { SSPOff, SSPOn, SSPReq };
162
163   enum SignedOverflowBehaviorTy {
164     SOB_Undefined,  // Default C standard behavior.
165     SOB_Defined,    // -fwrapv
166     SOB_Trapping    // -ftrapv
167   };
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;
171
172   LangOptions() {
173     Trigraphs = BCPLComment = Bool = DollarIdents = AsmPreprocessor = 0;
174     GNUMode = GNUKeywords = ImplicitInt = Digraphs = 0;
175     HexFloats = 0;
176     GC = ObjC1 = ObjC2 = ObjCNonFragileABI = ObjCNonFragileABI2 = 0;
177     AppleKext = 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;
185     MSBitfields = 0;
186     NeXTRuntime = 1;
187     RTTI = 1;
188     LaxVectorConversions = 1;
189     HeinousExtensions = 0;
190     AltiVec = OpenCL = CUDA = StackProtector = 0;
191
192     SymbolVisibility = (unsigned) DefaultVisibility;
193
194     ThreadsafeStatics = 1;
195     POSIXThreads = 0;
196     Blocks = 0;
197     EmitAllDecls = 0;
198     MathErrno = 1;
199     SignedOverflowBehavior = SOB_Undefined;
200
201     AssumeSaneOperatorNew = 1;
202     AccessControl = 1;
203     ElideConstructors = 1;
204
205     SignedOverflowBehavior = 0;
206     ObjCGCBitmapPrint = 0;
207
208     InstantiationDepth = 1024;
209
210     NumLargeByValueCopy = 0;
211     MSCVersion = 0;
212     
213     Optimize = 0;
214     OptimizeSize = 0;
215
216     Static = 0;
217     PICLevel = 0;
218
219     GNUInline = 0;
220     NoInline = 0;
221
222     Deprecated = 0;
223
224     CharIsSigned = 1;
225     ShortWChar = 0;
226     ShortEnums = 0;
227     CatchUndefined = 0;
228     DumpRecordLayouts = 0;
229     DumpVTableLayouts = 0;
230     SpellChecking = 1;
231     SinglePrecisionConstants = 0;
232     FastRelaxedMath = 0;
233     DefaultFPContract = 0;
234     NoBitFieldTypeAlign = 0;
235     FakeAddressSpaceMap = 0;
236     MRTD = 0;
237     DelayedTemplateParsing = 0;
238     ParseUnknownAnytype = 0;
239   }
240
241   GCMode getGCMode() const { return (GCMode) GC; }
242   void setGCMode(GCMode m) { GC = (unsigned) m; }
243
244   StackProtectorMode getStackProtectorMode() const {
245     return static_cast<StackProtectorMode>(StackProtector);
246   }
247   void setStackProtectorMode(StackProtectorMode m) {
248     StackProtector = static_cast<unsigned>(m);
249   }
250
251   Visibility getVisibilityMode() const {
252     return (Visibility) SymbolVisibility;
253   }
254   void setVisibilityMode(Visibility v) { SymbolVisibility = (unsigned) v; }
255
256   SignedOverflowBehaviorTy getSignedOverflowBehavior() const {
257     return (SignedOverflowBehaviorTy)SignedOverflowBehavior;
258   }
259   void setSignedOverflowBehavior(SignedOverflowBehaviorTy V) {
260     SignedOverflowBehavior = (unsigned)V;
261   }
262
263   bool isSignedOverflowDefined() const {
264     return getSignedOverflowBehavior() == SOB_Defined;
265   }
266 };
267
268 /// Floating point control options
269 class FPOptions {
270 public:
271   unsigned fp_contract : 1;
272
273   FPOptions() : fp_contract(0) {}
274
275   FPOptions(const LangOptions &LangOpts) :
276     fp_contract(LangOpts.DefaultFPContract) {}
277 };
278
279 /// OpenCL volatile options
280 class OpenCLOptions {
281 public:
282 #define OPENCLEXT(nm)  unsigned nm : 1;
283 #include "clang/Basic/OpenCLExtensions.def"
284
285   OpenCLOptions() {
286 #define OPENCLEXT(nm)   nm = 0;
287 #include "clang/Basic/OpenCLExtensions.def"
288   }
289 };
290
291 }  // end namespace clang
292
293 #endif