| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com) | 
|---|
| 5 | ** | 
|---|
| 6 | ** This file is part of the tools applications of the Qt Toolkit. | 
|---|
| 7 | ** | 
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 9 | ** Commercial Usage | 
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 13 | ** a written agreement between you and Nokia. | 
|---|
| 14 | ** | 
|---|
| 15 | ** GNU Lesser General Public License Usage | 
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software | 
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
| 19 | ** packaging of this file.  Please review the following information to | 
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
| 22 | ** | 
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain | 
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL | 
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this | 
|---|
| 26 | ** package. | 
|---|
| 27 | ** | 
|---|
| 28 | ** GNU General Public License Usage | 
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 32 | ** packaging of this file.  Please review the following information to | 
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please | 
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | /* | 
|---|
| 43 | codeparser.cpp | 
|---|
| 44 | */ | 
|---|
| 45 |  | 
|---|
| 46 | #include <QtCore> | 
|---|
| 47 | #include "codeparser.h" | 
|---|
| 48 | #include "node.h" | 
|---|
| 49 | #include "tree.h" | 
|---|
| 50 |  | 
|---|
| 51 | QT_BEGIN_NAMESPACE | 
|---|
| 52 |  | 
|---|
| 53 | #define COMMAND_COMPAT                  Doc::alias(QLatin1String("compat")) | 
|---|
| 54 | #define COMMAND_DEPRECATED              Doc::alias(QLatin1String("deprecated")) // ### don't document | 
|---|
| 55 | #define COMMAND_INGROUP                 Doc::alias(QLatin1String("ingroup")) | 
|---|
| 56 | #define COMMAND_INMODULE                Doc::alias(QLatin1String("inmodule"))  // ### don't document | 
|---|
| 57 | #define COMMAND_INTERNAL                Doc::alias(QLatin1String("internal")) | 
|---|
| 58 | #define COMMAND_MAINCLASS               Doc::alias(QLatin1String("mainclass")) | 
|---|
| 59 | #define COMMAND_NONREENTRANT            Doc::alias(QLatin1String("nonreentrant")) | 
|---|
| 60 | #define COMMAND_OBSOLETE                Doc::alias(QLatin1String("obsolete")) | 
|---|
| 61 | #define COMMAND_PRELIMINARY             Doc::alias(QLatin1String("preliminary")) | 
|---|
| 62 | #define COMMAND_INPUBLICGROUP           Doc::alias(QLatin1String("inpublicgroup")) | 
|---|
| 63 | #define COMMAND_REENTRANT               Doc::alias(QLatin1String("reentrant")) | 
|---|
| 64 | #define COMMAND_SINCE                   Doc::alias(QLatin1String("since")) | 
|---|
| 65 | #define COMMAND_SUBTITLE                Doc::alias(QLatin1String("subtitle")) | 
|---|
| 66 | #define COMMAND_THREADSAFE              Doc::alias(QLatin1String("threadsafe")) | 
|---|
| 67 | #define COMMAND_TITLE                   Doc::alias(QLatin1String("title")) | 
|---|
| 68 |  | 
|---|
| 69 | QList<CodeParser *> CodeParser::parsers; | 
|---|
| 70 |  | 
|---|
| 71 | /*! | 
|---|
| 72 | The constructor adds this code parser to the static | 
|---|
| 73 | list of code parsers. | 
|---|
| 74 | */ | 
|---|
| 75 | CodeParser::CodeParser() | 
|---|
| 76 | { | 
|---|
| 77 | parsers.prepend(this); | 
|---|
| 78 | } | 
|---|
| 79 |  | 
|---|
| 80 | /*! | 
|---|
| 81 | The destructor removes this code parser from the static | 
|---|
| 82 | list of code parsers. | 
|---|
| 83 | */ | 
|---|
| 84 | CodeParser::~CodeParser() | 
|---|
| 85 | { | 
|---|
| 86 | parsers.removeAll(this); | 
|---|
| 87 | } | 
|---|
| 88 |  | 
|---|
| 89 | /*! | 
|---|
| 90 | Initializing a code parser is trivial. | 
|---|
| 91 | */ | 
|---|
| 92 | void CodeParser::initializeParser(const Config & /* config */) | 
|---|
| 93 | { | 
|---|
| 94 | // nothing. | 
|---|
| 95 | } | 
|---|
| 96 |  | 
|---|
| 97 | /*! | 
|---|
| 98 | Teerminating a code parser is trivial. | 
|---|
| 99 | */ | 
|---|
| 100 | void CodeParser::terminateParser() | 
|---|
| 101 | { | 
|---|
| 102 | // nothing. | 
|---|
| 103 | } | 
|---|
| 104 |  | 
|---|
| 105 | QString CodeParser::headerFileNameFilter() | 
|---|
| 106 | { | 
|---|
| 107 | return sourceFileNameFilter(); | 
|---|
| 108 | } | 
|---|
| 109 |  | 
|---|
| 110 | void CodeParser::parseHeaderFile(const Location& location, | 
|---|
| 111 | const QString& filePath, | 
|---|
| 112 | Tree *tree) | 
|---|
| 113 | { | 
|---|
| 114 | parseSourceFile(location, filePath, tree); | 
|---|
| 115 | } | 
|---|
| 116 |  | 
|---|
| 117 | void CodeParser::doneParsingHeaderFiles(Tree *tree) | 
|---|
| 118 | { | 
|---|
| 119 | doneParsingSourceFiles(tree); | 
|---|
| 120 | } | 
|---|
| 121 |  | 
|---|
| 122 | /*! | 
|---|
| 123 | All the code parsers in the static list are initialized here, | 
|---|
| 124 | after the qdoc configuration variables have been set. | 
|---|
| 125 | */ | 
|---|
| 126 | void CodeParser::initialize(const Config& config) | 
|---|
| 127 | { | 
|---|
| 128 | QList<CodeParser *>::ConstIterator p = parsers.begin(); | 
|---|
| 129 | while (p != parsers.end()) { | 
|---|
| 130 | (*p)->initializeParser(config); | 
|---|
| 131 | ++p; | 
|---|
| 132 | } | 
|---|
| 133 | } | 
|---|
| 134 |  | 
|---|
| 135 | /*! | 
|---|
| 136 | All the code parsers in the static list are terminated here. | 
|---|
| 137 | */ | 
|---|
| 138 | void CodeParser::terminate() | 
|---|
| 139 | { | 
|---|
| 140 | QList<CodeParser *>::ConstIterator p = parsers.begin(); | 
|---|
| 141 | while (p != parsers.end()) { | 
|---|
| 142 | (*p)->terminateParser(); | 
|---|
| 143 | ++p; | 
|---|
| 144 | } | 
|---|
| 145 | } | 
|---|
| 146 |  | 
|---|
| 147 | CodeParser *CodeParser::parserForLanguage(const QString& language) | 
|---|
| 148 | { | 
|---|
| 149 | QList<CodeParser *>::ConstIterator p = parsers.begin(); | 
|---|
| 150 | while (p != parsers.end()) { | 
|---|
| 151 | if ((*p)->language() == language) | 
|---|
| 152 | return *p; | 
|---|
| 153 | ++p; | 
|---|
| 154 | } | 
|---|
| 155 | return 0; | 
|---|
| 156 | } | 
|---|
| 157 |  | 
|---|
| 158 | /*! | 
|---|
| 159 | Returns the set of strings representing the common metacommands. | 
|---|
| 160 | */ | 
|---|
| 161 | QSet<QString> CodeParser::commonMetaCommands() | 
|---|
| 162 | { | 
|---|
| 163 | return QSet<QString>() << COMMAND_COMPAT | 
|---|
| 164 | << COMMAND_DEPRECATED | 
|---|
| 165 | << COMMAND_INGROUP | 
|---|
| 166 | << COMMAND_INMODULE | 
|---|
| 167 | << COMMAND_INTERNAL | 
|---|
| 168 | << COMMAND_MAINCLASS | 
|---|
| 169 | << COMMAND_NONREENTRANT | 
|---|
| 170 | << COMMAND_OBSOLETE | 
|---|
| 171 | << COMMAND_PRELIMINARY | 
|---|
| 172 | << COMMAND_INPUBLICGROUP | 
|---|
| 173 | << COMMAND_REENTRANT | 
|---|
| 174 | << COMMAND_SINCE | 
|---|
| 175 | << COMMAND_SUBTITLE | 
|---|
| 176 | << COMMAND_THREADSAFE | 
|---|
| 177 | << COMMAND_TITLE; | 
|---|
| 178 | } | 
|---|
| 179 |  | 
|---|
| 180 | /*! | 
|---|
| 181 | The topic command has been processed. Now process the other | 
|---|
| 182 | metacommands that were found. These are not the text markup | 
|---|
| 183 | commands. | 
|---|
| 184 | */ | 
|---|
| 185 | void CodeParser::processCommonMetaCommand(const Location &location, | 
|---|
| 186 | const QString &command, | 
|---|
| 187 | const QString &arg, | 
|---|
| 188 | Node *node, | 
|---|
| 189 | Tree *tree) | 
|---|
| 190 | { | 
|---|
| 191 | if (command == COMMAND_COMPAT) { | 
|---|
| 192 | node->setStatus(Node::Compat); | 
|---|
| 193 | } | 
|---|
| 194 | else if (command == COMMAND_DEPRECATED) { | 
|---|
| 195 | node->setStatus(Node::Deprecated); | 
|---|
| 196 | } | 
|---|
| 197 | else if (command == COMMAND_INGROUP) { | 
|---|
| 198 | tree->addToGroup(node, arg); | 
|---|
| 199 | } | 
|---|
| 200 | else if (command == COMMAND_INPUBLICGROUP) { | 
|---|
| 201 | tree->addToPublicGroup(node, arg); | 
|---|
| 202 | } | 
|---|
| 203 | else if (command == COMMAND_INMODULE) { | 
|---|
| 204 | node->setModuleName(arg); | 
|---|
| 205 | } | 
|---|
| 206 | else if (command == COMMAND_MAINCLASS) { | 
|---|
| 207 | node->setStatus(Node::Main); | 
|---|
| 208 | } | 
|---|
| 209 | else if (command == COMMAND_OBSOLETE) { | 
|---|
| 210 | if (node->status() != Node::Compat) | 
|---|
| 211 | node->setStatus(Node::Obsolete); | 
|---|
| 212 | } | 
|---|
| 213 | else if (command == COMMAND_NONREENTRANT) { | 
|---|
| 214 | node->setThreadSafeness(Node::NonReentrant); | 
|---|
| 215 | } | 
|---|
| 216 | else if (command == COMMAND_PRELIMINARY) { | 
|---|
| 217 | node->setStatus(Node::Preliminary); | 
|---|
| 218 | } | 
|---|
| 219 | else if (command == COMMAND_INTERNAL) { | 
|---|
| 220 | node->setAccess(Node::Private); | 
|---|
| 221 | node->setStatus(Node::Internal); | 
|---|
| 222 | } | 
|---|
| 223 | else if (command == COMMAND_REENTRANT) { | 
|---|
| 224 | node->setThreadSafeness(Node::Reentrant); | 
|---|
| 225 | } | 
|---|
| 226 | else if (command == COMMAND_SINCE) { | 
|---|
| 227 | node->setSince(arg); | 
|---|
| 228 | } | 
|---|
| 229 | else if (command == COMMAND_SUBTITLE) { | 
|---|
| 230 | if (node->type() == Node::Fake) { | 
|---|
| 231 | FakeNode *fake = static_cast<FakeNode *>(node); | 
|---|
| 232 | fake->setSubTitle(arg); | 
|---|
| 233 | } | 
|---|
| 234 | else | 
|---|
| 235 | location.warning(tr("Ignored '\\%1'").arg(COMMAND_SUBTITLE)); | 
|---|
| 236 | } | 
|---|
| 237 | else if (command == COMMAND_THREADSAFE) { | 
|---|
| 238 | node->setThreadSafeness(Node::ThreadSafe); | 
|---|
| 239 | } | 
|---|
| 240 | else if (command == COMMAND_TITLE) { | 
|---|
| 241 | if (node->type() == Node::Fake) { | 
|---|
| 242 | FakeNode *fake = static_cast<FakeNode *>(node); | 
|---|
| 243 | fake->setTitle(arg); | 
|---|
| 244 | #ifdef QDOC2DOX | 
|---|
| 245 | /* qdoc -> doxygen. | 
|---|
| 246 | I think this must be done here, because there can be multiple | 
|---|
| 247 | "\externalpage" and "\title" metacommands in a single qdoc | 
|---|
| 248 | comment, which means, among other things, that the "\title" | 
|---|
| 249 | commands are not inserted into the metacommand map used by | 
|---|
| 250 | the Doc class. I'm sure there4 is a better way to do this in | 
|---|
| 251 | the DoxWriter class using the information in the FakeNode, | 
|---|
| 252 | but I don't have time to figure it out right now. | 
|---|
| 253 | */ | 
|---|
| 254 | if (DoxWriter::isDoxPass(1)) | 
|---|
| 255 | DoxWriter::insertTitle(fake,arg); | 
|---|
| 256 | #endif | 
|---|
| 257 | } | 
|---|
| 258 | else | 
|---|
| 259 | location.warning(tr("Ignored '\\%1'").arg(COMMAND_TITLE)); | 
|---|
| 260 | } | 
|---|
| 261 | } | 
|---|
| 262 |  | 
|---|
| 263 | QT_END_NAMESPACE | 
|---|