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 /// \file 11 /// \brief Defines the clang::LangOptions interface. 12 /// 13 //===----------------------------------------------------------------------===// 14 15 #ifndef LLVM_CLANG_LANGOPTIONS_H 16 #define LLVM_CLANG_LANGOPTIONS_H 17 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" 23 #include <string> 24 25 namespace clang { 26 27 struct SanitizerOptions { 28 #define SANITIZER(NAME, ID) unsigned ID : 1; 29 #include "clang/Basic/Sanitizers.def" 30 31 /// \brief Cached set of sanitizer options with all sanitizers disabled. 32 static const SanitizerOptions Disabled; 33 }; 34 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 { 38 public: 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" 43 44 SanitizerOptions Sanitize; 45 protected: 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) \ 50 unsigned Name : Bits; 51 #include "clang/Basic/LangOptions.def" 52 }; 53 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 { 57 public: 58 typedef clang::Visibility Visibility; 59 60 enum GCMode { NonGC, GCOnly, HybridGC }; 61 enum StackProtectorMode { SSPOff, SSPOn, SSPReq }; 62 63 enum SignedOverflowBehaviorTy { 64 SOB_Undefined, // Default C standard behavior. 65 SOB_Defined, // -fwrapv 66 SOB_Trapping // -ftrapv 67 }; 68 69 public: 70 clang::ObjCRuntime ObjCRuntime; 71 72 std::string ObjCConstantStringClass; 73 74 /// \brief The name of the handler function to be called when -ftrapv is 75 /// specified. 76 /// 77 /// If none is specified, abort (GCC-compatible behaviour). 78 std::string OverflowHandler; 79 80 /// \brief The name of the current module. 81 std::string CurrentModule; 82 83 /// \brief Options for parsing comments. 84 CommentOptions CommentOpts; 85 86 LangOptions(); 87 88 // Define accessors/mutators for language options of enumeration type. 89 #define LANGOPT(Name, Bits, Default, Description) 90 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ 91 Type get##Name() const { return static_cast<Type>(Name); } \ 92 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); } 93 #include "clang/Basic/LangOptions.def" 94 isSignedOverflowDefined()95 bool isSignedOverflowDefined() const { 96 return getSignedOverflowBehavior() == SOB_Defined; 97 } 98 99 /// \brief Reset all of the options that are not considered when building a 100 /// module. 101 void resetNonModularOptions(); 102 }; 103 104 /// \brief Floating point control options 105 class FPOptions { 106 public: 107 unsigned fp_contract : 1; 108 FPOptions()109 FPOptions() : fp_contract(0) {} 110 FPOptions(const LangOptions & LangOpts)111 FPOptions(const LangOptions &LangOpts) : 112 fp_contract(LangOpts.DefaultFPContract) {} 113 }; 114 115 /// \brief OpenCL volatile options 116 class OpenCLOptions { 117 public: 118 #define OPENCLEXT(nm) unsigned nm : 1; 119 #include "clang/Basic/OpenCLExtensions.def" 120 OpenCLOptions()121 OpenCLOptions() { 122 #define OPENCLEXT(nm) nm = 0; 123 #include "clang/Basic/OpenCLExtensions.def" 124 } 125 }; 126 127 /// \brief Describes the kind of translation unit being processed. 128 enum TranslationUnitKind { 129 /// \brief The translation unit is a complete translation unit. 130 TU_Complete, 131 /// \brief The translation unit is a prefix to a translation unit, and is 132 /// not complete. 133 TU_Prefix, 134 /// \brief The translation unit is a module. 135 TU_Module 136 }; 137 138 } // end namespace clang 139 140 #endif 141