Skip to content

Commit 18cfb6a

Browse files
committed
switch from astyle to uncrustify and reuse same configuration used in cppcheck
1 parent 5fcb073 commit 18cfb6a

File tree

7 files changed

+234
-75
lines changed

7 files changed

+234
-75
lines changed

.uncrustify.cfg

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Uncrustify-0.80.1_f
2+
3+
# The original size of tabs in the input.
4+
#
5+
# Default: 8
6+
input_tab_size = 4 # unsigned number
7+
8+
# The size of tabs in the output (only used if align_with_tabs=true).
9+
#
10+
# Default: 8
11+
output_tab_size = 4 # unsigned number
12+
13+
# Add or remove space between 'while' and '('.
14+
sp_while_paren_open = add # ignore/add/remove/force
15+
16+
# Add or remove space around boolean operators '&&' and '||'.
17+
sp_bool = force # ignore/add/remove/force
18+
19+
# Add or remove space inside '(' and ')'.
20+
sp_inside_paren = remove # ignore/add/remove/force
21+
22+
# Add or remove space between nested parentheses, i.e. '((' vs. ') )'.
23+
sp_paren_paren = remove # ignore/add/remove/force
24+
25+
# Add or remove space between ')' and '{'.
26+
sp_paren_brace = force # ignore/add/remove/force
27+
28+
# Add or remove space between pointer stars '*'.
29+
sp_between_ptr_star = remove # ignore/add/remove/force
30+
31+
# Add or remove space before '<'.
32+
sp_before_angle = remove # ignore/add/remove/force
33+
34+
# Add or remove space inside '<' and '>'.
35+
sp_inside_angle = remove # ignore/add/remove/force
36+
37+
# Add or remove space after '>'.
38+
sp_after_angle = add # ignore/add/remove/force
39+
40+
# Add or remove space between '>' and '(' as found in 'new List<byte>(foo);'.
41+
sp_angle_paren = remove # ignore/add/remove/force
42+
43+
# Add or remove space between '>' and a word as in 'List<byte> m;' or
44+
# 'template <typename T> static ...'.
45+
sp_angle_word = add # ignore/add/remove/force
46+
47+
# Add or remove space between '>' and '>' in '>>' (template stuff).
48+
#
49+
# Default: add
50+
sp_angle_shift = ignore # ignore/add/remove/force
51+
52+
# (C++11) Permit removal of the space between '>>' in 'foo<bar<int> >'. Note
53+
# that sp_angle_shift cannot remove the space without this option.
54+
sp_permit_cpp11_shift = true # true/false
55+
56+
# Add or remove space before '(' of control statements ('if', 'for', 'switch',
57+
# 'while', etc.).
58+
sp_before_sparen = force # ignore/add/remove/force
59+
60+
# Add or remove space inside '(' and ')' of control statements.
61+
sp_inside_sparen = remove # ignore/add/remove/force
62+
63+
# Add or remove space after ')' of control statements.
64+
sp_after_sparen = force # ignore/add/remove/force
65+
66+
# Add or remove space between ')' and '{' of of control statements.
67+
sp_sparen_brace = force # ignore/add/remove/force
68+
69+
# Add or remove space before ';' in non-empty 'for' statements.
70+
sp_before_semi_for = remove # ignore/add/remove/force
71+
72+
# Add or remove space after the final semicolon of an empty part of a for
73+
# statement, as in 'for ( ; ; <here> )'.
74+
sp_after_semi_for_empty = remove # ignore/add/remove/force
75+
76+
# Add or remove space before '[]'.
77+
sp_before_squares = remove # ignore/add/remove/force
78+
79+
# Add or remove space before C++17 structured bindings.
80+
sp_cpp_before_struct_binding = ignore # ignore/add/remove/force
81+
82+
# Add or remove space inside a non-empty '[' and ']'.
83+
sp_inside_square = remove # ignore/add/remove/force
84+
85+
# Add or remove space after class ':'.
86+
sp_after_class_colon = force # ignore/add/remove/force
87+
88+
# Add or remove space before class ':'.
89+
sp_before_class_colon = force # ignore/add/remove/force
90+
91+
# Add or remove space inside '{}'.
92+
sp_inside_braces_empty = remove # ignore/add/remove/force
93+
94+
# Add or remove space between 'else' and '{' if on the same line.
95+
sp_else_brace = force # ignore/add/remove/force
96+
97+
# Add or remove space between '}' and 'else' if on the same line.
98+
sp_brace_else = force # ignore/add/remove/force
99+
100+
# Add or remove space before the '{' of a 'catch' statement, if the '{' and
101+
# 'catch' are on the same line, as in 'catch (decl) <here> {'.
102+
sp_catch_brace = force # ignore/add/remove/force
103+
104+
# Add or remove space between '}' and 'catch' if on the same line.
105+
sp_brace_catch = force # ignore/add/remove/force
106+
107+
# The number of columns to indent per level. Usually 2, 3, 4, or 8.
108+
#
109+
# Default: 8
110+
indent_columns = 4 # unsigned number
111+
112+
# How to use tabs when indenting code.
113+
#
114+
# 0: Spaces only
115+
# 1: Indent with tabs to brace level, align with spaces (default)
116+
# 2: Indent and align with tabs, using spaces when not on a tabstop
117+
#
118+
# Default: 1
119+
indent_with_tabs = 0 # unsigned number
120+
121+
# Whether to indent the body of a 'namespace'.
122+
indent_namespace = true # true/false
123+
124+
# Whether the 'class' body is indented.
125+
indent_class = true # true/false
126+
127+
# How to indent access specifiers that are followed by a
128+
# colon.
129+
#
130+
# >0: Absolute column where 1 is the leftmost column
131+
# <=0: Subtract from brace indent
132+
#
133+
# Default: 1
134+
indent_access_spec = -4 # number
135+
136+
# Whether to collapse empty blocks between '{' and '}' except for functions.
137+
# Use nl_collapse_empty_body_functions to specify how empty function braces
138+
# should be formatted.
139+
nl_collapse_empty_body = true # true/false
140+
141+
# Whether to collapse empty blocks between '{' and '}' for functions only.
142+
# If true, overrides nl_inside_empty_func.
143+
nl_collapse_empty_body_functions = true # true/false
144+
145+
# Whether to convert all tabs to spaces in comments. If false, tabs in
146+
# comments are left alone, unless used for indenting.
147+
cmt_convert_tab_to_spaces = true # true/false
148+
149+
# An offset value that controls the indentation of the body of a multiline #define.
150+
# 'body' refers to all the lines of a multiline #define except the first line.
151+
# Requires 'pp_ignore_define_body = false'.
152+
#
153+
# <0: Absolute column: the body indentation starts off at the specified column
154+
# (ex. -3 ==> the body is indented starting from column 3)
155+
# >=0: Relative to the column of the '#' of '#define'
156+
# (ex. 3 ==> the body is indented starting 3 columns at the right of '#')
157+
#
158+
# Default: 8
159+
pp_multiline_define_body_indent = 4 # number
160+
161+
# The value might be used twice:
162+
# - at the assignment
163+
# - at the opening brace
164+
#
165+
# To prevent the double use of the indentation value, use this option with the
166+
# value 'true'.
167+
#
168+
# true: indentation will be used only once
169+
# false: indentation will be used every time (default)
170+
indent_cpp_lambda_only_once = true # true/false

runastyle

Lines changed: 0 additions & 23 deletions
This file was deleted.

runastyle.bat

Lines changed: 0 additions & 26 deletions
This file was deleted.

runformat

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/bash
2+
#
3+
# uncrustify-0.72 is used to format simplecpp and cppcheck source code.
4+
#
5+
# 1. Download source code: https://github.com/uncrustify/uncrustify/archive/refs/tags/uncrustify-0.72.0.zip
6+
# It's important that all developers use the exact same version so we don't get a "format battle".
7+
# 2. Building:
8+
# - Linux: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make
9+
# - Windows: mkdir build && cd build && cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release .. && nmake
10+
# 3. Ensure that the binary "uncrustify" is found by runformat. Either:
11+
# - you can put uncrustify in your PATH
12+
# - you can create an environment variable UNCRUSTIFY that has the full path of the binary
13+
14+
UNCRUSTIFY_VERSION="0.72.0"
15+
UNCRUSTIFY="${UNCRUSTIFY-uncrustify}"
16+
17+
DETECTED_VERSION=$("$UNCRUSTIFY" --version 2>&1 | grep -o -E '[0-9.]+')
18+
if [ "$DETECTED_VERSION" != "${UNCRUSTIFY_VERSION}" ]; then
19+
echo "You should use version: ${UNCRUSTIFY_VERSION}"
20+
echo "Detected version: ${DETECTED_VERSION}"
21+
exit 1
22+
fi
23+
24+
# OS variables
25+
[ $(uname -s) = "Darwin" ] && export OSX=1 && export UNIX=1
26+
[ $(uname -s) = "Linux" ] && export LINUX=1 && export UNIX=1
27+
uname -s | grep -q "_NT-" && export WINDOWS=1
28+
29+
if [ $OSX ]
30+
then
31+
export CPUCOUNT=$(sysctl -n hw.ncpu)
32+
elif [ $LINUX ]
33+
then
34+
export CPUCOUNT=$(nproc)
35+
else
36+
export CPUCOUNT="1"
37+
fi
38+
39+
$UNCRUSTIFY -c .uncrustify.cfg --no-backup *.cpp *.h

simplecpp.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -761,18 +761,18 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
761761
while (stream.good() && ch != '\n') {
762762
currentToken += ch;
763763
ch = stream.readChar();
764-
if(ch == '\\') {
764+
if (ch == '\\') {
765765
TokenString tmp;
766766
char tmp_ch = ch;
767-
while((stream.good()) && (tmp_ch == '\\' || tmp_ch == ' ' || tmp_ch == '\t')) {
767+
while ((stream.good()) && (tmp_ch == '\\' || tmp_ch == ' ' || tmp_ch == '\t')) {
768768
tmp += tmp_ch;
769769
tmp_ch = stream.readChar();
770770
}
771-
if(!stream.good()) {
771+
if (!stream.good()) {
772772
break;
773773
}
774774

775-
if(tmp_ch != '\n') {
775+
if (tmp_ch != '\n') {
776776
currentToken += tmp;
777777
} else {
778778
const TokenString check_portability = currentToken + tmp;
@@ -1667,7 +1667,7 @@ namespace simplecpp {
16671667
}
16681668

16691669
invalidHashHash(const Location &loc, const std::string &macroName, const std::string &message)
1670-
: Error(loc, format(macroName, message)) { }
1670+
: Error(loc, format(macroName, message)) {}
16711671

16721672
static inline invalidHashHash unexpectedToken(const Location &loc, const std::string &macroName, const Token *tokenA) {
16731673
return invalidHashHash(loc, macroName, "Unexpected token '"+ tokenA->str()+"'");
@@ -2672,7 +2672,7 @@ static unsigned long long stringToULLbounded(
26722672
int base = 0,
26732673
std::ptrdiff_t minlen = 1,
26742674
std::size_t maxlen = std::string::npos
2675-
)
2675+
)
26762676
{
26772677
const std::string sub = s.substr(pos, maxlen);
26782678
const char * const start = sub.c_str();
@@ -3354,7 +3354,7 @@ void simplecpp::preprocess(simplecpp::TokenList &output, const simplecpp::TokenL
33543354
includetokenstack.push(filedata->tokens.cfront());
33553355
}
33563356

3357-
std::map<std::string, std::list<Location> > maybeUsedMacros;
3357+
std::map<std::string, std::list<Location>> maybeUsedMacros;
33583358

33593359
for (const Token *rawtok = nullptr; rawtok || !includetokenstack.empty();) {
33603360
if (rawtok == nullptr) {
@@ -3751,11 +3751,11 @@ simplecpp::cstd_t simplecpp::getCStd(const std::string &std)
37513751
{
37523752
if (std == "c90" || std == "c89" || std == "iso9899:1990" || std == "iso9899:199409" || std == "gnu90" || std == "gnu89")
37533753
return C89;
3754-
if (std == "c99" || std == "c9x" || std == "iso9899:1999" || std == "iso9899:199x" || std == "gnu99"|| std == "gnu9x")
3754+
if (std == "c99" || std == "c9x" || std == "iso9899:1999" || std == "iso9899:199x" || std == "gnu99" || std == "gnu9x")
37553755
return C99;
37563756
if (std == "c11" || std == "c1x" || std == "iso9899:2011" || std == "gnu11" || std == "gnu1x")
37573757
return C11;
3758-
if (std == "c17" || std == "c18" || std == "iso9899:2017" || std == "iso9899:2018" || std == "gnu17"|| std == "gnu18")
3758+
if (std == "c17" || std == "c18" || std == "iso9899:2017" || std == "iso9899:2018" || std == "gnu17" || std == "gnu18")
37593759
return C17;
37603760
if (std == "c23" || std == "gnu23" || std == "c2x" || std == "gnu2x")
37613761
return C23;

simplecpp.h

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ namespace simplecpp {
114114
}
115115

116116
Token(const Token &tok) :
117-
macro(tok.macro), op(tok.op), comment(tok.comment), name(tok.name), number(tok.number), whitespaceahead(tok.whitespaceahead), location(tok.location), previous(nullptr), next(nullptr), nextcond(nullptr), string(tok.string), mExpandedFrom(tok.mExpandedFrom) {
118-
}
117+
macro(tok.macro), op(tok.op), comment(tok.comment), name(tok.name), number(tok.number), whitespaceahead(tok.whitespaceahead), location(tok.location), previous(nullptr), next(nullptr), nextcond(nullptr), string(tok.string), mExpandedFrom(tok.mExpandedFrom) {}
119118

120119
void flags() {
121120
name = (std::isalpha(static_cast<unsigned char>(string[0])) || string[0] == '_' || string[0] == '$')
@@ -325,9 +324,9 @@ namespace simplecpp {
325324
struct SIMPLECPP_LIB MacroUsage {
326325
explicit MacroUsage(const std::vector<std::string> &f, bool macroValueKnown_) : macroLocation(f), useLocation(f), macroValueKnown(macroValueKnown_) {}
327326
std::string macroName;
328-
Location macroLocation;
329-
Location useLocation;
330-
bool macroValueKnown;
327+
Location macroLocation;
328+
Location useLocation;
329+
bool macroValueKnown;
331330
};
332331

333332
/** Tracking #if/#elif expressions */

0 commit comments

Comments
 (0)