moved some classes/structs into anonymous namespace (#5669)

This commit is contained in:
Oliver Stöneberg 2023-11-16 15:49:41 +01:00 committed by GitHub
parent 63a5a71c20
commit e47300016b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 1861 additions and 1870 deletions

View File

@ -72,6 +72,7 @@
#include <windows.h>
#endif
namespace {
class XMLErrorMessagesLogger : public ErrorLogger
{
void reportOut(const std::string & outmsg, Color /*c*/ = Color::Reset) override
@ -108,6 +109,7 @@ public:
std::cout << message << std::endl;
}
};
}
class CppCheckExecutor::StdLogger : public ErrorLogger
{

View File

@ -68,6 +68,7 @@ ProcessExecutor::ProcessExecutor(const std::list<std::pair<std::string, std::siz
assert(mSettings.jobs > 1);
}
namespace {
class PipeWriter : public ErrorLogger {
public:
enum PipeSignal {REPORT_OUT='1',REPORT_ERROR='2', CHILD_END='5'};
@ -121,6 +122,7 @@ private:
const int mWpipe;
};
}
bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::string& filename)
{

View File

@ -47,6 +47,7 @@ class QWidget;
// TODO: get/compare functions from header
namespace {
class FunctionListItem : public QListWidgetItem {
public:
FunctionListItem(QListWidget *view,
@ -59,6 +60,7 @@ public:
}
CppcheckLibraryData::Function *function;
};
}
LibraryDialog::LibraryDialog(QWidget *parent) :
QDialog(parent),

View File

@ -2943,6 +2943,7 @@ static const Token* findExpressionChangedImpl(const Token* expr,
return result;
}
namespace {
struct ExpressionChangedSimpleFind {
template<class F>
const Token* operator()(const Token* start, const Token* end, F f) const
@ -2964,6 +2965,7 @@ struct ExpressionChangedSkipDeadCode {
return findTokenSkipDeadCode(library, start, end, f, *evaluate);
}
};
}
const Token* findExpressionChanged(const Token* expr,
const Token* start,

View File

@ -107,6 +107,7 @@ static OpenMode getMode(const std::string& str)
return OpenMode::UNKNOWN_OM;
}
namespace {
struct Filepointer {
OpenMode mode;
nonneg int mode_indent{};
@ -119,7 +120,6 @@ struct Filepointer {
: mode(mode_) {}
};
namespace {
const std::unordered_set<std::string> whitelist = { "clearerr", "feof", "ferror", "fgetpos", "ftell", "setbuf", "setvbuf", "ungetc", "ungetwc" };
}

View File

@ -760,10 +760,12 @@ bool CheckStl::checkIteratorPair(const Token* tok1, const Token* tok2)
return false;
}
namespace {
struct ArgIteratorInfo {
const Token* tok;
const Library::ArgumentChecks::IteratorInfo* info;
};
}
void CheckStl::mismatchingContainers()
{
@ -913,6 +915,7 @@ static const Token* getInvalidMethod(const Token* tok)
return nullptr;
}
namespace {
struct InvalidContainerAnalyzer {
struct Info {
struct Reference {
@ -1009,6 +1012,7 @@ struct InvalidContainerAnalyzer {
}
}
};
}
static const Token* getLoopContainer(const Token* tok)
{

View File

@ -39,6 +39,7 @@
#include <utility>
#include <vector>
namespace {
struct OnExit {
std::function<void()> f;
@ -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;
@ -891,6 +878,7 @@ struct ForwardTraversal {
return getStepTok(end->link());
}
};
}
Analyzer::Result valueFlowGenericForward(Token* start, const Token* end, const ValuePtr<Analyzer>& a, const Settings& settings)
{

View File

@ -48,26 +48,11 @@ static const ValueFlow::Value* getCompareValue(const std::list<ValueFlow::Value>
return result;
}
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};
@ -250,9 +235,6 @@ struct Interval {
return {};
}
};
std::string toString(const Interval& i) {
return i.str();
}
static void addToErrorPath(ValueFlow::Value& value, const std::vector<const ValueFlow::Value*>& refs)

View File

@ -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

View File

@ -552,6 +552,7 @@ static std::string removeAssign(const std::string& assign) {
return std::string{assign.cbegin(), assign.cend() - 1};
}
namespace {
struct assign {
template<class T, class U>
void operator()(T& x, const U& y) const
@ -559,6 +560,7 @@ struct assign {
x = y;
}
};
}
static bool isIntegralValue(const ValueFlow::Value& value)
{
@ -1197,6 +1199,7 @@ static BuiltinLibraryFunction getBuiltinLibraryFunction(const std::string& name)
return it->second;
}
namespace {
struct Executor {
ProgramMemory* pm = nullptr;
const Settings* settings = nullptr;
@ -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 {
@ -1545,6 +1548,7 @@ struct Executor {
return {};
}
};
}
static ValueFlow::Value execute(const Token* expr, ProgramMemory& pm, const Settings* settings)
{

View File

@ -35,6 +35,7 @@
#include <utility>
#include <vector>
namespace {
struct ReverseTraversal {
ReverseTraversal(const ValuePtr<Analyzer>& analyzer, const Settings& settings)
: analyzer(analyzer), settings(settings)
@ -386,6 +387,7 @@ struct ReverseTraversal {
return nullptr;
}
};
}
void valueFlowGenericReverse(Token* start, const Token* end, const ValuePtr<Analyzer>& a, const Settings& settings)
{

View File

@ -396,6 +396,7 @@ std::size_t TokenList::calculateHash() const
//---------------------------------------------------------------------------
namespace {
struct AST_state {
std::stack<Token*> op;
int depth{};
@ -407,6 +408,7 @@ struct AST_state {
const Token* functionCallEndPar{};
explicit AST_state(bool cpp) : cpp(cpp) {}
};
}
static Token* skipDecl(Token* tok, std::vector<Token*>* inner = nullptr)
{
@ -1703,6 +1705,7 @@ void TokenList::createAst() const
}
}
namespace {
struct OnException {
std::function<void()> f;
@ -1713,6 +1716,7 @@ struct OnException {
#endif
}
};
}
void TokenList::validateAst() const
{

View File

@ -48,6 +48,7 @@ namespace {
};
}
using TestSet = std::set<TestFixture*, CompareFixtures>;
namespace {
class TestRegistry {
TestSet _tests;
public:
@ -65,6 +66,7 @@ public:
return _tests;
}
};
}