LangOptions.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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. #ifndef LLVM_CLANG_BASIC_LANGOPTIONS_H
  15. #define LLVM_CLANG_BASIC_LANGOPTIONS_H
  16. #include "clang/Basic/CommentOptions.h"
  17. #include "clang/Basic/LLVM.h"
  18. #include "clang/Basic/ObjCRuntime.h"
  19. #include "clang/Basic/Sanitizers.h"
  20. #include "clang/Basic/Visibility.h"
  21. #include <string>
  22. #include <vector>
  23. namespace clang {
  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. #ifdef MS_SUPPORT_VARIABLE_LANGOPTS
  30. #define LANGOPT(Name, Bits, Default, Description) unsigned Name : Bits;
  31. #define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
  32. #include "clang/Basic/LangOptions.def"
  33. #else
  34. #define LANGOPT(Name, Bits, Default, Description) static const unsigned Name = Default;
  35. #define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
  36. #include "clang/Basic/LangOptions.fixed.def"
  37. #endif
  38. protected:
  39. // Define language options of enumeration type. These are private, and will
  40. // have accessors (below).
  41. #ifdef MS_SUPPORT_VARIABLE_LANGOPTS
  42. #define LANGOPT(Name, Bits, Default, Description)
  43. #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
  44. unsigned Name : Bits;
  45. #include "clang/Basic/LangOptions.def"
  46. #endif
  47. };
  48. // #ifndef MS_SUPPORT_VARIABLE_LANGOPTS
  49. // #define LANGOPT(Name, Bits, Default, Description) __declspec(selectany) unsigned LangOptionsBase::#Name = Default;
  50. // #define ENUM_LANGOPT(Name, Type, Bits, Default, Description)
  51. // #include "clang/Basic/LangOptions.fixed.def"
  52. // #endif
  53. /// \brief Keeps track of the various options that can be
  54. /// enabled, which controls the dialect of C or C++ that is accepted.
  55. class LangOptions : public LangOptionsBase {
  56. public:
  57. typedef clang::Visibility Visibility;
  58. enum GCMode { NonGC, GCOnly, HybridGC };
  59. enum StackProtectorMode { SSPOff, SSPOn, SSPStrong, SSPReq };
  60. enum SignedOverflowBehaviorTy {
  61. SOB_Undefined, // Default C standard behavior.
  62. SOB_Defined, // -fwrapv
  63. SOB_Trapping // -ftrapv
  64. };
  65. enum PragmaMSPointersToMembersKind {
  66. PPTMK_BestCase,
  67. PPTMK_FullGeneralitySingleInheritance,
  68. PPTMK_FullGeneralityMultipleInheritance,
  69. PPTMK_FullGeneralityVirtualInheritance
  70. };
  71. enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off };
  72. enum MSVCMajorVersion {
  73. MSVC2010 = 16,
  74. MSVC2012 = 17,
  75. MSVC2013 = 18,
  76. MSVC2015 = 19
  77. };
  78. public:
  79. /// \brief Set of enabled sanitizers.
  80. SanitizerSet Sanitize;
  81. /// \brief Paths to blacklist files specifying which objects
  82. /// (files, functions, variables) should not be instrumented.
  83. std::vector<std::string> SanitizerBlacklistFiles;
  84. clang::ObjCRuntime ObjCRuntime;
  85. std::string ObjCConstantStringClass;
  86. /// \brief The name of the handler function to be called when -ftrapv is
  87. /// specified.
  88. ///
  89. /// If none is specified, abort (GCC-compatible behaviour).
  90. std::string OverflowHandler;
  91. /// \brief The name of the current module.
  92. std::string CurrentModule;
  93. /// \brief The name of the module that the translation unit is an
  94. /// implementation of. Prevents semantic imports, but does not otherwise
  95. /// treat this as the CurrentModule.
  96. std::string ImplementationOfModule;
  97. /// \brief The names of any features to enable in module 'requires' decls
  98. /// in addition to the hard-coded list in Module.cpp and the target features.
  99. ///
  100. /// This list is sorted.
  101. std::vector<std::string> ModuleFeatures;
  102. /// \brief Options for parsing comments.
  103. CommentOptions CommentOpts;
  104. LangOptions();
  105. // Define accessors/mutators for language options of enumeration type.
  106. #ifdef MS_SUPPORT_VARIABLE_LANGOPTS
  107. #define LANGOPT(Name, Bits, Default, Description)
  108. #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
  109. Type get##Name() const { return static_cast<Type>(Name); } \
  110. void set##Name(Type Value) { Name = static_cast<unsigned>(Value); }
  111. #include "clang/Basic/LangOptions.def"
  112. #else
  113. #define LANGOPT(Name, Bits, Default, Description)
  114. #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
  115. Type get##Name() const { return static_cast<Type>(Default); } \
  116. void set##Name(Type Value) { assert(Value == Default); }
  117. #include "clang/Basic/LangOptions.fixed.def"
  118. #endif
  119. // MS Change Starts
  120. bool HLSL2015; // Only supported for IntelliSense scenarios.
  121. bool HLSL2016;
  122. bool HLSL2017;
  123. std::string HLSLEntryFunction;
  124. unsigned RootSigMajor;
  125. unsigned RootSigMinor;
  126. bool IsHLSLLibrary;
  127. bool UseMinPrecision; // use min precision, not native precision.
  128. // MS Change Ends
  129. bool SPIRV = false; // SPIRV Change
  130. bool isSignedOverflowDefined() const {
  131. return getSignedOverflowBehavior() == SOB_Defined;
  132. }
  133. bool isSubscriptPointerArithmetic() const {
  134. return ObjCRuntime.isSubscriptPointerArithmetic() &&
  135. !ObjCSubscriptingLegacyRuntime;
  136. }
  137. bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const {
  138. return MSCompatibilityVersion >= MajorVersion * 10000000U;
  139. }
  140. /// \brief Reset all of the options that are not considered when building a
  141. /// module.
  142. void resetNonModularOptions();
  143. };
  144. /// \brief Floating point control options
  145. class FPOptions {
  146. public:
  147. unsigned fp_contract : 1;
  148. FPOptions() : fp_contract(0) {}
  149. FPOptions(const LangOptions &LangOpts) :
  150. fp_contract(LangOpts.DefaultFPContract) {}
  151. };
  152. /// \brief OpenCL volatile options
  153. class OpenCLOptions {
  154. public:
  155. #define OPENCLEXT(nm) unsigned nm : 1;
  156. #include "clang/Basic/OpenCLExtensions.def"
  157. OpenCLOptions() {
  158. #define OPENCLEXT(nm) nm = 0;
  159. #include "clang/Basic/OpenCLExtensions.def"
  160. }
  161. };
  162. /// \brief Describes the kind of translation unit being processed.
  163. enum TranslationUnitKind {
  164. /// \brief The translation unit is a complete translation unit.
  165. TU_Complete,
  166. /// \brief The translation unit is a prefix to a translation unit, and is
  167. /// not complete.
  168. TU_Prefix,
  169. /// \brief The translation unit is a module.
  170. TU_Module
  171. };
  172. } // end namespace clang
  173. #endif