Warning: That file was not part of the compilation database. It may have many parsing errors.

1/****************************************************************************
2**
3** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4** Contact: http://www.qt-project.org/legal
5**
6** This file is part of the tools applications of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Digia. For licensing terms and
14** conditions see http://qt.digia.com/licensing. For further information
15** use the contact form at http://qt.digia.com/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 2.1 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 2.1 requirements
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24**
25** In addition, as a special exception, Digia gives you certain additional
26** rights. These rights are described in the Digia Qt LGPL Exception
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28**
29** GNU General Public License Usage
30** Alternatively, this file may be used under the terms of the GNU
31** General Public License version 3.0 as published by the Free Software
32** Foundation and appearing in the file LICENSE.GPL included in the
33** packaging of this file. Please review the following information to
34** ensure the GNU General Public License version 3.0 requirements will be
35** met: http://www.gnu.org/copyleft/gpl.html.
36**
37**
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42/*
43 codeparser.cpp
44*/
45
46#include "codeparser.h"
47#include "node.h"
48#include "tree.h"
49#include "config.h"
50
51QT_BEGIN_NAMESPACE
52
53#define COMMAND_COMPAT Doc::alias(QLatin1String("compat"))
54#define COMMAND_DEPENDS Doc::alias(QLatin1String("depends"))
55#define COMMAND_DEPRECATED Doc::alias(QLatin1String("deprecated")) // ### don't document
56#define COMMAND_INGROUP Doc::alias(QLatin1String("ingroup"))
57#define COMMAND_INMODULE Doc::alias(QLatin1String("inmodule")) // ### don't document
58#define COMMAND_INTERNAL Doc::alias(QLatin1String("internal"))
59#define COMMAND_MAINCLASS Doc::alias(QLatin1String("mainclass"))
60#define COMMAND_NONREENTRANT Doc::alias(QLatin1String("nonreentrant"))
61#define COMMAND_OBSOLETE Doc::alias(QLatin1String("obsolete"))
62#define COMMAND_PAGEKEYWORDS Doc::alias(QLatin1String("pagekeywords"))
63#define COMMAND_PRELIMINARY Doc::alias(QLatin1String("preliminary"))
64#define COMMAND_INPUBLICGROUP Doc::alias(QLatin1String("inpublicgroup"))
65#define COMMAND_REENTRANT Doc::alias(QLatin1String("reentrant"))
66#define COMMAND_SINCE Doc::alias(QLatin1String("since"))
67#define COMMAND_SUBTITLE Doc::alias(QLatin1String("subtitle"))
68#define COMMAND_THREADSAFE Doc::alias(QLatin1String("threadsafe"))
69#define COMMAND_TITLE Doc::alias(QLatin1String("title"))
70
71QList<CodeParser *> CodeParser::parsers;
72bool CodeParser::showInternal = false;
73QMap<QString,QString> CodeParser::nameToTitle;
74
75/*!
76 The constructor adds this code parser to the static
77 list of code parsers.
78 */
79CodeParser::CodeParser()
80{
81 parsers.prepend(this);
82}
83
84/*!
85 The destructor removes this code parser from the static
86 list of code parsers.
87 */
88CodeParser::~CodeParser()
89{
90 parsers.removeAll(this);
91}
92
93/*!
94 Initialize the code parser base class.
95 */
96void CodeParser::initializeParser(const Config& config)
97{
98 showInternal = config.getBool(QLatin1String(CONFIG_SHOWINTERNAL));
99}
100
101/*!
102 Terminating a code parser is trivial.
103 */
104void CodeParser::terminateParser()
105{
106 // nothing.
107}
108
109QStringList CodeParser::headerFileNameFilter()
110{
111 return sourceFileNameFilter();
112}
113
114void CodeParser::parseHeaderFile(const Location& location,
115 const QString& filePath,
116 Tree *tree)
117{
118 parseSourceFile(location, filePath, tree);
119}
120
121void CodeParser::doneParsingHeaderFiles(Tree *tree)
122{
123 doneParsingSourceFiles(tree);
124}
125
126/*!
127 All the code parsers in the static list are initialized here,
128 after the qdoc configuration variables have been set.
129 */
130void CodeParser::initialize(const Config& config)
131{
132 QList<CodeParser *>::ConstIterator p = parsers.begin();
133 while (p != parsers.end()) {
134 (*p)->initializeParser(config);
135 ++p;
136 }
137}
138
139/*!
140 All the code parsers in the static list are terminated here.
141 */
142void CodeParser::terminate()
143{
144 QList<CodeParser *>::ConstIterator p = parsers.begin();
145 while (p != parsers.end()) {
146 (*p)->terminateParser();
147 ++p;
148 }
149}
150
151CodeParser *CodeParser::parserForLanguage(const QString& language)
152{
153 QList<CodeParser *>::ConstIterator p = parsers.begin();
154 while (p != parsers.end()) {
155 if ((*p)->language() == language)
156 return *p;
157 ++p;
158 }
159 return 0;
160}
161
162CodeParser *CodeParser::parserForHeaderFile(const QString &filePath)
163{
164 QString fileName = QFileInfo(filePath).fileName();
165
166 QList<CodeParser *>::ConstIterator p = parsers.begin();
167 while (p != parsers.end()) {
168
169 QStringList headerPatterns = (*p)->headerFileNameFilter();
170 foreach (QString pattern, headerPatterns) {
171 QRegExp re(pattern, Qt::CaseInsensitive, QRegExp::Wildcard);
172 if (re.exactMatch(fileName))
173 return *p;
174 }
175 ++p;
176 }
177 return 0;
178}
179
180CodeParser *CodeParser::parserForSourceFile(const QString &filePath)
181{
182 QString fileName = QFileInfo(filePath).fileName();
183
184 QList<CodeParser *>::ConstIterator p = parsers.begin();
185 while (p != parsers.end()) {
186
187 QStringList sourcePatterns = (*p)->sourceFileNameFilter();
188 foreach (QString pattern, sourcePatterns) {
189 QRegExp re(pattern, Qt::CaseInsensitive, QRegExp::Wildcard);
190 if (re.exactMatch(fileName))
191 return *p;
192 }
193 ++p;
194 }
195 return 0;
196}
197
198/*!
199 Returns the set of strings representing the common metacommands.
200 */
201QSet<QString> CodeParser::commonMetaCommands()
202{
203 return QSet<QString>() << COMMAND_COMPAT
204 << COMMAND_DEPENDS
205 << COMMAND_DEPRECATED
206 << COMMAND_INGROUP
207 << COMMAND_INMODULE
208 << COMMAND_INTERNAL
209 << COMMAND_MAINCLASS
210 << COMMAND_NONREENTRANT
211 << COMMAND_OBSOLETE
212 << COMMAND_PAGEKEYWORDS
213 << COMMAND_PRELIMINARY
214 << COMMAND_INPUBLICGROUP
215 << COMMAND_REENTRANT
216 << COMMAND_SINCE
217 << COMMAND_SUBTITLE
218 << COMMAND_THREADSAFE
219 << COMMAND_TITLE;
220}
221
222/*!
223 The topic command has been processed. Now process the other
224 metacommands that were found. These are not the text markup
225 commands.
226 */
227void CodeParser::processCommonMetaCommand(const Location &location,
228 const QString &command,
229 const QString &arg,
230 Node *node,
231 Tree *tree)
232{
233 if (command == COMMAND_COMPAT) {
234 node->setStatus(Node::Compat);
235 }
236 else if (command == COMMAND_DEPENDS) {
237 node->addDependency(arg);
238 }
239 else if (command == COMMAND_DEPRECATED) {
240 node->setStatus(Node::Deprecated);
241 }
242 else if (command == COMMAND_INGROUP) {
243 tree->addToGroup(node, arg);
244 }
245 else if (command == COMMAND_INPUBLICGROUP) {
246 tree->addToPublicGroup(node, arg);
247 }
248 else if (command == COMMAND_INMODULE) {
249 node->setModuleName(arg);
250 }
251 else if (command == COMMAND_MAINCLASS) {
252 node->setStatus(Node::Main);
253 }
254 else if (command == COMMAND_OBSOLETE) {
255 if (node->status() != Node::Compat)
256 node->setStatus(Node::Obsolete);
257 }
258 else if (command == COMMAND_NONREENTRANT) {
259 node->setThreadSafeness(Node::NonReentrant);
260 }
261 else if (command == COMMAND_PRELIMINARY) {
262 node->setStatus(Node::Preliminary);
263 }
264 else if (command == COMMAND_INTERNAL) {
265 if (!showInternal) {
266 node->setAccess(Node::Private);
267 node->setStatus(Node::Internal);
268 }
269 }
270 else if (command == COMMAND_REENTRANT) {
271 node->setThreadSafeness(Node::Reentrant);
272 }
273 else if (command == COMMAND_SINCE) {
274 node->setSince(arg);
275 }
276 else if (command == COMMAND_PAGEKEYWORDS) {
277 node->addPageKeywords(arg);
278 }
279 else if (command == COMMAND_SUBTITLE) {
280 if (node->type() == Node::Fake) {
281 FakeNode *fake = static_cast<FakeNode *>(node);
282 fake->setSubTitle(arg);
283 }
284 else
285 location.warning(tr("Ignored '\\%1'").arg(COMMAND_SUBTITLE));
286 }
287 else if (command == COMMAND_THREADSAFE) {
288 node->setThreadSafeness(Node::ThreadSafe);
289 }
290 else if (command == COMMAND_TITLE) {
291 if (node->type() == Node::Fake) {
292 FakeNode *fake = static_cast<FakeNode *>(node);
293 fake->setTitle(arg);
294 nameToTitle.insert(fake->name(),arg);
295 if (fake->subType() == Node::Example) {
296
297 }
298 }
299 else
300 location.warning(tr("Ignored '\\%1'").arg(COMMAND_TITLE));
301 }
302}
303
304/*!
305 Find the page title given the page \a name and return it.
306 */
307const QString CodeParser::titleFromName(const QString& name)
308{
309 const QString t = nameToTitle.value(name);
310 return t;
311}
312
313QT_END_NAMESPACE
314

Warning: That file was not part of the compilation database. It may have many parsing errors.