clang - Appropriate AST Matcher for class parent declaration -
given class hierarchy:
class {}; class b {}; class c : public {}; class d : public c {};
i'm trying refactor class c inherit class b rather class a. can definition statement using recorddecl
:
recorddecl(hasname("c"), isdefinition()).bind("myclass")
with associated matchcallback, can dump()
class verify matched right node. have not found way bind instead public a
or, better, a
.
what appropriate ast matcher capture either public a
or a
class c?
edit:
the output of clang -ast-dump
filtered class c in situation show similar following:
cxxrecorddecl [address] <line numbers> <loc> class c definition |- public 'class a' |- cxxrecorddecl [address 2] <columns> <loc> implicit referenced class c
it's if there no ast node type represent parent class declarations in ast-dump.
i found link providing context how drill down. notably, 1 tutorial suggested using recorddecl
in match handler returned node vs. reference using cxxrecorddecl
. if output each base in match handler:
if (const cxxrecord *entitybase = result.nodes.getnodeas<clang::cxxrecorddecl>("entitybase")) { (auto &p : entitybase->bases()) { p.dump(); } }
we find reference class recordtype
referred cxxrecord
. using clang-query
, did not find way chain match recordtype(...)
conducive pulling public a
or a
. instead, solution became similar this:
std::string qual = "public "; std::string parentname = "a"; std::string parenttype = "class " + parentname; if (0 == parenttype.compare(p.gettype().getasstring())) { replacement rep(*(result.sourcemanager), p.getlocstart().getlocwithoffset(qual.length()), parentname.length(), "b"); replace->insert(rep); }
i'm not marking answer yet in case has way use recordtype snag base class reference directly rather iterating , checking base class type names, shown above.
Comments
Post a Comment