Example #1
0
// checks if side effects happen on the variable prior to tmp
void CheckAssert::checkVariableAssignment(const Token* assignTok)
{
    const Variable* v = assignTok->previous()->variable();
    if (!v) return;

    // assignment
    if (assignTok->isAssignmentOp() || assignTok->type() == Token::eIncDecOp) {

        if (v->isConst()) return;

        assignmentInAssertError(assignTok, v->name());
    }
    // TODO: function calls on v
}
Example #2
0
// checks if side effects happen on the variable prior to tmp
bool CheckAssert::checkVariableAssignment(const Token* assignTok, bool reportError /*= true*/)
{
    const Variable* v = assignTok->previous()->variable();
    if (!v) return false;

    // assignment
    if (assignTok->isAssignmentOp() || assignTok->type() == Token::eIncDecOp) {

        if (v->isConst()) return false;

        if (reportError) // report as variable assignment error
            assignmentInAssertError(assignTok, v->name());

        return true;
    }
    return false;
    // TODO: function calls on v
}
Example #3
0
// checks if side effects happen on the variable prior to tmp
void CheckAssert::checkVariableAssignment(const Token* assignTok, const Scope *assertionScope)
{
    const Variable* prevVar = assignTok->previous()->variable();
    if (!prevVar)
        return;

    // Variable declared in inner scope in assert => dont warn
    if (assertionScope != prevVar->scope()) {
        const Scope *s = prevVar->scope();
        while (s && s != assertionScope)
            s = s->nestedIn;
        if (s == assertionScope)
            return;
    }

    // assignment
    if (assignTok->isAssignmentOp() || assignTok->tokType() == Token::eIncDecOp) {
        if (prevVar->isConst())
            return;

        assignmentInAssertError(assignTok, prevVar->name());
    }
    // TODO: function calls on prevVar
}