astyle formatting

This commit is contained in:
Daniel Marjamäki 2020-11-11 09:15:36 +01:00
parent 829c543331
commit 7182da5c8e
8 changed files with 139 additions and 130 deletions

View File

@ -44,43 +44,65 @@ struct Analyzer {
Idempotent = (1 << 5), Idempotent = (1 << 5),
}; };
void set(unsigned int f, bool state = true) { mFlag = state ? mFlag | f : mFlag & ~f; } void set(unsigned int f, bool state = true) {
mFlag = state ? mFlag | f : mFlag & ~f;
}
bool get(unsigned int f) const { return ((mFlag & f) != 0); } bool get(unsigned int f) const {
return ((mFlag & f) != 0);
}
bool isRead() const { return get(Read); } bool isRead() const {
return get(Read);
}
bool isWrite() const { return get(Write); } bool isWrite() const {
return get(Write);
}
bool isInvalid() const { return get(Invalid); } bool isInvalid() const {
return get(Invalid);
}
bool isInconclusive() const { return get(Inconclusive); } bool isInconclusive() const {
return get(Inconclusive);
}
bool isNone() const { return mFlag == None; } bool isNone() const {
return mFlag == None;
}
bool isModified() const { return isWrite() || isInvalid(); } bool isModified() const {
return isWrite() || isInvalid();
}
bool isIdempotent() const { return get(Idempotent); } bool isIdempotent() const {
return get(Idempotent);
}
bool matches() const { return get(Match); } bool matches() const {
return get(Match);
}
Action& operator|=(Action a) Action& operator|=(Action a) {
{
set(a.mFlag); set(a.mFlag);
return *this; return *this;
} }
friend Action operator|(Action a, Action b) friend Action operator|(Action a, Action b) {
{
a |= b; a |= b;
return a; return a;
} }
friend bool operator==(Action a, Action b) { return a.mFlag == b.mFlag; } friend bool operator==(Action a, Action b) {
return a.mFlag == b.mFlag;
}
friend bool operator!=(Action a, Action b) { return a.mFlag != b.mFlag; } friend bool operator!=(Action a, Action b) {
return a.mFlag != b.mFlag;
}
private: private:
unsigned int mFlag; unsigned int mFlag;
}; };

View File

@ -315,8 +315,14 @@ static T* previousBeforeAstLeftmostLeafGeneric(T* tok)
return leftmostLeaf->previous(); return leftmostLeaf->previous();
} }
const Token* previousBeforeAstLeftmostLeaf(const Token* tok) { return previousBeforeAstLeftmostLeafGeneric(tok); } const Token* previousBeforeAstLeftmostLeaf(const Token* tok)
Token* previousBeforeAstLeftmostLeaf(Token* tok) { return previousBeforeAstLeftmostLeafGeneric(tok); } {
return previousBeforeAstLeftmostLeafGeneric(tok);
}
Token* previousBeforeAstLeftmostLeaf(Token* tok)
{
return previousBeforeAstLeftmostLeafGeneric(tok);
}
template <class T, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*>)> template <class T, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*>)>
static T* nextAfterAstRightmostLeafGeneric(T* tok) static T* nextAfterAstRightmostLeafGeneric(T* tok)

View File

@ -26,8 +26,12 @@ struct ForwardTraversal {
std::pair<bool, bool> evalCond(const Token* tok) { std::pair<bool, bool> evalCond(const Token* tok) {
std::vector<int> result = analyzer->evaluate(tok); std::vector<int> result = analyzer->evaluate(tok);
// TODO: We should convert to bool // TODO: We should convert to bool
bool checkThen = std::any_of(result.begin(), result.end(), [](int x) { return x == 1; }); bool checkThen = std::any_of(result.begin(), result.end(), [](int x) {
bool checkElse = std::any_of(result.begin(), result.end(), [](int x) { return x == 0; }); return x == 1;
});
bool checkElse = std::any_of(result.begin(), result.end(), [](int x) {
return x == 0;
});
return std::make_pair(checkThen, checkElse); return std::make_pair(checkThen, checkElse);
} }
@ -150,8 +154,7 @@ struct ForwardTraversal {
} }
template <class T> template <class T>
T* findRange(T* start, const Token* end, std::function<bool(Analyzer::Action)> pred) T* findRange(T* start, const Token* end, std::function<bool(Analyzer::Action)> pred) {
{
for (T* tok = start; tok && tok != end; tok = tok->next()) { for (T* tok = start; tok && tok != end; tok = tok->next()) {
Analyzer::Action action = analyzer->analyze(tok, Analyzer::Direction::Forward); Analyzer::Action action = analyzer->analyze(tok, Analyzer::Direction::Forward);
if (pred(action)) if (pred(action))
@ -160,8 +163,7 @@ struct ForwardTraversal {
return nullptr; return nullptr;
} }
Analyzer::Action analyzeRecursive(const Token* start) Analyzer::Action analyzeRecursive(const Token* start) {
{
Analyzer::Action result = Analyzer::Action::None; Analyzer::Action result = Analyzer::Action::None;
std::function<Progress(const Token*)> f = [&](const Token* tok) { std::function<Progress(const Token*)> f = [&](const Token* tok) {
result = analyzer->analyze(tok, Analyzer::Direction::Forward); result = analyzer->analyze(tok, Analyzer::Direction::Forward);
@ -173,8 +175,7 @@ struct ForwardTraversal {
return result; return result;
} }
Analyzer::Action analyzeRange(const Token* start, const Token* end) Analyzer::Action analyzeRange(const Token* start, const Token* end) {
{
Analyzer::Action result = Analyzer::Action::None; Analyzer::Action result = Analyzer::Action::None;
for (const Token* tok = start; tok && tok != end; tok = tok->next()) { for (const Token* tok = start; tok && tok != end; tok = tok->next()) {
Analyzer::Action action = analyzer->analyze(tok, Analyzer::Direction::Forward); Analyzer::Action action = analyzer->analyze(tok, Analyzer::Direction::Forward);
@ -211,17 +212,17 @@ struct ForwardTraversal {
Inconclusive, Inconclusive,
}; };
Analyzer::Action analyzeScope(const Token* endBlock) { return analyzeRange(endBlock->link(), endBlock); } Analyzer::Action analyzeScope(const Token* endBlock) {
return analyzeRange(endBlock->link(), endBlock);
}
Analyzer::Action checkScope(Token* endBlock) Analyzer::Action checkScope(Token* endBlock) {
{
Analyzer::Action a = analyzeScope(endBlock); Analyzer::Action a = analyzeScope(endBlock);
forkScope(endBlock, a.isModified()); forkScope(endBlock, a.isModified());
return a; return a;
} }
Analyzer::Action checkScope(const Token* endBlock) Analyzer::Action checkScope(const Token* endBlock) {
{
Analyzer::Action a = analyzeScope(endBlock); Analyzer::Action a = analyzeScope(endBlock);
return a; return a;
} }
@ -568,9 +569,9 @@ struct ForwardTraversal {
}; };
Analyzer::Action valueFlowGenericForward(Token* start, Analyzer::Action valueFlowGenericForward(Token* start,
const Token* end, const Token* end,
const ValuePtr<Analyzer>& a, const ValuePtr<Analyzer>& a,
const Settings* settings) const Settings* settings)
{ {
ForwardTraversal ft{a, settings}; ForwardTraversal ft{a, settings};
ft.updateRange(start, end); ft.updateRange(start, end);

View File

@ -27,9 +27,9 @@ class Token;
template <class T> class ValuePtr; template <class T> class ValuePtr;
Analyzer::Action valueFlowGenericForward(Token* start, Analyzer::Action valueFlowGenericForward(Token* start,
const Token* end, const Token* end,
const ValuePtr<Analyzer>& a, const ValuePtr<Analyzer>& a,
const Settings* settings); const Settings* settings);
Analyzer::Action valueFlowGenericForward(Token* start, const ValuePtr<Analyzer>& a, const Settings* settings); Analyzer::Action valueFlowGenericForward(Token* start, const ValuePtr<Analyzer>& a, const Settings* settings);

View File

@ -17,17 +17,19 @@ struct ReverseTraversal {
ValuePtr<Analyzer> analyzer; ValuePtr<Analyzer> analyzer;
const Settings* settings; const Settings* settings;
std::pair<bool, bool> evalCond(const Token* tok) std::pair<bool, bool> evalCond(const Token* tok) {
{
std::vector<int> result = analyzer->evaluate(tok); std::vector<int> result = analyzer->evaluate(tok);
// TODO: We should convert to bool // TODO: We should convert to bool
bool checkThen = std::any_of(result.begin(), result.end(), [](int x) { return x == 1; }); bool checkThen = std::any_of(result.begin(), result.end(), [](int x) {
bool checkElse = std::any_of(result.begin(), result.end(), [](int x) { return x == 0; }); return x == 1;
});
bool checkElse = std::any_of(result.begin(), result.end(), [](int x) {
return x == 0;
});
return std::make_pair(checkThen, checkElse); return std::make_pair(checkThen, checkElse);
} }
bool update(Token* tok) bool update(Token* tok) {
{
Analyzer::Action action = analyzer->analyze(tok, Analyzer::Direction::Reverse); Analyzer::Action action = analyzer->analyze(tok, Analyzer::Direction::Reverse);
if (!action.isNone()) if (!action.isNone())
analyzer->update(tok, action, Analyzer::Direction::Reverse); analyzer->update(tok, action, Analyzer::Direction::Reverse);
@ -38,8 +40,7 @@ struct ReverseTraversal {
return true; return true;
} }
bool updateRecursive(Token* start) bool updateRecursive(Token* start) {
{
bool continueB = true; bool continueB = true;
visitAstNodes(start, [&](Token* tok) { visitAstNodes(start, [&](Token* tok) {
continueB &= update(tok); continueB &= update(tok);
@ -51,8 +52,7 @@ struct ReverseTraversal {
return continueB; return continueB;
} }
Analyzer::Action analyzeRecursive(const Token* start) Analyzer::Action analyzeRecursive(const Token* start) {
{
Analyzer::Action result = Analyzer::Action::None; Analyzer::Action result = Analyzer::Action::None;
visitAstNodes(start, [&](const Token* tok) { visitAstNodes(start, [&](const Token* tok) {
result |= analyzer->analyze(tok, Analyzer::Direction::Reverse); result |= analyzer->analyze(tok, Analyzer::Direction::Reverse);
@ -63,8 +63,7 @@ struct ReverseTraversal {
return result; return result;
} }
Analyzer::Action analyzeRange(const Token* start, const Token* end) Analyzer::Action analyzeRange(const Token* start, const Token* end) {
{
Analyzer::Action result = Analyzer::Action::None; Analyzer::Action result = Analyzer::Action::None;
for (const Token* tok = start; tok && tok != end; tok = tok->next()) { for (const Token* tok = start; tok && tok != end; tok = tok->next()) {
Analyzer::Action action = analyzer->analyze(tok, Analyzer::Direction::Reverse); Analyzer::Action action = analyzer->analyze(tok, Analyzer::Direction::Reverse);
@ -75,8 +74,7 @@ struct ReverseTraversal {
return result; return result;
} }
Token* isDeadCode(Token* tok) Token* isDeadCode(Token* tok) {
{
int opSide = 0; int opSide = 0;
for (; tok && tok->astParent(); tok = tok->astParent()) { for (; tok && tok->astParent(); tok = tok->astParent()) {
Token* parent = tok->astParent(); Token* parent = tok->astParent();
@ -118,11 +116,10 @@ struct ReverseTraversal {
return nullptr; return nullptr;
} }
void traverse(Token* start) void traverse(Token* start) {
{
for (Token* tok = start->previous(); tok; tok = tok->previous()) { for (Token* tok = start->previous(); tok; tok = tok->previous()) {
if (tok == start || (tok->str() == "{" && (tok->scope()->type == Scope::ScopeType::eFunction || if (tok == start || (tok->str() == "{" && (tok->scope()->type == Scope::ScopeType::eFunction ||
tok->scope()->type == Scope::ScopeType::eLambda))) { tok->scope()->type == Scope::ScopeType::eLambda))) {
break; break;
} }
if (Token::Match(tok, "return|break|continue")) if (Token::Match(tok, "return|break|continue"))
@ -256,8 +253,7 @@ struct ReverseTraversal {
} }
} }
static Token* assignExpr(Token* tok) static Token* assignExpr(Token* tok) {
{
while (tok->astParent() && (astIsRHS(tok) || !tok->astParent()->isBinaryOp())) { while (tok->astParent() && (astIsRHS(tok) || !tok->astParent()->isBinaryOp())) {
if (tok->astParent()->isAssignmentOp()) if (tok->astParent()->isAssignmentOp())
return tok->astParent(); return tok->astParent();
@ -266,8 +262,7 @@ struct ReverseTraversal {
return nullptr; return nullptr;
} }
static Token* isUnevaluated(Token* tok) static Token* isUnevaluated(Token* tok) {
{
if (Token::Match(tok, ")|>") && tok->link()) { if (Token::Match(tok, ")|>") && tok->link()) {
Token* start = tok->link(); Token* start = tok->link();
if (Token::Match(start->previous(), "sizeof|decltype (")) if (Token::Match(start->previous(), "sizeof|decltype ("))

View File

@ -1741,11 +1741,11 @@ static void valueFlowGlobalStaticVar(TokenList *tokenList, const Settings *setti
} }
static Analyzer::Action valueFlowForwardVariable(Token* const startToken, static Analyzer::Action valueFlowForwardVariable(Token* const startToken,
const Token* const endToken, const Token* const endToken,
const Variable* const var, const Variable* const var,
std::list<ValueFlow::Value> values, std::list<ValueFlow::Value> values,
TokenList* const tokenlist, TokenList* const tokenlist,
const Settings* const settings); const Settings* const settings);
// Old deprecated version // Old deprecated version
static void valueFlowForward(Token* startToken, static void valueFlowForward(Token* startToken,
@ -1908,7 +1908,8 @@ static void valueFlowAST(Token *tok, nonneg int varid, const ValueFlow::Value &v
static const std::string& invertAssign(const std::string& assign) static const std::string& invertAssign(const std::string& assign)
{ {
static std::unordered_map<std::string, std::string> lookup = { static std::unordered_map<std::string, std::string> lookup = {
{"+=", "-="}, {"-=", "+="}, {"*=", "/="}, {"/=", "*="}, {"<<=", ">>="}, {">>=", "<<="}, {"^=", "^="}}; {"+=", "-="}, {"-=", "+="}, {"*=", "/="}, {"/=", "*="}, {"<<=", ">>="}, {">>=", "<<="}, {"^=", "^="}
};
static std::string empty = ""; static std::string empty = "";
auto it = lookup.find(assign); auto it = lookup.find(assign);
if (it == lookup.end()) if (it == lookup.end())
@ -2142,8 +2143,7 @@ struct ValueFlowAnalyzer : Analyzer {
return Action::None; return Action::None;
} }
virtual Action isWritable(const Token* tok, Direction d) const virtual Action isWritable(const Token* tok, Direction d) const {
{
const ValueFlow::Value* value = getValue(tok); const ValueFlow::Value* value = getValue(tok);
if (!value) if (!value)
return Action::None; return Action::None;
@ -2179,16 +2179,14 @@ struct ValueFlowAnalyzer : Analyzer {
return Action::None; return Action::None;
} }
static const std::string& getAssign(const Token* tok, Direction d) static const std::string& getAssign(const Token* tok, Direction d) {
{
if (d == Direction::Forward) if (d == Direction::Forward)
return tok->str(); return tok->str();
else else
return invertAssign(tok->str()); return invertAssign(tok->str());
} }
virtual void writeValue(ValueFlow::Value* value, const Token* tok, Direction d) const virtual void writeValue(ValueFlow::Value* value, const Token* tok, Direction d) const {
{
if (!value) if (!value)
return; return;
if (!tok->astParent()) if (!tok->astParent())
@ -2218,8 +2216,7 @@ struct ValueFlowAnalyzer : Analyzer {
} }
} }
virtual Action analyze(const Token* tok, Direction d) const OVERRIDE virtual Action analyze(const Token* tok, Direction d) const OVERRIDE {
{
if (invalid()) if (invalid())
return Action::Invalid; return Action::Invalid;
bool inconclusive = false; bool inconclusive = false;
@ -2306,8 +2303,7 @@ struct ValueFlowAnalyzer : Analyzer {
makeConditional(); makeConditional();
} }
virtual void update(Token* tok, Action a, Direction d) OVERRIDE virtual void update(Token* tok, Action a, Direction d) OVERRIDE {
{
ValueFlow::Value* value = getValue(tok); ValueFlow::Value* value = getValue(tok);
if (!value) if (!value)
return; return;
@ -2324,7 +2320,9 @@ struct ValueFlowAnalyzer : Analyzer {
setTokenValue(tok, *value, getSettings()); setTokenValue(tok, *value, getSettings());
} }
virtual ValuePtr<Analyzer> reanalyze(Token*, const std::string&) const OVERRIDE { return {}; } virtual ValuePtr<Analyzer> reanalyze(Token*, const std::string&) const OVERRIDE {
return {};
}
}; };
ValuePtr<Analyzer> makeAnalyzer(Token* exprTok, const ValueFlow::Value& value, const TokenList* tokenlist); ValuePtr<Analyzer> makeAnalyzer(Token* exprTok, const ValueFlow::Value& value, const TokenList* tokenlist);
@ -2432,8 +2430,7 @@ struct SingleValueFlowAnalyzer : ValueFlowAnalyzer {
return false; return false;
} }
virtual ValuePtr<Analyzer> reanalyze(Token* tok, const std::string& msg) const OVERRIDE virtual ValuePtr<Analyzer> reanalyze(Token* tok, const std::string& msg) const OVERRIDE {
{
ValueFlow::Value newValue = value; ValueFlow::Value newValue = value;
newValue.errorPath.emplace_back(tok, msg); newValue.errorPath.emplace_back(tok, msg);
return makeAnalyzer(tok, newValue, tokenlist); return makeAnalyzer(tok, newValue, tokenlist);
@ -2449,8 +2446,7 @@ struct VariableAnalyzer : SingleValueFlowAnalyzer {
const ValueFlow::Value& val, const ValueFlow::Value& val,
std::vector<const Variable*> paliases, std::vector<const Variable*> paliases,
const TokenList* t) const TokenList* t)
: SingleValueFlowAnalyzer(val, t), var(v) : SingleValueFlowAnalyzer(val, t), var(v) {
{
varids[var->declarationId()] = var; varids[var->declarationId()] = var;
for (const Variable* av:paliases) { for (const Variable* av:paliases) {
if (!av) if (!av)
@ -2500,12 +2496,12 @@ static std::vector<const Variable*> getAliasesFromValues(std::list<ValueFlow::Va
} }
static Analyzer::Action valueFlowForwardVariable(Token* const startToken, static Analyzer::Action valueFlowForwardVariable(Token* const startToken,
const Token* const endToken, const Token* const endToken,
const Variable* const var, const Variable* const var,
std::list<ValueFlow::Value> values, std::list<ValueFlow::Value> values,
std::vector<const Variable*> aliases, std::vector<const Variable*> aliases,
TokenList* const tokenlist, TokenList* const tokenlist,
const Settings* const settings) const Settings* const settings)
{ {
Analyzer::Action actions; Analyzer::Action actions;
for (ValueFlow::Value& v : values) { for (ValueFlow::Value& v : values) {
@ -2516,11 +2512,11 @@ static Analyzer::Action valueFlowForwardVariable(Token* const startToken,
} }
static Analyzer::Action valueFlowForwardVariable(Token* const startToken, static Analyzer::Action valueFlowForwardVariable(Token* const startToken,
const Token* const endToken, const Token* const endToken,
const Variable* const var, const Variable* const var,
std::list<ValueFlow::Value> values, std::list<ValueFlow::Value> values,
TokenList* const tokenlist, TokenList* const tokenlist,
const Settings* const settings) const Settings* const settings)
{ {
return valueFlowForwardVariable( return valueFlowForwardVariable(
startToken, endToken, var, std::move(values), getAliasesFromValues(values), tokenlist, settings); startToken, endToken, var, std::move(values), getAliasesFromValues(values), tokenlist, settings);
@ -2550,8 +2546,7 @@ struct ExpressionAnalyzer : SingleValueFlowAnalyzer {
ExpressionAnalyzer() : SingleValueFlowAnalyzer(), expr(nullptr), local(true), unknown(false) {} ExpressionAnalyzer() : SingleValueFlowAnalyzer(), expr(nullptr), local(true), unknown(false) {}
ExpressionAnalyzer(const Token* e, const ValueFlow::Value& val, const TokenList* t) ExpressionAnalyzer(const Token* e, const ValueFlow::Value& val, const TokenList* t)
: SingleValueFlowAnalyzer(val, t), expr(e), local(true), unknown(false) : SingleValueFlowAnalyzer(val, t), expr(e), local(true), unknown(false) {
{
setupExprVarIds(); setupExprVarIds();
} }
@ -2610,11 +2605,11 @@ struct ExpressionAnalyzer : SingleValueFlowAnalyzer {
}; };
static Analyzer::Action valueFlowForwardExpression(Token* startToken, static Analyzer::Action valueFlowForwardExpression(Token* startToken,
const Token* endToken, const Token* endToken,
const Token* exprTok, const Token* exprTok,
const std::list<ValueFlow::Value>& values, const std::list<ValueFlow::Value>& values,
const TokenList* const tokenlist, const TokenList* const tokenlist,
const Settings* settings) const Settings* settings)
{ {
Analyzer::Action actions; Analyzer::Action actions;
for (const ValueFlow::Value& v : values) { for (const ValueFlow::Value& v : values) {
@ -2697,11 +2692,11 @@ ValuePtr<Analyzer> makeAnalyzer(Token* exprTok, const ValueFlow::Value& value, c
} }
static Analyzer::Action valueFlowForward(Token* startToken, static Analyzer::Action valueFlowForward(Token* startToken,
const Token* endToken, const Token* endToken,
const Token* exprTok, const Token* exprTok,
std::list<ValueFlow::Value> values, std::list<ValueFlow::Value> values,
TokenList* const tokenlist, TokenList* const tokenlist,
const Settings* settings) const Settings* settings)
{ {
const Token* expr = solveExprValues(exprTok, values); const Token* expr = solveExprValues(exprTok, values);
if (expr->variable()) { if (expr->variable()) {
@ -4923,8 +4918,7 @@ struct MultiValueFlowAnalyzer : ValueFlowAnalyzer {
MultiValueFlowAnalyzer() : ValueFlowAnalyzer(), values(), vars() {} MultiValueFlowAnalyzer() : ValueFlowAnalyzer(), values(), vars() {}
MultiValueFlowAnalyzer(const std::unordered_map<const Variable*, ValueFlow::Value>& args, const TokenList* t) MultiValueFlowAnalyzer(const std::unordered_map<const Variable*, ValueFlow::Value>& args, const TokenList* t)
: ValueFlowAnalyzer(t), values(), vars() : ValueFlowAnalyzer(t), values(), vars() {
{
for (const auto& p:args) { for (const auto& p:args) {
values[p.first->declarationId()] = p.second; values[p.first->declarationId()] = p.second;
vars[p.first->declarationId()] = p.first; vars[p.first->declarationId()] = p.first;
@ -5774,8 +5768,7 @@ struct ContainerVariableAnalyzer : VariableAnalyzer {
return tok->varId() == var->declarationId() || (astIsIterator(tok) && isAliasOf(tok, var->declarationId())); return tok->varId() == var->declarationId() || (astIsIterator(tok) && isAliasOf(tok, var->declarationId()));
} }
virtual Action isWritable(const Token* tok, Direction d) const OVERRIDE virtual Action isWritable(const Token* tok, Direction d) const OVERRIDE {
{
if (astIsIterator(tok)) if (astIsIterator(tok))
return Action::None; return Action::None;
if (d == Direction::Reverse) if (d == Direction::Reverse)
@ -5805,8 +5798,7 @@ struct ContainerVariableAnalyzer : VariableAnalyzer {
return Action::None; return Action::None;
} }
virtual void writeValue(ValueFlow::Value* value, const Token* tok, Direction d) const OVERRIDE virtual void writeValue(ValueFlow::Value* value, const Token* tok, Direction d) const OVERRIDE {
{
if (d == Direction::Reverse) if (d == Direction::Reverse)
return; return;
if (!value) if (!value)
@ -5853,18 +5845,18 @@ struct ContainerVariableAnalyzer : VariableAnalyzer {
}; };
static Analyzer::Action valueFlowContainerForward(Token* tok, static Analyzer::Action valueFlowContainerForward(Token* tok,
const Token* endToken, const Token* endToken,
const Variable* var, const Variable* var,
ValueFlow::Value value, ValueFlow::Value value,
TokenList* tokenlist) TokenList* tokenlist)
{ {
ContainerVariableAnalyzer a(var, value, getAliasesFromValues({value}), tokenlist); ContainerVariableAnalyzer a(var, value, getAliasesFromValues({value}), tokenlist);
return valueFlowGenericForward(tok, endToken, a, tokenlist->getSettings()); return valueFlowGenericForward(tok, endToken, a, tokenlist->getSettings());
} }
static Analyzer::Action valueFlowContainerForward(Token* tok, static Analyzer::Action valueFlowContainerForward(Token* tok,
const Variable* var, const Variable* var,
ValueFlow::Value value, ValueFlow::Value value,
TokenList* tokenlist) TokenList* tokenlist)
{ {
const Token * endOfVarScope = nullptr; const Token * endOfVarScope = nullptr;
if (var->isLocal() || var->isArgument()) if (var->isLocal() || var->isArgument())

View File

@ -56,8 +56,7 @@ namespace ValueFlow {
struct equalVisitor { struct equalVisitor {
template <class T, class U> template <class T, class U>
void operator()(bool& result, T x, U y) const void operator()(bool& result, T x, U y) const {
{
result = !(x > y || x < y); result = !(x > y || x < y);
} }
}; };
@ -122,8 +121,7 @@ namespace ValueFlow {
} }
template <class T, class F> template <class T, class F>
static void visitValue(T& self, F f) static void visitValue(T& self, F f) {
{
switch (self.valueType) { switch (self.valueType) {
case ValueType::INT: case ValueType::INT:
case ValueType::BUFFER_SIZE: case ValueType::BUFFER_SIZE:
@ -163,8 +161,7 @@ namespace ValueFlow {
} }
template <class T, REQUIRES("T must be an arithmetic type", std::is_arithmetic<T>)> template <class T, REQUIRES("T must be an arithmetic type", std::is_arithmetic<T>)>
bool equalTo(const T& x) const bool equalTo(const T& x) const {
{
bool result = false; bool result = false;
visitValue(*this, std::bind(equalVisitor{}, std::ref(result), x, std::placeholders::_1)); visitValue(*this, std::bind(equalVisitor{}, std::ref(result), x, std::placeholders::_1));
return result; return result;

View File

@ -1899,8 +1899,7 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void nullpointer61() void nullpointer61() {
{
check("struct a {\n" check("struct a {\n"
" int *e;\n" " int *e;\n"
"};\n" "};\n"
@ -1933,8 +1932,7 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void nullpointer62() void nullpointer62() {
{
check("struct A {\n" check("struct A {\n"
" bool f()() const;\n" " bool f()() const;\n"
"};\n" "};\n"
@ -1964,8 +1962,7 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void nullpointer63() void nullpointer63() {
{
check("struct A {\n" check("struct A {\n"
" A* a() const;\n" " A* a() const;\n"
" A* b() const;\n" " A* b() const;\n"
@ -1979,8 +1976,7 @@ private:
ASSERT_EQUALS("", errout.str()); ASSERT_EQUALS("", errout.str());
} }
void nullpointer64() void nullpointer64() {
{
check("struct A {\n" check("struct A {\n"
" A* f() const;\n" " A* f() const;\n"
" int g() const;\n" " int g() const;\n"