clang  14.0.0git
LangOptions.cpp
Go to the documentation of this file.
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 
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 
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();
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  if (OpenCLCPlusPlus && Ver != 100)
51  return VersionTuple(Ver / 100);
52  return VersionTuple(Ver / 100, (Ver % 100) / 10);
53 }
54 
56  if (!OpenCLCPlusPlus)
57  return OpenCLVersion;
58  if (OpenCLCPlusPlusVersion == 100)
59  return 200;
60  if (OpenCLCPlusPlusVersion == 202100)
61  return 300;
62  llvm_unreachable("Unknown OpenCL version");
63 }
64 
66  for (const auto &Entry : MacroPrefixMap)
67  if (llvm::sys::path::replace_path_prefix(Path, Entry.first, Entry.second))
68  break;
69 }
70 
72  std::string Result;
73  {
74  llvm::raw_string_ostream Out(Result);
75  Out << (OpenCLCPlusPlus ? "C++ for OpenCL" : "OpenCL C") << " version "
76  << getOpenCLVersionTuple().getAsString();
77  }
78  return Result;
79 }
80 
82  FPOptions result(LO);
83  return result;
84 }
85 
86 LLVM_DUMP_METHOD void FPOptions::dump() {
87 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
88  llvm::errs() << "\n " #NAME " " << get##NAME();
89 #include "clang/Basic/FPOptions.def"
90  llvm::errs() << "\n";
91 }
92 
93 LLVM_DUMP_METHOD void FPOptionsOverride::dump() {
94 #define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
95  if (has##NAME##Override()) \
96  llvm::errs() << "\n " #NAME " Override is " << get##NAME##Override();
97 #include "clang/Basic/FPOptions.def"
98  llvm::errs() << "\n";
99 }
clang::LangOptions::CurrentModule
std::string CurrentModule
The name of the current module, of which the main source file is a part.
Definition: LangOptions.h:343
clang::LangOptions::XRayAlwaysInstrumentFiles
std::vector< std::string > XRayAlwaysInstrumentFiles
Paths to the XRay "always instrument" files specifying which objects (files, functions,...
Definition: LangOptions.h:306
clang::LangOptions::getOpenCLCompatibleVersion
unsigned getOpenCLCompatibleVersion() const
Return the OpenCL version that kernel language is compatible with.
Definition: LangOptions.cpp:55
string
string(SUBSTRING ${CMAKE_CURRENT_BINARY_DIR} 0 ${PATH_LIB_START} PATH_HEAD) string(SUBSTRING $
Definition: CMakeLists.txt:22
clang::LangOptions::getOpenCLVersionString
std::string getOpenCLVersionString() const
Return the OpenCL C or C++ for OpenCL language name and version as a string.
Definition: LangOptions.cpp:71
clang::LangOptions::MacroPrefixMap
std::map< std::string, std::string, std::greater< std::string > > MacroPrefixMap
A prefix map for FILE, BASE_FILE and __builtin_FILE().
Definition: LangOptions.h:358
LangOptions.h
clang::FPOptions
Definition: LangOptions.h:480
clang::LangOptions::NoBuiltinFuncs
std::vector< std::string > NoBuiltinFuncs
A list of all -fno-builtin-* function names (e.g., memset).
Definition: LangOptions.h:355
llvm::SmallString
Definition: LLVM.h:37
clang::LangOptions::IsHeaderFile
bool IsHeaderFile
Indicates whether the front-end is explicitly told that the input is a header file (i....
Definition: LangOptions.h:380
clang::FPOptions::defaultWithoutTrailingStorage
static FPOptions defaultWithoutTrailingStorage(const LangOptions &LO)
Return the default value of FPOptions that's used when trailing storage isn't required.
Definition: LangOptions.cpp:81
clang::LangOptions::isNoBuiltinFunc
bool isNoBuiltinFunc(StringRef Name) const
Is this a libc/libm function that is no longer recognized as a builtin because a -fno-builtin-* optio...
Definition: LangOptions.cpp:41
clang::LangOptions::XRayNeverInstrumentFiles
std::vector< std::string > XRayNeverInstrumentFiles
Paths to the XRay "never instrument" files specifying which objects (files, functions,...
Definition: LangOptions.h:312
clang::LangOptions::LangOptions
LangOptions()
Definition: LangOptions.cpp:19
clang::LangOptions::getOpenCLVersionTuple
VersionTuple getOpenCLVersionTuple() const
Return the OpenCL C or C++ version as a VersionTuple.
Definition: LangOptions.cpp:48
clang::LangOptions::remapPathPrefix
void remapPathPrefix(SmallString< 256 > &Path) const
Remap path prefix according to -fmacro-prefix-path option.
Definition: LangOptions.cpp:65
clang::LangOptions::NoSanitizeFiles
std::vector< std::string > NoSanitizeFiles
Paths to files specifying which objects (files, functions, variables) should not be instrumented.
Definition: LangOptions.h:300
clang::LangStandard
LangStandard - Information about the properties of a particular language standard.
Definition: LangStandard.h:63
clang::FPOptionsOverride::dump
LLVM_DUMP_METHOD void dump()
Definition: LangOptions.cpp:93
clang::LangOptions
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
Definition: LangOptions.h:58
clang
Definition: CalledOnceCheck.h:17
clang::LangOptions::resetNonModularOptions
void resetNonModularOptions()
Reset all of the options that are not considered when building a module.
Definition: LangOptions.cpp:25
clang::FPOptions::dump
LLVM_DUMP_METHOD void dump()
Definition: LangOptions.cpp:86