Skip to content
Snippets Groups Projects
Commit 69714e78 authored by Aaron Ballman's avatar Aaron Ballman
Browse files

Refactored Builtin::Context::isPrintfLike and isScanfLike into a helper...

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
parent 19bccb79
No related branches found
No related tags found
No related merge requests found
...@@ -177,6 +177,10 @@ private: ...@@ -177,6 +177,10 @@ private:
/// \brief Is this builtin supported according to the given language options? /// \brief Is this builtin supported according to the given language options?
bool BuiltinIsSupported(const Builtin::Info &BuiltinInfo, bool BuiltinIsSupported(const Builtin::Info &BuiltinInfo,
const LangOptions &LangOpts); const LangOptions &LangOpts);
/// \brief Helper function for isPrintfLike and isScanfLike.
bool isLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg,
const char *Fmt) const;
}; };
} }
......
...@@ -97,40 +97,35 @@ void Builtin::Context::ForgetBuiltin(unsigned ID, IdentifierTable &Table) { ...@@ -97,40 +97,35 @@ void Builtin::Context::ForgetBuiltin(unsigned ID, IdentifierTable &Table) {
Table.get(GetRecord(ID).Name).setBuiltinID(0); Table.get(GetRecord(ID).Name).setBuiltinID(0);
} }
bool bool Builtin::Context::isLike(unsigned ID, unsigned &FormatIdx,
Builtin::Context::isPrintfLike(unsigned ID, unsigned &FormatIdx, bool &HasVAListArg, const char *Fmt) const {
bool &HasVAListArg) { assert(Fmt && "Not passed a format string");
const char *Printf = strpbrk(GetRecord(ID).Attributes, "pP"); assert(::strlen(Fmt) == 2 &&
if (!Printf) "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; return false;
HasVAListArg = (*Printf == 'P'); HasVAListArg = (*Like == Fmt[1]);
++Printf; ++Like;
assert(*Printf == ':' && "p or P specifier must have be followed by a ':'"); assert(*Like == ':' && "Format specifier must be followed by a ':'");
++Printf; ++Like;
assert(strchr(Printf, ':') && "printf specifier must end with a ':'"); assert(::strchr(Like, ':') && "Format specifier must end with a ':'");
FormatIdx = strtol(Printf, 0, 10); FormatIdx = ::strtol(Like, 0, 10);
return true; return true;
} }
// FIXME: Refactor with isPrintfLike. bool Builtin::Context::isPrintfLike(unsigned ID, unsigned &FormatIdx,
bool bool &HasVAListArg) {
Builtin::Context::isScanfLike(unsigned ID, unsigned &FormatIdx, return isLike(ID, FormatIdx, HasVAListArg, "pP");
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::isScanfLike(unsigned ID, unsigned &FormatIdx,
bool &HasVAListArg) {
return isLike(ID, FormatIdx, HasVAListArg, "sS");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment