CoatiSoftware / Sourcetrail

Sourcetrail - free and open-source interactive source explorer
https://www.sourcetrail.com/
GNU General Public License v3.0
14.85k stars 1.4k forks source link

Shallow C++ indexing: Working with incomplete code #1091

Open peckto opened 3 years ago

peckto commented 3 years ago

Hi,

Thank you for this amazing source code analyzer! Its a great tool to get into new or existing code base. I know, the main purpose of Sourcetrail is to support developers. Another target would be static code analysis and audits, where you typically dont have the complete code. In some case, you also dont have all header files. This makes it a little bit tricky.

As far as I understand, Sourcetrail stops parsing a file, as soon as an include is missing. Of course, with missing definitions, you cannot decide every condition, especially in C/C++. It would be nice, to have a somewhat "fuzzy" parser, like an IDE trys to guess unknown types.

This feature would open up a whole new use case for Sourcetrail.

mlangkabel commented 3 years ago

Hi @peckto,

thanks for bringing this up. We already had an issue (#416) which was more broadly and resulted in implementing a shallow indexer that can work with an incomplete code base for Python.

Our current C++ indexer is based on the Clang compiler frontend, but it should be possible to implement an additional indexing mode based on a C++ parser.

peckto commented 3 years ago

Thank you for your answer. Good to know, that there is already a shallow python indexer :)

I'm not a clang expert, but as far as I know, the QT Creator also uses clang for its code model: https://doc.qt.io/qtcreator/creator-clang-codemodel.html As far as I understood, this is different to clangd: https://clangd.llvm.org/ There is also the clangd-indexer: https://github.com/llvm/llvm-project/blob/master/clang-tools-extra/clangd/indexer/IndexerMain.cpp Maybe that is interesting for you.