Skip to content
Snippets Groups Projects
qmljscheck.cpp 34.5 KiB
Newer Older
            // somebody typed "id." and error recovery still gave us a valid tree,
            // so just bail out here.
            return 0;
        }

        idPart = idPart->next;
        propertyName = idPart->name->asString();

Christian Kamm's avatar
Christian Kamm committed
        value = objectValue->lookupMember(propertyName, _context);
        if (! value) {
            error(idPart->identifierToken,
                  Check::tr("'%1' is not a member of '%2'").arg(
                          propertyName, objectValue->className()));
void Check::checkAssignInCondition(AST::ExpressionNode *condition)
{
    if (_options & WarnAssignInCondition) {
        if (BinaryExpression *binary = cast<BinaryExpression *>(condition)) {
            if (binary->op == QSOperator::Assign)
                warning(binary->operatorToken, tr("avoid assignments in conditions"));
        }
    }
}

void Check::checkEndsWithControlFlow(StatementList *statements, SourceLocation errorLoc)
{
    // full flow analysis would be neat
    if (!statements || !(_options & WarnCaseWithoutFlowControlEnd))
        return;

    Statement *lastStatement = 0;
    for (StatementList *slist = statements; slist; slist = slist->next)
        lastStatement = slist->statement;

    if (!cast<ReturnStatement *>(lastStatement)
            && !cast<ThrowStatement *>(lastStatement)
            && !cast<BreakStatement *>(lastStatement)
            && !cast<ContinueStatement *>(lastStatement)) {
        warning(errorLoc, tr("case does not end with return, break, continue or throw"));
    }
}

void Check::error(const AST::SourceLocation &loc, const QString &message)
{
    _messages.append(DiagnosticMessage(DiagnosticMessage::Error, loc, message));
}

void Check::warning(const AST::SourceLocation &loc, const QString &message)
{
    _messages.append(DiagnosticMessage(DiagnosticMessage::Warning, loc, message));
}

Node *Check::parent(int distance)
{
    const int index = _chain.size() - 2 - distance;
    if (index < 0)
        return 0;
    return _chain.at(index);
}