From 659a8e87a67de517e9689afcf20f29a3d147d712 Mon Sep 17 00:00:00 2001 From: Duncan Ogilvie Date: Thu, 6 Apr 2023 09:36:09 +0200 Subject: [PATCH] Get rid of the redundant rettype from Function --- btparser/types.cpp | 11 +++++------ btparser/types.h | 5 ++--- btparser/typesparser.cpp | 19 +++++++++++-------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/btparser/types.cpp b/btparser/types.cpp index eb9df5c..0da35c2 100644 --- a/btparser/types.cpp +++ b/btparser/types.cpp @@ -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();"); } diff --git a/btparser/types.h b/btparser/types.h index c6b060a..ef47f9e 100644 --- a/btparser/types.h +++ b/btparser/types.h @@ -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); diff --git a/btparser/typesparser.cpp b/btparser/typesparser.cpp index 8122787..8dee31a 100644 --- a/btparser/typesparser.cpp +++ b/btparser/typesparser.cpp @@ -78,9 +78,9 @@ struct Parser index++; } - bool parseVariable(const std::vector& tlist, std::string& type, QualifiedType& qtype, std::string& name) + bool parseVariable(const std::vector& 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 } }