moved some classes/structs into anonymous namespace (#5669)
This commit is contained in:
parent
63a5a71c20
commit
e47300016b
|
@ -72,8 +72,9 @@
|
|||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
class XMLErrorMessagesLogger : public ErrorLogger
|
||||
{
|
||||
namespace {
|
||||
class XMLErrorMessagesLogger : public ErrorLogger
|
||||
{
|
||||
void reportOut(const std::string & outmsg, Color /*c*/ = Color::Reset) override
|
||||
{
|
||||
std::cout << outmsg << std::endl;
|
||||
|
@ -86,11 +87,11 @@ class XMLErrorMessagesLogger : public ErrorLogger
|
|||
|
||||
void reportProgress(const std::string & /*filename*/, const char /*stage*/[], const std::size_t /*value*/) override
|
||||
{}
|
||||
};
|
||||
};
|
||||
|
||||
class CmdLineLoggerStd : public CmdLineLogger
|
||||
{
|
||||
public:
|
||||
class CmdLineLoggerStd : public CmdLineLogger
|
||||
{
|
||||
public:
|
||||
CmdLineLoggerStd() = default;
|
||||
|
||||
void printMessage(const std::string &message) override
|
||||
|
@ -107,7 +108,8 @@ public:
|
|||
{
|
||||
std::cout << message << std::endl;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
class CppCheckExecutor::StdLogger : public ErrorLogger
|
||||
{
|
||||
|
|
|
@ -68,8 +68,9 @@ ProcessExecutor::ProcessExecutor(const std::list<std::pair<std::string, std::siz
|
|||
assert(mSettings.jobs > 1);
|
||||
}
|
||||
|
||||
class PipeWriter : public ErrorLogger {
|
||||
public:
|
||||
namespace {
|
||||
class PipeWriter : public ErrorLogger {
|
||||
public:
|
||||
enum PipeSignal {REPORT_OUT='1',REPORT_ERROR='2', CHILD_END='5'};
|
||||
|
||||
explicit PipeWriter(int pipe) : mWpipe(pipe) {}
|
||||
|
@ -86,7 +87,7 @@ public:
|
|||
writeToPipe(CHILD_END, str);
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
// TODO: how to log file name in error?
|
||||
void writeToPipeInternal(PipeSignal type, const void* data, std::size_t to_write) const
|
||||
{
|
||||
|
@ -120,7 +121,8 @@ private:
|
|||
}
|
||||
|
||||
const int mWpipe;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::string& filename)
|
||||
{
|
||||
|
|
|
@ -47,8 +47,9 @@ class QWidget;
|
|||
|
||||
// TODO: get/compare functions from header
|
||||
|
||||
class FunctionListItem : public QListWidgetItem {
|
||||
public:
|
||||
namespace {
|
||||
class FunctionListItem : public QListWidgetItem {
|
||||
public:
|
||||
FunctionListItem(QListWidget *view,
|
||||
CppcheckLibraryData::Function *function,
|
||||
bool selected)
|
||||
|
@ -58,7 +59,8 @@ public:
|
|||
setSelected(selected);
|
||||
}
|
||||
CppcheckLibraryData::Function *function;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
LibraryDialog::LibraryDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
|
|
|
@ -2943,15 +2943,16 @@ static const Token* findExpressionChangedImpl(const Token* expr,
|
|||
return result;
|
||||
}
|
||||
|
||||
struct ExpressionChangedSimpleFind {
|
||||
namespace {
|
||||
struct ExpressionChangedSimpleFind {
|
||||
template<class F>
|
||||
const Token* operator()(const Token* start, const Token* end, F f) const
|
||||
{
|
||||
return findToken(start, end, f);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
struct ExpressionChangedSkipDeadCode {
|
||||
struct ExpressionChangedSkipDeadCode {
|
||||
const Library* library;
|
||||
const std::function<std::vector<MathLib::bigint>(const Token* tok)>* evaluate;
|
||||
ExpressionChangedSkipDeadCode(const Library* library,
|
||||
|
@ -2963,7 +2964,8 @@ struct ExpressionChangedSkipDeadCode {
|
|||
{
|
||||
return findTokenSkipDeadCode(library, start, end, f, *evaluate);
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
const Token* findExpressionChanged(const Token* expr,
|
||||
const Token* start,
|
||||
|
|
|
@ -107,7 +107,8 @@ static OpenMode getMode(const std::string& str)
|
|||
return OpenMode::UNKNOWN_OM;
|
||||
}
|
||||
|
||||
struct Filepointer {
|
||||
namespace {
|
||||
struct Filepointer {
|
||||
OpenMode mode;
|
||||
nonneg int mode_indent{};
|
||||
enum class Operation {NONE, UNIMPORTANT, READ, WRITE, POSITIONING, OPEN, CLOSE, UNKNOWN_OP} lastOperation = Operation::NONE;
|
||||
|
@ -117,9 +118,8 @@ struct Filepointer {
|
|||
std::string filename;
|
||||
explicit Filepointer(OpenMode mode_ = OpenMode::UNKNOWN_OM)
|
||||
: mode(mode_) {}
|
||||
};
|
||||
};
|
||||
|
||||
namespace {
|
||||
const std::unordered_set<std::string> whitelist = { "clearerr", "feof", "ferror", "fgetpos", "ftell", "setbuf", "setvbuf", "ungetc", "ungetwc" };
|
||||
}
|
||||
|
||||
|
|
|
@ -760,10 +760,12 @@ bool CheckStl::checkIteratorPair(const Token* tok1, const Token* tok2)
|
|||
return false;
|
||||
}
|
||||
|
||||
struct ArgIteratorInfo {
|
||||
namespace {
|
||||
struct ArgIteratorInfo {
|
||||
const Token* tok;
|
||||
const Library::ArgumentChecks::IteratorInfo* info;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
void CheckStl::mismatchingContainers()
|
||||
{
|
||||
|
@ -913,7 +915,8 @@ static const Token* getInvalidMethod(const Token* tok)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
struct InvalidContainerAnalyzer {
|
||||
namespace {
|
||||
struct InvalidContainerAnalyzer {
|
||||
struct Info {
|
||||
struct Reference {
|
||||
const Token* tok;
|
||||
|
@ -1008,7 +1011,8 @@ struct InvalidContainerAnalyzer {
|
|||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
static const Token* getLoopContainer(const Token* tok)
|
||||
{
|
||||
|
|
|
@ -39,15 +39,16 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
struct OnExit {
|
||||
namespace {
|
||||
struct OnExit {
|
||||
std::function<void()> f;
|
||||
|
||||
~OnExit() {
|
||||
f();
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
struct ForwardTraversal {
|
||||
struct ForwardTraversal {
|
||||
enum class Progress { Continue, Break, Skip };
|
||||
enum class Terminate { None, Bail, Inconclusive };
|
||||
ForwardTraversal(const ValuePtr<Analyzer>& analyzer, const Settings& settings)
|
||||
|
@ -115,11 +116,6 @@ struct ForwardTraversal {
|
|||
return evalCond(tok, ctx).first;
|
||||
}
|
||||
|
||||
// cppcheck-suppress unusedFunction
|
||||
bool isConditionFalse(const Token* tok, const Token* ctx = nullptr) const {
|
||||
return evalCond(tok, ctx).second;
|
||||
}
|
||||
|
||||
template<class T, class F, REQUIRES("T must be a Token class", std::is_convertible<T*, const Token*> )>
|
||||
Progress traverseTok(T* tok, F f, bool traverseUnknown, T** out = nullptr) {
|
||||
if (Token::Match(tok, "asm|goto"))
|
||||
|
@ -873,15 +869,6 @@ struct ForwardTraversal {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
static bool isConditional(const Token* tok) {
|
||||
const Token* parent = tok->astParent();
|
||||
while (parent && !Token::Match(parent, "%oror%|&&|:")) {
|
||||
tok = parent;
|
||||
parent = parent->astParent();
|
||||
}
|
||||
return parent && (parent->str() == ":" || parent->astOperand2() == tok);
|
||||
}
|
||||
|
||||
static Token* getStepTokFromEnd(Token* tok) {
|
||||
if (!Token::simpleMatch(tok, "}"))
|
||||
return nullptr;
|
||||
|
@ -890,7 +877,8 @@ struct ForwardTraversal {
|
|||
return nullptr;
|
||||
return getStepTok(end->link());
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Analyzer::Result valueFlowGenericForward(Token* start, const Token* end, const ValuePtr<Analyzer>& a, const Settings& settings)
|
||||
{
|
||||
|
|
|
@ -48,26 +48,11 @@ static const ValueFlow::Value* getCompareValue(const std::list<ValueFlow::Value>
|
|||
return result;
|
||||
}
|
||||
|
||||
struct Interval {
|
||||
namespace {
|
||||
struct Interval {
|
||||
std::vector<MathLib::bigint> minvalue, maxvalue;
|
||||
std::vector<const ValueFlow::Value*> minRef, maxRef;
|
||||
|
||||
std::string str() const
|
||||
{
|
||||
std::string result = "[";
|
||||
if (minvalue.size() == 1)
|
||||
result += std::to_string(minvalue.front());
|
||||
else
|
||||
result += "*";
|
||||
result += ",";
|
||||
if (maxvalue.size() == 1)
|
||||
result += std::to_string(maxvalue.front());
|
||||
else
|
||||
result += "*";
|
||||
result += "]";
|
||||
return result;
|
||||
}
|
||||
|
||||
void setMinValue(MathLib::bigint x, const ValueFlow::Value* ref = nullptr)
|
||||
{
|
||||
minvalue = {x};
|
||||
|
@ -249,10 +234,7 @@ struct Interval {
|
|||
return {b};
|
||||
return {};
|
||||
}
|
||||
};
|
||||
|
||||
std::string toString(const Interval& i) {
|
||||
return i.str();
|
||||
};
|
||||
}
|
||||
|
||||
static void addToErrorPath(ValueFlow::Value& value, const std::vector<const ValueFlow::Value*>& refs)
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
struct Interval;
|
||||
template<class T> class ValuePtr;
|
||||
|
||||
struct InferModel {
|
||||
|
@ -57,6 +56,4 @@ std::vector<ValueFlow::Value> infer(const ValuePtr<InferModel>& model,
|
|||
CPPCHECKLIB std::vector<MathLib::bigint> getMinValue(const ValuePtr<InferModel>& model, const std::list<ValueFlow::Value>& values);
|
||||
std::vector<MathLib::bigint> getMaxValue(const ValuePtr<InferModel>& model, const std::list<ValueFlow::Value>& values);
|
||||
|
||||
std::string toString(const Interval& i);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -552,13 +552,15 @@ static std::string removeAssign(const std::string& assign) {
|
|||
return std::string{assign.cbegin(), assign.cend() - 1};
|
||||
}
|
||||
|
||||
struct assign {
|
||||
namespace {
|
||||
struct assign {
|
||||
template<class T, class U>
|
||||
void operator()(T& x, const U& y) const
|
||||
{
|
||||
x = y;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
static bool isIntegralValue(const ValueFlow::Value& value)
|
||||
{
|
||||
|
@ -1197,7 +1199,8 @@ static BuiltinLibraryFunction getBuiltinLibraryFunction(const std::string& name)
|
|||
return it->second;
|
||||
}
|
||||
|
||||
struct Executor {
|
||||
namespace {
|
||||
struct Executor {
|
||||
ProgramMemory* pm = nullptr;
|
||||
const Settings* settings = nullptr;
|
||||
int fdepth = 4;
|
||||
|
@ -1336,13 +1339,13 @@ struct Executor {
|
|||
if (expr->isComparisonOp() && (r.isUninitValue() || r.isImpossible())) {
|
||||
if (rhs.isIntValue()) {
|
||||
std::vector<ValueFlow::Value> result =
|
||||
infer(ValueFlow::makeIntegralInferModel(), expr->str(), expr->astOperand1()->values(), {std::move(rhs)});
|
||||
infer(ValueFlow::makeIntegralInferModel(), expr->str(), expr->astOperand1()->values(), {rhs});
|
||||
if (!result.empty() && result.front().isKnown())
|
||||
return result.front();
|
||||
}
|
||||
if (lhs.isIntValue()) {
|
||||
std::vector<ValueFlow::Value> result =
|
||||
infer(ValueFlow::makeIntegralInferModel(), expr->str(), {std::move(lhs)}, expr->astOperand2()->values());
|
||||
infer(ValueFlow::makeIntegralInferModel(), expr->str(), {lhs}, expr->astOperand2()->values());
|
||||
if (!result.empty() && result.front().isKnown())
|
||||
return result.front();
|
||||
}
|
||||
|
@ -1418,7 +1421,7 @@ struct Executor {
|
|||
ex.fdepth--;
|
||||
auto r = ex.execute(f->functionScope);
|
||||
if (!r.empty())
|
||||
result = std::move(r.front());
|
||||
result = r.front();
|
||||
// TODO: Track values changed by reference
|
||||
}
|
||||
} else {
|
||||
|
@ -1544,7 +1547,8 @@ struct Executor {
|
|||
}
|
||||
return {};
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
static ValueFlow::Value execute(const Token* expr, ProgramMemory& pm, const Settings* settings)
|
||||
{
|
||||
|
|
|
@ -35,7 +35,8 @@
|
|||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
struct ReverseTraversal {
|
||||
namespace {
|
||||
struct ReverseTraversal {
|
||||
ReverseTraversal(const ValuePtr<Analyzer>& analyzer, const Settings& settings)
|
||||
: analyzer(analyzer), settings(settings)
|
||||
{}
|
||||
|
@ -385,7 +386,8 @@ struct ReverseTraversal {
|
|||
}
|
||||
return nullptr;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
void valueFlowGenericReverse(Token* start, const Token* end, const ValuePtr<Analyzer>& a, const Settings& settings)
|
||||
{
|
||||
|
|
|
@ -396,7 +396,8 @@ std::size_t TokenList::calculateHash() const
|
|||
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
struct AST_state {
|
||||
namespace {
|
||||
struct AST_state {
|
||||
std::stack<Token*> op;
|
||||
int depth{};
|
||||
int inArrayAssignment{};
|
||||
|
@ -406,7 +407,8 @@ struct AST_state {
|
|||
bool stopAtColon{}; // help to properly parse ternary operators
|
||||
const Token* functionCallEndPar{};
|
||||
explicit AST_state(bool cpp) : cpp(cpp) {}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
static Token* skipDecl(Token* tok, std::vector<Token*>* inner = nullptr)
|
||||
{
|
||||
|
@ -1703,7 +1705,8 @@ void TokenList::createAst() const
|
|||
}
|
||||
}
|
||||
|
||||
struct OnException {
|
||||
namespace {
|
||||
struct OnException {
|
||||
std::function<void()> f;
|
||||
|
||||
~OnException() {
|
||||
|
@ -1712,7 +1715,8 @@ struct OnException {
|
|||
f();
|
||||
#endif
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
void TokenList::validateAst() const
|
||||
{
|
||||
|
|
|
@ -48,9 +48,10 @@ namespace {
|
|||
};
|
||||
}
|
||||
using TestSet = std::set<TestFixture*, CompareFixtures>;
|
||||
class TestRegistry {
|
||||
namespace {
|
||||
class TestRegistry {
|
||||
TestSet _tests;
|
||||
public:
|
||||
public:
|
||||
|
||||
static TestRegistry &theInstance() {
|
||||
static TestRegistry testreg;
|
||||
|
@ -64,7 +65,8 @@ public:
|
|||
const TestSet &tests() const {
|
||||
return _tests;
|
||||
}
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue