blob: 0bd983e8e6c68a1dbc307b924905ae080d057268 [file] [log] [blame]
Reid Spencer5f016e22007-07-11 17:01:13 +00001//===--- LangOptions.h - C Language Family Language Options -----*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
Chris Lattner0bc735f2007-12-29 19:59:25 +00005// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Reid Spencer5f016e22007-07-11 17:01:13 +00007//
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
Daniel Dunbar1b096952009-11-29 02:38:47 +000017#include <string>
John McCall1fb0caa2010-10-22 21:05:15 +000018#include "clang/Basic/Visibility.h"
Daniel Dunbar1b096952009-11-29 02:38:47 +000019
Reid Spencer5f016e22007-07-11 17:01:13 +000020namespace clang {
21
Ted Kremenek1b27ab32010-11-14 17:53:34 +000022/// LangOptions - This class keeps track of the various options that can be
23/// enabled, which controls the dialect of C that is accepted.
24class LangOptions {
Cedric Venetea684e62009-02-14 16:15:20 +000025public:
Reid Spencer5f016e22007-07-11 17:01:13 +000026 unsigned Trigraphs : 1; // Trigraphs in source files.
Chris Lattnerd658b562008-04-05 06:32:51 +000027 unsigned BCPLComment : 1; // BCPL-style '//' comments.
Chris Lattnere4f21422009-06-30 01:26:17 +000028 unsigned Bool : 1; // 'bool', 'true', 'false' keywords.
Reid Spencer5f016e22007-07-11 17:01:13 +000029 unsigned DollarIdents : 1; // '$' allowed in identifiers.
Daniel Dunbarc1571452008-12-01 18:55:22 +000030 unsigned AsmPreprocessor : 1; // Preprocessor in asm mode.
Chris Lattner7e9c90b2009-03-20 15:44:26 +000031 unsigned GNUMode : 1; // True in gnu99 mode false in c99 mode (etc)
Chandler Carrutheb5d7b72010-04-17 20:17:31 +000032 unsigned GNUKeywords : 1; // True if GNU-only keywords are allowed
Chris Lattnerd658b562008-04-05 06:32:51 +000033 unsigned ImplicitInt : 1; // C89 implicit 'int'.
Chris Lattner3426b9b2008-02-25 04:01:39 +000034 unsigned Digraphs : 1; // C94, C99 and C++
Reid Spencer5f016e22007-07-11 17:01:13 +000035 unsigned HexFloats : 1; // C99 Hexadecimal float constants.
36 unsigned C99 : 1; // C99 Support
37 unsigned Microsoft : 1; // Microsoft extensions.
Dawn Perchik400b6072010-09-02 23:59:25 +000038 unsigned Borland : 1; // Borland extensions.
Reid Spencer5f016e22007-07-11 17:01:13 +000039 unsigned CPlusPlus : 1; // C++ Support
Chris Lattnerd4b80f12007-07-16 04:18:29 +000040 unsigned CPlusPlus0x : 1; // C++0x Support
Reid Spencer5f016e22007-07-11 17:01:13 +000041 unsigned CXXOperatorNames : 1; // Treat C++ operator names as keywords.
Mike Stump1eb44332009-09-09 15:08:12 +000042
Ted Kremenek01d9dbf2008-04-29 04:37:03 +000043 unsigned ObjC1 : 1; // Objective-C 1 support enabled.
44 unsigned ObjC2 : 1; // Objective-C 2 support enabled.
Fariborz Jahanian30bc5712009-01-22 23:02:58 +000045 unsigned ObjCNonFragileABI : 1; // Objective-C modern abi enabled
Fariborz Jahanian412e7982010-02-09 19:31:38 +000046 unsigned ObjCNonFragileABI2 : 1; // Objective-C enhanced modern abi enabled
Ted Kremenekc32647d2010-12-23 21:35:43 +000047 unsigned ObjCDefaultSynthProperties : 1; // Objective-C auto-synthesized properties.
Fariborz Jahanianb466d012011-01-07 01:05:02 +000048 unsigned AppleKext : 1; // Allow apple kext features.
Mike Stump1eb44332009-09-09 15:08:12 +000049
Anders Carlssonee98ac52007-10-15 02:50:23 +000050 unsigned PascalStrings : 1; // Allow Pascal strings
Chris Lattner45e8cbd2007-11-28 05:34:05 +000051 unsigned WritableStrings : 1; // Allow writable strings
John McCall4b7a8342010-03-15 10:54:44 +000052 unsigned ConstStrings : 1; // Add const qualifier to strings (-Wwrite-strings)
Anders Carlsson695dbb62007-11-30 04:21:22 +000053 unsigned LaxVectorConversions : 1;
Nate Begeman4e3629e2009-06-25 22:43:10 +000054 unsigned AltiVec : 1; // Support AltiVec-style vector initializers.
Daniel Dunbar6379a7a2008-08-11 17:36:14 +000055 unsigned Exceptions : 1; // Support exception handling.
Anders Carlssonda4b7cf2011-02-19 23:53:54 +000056 unsigned ObjCExceptions : 1; // Support Objective-C exceptions.
Anders Carlsson7da99b02011-02-23 03:04:54 +000057 unsigned CXXExceptions : 1; // Support C++ exceptions.
58 unsigned SjLjExceptions : 1; // Use setjmp-longjump exception handling.
Mike Stumpde050572009-12-02 18:57:08 +000059 unsigned RTTI : 1; // Support RTTI information.
Daniel Dunbarf77ac862008-08-11 21:35:06 +000060
Douglas Gregor6f755502011-02-01 15:15:22 +000061 unsigned MSBitfields : 1; // MS-compatible structure layout
Daniel Dunbarf77ac862008-08-11 21:35:06 +000062 unsigned NeXTRuntime : 1; // Use NeXT runtime.
Douglas Gregor3573c0c2009-02-14 20:49:29 +000063 unsigned Freestanding : 1; // Freestanding implementation
Chris Lattner7644f072009-03-13 22:38:49 +000064 unsigned NoBuiltin : 1; // Do not use builtin functions (-fno-builtin)
Daniel Dunbarf77ac862008-08-11 21:35:06 +000065
Anders Carlssone1b29ef2008-08-22 16:00:37 +000066 unsigned ThreadsafeStatics : 1; // Whether static initializers are protected
Ted Kremenek1b27ab32010-11-14 17:53:34 +000067 // by locks.
Daniel Dunbar5345c392009-09-03 04:54:28 +000068 unsigned POSIXThreads : 1; // Compiling with POSIX thread support
Ted Kremenek1b27ab32010-11-14 17:53:34 +000069 // (-pthread)
Steve Naroff5618bd42008-08-27 16:04:49 +000070 unsigned Blocks : 1; // block extension to C
Daniel Dunbard604c402009-02-04 21:19:06 +000071 unsigned EmitAllDecls : 1; // Emit all declarations, even if
Ted Kremenek1b27ab32010-11-14 17:53:34 +000072 // they are unused.
Daniel Dunbaref2abfe2009-02-16 22:43:43 +000073 unsigned MathErrno : 1; // Math functions must respect errno
Ted Kremenek1b27ab32010-11-14 17:53:34 +000074 // (modulo the platform support).
Daniel Dunbaref2abfe2009-02-16 22:43:43 +000075
Chris Lattner810f6d52009-03-13 17:38:01 +000076 unsigned HeinousExtensions : 1; // Extensions that we really don't like and
Ted Kremenek1b27ab32010-11-14 17:53:34 +000077 // may be ripped out at any time.
Fariborz Jahanian7cd2e932009-04-03 03:28:57 +000078
Anders Carlsson4ca076f2009-04-06 17:37:10 +000079 unsigned Optimize : 1; // Whether __OPTIMIZE__ should be defined.
Mike Stump1eb44332009-09-09 15:08:12 +000080 unsigned OptimizeSize : 1; // Whether __OPTIMIZE_SIZE__ should be
Ted Kremenek1b27ab32010-11-14 17:53:34 +000081 // defined.
Daniel Dunbar3bbc7532009-04-08 18:03:55 +000082 unsigned Static : 1; // Should __STATIC__ be defined (as
Ted Kremenek1b27ab32010-11-14 17:53:34 +000083 // opposed to __DYNAMIC__).
Daniel Dunbar9fd0b1f2009-04-08 03:03:23 +000084 unsigned PICLevel : 2; // The value for __PIC__, if non-zero.
85
Daniel Dunbar3bbc7532009-04-08 18:03:55 +000086 unsigned GNUInline : 1; // Should GNU inline semantics be
Ted Kremenek1b27ab32010-11-14 17:53:34 +000087 // used (instead of C99 semantics).
Daniel Dunbar3bbc7532009-04-08 18:03:55 +000088 unsigned NoInline : 1; // Should __NO_INLINE__ be defined.
89
Fariborz Jahanian448f5e62009-04-17 03:04:15 +000090 unsigned ObjCGCBitmapPrint : 1; // Enable printing of gc's bitmap layout
Ted Kremenek1b27ab32010-11-14 17:53:34 +000091 // for __weak/__strong ivars.
Fariborz Jahanian448f5e62009-04-17 03:04:15 +000092
Mike Stump1eb44332009-09-09 15:08:12 +000093 unsigned AccessControl : 1; // Whether C++ access control should
Ted Kremenek1b27ab32010-11-14 17:53:34 +000094 // be enabled.
Eli Friedman15b91762009-06-05 07:05:05 +000095 unsigned CharIsSigned : 1; // Whether char is a signed or unsigned type
John Thompsona6fda122009-11-05 20:14:16 +000096 unsigned ShortWChar : 1; // Force wchar_t to be unsigned short int.
Nate Begeman4e3629e2009-06-25 22:43:10 +000097
Argyrios Kyrtzidis9a2b9d72010-10-08 00:25:19 +000098 unsigned ShortEnums : 1; // The enum type will be equivalent to the
Ted Kremenek1b27ab32010-11-14 17:53:34 +000099 // smallest integer type with enough room.
Argyrios Kyrtzidis9a2b9d72010-10-08 00:25:19 +0000100
Nate Begeman4e3629e2009-06-25 22:43:10 +0000101 unsigned OpenCL : 1; // OpenCL C99 language extensions.
Peter Collingbournee2dd6c82010-12-01 03:15:10 +0000102 unsigned CUDA : 1; // CUDA C++ language extensions.
Michael J. Spencer20249a12010-10-21 03:16:25 +0000103
Nuno Lopesfc284482009-12-16 16:59:22 +0000104 unsigned AssumeSaneOperatorNew : 1; // Whether to add __attribute__((malloc))
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000105 // to the declaration of C++'s new
106 // operators
Anders Carlsson92f58222009-08-22 22:30:33 +0000107 unsigned ElideConstructors : 1; // Whether C++ copy constructors should be
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000108 // elided if possible.
Anders Carlsson824d7ea2010-02-11 08:02:13 +0000109 unsigned CatchUndefined : 1; // Generate code to check for undefined ops.
Daniel Dunbarb69eca52010-04-08 02:59:56 +0000110 unsigned DumpRecordLayouts : 1; /// Dump the layout of IRgen'd records.
Anders Carlsson046c2942010-04-17 20:15:18 +0000111 unsigned DumpVTableLayouts : 1; /// Dump the layouts of emitted vtables.
Fariborz Jahanian33e982b2010-04-22 20:26:39 +0000112 unsigned NoConstantCFStrings : 1; // Do not do CF strings
Douglas Gregor7cf84d62010-06-15 17:05:35 +0000113 unsigned InlineVisibilityHidden : 1; // Whether inline C++ methods have
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000114 // hidden visibility by default.
Daniel Dunbarfb937b82010-04-15 15:06:22 +0000115
Douglas Gregora0068fc2010-07-09 17:35:33 +0000116 unsigned SpellChecking : 1; // Whether to perform spell-checking for error
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000117 // recovery.
Peter Collingbourne09821362010-12-04 01:50:56 +0000118 unsigned SinglePrecisionConstants : 1; // Whether to treat double-precision
119 // floating point constants as
120 // single precision constants.
Peter Collingbournef0840822010-12-04 01:51:23 +0000121 unsigned FastRelaxedMath : 1; // OpenCL fast relaxed math (on its own,
122 // defines __FAST_RELAXED_MATH__).
Peter Collingbourne321b8172011-02-14 01:42:35 +0000123 unsigned DefaultFPContract : 1; // Default setting for FP_CONTRACT
Daniel Dunbarfb937b82010-04-15 15:06:22 +0000124 // FIXME: This is just a temporary option, for testing purposes.
125 unsigned NoBitFieldTypeAlign : 1;
126
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000127private:
Chris Lattnera4d71452010-06-26 21:25:03 +0000128 // We declare multibit enums as unsigned because MSVC insists on making enums
129 // signed. Set/Query these values using accessors.
130 unsigned GC : 2; // Objective-C Garbage Collection modes.
Fariborz Jahanian7cd2e932009-04-03 03:28:57 +0000131 unsigned SymbolVisibility : 3; // Symbol's visibility.
Chris Lattnera4d71452010-06-26 21:25:03 +0000132 unsigned StackProtector : 2; // Whether stack protectors are on.
133 unsigned SignedOverflowBehavior : 2; // How to handle signed integer overflow.
Fariborz Jahanian7cd2e932009-04-03 03:28:57 +0000134
Mike Stump1eb44332009-09-09 15:08:12 +0000135public:
Douglas Gregor26dce442009-03-10 00:06:19 +0000136 unsigned InstantiationDepth; // Maximum template instantiation depth.
Argyrios Kyrtzidis1380a142010-11-18 00:20:36 +0000137 unsigned NumLargeByValueCopy; // Warn if parameter/return value is larger
Argyrios Kyrtzidis3532fdd2010-11-17 23:11:54 +0000138 // in bytes than this setting. 0 is no check.
Ted Kremenek01d9dbf2008-04-29 04:37:03 +0000139
Michael J. Spencerdae4ac42010-10-21 05:21:48 +0000140 // Version of Microsoft Visual C/C++ we are pretending to be. This is
141 // temporary until we support all MS extensions used in Windows SDK and stdlib
142 // headers. Sets _MSC_VER.
143 unsigned MSCVersion;
144
Daniel Dunbar1b096952009-11-29 02:38:47 +0000145 std::string ObjCConstantStringClass;
David Chisnall8a5a9aa2009-08-31 16:41:57 +0000146
Ted Kremenek01d9dbf2008-04-29 04:37:03 +0000147 enum GCMode { NonGC, GCOnly, HybridGC };
Bill Wendling4ebe3e42009-06-28 23:01:01 +0000148 enum StackProtectorMode { SSPOff, SSPOn, SSPReq };
Michael J. Spencer20249a12010-10-21 03:16:25 +0000149
Chris Lattnera4d71452010-06-26 21:25:03 +0000150 enum SignedOverflowBehaviorTy {
151 SOB_Undefined, // Default C standard behavior.
152 SOB_Defined, // -fwrapv
153 SOB_Trapping // -ftrapv
154 };
David Chisnall7f18e672010-09-17 18:29:54 +0000155 /// The name of the handler function to be called when -ftrapv is specified.
156 /// If none is specified, abort (GCC-compatible behaviour).
157 std::string OverflowHandler;
Mike Stump1eb44332009-09-09 15:08:12 +0000158
Reid Spencer5f016e22007-07-11 17:01:13 +0000159 LangOptions() {
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000160 Trigraphs = BCPLComment = Bool = DollarIdents = AsmPreprocessor = 0;
161 GNUMode = GNUKeywords = ImplicitInt = Digraphs = 0;
162 HexFloats = 0;
163 GC = ObjC1 = ObjC2 = ObjCNonFragileABI = ObjCNonFragileABI2 = 0;
Fariborz Jahanianb466d012011-01-07 01:05:02 +0000164 AppleKext = 0;
Ted Kremenekc32647d2010-12-23 21:35:43 +0000165 ObjCDefaultSynthProperties = 0;
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000166 NoConstantCFStrings = 0; InlineVisibilityHidden = 0;
167 C99 = Microsoft = Borland = CPlusPlus = CPlusPlus0x = 0;
168 CXXOperatorNames = PascalStrings = WritableStrings = ConstStrings = 0;
Anders Carlsson7da99b02011-02-23 03:04:54 +0000169 Exceptions = ObjCExceptions = CXXExceptions = SjLjExceptions = 0;
170 Freestanding = NoBuiltin = 0;
Douglas Gregor6f755502011-02-01 15:15:22 +0000171 MSBitfields = 0;
Daniel Dunbarc5a97ec2009-11-17 07:07:28 +0000172 NeXTRuntime = 1;
Mike Stumpde050572009-12-02 18:57:08 +0000173 RTTI = 1;
Anders Carlssonb0f90cc2009-01-30 23:17:46 +0000174 LaxVectorConversions = 1;
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000175 HeinousExtensions = 0;
Peter Collingbournee2dd6c82010-12-01 03:15:10 +0000176 AltiVec = OpenCL = CUDA = StackProtector = 0;
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000177
John McCall1fb0caa2010-10-22 21:05:15 +0000178 SymbolVisibility = (unsigned) DefaultVisibility;
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000179
Anders Carlssona508b7d2010-02-06 23:23:06 +0000180 ThreadsafeStatics = 1;
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000181 POSIXThreads = 0;
182 Blocks = 0;
183 EmitAllDecls = 0;
Daniel Dunbaref2abfe2009-02-16 22:43:43 +0000184 MathErrno = 1;
Chris Lattnera4d71452010-06-26 21:25:03 +0000185 SignedOverflowBehavior = SOB_Undefined;
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000186
Nuno Lopesfc284482009-12-16 16:59:22 +0000187 AssumeSaneOperatorNew = 1;
Chris Lattner1ea9c3d2010-06-28 17:11:58 +0000188 AccessControl = 1;
Anders Carlsson92f58222009-08-22 22:30:33 +0000189 ElideConstructors = 1;
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000190
191 SignedOverflowBehavior = 0;
192 ObjCGCBitmapPrint = 0;
193
Douglas Gregore2e69ef2010-05-01 16:59:21 +0000194 InstantiationDepth = 1024;
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000195
Argyrios Kyrtzidis1380a142010-11-18 00:20:36 +0000196 NumLargeByValueCopy = 0;
Douglas Gregor786e6172010-12-21 06:21:20 +0000197 MSCVersion = 0;
198
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000199 Optimize = 0;
200 OptimizeSize = 0;
201
202 Static = 0;
203 PICLevel = 0;
204
205 GNUInline = 0;
206 NoInline = 0;
207
Eli Friedman15b91762009-06-05 07:05:05 +0000208 CharIsSigned = 1;
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000209 ShortWChar = 0;
210 ShortEnums = 0;
211 CatchUndefined = 0;
212 DumpRecordLayouts = 0;
213 DumpVTableLayouts = 0;
Douglas Gregora0068fc2010-07-09 17:35:33 +0000214 SpellChecking = 1;
Peter Collingbourne09821362010-12-04 01:50:56 +0000215 SinglePrecisionConstants = 0;
Peter Collingbournef0840822010-12-04 01:51:23 +0000216 FastRelaxedMath = 0;
Peter Collingbourne321b8172011-02-14 01:42:35 +0000217 DefaultFPContract = 0;
Ted Kremenek1b27ab32010-11-14 17:53:34 +0000218 NoBitFieldTypeAlign = 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000219 }
Mike Stump1eb44332009-09-09 15:08:12 +0000220
Ted Kremenek01d9dbf2008-04-29 04:37:03 +0000221 GCMode getGCMode() const { return (GCMode) GC; }
222 void setGCMode(GCMode m) { GC = (unsigned) m; }
Fariborz Jahanian7cd2e932009-04-03 03:28:57 +0000223
Bill Wendling4ebe3e42009-06-28 23:01:01 +0000224 StackProtectorMode getStackProtectorMode() const {
225 return static_cast<StackProtectorMode>(StackProtector);
226 }
227 void setStackProtectorMode(StackProtectorMode m) {
228 StackProtector = static_cast<unsigned>(m);
229 }
230
John McCall1fb0caa2010-10-22 21:05:15 +0000231 Visibility getVisibilityMode() const {
232 return (Visibility) SymbolVisibility;
Daniel Dunbar04d40782009-04-14 06:00:08 +0000233 }
John McCall1fb0caa2010-10-22 21:05:15 +0000234 void setVisibilityMode(Visibility v) { SymbolVisibility = (unsigned) v; }
Michael J. Spencer20249a12010-10-21 03:16:25 +0000235
Chris Lattnera4d71452010-06-26 21:25:03 +0000236 SignedOverflowBehaviorTy getSignedOverflowBehavior() const {
237 return (SignedOverflowBehaviorTy)SignedOverflowBehavior;
238 }
239 void setSignedOverflowBehavior(SignedOverflowBehaviorTy V) {
240 SignedOverflowBehavior = (unsigned)V;
241 }
Anders Carlssonc1cfdf82011-02-20 00:20:27 +0000242
243 bool areExceptionsEnabled() const {
244 return Exceptions;
245 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000246};
247
Peter Collingbourne321b8172011-02-14 01:42:35 +0000248/// Floating point control options
249class FPOptions {
250public:
251 unsigned fp_contract : 1;
252
253 FPOptions() : fp_contract(0) {}
254
255 FPOptions(const LangOptions &LangOpts) :
256 fp_contract(LangOpts.DefaultFPContract) {}
257};
258
Peter Collingbournef315fa82011-02-14 01:42:53 +0000259/// OpenCL volatile options
260class OpenCLOptions {
261public:
262#define OPENCLEXT(nm) unsigned nm : 1;
263#include "clang/Basic/OpenCLExtensions.def"
264
265 OpenCLOptions() {
266#define OPENCLEXT(nm) nm = 0;
267#include "clang/Basic/OpenCLExtensions.def"
268 }
269};
270
Reid Spencer5f016e22007-07-11 17:01:13 +0000271} // end namespace clang
272
273#endif