[cfe-dev] Get full source of multiple macro definitions using libtooling

John Bartelme via cfe-dev cfe-dev at lists.llvm.org
Wed May 11 05:12:48 PDT 2016


On May 10, 2016 8:54 AM, "John Bartelme" <bartelme at gmail.com> wrote:
>
>
> On May 9, 2016 10:30 AM, "Manuel Klimek" <klimek at google.com> wrote:
> >
> > On Mon, May 9, 2016 at 4:13 PM John Bartelme <bartelme at gmail.com> wrote:
> >>
> >> Thanks for the response.  As I alluded to in the opening paragraph I
have thousands of legacy header files that are a various mix of linkages
and interdependencies.  I have a need to strip out various structures and
typedefs and all structures/enums etc. they depend on from these files and
make just one small cohesive header.  I looked around a lot to try and see
what various technologies I could leverage for this end and ultimately
decided that libtooling would give me the best shot at it.  I was able to
get everything pulled out except for the statements that have multiple
macros as described earlier.  I’m using Lexer::getSourceText to access the
source for the given range.  Perhaps there is a way to print out the source
after it has already been preprocessed and macros expanded?  I’m very open
to switching gears if it is believed there is an easier way to do this.
Thanks, john
> >
> > Ok, yea, in that case just running it past -E first seems like that
might make things considerably easier; generally, clang tries to preserve
all the macro expansion history, but in your case, it sounds like you'd
actually prefer a completely flat view.
>
> Thank you for the suggestion.  I had actually thought of it earlier in
the process but then moved away from it as at the time I thought the macro
definitions had to stay in the source.  Given that you say it's challenging
or impossible to get at the multiple macro SourceLocations in a statement
I'll continue forward with preprocessing first.  If you or any else can
think of a way or approach to potentially get at all the expandable
SourceLocations in a statement I'd love to here about it as I'll probably
come back at a later date and try and tackle this again.   Thanks again for
all the help.

After going through more and more structures I've found a case where I
really need to retain the macro definition.  If anyone can think of an idea
to try and pull out the multiple expansion locations with their spelling
locations I'd be grateful.  Thanks.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160511/99982d0c/attachment.html>


More information about the cfe-dev mailing list