[cfe-dev] Ignore the content from the included files with RecursiveASTVisitor

Richard Smith richard at metafoo.co.uk
Mon Mar 17 17:54:52 PDT 2014


On Mon, Mar 17, 2014 at 5:51 PM, Richard Smith <richard at metafoo.co.uk>wrote:

> It appears that nabble.com failed to send your AST dump and code snippet
> to the mailing list. Snippets listed below.
>
> On Mon, Mar 17, 2014 at 4:13 PM, Etienne <eollivier at bsu.edu> wrote:
>
>> Hello,
>> I am working on a project where I am using the RecursiveASTVisitor to get
>> metrics from files.
>> I would like to exclude the parts of the AST that are from included files,
>> so the metrics I get concern only the file I want to analyze.
>> I tried to check the location of the Statements, Declarations etc and
>> exclude them if their location is not the file I am analyzing.
>> However this solution doesn't really work.
>> As an example if I call a function from cstdarg:
>>
>
> va_start(args, count);
>

va_start is a macro, not a function.

As the dump shows, the location of the CallExpr is in stdarg.h so my method
>> excludes it, even if I would like to keep it since it appears in my source
>> file
>>
>
> -CallExpr 0x6080720 </**/../lib/clang/3.5/include/stdarg.h:33:29, col:57>
> 'void'
>  |-ImplicitCastExpr 0x6080708 <col:29> 'void (*)(__va_list_tag *, ...)'
> <BuiltinFnToFnPtr>
>  | `-DeclRefExpr 0x6080630 <col:29> '<builtin fn type>' Function 0x60804f0
> '__builtin_va_start' 'void (__va_list_tag *, ...)'
>  |-ImplicitCastExpr 0x6080758 <myfile.cpp:68:14> '__va_list_tag *'
> <ArrayToPointerDecay>
>  | `-DeclRefExpr 0x6080658 <col:14> 'va_list':'__va_list_tag [1]' lvalue
> Var 0x607fe40 'args' 'va_list':'__va_list_tag [1]'
>  `-DeclRefExpr 0x6080680 <col:20> 'int' lvalue ParmVar 0x607fc00 'count'
> 'int'
>
>
>> Would you have a suggestion to avoid this problem or an other method that
>> could work?
>>
>
You can ask the SourceManager for the expansion location of each source
location to map to the place where a macro was expanded from, if any.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140317/2a9e6410/attachment.html>


More information about the cfe-dev mailing list