D6013: DebugVisitor: catch and show invalid token indizes

Friedrich W. H. Kossebau noreply at phabricator.kde.org
Mon May 29 14:56:15 UTC 2017


kossebau added a comment.


  Generated code example:
  
    void printToken(const AstNode *node, const QString &mType, const QString &mName = QString())
    {
        KDevPG::TokenStream::Token startToken;
        KDevPG::TokenStream::Token endToken;
        qint64 line, column;
        const bool isValidStartToken = (0 <= node->startToken && node->startToken < m_str->size());
        QString startTokenString;
        if (isValidStartToken)
        {
            startToken = m_str->at(node->startToken);
            m_str->startPosition(node->startToken, &line, &column);
            startTokenString = QString::number(startToken.begin) + QLatin1String(", ") + QString::number(line) + QLatin1String(", ") + QString::number(column);
        }
        else
        {
            startTokenString = QLatin1String("invalid token index: ") + QString::number(node->startToken);
        }
        const bool isValidEndToken = (0 <= node->endToken && node->endToken < m_str->size());
        QString endTokenString;
        if (isValidEndToken)
        {
            endToken = m_str->at(node->endToken);
            m_str->startPosition(node->endToken, &line, &column);
            endTokenString = QString::number(endToken.begin) + QLatin1String(", ") + QString::number(line) + QLatin1String(", ") + QString::number(column);
        }
        else
        {
            endTokenString = QLatin1String("invalid token index: ") + QString::number(node->endToken);
        }
        QString tokenString;
        if (!m_content.isEmpty() && isValidStartToken && isValidEndToken)
        {
            const int begin = startToken.begin;
            const int end = endToken.end;
            if (end-begin > 30)
            {
                tokenString = m_content.mid(begin, 10);
                tokenString += QStringLiteral(" ...");
                tokenString += QStringLiteral("%1 more").arg(end-begin-20);
                tokenString += QStringLiteral("... ");
                tokenString += m_content.midRef(end-10, 10);
            }
            else
            {
                tokenString = m_content.mid(begin, end-begin+1);
            }
            tokenString.replace('\n', QStringLiteral("\\n"));
            tokenString.replace('\r', QStringLiteral("\\r"));
        }
        qDebug() << QString(QString().fill(QLatin1Char(' '), m_indent) + mName + QLatin1String(!mName.isEmpty() ? "->" : "") + mType + QLatin1Char('[') + startTokenString + QLatin1String("] --- [") + endTokenString + QLatin1String("] ")).toUtf8().constData() << tokenString;
    }

REPOSITORY
  R51 KDevelop: PG Qt

REVISION DETAIL
  https://phabricator.kde.org/D6013

To: kossebau, #kdevelop
Cc: kdevelop-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kdevelop-devel/attachments/20170529/9c0811d2/attachment-0001.html>


More information about the KDevelop-devel mailing list