mirror of https://github.com/x64dbg/btparser
Get rid of the redundant rettype from Function
This commit is contained in:
parent
2973445c5f
commit
659a8e87a6
|
@ -175,7 +175,7 @@ bool Types::TypeManager::AddEnumerator(const std::string& enumType, const std::s
|
||||||
return true;
|
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);
|
auto found = functions.find(name);
|
||||||
if(found != functions.end() || name.empty() || owner.empty())
|
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;
|
Function f;
|
||||||
f.owner = owner;
|
f.owner = owner;
|
||||||
f.name = name;
|
f.name = name;
|
||||||
if(rettype != "void" && !isDefined(rettype) && !validPtr(rettype))
|
if (retqtype.name != "void" && !isDefined(retqtype.name))
|
||||||
return false;
|
return false;
|
||||||
f.rettype = rettype;
|
f.retqtype = retqtype;
|
||||||
f.callconv = callconv;
|
f.callconv = callconv;
|
||||||
f.noreturn = noreturn;
|
f.noreturn = noreturn;
|
||||||
f.typeonly = typeonly;
|
f.typeonly = typeonly;
|
||||||
f.retqtype = retqtype;
|
|
||||||
functions.emplace(f.name, f);
|
functions.emplace(f.name, f);
|
||||||
return true;
|
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());
|
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());
|
printf(" orig_%s(", fn.name.c_str());
|
||||||
}
|
}
|
||||||
|
@ -593,7 +592,7 @@ bool TypeManager::GenerateStubs() const
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
puts(");");
|
puts(");");
|
||||||
if(fn.rettype == "void")
|
if(fn.retqtype.name == "void")
|
||||||
{
|
{
|
||||||
puts(" LOG_RETURN_VOID();");
|
puts(" LOG_RETURN_VOID();");
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,8 +94,7 @@ namespace Types
|
||||||
{
|
{
|
||||||
std::string owner; //Function owner
|
std::string owner; //Function owner
|
||||||
std::string name; //Function identifier
|
std::string name; //Function identifier
|
||||||
std::string rettype; //Function return type
|
QualifiedType retqtype; // Function return type
|
||||||
QualifiedType retqtype; // Function return qualified type
|
|
||||||
CallingConvention callconv = DefaultDecl; //Function calling convention
|
CallingConvention callconv = DefaultDecl; //Function calling convention
|
||||||
bool noreturn = false; //Function does not return (ExitProcess, _exit)
|
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)
|
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 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 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 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 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 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);
|
bool AppendArg(const std::string & type, const std::string & name, const QualifiedType& qtype);
|
||||||
|
|
|
@ -78,9 +78,9 @@ struct Parser
|
||||||
index++;
|
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();
|
qtype = QualifiedType();
|
||||||
name.clear();
|
name.clear();
|
||||||
|
|
||||||
|
@ -182,7 +182,7 @@ struct Parser
|
||||||
// TODO: calling conventions
|
// TODO: calling conventions
|
||||||
|
|
||||||
std::string retname;
|
std::string retname;
|
||||||
if (!parseVariable(rettypes, fn.rettype, fn.retqtype, retname))
|
if (!parseVariable(rettypes, fn.retqtype, retname))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (ptr)
|
if (ptr)
|
||||||
|
@ -248,8 +248,9 @@ struct Parser
|
||||||
auto finalizeArgument = [&]()
|
auto finalizeArgument = [&]()
|
||||||
{
|
{
|
||||||
Member am;
|
Member am;
|
||||||
if (!parseVariable(tlist, am.type, am.qtype, am.name))
|
if (!parseVariable(tlist, am.qtype, am.name))
|
||||||
return false;
|
return false;
|
||||||
|
am.type = am.qtype.noconst(); // TODO: remove
|
||||||
fn.args.push_back(am);
|
fn.args.push_back(am);
|
||||||
tlist.clear();
|
tlist.clear();
|
||||||
startToken = curToken();
|
startToken = curToken();
|
||||||
|
@ -412,8 +413,9 @@ struct Parser
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parseVariable(tlist, m.type, m.qtype, m.name))
|
if (!parseVariable(tlist, m.qtype, m.name))
|
||||||
return false;
|
return false;
|
||||||
|
m.type = m.qtype.noconst();
|
||||||
|
|
||||||
if (m.type == "void")
|
if (m.type == "void")
|
||||||
{
|
{
|
||||||
|
@ -880,8 +882,9 @@ struct Parser
|
||||||
}
|
}
|
||||||
|
|
||||||
Member tm;
|
Member tm;
|
||||||
if (!parseVariable(tlist, tm.type, tm.qtype, tm.name))
|
if (!parseVariable(tlist, tm.qtype, tm.name))
|
||||||
return false;
|
return false;
|
||||||
|
tm.type = tm.qtype.noconst();
|
||||||
model.types.push_back(tm);
|
model.types.push_back(tm);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -1064,11 +1067,11 @@ struct Parser
|
||||||
//Add base function types to avoid errors later
|
//Add base function types to avoid errors later
|
||||||
for (auto& function : model.functions)
|
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)
|
if (!success)
|
||||||
{
|
{
|
||||||
//TODO properly handle errors
|
//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
|
function.name.clear(); //signal error
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue