PDA

View Full Version : Qt C++ Source Code Analyzer Example



Mike_m
7th July 2017, 12:31
Qt 5.9 has "C++ Source Code Analyzer" Example. It has following project file:

12510

Added after 6 minutes:

Following is help information about this Source Code Analyzer Example:

12511

Added after 11 minutes:

I built and ran this example and got following GUI window:

12512

Added after 6 minutes:

Why this example program is saying: "Could not find the executable, please specify one."?

How to use this example program please?

I am expecting this program to be able to open a C++ file.

What to type in the "Command line arguments" text box?
Thank you for any information about how to use this example program please?

Added after 6 minutes:

Is there a C++ source file(s) this example file is based on?
What is meant by "TEMPLATE = aux" in this example program's xquery.pro file?

How to look at this example program's C++ file?
I want to look at its C++ file and modify it to display all assignment statements in an input C++ text file.

Is it possible to look at the C++ file of this example program please?
Thanks

d_stranz
7th July 2017, 23:40
The "C++ Source Code Analyzer" example does not build a program. It provides an xquery script that will take the output of the gcc source code analysis XML file and transform it into XML for display in a browser. The dialog box you see is displayed by Qt Creator when it can't find an executable for the project you are trying to run.

Read all of the "C++ Source Code Analyzer Example" help page you linked to. You need to get the GCC-XML tool from Kitware that is linked to in the help text. After you install it, you need to run it on your source file:



gccxml [options] <input-file> -fxml=<output-file>


as explained on the GCC-XML page (https://gccxml.github.io/HTML/Running.html).

Next, you need to run the xmlpatterns program (part of the Qt distribution) on the output XML file:



xmlpatterns reportGlobals.xq -param fileToOpen=<output-file>.gccxml -output <html-file>.html


The xquery in this case is "reportglobals.xq", which will generate a report of all the global declarations in your source code file. This xquery script is in the "globalvariables" subdirectory of the xquery example project.

If you want any other type of report, you will have to write your own XQuery script to generate it. That's why this is an example, not a complete source code analyzer.

If you want a real source code analyzer, then you will have to use Google to find one.

Mike_m
8th July 2017, 02:34
Hello d_stranz,
Thank you very much for excellent information about "C++ Source Code Analyzer" Qt example.

I do not need off-the shelf source code analyzer (unless it is a small C++ program less than 1000 or 2000 line and its source code is open source).
I need this example kind of Qt program so that I can modify it to produce:
1. List of global variable names of input C++ file and their C++ types
2. List of local variable names and their C++ types
3. List of Assignment statements in each function of the input C++ file
4. List of Function call statements in the input C++ file.

Using your inputs, I will read and understand the information you have given and develop the example so that it outputs above four kinds of data to an output text file.

Once I get the above four kinds of information, I need to develop additional features to this example program.

If there is a similar Qt example that is developed using C++ only, I would have preferred.

Again, thank you very much for your detailed reply.

d_stranz
8th July 2017, 17:56
You will have to modify the "reportglobals.xq" file (or better, write a new xquery file using that as a start) to identify and report the additional features you want. I don't know enough about XQuery to tell you what to do; you'll have to go to the WW3 web site, read the XQuery documentation, and try to teach yourself.

You are also going to probably have to configure the options for GCC-XML so they match what your compiler does when it builds your source code. For example, any #define / #ifdef preprocessor options have to work the same way. It also has to be able to find all of the system #include files used by your compiler so it finds the definitions for system-level classes and namespaces (like std:: ).

GCC-XML does not handle code beyond C++99, so any C++11 or later code won't work. For that you will need to use the CastXML tool that has replaced GCC-XML. I would advise you to start with CastXML instead of GCC-XML.

Personally, I think you would be better off looking around for a real source code analyzer rather than trying to learn all of these new technologies and writing your own.