[cfe-dev] libtooling: source location vs nested macros

Miklos Vajna vmiklos at vmiklos.hu
Fri May 8 00:40:20 PDT 2015


I'm trying to put together a tool based on libtooling that renames a
class' member variable from the commandline.

I got it to the level that it's useful in practice, but there is one
case I can't handle: when the member variable is used in a macro that
calls another macro.

Here's how to use the tool:

- Build it with 'make', then
- bin/tool -dump -old-name=C::nX -new-name=m_nX test.cxx --

If you replace the call to OUTER() to INNER() in test.cxx, then the
rename is performed correctly. I guess it's something around how I call
the source manager's getImmediateSpellingLoc(), but I'm not sure what's
the exact problem.

Any ideas what I'm missing?

I tested the code only with clang-3.5 that comes by default in openSUSE
13.2, if SVN trunk is different in this regard, please let me know. I'm
attaching the Makefile, the tool itself and the test input.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: tool.cxx
Type: text/x-c
Size: 7186 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150508/895cbc0d/attachment.bin>
-------------- next part --------------
CLANGWARNS=-Werror -Wall -Wno-missing-braces -Wnon-virtual-dtor -Wendif-labels -Wextra -Wundef -Wunused-macros -Wshadow -Woverloaded-virtual
CLANGLIBS = -lLLVMSupport -lclangAST -lclangBasic -lclangFrontend -lclangRewrite -lclangTooling

bin/tool: tool.cxx Makefile
	ln -sf /usr/lib64 .
	mkdir -p bin
	clang++ $(CLANGFLAGS) $(CLANGLIBS) -o $@ $<

# vim: set noet sw=4 ts=4:
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.cxx
Type: text/x-c
Size: 287 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150508/895cbc0d/attachment-0001.bin>

More information about the cfe-dev mailing list