diff options
author | David Boddie <david.boddie@nokia.com> | 2010-12-06 17:52:38 (GMT) |
---|---|---|
committer | David Boddie <david.boddie@nokia.com> | 2010-12-06 17:52:38 (GMT) |
commit | bb6d5d9eb2a40de14ab3a41fbdaf4092c1a3b4e8 (patch) | |
tree | 44614b8add20ea5f89e3cbe5e87ba8b9eff1e781 /tools/qdoc3/qmlmarkupvisitor.cpp | |
parent | 6834727fff1f74e15b2c9f25af1845e7f529afaa (diff) | |
download | Qt-bb6d5d9eb2a40de14ab3a41fbdaf4092c1a3b4e8.zip Qt-bb6d5d9eb2a40de14ab3a41fbdaf4092c1a3b4e8.tar.gz Qt-bb6d5d9eb2a40de14ab3a41fbdaf4092c1a3b4e8.tar.bz2 |
Added missing qmlcodemarker.cpp and qmlcodemarker.h files.
Added code to remove pragmas before parsing and add them to the output.
The extractPragmas() function was copied into both qmlcodeparser.cpp and
qmlcodemarker.cpp from src/declarative/qml/qdeclarativescriptparser.cpp,
and was modified to return either nothing (for the API parser) or a
list of removed pragmas (for the code marker).
Diffstat (limited to 'tools/qdoc3/qmlmarkupvisitor.cpp')
-rw-r--r-- | tools/qdoc3/qmlmarkupvisitor.cpp | 75 |
1 files changed, 57 insertions, 18 deletions
diff --git a/tools/qdoc3/qmlmarkupvisitor.cpp b/tools/qdoc3/qmlmarkupvisitor.cpp index 907b95d..6bede96 100644 --- a/tools/qdoc3/qmlmarkupvisitor.cpp +++ b/tools/qdoc3/qmlmarkupvisitor.cpp @@ -49,12 +49,42 @@ QT_BEGIN_NAMESPACE -QmlMarkupVisitor::QmlMarkupVisitor(const QString &source, QDeclarativeJS::Engine *engine) +QmlMarkupVisitor::QmlMarkupVisitor(const QString &source, + const QList<QDeclarativeJS::AST::SourceLocation> &pragmas, + QDeclarativeJS::Engine *engine) { this->source = source; this->engine = engine; + cursor = 0; - commentIndex = 0; + extraIndex = 0; + + // Merge the lists of locations of pragmas and comments in the source code. + int i = 0; + int j = 0; + while (i < engine->comments().length() && j < pragmas.length()) { + if (engine->comments()[i].offset < pragmas[j].offset) { + extraTypes.append(Comment); + extraLocations.append(engine->comments()[i]); + ++i; + } else { + extraTypes.append(Pragma); + extraLocations.append(engine->comments()[j]); + ++j; + } + } + + while (i < engine->comments().length()) { + extraTypes.append(Comment); + extraLocations.append(engine->comments()[i]); + ++i; + } + + while (j < pragmas.length()) { + extraTypes.append(Pragma); + extraLocations.append(pragmas[j]); + ++j; + } } QmlMarkupVisitor::~QmlMarkupVisitor() @@ -96,7 +126,7 @@ QString QmlMarkupVisitor::markedUpCode() void QmlMarkupVisitor::addExtra(quint32 start, quint32 finish) { - if (commentIndex >= engine->comments().length()) { + if (extraIndex >= extraLocations.length()) { QString extra = source.mid(start, finish - start); if (extra.trimmed().isEmpty()) output += extra; @@ -107,28 +137,37 @@ void QmlMarkupVisitor::addExtra(quint32 start, quint32 finish) return; } - while (commentIndex < engine->comments().length()) { - if (engine->comments()[commentIndex].offset - 2 >= start) - break; - commentIndex++; + while (extraIndex < extraLocations.length()) { + if (extraTypes[extraIndex] == Comment) { + if (extraLocations[extraIndex].offset - 2 >= start) + break; + } else { + if (extraLocations[extraIndex].offset >= start) + break; + } + extraIndex++; } quint32 i = start; - while (i < finish && commentIndex < engine->comments().length()) { - quint32 j = engine->comments()[commentIndex].offset - 2; + while (i < finish && extraIndex < extraLocations.length()) { + quint32 j = extraLocations[extraIndex].offset - 2; if (i <= j && j < finish) { if (i < j) output += protect(source.mid(i, j - i)); - quint32 l = engine->comments()[commentIndex].length; - if (source.mid(j, 2) == QLatin1String("/*")) - l += 4; - else - l += 2; - output += QLatin1String("<@comment>"); - output += protect(source.mid(j, l)); - output += QLatin1String("</@comment>"); - commentIndex++; + quint32 l = extraLocations[extraIndex].length; + if (extraTypes[extraIndex] == Comment) { + if (source.mid(j, 2) == QLatin1String("/*")) + l += 4; + else + l += 2; + output += QLatin1String("<@comment>"); + output += protect(source.mid(j, l)); + output += QLatin1String("</@comment>"); + } else + output += protect(source.mid(j, l)); + + extraIndex++; i = j + l; } else break; |