"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/astutils.h" between
cppcheck-1.86.tar.gz and cppcheck-1.87.tar.gz

About: Cppcheck is a static analysis tool for C/C++ code. It checks for memory leaks, mismatching allocation-deallocation, buffer overrun, and many more.

astutils.h  (cppcheck-1.86):astutils.h  (cppcheck-1.87)
/* /*
* Cppcheck - A tool for static C/C++ code analysis * Cppcheck - A tool for static C/C++ code analysis
* Copyright (C) 2007-2018 Cppcheck team. * Copyright (C) 2007-2019 Cppcheck team.
* *
* This program is free software: you can redistribute it and/or modify * This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
skipping to change at line 162 skipping to change at line 162
*/ */
const Token *findLambdaEndToken(const Token *first); const Token *findLambdaEndToken(const Token *first);
/** /**
* do we see a likely write of rhs through overloaded operator * do we see a likely write of rhs through overloaded operator
* s >> x; * s >> x;
* a & x; * a & x;
*/ */
bool isLikelyStreamRead(bool cpp, const Token *op); bool isLikelyStreamRead(bool cpp, const Token *op);
bool isCPPCast(const Token* tok);
bool isConstVarExpression(const Token *tok);
/**
* Forward data flow analysis for checks
* - unused value
* - redundant assignment
* - valueflow analysis
*/
class FwdAnalysis { class FwdAnalysis {
public: public:
FwdAnalysis(bool cpp, const Library &library) : mCpp(cpp), mLibrary(library) , mReassign(false) {} FwdAnalysis(bool cpp, const Library &library) : mCpp(cpp), mLibrary(library) , mWhat(What::Reassign), mValueFlowKnown(true) {}
bool hasOperand(const Token *tok, const Token *lhs) const; bool hasOperand(const Token *tok, const Token *lhs) const;
/** /**
* Check if "expr" is reassigned. The "expr" can be a tree (x.y[12]). * Check if "expr" is reassigned. The "expr" can be a tree (x.y[12]).
* @param expr Symbolic expression to perform forward analysis for * @param expr Symbolic expression to perform forward analysis for
* @param startToken First token in forward analysis * @param startToken First token in forward analysis
* @param endToken Last token in forward analysis * @param endToken Last token in forward analysis
* @return Token where expr is reassigned. If it's not reassigned then nullp tr is returned. * @return Token where expr is reassigned. If it's not reassigned then nullp tr is returned.
*/ */
const Token *reassign(const Token *expr, const Token *startToken, const Toke n *endToken); const Token *reassign(const Token *expr, const Token *startToken, const Toke n *endToken);
/**
* Check if "expr" is used. The "expr" can be a tree (x.y[12]).
* @param expr Symbolic expression to perform forward analysis for
* @param startToken First token in forward analysis
* @param endToken Last token in forward analysis
* @return true if expr is used.
*/
bool unusedValue(const Token *expr, const Token *startToken, const Token *en
dToken);
struct KnownAndToken {
bool known;
const Token *token;
};
std::vector<KnownAndToken> valueFlow(const Token *expr, const Token *startTo
ken, const Token *endToken);
/** Is there some possible alias for given expression */
bool possiblyAliased(const Token *expr, const Token *startToken) const;
static bool isNullOperand(const Token *expr);
private: private:
/** Result of forward analysis */ /** Result of forward analysis */
struct Result { struct Result {
enum class Type { NONE, READ, WRITE, BREAK, RETURN, BAILOUT } type; enum class Type { NONE, READ, WRITE, BREAK, RETURN, BAILOUT } type;
explicit Result(Type type) : type(type), token(nullptr) {} explicit Result(Type type) : type(type), token(nullptr) {}
Result(Type type, const Token *token) : type(type), token(token) {} Result(Type type, const Token *token) : type(type), token(token) {}
const Token *token; const Token *token;
}; };
struct Result check(const Token *expr, const Token *startToken, const Token *endToken); struct Result check(const Token *expr, const Token *startToken, const Token *endToken);
struct Result checkRecursive(const Token *expr, const Token *startToken, con st Token *endToken, const std::set<unsigned int> &exprVarIds, bool local); struct Result checkRecursive(const Token *expr, const Token *startToken, con st Token *endToken, const std::set<unsigned int> &exprVarIds, bool local);
// Is expression a l-value global data?
bool isGlobalData(const Token *expr) const;
const bool mCpp; const bool mCpp;
const Library &mLibrary; const Library &mLibrary;
bool mReassign; enum class What { Reassign, UnusedValue, ValueFlow } mWhat;
std::vector<const Token *> mReads; std::vector<KnownAndToken> mValueFlow;
bool mValueFlowKnown;
}; };
#endif // astutilsH #endif // astutilsH
 End of changes. 6 change blocks. 
4 lines changed or deleted 40 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)