LangOptions.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. //===- LangOptions.cpp - C Language Family Language Options ---------------===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file defines the LangOptions class.
  10. //
  11. //===----------------------------------------------------------------------===//
  12. #include "clang/Basic/LangOptions.h"
  13. #include "llvm/ADT/SmallString.h"
  14. #include "llvm/Support/Path.h"
  15. using namespace clang;
  16. LangOptions::LangOptions() : LangStd(LangStandard::lang_unspecified) {
  17. #define LANGOPT(Name, Bits, Default, Description) Name = Default;
  18. #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) set##Name(Default);
  19. #include "clang/Basic/LangOptions.def"
  20. }
  21. void LangOptions::resetNonModularOptions() {
  22. #define LANGOPT(Name, Bits, Default, Description)
  23. #define BENIGN_LANGOPT(Name, Bits, Default, Description) Name = Default;
  24. #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
  25. Name = static_cast<unsigned>(Default);
  26. #include "clang/Basic/LangOptions.def"
  27. // These options do not affect AST generation.
  28. NoSanitizeFiles.clear();
  29. XRayAlwaysInstrumentFiles.clear();
  30. XRayNeverInstrumentFiles.clear();
  31. CurrentModule.clear();
  32. IsHeaderFile = false;
  33. }
  34. bool LangOptions::isNoBuiltinFunc(StringRef FuncName) const {
  35. for (unsigned i = 0, e = NoBuiltinFuncs.size(); i != e; ++i)
  36. if (FuncName.equals(NoBuiltinFuncs[i]))
  37. return true;
  38. return false;
  39. }
  40. VersionTuple LangOptions::getOpenCLVersionTuple() const {
  41. const int Ver = OpenCLCPlusPlus ? OpenCLCPlusPlusVersion : OpenCLVersion;
  42. if (OpenCLCPlusPlus && Ver != 100)
  43. return VersionTuple(Ver / 100);
  44. return VersionTuple(Ver / 100, (Ver % 100) / 10);
  45. }
  46. unsigned LangOptions::getOpenCLCompatibleVersion() const {
  47. if (!OpenCLCPlusPlus)
  48. return OpenCLVersion;
  49. if (OpenCLCPlusPlusVersion == 100)
  50. return 200;
  51. if (OpenCLCPlusPlusVersion == 202100)
  52. return 300;
  53. llvm_unreachable("Unknown OpenCL version");
  54. }
  55. void LangOptions::remapPathPrefix(SmallString<256> &Path) const {
  56. for (const auto &Entry : MacroPrefixMap)
  57. if (llvm::sys::path::replace_path_prefix(Path, Entry.first, Entry.second))
  58. break;
  59. }
  60. std::string LangOptions::getOpenCLVersionString() const {
  61. std::string Result;
  62. {
  63. llvm::raw_string_ostream Out(Result);
  64. Out << (OpenCLCPlusPlus ? "C++ for OpenCL" : "OpenCL C") << " version "
  65. << getOpenCLVersionTuple().getAsString();
  66. }
  67. return Result;
  68. }
  69. FPOptions FPOptions::defaultWithoutTrailingStorage(const LangOptions &LO) {
  70. FPOptions result(LO);
  71. return result;
  72. }
  73. LLVM_DUMP_METHOD void FPOptions::dump() {
  74. #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
  75. llvm::errs() << "\n " #NAME " " << get##NAME();
  76. #include "clang/Basic/FPOptions.def"
  77. llvm::errs() << "\n";
  78. }
  79. LLVM_DUMP_METHOD void FPOptionsOverride::dump() {
  80. #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
  81. if (has##NAME##Override()) \
  82. llvm::errs() << "\n " #NAME " Override is " << get##NAME##Override();
  83. #include "clang/Basic/FPOptions.def"
  84. llvm::errs() << "\n";
  85. }