summaryrefslogtreecommitdiffstats
path: root/src/tools/qdoc/puredocparser.cpp
diff options
context:
space:
mode:
authorMartin Smith <[email protected]>2012-05-24 12:23:59 +0200
committerQt by Nokia <[email protected]>2012-05-25 17:23:20 +0200
commita755049931031d7e234ba157c960e7cf96489b2a (patch)
tree8224378c1541772dc43072af6c943885972e9092 /src/tools/qdoc/puredocparser.cpp
parent4830bcc9626ba285257aa170922360b6207b4261 (diff)
qdoc: Fixed pure doc parser
This parser was meant to parse any file for qdoc comments only, ignoring everything else that is not inside a qdoc comment. But it wasn't doing that. It was parsing all code, regardless of the language, using the C++ parser. Now it has been corrected to look at qdoc comments and skip over everything else. Note thast this means qdoc will expect a qdoc topic command in each and every qdoc comment in the file. The posiution of the qdoc comment with respect to the code it is meant to document is not taken into account in the pure doc parser. This is in contrast to the QML and C++ parsers which do take comment location into account in some cases. Change-Id: I0804a4149baa942b463e0b6990c71e4039ac1a50 Reviewed-by: Keith Isdale <[email protected]> Reviewed-by: Martin Smith <[email protected]>
Diffstat (limited to 'src/tools/qdoc/puredocparser.cpp')
-rw-r--r--src/tools/qdoc/puredocparser.cpp146
1 files changed, 145 insertions, 1 deletions
diff --git a/src/tools/qdoc/puredocparser.cpp b/src/tools/qdoc/puredocparser.cpp
index 072e6331a04..19a19373bd7 100644
--- a/src/tools/qdoc/puredocparser.cpp
+++ b/src/tools/qdoc/puredocparser.cpp
@@ -43,6 +43,14 @@
puredocparser.cpp
*/
+#include <qfile.h>
+#include <stdio.h>
+#include <errno.h>
+#include "codechunk.h"
+#include "config.h"
+#include "tokenizer.h"
+#include "tree.h"
+#include <qdebug.h>
#include "puredocparser.h"
QT_BEGIN_NAMESPACE
@@ -57,7 +65,143 @@ PureDocParser::~PureDocParser()
QStringList PureDocParser::sourceFileNameFilter()
{
- return QStringList() << "*.qdoc" << "*.qtx" << "*.qtt";
+ return QStringList() << "*.qdoc" << "*.qtx" << "*.qtt" << "*.js";
}
+/*!
+ Parse the source file identified by \a filePath and add its
+ parsed contents to the big \a tree. \a location is used for
+ reporting errors.
+ */
+void PureDocParser::parseSourceFile(const Location& location,
+ const QString& filePath,
+ Tree *tree)
+{
+ QFile in(filePath);
+ if (!in.open(QIODevice::ReadOnly)) {
+ location.error(tr("Can't open source file '%1' (%2)").arg(filePath).arg(strerror(errno)));
+ return;
+ }
+ createOutputSubdirectory(location, filePath);
+
+ reset(tree);
+ Location fileLocation(filePath);
+ Tokenizer fileTokenizer(fileLocation, in);
+ tokenizer = &fileTokenizer;
+ readToken();
+
+ /*
+ The set of active namespaces is cleared before parsing
+ each source file. The word "source" here means cpp file.
+ */
+ activeNamespaces_.clear();
+
+ processQdocComments();
+ in.close();
+}
+
+/*!
+ This is called by parseSourceFile() to do the actual parsing
+ and tree building. It only processes qdoc comments. It skips
+ everything else.
+ */
+bool PureDocParser::processQdocComments()
+{
+ QSet<QString> topicCommandsAllowed = topicCommands();
+ QSet<QString> otherMetacommandsAllowed = otherMetaCommands();
+ QSet<QString> metacommandsAllowed = topicCommandsAllowed + otherMetacommandsAllowed;
+
+ while (tok != Tok_Eoi) {
+ if (tok == Tok_Doc) {
+ /*
+ lexeme() returns an entire qdoc comment.
+ */
+ QString comment = lexeme();
+ Location start_loc(location());
+ readToken();
+
+ Doc::trimCStyleComment(start_loc,comment);
+ Location end_loc(location());
+
+ /*
+ Doc parses the comment.
+ */
+ Doc doc(start_loc,end_loc,comment,metacommandsAllowed);
+
+ QString topic;
+ ArgList args;
+
+ QSet<QString> topicCommandsUsed = topicCommandsAllowed & doc.metaCommandsUsed();
+
+ /*
+ There should be one topic command in the set,
+ or none. If the set is empty, then the comment
+ should be a function description.
+ */
+ if (topicCommandsUsed.count() > 0) {
+ topic = *topicCommandsUsed.begin();
+ args = doc.metaCommandArgs(topic);
+ }
+
+ NodeList nodes;
+ QList<Doc> docs;
+
+ if (topic.isEmpty()) {
+ doc.location().warning(tr("This qdoc comment contains no topic command "
+ "(e.g., '\\%1', '\\%2').")
+ .arg(COMMAND_MODULE).arg(COMMAND_PAGE));
+ }
+ else {
+ /*
+ There is a topic command. Process it.
+ */
+ if ((topic == COMMAND_QMLPROPERTY) ||
+ (topic == COMMAND_QMLATTACHEDPROPERTY)) {
+ Doc nodeDoc = doc;
+ Node* node = processTopicCommandGroup(topic,args);
+ if (node != 0) {
+ nodes.append(node);
+ docs.append(nodeDoc);
+ }
+ }
+ else {
+ ArgList::ConstIterator a = args.begin();
+ while (a != args.end()) {
+ Doc nodeDoc = doc;
+ Node* node = processTopicCommand(nodeDoc,topic,*a);
+ if (node != 0) {
+ nodes.append(node);
+ docs.append(nodeDoc);
+ }
+ ++a;
+ }
+ }
+ }
+
+ NodeList::Iterator n = nodes.begin();
+ QList<Doc>::Iterator d = docs.begin();
+ while (n != nodes.end()) {
+ processOtherMetaCommands(*d, *n);
+ (*n)->setDoc(*d);
+ if ((*n)->isInnerNode() && ((InnerNode *)*n)->includes().isEmpty()) {
+ InnerNode *m = static_cast<InnerNode *>(*n);
+ while (m->parent() != tree_->root())
+ m = m->parent();
+ if (m == *n)
+ ((InnerNode *)*n)->addInclude((*n)->name());
+ else
+ ((InnerNode *)*n)->setIncludes(m->includes());
+ }
+ ++d;
+ ++n;
+ }
+ }
+ else {
+ readToken();
+ }
+ }
+ return true;
+}
+
+
QT_END_NAMESPACE