diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2014-01-03 20:10:54 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2014-01-03 20:10:54 +0000 |
commit | 69714e78e08babfbd0376c2a0b7b28a54b01aa6d (patch) | |
tree | d575266d0727a5ab88a37c634dfa5c71abacbf61 /clang/lib/Basic/Builtins.cpp | |
parent | 19bccb790e98d3875617d9659ddec2bbb10856ec (diff) | |
download | bcm5719-llvm-69714e78e08babfbd0376c2a0b7b28a54b01aa6d.tar.gz bcm5719-llvm-69714e78e08babfbd0376c2a0b7b28a54b01aa6d.zip |
Refactored Builtin::Context::isPrintfLike and isScanfLike into a helper function. The implementations are identical, except for the format arguments being searched for.
No functional changes intended.
llvm-svn: 198446
Diffstat (limited to 'clang/lib/Basic/Builtins.cpp')
-rw-r--r-- | clang/lib/Basic/Builtins.cpp | 51 |
1 files changed, 23 insertions, 28 deletions
diff --git a/clang/lib/Basic/Builtins.cpp b/clang/lib/Basic/Builtins.cpp index c84dd6dc38f..2fd00dd0b44 100644 --- a/clang/lib/Basic/Builtins.cpp +++ b/clang/lib/Basic/Builtins.cpp @@ -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, 0, 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"); +} |