astyle formatting
This commit is contained in:
parent
829c543331
commit
7182da5c8e
|
@ -44,41 +44,63 @@ struct Analyzer {
|
|||
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);
|
||||
return *this;
|
||||
}
|
||||
|
||||
friend Action operator|(Action a, Action b)
|
||||
{
|
||||
friend Action operator|(Action a, Action b) {
|
||||
a |= b;
|
||||
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:
|
||||
unsigned int mFlag;
|
||||
|
|
|
@ -315,8 +315,14 @@ static T* previousBeforeAstLeftmostLeafGeneric(T* tok)
|
|||
return leftmostLeaf->previous();
|
||||
}
|
||||
|
||||
const Token* previousBeforeAstLeftmostLeaf(const Token* tok) { return previousBeforeAstLeftmostLeafGeneric(tok); }
|
||||
Token* previousBeforeAstLeftmostLeaf(Token* tok) { return previousBeforeAstLeftmostLeafGeneric(tok); }
|
||||
const Token* previousBeforeAstLeftmostLeaf(const Token* 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*>)>
|
||||
static T* nextAfterAstRightmostLeafGeneric(T* tok)
|
||||
|
|
|
@ -26,8 +26,12 @@ struct ForwardTraversal {
|
|||
std::pair<bool, bool> evalCond(const Token* tok) {
|
||||
std::vector<int> result = analyzer->evaluate(tok);
|
||||
// TODO: We should convert to bool
|
||||
bool checkThen = std::any_of(result.begin(), result.end(), [](int x) { return x == 1; });
|
||||
bool checkElse = std::any_of(result.begin(), result.end(), [](int x) { return x == 0; });
|
||||
bool checkThen = std::any_of(result.begin(), result.end(), [](int x) {
|
||||
return x == 1;
|
||||
});
|
||||
bool checkElse = std::any_of(result.begin(), result.end(), [](int x) {
|
||||
return x == 0;
|
||||
});
|
||||
return std::make_pair(checkThen, checkElse);
|
||||
}
|
||||
|
||||
|
@ -150,8 +154,7 @@ struct ForwardTraversal {
|
|||
}
|
||||
|
||||
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()) {
|
||||
Analyzer::Action action = analyzer->analyze(tok, Analyzer::Direction::Forward);
|
||||
if (pred(action))
|
||||
|
@ -160,8 +163,7 @@ struct ForwardTraversal {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
Analyzer::Action analyzeRecursive(const Token* start)
|
||||
{
|
||||
Analyzer::Action analyzeRecursive(const Token* start) {
|
||||
Analyzer::Action result = Analyzer::Action::None;
|
||||
std::function<Progress(const Token*)> f = [&](const Token* tok) {
|
||||
result = analyzer->analyze(tok, Analyzer::Direction::Forward);
|
||||
|
@ -173,8 +175,7 @@ struct ForwardTraversal {
|
|||
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;
|
||||
for (const Token* tok = start; tok && tok != end; tok = tok->next()) {
|
||||
Analyzer::Action action = analyzer->analyze(tok, Analyzer::Direction::Forward);
|
||||
|
@ -211,17 +212,17 @@ struct ForwardTraversal {
|
|||
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);
|
||||
forkScope(endBlock, a.isModified());
|
||||
return a;
|
||||
}
|
||||
|
||||
Analyzer::Action checkScope(const Token* endBlock)
|
||||
{
|
||||
Analyzer::Action checkScope(const Token* endBlock) {
|
||||
Analyzer::Action a = analyzeScope(endBlock);
|
||||
return a;
|
||||
}
|
||||
|
|
|
@ -17,17 +17,19 @@ struct ReverseTraversal {
|
|||
ValuePtr<Analyzer> analyzer;
|
||||
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);
|
||||
// TODO: We should convert to bool
|
||||
bool checkThen = std::any_of(result.begin(), result.end(), [](int x) { return x == 1; });
|
||||
bool checkElse = std::any_of(result.begin(), result.end(), [](int x) { return x == 0; });
|
||||
bool checkThen = std::any_of(result.begin(), result.end(), [](int x) {
|
||||
return x == 1;
|
||||
});
|
||||
bool checkElse = std::any_of(result.begin(), result.end(), [](int x) {
|
||||
return x == 0;
|
||||
});
|
||||
return std::make_pair(checkThen, checkElse);
|
||||
}
|
||||
|
||||
bool update(Token* tok)
|
||||
{
|
||||
bool update(Token* tok) {
|
||||
Analyzer::Action action = analyzer->analyze(tok, Analyzer::Direction::Reverse);
|
||||
if (!action.isNone())
|
||||
analyzer->update(tok, action, Analyzer::Direction::Reverse);
|
||||
|
@ -38,8 +40,7 @@ struct ReverseTraversal {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool updateRecursive(Token* start)
|
||||
{
|
||||
bool updateRecursive(Token* start) {
|
||||
bool continueB = true;
|
||||
visitAstNodes(start, [&](Token* tok) {
|
||||
continueB &= update(tok);
|
||||
|
@ -51,8 +52,7 @@ struct ReverseTraversal {
|
|||
return continueB;
|
||||
}
|
||||
|
||||
Analyzer::Action analyzeRecursive(const Token* start)
|
||||
{
|
||||
Analyzer::Action analyzeRecursive(const Token* start) {
|
||||
Analyzer::Action result = Analyzer::Action::None;
|
||||
visitAstNodes(start, [&](const Token* tok) {
|
||||
result |= analyzer->analyze(tok, Analyzer::Direction::Reverse);
|
||||
|
@ -63,8 +63,7 @@ struct ReverseTraversal {
|
|||
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;
|
||||
for (const Token* tok = start; tok && tok != end; tok = tok->next()) {
|
||||
Analyzer::Action action = analyzer->analyze(tok, Analyzer::Direction::Reverse);
|
||||
|
@ -75,8 +74,7 @@ struct ReverseTraversal {
|
|||
return result;
|
||||
}
|
||||
|
||||
Token* isDeadCode(Token* tok)
|
||||
{
|
||||
Token* isDeadCode(Token* tok) {
|
||||
int opSide = 0;
|
||||
for (; tok && tok->astParent(); tok = tok->astParent()) {
|
||||
Token* parent = tok->astParent();
|
||||
|
@ -118,8 +116,7 @@ struct ReverseTraversal {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
void traverse(Token* start)
|
||||
{
|
||||
void traverse(Token* start) {
|
||||
for (Token* tok = start->previous(); tok; tok = tok->previous()) {
|
||||
if (tok == start || (tok->str() == "{" && (tok->scope()->type == Scope::ScopeType::eFunction ||
|
||||
tok->scope()->type == Scope::ScopeType::eLambda))) {
|
||||
|
@ -256,8 +253,7 @@ struct ReverseTraversal {
|
|||
}
|
||||
}
|
||||
|
||||
static Token* assignExpr(Token* tok)
|
||||
{
|
||||
static Token* assignExpr(Token* tok) {
|
||||
while (tok->astParent() && (astIsRHS(tok) || !tok->astParent()->isBinaryOp())) {
|
||||
if (tok->astParent()->isAssignmentOp())
|
||||
return tok->astParent();
|
||||
|
@ -266,8 +262,7 @@ struct ReverseTraversal {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
static Token* isUnevaluated(Token* tok)
|
||||
{
|
||||
static Token* isUnevaluated(Token* tok) {
|
||||
if (Token::Match(tok, ")|>") && tok->link()) {
|
||||
Token* start = tok->link();
|
||||
if (Token::Match(start->previous(), "sizeof|decltype ("))
|
||||
|
|
|
@ -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 std::unordered_map<std::string, std::string> lookup = {
|
||||
{"+=", "-="}, {"-=", "+="}, {"*=", "/="}, {"/=", "*="}, {"<<=", ">>="}, {">>=", "<<="}, {"^=", "^="}};
|
||||
{"+=", "-="}, {"-=", "+="}, {"*=", "/="}, {"/=", "*="}, {"<<=", ">>="}, {">>=", "<<="}, {"^=", "^="}
|
||||
};
|
||||
static std::string empty = "";
|
||||
auto it = lookup.find(assign);
|
||||
if (it == lookup.end())
|
||||
|
@ -2142,8 +2143,7 @@ struct ValueFlowAnalyzer : Analyzer {
|
|||
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);
|
||||
if (!value)
|
||||
return Action::None;
|
||||
|
@ -2179,16 +2179,14 @@ struct ValueFlowAnalyzer : Analyzer {
|
|||
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)
|
||||
return tok->str();
|
||||
else
|
||||
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)
|
||||
return;
|
||||
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())
|
||||
return Action::Invalid;
|
||||
bool inconclusive = false;
|
||||
|
@ -2306,8 +2303,7 @@ struct ValueFlowAnalyzer : Analyzer {
|
|||
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);
|
||||
if (!value)
|
||||
return;
|
||||
|
@ -2324,7 +2320,9 @@ struct ValueFlowAnalyzer : Analyzer {
|
|||
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);
|
||||
|
@ -2432,8 +2430,7 @@ struct SingleValueFlowAnalyzer : ValueFlowAnalyzer {
|
|||
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;
|
||||
newValue.errorPath.emplace_back(tok, msg);
|
||||
return makeAnalyzer(tok, newValue, tokenlist);
|
||||
|
@ -2449,8 +2446,7 @@ struct VariableAnalyzer : SingleValueFlowAnalyzer {
|
|||
const ValueFlow::Value& val,
|
||||
std::vector<const Variable*> paliases,
|
||||
const TokenList* t)
|
||||
: SingleValueFlowAnalyzer(val, t), var(v)
|
||||
{
|
||||
: SingleValueFlowAnalyzer(val, t), var(v) {
|
||||
varids[var->declarationId()] = var;
|
||||
for (const Variable* av:paliases) {
|
||||
if (!av)
|
||||
|
@ -2550,8 +2546,7 @@ struct ExpressionAnalyzer : SingleValueFlowAnalyzer {
|
|||
ExpressionAnalyzer() : SingleValueFlowAnalyzer(), expr(nullptr), local(true), unknown(false) {}
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -4923,8 +4918,7 @@ struct MultiValueFlowAnalyzer : ValueFlowAnalyzer {
|
|||
MultiValueFlowAnalyzer() : ValueFlowAnalyzer(), values(), vars() {}
|
||||
|
||||
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) {
|
||||
values[p.first->declarationId()] = p.second;
|
||||
vars[p.first->declarationId()] = p.first;
|
||||
|
@ -5774,8 +5768,7 @@ struct ContainerVariableAnalyzer : VariableAnalyzer {
|
|||
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))
|
||||
return Action::None;
|
||||
if (d == Direction::Reverse)
|
||||
|
@ -5805,8 +5798,7 @@ struct ContainerVariableAnalyzer : VariableAnalyzer {
|
|||
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)
|
||||
return;
|
||||
if (!value)
|
||||
|
|
|
@ -56,8 +56,7 @@ namespace ValueFlow {
|
|||
|
||||
struct equalVisitor {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
@ -122,8 +121,7 @@ namespace ValueFlow {
|
|||
}
|
||||
|
||||
template <class T, class F>
|
||||
static void visitValue(T& self, F f)
|
||||
{
|
||||
static void visitValue(T& self, F f) {
|
||||
switch (self.valueType) {
|
||||
case ValueType::INT:
|
||||
case ValueType::BUFFER_SIZE:
|
||||
|
@ -163,8 +161,7 @@ namespace ValueFlow {
|
|||
}
|
||||
|
||||
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;
|
||||
visitValue(*this, std::bind(equalVisitor{}, std::ref(result), x, std::placeholders::_1));
|
||||
return result;
|
||||
|
|
|
@ -1899,8 +1899,7 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void nullpointer61()
|
||||
{
|
||||
void nullpointer61() {
|
||||
check("struct a {\n"
|
||||
" int *e;\n"
|
||||
"};\n"
|
||||
|
@ -1933,8 +1932,7 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void nullpointer62()
|
||||
{
|
||||
void nullpointer62() {
|
||||
check("struct A {\n"
|
||||
" bool f()() const;\n"
|
||||
"};\n"
|
||||
|
@ -1964,8 +1962,7 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void nullpointer63()
|
||||
{
|
||||
void nullpointer63() {
|
||||
check("struct A {\n"
|
||||
" A* a() const;\n"
|
||||
" A* b() const;\n"
|
||||
|
@ -1979,8 +1976,7 @@ private:
|
|||
ASSERT_EQUALS("", errout.str());
|
||||
}
|
||||
|
||||
void nullpointer64()
|
||||
{
|
||||
void nullpointer64() {
|
||||
check("struct A {\n"
|
||||
" A* f() const;\n"
|
||||
" int g() const;\n"
|
||||
|
|
Loading…
Reference in New Issue