From a19c22ebf8775f73b840f52b7e03869166ca0dab Mon Sep 17 00:00:00 2001 From: Martin Smith Date: Thu, 7 Mar 2013 10:23:57 +0100 Subject: [PATCH] qdoc: Initialize an uninitialized variable qdoc already ignores QML signal handler comments and does not report errors for missing QML signal handler documentation. but the test case for this bug revealed a separate bug. The test case contains no import statements, which, technically is legal but probably won't happen. Still, qdoc failed to generate output for the test case QML file because it didn't contain an import statement before the first qdoc comment. This was caused by an uninitialized variable, which has now been fixed. Task-number: QTBUG-30043 Change-Id: Iafa2087b85a6c9e354b2be86c779bbd191181218 Reviewed-by: J-P Nurmi --- src/tools/qdoc/qmlvisitor.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/tools/qdoc/qmlvisitor.cpp b/src/tools/qdoc/qmlvisitor.cpp index 6d44b99af7..ffe1afe28b 100644 --- a/src/tools/qdoc/qmlvisitor.cpp +++ b/src/tools/qdoc/qmlvisitor.cpp @@ -88,6 +88,7 @@ QmlDocVisitor::QmlDocVisitor(const QString &filePath, QSet &topics) : nestingLevel(0) { + lastEndOffset = 0; this->filePath = filePath; this->name = QFileInfo(filePath).baseName(); document = code; @@ -117,21 +118,21 @@ QQmlJS::AST::SourceLocation QmlDocVisitor::precedingComment(quint32 offset) cons QQmlJS::AST::SourceLocation loc = it.previous(); - if (loc.begin() <= lastEndOffset) + if (loc.begin() <= lastEndOffset) { // Return if we reach the end of the preceding structure. break; - - else if (usedComments.contains(loc.begin())) + } + else if (usedComments.contains(loc.begin())) { // Return if we encounter a previously used comment. break; - + } else if (loc.begin() > lastEndOffset && loc.end() < offset) { - // Only examine multiline comments in order to avoid snippet markers. if (document.at(loc.offset - 1) == QLatin1Char('*')) { QString comment = document.mid(loc.offset, loc.length); - if (comment.startsWith(QLatin1Char('!')) || comment.startsWith(QLatin1Char('*'))) + if (comment.startsWith(QLatin1Char('!')) || comment.startsWith(QLatin1Char('*'))) { return loc; + } } } } @@ -165,8 +166,9 @@ bool QmlDocVisitor::applyDocumentation(QQmlJS::AST::SourceLocation location, Nod node->setDoc(doc); applyMetacommands(loc, node, doc); usedComments.insert(loc.offset); - if (doc.isEmpty()) + if (doc.isEmpty()) { return false; + } return true; } Location codeLoc(filePath);