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

Function parseComparison

lib/checkcondition.cpp:1072–1117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1070}
1071
1072static bool parseComparison(const Token *comp, bool &not1, std::string &op, std::string &value, const Token *&expr, bool &inconclusive)
1073{
1074 not1 = false;
1075 while (comp && comp->str() == "!") {
1076 not1 = !not1;
1077 comp = comp->astOperand1();
1078 }
1079
1080 if (!comp)
1081 return false;
1082
1083 const Token* op1 = comp->astOperand1();
1084 const Token* op2 = comp->astOperand2();
1085 if (!comp->isComparisonOp() || !op1 || !op2) {
1086 op = "!=";
1087 value = "0";
1088 expr = comp;
1089 } else if (op1->isLiteral()) {
1090 if (op1->isExpandedMacro())
1091 return false;
1092 op = invertOperatorForOperandSwap(comp->str());
1093 if (op1->enumerator() && op1->enumerator()->value_known)
1094 value = MathLib::toString(op1->enumerator()->value);
1095 else
1096 value = op1->str();
1097 expr = op2;
1098 } else if (comp->astOperand2()->isLiteral()) {
1099 if (op2->isExpandedMacro())
1100 return false;
1101 op = comp->str();
1102 if (op2->enumerator() && op2->enumerator()->value_known)
1103 value = MathLib::toString(op2->enumerator()->value);
1104 else
1105 value = op2->str();
1106 expr = op1;
1107 } else {
1108 op = "!=";
1109 value = "0";
1110 expr = comp;
1111 }
1112
1113 inconclusive = inconclusive || (value[0] == '\'' && !(op == "!=" || op == "=="));
1114
1115 // Only float and int values are currently handled
1116 return MathLib::isInt(value) || MathLib::isFloat(value) || (value[0] == '\'');
1117}
1118
1119static std::string conditionString(bool not1, const Token *expr1, const std::string &op, const std::string &value1)
1120{

Callers 2

conditionStringFunction · 0.85

Calls 6

isFloatFunction · 0.85
astOperand1Method · 0.80
astOperand2Method · 0.80
toStringFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected