Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. How to find symbols in extern code files or projects and get their "type" (code analysis library)?

How to find symbols in extern code files or projects and get their "type" (code analysis library)?

Scheduled Pinned Locked Moved Unsolved C++ Gurus
c++ symbolscode analysislibrary
13 Posts 5 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 3 Jun 2024, 19:41 last edited by
    #4

    Hi,

    Are you trying to reimplement something like the clang code model from Qt Creator ?

    Interested in AI ? www.idiap.ch
    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

    Q 1 Reply Last reply 3 Jun 2024, 23:52
    0
    • S SGaist
      3 Jun 2024, 19:41

      Hi,

      Are you trying to reimplement something like the clang code model from Qt Creator ?

      Q Offline
      Q Offline
      Qtpp
      wrote on 3 Jun 2024, 23:52 last edited by
      #5

      @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?

      1 Reply Last reply
      0
      • S Offline
        S Offline
        SGaist
        Lifetime Qt Champion
        wrote on 6 Jun 2024, 06:29 last edited by
        #6

        From your description, it looks like you are after libclang to parse the code and extract information.

        I don't think the code model exposes stuff but you should check the sources to confirm.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        Q 1 Reply Last reply 7 Jun 2024, 18:46
        1
        • S SGaist
          6 Jun 2024, 06:29

          From your description, it looks like you are after libclang to parse the code and extract information.

          I don't think the code model exposes stuff but you should check the sources to confirm.

          Q Offline
          Q Offline
          Qtpp
          wrote on 7 Jun 2024, 18:46 last edited by
          #7

          @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 :/

          1 Reply Last reply
          0
          • S Offline
            S Offline
            SGaist
            Lifetime Qt Champion
            wrote on 7 Jun 2024, 18:53 last edited by
            #8

            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.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            Q 2 Replies Last reply 13 Jun 2024, 00:51
            0
            • S SGaist
              7 Jun 2024, 18:53

              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.

              Q Offline
              Q Offline
              Qtpp
              wrote on 13 Jun 2024, 00:51 last edited by Qtpp
              #9

              @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 :)

              J 1 Reply Last reply 14 Jun 2024, 05:47
              0
              • Q Qtpp
                13 Jun 2024, 00:51

                @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 :)

                J Offline
                J Offline
                jsulm
                Lifetime Qt Champion
                wrote on 14 Jun 2024, 05:47 last edited by
                #10

                @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

                https://lists.qt-project.org/listinfo/qt-creator

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • S SGaist
                  7 Jun 2024, 18:53

                  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.

                  Q Offline
                  Q Offline
                  Qtpp
                  wrote on 28 Feb 2025, 17:31 last edited by
                  #11

                  @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"?!

                  1 Reply Last reply
                  0
                  • S Offline
                    S Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on 28 Feb 2025, 20:01 last edited by
                    #12

                    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.

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    1
                    • Christian EhrlicherC Online
                      Christian EhrlicherC Online
                      Christian Ehrlicher
                      Lifetime Qt Champion
                      wrote on 28 Feb 2025, 20:34 last edited by
                      #13

                      clazy is also using libclang

                      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                      Visit the Qt Academy at https://academy.qt.io/catalog

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved