How to find symbols in extern code files or projects and get their "type" (code analysis library)?
-
Hi,
Are you trying to reimplement something like the clang code model from Qt Creator ?
-
@SGaist said in How to find symbols in extern code files or projects and get their "type" (code analysis library)?:
Are you trying to reimplement something like the clang code model from Qt Creator ?
Hi, not quite.
At least this is not my intention just for the sake of doing it.I think I would be happy if I can access it from my QtCreator Plugin. Don't know if it's a good idea to go this way and if it helps to solve my issue. That's why I'm asking.
Are you following the whole thread here?
My only, but not so easy (as I found out and as @FeRDNYC told me) goal is it to extract variables (symbols) from code files or projects and do something with that information. I may not need all of them, and the user should decide which ones to include or exclude.
To be 100% accurate, I am only interested in the particular classes and objects (i.e. their class names) that appear in a file.So, does a QtCreator Plugin have access to the "clang code model from QtCreator"?
If so, how can I do it?
-
@SGaist said in How to find symbols in extern code files or projects and get their "type" (code analysis library)?:
From your description, it looks like you are after libclang to parse the code and extract information.
That is looking promising.
So I can use my own clang to parse and inspect the file(s)?!
And the clang / code model used by the IDE is just read-only? You don't have access to it and can't gain access in some way by installing or modifying something?!But thanks, that helped. Will try libclang then... looks complicated to use tho :/
-
Libclang is just a library.
As I wrote, I currently don't know how the code model is implemented and if you can tap in it. However, you can check that, the code of Qt Creator is available.
-
@SGaist said in How to find symbols in extern code files or projects and get their "type" (code analysis library)?:
As I wrote, I currently don't know how the code model is implemented and if you can tap in it. However, you can check that, the code of Qt Creator is available.
Thanks for your reply.
I've checked QtCreator on Github and was able to find the clangcodemodel plugin here. Meanwhile I realized that QtCreator itself is made out of many plugins for each purpose.
Before I start to learn the whole thing for nothing, is it somehow possible to reach out to one of the QtCreator maintainers/devs, some person who knows all the internal QtCreator things well, so he/she can confirm or contradict that it's doable?!
Because it feels like I can look at this code for month without finding out if it's worth to create a QtCreator plugin for my use case.
A clear "yes" or "no, because...." would help a lot.PS:
While scrolling through the GitHub folders I saw a plugin called "cppcheck" in there. Stumbled upon this "software" during my research on how to analyse and extract stuff from C++ code.
Don't know exactly what the purpose of this is and if it's used by clang or maybe can be used in my case instead of clang?!
Will continue to research :) -
@Qtpp said in How to find symbols in extern code files or projects and get their "type" (code analysis library)?:
is it somehow possible to reach out to one of the QtCreator maintainers/devs
-
@SGaist said in How to find symbols in extern code files or projects and get their "type" (code analysis library)?:
Libclang is just a library.
Made some progress in this case.
However most guides describe how to extend clang through your own custom written clang-tools (which requires re-compiling clang every time)...
I was thinking more about a standalone program which links (maybe statically) clang and accesses already existing API/tools like- https://clang.llvm.org/docs/LibASTMatchersTutorial.html
- https://clang.llvm.org/docs/LibASTMatchers.html
This must also be possible right? Did not find anything like that as most guides show how to write clang "plugins"?!
-
cppcheck is a static analyzer however I don't know how it's currently implemented.
As for writing an application with libclang, I think their tutorial should get you started.
-
clazy is also using libclang