MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / valueFlowEnumValue

Function valueFlowEnumValue

lib/valueflow.cpp:1181–1206  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1179}
1180
1181static void valueFlowEnumValue(SymbolDatabase & symboldatabase, const Settings & settings)
1182{
1183 for (Scope & scope : symboldatabase.scopeList) {
1184 if (scope.type != ScopeType::eEnum)
1185 continue;
1186 MathLib::bigint value = 0;
1187 bool prev_enum_is_known = true;
1188
1189 for (Enumerator & enumerator : scope.enumeratorList) {
1190 if (enumerator.start) {
1191 auto* rhs = const_cast<Token*>(enumerator.start->previous()->astOperand2());
1192 ValueFlow::valueFlowConstantFoldAST(rhs, settings);
1193 if (rhs && rhs->hasKnownIntValue()) {
1194 enumerator.value = rhs->getKnownIntValue();
1195 enumerator.value_known = true;
1196 value = enumerator.value + 1;
1197 prev_enum_is_known = true;
1198 } else
1199 prev_enum_is_known = false;
1200 } else if (prev_enum_is_known) {
1201 enumerator.value = value++;
1202 enumerator.value_known = true;
1203 }
1204 }
1205 }
1206}
1207
1208// trampoline to generate unique timer results entry
1209static void valueFlowEnumValueEarly(SymbolDatabase & symboldatabase, const Settings & settings)

Callers 2

valueFlowEnumValueEarlyFunction · 0.85
setValuesMethod · 0.85

Calls 3

astOperand2Method · 0.80
getKnownIntValueMethod · 0.80
hasKnownIntValueMethod · 0.45

Tested by

no test coverage detected