diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Basic/Builtins.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Basic/Builtins.cpp | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/contrib/llvm/tools/clang/lib/Basic/Builtins.cpp b/contrib/llvm/tools/clang/lib/Basic/Builtins.cpp index c84dd6d..8efcac6 100644 --- a/contrib/llvm/tools/clang/lib/Basic/Builtins.cpp +++ b/contrib/llvm/tools/clang/lib/Basic/Builtins.cpp @@ -20,7 +20,7 @@ using namespace clang; static const Builtin::Info BuiltinInfo[] = { - { "not a builtin function", 0, 0, 0, ALL_LANGUAGES }, + { "not a builtin function", nullptr, nullptr, nullptr, ALL_LANGUAGES}, #define BUILTIN(ID, TYPE, ATTRS) { #ID, TYPE, ATTRS, 0, ALL_LANGUAGES }, #define LANGBUILTIN(ID, TYPE, ATTRS, BUILTIN_LANG) { #ID, TYPE, ATTRS, 0, BUILTIN_LANG }, #define LIBBUILTIN(ID, TYPE, ATTRS, HEADER, BUILTIN_LANG) { #ID, TYPE, ATTRS, HEADER,\ @@ -37,7 +37,7 @@ const Builtin::Info &Builtin::Context::GetRecord(unsigned ID) const { Builtin::Context::Context() { // Get the target specific builtins from the target. - TSRecords = 0; + TSRecords = nullptr; NumTSRecords = 0; } @@ -76,7 +76,7 @@ void Builtin::Context::InitializeBuiltins(IdentifierTable &Table, // Step #2: Register target-specific builtins. for (unsigned i = 0, e = NumTSRecords; i != e; ++i) - if (!LangOpts.NoBuiltin || !strchr(TSRecords[i].Attributes, 'f')) + if (BuiltinIsSupported(TSRecords[i], LangOpts)) Table.get(TSRecords[i].Name).setBuiltinID(i+Builtin::FirstTSBuiltin); } @@ -97,40 +97,35 @@ void Builtin::Context::ForgetBuiltin(unsigned ID, IdentifierTable &Table) { Table.get(GetRecord(ID).Name).setBuiltinID(0); } -bool -Builtin::Context::isPrintfLike(unsigned ID, unsigned &FormatIdx, - bool &HasVAListArg) { - const char *Printf = strpbrk(GetRecord(ID).Attributes, "pP"); - if (!Printf) +bool Builtin::Context::isLike(unsigned ID, unsigned &FormatIdx, + bool &HasVAListArg, const char *Fmt) const { + assert(Fmt && "Not passed a format string"); + assert(::strlen(Fmt) == 2 && + "Format string needs to be two characters long"); + assert(::toupper(Fmt[0]) == Fmt[1] && + "Format string is not in the form \"xX\""); + + const char *Like = ::strpbrk(GetRecord(ID).Attributes, Fmt); + if (!Like) return false; - HasVAListArg = (*Printf == 'P'); + HasVAListArg = (*Like == Fmt[1]); - ++Printf; - assert(*Printf == ':' && "p or P specifier must have be followed by a ':'"); - ++Printf; + ++Like; + assert(*Like == ':' && "Format specifier must be followed by a ':'"); + ++Like; - assert(strchr(Printf, ':') && "printf specifier must end with a ':'"); - FormatIdx = strtol(Printf, 0, 10); + assert(::strchr(Like, ':') && "Format specifier must end with a ':'"); + FormatIdx = ::strtol(Like, nullptr, 10); return true; } -// FIXME: Refactor with isPrintfLike. -bool -Builtin::Context::isScanfLike(unsigned ID, unsigned &FormatIdx, - bool &HasVAListArg) { - const char *Scanf = strpbrk(GetRecord(ID).Attributes, "sS"); - if (!Scanf) - return false; - - HasVAListArg = (*Scanf == 'S'); - - ++Scanf; - assert(*Scanf == ':' && "s or S specifier must have be followed by a ':'"); - ++Scanf; - - assert(strchr(Scanf, ':') && "printf specifier must end with a ':'"); - FormatIdx = strtol(Scanf, 0, 10); - return true; +bool Builtin::Context::isPrintfLike(unsigned ID, unsigned &FormatIdx, + bool &HasVAListArg) { + return isLike(ID, FormatIdx, HasVAListArg, "pP"); } +bool Builtin::Context::isScanfLike(unsigned ID, unsigned &FormatIdx, + bool &HasVAListArg) { + return isLike(ID, FormatIdx, HasVAListArg, "sS"); +} |