Skip to content

Commit 5765f66

Browse files
committed
moved IteratorInferModel and related classes to infer.{cpp|h}
1 parent 2e2278c commit 5765f66

3 files changed

Lines changed: 43 additions & 28 deletions

File tree

lib/infer.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,44 @@ ValuePtr<InferModel> makeSymbolicInferModel(const Token* token)
435435
return SymbolicInferModel{token};
436436
}
437437

438+
namespace {
439+
struct IteratorInferModel : InferModel {
440+
virtual ValueFlow::Value::ValueType getType() const = 0;
441+
bool match(const ValueFlow::Value& value) const override {
442+
return value.valueType == getType();
443+
}
444+
ValueFlow::Value yield(MathLib::bigint value) const override
445+
{
446+
ValueFlow::Value result(value);
447+
result.valueType = getType();
448+
result.setKnown();
449+
return result;
450+
}
451+
};
452+
453+
struct EndIteratorInferModel : IteratorInferModel {
454+
ValueFlow::Value::ValueType getType() const override {
455+
return ValueFlow::Value::ValueType::ITERATOR_END;
456+
}
457+
};
458+
459+
struct StartIteratorInferModel : IteratorInferModel {
460+
ValueFlow::Value::ValueType getType() const override {
461+
return ValueFlow::Value::ValueType::ITERATOR_END;
462+
}
463+
};
464+
}
465+
466+
ValuePtr<InferModel> makeEndIteratorInferModel()
467+
{
468+
return EndIteratorInferModel{};
469+
}
470+
471+
ValuePtr<InferModel> makeStartIteratorInferModel()
472+
{
473+
return StartIteratorInferModel{};
474+
}
475+
438476
ValueFlow::Value inferCondition(const std::string& op, const Token* varTok, MathLib::bigint val)
439477
{
440478
if (!varTok)

lib/infer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ ValuePtr<InferModel> makeIntegralInferModel();
6565

6666
ValuePtr<InferModel> makeSymbolicInferModel(const Token* token);
6767

68+
ValuePtr<InferModel> makeEndIteratorInferModel();
69+
ValuePtr<InferModel> makeStartIteratorInferModel();
70+
6871
ValueFlow::Value inferCondition(const std::string& op, const Token* varTok, MathLib::bigint val);
6972

7073
#endif

lib/valueflow.cpp

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5113,32 +5113,6 @@ struct SimpleConditionHandler : ConditionHandler {
51135113
}
51145114
};
51155115

5116-
struct IteratorInferModel : InferModel {
5117-
virtual ValueFlow::Value::ValueType getType() const = 0;
5118-
bool match(const ValueFlow::Value& value) const override {
5119-
return value.valueType == getType();
5120-
}
5121-
ValueFlow::Value yield(MathLib::bigint value) const override
5122-
{
5123-
ValueFlow::Value result(value);
5124-
result.valueType = getType();
5125-
result.setKnown();
5126-
return result;
5127-
}
5128-
};
5129-
5130-
struct EndIteratorInferModel : IteratorInferModel {
5131-
ValueFlow::Value::ValueType getType() const override {
5132-
return ValueFlow::Value::ValueType::ITERATOR_END;
5133-
}
5134-
};
5135-
5136-
struct StartIteratorInferModel : IteratorInferModel {
5137-
ValueFlow::Value::ValueType getType() const override {
5138-
return ValueFlow::Value::ValueType::ITERATOR_END;
5139-
}
5140-
};
5141-
51425116
static bool isIntegralOnlyOperator(const Token* tok) {
51435117
return Token::Match(tok, "%|<<|>>|&|^|~|%or%");
51445118
}
@@ -5174,8 +5148,8 @@ static void valueFlowInferCondition(TokenList& tokenlist, const Settings& settin
51745148
continue;
51755149
if (Token::Match(tok, "%comp%|-") && tok->astOperand1() && tok->astOperand2()) {
51765150
if (astIsIterator(tok->astOperand1()) || astIsIterator(tok->astOperand2())) {
5177-
static const std::array<ValuePtr<InferModel>, 2> iteratorModels = {EndIteratorInferModel{},
5178-
StartIteratorInferModel{}};
5151+
static const std::array<ValuePtr<InferModel>, 2> iteratorModels = {makeEndIteratorInferModel(),
5152+
makeStartIteratorInferModel()};
51795153
for (const ValuePtr<InferModel>& model : iteratorModels) {
51805154
std::vector<ValueFlow::Value> result =
51815155
infer(model, tok->str(), tok->astOperand1()->values(), tok->astOperand2()->values());

0 commit comments

Comments
 (0)