author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Mon, 04 Oct 2010 01:19:32 +0300 | |
changeset 37 | 758a864f9613 |
parent 30 | 5dc02b23752f |
permissions | -rw-r--r-- |
0 | 1 |
/**************************************************************************** |
2 |
** |
|
18
2f34d5167611
Revision: 201011
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
3
diff
changeset
|
3 |
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 4 |
** All rights reserved. |
5 |
** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 |
** |
|
7 |
** This file is part of the tools applications of the Qt Toolkit. |
|
8 |
** |
|
9 |
** $QT_BEGIN_LICENSE:LGPL$ |
|
10 |
** No Commercial Usage |
|
11 |
** This file contains pre-release code and may not be distributed. |
|
12 |
** You may use this file in accordance with the terms and conditions |
|
13 |
** contained in the Technology Preview License Agreement accompanying |
|
14 |
** this package. |
|
15 |
** |
|
16 |
** GNU Lesser General Public License Usage |
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 |
** General Public License version 2.1 as published by the Free Software |
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 |
** packaging of this file. Please review the following information to |
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 |
** |
|
24 |
** In addition, as a special exception, Nokia gives you certain additional |
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 |
** |
|
28 |
** If you have questions regarding the use of this file, please contact |
|
29 |
** Nokia at qt-info@nokia.com. |
|
30 |
** |
|
31 |
** |
|
32 |
** |
|
33 |
** |
|
34 |
** |
|
35 |
** |
|
36 |
** |
|
37 |
** |
|
38 |
** $QT_END_LICENSE$ |
|
39 |
** |
|
40 |
****************************************************************************/ |
|
41 |
||
42 |
/* |
|
43 |
generator.cpp |
|
44 |
*/ |
|
45 |
#include <qdir.h> |
|
46 |
#include <qdebug.h> |
|
47 |
#include "codemarker.h" |
|
48 |
#include "config.h" |
|
49 |
#include "doc.h" |
|
50 |
#include "editdistance.h" |
|
51 |
#include "generator.h" |
|
52 |
#include "node.h" |
|
53 |
#include "openedlist.h" |
|
54 |
#include "quoter.h" |
|
55 |
#include "separator.h" |
|
56 |
#include "tokenizer.h" |
|
57 |
||
58 |
QT_BEGIN_NAMESPACE |
|
59 |
||
60 |
QList<Generator *> Generator::generators; |
|
61 |
QMap<QString, QMap<QString, QString> > Generator::fmtLeftMaps; |
|
62 |
QMap<QString, QMap<QString, QString> > Generator::fmtRightMaps; |
|
63 |
QMap<QString, QStringList> Generator::imgFileExts; |
|
64 |
QSet<QString> Generator::outputFormats; |
|
65 |
QStringList Generator::imageFiles; |
|
66 |
QStringList Generator::imageDirs; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
67 |
QStringList Generator::exampleDirs; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
68 |
QStringList Generator::exampleImgExts; |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
69 |
QStringList Generator::scriptFiles; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
70 |
QStringList Generator::scriptDirs; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
71 |
QStringList Generator::styleFiles; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
72 |
QStringList Generator::styleDirs; |
0 | 73 |
QString Generator::outDir; |
74 |
QString Generator::project; |
|
75 |
||
76 |
static void singularPlural(Text& text, const NodeList& nodes) |
|
77 |
{ |
|
78 |
if (nodes.count() == 1) |
|
79 |
text << " is"; |
|
80 |
else |
|
81 |
text << " are"; |
|
82 |
} |
|
83 |
||
84 |
Generator::Generator() |
|
85 |
: amp("&"), |
|
86 |
lt("<"), |
|
87 |
gt(">"), |
|
88 |
quot("""), |
|
89 |
tag("</?@[^>]*>") |
|
90 |
{ |
|
91 |
generators.prepend(this); |
|
92 |
} |
|
93 |
||
94 |
Generator::~Generator() |
|
95 |
{ |
|
96 |
generators.removeAll(this); |
|
97 |
} |
|
98 |
||
99 |
void Generator::initializeGenerator(const Config & /* config */) |
|
100 |
{ |
|
101 |
} |
|
102 |
||
103 |
void Generator::terminateGenerator() |
|
104 |
{ |
|
105 |
} |
|
106 |
||
107 |
void Generator::initialize(const Config &config) |
|
108 |
{ |
|
109 |
outputFormats = config.getStringSet(CONFIG_OUTPUTFORMATS); |
|
110 |
if (!outputFormats.isEmpty()) { |
|
111 |
outDir = config.getString(CONFIG_OUTPUTDIR); |
|
112 |
if (outDir.isEmpty()) |
|
113 |
config.lastLocation().fatal(tr("No output directory specified in configuration file")); |
|
114 |
||
115 |
QDir dirInfo; |
|
116 |
if (dirInfo.exists(outDir)) { |
|
117 |
if (!Config::removeDirContents(outDir)) |
|
118 |
config.lastLocation().error(tr("Cannot empty output directory '%1'").arg(outDir)); |
|
119 |
} |
|
120 |
else { |
|
121 |
if (!dirInfo.mkpath(outDir)) |
|
122 |
config.lastLocation().fatal(tr("Cannot create output directory '%1'").arg(outDir)); |
|
123 |
} |
|
124 |
||
125 |
if (!dirInfo.mkdir(outDir + "/images")) |
|
126 |
config.lastLocation().fatal(tr("Cannot create output directory '%1'") |
|
127 |
.arg(outDir + "/images")); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
128 |
if (!dirInfo.mkdir(outDir + "/images/used-in-examples")) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
129 |
config.lastLocation().fatal(tr("Cannot create output directory '%1'") |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
130 |
.arg(outDir + "/images/used-in-examples")); |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
131 |
if (!dirInfo.mkdir(outDir + "/scripts")) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
132 |
config.lastLocation().fatal(tr("Cannot create output directory '%1'") |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
133 |
.arg(outDir + "/scripts")); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
134 |
if (!dirInfo.mkdir(outDir + "/style")) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
135 |
config.lastLocation().fatal(tr("Cannot create output directory '%1'") |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
136 |
.arg(outDir + "/style")); |
0 | 137 |
} |
138 |
||
139 |
imageFiles = config.getStringList(CONFIG_IMAGES); |
|
140 |
imageDirs = config.getStringList(CONFIG_IMAGEDIRS); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
141 |
scriptFiles = config.getStringList(CONFIG_SCRIPTS); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
142 |
scriptDirs = config.getStringList(CONFIG_SCRIPTDIRS); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
143 |
styleFiles = config.getStringList(CONFIG_STYLES); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
144 |
styleDirs = config.getStringList(CONFIG_STYLEDIRS); |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
145 |
exampleDirs = config.getStringList(CONFIG_EXAMPLEDIRS); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
146 |
exampleImgExts = config.getStringList(CONFIG_EXAMPLES + Config::dot + |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
147 |
CONFIG_IMAGEEXTENSIONS); |
0 | 148 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
149 |
QString imagesDotFileExtensions = |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
150 |
CONFIG_IMAGES + Config::dot + CONFIG_FILEEXTENSIONS; |
0 | 151 |
QSet<QString> formats = config.subVars(imagesDotFileExtensions); |
152 |
QSet<QString>::ConstIterator f = formats.begin(); |
|
153 |
while (f != formats.end()) { |
|
154 |
imgFileExts[*f] = config.getStringList(imagesDotFileExtensions + |
|
155 |
Config::dot + *f); |
|
156 |
++f; |
|
157 |
} |
|
158 |
||
159 |
QList<Generator *>::ConstIterator g = generators.begin(); |
|
160 |
while (g != generators.end()) { |
|
161 |
if (outputFormats.contains((*g)->format())) { |
|
162 |
(*g)->initializeGenerator(config); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
163 |
QStringList extraImages = |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
164 |
config.getStringList(CONFIG_EXTRAIMAGES+Config::dot+(*g)->format()); |
0 | 165 |
QStringList::ConstIterator e = extraImages.begin(); |
166 |
while (e != extraImages.end()) { |
|
167 |
QString userFriendlyFilePath; |
|
168 |
QString filePath = Config::findFile(config.lastLocation(), |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
169 |
imageFiles, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
170 |
imageDirs, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
171 |
*e, |
0 | 172 |
imgFileExts[(*g)->format()], |
173 |
userFriendlyFilePath); |
|
174 |
if (!filePath.isEmpty()) |
|
175 |
Config::copyFile(config.lastLocation(), |
|
176 |
filePath, |
|
177 |
userFriendlyFilePath, |
|
178 |
(*g)->outputDir() + |
|
179 |
"/images"); |
|
180 |
++e; |
|
181 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
182 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
183 |
QStringList noExts; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
184 |
QStringList scripts = |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
185 |
config.getStringList(CONFIG_SCRIPTS+Config::dot+(*g)->format()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
186 |
e = scripts.begin(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
187 |
while (e != scripts.end()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
188 |
QString userFriendlyFilePath; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
189 |
QString filePath = Config::findFile(config.lastLocation(), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
190 |
scriptFiles, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
191 |
scriptDirs, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
192 |
*e, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
193 |
noExts, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
194 |
userFriendlyFilePath); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
195 |
if (!filePath.isEmpty()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
196 |
Config::copyFile(config.lastLocation(), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
197 |
filePath, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
198 |
userFriendlyFilePath, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
199 |
(*g)->outputDir() + |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
200 |
"/scripts"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
201 |
++e; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
202 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
203 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
204 |
QStringList styles = |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
205 |
config.getStringList(CONFIG_STYLES+Config::dot+(*g)->format()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
206 |
e = styles.begin(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
207 |
while (e != styles.end()) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
208 |
QString userFriendlyFilePath; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
209 |
QString filePath = Config::findFile(config.lastLocation(), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
210 |
styleFiles, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
211 |
styleDirs, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
212 |
*e, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
213 |
noExts, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
214 |
userFriendlyFilePath); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
215 |
if (!filePath.isEmpty()) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
216 |
Config::copyFile(config.lastLocation(), |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
217 |
filePath, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
218 |
userFriendlyFilePath, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
219 |
(*g)->outputDir() + |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
220 |
"/style"); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
221 |
++e; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
222 |
} |
0 | 223 |
} |
224 |
++g; |
|
225 |
} |
|
226 |
||
227 |
QRegExp secondParamAndAbove("[\2-\7]"); |
|
228 |
QSet<QString> formattingNames = config.subVars(CONFIG_FORMATTING); |
|
229 |
QSet<QString>::ConstIterator n = formattingNames.begin(); |
|
230 |
while (n != formattingNames.end()) { |
|
231 |
QString formattingDotName = CONFIG_FORMATTING + Config::dot + *n; |
|
232 |
||
233 |
QSet<QString> formats = config.subVars(formattingDotName); |
|
234 |
QSet<QString>::ConstIterator f = formats.begin(); |
|
235 |
while (f != formats.end()) { |
|
236 |
QString def = config.getString(formattingDotName + |
|
237 |
Config::dot + *f); |
|
238 |
if (!def.isEmpty()) { |
|
239 |
int numParams = Config::numParams(def); |
|
240 |
int numOccs = def.count("\1"); |
|
241 |
||
242 |
if (numParams != 1) { |
|
243 |
config.lastLocation().warning(tr("Formatting '%1' must " |
|
244 |
"have exactly one " |
|
245 |
"parameter (found %2)") |
|
246 |
.arg(*n).arg(numParams)); |
|
247 |
} |
|
248 |
else if (numOccs > 1) { |
|
249 |
config.lastLocation().fatal(tr("Formatting '%1' must " |
|
250 |
"contain exactly one " |
|
251 |
"occurrence of '\\1' " |
|
252 |
"(found %2)") |
|
253 |
.arg(*n).arg(numOccs)); |
|
254 |
} |
|
255 |
else { |
|
256 |
int paramPos = def.indexOf("\1"); |
|
257 |
fmtLeftMaps[*f].insert(*n, def.left(paramPos)); |
|
258 |
fmtRightMaps[*f].insert(*n, def.mid(paramPos + 1)); |
|
259 |
} |
|
260 |
} |
|
261 |
++f; |
|
262 |
} |
|
263 |
++n; |
|
264 |
} |
|
265 |
||
266 |
project = config.getString(CONFIG_PROJECT); |
|
267 |
} |
|
268 |
||
269 |
void Generator::terminate() |
|
270 |
{ |
|
271 |
QList<Generator *>::ConstIterator g = generators.begin(); |
|
272 |
while (g != generators.end()) { |
|
273 |
if (outputFormats.contains((*g)->format())) |
|
274 |
(*g)->terminateGenerator(); |
|
275 |
++g; |
|
276 |
} |
|
277 |
||
278 |
fmtLeftMaps.clear(); |
|
279 |
fmtRightMaps.clear(); |
|
280 |
imgFileExts.clear(); |
|
281 |
imageFiles.clear(); |
|
282 |
imageDirs.clear(); |
|
283 |
outDir = ""; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
284 |
QmlClassNode::clear(); |
0 | 285 |
} |
286 |
||
287 |
Generator *Generator::generatorForFormat(const QString& format) |
|
288 |
{ |
|
289 |
QList<Generator *>::ConstIterator g = generators.begin(); |
|
290 |
while (g != generators.end()) { |
|
291 |
if ((*g)->format() == format) |
|
292 |
return *g; |
|
293 |
++g; |
|
294 |
} |
|
295 |
return 0; |
|
296 |
} |
|
297 |
||
298 |
void Generator::startText(const Node * /* relative */, |
|
299 |
CodeMarker * /* marker */) |
|
300 |
{ |
|
301 |
} |
|
302 |
||
303 |
void Generator::endText(const Node * /* relative */, |
|
304 |
CodeMarker * /* marker */) |
|
305 |
{ |
|
306 |
} |
|
307 |
||
308 |
int Generator::generateAtom(const Atom * /* atom */, |
|
309 |
const Node * /* relative */, |
|
310 |
CodeMarker * /* marker */) |
|
311 |
{ |
|
312 |
return 0; |
|
313 |
} |
|
314 |
||
315 |
void Generator::generateClassLikeNode(const InnerNode * /* classe */, |
|
316 |
CodeMarker * /* marker */) |
|
317 |
{ |
|
318 |
} |
|
319 |
||
320 |
void Generator::generateFakeNode(const FakeNode * /* fake */, |
|
321 |
CodeMarker * /* marker */) |
|
322 |
{ |
|
323 |
} |
|
324 |
||
325 |
bool Generator::generateText(const Text& text, |
|
326 |
const Node *relative, |
|
327 |
CodeMarker *marker) |
|
328 |
{ |
|
329 |
if (text.firstAtom() != 0) { |
|
330 |
int numAtoms = 0; |
|
331 |
startText(relative, marker); |
|
332 |
generateAtomList(text.firstAtom(), |
|
333 |
relative, |
|
334 |
marker, |
|
335 |
true, |
|
336 |
numAtoms); |
|
337 |
endText(relative, marker); |
|
338 |
return true; |
|
339 |
} |
|
340 |
return false; |
|
341 |
} |
|
342 |
||
343 |
#ifdef QDOC_QML |
|
344 |
/*! |
|
345 |
Extract sections of markup text surrounded by \e qmltext |
|
346 |
and \e endqmltext and output them. |
|
347 |
*/ |
|
348 |
bool Generator::generateQmlText(const Text& text, |
|
349 |
const Node *relative, |
|
350 |
CodeMarker *marker, |
|
351 |
const QString& /* qmlName */ ) |
|
352 |
{ |
|
353 |
const Atom* atom = text.firstAtom(); |
|
354 |
if (atom == 0) |
|
355 |
return false; |
|
356 |
||
357 |
startText(relative, marker); |
|
358 |
while (atom) { |
|
359 |
if (atom->type() != Atom::QmlText) |
|
360 |
atom = atom->next(); |
|
361 |
else { |
|
362 |
atom = atom->next(); |
|
363 |
while (atom && (atom->type() != Atom::EndQmlText)) { |
|
364 |
int n = 1 + generateAtom(atom, relative, marker); |
|
365 |
while (n-- > 0) |
|
366 |
atom = atom->next(); |
|
367 |
} |
|
368 |
} |
|
369 |
} |
|
370 |
endText(relative, marker); |
|
371 |
return true; |
|
372 |
} |
|
373 |
#endif |
|
374 |
||
375 |
void Generator::generateBody(const Node *node, CodeMarker *marker) |
|
376 |
{ |
|
377 |
bool quiet = false; |
|
378 |
||
379 |
if (node->type() == Node::Function) { |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
380 |
#if 0 |
0 | 381 |
const FunctionNode *func = (const FunctionNode *) node; |
382 |
if (func->isOverload() && func->metaness() != FunctionNode::Ctor) |
|
383 |
generateOverload(node, marker); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
384 |
#endif |
0 | 385 |
} |
386 |
else if (node->type() == Node::Fake) { |
|
387 |
const FakeNode *fake = static_cast<const FakeNode *>(node); |
|
388 |
if (fake->subType() == Node::Example) |
|
389 |
generateExampleFiles(fake, marker); |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
390 |
else if ((fake->subType() == Node::File) || (fake->subType() == Node::Image)) |
0 | 391 |
quiet = true; |
392 |
} |
|
393 |
||
394 |
if (node->doc().isEmpty()) { |
|
395 |
if (!quiet && !node->isReimp()) // ### might be unnecessary |
|
396 |
node->location().warning(tr("No documentation for '%1'") |
|
397 |
.arg(marker->plainFullName(node))); |
|
398 |
} |
|
399 |
else { |
|
400 |
if (node->type() == Node::Function) { |
|
401 |
const FunctionNode *func = static_cast<const FunctionNode *>(node); |
|
402 |
if (func->reimplementedFrom() != 0) |
|
403 |
generateReimplementedFrom(func, marker); |
|
404 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
405 |
|
0 | 406 |
if (!generateText(node->doc().body(), node, marker)) |
407 |
if (node->isReimp()) |
|
408 |
return; |
|
409 |
||
410 |
if (node->type() == Node::Enum) { |
|
411 |
const EnumNode *enume = (const EnumNode *) node; |
|
412 |
||
413 |
QSet<QString> definedItems; |
|
414 |
QList<EnumItem>::ConstIterator it = enume->items().begin(); |
|
415 |
while (it != enume->items().end()) { |
|
416 |
definedItems.insert((*it).name()); |
|
417 |
++it; |
|
418 |
} |
|
419 |
||
420 |
QSet<QString> documentedItems = enume->doc().enumItemNames().toSet(); |
|
421 |
QSet<QString> allItems = definedItems + documentedItems; |
|
422 |
if (allItems.count() > definedItems.count() || |
|
423 |
allItems.count() > documentedItems.count()) { |
|
424 |
QSet<QString>::ConstIterator a = allItems.begin(); |
|
425 |
while (a != allItems.end()) { |
|
426 |
if (!definedItems.contains(*a)) { |
|
427 |
QString details; |
|
428 |
QString best = nearestName(*a, definedItems); |
|
429 |
if (!best.isEmpty() && !documentedItems.contains(best)) |
|
430 |
details = tr("Maybe you meant '%1'?").arg(best); |
|
431 |
||
432 |
node->doc().location().warning( |
|
433 |
tr("No such enum item '%1' in %2").arg(*a).arg(marker->plainFullName(node)), |
|
434 |
details); |
|
435 |
} |
|
436 |
else if (!documentedItems.contains(*a)) { |
|
437 |
node->doc().location().warning( |
|
438 |
tr("Undocumented enum item '%1' in %2").arg(*a).arg(marker->plainFullName(node))); |
|
439 |
} |
|
440 |
++a; |
|
441 |
} |
|
442 |
} |
|
443 |
} |
|
444 |
else if (node->type() == Node::Function) { |
|
445 |
const FunctionNode *func = static_cast<const FunctionNode *>(node); |
|
446 |
QSet<QString> definedParams; |
|
447 |
QList<Parameter>::ConstIterator p = func->parameters().begin(); |
|
448 |
while (p != func->parameters().end()) { |
|
449 |
if ((*p).name().isEmpty() && (*p).leftType() != QLatin1String("...") |
|
450 |
&& func->name() != QLatin1String("operator++") |
|
451 |
&& func->name() != QLatin1String("operator--")) { |
|
452 |
node->doc().location().warning(tr("Missing parameter name")); |
|
453 |
} |
|
454 |
else { |
|
455 |
definedParams.insert((*p).name()); |
|
456 |
} |
|
457 |
++p; |
|
458 |
} |
|
459 |
||
460 |
QSet<QString> documentedParams = func->doc().parameterNames(); |
|
461 |
QSet<QString> allParams = definedParams + documentedParams; |
|
462 |
if (allParams.count() > definedParams.count() |
|
463 |
|| allParams.count() > documentedParams.count()) { |
|
464 |
QSet<QString>::ConstIterator a = allParams.begin(); |
|
465 |
while (a != allParams.end()) { |
|
466 |
if (!definedParams.contains(*a)) { |
|
467 |
QString details; |
|
468 |
QString best = nearestName(*a, definedParams); |
|
469 |
if (!best.isEmpty()) |
|
470 |
details = tr("Maybe you meant '%1'?").arg(best); |
|
471 |
||
472 |
node->doc().location().warning( |
|
473 |
tr("No such parameter '%1' in %2").arg(*a).arg(marker->plainFullName(node)), |
|
474 |
details); |
|
475 |
} |
|
476 |
else if (!(*a).isEmpty() && !documentedParams.contains(*a)) { |
|
477 |
bool needWarning = (func->status() > Node::Obsolete); |
|
478 |
if (func->overloadNumber() > 1) { |
|
479 |
FunctionNode *primaryFunc = |
|
480 |
func->parent()->findFunctionNode(func->name()); |
|
481 |
if (primaryFunc) { |
|
482 |
foreach (const Parameter ¶m, |
|
483 |
primaryFunc->parameters()) { |
|
484 |
if (param.name() == *a) { |
|
485 |
needWarning = false; |
|
486 |
break; |
|
487 |
} |
|
488 |
} |
|
489 |
} |
|
490 |
} |
|
491 |
if (needWarning && !func->isReimp()) |
|
492 |
node->doc().location().warning( |
|
493 |
tr("Undocumented parameter '%1' in %2") |
|
494 |
.arg(*a).arg(marker->plainFullName(node))); |
|
495 |
} |
|
496 |
++a; |
|
497 |
} |
|
498 |
} |
|
499 |
/* Something like this return value check should be implemented at some point. */ |
|
500 |
if (func->status() > Node::Obsolete && func->returnType() == "bool" |
|
501 |
&& func->reimplementedFrom() == 0 && !func->isOverload()) { |
|
502 |
QString body = func->doc().body().toString(); |
|
503 |
if (!body.contains("return", Qt::CaseInsensitive)) |
|
504 |
node->doc().location().warning(tr("Undocumented return value")); |
|
505 |
} |
|
506 |
#if 0 |
|
507 |
// Now we put this at the top, before the other text. |
|
508 |
if (func->reimplementedFrom() != 0) |
|
509 |
generateReimplementedFrom(func, marker); |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
510 |
#endif |
0 | 511 |
} |
512 |
} |
|
513 |
||
514 |
if (node->type() == Node::Fake) { |
|
515 |
const FakeNode *fake = static_cast<const FakeNode *>(node); |
|
516 |
if (fake->subType() == Node::File) { |
|
517 |
Text text; |
|
518 |
Quoter quoter; |
|
519 |
Doc::quoteFromFile(fake->doc().location(), quoter, fake->name()); |
|
520 |
QString code = quoter.quoteTo(fake->location(), "", ""); |
|
521 |
text << Atom(Atom::Code, code); |
|
522 |
generateText(text, fake, marker); |
|
523 |
} |
|
524 |
} |
|
525 |
} |
|
526 |
||
527 |
void Generator::generateAlsoList(const Node *node, CodeMarker *marker) |
|
528 |
{ |
|
529 |
QList<Text> alsoList = node->doc().alsoList(); |
|
530 |
supplementAlsoList(node, alsoList); |
|
531 |
||
532 |
if (!alsoList.isEmpty()) { |
|
533 |
Text text; |
|
534 |
text << Atom::ParaLeft << "See also "; |
|
535 |
||
536 |
for (int i = 0; i < alsoList.size(); ++i) |
|
537 |
text << alsoList.at(i) << separator(i, alsoList.size()); |
|
538 |
||
539 |
text << Atom::ParaRight; |
|
540 |
generateText(text, node, marker); |
|
541 |
} |
|
542 |
} |
|
543 |
||
544 |
void Generator::generateInherits(const ClassNode *classe, CodeMarker *marker) |
|
545 |
{ |
|
546 |
QList<RelatedClass>::ConstIterator r; |
|
547 |
int index; |
|
548 |
||
549 |
if (!classe->baseClasses().isEmpty()) { |
|
550 |
Text text; |
|
551 |
text << Atom::ParaLeft << "Inherits "; |
|
552 |
||
553 |
r = classe->baseClasses().begin(); |
|
554 |
index = 0; |
|
555 |
while (r != classe->baseClasses().end()) { |
|
556 |
text << Atom(Atom::LinkNode, CodeMarker::stringForNode((*r).node)) |
|
557 |
<< Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) |
|
558 |
<< Atom(Atom::String, (*r).dataTypeWithTemplateArgs) |
|
559 |
<< Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK); |
|
560 |
||
561 |
if ((*r).access == Node::Protected) { |
|
562 |
text << " (protected)"; |
|
563 |
} |
|
564 |
else if ((*r).access == Node::Private) { |
|
565 |
text << " (private)"; |
|
566 |
} |
|
567 |
text << separator(index++, classe->baseClasses().count()); |
|
568 |
++r; |
|
569 |
} |
|
570 |
text << Atom::ParaRight; |
|
571 |
generateText(text, classe, marker); |
|
572 |
} |
|
573 |
} |
|
574 |
||
575 |
#ifdef QDOC_QML |
|
576 |
/*! |
|
577 |
*/ |
|
578 |
void Generator::generateQmlInherits(const QmlClassNode* , CodeMarker* ) |
|
579 |
{ |
|
580 |
// stub. |
|
581 |
} |
|
582 |
#endif |
|
583 |
||
584 |
void Generator::generateInheritedBy(const ClassNode *classe, |
|
585 |
CodeMarker *marker) |
|
586 |
{ |
|
587 |
if (!classe->derivedClasses().isEmpty()) { |
|
588 |
Text text; |
|
589 |
text << Atom::ParaLeft << "Inherited by "; |
|
590 |
||
591 |
appendSortedNames(text, classe, classe->derivedClasses(), marker); |
|
592 |
text << Atom::ParaRight; |
|
593 |
generateText(text, classe, marker); |
|
594 |
} |
|
595 |
} |
|
596 |
||
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
597 |
/*! |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
598 |
This function is called when the documentation for an |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
599 |
example is being formatted. It outputs the list of source |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
600 |
files comprising the example, and the list of images used |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
601 |
by the example. The images are copied into a subtree of |
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
602 |
\c{...doc/html/images/used-in-examples/...} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
603 |
*/ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
604 |
void Generator::generateFileList(const FakeNode* fake, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
605 |
CodeMarker* marker, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
606 |
Node::SubType subtype, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
607 |
const QString& tag) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
608 |
{ |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
609 |
int count = 0; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
610 |
Text text; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
611 |
OpenedList openedList(OpenedList::Bullet); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
612 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
613 |
text << Atom::ParaLeft << tag << Atom::ParaRight |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
614 |
<< Atom(Atom::ListLeft, openedList.styleString()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
615 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
616 |
foreach (const Node* child, fake->childNodes()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
617 |
if (child->subType() == subtype) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
618 |
++count; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
619 |
QString file = child->name(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
620 |
if (subtype == Node::Image) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
621 |
if (!file.isEmpty()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
622 |
QDir dirInfo; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
623 |
QString userFriendlyFilePath; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
624 |
QString srcPath = Config::findFile(fake->location(), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
625 |
QStringList(), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
626 |
exampleDirs, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
627 |
file, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
628 |
exampleImgExts, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
629 |
userFriendlyFilePath); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
630 |
userFriendlyFilePath.truncate(userFriendlyFilePath.lastIndexOf('/')); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
631 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
632 |
QString imgOutDir = outDir + "/images/used-in-examples/" + userFriendlyFilePath; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
633 |
if (!dirInfo.mkpath(imgOutDir)) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
634 |
fake->location().fatal(tr("Cannot create output directory '%1'") |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
635 |
.arg(imgOutDir)); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
636 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
637 |
QString imgOutName = Config::copyFile(fake->location(), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
638 |
srcPath, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
639 |
file, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
640 |
imgOutDir); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
641 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
642 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
643 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
644 |
|
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
645 |
openedList.next(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
646 |
text << Atom(Atom::ListItemNumber, openedList.numberString()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
647 |
<< Atom(Atom::ListItemLeft, openedList.styleString()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
648 |
<< Atom::ParaLeft |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
649 |
<< Atom(Atom::Link, file) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
650 |
<< Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
651 |
<< file |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
652 |
<< Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
653 |
<< Atom::ParaRight |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
654 |
<< Atom(Atom::ListItemRight, openedList.styleString()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
655 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
656 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
657 |
text << Atom(Atom::ListRight, openedList.styleString()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
658 |
if (count > 0) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
659 |
generateText(text, fake, marker); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
660 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
661 |
|
0 | 662 |
void Generator::generateExampleFiles(const FakeNode *fake, CodeMarker *marker) |
663 |
{ |
|
664 |
if (fake->childNodes().isEmpty()) |
|
665 |
return; |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
666 |
generateFileList(fake, marker, Node::File, QString("Files:")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
667 |
generateFileList(fake, marker, Node::Image, QString("Images:")); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
668 |
} |
0 | 669 |
|
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
670 |
#if 0 |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
671 |
QList<Generator *>::ConstIterator g = generators.begin(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
672 |
while (g != generators.end()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
673 |
if (outputFormats.contains((*g)->format())) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
674 |
(*g)->initializeGenerator(config); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
675 |
QStringList extraImages = |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
676 |
config.getStringList(CONFIG_EXTRAIMAGES+Config::dot+(*g)->format()); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
677 |
QStringList::ConstIterator e = extraImages.begin(); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
678 |
while (e != extraImages.end()) { |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
679 |
QString userFriendlyFilePath; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
680 |
QString filePath = Config::findFile(config.lastLocation(), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
681 |
imageFiles, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
682 |
imageDirs, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
683 |
*e, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
684 |
imgFileExts[(*g)->format()], |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
685 |
userFriendlyFilePath); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
686 |
if (!filePath.isEmpty()) |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
687 |
Config::copyFile(config.lastLocation(), |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
688 |
filePath, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
689 |
userFriendlyFilePath, |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
690 |
(*g)->outputDir() + |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
691 |
"/images"); |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
692 |
++e; |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
693 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
694 |
} |
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
695 |
++g; |
0 | 696 |
} |
3
41300fa6a67c
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
697 |
#endif |
0 | 698 |
|
699 |
QString Generator::indent(int level, const QString& markedCode) |
|
700 |
{ |
|
701 |
if (level == 0) |
|
702 |
return markedCode; |
|
703 |
||
704 |
QString t; |
|
705 |
int column = 0; |
|
706 |
||
707 |
int i = 0; |
|
708 |
while (i < (int) markedCode.length()) { |
|
709 |
if (markedCode.at(i) == QLatin1Char('<')) { |
|
710 |
while (i < (int) markedCode.length()) { |
|
711 |
t += markedCode.at(i++); |
|
712 |
if (markedCode.at(i - 1) == QLatin1Char('>')) |
|
713 |
break; |
|
714 |
} |
|
715 |
} |
|
716 |
else { |
|
717 |
if (markedCode.at(i) == QLatin1Char('\n')) { |
|
718 |
column = 0; |
|
719 |
} |
|
720 |
else { |
|
721 |
if (column == 0) { |
|
722 |
for (int j = 0; j < level; j++) |
|
723 |
t += QLatin1Char(' '); |
|
724 |
} |
|
725 |
column++; |
|
726 |
} |
|
727 |
t += markedCode.at(i++); |
|
728 |
} |
|
729 |
} |
|
730 |
return t; |
|
731 |
} |
|
732 |
||
733 |
QString Generator::plainCode(const QString& markedCode) |
|
734 |
{ |
|
735 |
QString t = markedCode; |
|
736 |
t.replace(tag, QString()); |
|
737 |
t.replace(quot, QLatin1String("\"")); |
|
738 |
t.replace(gt, QLatin1String(">")); |
|
739 |
t.replace(lt, QLatin1String("<")); |
|
740 |
t.replace(amp, QLatin1String("&")); |
|
741 |
return t; |
|
742 |
} |
|
743 |
||
744 |
QString Generator::typeString(const Node *node) |
|
745 |
{ |
|
746 |
switch (node->type()) { |
|
747 |
case Node::Namespace: |
|
748 |
return "namespace"; |
|
749 |
case Node::Class: |
|
750 |
return "class"; |
|
751 |
case Node::Fake: |
|
752 |
default: |
|
753 |
return "documentation"; |
|
754 |
case Node::Enum: |
|
755 |
return "enum"; |
|
756 |
case Node::Typedef: |
|
757 |
return "typedef"; |
|
758 |
case Node::Function: |
|
759 |
return "function"; |
|
760 |
case Node::Property: |
|
761 |
return "property"; |
|
762 |
} |
|
763 |
} |
|
764 |
||
765 |
QString Generator::imageFileName(const Node *relative, const QString& fileBase) |
|
766 |
{ |
|
767 |
QString userFriendlyFilePath; |
|
768 |
QString filePath = Config::findFile( |
|
769 |
relative->doc().location(), imageFiles, imageDirs, fileBase, |
|
770 |
imgFileExts[format()], userFriendlyFilePath); |
|
771 |
||
772 |
if (filePath.isEmpty()) |
|
773 |
return QString(); |
|
774 |
||
775 |
return QLatin1String("images/") |
|
776 |
+ Config::copyFile(relative->doc().location(), |
|
777 |
filePath, userFriendlyFilePath, |
|
778 |
outputDir() + QLatin1String("/images")); |
|
779 |
} |
|
780 |
||
781 |
void Generator::setImageFileExtensions(const QStringList& extensions) |
|
782 |
{ |
|
783 |
imgFileExts[format()] = extensions; |
|
784 |
} |
|
785 |
||
786 |
void Generator::unknownAtom(const Atom *atom) |
|
787 |
{ |
|
788 |
Location::internalError(tr("unknown atom type '%1' in %2 generator") |
|
789 |
.arg(atom->typeString()).arg(format())); |
|
790 |
} |
|
791 |
||
792 |
bool Generator::matchAhead(const Atom *atom, Atom::Type expectedAtomType) |
|
793 |
{ |
|
794 |
return atom->next() != 0 && atom->next()->type() == expectedAtomType; |
|
795 |
} |
|
796 |
||
797 |
void Generator::supplementAlsoList(const Node *node, QList<Text> &alsoList) |
|
798 |
{ |
|
799 |
if (node->type() == Node::Function) { |
|
800 |
const FunctionNode *func = static_cast<const FunctionNode *>(node); |
|
801 |
if (func->overloadNumber() == 1) { |
|
802 |
QString alternateName; |
|
803 |
const FunctionNode *alternateFunc = 0; |
|
804 |
||
805 |
if (func->name().startsWith("set") && func->name().size() >= 4) { |
|
806 |
alternateName = func->name()[3].toLower(); |
|
807 |
alternateName += func->name().mid(4); |
|
808 |
alternateFunc = func->parent()->findFunctionNode(alternateName); |
|
809 |
||
810 |
if (!alternateFunc) { |
|
811 |
alternateName = "is" + func->name().mid(3); |
|
812 |
alternateFunc = func->parent()->findFunctionNode(alternateName); |
|
813 |
if (!alternateFunc) { |
|
814 |
alternateName = "has" + func->name().mid(3); |
|
815 |
alternateFunc = func->parent()->findFunctionNode(alternateName); |
|
816 |
} |
|
817 |
} |
|
818 |
} |
|
819 |
else if (!func->name().isEmpty()) { |
|
820 |
alternateName = "set"; |
|
821 |
alternateName += func->name()[0].toUpper(); |
|
822 |
alternateName += func->name().mid(1); |
|
823 |
alternateFunc = func->parent()->findFunctionNode(alternateName); |
|
824 |
} |
|
825 |
||
826 |
if (alternateFunc && alternateFunc->access() != Node::Private) { |
|
827 |
int i; |
|
828 |
for (i = 0; i < alsoList.size(); ++i) { |
|
829 |
if (alsoList.at(i).toString().contains(alternateName)) |
|
830 |
break; |
|
831 |
} |
|
832 |
||
833 |
if (i == alsoList.size()) { |
|
834 |
alternateName += "()"; |
|
835 |
||
836 |
Text also; |
|
837 |
also << Atom(Atom::Link, alternateName) |
|
838 |
<< Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) |
|
839 |
<< alternateName |
|
840 |
<< Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK); |
|
841 |
alsoList.prepend(also); |
|
842 |
} |
|
843 |
} |
|
844 |
} |
|
845 |
} |
|
846 |
} |
|
847 |
||
848 |
QMap<QString, QString>& Generator::formattingLeftMap() |
|
849 |
{ |
|
850 |
return fmtLeftMaps[format()]; |
|
851 |
} |
|
852 |
||
853 |
QMap<QString, QString>& Generator::formattingRightMap() |
|
854 |
{ |
|
855 |
return fmtRightMaps[format()]; |
|
856 |
} |
|
857 |
||
858 |
QString Generator::trimmedTrailing(const QString &string) |
|
859 |
{ |
|
860 |
QString trimmed = string; |
|
861 |
while (trimmed.length() > 0 && trimmed[trimmed.length() - 1].isSpace()) |
|
862 |
trimmed.truncate(trimmed.length() - 1); |
|
863 |
return trimmed; |
|
864 |
} |
|
865 |
||
866 |
void Generator::generateStatus(const Node *node, CodeMarker *marker) |
|
867 |
{ |
|
868 |
Text text; |
|
869 |
||
870 |
switch (node->status()) { |
|
871 |
case Node::Commendable: |
|
872 |
case Node::Main: |
|
873 |
break; |
|
874 |
case Node::Preliminary: |
|
875 |
text << Atom::ParaLeft |
|
876 |
<< Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) |
|
877 |
<< "This " |
|
878 |
<< typeString(node) |
|
879 |
<< " is under development and is subject to change." |
|
880 |
<< Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD) |
|
881 |
<< Atom::ParaRight; |
|
882 |
break; |
|
883 |
case Node::Deprecated: |
|
884 |
text << Atom::ParaLeft; |
|
885 |
if (node->isInnerNode()) |
|
886 |
text << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD); |
|
887 |
text << "This " << typeString(node) << " is deprecated."; |
|
888 |
if (node->isInnerNode()) |
|
889 |
text << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD); |
|
890 |
text << Atom::ParaRight; |
|
891 |
break; |
|
892 |
case Node::Obsolete: |
|
893 |
text << Atom::ParaLeft; |
|
894 |
if (node->isInnerNode()) |
|
895 |
text << Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD); |
|
896 |
text << "This " << typeString(node) << " is obsolete."; |
|
897 |
if (node->isInnerNode()) |
|
898 |
text << Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD); |
|
899 |
text << " It is provided to keep old source code working. " |
|
900 |
<< "We strongly advise against " |
|
901 |
<< "using it in new code." << Atom::ParaRight; |
|
902 |
break; |
|
903 |
case Node::Compat: |
|
904 |
// reimplemented in HtmlGenerator subclass |
|
905 |
if (node->isInnerNode()) { |
|
906 |
text << Atom::ParaLeft |
|
907 |
<< Atom(Atom::FormattingLeft, ATOM_FORMATTING_BOLD) |
|
908 |
<< "This " |
|
909 |
<< typeString(node) |
|
910 |
<< " is part of the Qt 3 compatibility layer." |
|
911 |
<< Atom(Atom::FormattingRight, ATOM_FORMATTING_BOLD) |
|
912 |
<< " It is provided to keep old source code working. " |
|
913 |
<< "We strongly advise against " |
|
914 |
<< "using it in new code. See " |
|
915 |
<< Atom(Atom::AutoLink, "Porting to Qt 4") |
|
916 |
<< " for more information." |
|
917 |
<< Atom::ParaRight; |
|
918 |
} |
|
919 |
break; |
|
920 |
case Node::Internal: |
|
921 |
default: |
|
922 |
break; |
|
923 |
} |
|
924 |
generateText(text, node, marker); |
|
925 |
} |
|
926 |
||
927 |
void Generator::generateThreadSafeness(const Node *node, CodeMarker *marker) |
|
928 |
{ |
|
929 |
Text text; |
|
930 |
Text theStockLink; |
|
931 |
Node::ThreadSafeness threadSafeness = node->threadSafeness(); |
|
932 |
||
933 |
Text rlink; |
|
934 |
rlink << Atom(Atom::Link,"reentrant") |
|
935 |
<< Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) |
|
936 |
<< "reentrant" |
|
937 |
<< Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK); |
|
938 |
||
939 |
Text tlink; |
|
940 |
tlink << Atom(Atom::Link,"thread-safe") |
|
941 |
<< Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) |
|
942 |
<< "thread-safe" |
|
943 |
<< Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK); |
|
944 |
||
945 |
switch (threadSafeness) { |
|
946 |
case Node::UnspecifiedSafeness: |
|
947 |
break; |
|
948 |
case Node::NonReentrant: |
|
949 |
text << Atom::ParaLeft |
|
950 |
<< Atom(Atom::FormattingLeft,ATOM_FORMATTING_BOLD) |
|
951 |
<< "Warning:" |
|
952 |
<< Atom(Atom::FormattingRight,ATOM_FORMATTING_BOLD) |
|
953 |
<< " This " |
|
954 |
<< typeString(node) |
|
955 |
<< " is not " |
|
956 |
<< rlink |
|
957 |
<< "." |
|
958 |
<< Atom::ParaRight; |
|
959 |
break; |
|
960 |
case Node::Reentrant: |
|
961 |
case Node::ThreadSafe: |
|
962 |
text << Atom::ParaLeft |
|
963 |
<< Atom(Atom::FormattingLeft,ATOM_FORMATTING_BOLD) |
|
964 |
<< "Note:" |
|
965 |
<< Atom(Atom::FormattingRight,ATOM_FORMATTING_BOLD) |
|
966 |
<< " "; |
|
967 |
||
968 |
if (node->isInnerNode()) { |
|
969 |
const InnerNode* innerNode = static_cast<const InnerNode*>(node); |
|
970 |
text << "All functions in this " |
|
971 |
<< typeString(node) |
|
972 |
<< " are "; |
|
973 |
if (threadSafeness == Node::ThreadSafe) |
|
974 |
text << tlink; |
|
975 |
else |
|
976 |
text << rlink; |
|
977 |
||
978 |
bool exceptions = false; |
|
979 |
NodeList reentrant; |
|
980 |
NodeList threadsafe; |
|
981 |
NodeList nonreentrant; |
|
982 |
NodeList::ConstIterator c = innerNode->childNodes().begin(); |
|
983 |
while (c != innerNode->childNodes().end()) { |
|
984 |
switch ((*c)->threadSafeness()) { |
|
985 |
case Node::Reentrant: |
|
986 |
reentrant.append(*c); |
|
987 |
if (threadSafeness == Node::ThreadSafe) |
|
988 |
exceptions = true; |
|
989 |
break; |
|
990 |
case Node::ThreadSafe: |
|
991 |
threadsafe.append(*c); |
|
992 |
if (threadSafeness == Node::Reentrant) |
|
993 |
exceptions = true; |
|
994 |
break; |
|
995 |
case Node::NonReentrant: |
|
996 |
nonreentrant.append(*c); |
|
997 |
exceptions = true; |
|
998 |
break; |
|
999 |
default: |
|
1000 |
break; |
|
1001 |
} |
|
1002 |
++c; |
|
1003 |
} |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1004 |
if (!exceptions) |
0 | 1005 |
text << "."; |
1006 |
else if (threadSafeness == Node::Reentrant) { |
|
1007 |
if (nonreentrant.isEmpty()) { |
|
1008 |
if (!threadsafe.isEmpty()) { |
|
1009 |
text << ", but "; |
|
1010 |
appendFullNames(text,threadsafe,innerNode,marker); |
|
1011 |
singularPlural(text,threadsafe); |
|
1012 |
text << " also " << tlink << "."; |
|
1013 |
} |
|
1014 |
else |
|
1015 |
text << "."; |
|
1016 |
} |
|
1017 |
else { |
|
1018 |
text << ", except for "; |
|
1019 |
appendFullNames(text,nonreentrant,innerNode,marker); |
|
1020 |
text << ", which"; |
|
1021 |
singularPlural(text,nonreentrant); |
|
1022 |
text << " nonreentrant."; |
|
1023 |
if (!threadsafe.isEmpty()) { |
|
1024 |
text << " "; |
|
1025 |
appendFullNames(text,threadsafe,innerNode,marker); |
|
1026 |
singularPlural(text,threadsafe); |
|
1027 |
text << " " << tlink << "."; |
|
1028 |
} |
|
1029 |
} |
|
1030 |
} |
|
1031 |
else { // thread-safe |
|
1032 |
if (!nonreentrant.isEmpty() || !reentrant.isEmpty()) { |
|
1033 |
text << ", except for "; |
|
1034 |
if (!reentrant.isEmpty()) { |
|
1035 |
appendFullNames(text,reentrant,innerNode,marker); |
|
1036 |
text << ", which"; |
|
1037 |
singularPlural(text,reentrant); |
|
1038 |
text << " only " << rlink; |
|
1039 |
if (!nonreentrant.isEmpty()) |
|
1040 |
text << ", and "; |
|
1041 |
} |
|
1042 |
if (!nonreentrant.isEmpty()) { |
|
1043 |
appendFullNames(text,nonreentrant,innerNode,marker); |
|
1044 |
text << ", which"; |
|
1045 |
singularPlural(text,nonreentrant); |
|
1046 |
text << " nonreentrant."; |
|
1047 |
} |
|
1048 |
text << "."; |
|
1049 |
} |
|
1050 |
} |
|
1051 |
} |
|
1052 |
else { |
|
1053 |
text << "This " << typeString(node) << " is "; |
|
1054 |
if (threadSafeness == Node::ThreadSafe) |
|
1055 |
text << tlink; |
|
1056 |
else |
|
1057 |
text << rlink; |
|
1058 |
text << "."; |
|
1059 |
} |
|
1060 |
text << Atom::ParaRight; |
|
1061 |
} |
|
1062 |
generateText(text,node,marker); |
|
1063 |
} |
|
1064 |
||
1065 |
void Generator::generateSince(const Node *node, CodeMarker *marker) |
|
1066 |
{ |
|
1067 |
if (!node->since().isEmpty()) { |
|
1068 |
Text text; |
|
1069 |
text << Atom::ParaLeft |
|
1070 |
<< "This " |
|
37
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1071 |
<< typeString(node); |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1072 |
if (node->type() == Node::Enum) |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1073 |
text << " was introduced or modified in "; |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1074 |
else |
758a864f9613
Revision: 201037
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
30
diff
changeset
|
1075 |
text << " was introduced in "; |
0 | 1076 |
if (project.isEmpty()) |
1077 |
text << "version"; |
|
1078 |
else |
|
1079 |
text << project; |
|
1080 |
text << " " << node->since() << "." << Atom::ParaRight; |
|
1081 |
generateText(text, node, marker); |
|
1082 |
} |
|
1083 |
} |
|
1084 |
||
1085 |
/*! |
|
1086 |
No longer in use. |
|
1087 |
*/ |
|
1088 |
void Generator::generateOverload(const Node *node, CodeMarker *marker) |
|
1089 |
{ |
|
1090 |
Text text; |
|
1091 |
text << Atom::ParaLeft |
|
1092 |
<< "This function overloads "; |
|
1093 |
QString t = node->name() + "()"; |
|
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1094 |
text << Atom::AutoLink << t |
0 | 1095 |
<< Atom::ParaRight; |
1096 |
generateText(text, node, marker); |
|
1097 |
} |
|
1098 |
||
1099 |
void Generator::generateReimplementedFrom(const FunctionNode *func, |
|
1100 |
CodeMarker *marker) |
|
1101 |
{ |
|
1102 |
if (func->reimplementedFrom() != 0) { |
|
1103 |
const FunctionNode *from = func->reimplementedFrom(); |
|
1104 |
if (from->access() != Node::Private && |
|
1105 |
from->parent()->access() != Node::Private) { |
|
1106 |
Text text; |
|
1107 |
text << Atom::ParaLeft << "Reimplemented from "; |
|
1108 |
QString fullName = from->parent()->name() + "::" + from->name() + "()"; |
|
1109 |
appendFullName(text, from->parent(), fullName, from); |
|
1110 |
text << "." << Atom::ParaRight; |
|
1111 |
generateText(text, func, marker); |
|
1112 |
} |
|
1113 |
} |
|
1114 |
} |
|
1115 |
||
1116 |
const Atom *Generator::generateAtomList(const Atom *atom, |
|
1117 |
const Node *relative, |
|
1118 |
CodeMarker *marker, |
|
1119 |
bool generate, |
|
1120 |
int &numAtoms) |
|
1121 |
{ |
|
1122 |
while (atom) { |
|
1123 |
if (atom->type() == Atom::FormatIf) { |
|
1124 |
int numAtoms0 = numAtoms; |
|
1125 |
bool rightFormat = canHandleFormat(atom->string()); |
|
1126 |
atom = generateAtomList(atom->next(), |
|
1127 |
relative, |
|
1128 |
marker, |
|
1129 |
generate && rightFormat, |
|
1130 |
numAtoms); |
|
1131 |
if (!atom) |
|
1132 |
return 0; |
|
1133 |
||
1134 |
if (atom->type() == Atom::FormatElse) { |
|
1135 |
++numAtoms; |
|
1136 |
atom = generateAtomList(atom->next(), |
|
1137 |
relative, |
|
1138 |
marker, |
|
1139 |
generate && !rightFormat, |
|
1140 |
numAtoms); |
|
1141 |
if (!atom) |
|
1142 |
return 0; |
|
1143 |
} |
|
1144 |
||
1145 |
if (atom->type() == Atom::FormatEndif) { |
|
1146 |
if (generate && numAtoms0 == numAtoms) { |
|
1147 |
relative->location().warning(tr("Output format %1 not handled") |
|
1148 |
.arg(format())); |
|
1149 |
Atom unhandledFormatAtom(Atom::UnhandledFormat, format()); |
|
1150 |
generateAtomList(&unhandledFormatAtom, |
|
1151 |
relative, |
|
1152 |
marker, |
|
1153 |
generate, |
|
1154 |
numAtoms); |
|
1155 |
} |
|
1156 |
atom = atom->next(); |
|
1157 |
} |
|
1158 |
} |
|
1159 |
else if (atom->type() == Atom::FormatElse || |
|
1160 |
atom->type() == Atom::FormatEndif) { |
|
1161 |
return atom; |
|
1162 |
} |
|
1163 |
else { |
|
1164 |
int n = 1; |
|
1165 |
if (generate) { |
|
1166 |
n += generateAtom(atom, relative, marker); |
|
1167 |
numAtoms += n; |
|
1168 |
} |
|
1169 |
while (n-- > 0) |
|
1170 |
atom = atom->next(); |
|
1171 |
} |
|
1172 |
} |
|
1173 |
return 0; |
|
1174 |
} |
|
1175 |
||
1176 |
void Generator::appendFullName(Text& text, |
|
1177 |
const Node *apparentNode, |
|
1178 |
const Node *relative, |
|
1179 |
CodeMarker *marker, |
|
1180 |
const Node *actualNode) |
|
1181 |
{ |
|
1182 |
if (actualNode == 0) |
|
1183 |
actualNode = apparentNode; |
|
1184 |
text << Atom(Atom::LinkNode, CodeMarker::stringForNode(actualNode)) |
|
1185 |
<< Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) |
|
1186 |
<< Atom(Atom::String, marker->plainFullName(apparentNode, relative)) |
|
1187 |
<< Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK); |
|
1188 |
} |
|
1189 |
||
1190 |
void Generator::appendFullName(Text& text, |
|
1191 |
const Node *apparentNode, |
|
1192 |
const QString& fullName, |
|
1193 |
const Node *actualNode) |
|
1194 |
{ |
|
1195 |
if (actualNode == 0) |
|
1196 |
actualNode = apparentNode; |
|
1197 |
text << Atom(Atom::LinkNode, CodeMarker::stringForNode(actualNode)) |
|
1198 |
<< Atom(Atom::FormattingLeft, ATOM_FORMATTING_LINK) |
|
1199 |
<< Atom(Atom::String, fullName) |
|
1200 |
<< Atom(Atom::FormattingRight, ATOM_FORMATTING_LINK); |
|
1201 |
} |
|
1202 |
||
1203 |
void Generator::appendFullNames(Text& text, |
|
1204 |
const NodeList& nodes, |
|
1205 |
const Node* relative, |
|
1206 |
CodeMarker* marker) |
|
1207 |
{ |
|
1208 |
NodeList::ConstIterator n = nodes.begin(); |
|
1209 |
int index = 0; |
|
1210 |
while (n != nodes.end()) { |
|
1211 |
appendFullName(text,*n,relative,marker); |
|
1212 |
text << comma(index++,nodes.count()); |
|
1213 |
++n; |
|
1214 |
} |
|
1215 |
} |
|
1216 |
||
1217 |
void Generator::appendSortedNames(Text& text, |
|
1218 |
const ClassNode *classe, |
|
1219 |
const QList<RelatedClass> &classes, |
|
1220 |
CodeMarker *marker) |
|
1221 |
{ |
|
1222 |
QList<RelatedClass>::ConstIterator r; |
|
1223 |
QMap<QString,Text> classMap; |
|
1224 |
int index = 0; |
|
1225 |
||
1226 |
r = classes.begin(); |
|
1227 |
while (r != classes.end()) { |
|
1228 |
if ((*r).node->access() == Node::Public && |
|
1229 |
(*r).node->status() != Node::Internal |
|
1230 |
&& !(*r).node->doc().isEmpty()) { |
|
1231 |
Text className; |
|
1232 |
appendFullName(className, (*r).node, classe, marker); |
|
1233 |
classMap[className.toString().toLower()] = className; |
|
1234 |
} |
|
1235 |
++r; |
|
1236 |
} |
|
1237 |
||
1238 |
QStringList classNames = classMap.keys(); |
|
1239 |
classNames.sort(); |
|
1240 |
||
1241 |
foreach (const QString &className, classNames) { |
|
1242 |
text << classMap[className]; |
|
1243 |
text << separator(index++, classNames.count()); |
|
1244 |
} |
|
1245 |
} |
|
1246 |
||
30
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1247 |
void Generator::appendSortedQmlNames(Text& text, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1248 |
const Node* base, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1249 |
const NodeList& subs, |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1250 |
CodeMarker *marker) |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1251 |
{ |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1252 |
QMap<QString,Text> classMap; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1253 |
int index = 0; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1254 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1255 |
#ifdef DEBUG_MULTIPLE_QDOCCONF_FILES |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1256 |
qDebug() << "Generator::appendSortedQmlNames():" << base->name() << "is inherited by..."; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1257 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1258 |
for (int i = 0; i < subs.size(); ++i) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1259 |
Text t; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1260 |
#ifdef DEBUG_MULTIPLE_QDOCCONF_FILES |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1261 |
qDebug() << " " << subs[i]->name(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1262 |
#endif |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1263 |
appendFullName(t, subs[i], base, marker); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1264 |
classMap[t.toString().toLower()] = t; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1265 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1266 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1267 |
QStringList names = classMap.keys(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1268 |
names.sort(); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1269 |
|
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1270 |
foreach (const QString &name, names) { |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1271 |
text << classMap[name]; |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1272 |
text << separator(index++, names.count()); |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1273 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1274 |
} |
5dc02b23752f
Revision: 201025
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
18
diff
changeset
|
1275 |
|
0 | 1276 |
int Generator::skipAtoms(const Atom *atom, Atom::Type type) const |
1277 |
{ |
|
1278 |
int skipAhead = 0; |
|
1279 |
atom = atom->next(); |
|
1280 |
while (atom != 0 && atom->type() != type) { |
|
1281 |
skipAhead++; |
|
1282 |
atom = atom->next(); |
|
1283 |
} |
|
1284 |
return skipAhead; |
|
1285 |
} |
|
1286 |
||
1287 |
QString Generator::fullName(const Node *node, |
|
1288 |
const Node *relative, |
|
1289 |
CodeMarker *marker) const |
|
1290 |
{ |
|
1291 |
if (node->type() == Node::Fake) |
|
1292 |
return static_cast<const FakeNode *>(node)->title(); |
|
1293 |
else if (node->type() == Node::Class && |
|
1294 |
!(static_cast<const ClassNode *>(node))->serviceName().isEmpty()) |
|
1295 |
return (static_cast<const ClassNode *>(node))->serviceName(); |
|
1296 |
else |
|
1297 |
return marker->plainFullName(node, relative); |
|
1298 |
} |
|
1299 |
||
1300 |
QT_END_NAMESPACE |