c++ - Refactoring fields of anonymous unions using clang lib -
c++ - Refactoring fields of anonymous unions using clang lib -
i'm doing little refactoring tool assist me automated c code generation , i'm using clang api that. developed tool works 1 specific test case:
typedef int mytype; typedef float mytype2; union ab { mytype a; mytype2 b; }; int fun(int); int foo(mytype bar) { homecoming fun( ((union{ mytype a; mytype2 b; })bar).a ); }
in code want refactor "mytype" occurrences new "mytype3", way i'm doing creating typeloc ast matcher ( typeloc().bind("id") ) find types , replace them refactoringtool (standard refactoring procedure found everywhere on internet). specific case ast doesn't seem contain definition anonymous union beingness used casting, dumped ast using xclang:
`-functiondecl 0x6b757f0 <line:12:1, line:15:1> line:12:5 foo 'int (mytype)' |-parmvardecl 0x6b75730 <col:9, col:16> col:16 bar 'mytype':'int' `-compoundstmt 0x6b75bb0 <line:13:1, line:15:1> `-returnstmt 0x6b75b90 <line:14:2, col:53> `-callexpr 0x6b75b60 <col:9, col:53> 'int' |-implicitcastexpr 0x6b75b48 <col:9> 'int (*)(int)' <functiontopointerdecay> | `-declrefexpr 0x6b75898 <col:9> 'int (int)' function 0x6b2f790 'fun' 'int (int)' `-memberexpr 0x6b75af0 <col:14, col:51> 'mytype':'int' .a 0x6b75970 `-parenexpr 0x6b75ad0 <col:14, col:49> 'union (anonymous union @ unions.c:14:16)':'union (anonymous @ unions.c:14:16)' `-cstylecastexpr 0x6b75aa8 <col:15, col:46> 'union (anonymous union @ unions.c:14:16)':'union (anonymous @ unions.c:14:16)' <tounion> `-implicitcastexpr 0x6b75a90 <col:46> 'mytype':'int' <lvaluetorvalue> `-declrefexpr 0x6b75a18 <col:46> 'mytype':'int' lvalue parmvar 0x6b75730 'bar' 'mytype':'int'
and in fact appears ignore body of union completely. there solution "problem", or @ to the lowest degree alternative refactoring?
as alternative tried enumerate fields of anonymous union recorddecl object, couldn't find how.
thank you.
c++ c refactoring llvm-clang
Comments
Post a Comment