Skip to content

Commit e473000

Browse files
authored
moved some classes/structs into anonymous namespace (#5669)
1 parent 63a5a71 commit e473000

File tree

13 files changed

+1810
-1819
lines changed

13 files changed

+1810
-1819
lines changed

cli/cppcheckexecutor.cpp

Lines changed: 31 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -72,42 +72,44 @@
7272
#include <windows.h>
7373
#endif
7474

75-
class XMLErrorMessagesLogger : public ErrorLogger
76-
{
77-
void reportOut(const std::string & outmsg, Color /*c*/ = Color::Reset) override
78-
{
79-
std::cout << outmsg << std::endl;
80-
}
81-
82-
void reportErr(const ErrorMessage &msg) override
75+
namespace {
76+
class XMLErrorMessagesLogger : public ErrorLogger
8377
{
84-
reportOut(msg.toXML());
85-
}
78+
void reportOut(const std::string & outmsg, Color /*c*/ = Color::Reset) override
79+
{
80+
std::cout << outmsg << std::endl;
81+
}
8682

87-
void reportProgress(const std::string & /*filename*/, const char /*stage*/[], const std::size_t /*value*/) override
88-
{}
89-
};
83+
void reportErr(const ErrorMessage &msg) override
84+
{
85+
reportOut(msg.toXML());
86+
}
9087

91-
class CmdLineLoggerStd : public CmdLineLogger
92-
{
93-
public:
94-
CmdLineLoggerStd() = default;
88+
void reportProgress(const std::string & /*filename*/, const char /*stage*/[], const std::size_t /*value*/) override
89+
{}
90+
};
9591

96-
void printMessage(const std::string &message) override
92+
class CmdLineLoggerStd : public CmdLineLogger
9793
{
98-
printRaw("cppcheck: " + message);
99-
}
94+
public:
95+
CmdLineLoggerStd() = default;
10096

101-
void printError(const std::string &message) override
102-
{
103-
printMessage("error: " + message);
104-
}
97+
void printMessage(const std::string &message) override
98+
{
99+
printRaw("cppcheck: " + message);
100+
}
105101

106-
void printRaw(const std::string &message) override
107-
{
108-
std::cout << message << std::endl;
109-
}
110-
};
102+
void printError(const std::string &message) override
103+
{
104+
printMessage("error: " + message);
105+
}
106+
107+
void printRaw(const std::string &message) override
108+
{
109+
std::cout << message << std::endl;
110+
}
111+
};
112+
}
111113

112114
class CppCheckExecutor::StdLogger : public ErrorLogger
113115
{

cli/processexecutor.cpp

Lines changed: 43 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -68,59 +68,61 @@ ProcessExecutor::ProcessExecutor(const std::list<std::pair<std::string, std::siz
6868
assert(mSettings.jobs > 1);
6969
}
7070

71-
class PipeWriter : public ErrorLogger {
72-
public:
73-
enum PipeSignal {REPORT_OUT='1',REPORT_ERROR='2', CHILD_END='5'};
71+
namespace {
72+
class PipeWriter : public ErrorLogger {
73+
public:
74+
enum PipeSignal {REPORT_OUT='1',REPORT_ERROR='2', CHILD_END='5'};
7475

75-
explicit PipeWriter(int pipe) : mWpipe(pipe) {}
76+
explicit PipeWriter(int pipe) : mWpipe(pipe) {}
7677

77-
void reportOut(const std::string &outmsg, Color c) override {
78-
writeToPipe(REPORT_OUT, static_cast<char>(c) + outmsg);
79-
}
80-
81-
void reportErr(const ErrorMessage &msg) override {
82-
writeToPipe(REPORT_ERROR, msg.serialize());
83-
}
84-
85-
void writeEnd(const std::string& str) const {
86-
writeToPipe(CHILD_END, str);
87-
}
78+
void reportOut(const std::string &outmsg, Color c) override {
79+
writeToPipe(REPORT_OUT, static_cast<char>(c) + outmsg);
80+
}
8881

89-
private:
90-
// TODO: how to log file name in error?
91-
void writeToPipeInternal(PipeSignal type, const void* data, std::size_t to_write) const
92-
{
93-
const ssize_t bytes_written = write(mWpipe, data, to_write);
94-
if (bytes_written <= 0) {
95-
const int err = errno;
96-
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": " << std::strerror(err) << std::endl;
97-
std::exit(EXIT_FAILURE);
82+
void reportErr(const ErrorMessage &msg) override {
83+
writeToPipe(REPORT_ERROR, msg.serialize());
9884
}
99-
// TODO: write until everything is written
100-
if (bytes_written != to_write) {
101-
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << std::endl;
102-
std::exit(EXIT_FAILURE);
85+
86+
void writeEnd(const std::string& str) const {
87+
writeToPipe(CHILD_END, str);
10388
}
104-
}
10589

106-
void writeToPipe(PipeSignal type, const std::string &data) const
107-
{
90+
private:
91+
// TODO: how to log file name in error?
92+
void writeToPipeInternal(PipeSignal type, const void* data, std::size_t to_write) const
10893
{
109-
const char t = static_cast<char>(type);
110-
writeToPipeInternal(type, &t, 1);
94+
const ssize_t bytes_written = write(mWpipe, data, to_write);
95+
if (bytes_written <= 0) {
96+
const int err = errno;
97+
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": " << std::strerror(err) << std::endl;
98+
std::exit(EXIT_FAILURE);
99+
}
100+
// TODO: write until everything is written
101+
if (bytes_written != to_write) {
102+
std::cerr << "#### ThreadExecutor::writeToPipeInternal() error for type " << type << ": insufficient data written (expected: " << to_write << " / got: " << bytes_written << ")" << std::endl;
103+
std::exit(EXIT_FAILURE);
104+
}
111105
}
112106

113-
const unsigned int len = static_cast<unsigned int>(data.length());
107+
void writeToPipe(PipeSignal type, const std::string &data) const
114108
{
115-
static constexpr std::size_t l_size = sizeof(unsigned int);
116-
writeToPipeInternal(type, &len, l_size);
117-
}
109+
{
110+
const char t = static_cast<char>(type);
111+
writeToPipeInternal(type, &t, 1);
112+
}
118113

119-
writeToPipeInternal(type, data.c_str(), len);
120-
}
114+
const unsigned int len = static_cast<unsigned int>(data.length());
115+
{
116+
static constexpr std::size_t l_size = sizeof(unsigned int);
117+
writeToPipeInternal(type, &len, l_size);
118+
}
121119

122-
const int mWpipe;
123-
};
120+
writeToPipeInternal(type, data.c_str(), len);
121+
}
122+
123+
const int mWpipe;
124+
};
125+
}
124126

125127
bool ProcessExecutor::handleRead(int rpipe, unsigned int &result, const std::string& filename)
126128
{

gui/librarydialog.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,20 @@ class QWidget;
4747

4848
// TODO: get/compare functions from header
4949

50-
class FunctionListItem : public QListWidgetItem {
51-
public:
52-
FunctionListItem(QListWidget *view,
53-
CppcheckLibraryData::Function *function,
54-
bool selected)
55-
: QListWidgetItem(view), function(function) {
56-
setText(function->name);
57-
setFlags(flags() | Qt::ItemIsEditable);
58-
setSelected(selected);
59-
}
60-
CppcheckLibraryData::Function *function;
61-
};
50+
namespace {
51+
class FunctionListItem : public QListWidgetItem {
52+
public:
53+
FunctionListItem(QListWidget *view,
54+
CppcheckLibraryData::Function *function,
55+
bool selected)
56+
: QListWidgetItem(view), function(function) {
57+
setText(function->name);
58+
setFlags(flags() | Qt::ItemIsEditable);
59+
setSelected(selected);
60+
}
61+
CppcheckLibraryData::Function *function;
62+
};
63+
}
6264

6365
LibraryDialog::LibraryDialog(QWidget *parent) :
6466
QDialog(parent),

lib/astutils.cpp

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2943,27 +2943,29 @@ static const Token* findExpressionChangedImpl(const Token* expr,
29432943
return result;
29442944
}
29452945

2946-
struct ExpressionChangedSimpleFind {
2947-
template<class F>
2948-
const Token* operator()(const Token* start, const Token* end, F f) const
2949-
{
2950-
return findToken(start, end, f);
2951-
}
2952-
};
2953-
2954-
struct ExpressionChangedSkipDeadCode {
2955-
const Library* library;
2956-
const std::function<std::vector<MathLib::bigint>(const Token* tok)>* evaluate;
2957-
ExpressionChangedSkipDeadCode(const Library* library,
2958-
const std::function<std::vector<MathLib::bigint>(const Token* tok)>& evaluate)
2959-
: library(library), evaluate(&evaluate)
2960-
{}
2961-
template<class F>
2962-
const Token* operator()(const Token* start, const Token* end, F f) const
2963-
{
2964-
return findTokenSkipDeadCode(library, start, end, f, *evaluate);
2965-
}
2966-
};
2946+
namespace {
2947+
struct ExpressionChangedSimpleFind {
2948+
template<class F>
2949+
const Token* operator()(const Token* start, const Token* end, F f) const
2950+
{
2951+
return findToken(start, end, f);
2952+
}
2953+
};
2954+
2955+
struct ExpressionChangedSkipDeadCode {
2956+
const Library* library;
2957+
const std::function<std::vector<MathLib::bigint>(const Token* tok)>* evaluate;
2958+
ExpressionChangedSkipDeadCode(const Library* library,
2959+
const std::function<std::vector<MathLib::bigint>(const Token* tok)>& evaluate)
2960+
: library(library), evaluate(&evaluate)
2961+
{}
2962+
template<class F>
2963+
const Token* operator()(const Token* start, const Token* end, F f) const
2964+
{
2965+
return findTokenSkipDeadCode(library, start, end, f, *evaluate);
2966+
}
2967+
};
2968+
}
29672969

29682970
const Token* findExpressionChanged(const Token* expr,
29692971
const Token* start,

lib/checkio.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,19 @@ static OpenMode getMode(const std::string& str)
107107
return OpenMode::UNKNOWN_OM;
108108
}
109109

110-
struct Filepointer {
111-
OpenMode mode;
112-
nonneg int mode_indent{};
113-
enum class Operation {NONE, UNIMPORTANT, READ, WRITE, POSITIONING, OPEN, CLOSE, UNKNOWN_OP} lastOperation = Operation::NONE;
114-
nonneg int op_indent{};
115-
enum class AppendMode { UNKNOWN_AM, APPEND, APPEND_EX };
116-
AppendMode append_mode = AppendMode::UNKNOWN_AM;
117-
std::string filename;
118-
explicit Filepointer(OpenMode mode_ = OpenMode::UNKNOWN_OM)
119-
: mode(mode_) {}
120-
};
121-
122110
namespace {
111+
struct Filepointer {
112+
OpenMode mode;
113+
nonneg int mode_indent{};
114+
enum class Operation {NONE, UNIMPORTANT, READ, WRITE, POSITIONING, OPEN, CLOSE, UNKNOWN_OP} lastOperation = Operation::NONE;
115+
nonneg int op_indent{};
116+
enum class AppendMode { UNKNOWN_AM, APPEND, APPEND_EX };
117+
AppendMode append_mode = AppendMode::UNKNOWN_AM;
118+
std::string filename;
119+
explicit Filepointer(OpenMode mode_ = OpenMode::UNKNOWN_OM)
120+
: mode(mode_) {}
121+
};
122+
123123
const std::unordered_set<std::string> whitelist = { "clearerr", "feof", "ferror", "fgetpos", "ftell", "setbuf", "setvbuf", "ungetc", "ungetwc" };
124124
}
125125

0 commit comments

Comments
 (0)