Skip to content

Commit

Permalink
reverted remaining Valueflow changes (#7040)
Browse files Browse the repository at this point in the history
Move `valueFlowNumber` and `valueFlowEnumValue` back to valueflow.cpp
and remove the unused header files.
  • Loading branch information
pfultz2 authored Nov 26, 2024
1 parent c063121 commit 93ea424
Show file tree
Hide file tree
Showing 24 changed files with 57 additions and 679 deletions.
10 changes: 1 addition & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,6 @@ LIBOBJ = $(libcppdir)/valueflow.o \
$(libcppdir)/utils.o \
$(libcppdir)/vf_analyzers.o \
$(libcppdir)/vf_common.o \
$(libcppdir)/vf_enumvalue.o \
$(libcppdir)/vf_number.o \
$(libcppdir)/vf_settokenvalue.o \
$(libcppdir)/vfvalue.o

Expand Down Expand Up @@ -459,7 +457,7 @@ validateRules:

###### Build

$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/addoninfo.h lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/findtoken.h lib/forwardanalyzer.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vf_analyze.h lib/vf_analyzers.h lib/vf_common.h lib/vf_enumvalue.h lib/vf_number.h lib/vf_settokenvalue.h lib/vfvalue.h
$(libcppdir)/valueflow.o: lib/valueflow.cpp lib/addoninfo.h lib/analyzer.h lib/astutils.h lib/calculate.h lib/check.h lib/checkuninitvar.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/findtoken.h lib/forwardanalyzer.h lib/infer.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/programmemory.h lib/reverseanalyzer.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vf_analyzers.h lib/vf_common.h lib/vf_settokenvalue.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/valueflow.cpp

$(libcppdir)/tokenize.o: lib/tokenize.cpp externals/simplecpp/simplecpp.h lib/addoninfo.h lib/astutils.h lib/color.h lib/config.h lib/errorlogger.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/preprocessor.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/summaries.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/timer.h lib/token.h lib/tokenize.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/vfvalue.h
Expand Down Expand Up @@ -657,12 +655,6 @@ $(libcppdir)/vf_analyzers.o: lib/vf_analyzers.cpp lib/addoninfo.h lib/analyzer.h
$(libcppdir)/vf_common.o: lib/vf_common.cpp lib/addoninfo.h lib/astutils.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/path.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueflow.h lib/vf_common.h lib/vf_settokenvalue.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_common.cpp

$(libcppdir)/vf_enumvalue.o: lib/vf_enumvalue.cpp lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueflow.h lib/vf_enumvalue.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_enumvalue.cpp

$(libcppdir)/vf_number.o: lib/vf_number.cpp lib/addoninfo.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vf_common.h lib/vf_number.h lib/vf_settokenvalue.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_number.cpp

$(libcppdir)/vf_settokenvalue.o: lib/vf_settokenvalue.cpp lib/addoninfo.h lib/astutils.h lib/calculate.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/platform.h lib/settings.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/suppressions.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/utils.h lib/valueflow.h lib/vf_common.h lib/vf_settokenvalue.h lib/vfvalue.h
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_settokenvalue.cpp

Expand Down
4 changes: 0 additions & 4 deletions lib/cppcheck.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,6 @@
<ClCompile Include="utils.cpp" />
<ClCompile Include="vf_analyzers.cpp" />
<ClCompile Include="vf_common.cpp" />
<ClCompile Include="vf_enumvalue.cpp" />
<ClCompile Include="vf_number.cpp" />
<ClCompile Include="vf_settokenvalue.cpp" />
<ClCompile Include="vfvalue.cpp" />
</ItemGroup>
Expand Down Expand Up @@ -179,8 +177,6 @@
<ClInclude Include="vf_analyze.h" />
<ClInclude Include="vf_analyzers.h" />
<ClInclude Include="vf_common.h" />
<ClInclude Include="vf_enumvalue.h" />
<ClInclude Include="vf_number.h" />
<ClInclude Include="vf_settokenvalue.h" />
<ClInclude Include="vfvalue.h" />
<ClInclude Include="xml.h" />
Expand Down
59 changes: 55 additions & 4 deletions lib/valueflow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
#include "valueptr.h"
#include "vfvalue.h"

#include "vf_analyze.h"
#include "vf_analyzers.h"
#include "vf_common.h"
#include "vf_settokenvalue.h"
Expand Down Expand Up @@ -555,6 +554,31 @@ size_t ValueFlow::getSizeOf(const ValueType &vt, const Settings &settings, int m
return 0;
}

static void valueFlowNumber(TokenList &tokenlist, const Settings& settings)
{
for (Token *tok = tokenlist.front(); tok;) {
tok = ValueFlow::valueFlowSetConstantValue(tok, settings);
}

if (tokenlist.isCPP() || settings.standards.c >= Standards::C23) {
for (Token *tok = tokenlist.front(); tok; tok = tok->next()) {
if (tok->isName() && !tok->varId() && Token::Match(tok, "false|true")) {
ValueFlow::Value value(tok->str() == "true");
if (!tok->isTemplateArg())
value.setKnown();
setTokenValue(tok, std::move(value), settings);
} else if (Token::Match(tok, "[(,] NULL [,)]")) {
// NULL function parameters are not simplified in the
// normal tokenlist
ValueFlow::Value value(0);
if (!tok->isTemplateArg())
value.setKnown();
setTokenValue(tok->next(), std::move(value), settings);
}
}
}
}

static void valueFlowString(TokenList& tokenlist, const Settings& settings)
{
for (Token* tok = tokenlist.front(); tok; tok = tok->next()) {
Expand Down Expand Up @@ -1113,6 +1137,33 @@ static void valueFlowImpossibleValues(TokenList& tokenList, const Settings& sett
}
}

static void valueFlowEnumValue(SymbolDatabase & symboldatabase, const Settings & settings)
{
for (Scope & scope : symboldatabase.scopeList) {
if (scope.type != Scope::eEnum)
continue;
MathLib::bigint value = 0;
bool prev_enum_is_known = true;

for (Enumerator & enumerator : scope.enumeratorList) {
if (enumerator.start) {
auto* rhs = const_cast<Token*>(enumerator.start->previous()->astOperand2());
ValueFlow::valueFlowConstantFoldAST(rhs, settings);
if (rhs && rhs->hasKnownIntValue()) {
enumerator.value = rhs->values().front().intvalue;
enumerator.value_known = true;
value = enumerator.value + 1;
prev_enum_is_known = true;
} else
prev_enum_is_known = false;
} else if (prev_enum_is_known) {
enumerator.value = value++;
enumerator.value_known = true;
}
}
}
}

static void valueFlowGlobalConstVar(TokenList& tokenList, const Settings& settings)
{
// Get variable values...
Expand Down Expand Up @@ -7164,13 +7215,13 @@ void ValueFlow::setValues(TokenList& tokenlist,

ValueFlowPassRunner runner{ValueFlowState{tokenlist, symboldatabase, errorLogger, settings}, timerResults};
runner.run_once({
VFA(analyzeEnumValue(symboldatabase, settings)),
VFA(analyzeNumber(tokenlist, settings)),
VFA(valueFlowEnumValue(symboldatabase, settings)),
VFA(valueFlowNumber(tokenlist, settings)),
VFA(valueFlowString(tokenlist, settings)),
VFA(valueFlowArray(tokenlist, settings)),
VFA(valueFlowUnknownFunctionReturn(tokenlist, settings)),
VFA(valueFlowGlobalConstVar(tokenlist, settings)),
VFA(analyzeEnumValue(symboldatabase, settings)),
VFA(valueFlowEnumValue(symboldatabase, settings)),
VFA(valueFlowGlobalStaticVar(tokenlist, settings)),
VFA(valueFlowPointerAlias(tokenlist, settings)),
VFA(valueFlowLifetime(tokenlist, errorLogger, settings)),
Expand Down
25 changes: 0 additions & 25 deletions lib/vf_analyze.h

This file was deleted.

30 changes: 0 additions & 30 deletions lib/vf_array.h

This file was deleted.

30 changes: 0 additions & 30 deletions lib/vf_arraybool.h

This file was deleted.

30 changes: 0 additions & 30 deletions lib/vf_arrayelement.h

This file was deleted.

30 changes: 0 additions & 30 deletions lib/vf_bitand.h

This file was deleted.

31 changes: 0 additions & 31 deletions lib/vf_debug.h

This file was deleted.

58 changes: 0 additions & 58 deletions lib/vf_enumvalue.cpp

This file was deleted.

Loading

0 comments on commit 93ea424

Please sign in to comment.