Skip to content

Commit 0cbdac2

Browse files
committed
moved IteratorInferModel and related classes to infer.{cpp|h}
1 parent 607c3b5 commit 0cbdac2

File tree

5 files changed

+45
-32
lines changed

5 files changed

+45
-32
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ $(libcppdir)/vf_globalstaticvar.o: lib/vf_globalstaticvar.cpp lib/astutils.h lib
708708
$(libcppdir)/vf_impossiblevalues.o: lib/vf_impossiblevalues.cpp lib/astutils.h lib/calculate.h lib/config.h lib/errortypes.h lib/library.h lib/mathlib.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/vf_impossiblevalues.h lib/vf_settokenvalue.h lib/vfvalue.h
709709
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_impossiblevalues.cpp
710710

711-
$(libcppdir)/vf_infercondition.o: lib/vf_infercondition.cpp lib/astutils.h lib/config.h lib/errortypes.h lib/infer.h lib/library.h lib/mathlib.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/valueflow.h lib/valueptr.h lib/vf_infercondition.h lib/vf_settokenvalue.h lib/vfvalue.h
711+
$(libcppdir)/vf_infercondition.o: lib/vf_infercondition.cpp lib/astutils.h lib/config.h lib/errortypes.h lib/infer.h lib/library.h lib/mathlib.h lib/smallvector.h lib/sourcelocation.h lib/standards.h lib/symboldatabase.h lib/templatesimplifier.h lib/token.h lib/tokenlist.h lib/utils.h lib/valueptr.h lib/vf_infercondition.h lib/vf_settokenvalue.h lib/vfvalue.h
712712
$(CXX) ${INCLUDE_FOR_LIB} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_infercondition.cpp
713713

714714
$(libcppdir)/vf_iteratorinfer.o: lib/vf_iteratorinfer.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/tokenlist.h lib/utils.h lib/vf_common.h lib/vf_iteratorinfer.h lib/vf_settokenvalue.h lib/vfvalue.h

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)

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

lib/vf_infercondition.cpp

+2-30
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,8 @@
2020

2121
#include "astutils.h"
2222
#include "infer.h"
23-
#include "mathlib.h"
2423
#include "token.h"
2524
#include "tokenlist.h"
26-
#include "valueflow.h"
2725
#include "valueptr.h"
2826
#include "vfvalue.h"
2927

@@ -36,32 +34,6 @@
3634

3735
namespace ValueFlow
3836
{
39-
struct IteratorInferModel : InferModel {
40-
virtual Value::ValueType getType() const = 0;
41-
bool match(const Value& value) const override {
42-
return value.valueType == getType();
43-
}
44-
Value yield(MathLib::bigint value) const override
45-
{
46-
Value result(value);
47-
result.valueType = getType();
48-
result.setKnown();
49-
return result;
50-
}
51-
};
52-
53-
struct EndIteratorInferModel : IteratorInferModel {
54-
Value::ValueType getType() const override {
55-
return Value::ValueType::ITERATOR_END;
56-
}
57-
};
58-
59-
struct StartIteratorInferModel : IteratorInferModel {
60-
Value::ValueType getType() const override {
61-
return Value::ValueType::ITERATOR_END;
62-
}
63-
};
64-
6537
static bool isIntegralOnlyOperator(const Token* tok) {
6638
return Token::Match(tok, "%|<<|>>|&|^|~|%or%");
6739
}
@@ -97,8 +69,8 @@ namespace ValueFlow
9769
continue;
9870
if (Token::Match(tok, "%comp%|-") && tok->astOperand1() && tok->astOperand2()) {
9971
if (astIsIterator(tok->astOperand1()) || astIsIterator(tok->astOperand2())) {
100-
static const std::array<ValuePtr<InferModel>, 2> iteratorModels = {EndIteratorInferModel{},
101-
StartIteratorInferModel{}};
72+
static const std::array<ValuePtr<InferModel>, 2> iteratorModels = {makeEndIteratorInferModel(),
73+
makeStartIteratorInferModel()};
10274
for (const ValuePtr<InferModel>& model : iteratorModels) {
10375
std::vector<Value> result =
10476
infer(model, tok->str(), tok->astOperand1()->values(), tok->astOperand2()->values());

oss-fuzz/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ $(libcppdir)/vf_globalstaticvar.o: ../lib/vf_globalstaticvar.cpp ../lib/astutils
395395
$(libcppdir)/vf_impossiblevalues.o: ../lib/vf_impossiblevalues.cpp ../lib/astutils.h ../lib/calculate.h ../lib/config.h ../lib/errortypes.h ../lib/library.h ../lib/mathlib.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenlist.h ../lib/utils.h ../lib/vf_impossiblevalues.h ../lib/vf_settokenvalue.h ../lib/vfvalue.h
396396
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_impossiblevalues.cpp
397397

398-
$(libcppdir)/vf_infercondition.o: ../lib/vf_infercondition.cpp ../lib/astutils.h ../lib/config.h ../lib/errortypes.h ../lib/infer.h ../lib/library.h ../lib/mathlib.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenlist.h ../lib/utils.h ../lib/valueflow.h ../lib/valueptr.h ../lib/vf_infercondition.h ../lib/vf_settokenvalue.h ../lib/vfvalue.h
398+
$(libcppdir)/vf_infercondition.o: ../lib/vf_infercondition.cpp ../lib/astutils.h ../lib/config.h ../lib/errortypes.h ../lib/infer.h ../lib/library.h ../lib/mathlib.h ../lib/smallvector.h ../lib/sourcelocation.h ../lib/standards.h ../lib/symboldatabase.h ../lib/templatesimplifier.h ../lib/token.h ../lib/tokenlist.h ../lib/utils.h ../lib/valueptr.h ../lib/vf_infercondition.h ../lib/vf_settokenvalue.h ../lib/vfvalue.h
399399
$(CXX) ${LIB_FUZZING_ENGINE} $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $(libcppdir)/vf_infercondition.cpp
400400

401401
$(libcppdir)/vf_iteratorinfer.o: ../lib/vf_iteratorinfer.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/tokenlist.h ../lib/utils.h ../lib/vf_common.h ../lib/vf_iteratorinfer.h ../lib/vf_settokenvalue.h ../lib/vfvalue.h

0 commit comments

Comments
 (0)