Location of typedef types

Hi all,

we are working on source-to-source transformation tool based on clang and have a following problem. Example code:

void foo()
{
typedef int i32;
typedef i32 s32;
typedef i32 (*pfun)();

i32 a = (s32)0x1234u;
}

We want to rename i32, s32, pfun and all their occurrences in this function. We tried using VisitDeclRefExpr from clang::RecursiveASTVisitor, but it didn’t walk through typedefs. We tried to use VisitTypedefType and it correctly visited all occurrences of i32/s32 for this function, but we haven’t figured out how to get location information from clang::TypedefType to make actual renaming possible.

What would be a working (best?) way to do it?

Thanks,
Sergejs

Hi all,

we are working on source-to-source transformation tool based on clang and
have a following problem. Example code:

void foo()
{
  typedef int i32;
  typedef i32 s32;
  typedef i32 (*pfun)();

  i32 a = (s32)0x1234u;
}

We want to rename i32, s32, pfun and all their occurrences in this
function. We tried using VisitDeclRefExpr from clang::RecursiveASTVisitor,
but it didn't walk through typedefs. We tried to use VisitTypedefType and
it correctly visited all occurrences of i32/s32 for this function, but we
haven't figured out how to get location information from clang::TypedefType
to make actual renaming possible.

What would be a working (best?) way to do it?

Visit the corresponding TypeLoc (in this case VisitTypedefTypeLoc)

Cheers,
/Manuel

It solved the problem, thanks!

Sergejs