xref: /freebsd/contrib/llvm-project/clang/lib/Basic/LangOptions.cpp (revision 69ade1e033e478ec426cafc0ec2104d672de294a)
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 
13 #include "clang/Basic/LangOptions.h"
14 #include "llvm/ADT/SmallString.h"
15 #include "llvm/Support/Path.h"
16 
17 using namespace clang;
18 
19 LangOptions::LangOptions() : LangStd(LangStandard::lang_unspecified) {
20 #define LANGOPT(Name, Bits, Default, Description) Name = Default;
21 #define ENUM_LANGOPT(Name, Type, Bits, Default, Description) set##Name(Default);
22 #include "clang/Basic/LangOptions.def"
23 }
24 
25 void LangOptions::resetNonModularOptions() {
26 #define LANGOPT(Name, Bits, Default, Description)
27 #define BENIGN_LANGOPT(Name, Bits, Default, Description) Name = Default;
28 #define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
29   Name = static_cast<unsigned>(Default);
30 #include "clang/Basic/LangOptions.def"
31 
32   // These options do not affect AST generation.
33   NoSanitizeFiles.clear();
34   XRayAlwaysInstrumentFiles.clear();
35   XRayNeverInstrumentFiles.clear();
36 
37   CurrentModule.clear();
38   IsHeaderFile = false;
39 }
40 
41 bool LangOptions::isNoBuiltinFunc(StringRef FuncName) const {
42   for (unsigned i = 0, e = NoBuiltinFuncs.size(); i != e; ++i)
43     if (FuncName.equals(NoBuiltinFuncs[i]))
44       return true;
45   return false;
46 }
47 
48 VersionTuple LangOptions::getOpenCLVersionTuple() const {
49   const int Ver = OpenCLCPlusPlus ? OpenCLCPlusPlusVersion : OpenCLVersion;
50   return VersionTuple(Ver / 100, (Ver % 100) / 10);
51 }
52 
53 void LangOptions::remapPathPrefix(SmallString<256> &Path) const {
54   for (const auto &Entry : MacroPrefixMap)
55     if (llvm::sys::path::replace_path_prefix(Path, Entry.first, Entry.second))
56       break;
57 }
58 
59 FPOptions FPOptions::defaultWithoutTrailingStorage(const LangOptions &LO) {
60   FPOptions result(LO);
61   return result;
62 }
63 
64 LLVM_DUMP_METHOD void FPOptions::dump() {
65 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS)                                    \
66   llvm::errs() << "\n " #NAME " " << get##NAME();
67 #include "clang/Basic/FPOptions.def"
68   llvm::errs() << "\n";
69 }
70 
71 LLVM_DUMP_METHOD void FPOptionsOverride::dump() {
72 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS)                                    \
73   if (has##NAME##Override())                                                   \
74     llvm::errs() << "\n " #NAME " Override is " << get##NAME##Override();
75 #include "clang/Basic/FPOptions.def"
76   llvm::errs() << "\n";
77 }
78