Qt wiki will be updated on October 12th 2023 starting at 11:30 AM (EEST) and the maintenance will last around 2-3 hours. During the maintenance the site will be unavailable.

Qt Creator DevIntro CppSupport

From Qt Wiki
Revision as of 16:43, 14 January 2015 by Maintenance script (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<BIG RED>CAUTION: This page is no yet reviewed by the C++ Support maintainer.</BIG RED>

C++ Support in Qt Creator

This page is meant as an introduction / collection of hints for developers wanting to help with the C++ Support in Qt Creator.

Here is a filter showing all unresolved C++ bugs: Creator / C++ > All unresolved bugs [bugreports.qt.io]

Please read the mailing list post Editors/Code-models: new year’s resolutions [lists.qt.io] .

Hint: The paths on this page are relative to the top level directory of Qt Creator.

Related source directories and classes

The sources for the C++ Support are spread over several directories. To give you a quick overview, here are some important source directories and prominent classes you will find in them.

Libraries

  • src/libs/3rdparty/cplusplus – C++ Frontend
    Token, Lexer, Parser, Bind, Control, <span class="caps">AST</span>, <span class="caps">ASTV</span>isitor, Scope, Type, TranslationUnit
    
  • src/libs/cplusplus
    Preprocessor, Snapshot, LookupContext, Document, Macro, FindUsages
    

Plugins

  • src/plugins/cppeditor – C++ Editor
    CppPlugin, CppClass, CppFunction, CppInclude, SemanticHighlighter
    
  • src/plugins/cpptools – C++ Tools
    CppToolsPlugin, FindInClass, FindLocalSymbols, FindFunctionDefinition, IndexingSupport, CheckSymbols, CppCompletionAssistProvider, CppPreprocessor, CppModelManager, CppLocatorFilter, SemanticInfo
    

General hints

  • Care about the tests – See also section about tests below.
    You can learn a lot from tests. Please run them. Please fix them. Please add new tests for new functionality.
  • Debugging / Remove optimization before debugging
    src/libs/cplusplus/cplusplus.pro: Comment out
    <span class="caps">QMAKE</span>_CXXFLAGS_DEBUG += -O2
    
    for proper debugging.
  • Debugging / Enable parser tracing
    src/libs/3rdparty/cplusplus/Parser.cpp: Comment out
    #define <span class="caps">CPLUSPLUS</span>_NO_DEBUG_RULE
    
    to get output like:
  • Debugging / Enable preprocessor tracing
    Set the environment variable
    <span class="caps">QTCREATOR</span>_DUMP_FILENAME_WHILE_PARSING
    
    (evaluated at run time) to get output like:
  • Debugging / Enable dumping the ModelManager configuration
    Set the environment variable
    <span class="caps">QTCREATOR</span>_DUMP_PROJECT_INFO
    
    (evaluated at run time) to get debug statements regarding the detected language, C++11 detection, Qt Version, precompiled header, defines, includes, frameworkPaths, sources. The merged include paths, merged framework paths and merged defined macros will also be printed. In total you will get quite much output. This configuration changes on e.g. switching Kits.
  • Use the provided tools – See also section about tools below.

Tools used for development

There is a number of tools you can and should make use of. They should work on all major platforms (GNU/Linux, Mac, Windows).

  • cplusplus-mkvisitor – Creates an AST visitor class.
  • cplusplus-update-frontend – Updates sources in the parser after modifying AST.h.
  • cplusplus-ast2png – Visualizes AST and symbol hierarchy by generating PNG files for given code.
  • cplusplus-frontend – Parses given files (parser as standalone tool).

cplusplus-mkvisitor

Source directory: src/tools/cplusplus-mkvisitor

Usage & Purpose:

Example Usage:

cplusplus-update-frontend

Source directory: src/tools/cplusplus-update-frontend

Usage & Purpose:

Example Usage:

cplusplus-ast2png

Source directory: tests/tools/cplusplus-ast2png

Usage & Purpose:

dot

comes with graphviz [graphviz.org]. On Ubuntu you have to install the package graphviz.

Note also that processing might fail for too big input files. Generating an image (dot) is a cpu and memory intensive task. This tool is meant for small snippets, therefore the processing of input from stdin.

Example Usage:

cplusplus-frontend

Source directory: tests/manual/cplusplus-frontend

Usage & Purpose:

Example Usage:

Tests

“Plugin” auto tests

These tests are in src/plugins/cpptools/*_test.cpp and src/plugins/cppeditor/*_test.cpp. They are included in the plugin itself, since they can’t be separated easily.

Make sure that WITH_TESTS is defined (currently this is set for a debug build). Otherwise Qt Creator will not understand the “-test” option.

Run the tests with:

$ ./qtcreator -test CppTools -test CppEditor

Qt Creator will start, execute all tests and quit. Watch the output.

“External” auto tests

You can find these tests in tests/auto/cplusplus. They are the ‘separable’ tests.

Just build and run the relevant test project.

If you’re using shadow builds, make sure to place the build directory accordingly to the source tree inside the build directory of Qt Creator since the tests referene libCPlusPlus.so.1 from Qt Creator. If you run the tests from Qt Creator, you probably want to add the Qt Creator project as a dependency (Projects, <test project>, Dependencies).

Running all tests

  1. (Open &) Build the project tests/auto/cplusplus.pro either in-source or as shadow-build.
  2. Run
    $ make check
    
    to run all tests. If a test fails, subsequent tests will not be executed, therefore you might want to add “-i” to the command for ignoring failures. If you run the tests from Qt Creator, you probably want to add a custom run configuration calling these commands.

Manual tests

Instructions for the manual tests should be published soon.

Categories: