2018-02-17 07:40:07 +08:00
|
|
|
//===- LangOptions.cpp - C Language Family Language Options ---------------===//
|
2011-09-14 01:21:33 +08:00
|
|
|
//
|
2019-01-19 16:50:56 +08:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2011-09-14 01:21:33 +08:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file defines the LangOptions class.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2018-02-17 07:40:07 +08:00
|
|
|
|
2011-09-14 01:21:33 +08:00
|
|
|
#include "clang/Basic/LangOptions.h"
|
2021-08-05 07:42:14 +08:00
|
|
|
#include "llvm/ADT/SmallString.h"
|
|
|
|
#include "llvm/Support/Path.h"
|
2011-09-14 01:21:33 +08:00
|
|
|
|
|
|
|
using namespace clang;
|
|
|
|
|
2021-01-26 15:52:31 +08:00
|
|
|
LangOptions::LangOptions() : LangStd(LangStandard::lang_unspecified) {
|
2011-09-14 01:21:33 +08:00
|
|
|
#define LANGOPT(Name, Bits, Default, Description) Name = Default;
|
|
|
|
#define ENUM_LANGOPT(Name, Type, Bits, Default, Description) set##Name(Default);
|
|
|
|
#include "clang/Basic/LangOptions.def"
|
|
|
|
}
|
2011-09-14 04:44:41 +08:00
|
|
|
|
|
|
|
void LangOptions::resetNonModularOptions() {
|
|
|
|
#define LANGOPT(Name, Bits, Default, Description)
|
|
|
|
#define BENIGN_LANGOPT(Name, Bits, Default, Description) Name = Default;
|
2011-09-15 22:56:27 +08:00
|
|
|
#define BENIGN_ENUM_LANGOPT(Name, Type, Bits, Default, Description) \
|
2020-06-27 00:23:45 +08:00
|
|
|
Name = static_cast<unsigned>(Default);
|
2011-09-15 22:56:27 +08:00
|
|
|
#include "clang/Basic/LangOptions.def"
|
2013-01-18 19:30:38 +08:00
|
|
|
|
2017-06-02 04:01:01 +08:00
|
|
|
// These options do not affect AST generation.
|
2021-02-23 03:47:29 +08:00
|
|
|
NoSanitizeFiles.clear();
|
2017-03-30 08:29:36 +08:00
|
|
|
XRayAlwaysInstrumentFiles.clear();
|
|
|
|
XRayNeverInstrumentFiles.clear();
|
2013-01-18 19:30:38 +08:00
|
|
|
|
2011-11-16 03:35:01 +08:00
|
|
|
CurrentModule.clear();
|
2016-10-27 22:17:10 +08:00
|
|
|
IsHeaderFile = false;
|
2011-09-14 04:44:41 +08:00
|
|
|
}
|
|
|
|
|
2016-10-11 00:34:07 +08:00
|
|
|
bool LangOptions::isNoBuiltinFunc(StringRef FuncName) const {
|
2016-01-06 22:35:46 +08:00
|
|
|
for (unsigned i = 0, e = NoBuiltinFuncs.size(); i != e; ++i)
|
|
|
|
if (FuncName.equals(NoBuiltinFuncs[i]))
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-08 21:47:43 +08:00
|
|
|
|
|
|
|
VersionTuple LangOptions::getOpenCLVersionTuple() const {
|
|
|
|
const int Ver = OpenCLCPlusPlus ? OpenCLCPlusPlusVersion : OpenCLVersion;
|
2021-08-19 22:43:32 +08:00
|
|
|
if (OpenCLCPlusPlus && Ver != 100)
|
|
|
|
return VersionTuple(Ver / 100);
|
2018-05-08 21:47:43 +08:00
|
|
|
return VersionTuple(Ver / 100, (Ver % 100) / 10);
|
|
|
|
}
|
2020-04-11 04:34:46 +08:00
|
|
|
|
2021-08-24 18:59:42 +08:00
|
|
|
unsigned LangOptions::getOpenCLCompatibleVersion() const {
|
|
|
|
if (!OpenCLCPlusPlus)
|
|
|
|
return OpenCLVersion;
|
|
|
|
if (OpenCLCPlusPlusVersion == 100)
|
|
|
|
return 200;
|
|
|
|
if (OpenCLCPlusPlusVersion == 202100)
|
|
|
|
return 300;
|
|
|
|
llvm_unreachable("Unknown OpenCL version");
|
|
|
|
}
|
|
|
|
|
2021-08-05 07:42:14 +08:00
|
|
|
void LangOptions::remapPathPrefix(SmallString<256> &Path) const {
|
|
|
|
for (const auto &Entry : MacroPrefixMap)
|
|
|
|
if (llvm::sys::path::replace_path_prefix(Path, Entry.first, Entry.second))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-08-06 20:50:13 +08:00
|
|
|
std::string LangOptions::getOpenCLVersionString() const {
|
|
|
|
std::string Result;
|
|
|
|
{
|
|
|
|
llvm::raw_string_ostream Out(Result);
|
|
|
|
Out << (OpenCLCPlusPlus ? "C++ for OpenCL" : "OpenCL C") << " version "
|
|
|
|
<< getOpenCLVersionTuple().getAsString();
|
|
|
|
}
|
|
|
|
return Result;
|
|
|
|
}
|
|
|
|
|
2020-04-16 17:45:02 +08:00
|
|
|
FPOptions FPOptions::defaultWithoutTrailingStorage(const LangOptions &LO) {
|
|
|
|
FPOptions result(LO);
|
2020-04-11 04:34:46 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2020-06-27 00:23:45 +08:00
|
|
|
LLVM_DUMP_METHOD void FPOptions::dump() {
|
|
|
|
#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
|
|
|
|
llvm::errs() << "\n " #NAME " " << get##NAME();
|
|
|
|
#include "clang/Basic/FPOptions.def"
|
|
|
|
llvm::errs() << "\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
LLVM_DUMP_METHOD void FPOptionsOverride::dump() {
|
|
|
|
#define OPTION(NAME, TYPE, WIDTH, PREVIOUS) \
|
|
|
|
if (has##NAME##Override()) \
|
|
|
|
llvm::errs() << "\n " #NAME " Override is " << get##NAME##Override();
|
|
|
|
#include "clang/Basic/FPOptions.def"
|
|
|
|
llvm::errs() << "\n";
|
2020-04-11 04:34:46 +08:00
|
|
|
}
|