18 #include "llvm/ADT/SmallVector.h"
19 #include "llvm/ADT/StringRef.h"
20 using namespace clang;
23 {
"not a builtin function",
nullptr,
nullptr,
nullptr,
ALL_LANGUAGES},
24 #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES },
25 #define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) { #ID, TYPE, ATTRS, 0, BUILTIN_LANG },
26 #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, BUILTIN_LANG) { #ID, TYPE, ATTRS, HEADER,\
28 #include "clang/Basic/Builtins.def"
45 assert(NumTSRecords == 0 &&
"Already initialized target?");
51 bool BuiltinsUnsupported = LangOpts.NoBuiltin &&
53 bool MathBuiltinsUnsupported =
54 LangOpts.NoMathBuiltin && BuiltinInfo.
HeaderName &&
55 llvm::StringRef(BuiltinInfo.
HeaderName).equals(
"math.h");
56 bool GnuModeUnsupported = !LangOpts.GNUMode &&
58 bool MSModeUnsupported = !LangOpts.MicrosoftExt &&
60 bool ObjCUnsupported = !LangOpts.ObjC1 &&
62 return !BuiltinsUnsupported && !MathBuiltinsUnsupported &&
63 !GnuModeUnsupported && !MSModeUnsupported && !ObjCUnsupported;
73 if (BuiltinIsSupported(BuiltinInfo[i], LangOpts)) {
78 for (
unsigned i = 0, e = NumTSRecords; i != e; ++i)
79 if (BuiltinIsSupported(TSRecords[i], LangOpts))
87 if (!strchr(BuiltinInfo[i].Attributes,
'f'))
88 Names.push_back(BuiltinInfo[i].Name);
91 for (
unsigned i = 0, e = NumTSRecords; i != e; ++i)
92 if (!strchr(TSRecords[i].Attributes,
'f'))
93 Names.push_back(TSRecords[i].Name);
100 bool Builtin::Context::isLike(
unsigned ID,
unsigned &FormatIdx,
101 bool &HasVAListArg,
const char *Fmt)
const {
102 assert(Fmt &&
"Not passed a format string");
103 assert(::strlen(Fmt) == 2 &&
104 "Format string needs to be two characters long");
105 assert(::toupper(Fmt[0]) == Fmt[1] &&
106 "Format string is not in the form \"xX\"");
108 const char *Like = ::strpbrk(GetRecord(ID).Attributes, Fmt);
112 HasVAListArg = (*Like == Fmt[1]);
115 assert(*Like ==
':' &&
"Format specifier must be followed by a ':'");
118 assert(::strchr(Like,
':') &&
"Format specifier must end with a ':'");
119 FormatIdx = ::strtol(Like,
nullptr, 10);
124 bool &HasVAListArg) {
125 return isLike(ID, FormatIdx, HasVAListArg,
"pP");
129 bool &HasVAListArg) {
130 return isLike(ID, FormatIdx, HasVAListArg,
"sS");
static const Builtin::Info BuiltinInfo[]
virtual void getTargetBuiltins(const Builtin::Info *&Records, unsigned &NumRecords) const =0
bool isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg)
Determine whether this builtin is like printf in its formatting rules and, if so, set the index to th...
void GetBuiltinNames(SmallVectorImpl< const char * > &Names)
Populate the vector with the names of all of the builtins.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
void ForgetBuiltin(unsigned ID, IdentifierTable &Table)
Completely forget that the given ID was ever considered a builtin, e.g., because the user provided a ...
ID
Defines the set of possible language-specific address spaces.
Exposes information about the current target.
Defines the clang::LangOptions interface.
Implements an efficient mapping from strings to IdentifierInfo nodes.
void InitializeTarget(const TargetInfo &Target)
Perform target-specific initialization.
Defines the clang::IdentifierInfo, clang::IdentifierTable, and clang::Selector interfaces.
IdentifierInfo & get(StringRef Name)
Return the identifier token info for the specified named identifier.
bool isScanfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg)
Determine whether this builtin is like scanf in its formatting rules and, if so, set the index to the...
void setBuiltinID(unsigned ID)
void InitializeBuiltins(IdentifierTable &Table, const LangOptions &LangOpts)
Mark the identifiers for all the builtins with their appropriate builtin ID # and mark any non-portab...
Defines the clang::TargetInfo interface.
Defines enum values for all the target-independent builtin functions.