[cfe-dev] How to get typedef name?
Miklos Vajna via cfe-dev
cfe-dev at lists.llvm.org
Wed Nov 6 13:13:58 PST 2019
Hi Kenth,
On Tue, Nov 05, 2019 at 09:28:42AM +0000, Kenth Eriksson via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> > Care to share a short, self-contained example?
>
> typedef int my_int_t;
>
> int my_func(my_int_t i);
And what code do you use to parse this?
> I would like to get the the typedef name for parameter 0 in the
> function decl. I don't want to desugar it, only get the typedef name.
That's what you get by default if you match for e.g. functionDecl() and
have a callback like this:
----
class Callback : public clang::ast_matchers::MatchFinder::MatchCallback
{
public:
Callback() {}
void
run(const clang::ast_matchers::MatchFinder::MatchResult& result) override
{
const auto decl = result.Nodes.getNodeAs<clang::FunctionDecl>("decl");
if (!decl)
{
return;
}
std::cerr << decl->parameters()[0]->getType().getAsString() << std::endl;
}
};
----
This prints "my_int_t" for me with your above 2 liner input.
Regards,
Miklos
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: Digital signature
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20191106/e5ae7c26/attachment.sig>
More information about the cfe-dev
mailing list