From b94eaeca6aaae8d15b795d41c813a1902c64afab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 8 May 2016 11:17:10 +0200 Subject: [PATCH] ValueFlow: For convenience, return constant folded value --- lib/valueflow.cpp | 13 +++++++------ lib/valueflow.h | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/valueflow.cpp b/lib/valueflow.cpp index b822eefc2..213a37e3f 100644 --- a/lib/valueflow.cpp +++ b/lib/valueflow.cpp @@ -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; - valueFlowConstantFoldAST(expr->astOperand1()); - valueFlowConstantFoldAST(expr->astOperand2()); - valueFlowSetConstantValue(expr); + 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; } diff --git a/lib/valueflow.h b/lib/valueflow.h index 1beec7934..643a2c227 100644 --- a/lib/valueflow.h +++ b/lib/valueflow.h @@ -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);