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 // This file defines the LangOptions interface. 11 // 12 //===----------------------------------------------------------------------===// 13 14 #ifndef LLVM_CLANG_LANGOPTIONS_H 15 #define LLVM_CLANG_LANGOPTIONS_H 16 17 #include <string> 18 #include "clang/Basic/LLVM.h" 19 #include "clang/Basic/Visibility.h" 20 #include "llvm/ADT/IntrusiveRefCntPtr.h" 21 22 namespace clang { 23 24 /// Bitfields of LangOptions, split out from LangOptions in order to ensure that 25 /// this large collection of bitfields is a trivial class type. 26 class LangOptionsBase { 27 public: 28 // Define simple language options (with no accessors). 29 #define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits; 30 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) 31 #include "clang/Basic/LangOptions.def" 32 33 protected: 34 // Define language options of enumeration type. These are private, and will 35 // have accessors (below). 36 #define LANGOPT(Name, Bits, Default, Description) 37 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ 38 unsigned Name : Bits; 39 #include "clang/Basic/LangOptions.def" 40 }; 41 42 /// LangOptions - This class keeps track of the various options that can be 43 /// enabled, which controls the dialect of C that is accepted. 44 class LangOptions : public RefCountedBase<LangOptions>, public LangOptionsBase { 45 public: 46 typedef clang::Visibility Visibility; 47 48 enum GCMode { NonGC, GCOnly, HybridGC }; 49 enum StackProtectorMode { SSPOff, SSPOn, SSPReq }; 50 51 enum SignedOverflowBehaviorTy { 52 SOB_Undefined, // Default C standard behavior. 53 SOB_Defined, // -fwrapv 54 SOB_Trapping // -ftrapv 55 }; 56 57 public: 58 std::string ObjCConstantStringClass; 59 60 /// The name of the handler function to be called when -ftrapv is specified. 61 /// If none is specified, abort (GCC-compatible behaviour). 62 std::string OverflowHandler; 63 64 /// \brief The name of the current module. 65 std::string CurrentModule; 66 67 LangOptions(); 68 69 // Define accessors/mutators for language options of enumeration type. 70 #define LANGOPT(Name, Bits, Default, Description) 71 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \ 72 Type get##Name() const { return static_cast<Type>(Name); } \ 73 void set##Name(Type Value) { Name = static_cast<unsigned>(Value); } 74 #include "clang/Basic/LangOptions.def" 75 isSignedOverflowDefined()76 bool isSignedOverflowDefined() const { 77 return getSignedOverflowBehavior() == SOB_Defined; 78 } 79 80 /// \brief Reset all of the options that are not considered when building a 81 /// module. 82 void resetNonModularOptions(); 83 }; 84 85 /// Floating point control options 86 class FPOptions { 87 public: 88 unsigned fp_contract : 1; 89 FPOptions()90 FPOptions() : fp_contract(0) {} 91 FPOptions(const LangOptions & LangOpts)92 FPOptions(const LangOptions &LangOpts) : 93 fp_contract(LangOpts.DefaultFPContract) {} 94 }; 95 96 /// OpenCL volatile options 97 class OpenCLOptions { 98 public: 99 #define OPENCLEXT(nm) unsigned nm : 1; 100 #include "clang/Basic/OpenCLExtensions.def" 101 OpenCLOptions()102 OpenCLOptions() { 103 #define OPENCLEXT(nm) nm = 0; 104 #include "clang/Basic/OpenCLExtensions.def" 105 } 106 }; 107 108 /// \brief Describes the kind of translation unit being processed. 109 enum TranslationUnitKind { 110 /// \brief The translation unit is a complete translation unit. 111 TU_Complete, 112 /// \brief The translation unit is a prefix to a translation unit, and is 113 /// not complete. 114 TU_Prefix, 115 /// \brief The translation unit is a module. 116 TU_Module 117 }; 118 119 /// \brief 120 } // end namespace clang 121 122 #endif 123