blob: 7fd57c0499a2aa4b59a9044f1ddea3b63b033907 [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
17namespace clang {
18
19/// LangOptions - This class keeps track of the various options that can be
20/// enabled, which controls the dialect of C that is accepted.
Cedric Venetea684e62009-02-14 16:15:20 +000021class LangOptions {
22public:
Reid Spencer5f016e22007-07-11 17:01:13 +000023 unsigned Trigraphs : 1; // Trigraphs in source files.
Chris Lattnerd658b562008-04-05 06:32:51 +000024 unsigned BCPLComment : 1; // BCPL-style '//' comments.
Chris Lattnere4f21422009-06-30 01:26:17 +000025 unsigned Bool : 1; // 'bool', 'true', 'false' keywords.
Reid Spencer5f016e22007-07-11 17:01:13 +000026 unsigned DollarIdents : 1; // '$' allowed in identifiers.
Daniel Dunbarc1571452008-12-01 18:55:22 +000027 unsigned AsmPreprocessor : 1; // Preprocessor in asm mode.
Chris Lattner7e9c90b2009-03-20 15:44:26 +000028 unsigned GNUMode : 1; // True in gnu99 mode false in c99 mode (etc)
Chris Lattnerd658b562008-04-05 06:32:51 +000029 unsigned ImplicitInt : 1; // C89 implicit 'int'.
Chris Lattner3426b9b2008-02-25 04:01:39 +000030 unsigned Digraphs : 1; // C94, C99 and C++
Reid Spencer5f016e22007-07-11 17:01:13 +000031 unsigned HexFloats : 1; // C99 Hexadecimal float constants.
32 unsigned C99 : 1; // C99 Support
33 unsigned Microsoft : 1; // Microsoft extensions.
34 unsigned CPlusPlus : 1; // C++ Support
Chris Lattnerd4b80f12007-07-16 04:18:29 +000035 unsigned CPlusPlus0x : 1; // C++0x Support
Reid Spencer5f016e22007-07-11 17:01:13 +000036 unsigned CXXOperatorNames : 1; // Treat C++ operator names as keywords.
Mike Stump1eb44332009-09-09 15:08:12 +000037
Ted Kremenek01d9dbf2008-04-29 04:37:03 +000038 unsigned ObjC1 : 1; // Objective-C 1 support enabled.
39 unsigned ObjC2 : 1; // Objective-C 2 support enabled.
Fariborz Jahanian30bc5712009-01-22 23:02:58 +000040 unsigned ObjCNonFragileABI : 1; // Objective-C modern abi enabled
Mike Stump1eb44332009-09-09 15:08:12 +000041
Anders Carlssonee98ac52007-10-15 02:50:23 +000042 unsigned PascalStrings : 1; // Allow Pascal strings
Chris Lattner45e8cbd2007-11-28 05:34:05 +000043 unsigned WritableStrings : 1; // Allow writable strings
Anders Carlsson695dbb62007-11-30 04:21:22 +000044 unsigned LaxVectorConversions : 1;
Nate Begeman4e3629e2009-06-25 22:43:10 +000045 unsigned AltiVec : 1; // Support AltiVec-style vector initializers.
Daniel Dunbar6379a7a2008-08-11 17:36:14 +000046 unsigned Exceptions : 1; // Support exception handling.
Mike Stump738f8c22009-07-31 23:15:31 +000047 unsigned Rtti : 1; // Support rtti information.
Daniel Dunbarf77ac862008-08-11 21:35:06 +000048
49 unsigned NeXTRuntime : 1; // Use NeXT runtime.
Douglas Gregor3573c0c2009-02-14 20:49:29 +000050 unsigned Freestanding : 1; // Freestanding implementation
Chris Lattner7644f072009-03-13 22:38:49 +000051 unsigned NoBuiltin : 1; // Do not use builtin functions (-fno-builtin)
Daniel Dunbarf77ac862008-08-11 21:35:06 +000052
Anders Carlssone1b29ef2008-08-22 16:00:37 +000053 unsigned ThreadsafeStatics : 1; // Whether static initializers are protected
Daniel Dunbarc1571452008-12-01 18:55:22 +000054 // by locks.
Daniel Dunbar5345c392009-09-03 04:54:28 +000055 unsigned POSIXThreads : 1; // Compiling with POSIX thread support
56 // (-pthread)
Steve Naroff5618bd42008-08-27 16:04:49 +000057 unsigned Blocks : 1; // block extension to C
Daniel Dunbard604c402009-02-04 21:19:06 +000058 unsigned EmitAllDecls : 1; // Emit all declarations, even if
59 // they are unused.
Daniel Dunbaref2abfe2009-02-16 22:43:43 +000060 unsigned MathErrno : 1; // Math functions must respect errno
61 // (modulo the platform support).
62
Mike Stump2add4732009-04-01 20:28:16 +000063 unsigned OverflowChecking : 1; // Extension to call a handler function when
Mike Stump5d8b2cf2009-04-02 01:03:55 +000064 // signed integer arithmetic overflows.
Mike Stump2add4732009-04-01 20:28:16 +000065
Chris Lattner810f6d52009-03-13 17:38:01 +000066 unsigned HeinousExtensions : 1; // Extensions that we really don't like and
67 // may be ripped out at any time.
Fariborz Jahanian7cd2e932009-04-03 03:28:57 +000068
Anders Carlsson4ca076f2009-04-06 17:37:10 +000069 unsigned Optimize : 1; // Whether __OPTIMIZE__ should be defined.
Mike Stump1eb44332009-09-09 15:08:12 +000070 unsigned OptimizeSize : 1; // Whether __OPTIMIZE_SIZE__ should be
Anders Carlsson4ca076f2009-04-06 17:37:10 +000071 // defined.
Daniel Dunbar3bbc7532009-04-08 18:03:55 +000072 unsigned Static : 1; // Should __STATIC__ be defined (as
73 // opposed to __DYNAMIC__).
Daniel Dunbar9fd0b1f2009-04-08 03:03:23 +000074 unsigned PICLevel : 2; // The value for __PIC__, if non-zero.
75
Daniel Dunbar3bbc7532009-04-08 18:03:55 +000076 unsigned GNUInline : 1; // Should GNU inline semantics be
77 // used (instead of C99 semantics).
78 unsigned NoInline : 1; // Should __NO_INLINE__ be defined.
79
Fariborz Jahanian448f5e62009-04-17 03:04:15 +000080 unsigned ObjCGCBitmapPrint : 1; // Enable printing of gc's bitmap layout
81 // for __weak/__strong ivars.
82
Mike Stump1eb44332009-09-09 15:08:12 +000083 unsigned AccessControl : 1; // Whether C++ access control should
Anders Carlssona33d9b42009-05-13 19:49:53 +000084 // be enabled.
Eli Friedman15b91762009-06-05 07:05:05 +000085 unsigned CharIsSigned : 1; // Whether char is a signed or unsigned type
John Thompsona6fda122009-11-05 20:14:16 +000086 unsigned ShortWChar : 1; // Force wchar_t to be unsigned short int.
Nate Begeman4e3629e2009-06-25 22:43:10 +000087
88 unsigned OpenCL : 1; // OpenCL C99 language extensions.
89
Anders Carlsson92f58222009-08-22 22:30:33 +000090 unsigned ElideConstructors : 1; // Whether C++ copy constructors should be
91 // elided if possible.
Ted Kremenek01d9dbf2008-04-29 04:37:03 +000092private:
Bill Wendling4ebe3e42009-06-28 23:01:01 +000093 unsigned GC : 2; // Objective-C Garbage Collection modes. We
94 // declare this enum as unsigned because MSVC
95 // insists on making enums signed. Set/Query
96 // this value using accessors.
Fariborz Jahanian7cd2e932009-04-03 03:28:57 +000097 unsigned SymbolVisibility : 3; // Symbol's visibility.
Bill Wendling4ebe3e42009-06-28 23:01:01 +000098 unsigned StackProtector : 2; // Whether stack protectors are on. We declare
99 // this enum as unsigned because MSVC insists
100 // on making enums signed. Set/Query this
101 // value using accessors.
Fariborz Jahanian7cd2e932009-04-03 03:28:57 +0000102
Daniel Dunbarc9abc042009-04-08 05:11:16 +0000103 /// The user provided name for the "main file", if non-null. This is
104 /// useful in situations where the input file name does not match
105 /// the original input file, for example with -save-temps.
106 const char *MainFileName;
107
Mike Stump1eb44332009-09-09 15:08:12 +0000108public:
Douglas Gregor26dce442009-03-10 00:06:19 +0000109 unsigned InstantiationDepth; // Maximum template instantiation depth.
Ted Kremenek01d9dbf2008-04-29 04:37:03 +0000110
David Chisnall8a5a9aa2009-08-31 16:41:57 +0000111 const char *ObjCConstantStringClass;
112
Ted Kremenek01d9dbf2008-04-29 04:37:03 +0000113 enum GCMode { NonGC, GCOnly, HybridGC };
Bill Wendling4ebe3e42009-06-28 23:01:01 +0000114 enum StackProtectorMode { SSPOff, SSPOn, SSPReq };
Mike Stump1eb44332009-09-09 15:08:12 +0000115 enum VisibilityMode {
116 Default,
117 Protected,
Daniel Dunbar04d40782009-04-14 06:00:08 +0000118 Hidden
119 };
Mike Stump1eb44332009-09-09 15:08:12 +0000120
Reid Spencer5f016e22007-07-11 17:01:13 +0000121 LangOptions() {
Chris Lattnere4f21422009-06-30 01:26:17 +0000122 Trigraphs = BCPLComment = Bool = DollarIdents = AsmPreprocessor = 0;
Chris Lattner7e9c90b2009-03-20 15:44:26 +0000123 GNUMode = ImplicitInt = Digraphs = 0;
Chris Lattnerd658b562008-04-05 06:32:51 +0000124 HexFloats = 0;
Daniel Dunbar913af352009-05-07 21:58:26 +0000125 GC = ObjC1 = ObjC2 = ObjCNonFragileABI = 0;
David Chisnall8a5a9aa2009-08-31 16:41:57 +0000126 ObjCConstantStringClass = 0;
Eli Friedmanc71133f2009-04-28 03:28:55 +0000127 C99 = Microsoft = CPlusPlus = CPlusPlus0x = 0;
128 CXXOperatorNames = PascalStrings = WritableStrings = 0;
Daniel Dunbarc5a97ec2009-11-17 07:07:28 +0000129 Exceptions = Freestanding = NoBuiltin = 0;
130 NeXTRuntime = 1;
Mike Stump738f8c22009-07-31 23:15:31 +0000131 Rtti = 1;
Anders Carlssonb0f90cc2009-01-30 23:17:46 +0000132 LaxVectorConversions = 1;
Chris Lattner810f6d52009-03-13 17:38:01 +0000133 HeinousExtensions = 0;
Bill Wendling45483f72009-06-28 07:36:13 +0000134 AltiVec = OpenCL = StackProtector = 0;
David Chisnall8a5a9aa2009-08-31 16:41:57 +0000135
Daniel Dunbar04d40782009-04-14 06:00:08 +0000136 SymbolVisibility = (unsigned) Default;
Mike Stump1eb44332009-09-09 15:08:12 +0000137
Anders Carlssone1b29ef2008-08-22 16:00:37 +0000138 // FIXME: The default should be 1.
139 ThreadsafeStatics = 0;
Daniel Dunbar5345c392009-09-03 04:54:28 +0000140 POSIXThreads = 0;
Chris Lattnerae0ee032008-12-04 23:20:07 +0000141 Blocks = 0;
Daniel Dunbard604c402009-02-04 21:19:06 +0000142 EmitAllDecls = 0;
Daniel Dunbaref2abfe2009-02-16 22:43:43 +0000143 MathErrno = 1;
Douglas Gregor26dce442009-03-10 00:06:19 +0000144
Anders Carlssona33d9b42009-05-13 19:49:53 +0000145 // FIXME: The default should be 1.
146 AccessControl = 0;
Anders Carlsson92f58222009-08-22 22:30:33 +0000147 ElideConstructors = 1;
Mike Stump1eb44332009-09-09 15:08:12 +0000148
Mike Stump2add4732009-04-01 20:28:16 +0000149 OverflowChecking = 0;
Fariborz Jahanian448f5e62009-04-17 03:04:15 +0000150 ObjCGCBitmapPrint = 0;
Mike Stump2add4732009-04-01 20:28:16 +0000151
Douglas Gregor26dce442009-03-10 00:06:19 +0000152 InstantiationDepth = 99;
Mike Stump1eb44332009-09-09 15:08:12 +0000153
Anders Carlsson4ca076f2009-04-06 17:37:10 +0000154 Optimize = 0;
155 OptimizeSize = 0;
Daniel Dunbar9fd0b1f2009-04-08 03:03:23 +0000156
Daniel Dunbar3bbc7532009-04-08 18:03:55 +0000157 Static = 0;
Daniel Dunbar9fd0b1f2009-04-08 03:03:23 +0000158 PICLevel = 0;
Daniel Dunbarc9abc042009-04-08 05:11:16 +0000159
Daniel Dunbar3bbc7532009-04-08 18:03:55 +0000160 GNUInline = 0;
161 NoInline = 0;
162
Eli Friedman15b91762009-06-05 07:05:05 +0000163 CharIsSigned = 1;
John Thompson40d1bb62009-11-05 22:03:02 +0000164 ShortWChar = 0;
Eli Friedman15b91762009-06-05 07:05:05 +0000165
Daniel Dunbarc9abc042009-04-08 05:11:16 +0000166 MainFileName = 0;
Reid Spencer5f016e22007-07-11 17:01:13 +0000167 }
Mike Stump1eb44332009-09-09 15:08:12 +0000168
Ted Kremenek01d9dbf2008-04-29 04:37:03 +0000169 GCMode getGCMode() const { return (GCMode) GC; }
170 void setGCMode(GCMode m) { GC = (unsigned) m; }
Fariborz Jahanian7cd2e932009-04-03 03:28:57 +0000171
Bill Wendling4ebe3e42009-06-28 23:01:01 +0000172 StackProtectorMode getStackProtectorMode() const {
173 return static_cast<StackProtectorMode>(StackProtector);
174 }
175 void setStackProtectorMode(StackProtectorMode m) {
176 StackProtector = static_cast<unsigned>(m);
177 }
178
Daniel Dunbarc9abc042009-04-08 05:11:16 +0000179 const char *getMainFileName() const { return MainFileName; }
180 void setMainFileName(const char *Name) { MainFileName = Name; }
181
Mike Stump1eb44332009-09-09 15:08:12 +0000182 VisibilityMode getVisibilityMode() const {
183 return (VisibilityMode) SymbolVisibility;
Daniel Dunbar04d40782009-04-14 06:00:08 +0000184 }
Fariborz Jahanian7cd2e932009-04-03 03:28:57 +0000185 void setVisibilityMode(VisibilityMode v) { SymbolVisibility = (unsigned) v; }
Reid Spencer5f016e22007-07-11 17:01:13 +0000186};
187
188} // end namespace clang
189
190#endif