Skip to content

Commit 10cf643

Browse files
committed
moved IteratorInferModel and related classes to infer.{cpp|h}
1 parent 0ca5c58 commit 10cf643

File tree

3 files changed

+43
-28
lines changed

3 files changed

+43
-28
lines changed

Diff for: lib/infer.cpp

+38
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,44 @@ ValuePtr<InferModel> makeSymbolicInferModel(const Token* token)
434434
return SymbolicInferModel{token};
435435
}
436436

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

Diff for: lib/infer.h

+3
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ ValuePtr<InferModel> makeIntegralInferModel();
6161

6262
ValuePtr<InferModel> makeSymbolicInferModel(const Token* token);
6363

64+
ValuePtr<InferModel> makeEndIteratorInferModel();
65+
ValuePtr<InferModel> makeStartIteratorInferModel();
66+
6467
ValueFlow::Value inferCondition(const std::string& op, const Token* varTok, MathLib::bigint val);
6568

6669
#endif

Diff for: lib/valueflow.cpp

+2-28
Original file line numberDiff line numberDiff line change
@@ -4900,32 +4900,6 @@ struct SimpleConditionHandler : ConditionHandler {
49004900
}
49014901
};
49024902

4903-
struct IteratorInferModel : InferModel {
4904-
virtual ValueFlow::Value::ValueType getType() const = 0;
4905-
bool match(const ValueFlow::Value& value) const override {
4906-
return value.valueType == getType();
4907-
}
4908-
ValueFlow::Value yield(MathLib::bigint value) const override
4909-
{
4910-
ValueFlow::Value result(value);
4911-
result.valueType = getType();
4912-
result.setKnown();
4913-
return result;
4914-
}
4915-
};
4916-
4917-
struct EndIteratorInferModel : IteratorInferModel {
4918-
ValueFlow::Value::ValueType getType() const override {
4919-
return ValueFlow::Value::ValueType::ITERATOR_END;
4920-
}
4921-
};
4922-
4923-
struct StartIteratorInferModel : IteratorInferModel {
4924-
ValueFlow::Value::ValueType getType() const override {
4925-
return ValueFlow::Value::ValueType::ITERATOR_END;
4926-
}
4927-
};
4928-
49294903
static bool isIntegralOnlyOperator(const Token* tok) {
49304904
return Token::Match(tok, "%|<<|>>|&|^|~|%or%");
49314905
}
@@ -4961,8 +4935,8 @@ static void valueFlowInferCondition(TokenList& tokenlist, const Settings& settin
49614935
continue;
49624936
if (Token::Match(tok, "%comp%|-") && tok->astOperand1() && tok->astOperand2()) {
49634937
if (astIsIterator(tok->astOperand1()) || astIsIterator(tok->astOperand2())) {
4964-
static const std::array<ValuePtr<InferModel>, 2> iteratorModels = {EndIteratorInferModel{},
4965-
StartIteratorInferModel{}};
4938+
static const std::array<ValuePtr<InferModel>, 2> iteratorModels = {makeEndIteratorInferModel(),
4939+
makeStartIteratorInferModel()};
49664940
for (const ValuePtr<InferModel>& model : iteratorModels) {
49674941
std::vector<ValueFlow::Value> result =
49684942
infer(model, tok->str(), tok->astOperand1()->values(), tok->astOperand2()->values());

0 commit comments

Comments
 (0)