blob: c4f368801d272fd2ad53fb0564d1113e90a33ab2 [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>
18
Reid Spencer5f016e22007-07-11 17:01:13 +000019namespace clang {
20
21/// LangOptions - This class keeps track of the various options that can be
22/// enabled, which controls the dialect of C that is accepted.
Cedric Venetea684e62009-02-14 16:15:20 +000023class LangOptions {
24public:
Reid Spencer5f016e22007-07-11 17:01:13 +000025 unsigned Trigraphs : 1; // Trigraphs in source files.
Chris Lattnerd658b562008-04-05 06:32:51 +000026 unsigned BCPLComment : 1; // BCPL-style '//' comments.
Chris Lattnere4f21422009-06-30 01:26:17 +000027 unsigned Bool : 1; // 'bool', 'true', 'false' keywords.
Reid Spencer5f016e22007-07-11 17:01:13 +000028 unsigned DollarIdents : 1; // '$' allowed in identifiers.
Daniel Dunbarc1571452008-12-01 18:55:22 +000029 unsigned AsmPreprocessor : 1; // Preprocessor in asm mode.
Chris Lattner7e9c90b2009-03-20 15:44:26 +000030 unsigned GNUMode : 1; // True in gnu99 mode false in c99 mode (etc)
Chandler Carrutheb5d7b72010-04-17 20:17:31 +000031 unsigned GNUKeywords : 1; // True if GNU-only keywords are allowed
Chris Lattnerd658b562008-04-05 06:32:51 +000032 unsigned ImplicitInt : 1; // C89 implicit 'int'.
Chris Lattner3426b9b2008-02-25 04:01:39 +000033 unsigned Digraphs : 1; // C94, C99 and C++
Reid Spencer5f016e22007-07-11 17:01:13 +000034 unsigned HexFloats : 1; // C99 Hexadecimal float constants.
35 unsigned C99 : 1; // C99 Support
36 unsigned Microsoft : 1; // Microsoft extensions.
37 unsigned CPlusPlus : 1; // C++ Support
Chris Lattnerd4b80f12007-07-16 04:18:29 +000038 unsigned CPlusPlus0x : 1; // C++0x Support
Reid Spencer5f016e22007-07-11 17:01:13 +000039 unsigned CXXOperatorNames : 1; // Treat C++ operator names as keywords.
Mike Stump1eb44332009-09-09 15:08:12 +000040
Ted Kremenek01d9dbf2008-04-29 04:37:03 +000041 unsigned ObjC1 : 1; // Objective-C 1 support enabled.
42 unsigned ObjC2 : 1; // Objective-C 2 support enabled.
Fariborz Jahanian30bc5712009-01-22 23:02:58 +000043 unsigned ObjCNonFragileABI : 1; // Objective-C modern abi enabled
Fariborz Jahanian412e7982010-02-09 19:31:38 +000044 unsigned ObjCNonFragileABI2 : 1; // Objective-C enhanced modern abi enabled
Mike Stump1eb44332009-09-09 15:08:12 +000045
Anders Carlssonee98ac52007-10-15 02:50:23 +000046 unsigned PascalStrings : 1; // Allow Pascal strings
Chris Lattner45e8cbd2007-11-28 05:34:05 +000047 unsigned WritableStrings : 1; // Allow writable strings
John McCall4b7a8342010-03-15 10:54:44 +000048 unsigned ConstStrings : 1; // Add const qualifier to strings (-Wwrite-strings)
Anders Carlsson695dbb62007-11-30 04:21:22 +000049 unsigned LaxVectorConversions : 1;
Nate Begeman4e3629e2009-06-25 22:43:10 +000050 unsigned AltiVec : 1; // Support AltiVec-style vector initializers.
Daniel Dunbar6379a7a2008-08-11 17:36:14 +000051 unsigned Exceptions : 1; // Support exception handling.
Daniel Dunbar73482882010-02-10 18:48:44 +000052 unsigned SjLjExceptions : 1; // Use setjmp-longjump exception handling.
Mike Stumpde050572009-12-02 18:57:08 +000053 unsigned RTTI : 1; // Support RTTI information.
Daniel Dunbarf77ac862008-08-11 21:35:06 +000054
55 unsigned NeXTRuntime : 1; // Use NeXT runtime.
Douglas Gregor3573c0c2009-02-14 20:49:29 +000056 unsigned Freestanding : 1; // Freestanding implementation
Chris Lattner7644f072009-03-13 22:38:49 +000057 unsigned NoBuiltin : 1; // Do not use builtin functions (-fno-builtin)
Daniel Dunbarf77ac862008-08-11 21:35:06 +000058
Anders Carlssone1b29ef2008-08-22 16:00:37 +000059 unsigned ThreadsafeStatics : 1; // Whether static initializers are protected
Daniel Dunbarc1571452008-12-01 18:55:22 +000060 // by locks.
Daniel Dunbar5345c392009-09-03 04:54:28 +000061 unsigned POSIXThreads : 1; // Compiling with POSIX thread support
62 // (-pthread)
Steve Naroff5618bd42008-08-27 16:04:49 +000063 unsigned Blocks : 1; // block extension to C
Daniel Dunbard604c402009-02-04 21:19:06 +000064 unsigned EmitAllDecls : 1; // Emit all declarations, even if
65 // they are unused.
Daniel Dunbaref2abfe2009-02-16 22:43:43 +000066 unsigned MathErrno : 1; // Math functions must respect errno
67 // (modulo the platform support).
68
Chris Lattner810f6d52009-03-13 17:38:01 +000069 unsigned HeinousExtensions : 1; // Extensions that we really don't like and
70 // may be ripped out at any time.
Fariborz Jahanian7cd2e932009-04-03 03:28:57 +000071
Anders Carlsson4ca076f2009-04-06 17:37:10 +000072 unsigned Optimize : 1; // Whether __OPTIMIZE__ should be defined.
Mike Stump1eb44332009-09-09 15:08:12 +000073 unsigned OptimizeSize : 1; // Whether __OPTIMIZE_SIZE__ should be
Anders Carlsson4ca076f2009-04-06 17:37:10 +000074 // defined.
Daniel Dunbar3bbc7532009-04-08 18:03:55 +000075 unsigned Static : 1; // Should __STATIC__ be defined (as
76 // opposed to __DYNAMIC__).
Daniel Dunbar9fd0b1f2009-04-08 03:03:23 +000077 unsigned PICLevel : 2; // The value for __PIC__, if non-zero.
78
Daniel Dunbar3bbc7532009-04-08 18:03:55 +000079 unsigned GNUInline : 1; // Should GNU inline semantics be
80 // used (instead of C99 semantics).
81 unsigned NoInline : 1; // Should __NO_INLINE__ be defined.
82
Fariborz Jahanian448f5e62009-04-17 03:04:15 +000083 unsigned ObjCGCBitmapPrint : 1; // Enable printing of gc's bitmap layout
84 // for __weak/__strong ivars.
85
Mike Stump1eb44332009-09-09 15:08:12 +000086 unsigned AccessControl : 1; // Whether C++ access control should
Anders Carlssona33d9b42009-05-13 19:49:53 +000087 // be enabled.
Eli Friedman15b91762009-06-05 07:05:05 +000088 unsigned CharIsSigned : 1; // Whether char is a signed or unsigned type
John Thompsona6fda122009-11-05 20:14:16 +000089 unsigned ShortWChar : 1; // Force wchar_t to be unsigned short int.
Nate Begeman4e3629e2009-06-25 22:43:10 +000090
91 unsigned OpenCL : 1; // OpenCL C99 language extensions.
Nuno Lopesfc284482009-12-16 16:59:22 +000092
93 unsigned AssumeSaneOperatorNew : 1; // Whether to add __attribute__((malloc))
94 // to the declaration of C++'s new
95 // operators
Anders Carlsson92f58222009-08-22 22:30:33 +000096 unsigned ElideConstructors : 1; // Whether C++ copy constructors should be
97 // elided if possible.
Anders Carlsson824d7ea2010-02-11 08:02:13 +000098 unsigned CatchUndefined : 1; // Generate code to check for undefined ops.
Daniel Dunbarb69eca52010-04-08 02:59:56 +000099 unsigned DumpRecordLayouts : 1; /// Dump the layout of IRgen'd records.
Anders Carlsson046c2942010-04-17 20:15:18 +0000100 unsigned DumpVTableLayouts : 1; /// Dump the layouts of emitted vtables.
Fariborz Jahanian33e982b2010-04-22 20:26:39 +0000101 unsigned NoConstantCFStrings : 1; // Do not do CF strings
Douglas Gregor7cf84d62010-06-15 17:05:35 +0000102 unsigned InlineVisibilityHidden : 1; // Whether inline C++ methods have
103 // hidden visibility by default.
Daniel Dunbarfb937b82010-04-15 15:06:22 +0000104
105 // FIXME: This is just a temporary option, for testing purposes.
106 unsigned NoBitFieldTypeAlign : 1;
107
Ted Kremenek01d9dbf2008-04-29 04:37:03 +0000108private:
Chris Lattnera4d71452010-06-26 21:25:03 +0000109 // We declare multibit enums as unsigned because MSVC insists on making enums
110 // signed. Set/Query these values using accessors.
111 unsigned GC : 2; // Objective-C Garbage Collection modes.
Fariborz Jahanian7cd2e932009-04-03 03:28:57 +0000112 unsigned SymbolVisibility : 3; // Symbol's visibility.
Chris Lattnera4d71452010-06-26 21:25:03 +0000113 unsigned StackProtector : 2; // Whether stack protectors are on.
114 unsigned SignedOverflowBehavior : 2; // How to handle signed integer overflow.
Fariborz Jahanian7cd2e932009-04-03 03:28:57 +0000115
Mike Stump1eb44332009-09-09 15:08:12 +0000116public:
Douglas Gregor26dce442009-03-10 00:06:19 +0000117 unsigned InstantiationDepth; // Maximum template instantiation depth.
Ted Kremenek01d9dbf2008-04-29 04:37:03 +0000118
Daniel Dunbar1b096952009-11-29 02:38:47 +0000119 std::string ObjCConstantStringClass;
David Chisnall8a5a9aa2009-08-31 16:41:57 +0000120
Ted Kremenek01d9dbf2008-04-29 04:37:03 +0000121 enum GCMode { NonGC, GCOnly, HybridGC };
Bill Wendling4ebe3e42009-06-28 23:01:01 +0000122 enum StackProtectorMode { SSPOff, SSPOn, SSPReq };
Mike Stump1eb44332009-09-09 15:08:12 +0000123 enum VisibilityMode {
124 Default,
125 Protected,
Daniel Dunbar04d40782009-04-14 06:00:08 +0000126 Hidden
127 };
Chris Lattnera4d71452010-06-26 21:25:03 +0000128
129 enum SignedOverflowBehaviorTy {
130 SOB_Undefined, // Default C standard behavior.
131 SOB_Defined, // -fwrapv
132 SOB_Trapping // -ftrapv
133 };
Mike Stump1eb44332009-09-09 15:08:12 +0000134
Reid Spencer5f016e22007-07-11 17:01:13 +0000135 LangOptions() {
Chris Lattnere4f21422009-06-30 01:26:17 +0000136 Trigraphs = BCPLComment = Bool = DollarIdents = AsmPreprocessor = 0;
Chandler Carrutheb5d7b72010-04-17 20:17:31 +0000137 GNUMode = GNUKeywords = ImplicitInt = Digraphs = 0;
Chris Lattnerd658b562008-04-05 06:32:51 +0000138 HexFloats = 0;
Fariborz Jahanian412e7982010-02-09 19:31:38 +0000139 GC = ObjC1 = ObjC2 = ObjCNonFragileABI = ObjCNonFragileABI2 = 0;
Douglas Gregor7cf84d62010-06-15 17:05:35 +0000140 NoConstantCFStrings = 0; InlineVisibilityHidden = 0;
Eli Friedmanc71133f2009-04-28 03:28:55 +0000141 C99 = Microsoft = CPlusPlus = CPlusPlus0x = 0;
John McCall4b7a8342010-03-15 10:54:44 +0000142 CXXOperatorNames = PascalStrings = WritableStrings = ConstStrings = 0;
Daniel Dunbar73482882010-02-10 18:48:44 +0000143 Exceptions = SjLjExceptions = Freestanding = NoBuiltin = 0;
Daniel Dunbarc5a97ec2009-11-17 07:07:28 +0000144 NeXTRuntime = 1;
Mike Stumpde050572009-12-02 18:57:08 +0000145 RTTI = 1;
Anders Carlssonb0f90cc2009-01-30 23:17:46 +0000146 LaxVectorConversions = 1;
Chris Lattner810f6d52009-03-13 17:38:01 +0000147 HeinousExtensions = 0;
Bill Wendling45483f72009-06-28 07:36:13 +0000148 AltiVec = OpenCL = StackProtector = 0;
David Chisnall8a5a9aa2009-08-31 16:41:57 +0000149
Daniel Dunbar04d40782009-04-14 06:00:08 +0000150 SymbolVisibility = (unsigned) Default;
Douglas Gregor7cf84d62010-06-15 17:05:35 +0000151
Anders Carlssona508b7d2010-02-06 23:23:06 +0000152 ThreadsafeStatics = 1;
Daniel Dunbar5345c392009-09-03 04:54:28 +0000153 POSIXThreads = 0;
Chris Lattnerae0ee032008-12-04 23:20:07 +0000154 Blocks = 0;
Daniel Dunbard604c402009-02-04 21:19:06 +0000155 EmitAllDecls = 0;
Daniel Dunbaref2abfe2009-02-16 22:43:43 +0000156 MathErrno = 1;
Chris Lattnera4d71452010-06-26 21:25:03 +0000157 SignedOverflowBehavior = SOB_Undefined;
158
Nuno Lopesfc284482009-12-16 16:59:22 +0000159 AssumeSaneOperatorNew = 1;
Chris Lattner1ea9c3d2010-06-28 17:11:58 +0000160 AccessControl = 1;
Anders Carlsson92f58222009-08-22 22:30:33 +0000161 ElideConstructors = 1;
Mike Stump1eb44332009-09-09 15:08:12 +0000162
Chris Lattnera4d71452010-06-26 21:25:03 +0000163 SignedOverflowBehavior = 0;
Fariborz Jahanian448f5e62009-04-17 03:04:15 +0000164 ObjCGCBitmapPrint = 0;
Mike Stump2add4732009-04-01 20:28:16 +0000165
Douglas Gregore2e69ef2010-05-01 16:59:21 +0000166 InstantiationDepth = 1024;
Mike Stump1eb44332009-09-09 15:08:12 +0000167
Anders Carlsson4ca076f2009-04-06 17:37:10 +0000168 Optimize = 0;
169 OptimizeSize = 0;
Daniel Dunbar9fd0b1f2009-04-08 03:03:23 +0000170
Daniel Dunbar3bbc7532009-04-08 18:03:55 +0000171 Static = 0;
Daniel Dunbar9fd0b1f2009-04-08 03:03:23 +0000172 PICLevel = 0;
Daniel Dunbarc9abc042009-04-08 05:11:16 +0000173
Daniel Dunbar3bbc7532009-04-08 18:03:55 +0000174 GNUInline = 0;
175 NoInline = 0;
176
Eli Friedman15b91762009-06-05 07:05:05 +0000177 CharIsSigned = 1;
John Thompson40d1bb62009-11-05 22:03:02 +0000178 ShortWChar = 0;
Mike Stump9c276ae2009-12-12 01:27:46 +0000179 CatchUndefined = 0;
Daniel Dunbarb69eca52010-04-08 02:59:56 +0000180 DumpRecordLayouts = 0;
Anders Carlsson046c2942010-04-17 20:15:18 +0000181 DumpVTableLayouts = 0;
Daniel Dunbarfb937b82010-04-15 15:06:22 +0000182 NoBitFieldTypeAlign = 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000183 }
Mike Stump1eb44332009-09-09 15:08:12 +0000184
Ted Kremenek01d9dbf2008-04-29 04:37:03 +0000185 GCMode getGCMode() const { return (GCMode) GC; }
186 void setGCMode(GCMode m) { GC = (unsigned) m; }
Fariborz Jahanian7cd2e932009-04-03 03:28:57 +0000187
Bill Wendling4ebe3e42009-06-28 23:01:01 +0000188 StackProtectorMode getStackProtectorMode() const {
189 return static_cast<StackProtectorMode>(StackProtector);
190 }
191 void setStackProtectorMode(StackProtectorMode m) {
192 StackProtector = static_cast<unsigned>(m);
193 }
194
Mike Stump1eb44332009-09-09 15:08:12 +0000195 VisibilityMode getVisibilityMode() const {
196 return (VisibilityMode) SymbolVisibility;
Daniel Dunbar04d40782009-04-14 06:00:08 +0000197 }
Fariborz Jahanian7cd2e932009-04-03 03:28:57 +0000198 void setVisibilityMode(VisibilityMode v) { SymbolVisibility = (unsigned) v; }
Chris Lattnera4d71452010-06-26 21:25:03 +0000199
200 SignedOverflowBehaviorTy getSignedOverflowBehavior() const {
201 return (SignedOverflowBehaviorTy)SignedOverflowBehavior;
202 }
203 void setSignedOverflowBehavior(SignedOverflowBehaviorTy V) {
204 SignedOverflowBehavior = (unsigned)V;
205 }
Reid Spencer5f016e22007-07-11 17:01:13 +0000206};
207
208} // end namespace clang
209
210#endif