[cfe-dev] Tooling and Replacements -- How can I get structures for any conflicting replacements?

Steven Lu stevenlu443 at gmail.com
Sat Mar 28 23:45:03 PDT 2015


I am creating a source instrumentation tool, and although the primary mode
of operation is additive in nature (which is quite a comfortable subset of
general C++ source-to-source transformation), I would like to get a better
handle on where things stand.

I am looking at
http://clang.llvm.org/extra/doxygen/namespaceclang_1_1replace.html and I
see that this appears to have friendly code that maybe I could use to help
me get helpful structures to browse and reveal any conflicts in my tool.
The tool is a RecursiveASTVisitor based tool that uses AST Matchers.

However I find in my checked-out source tree that ApplyReplacements.h lives
here: tools/clang/tools/extra/clang-apply-replacements/include/clang-apply-replacements/Tooling/ApplyReplacements.h

This seems kind of secluded and I am unable to find examples that use
ApplyReplacements.h along with a workflow that seems to use clang tooling
Replacements.

So at this point my deduction is that ApplyReplacements.h might be old, or
some one-off code for another example tool or unit tests. Maybe
Replacements is newer and I have to find something else to use with my
Replacements.

Now I have found in here: (
http://clang.llvm.org/doxygen/namespaceclang_1_1tooling.html) the function

void clang::tooling::deduplicate(std::vector< Replacement > & Replaces,
std::vector< Range > & Conflicts)

This seems promising... So I grep the llvm source tree once again for
references to this function and -- lo and behold -- I am staring at the
guts of ApplyReplacements.h again!!

Maybe I need some hints about how I can fit these puzzle pieces together. I
have found that FileToReplacementMap and TUReplacements are just typedefs
and I eventually traced it back to collectReplacementsFromDirectory which
seems to be infiltrating replacements stored in YAML (or something to this
effect). This is cool, but I guess I'm more interested in how to get to use
the ApplyReplacements code with my non-YAML Replacements that are generated
on the fly with my RecursiveASTVisitor.

Thanks for reading my question.

Steven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150329/22bb3325/attachment.html>


More information about the cfe-dev mailing list