Get rid of the redundant rettype from Function

This commit is contained in:
Duncan Ogilvie 2023-04-06 09:36:09 +02:00
parent 2973445c5f
commit 659a8e87a6
3 changed files with 18 additions and 17 deletions

View File

@ -175,7 +175,7 @@ bool Types::TypeManager::AddEnumerator(const std::string& enumType, const std::s
return true;
}
bool TypeManager::AddFunction(const std::string & owner, const std::string & name, const std::string & rettype, CallingConvention callconv, bool noreturn, bool typeonly, const QualifiedType& retqtype)
bool TypeManager::AddFunction(const std::string & owner, const std::string & name, const QualifiedType& retqtype, CallingConvention callconv, bool noreturn, bool typeonly)
{
auto found = functions.find(name);
if(found != functions.end() || name.empty() || owner.empty())
@ -184,13 +184,12 @@ bool TypeManager::AddFunction(const std::string & owner, const std::string & nam
Function f;
f.owner = owner;
f.name = name;
if(rettype != "void" && !isDefined(rettype) && !validPtr(rettype))
if (retqtype.name != "void" && !isDefined(retqtype.name))
return false;
f.rettype = rettype;
f.retqtype = retqtype;
f.callconv = callconv;
f.noreturn = noreturn;
f.typeonly = typeonly;
f.retqtype = retqtype;
functions.emplace(f.name, f);
return true;
}
@ -575,7 +574,7 @@ bool TypeManager::GenerateStubs() const
{
printf(" LOG_ARGUMENT(\"%s\", %s);\n", argtypes[i].c_str(), fn.args[i].name.c_str());
}
if(fn.rettype == "void")
if(fn.retqtype.name == "void")
{
printf(" orig_%s(", fn.name.c_str());
}
@ -593,7 +592,7 @@ bool TypeManager::GenerateStubs() const
}
}
puts(");");
if(fn.rettype == "void")
if(fn.retqtype.name == "void")
{
puts(" LOG_RETURN_VOID();");
}

View File

@ -94,8 +94,7 @@ namespace Types
{
std::string owner; //Function owner
std::string name; //Function identifier
std::string rettype; //Function return type
QualifiedType retqtype; // Function return qualified type
QualifiedType retqtype; // Function return type
CallingConvention callconv = DefaultDecl; //Function calling convention
bool noreturn = false; //Function does not return (ExitProcess, _exit)
bool typeonly = false; //Function is only used as a type (the name is based on where it's used)
@ -162,7 +161,7 @@ namespace Types
bool AddUnion(const std::string & owner, const std::string & name);
bool AddMember(const std::string & parent, const std::string & type, const std::string & name, int arrsize = 0, int offset = -1);
bool AppendMember(const std::string & type, const std::string & name, int arrsize = 0, int offset = -1);
bool AddFunction(const std::string & owner, const std::string & name, const std::string & rettype, CallingConvention callconv = Cdecl, bool noreturn = false, bool typeonly = false, const QualifiedType& retqtype = {});
bool AddFunction(const std::string & owner, const std::string & name, const QualifiedType& retqtype, CallingConvention callconv = Cdecl, bool noreturn = false, bool typeonly = false);
bool AddEnumerator(const std::string& enumType, const std::string& name, uint64_t value);
bool AddArg(const std::string & function, const std::string & type, const std::string & name, const QualifiedType& qtype);
bool AppendArg(const std::string & type, const std::string & name, const QualifiedType& qtype);

View File

@ -78,9 +78,9 @@ struct Parser
index++;
}
bool parseVariable(const std::vector<Lexer::TokenState>& tlist, std::string& type, QualifiedType& qtype, std::string& name)
bool parseVariable(const std::vector<Lexer::TokenState>& tlist, QualifiedType& qtype, std::string& name)
{
type.clear();
std::string type; // TODO: get rid of this variable
qtype = QualifiedType();
name.clear();
@ -182,7 +182,7 @@ struct Parser
// TODO: calling conventions
std::string retname;
if (!parseVariable(rettypes, fn.rettype, fn.retqtype, retname))
if (!parseVariable(rettypes, fn.retqtype, retname))
return false;
if (ptr)
@ -248,8 +248,9 @@ struct Parser
auto finalizeArgument = [&]()
{
Member am;
if (!parseVariable(tlist, am.type, am.qtype, am.name))
if (!parseVariable(tlist, am.qtype, am.name))
return false;
am.type = am.qtype.noconst(); // TODO: remove
fn.args.push_back(am);
tlist.clear();
startToken = curToken();
@ -412,8 +413,9 @@ struct Parser
return false;
}
if (!parseVariable(tlist, m.type, m.qtype, m.name))
if (!parseVariable(tlist, m.qtype, m.name))
return false;
m.type = m.qtype.noconst();
if (m.type == "void")
{
@ -880,8 +882,9 @@ struct Parser
}
Member tm;
if (!parseVariable(tlist, tm.type, tm.qtype, tm.name))
if (!parseVariable(tlist, tm.qtype, tm.name))
return false;
tm.type = tm.qtype.noconst();
model.types.push_back(tm);
}
return true;
@ -1064,11 +1067,11 @@ struct Parser
//Add base function types to avoid errors later
for (auto& function : model.functions)
{
auto success = typeManager.AddFunction(owner, function.name, function.rettype, function.callconv, function.noreturn, function.typeonly, function.retqtype);
auto success = typeManager.AddFunction(owner, function.name, function.retqtype, function.callconv, function.noreturn, function.typeonly);
if (!success)
{
//TODO properly handle errors
dprintf(QT_TRANSLATE_NOOP("DBG", "Failed to add function %s %s()\n"), function.rettype.c_str(), function.name.c_str());
dprintf(QT_TRANSLATE_NOOP("DBG", "Failed to add function %s %s()\n"), function.retqtype.pretty().c_str(), function.name.c_str());
function.name.clear(); //signal error
}
}