1 //===--- LangOptions.h - C Language Family Language Options -----*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Defines the clang::LangOptions interface.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CLANG_LANGOPTIONS_H
16 #define LLVM_CLANG_LANGOPTIONS_H
18 #include "clang/Basic/CommentOptions.h"
19 #include "clang/Basic/LLVM.h"
20 #include "clang/Basic/ObjCRuntime.h"
21 #include "clang/Basic/Visibility.h"
22 #include "llvm/ADT/IntrusiveRefCntPtr.h"
27 struct SanitizerOptions {
28 #define SANITIZER(NAME, ID) unsigned ID : 1;
29 #include "clang/Basic/Sanitizers.def"
31 /// \brief Cached set of sanitizer options with all sanitizers disabled.
32 static const SanitizerOptions Disabled;
35 /// Bitfields of LangOptions, split out from LangOptions in order to ensure that
36 /// this large collection of bitfields is a trivial class type.
37 class LangOptionsBase {
39 // Define simple language options (with no accessors).
40 #define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
41 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
42 #include "clang/Basic/LangOptions.def"
44 SanitizerOptions Sanitize;
46 // Define language options of enumeration type. These are private, and will
47 // have accessors (below).
48 #define LANGOPT(Name, Bits, Default, Description)
49 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
51 #include "clang/Basic/LangOptions.def"
54 /// \brief Keeps track of the various options that can be
55 /// enabled, which controls the dialect of C or C++ that is accepted.
56 class LangOptions : public RefCountedBase<LangOptions>, public LangOptionsBase {
58 typedef clang::Visibility Visibility;
60 enum GCMode { NonGC, GCOnly, HybridGC };
61 enum StackProtectorMode { SSPOff, SSPOn, SSPReq };
63 enum SignedOverflowBehaviorTy {
64 SOB_Undefined, // Default C standard behavior.
65 SOB_Defined, // -fwrapv
66 SOB_Trapping // -ftrapv
69 enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
72 clang::ObjCRuntime ObjCRuntime;
74 std::string ObjCConstantStringClass;
76 /// \brief The name of the handler function to be called when -ftrapv is
79 /// If none is specified, abort (GCC-compatible behaviour).
80 std::string OverflowHandler;
82 /// \brief The name of the current module.
83 std::string CurrentModule;
85 /// \brief Options for parsing comments.
86 CommentOptions CommentOpts;
90 // Define accessors/mutators for language options of enumeration type.
91 #define LANGOPT(Name, Bits, Default, Description)
92 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
93 Type get##Name() const { return static_cast<Type>(Name); } \
94 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
95 #include "clang/Basic/LangOptions.def"
97 bool isSignedOverflowDefined() const {
98 return getSignedOverflowBehavior() == SOB_Defined;
101 bool isSubscriptPointerArithmetic() const {
102 return ObjCRuntime.isSubscriptPointerArithmetic() &&
103 !ObjCSubscriptingLegacyRuntime;
106 /// \brief Reset all of the options that are not considered when building a
108 void resetNonModularOptions();
111 /// \brief Floating point control options
114 unsigned fp_contract : 1;
116 FPOptions() : fp_contract(0) {}
118 FPOptions(const LangOptions &LangOpts) :
119 fp_contract(LangOpts.DefaultFPContract) {}
122 /// \brief OpenCL volatile options
123 class OpenCLOptions {
125 #define OPENCLEXT(nm) unsigned nm : 1;
126 #include "clang/Basic/OpenCLExtensions.def"
129 #define OPENCLEXT(nm) nm = 0;
130 #include "clang/Basic/OpenCLExtensions.def"
134 /// \brief Describes the kind of translation unit being processed.
135 enum TranslationUnitKind {
136 /// \brief The translation unit is a complete translation unit.
138 /// \brief The translation unit is a prefix to a translation unit, and is
141 /// \brief The translation unit is a module.
145 } // end namespace clang