[cfe-users] Getting type from vardecl

Ryan Bartling via cfe-users cfe-users at lists.llvm.org
Mon Apr 30 01:12:55 PDT 2018


Hello, I'm writing my first clang-tidy check.  Basically I'm working on a
project where I'm forced to use systems hungarian notation.  I was trying
to get the applicable typedef from a vardecl (e.g. uin32_t)

I've started off with a simple matcher:
void AfrhungarianvariablesCheck::registerMatchers(MatchFinder *Finder)
{
    Finder->addMatcher(varDecl().bind("var"), this);
}

And I've been poking around what it finds with things like:
auto MatchedKind    = MatchedDecl->getKind();
auto MatchedType    = MatchedDecl->getType();
auto MatchedTypeRef = *MatchedType;
auto MatchedTypePtr = MatchedType.getTypePtr();
MatchedDecl->dump();

It'd be nice to have something like:
switch (type_of_var){
  case int8_t:
    prefix = "c";
    break;
  case int16_t:
    prefix = "s";
    break;
etc.
}

I'm mostly from an embedded C background, so a lot of the various tools to
work with clang are a bit new to me (gdb, Clang AST, C++, etc).  but I
think a lot of this will be very useful to me in the future.

Also, I found a sort of getting started talk for clang-tidy in the videos
from code:dive (https://www.youtube.com/watch?v=-QsiqIU8z7E), but the
camera was never pointed at the screen.  Is there anything similar with
better camera work?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-users/attachments/20180430/b117dee8/attachment.html>


More information about the cfe-users mailing list