ValueFlow: For convenience, return constant folded value

This commit is contained in:
Daniel Marjamäki 2016-05-08 11:17:10 +02:00
parent b26dd1ccab
commit b94eaeca6a
2 changed files with 8 additions and 7 deletions

View File

@ -2377,13 +2377,14 @@ static void valueFlowFunctionReturn(TokenList *tokenlist, ErrorLogger *errorLogg
}
}
void ValueFlow::valueFlowConstantFoldAST(const Token *expr)
const ValueFlow::Value *ValueFlow::valueFlowConstantFoldAST(const Token *expr)
{
if (!expr || !expr->values.empty())
return;
if (expr && expr->values.empty()) {
valueFlowConstantFoldAST(expr->astOperand1());
valueFlowConstantFoldAST(expr->astOperand2());
valueFlowSetConstantValue(expr);
}
return expr && expr->values.size() == 1U && expr->values.front().isKnown() ? &expr->values.front() : nullptr;
}

View File

@ -95,7 +95,7 @@ namespace ValueFlow {
};
/// Constant folding of expression. This can be used before the full ValueFlow has been executed (ValueFlow::setValues).
void valueFlowConstantFoldAST(const Token *expr);
const ValueFlow::Value * valueFlowConstantFoldAST(const Token *expr);
/// Perform valueflow analysis.
void setValues(TokenList *tokenlist, SymbolDatabase* symboldatabase, ErrorLogger *errorLogger, const Settings *settings);