1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
4 | ** All rights reserved.
|
---|
5 | ** Contact: Nokia Corporation ([email protected])
|
---|
6 | **
|
---|
7 | ** This file is part of the documentation of the Qt Toolkit.
|
---|
8 | **
|
---|
9 | ** $QT_BEGIN_LICENSE:FDL$
|
---|
10 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in a
|
---|
14 | ** written agreement between you and Nokia.
|
---|
15 | **
|
---|
16 | ** GNU Free Documentation License
|
---|
17 | ** Alternatively, this file may be used under the terms of the GNU Free
|
---|
18 | ** Documentation License version 1.3 as published by the Free Software
|
---|
19 | ** Foundation and appearing in the file included in the packaging of this
|
---|
20 | ** file.
|
---|
21 | **
|
---|
22 | ** If you have questions regarding the use of this file, please contact
|
---|
23 | ** Nokia at [email protected].
|
---|
24 | ** $QT_END_LICENSE$
|
---|
25 | **
|
---|
26 | ****************************************************************************/
|
---|
27 |
|
---|
28 | /*!
|
---|
29 | \example xmlpatterns/xquery/globalVariables
|
---|
30 | \title C++ Source Code Analyzer Example
|
---|
31 |
|
---|
32 | This example uses XQuery and the \c xmlpatterns command line utility to
|
---|
33 | query C++ source code.
|
---|
34 |
|
---|
35 | \tableofcontents
|
---|
36 |
|
---|
37 | \section1 Introduction
|
---|
38 |
|
---|
39 | Suppose we want to analyze C++ source code to find coding standard
|
---|
40 | violations and instances of bad or inefficient patterns. We can do
|
---|
41 | it using the common searching and pattern matching utilities to
|
---|
42 | process the C++ files (e.g., \c{grep}, \c{sed}, and \c{awk}). Now
|
---|
43 | we can also use XQuery with the QtXmlPatterns module.
|
---|
44 |
|
---|
45 | An extension to the \c{g++} open source C++ compiler
|
---|
46 | (\l{http://public.kitware.com/GCC_XML/HTML/Index.html} {GCC-XML})
|
---|
47 | generates an XML description of C++ source code declarations. This
|
---|
48 | XML description can then be processed by QtXmlPatterns using
|
---|
49 | XQueries to navigate the XML description of the C++ source and
|
---|
50 | produce a report. Consider the problem of finding mutable global
|
---|
51 | variables:
|
---|
52 |
|
---|
53 | \section2 Reporting Uses of Mutable Global Variables
|
---|
54 |
|
---|
55 | Suppose we want to introduce threading to a C++ application that
|
---|
56 | was originally written without threading. In a threaded program,
|
---|
57 | mutable global variables can cause bugs, because one thread might
|
---|
58 | change a global variable that other threads are reading, or two
|
---|
59 | threads might try to set the same global variable. So when
|
---|
60 | converting our program to use threading, one of the things we must
|
---|
|
---|