creator-clang-codemodel.qdoc 6.46 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/****************************************************************************
**
** Copyright (c) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator
**
**
** GNU Free Documentation License
**
** Alternatively, this file may be used under the terms of the GNU Free
** Documentation License version 1.3 as published by the Free Software
** Foundation and appearing in the file included in the packaging of this
** file.
**
**
****************************************************************************/

// **********************************************************************
// NOTE: the sections are not ordered by their logical order to avoid
// reshuffling the file each time the index order changes (i.e., often).
// Run the fixnavi.pl script to adjust the links to the index order.
// **********************************************************************

/*!
26
    \contentspage {Qt Creator Manual}
27
28
29
30
31
32
33
34
35
36
37
38
    \previouspage creator-diff-editor.html
    \page creator-clang-codemodel.html
    \nextpage creator-finding-overview.html

    \title Parsing C++ Files

    The \e {code model} is the part of an IDE that understands the language you
    are using to write your application. It is the framework that allows \QC
    to provide the following services:

    \list

39
        \li \l{Completing Code}{Code completion}
40

41
        \li Syntactic and \l{Semantic Highlighting}{semantic highlighting}
42

43
44
45
        \li Navigating in the code by using the \l{Searching with the Locator}
            {locator}, \l{Moving to Symbol Definition or Declaration}
            {following symbols}, and so on
46

47
48
        \li Inspecting code by using the \l{Browsing Project Contents}
            {class browser}, the \l{Viewing QML Types}{outline}, and so on
49

50
        \li Diagnostics and \l{Viewing Function Tooltips}{tooltips}
51

52
        \li \l{Finding Symbols}{Finding and renaming symbols}
53

54
        \li \l{Applying Refactoring Actions}{Refactoring actions}
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185

    \endlist

    An IDE needs a parser for the language and the semantic
    analyzes. The only difference between a code model and a compiler is that a
    code model does not generate an executable.

    As \l{http://clang.llvm.org/}{Clang} is a compiler, as well as a code model,
    it provides accurate information. The feedback you get through warning and
    error markers is the same as the compiler will give you, not an incomplete
    set or a close approximation, as when using the built-in \QC code model.
    Clang focuses on detailed information for diagnostics, which is really
    useful if the code contains typos, for example.

    Also, Clang already supports C++98/03, C89 and C99, Objective-C
    (and Objective-C++), and C++11 support is in active development.

    On the downside, for large projects using Clang as code model is slower than
    using the built-in code model. Clang does not need to generate object files,
    but it still needs to parse and analyze the source files. For small projects
    that only use STL, this is relatively fast. But for larger projects that
    include several files, processing a single file and all the included files
    can take a while.

    To make parsing faster, pre-compiled headers are ignored by default. You can
    specify that Clang processes them in \gui {Code Model} options.

    The following services are currently implemented in the experimental Clang
    code model plugin:

    \list

        \li Highlighting
        \li Code completion

    \endlist

    To use the plugin, you must build it and configure it in \QC.

    \section1 Building Clang Code Model Plugin

    \list 1

        \li To build the Clang code model plugin, you must acquire Clang and
            LLVM in one of the following ways:

            \list

                \li Build optimized versions of LLVM and Clang, as instructed in
                    \l{http://clang.llvm.org/get_started.html}
                    {Getting Started: Building and Running Clang}.

                    The instructions describe how to build debug versions. To
                    build optimized versions, enter the following command
                    instead of just \c make:

                    \c{make ENABLE_OPTIMIZED=1}

                    For information about Git mirrors, see
                    \l{http://llvm.org/docs/GettingStarted.html#git-mirror}
                    {Git Mirror}.

                    Install the built versions by entering the following
                    command:

                    \c{make install}

                \li Download and install LLVM from the
                    \l{http://llvm.org/releases/}{LLVM Download Page} or
                    \l{http://llvm.org/builds/}{LLVM Snapshot Builds}.

                \li Use the package manager of your system.

            \endlist

        \li Set LLVM_INSTALL_DIR to point to the installation directory
            of LLVM either as part of the build environment or pass it directly
            to qmake when you build \QC.

            The following are examples of the LLVM_INSTALL_DIR values to use
            depending on the installation method:

            \list

                \li Installed via package manager on Linux:

                    \c {LLVM_INSTALL_DIR=/usr/lib/llvm-3.4}

                \li Manually built on Unix in release mode:

                    \c {LLVM_INSTALL_DIR=$HOME/llvm-build/Release+Asserts}

                \li Installed from a snapshot on Windows:

                    \c {LLVM_INSTALL_DIR=C:\llvm}

            \endlist

            The following messages indicate that the Clang code model plugin is
            built:

            \list

                \li \c {Project MESSAGE: Building ClangCodeModel plugin with Clang from /usr/lib/llvm-3.4}
                \li \c {Project MESSAGE: INCLUDEPATH += /usr/lib/llvm-3.4/include}
                \li \c {Project MESSAGE: LIBS += -L/usr/lib/llvm-3.4/lib -lclang}

            \endlist

    \li Rebuild \QC.

    \endlist

    \section1 Configuring Clang Code Model Plugin

    \list 1

        \li Select \gui Help > \gui {About Plugins} > \gui {C++} >
            \gui ClangCodeModel to enable the plugin.

        \li Restart \QC to be able to use the plugin.

        \li Select \gui Tools > \gui Options > \gui {C++} > \gui {Code Model},
            and select the parser to use for files of each type.

        \li To process pre-compiled headers before processing any project files,
            deselect the \gui {Ignore pre-compiled headers} check box.

    \endlist

*/