[cfe-dev] How to execute clang front-end AST visitor to exract some information from source code without compiling the source code first

Georgiou, Andreas via cfe-dev cfe-dev at lists.llvm.org
Thu Jul 14 02:47:44 PDT 2016


Hi all,

I have read the project documentation about the compilation databases and this is my exact case:


There can be multiple command objects for the same file, for example if the same source file is compiled with different configurations.


Except from deleting one entry out of the two since I just want semantic analysis of the source file and I dont really care about the way it will be compiled is there something else?

________________________________
From: Georgiou, Andreas
Sent: 14 July 2016 00:03:20
To: Laszlo Nagy
Cc: Miklos Vajna; David Blaikie; cfe-dev at lists.llvm.org
Subject: Re: [cfe-dev] How to execute clang front-end AST visitor to exract some information from source code without compiling the source code first


Dear Laszlo,


Thank you for the provided information. I will try it and I will report back to you all and also Bear issue tracker.

________________________________
From: Laszlo Nagy <rizsotto.mailinglist at gmail.com>
Sent: 13 July 2016 23:50:15
To: Georgiou, Andreas
Cc: Miklos Vajna; David Blaikie; cfe-dev at lists.llvm.org
Subject: Re: [cfe-dev] How to execute clang front-end AST visitor to exract some information from source code without compiling the source code first

hi Andreas,

can you try to create (or modify the existing) compilation database which makes the tools happy? (both clang-check and your tool too.) the project documentation has a chapter<http://clang.llvm.org/docs/JSONCompilationDatabase.html> to explain how that file should look like.

and if there any difference between the generated one and your hand written one, please post your findings to Bear<https://github.com/rizsotto/Bear/> issue tracker.

double AST visit can be caused by double entries in the compilation database. (you can check the file if that was the case or not.) it's a bug in Bear if there are duplicated entries in your compilation database.

regards,
Laszlo

On Thu, Jul 14, 2016 at 4:45 AM, Georgiou, Andreas <andreas.georgiou15 at imperial.ac.uk<mailto:andreas.georgiou15 at imperial.ac.uk>> wrote:

Hi all,

I did what you said and using the same compilation database I run clang-check and the tool gave me the same error.
Does it just trying to say that there is no "rule" for the specific file in the compilation database?

Furthermore something that I noticed is that some of my files are being analysed 2 times from my AST visitor and this is because of the compilation database. Is something I can do about it?
Something for example to avoid parsing 2 times the same file?


________________________________
From: Laszlo Nagy <rizsotto.mailinglist at gmail.com<mailto:rizsotto.mailinglist at gmail.com>>
Sent: 13 July 2016 13:45:40
To: Georgiou, Andreas
Cc: Miklos Vajna; David Blaikie; cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>

Subject: Re: [cfe-dev] How to execute clang front-end AST visitor to exract some information from source code without compiling the source code first

@Georgiou, when you generate a compilation database, it's better to validate it with other tools. you can run `clang-check`, `clang-format` just to see it's valid. if it is and your tool still fails with include problems, it might be the reason<http://clang.llvm.org/docs/LibTooling.html#builtin-includes> mentioned in the tooling doc. the other thing i noticed, that you use relative path to the module. (instead of `
../ffmpeg-0.6/libavcodec/libxvid_rc.c` try `/home/andreas/Desktop/ffmpeg-0.6/libavcodec/libxvid_rc.c`)

@David, the `build-interposition` command is already in the Clang source repo. it's in `tools/scan-build-py/bin` called `intercept-build`.


regards,
Laszlo

On Wed, Jul 13, 2016 at 9:10 PM, Georgiou, Andreas via cfe-dev <cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>> wrote:

Hi all,


As Miklos pointed out I am using Bear to create a compilation database to analyze my source code. This lead to much better results.

Although I still have some problems. Does anyone knows why this happens?


When I am executing using the compilation database I get this error on certain files:

Executing ASTvisitor ../ffmpeg-0.6/libavcodec/libxvid_rc.c
Skipping /home/andreas/Desktop/test_analysis/../ffmpeg-0.6/libavcodec/libxvid_rc.c. Command line not found.

And does  not extract anything from the file.

When am executing myAST visitor with the exact same file but without the compilation database it gives me the error:
 'xvid.h' file not found

but it analyses the file and the results are mostly correct. The visitor skips enything which has to do with variable declarations of the xvid.h header.
"How can the command line not found" error can be fixed?

Thank you all.


________________________________
From: Miklos Vajna <vmiklos at vmiklos.hu<mailto:vmiklos at vmiklos.hu>>
Sent: 12 July 2016 20:06:46
To: David Blaikie
Cc: Georgiou, Andreas; cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>
Subject: Re: [cfe-dev] How to execute clang front-end AST visitor to exract some information from source code without compiling the source code first

Hi,

On Tue, Jul 12, 2016 at 08:34:54AM -0700, David Blaikie via cfe-dev <cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>> wrote:
> (probably the most generic thing someone could build to help here would be
> a scan-build like build-interposition tool to make a compilation database
> from any project/build system. Not the most efficient, but would be handy
> as a fallback)

This is exactly what <https://github.com/rizsotto/Bear> implements.

Regards,

Miklos

_______________________________________________
cfe-dev mailing list
cfe-dev at lists.llvm.org<mailto:cfe-dev at lists.llvm.org>
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160714/1edf931f/attachment.html>


More information about the cfe-dev mailing list