Skip to content

Commit 15ab116

Browse files
committed
update format
1 parent edfb617 commit 15ab116

12 files changed

Lines changed: 126 additions & 127 deletions

File tree

.clang-format

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ BraceWrapping:
1515
AfterUnion: false
1616
BeforeCatch: false
1717
BeforeElse: false
18-
18+
19+
AlignConsecutiveShortCaseStatements:
20+
Enabled: true
21+
AcrossEmptyLines: true
22+
AcrossComments: true
23+
AlignCaseColons: false
1924

2025
CompactNamespaces: false
2126
AlignConsecutiveAssignments: true

include/zeroerr/assert.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ struct context_helper<T, false> {
280280
switch (data.info.level) {
281281
case assert_level::ZEROERR_FATAL_l:
282282
case assert_level::ZEROERR_ERROR_l: ctx->failed_as++; break;
283-
case assert_level::ZEROERR_WARN_l: ctx->warning_as++; break;
283+
case assert_level::ZEROERR_WARN_l: ctx->warning_as++; break;
284284
}
285285
}
286286
};

include/zeroerr/benchmark.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
1616

17-
#define ZEROERR_CREATE_BENCHMARK_FUNC(function, name) \
18-
static void function(zeroerr::TestContext*); \
19-
static zeroerr::detail::regTest ZEROERR_NAMEGEN(_zeroerr_reg)( \
17+
#define ZEROERR_CREATE_BENCHMARK_FUNC(function, name) \
18+
static void function(zeroerr::TestContext*); \
19+
static zeroerr::detail::regTest ZEROERR_NAMEGEN(_zeroerr_reg)( \
2020
{name, __FILE__, __LINE__, function}, zeroerr::TestType::bench); \
2121
static void function(ZEROERR_UNUSED(zeroerr::TestContext* _ZEROERR_TEST_CONTEXT))
2222

@@ -48,7 +48,7 @@ using Clock = std::conditional<std::chrono::high_resolution_clock::is_steady,
4848
namespace detail {
4949
struct LinuxPerformanceCounter;
5050
struct WindowsPerformanceCounter;
51-
}
51+
} // namespace detail
5252

5353
/**
5454
* @brief PerformanceCounter is a class to measure the performance of a function.
@@ -73,7 +73,7 @@ struct PerformanceCounter {
7373
PerfCountSet<uint64_t> _val;
7474
PerfCountSet<bool> _has;
7575

76-
detail::LinuxPerformanceCounter* _perf = nullptr;
76+
detail::LinuxPerformanceCounter* _perf = nullptr;
7777
detail::WindowsPerformanceCounter* win_perf = nullptr;
7878
};
7979

include/zeroerr/format.h

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
#pragma once
22
#include "zeroerr/print.h"
33

4-
#include <string>
54
#include <sstream>
5+
#include <string>
66

7-
namespace zeroerr
8-
{
7+
namespace zeroerr {
98

109
template <typename... T>
1110
std::string format(const char* fmt, T... args) {
1211
std::stringstream ss;
13-
bool parse_name = false;
14-
Printer print;
15-
print.isQuoted = false; print.isCompact = true;
16-
print.line_break = "";
12+
bool parse_name = false;
13+
Printer print;
14+
15+
print.isQuoted = false;
16+
print.isCompact = true;
17+
print.line_break = "";
1718
std::string str_args[] = {print(args)...};
19+
1820
int j = 0;
1921
for (const char* i = fmt; *i != '\0'; i++) {
20-
switch (*i)
21-
{
22-
case '{':
23-
parse_name = true;
24-
break;
25-
case '}':
26-
parse_name = false;
27-
ss << str_args[j++];
28-
break;
29-
default:
30-
if (!parse_name) ss << *i;
31-
break;
22+
switch (*i) {
23+
case '{': parse_name = true; break;
24+
case '}':
25+
parse_name = false;
26+
ss << str_args[j++];
27+
break;
28+
default:
29+
if (!parse_name) ss << *i;
30+
break;
3231
}
3332
}
3433
return ss.str();
3534
}
3635

37-
} // namespace zeroerr
36+
} // namespace zeroerr

include/zeroerr/print.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "zeroerr/internal/typetraits.h"
66

77

8-
98
#ifdef __GNUG__
109
#include <cxxabi.h>
1110
#endif
@@ -25,7 +24,6 @@
2524
ZEROERR_SUPPRESS_COMMON_WARNINGS_PUSH
2625

2726

28-
2927
namespace zeroerr {
3028

3129

@@ -224,7 +222,8 @@ struct Printer {
224222

225223
template <class TupType, unsigned... I>
226224
inline void print_tuple(const TupType& _tup, unsigned level, const char*, detail::seq<I...>) {
227-
int _[] = {(os << (I == 0 ? "" : ", "), print(std::get<I>(_tup), level+1, "", rank<max_rank>{}), 0)...};
225+
int _[] = {(os << (I == 0 ? "" : ", "),
226+
print(std::get<I>(_tup), level + 1, "", rank<max_rank>{}), 0)...};
228227
(void)_;
229228
}
230229

src/console.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ bool isTerminalOutput(OutputStream stream) {
1818
switch (stream) {
1919
case STDOUT: return isatty(fileno(stdout)) != 0;
2020
case STDERR: return isatty(fileno(stderr)) != 0;
21-
default: return false;
21+
default: return false;
2222
}
2323
}
2424

@@ -36,7 +36,7 @@ bool isTerminalOutput(OutputStream stream) {
3636
switch (stream) {
3737
case STDOUT: return GetFileType(GetStdHandle(STD_OUTPUT_HANDLE)) == FILE_TYPE_CHAR;
3838
case STDERR: return GetFileType(GetStdHandle(STD_ERROR_HANDLE)) == FILE_TYPE_CHAR;
39-
default: return false;
39+
default: return false;
4040
}
4141
}
4242

src/fuzztest.cpp

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,39 @@
11
#include "zeroerr/fuzztest.h"
2-
#include "zeroerr/log.h"
32
#include "zeroerr/assert.h"
3+
#include "zeroerr/log.h"
44

55
#include <cstring>
66
#ifdef ZEROERR_ENABLE_FUZZING
77
extern "C" int LLVMFuzzerRunDriver(int* argc, char*** argv,
8-
int (*user_callback)(const uint8_t* data,
9-
size_t size));
8+
int (*user_callback)(const uint8_t* data, size_t size));
109

11-
extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size,
12-
size_t max_size, unsigned int seed);
10+
extern "C" size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size, size_t max_size,
11+
unsigned int seed);
1312
#endif
1413

1514
namespace zeroerr {
1615
static IFuzzTest* current_fuzz_test = nullptr;
1716
} // namespace zeroerr
1817

19-
size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size, size_t max_size,
20-
unsigned int seed) {
21-
const std::string mutated_data = zeroerr::current_fuzz_test->MutateData(data, size, max_size, seed);
22-
if (mutated_data.size() > max_size) {
23-
WARN("Mutated data is larger than the limit({limit}). Returning the original data ({ori})", max_size, size);
24-
return size;
25-
}
26-
memcpy(data, mutated_data.data(), mutated_data.size());
27-
return mutated_data.size();
18+
size_t LLVMFuzzerCustomMutator(uint8_t* data, size_t size, size_t max_size, unsigned int seed) {
19+
const std::string mutated_data =
20+
zeroerr::current_fuzz_test->MutateData(data, size, max_size, seed);
21+
if (mutated_data.size() > max_size) {
22+
WARN("Mutated data is larger than the limit({limit}). Returning the original data ({ori})",
23+
max_size, size);
24+
return size;
25+
}
26+
memcpy(data, mutated_data.data(), mutated_data.size());
27+
return mutated_data.size();
2828
}
2929

3030
namespace zeroerr {
3131

32-
void RunFuzzTest(IFuzzTest& fuzz_test, int seed, int runs, int max_len, int timeout, int len_control) {
32+
void RunFuzzTest(IFuzzTest& fuzz_test, int seed, int runs, int max_len, int timeout,
33+
int len_control) {
3334
#ifdef ZEROERR_ENABLE_FUZZING
34-
current_fuzz_test = &fuzz_test;
35-
int argc = 6;
35+
current_fuzz_test = &fuzz_test;
36+
int argc = 6;
3637
std::string argv[] = {
3738
"fuzztest",
3839
"-max_len=" + std::to_string(max_len),
@@ -46,9 +47,9 @@ void RunFuzzTest(IFuzzTest& fuzz_test, int seed, int runs, int max_len, int time
4647
argv_c[i] = (char*)argv[i].c_str();
4748
}
4849
LOG("Running fuzz test");
49-
50+
5051
LLVMFuzzerRunDriver(&argc, &argv_c, [](const uint8_t* data, size_t size) -> int {
51-
LOG("Running RunOneTime");
52+
LOG("Running RunOneTime");
5253
if (current_fuzz_test->should_stop()) {
5354
throw FuzzFinishedException();
5455
}

src/log.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ LogInfo::LogInfo(const char* filename, const char* function, const char* message
2929
const char* q = p + 1;
3030
while (*q && *q != '}') q++;
3131
if (*q == '}') {
32-
names[std::string(p + 1, q)] = names.size();
33-
p = q;
32+
std::string N(p + 1, q);
33+
names[N] = names.size();
34+
p = q;
3435
}
3536
}
3637
}
@@ -213,9 +214,9 @@ static std::string DefaultLogCallback(const LogMessage& msg, bool colorful) {
213214

214215
ss << zeroerr_color(Dim) << '[' << zeroerr_color(Reset);
215216
switch (msg.info->severity) {
216-
case INFO_l: ss << "INFO "; break;
217-
case LOG_l: ss << zeroerr_color(FgGreen) << "LOG " << zeroerr_color(Reset); break;
218-
case WARN_l: ss << zeroerr_color(FgYellow) << "WARN " << zeroerr_color(Reset); break;
217+
case INFO_l: ss << "INFO "; break;
218+
case LOG_l: ss << zeroerr_color(FgGreen) << "LOG " << zeroerr_color(Reset); break;
219+
case WARN_l: ss << zeroerr_color(FgYellow) << "WARN " << zeroerr_color(Reset); break;
219220
case ERROR_l: ss << zeroerr_color(FgRed) << "ERROR" << zeroerr_color(Reset); break;
220221
case FATAL_l: ss << zeroerr_color(FgMagenta) << "FATAL" << zeroerr_color(Reset); break;
221222
}

src/rng.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44
#include <stdexcept>
55
#include <string>
66

7-
namespace zeroerr
8-
{
7+
namespace zeroerr {
98

109
Rng::Rng() : mX(0), mY(0) {
1110
std::random_device rd;
@@ -57,9 +56,7 @@ uint64_t Rng::min() { return 0; }
5756
uint64_t Rng::max() { return (std::numeric_limits<uint64_t>::max)(); }
5857

5958

60-
uint64_t Rng::rotl(uint64_t x, unsigned k) noexcept {
61-
return (x << k) | (x >> (64U - k));
62-
}
59+
uint64_t Rng::rotl(uint64_t x, unsigned k) noexcept { return (x << k) | (x >> (64U - k)); }
6360

6461

65-
} // namespace zeroerr
62+
} // namespace zeroerr

src/table.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "zeroerr/table.h"
2-
#include "zeroerr/log.h"
32
#include "zeroerr/assert.h"
3+
#include "zeroerr/log.h"
44

55
#include <algorithm>
66
#include <map>

0 commit comments

Comments
 (0)