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