Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 170 additions & 0 deletions .uncrustify.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
# Uncrustify-0.80.1_f

# The original size of tabs in the input.
#
# Default: 8
input_tab_size = 4 # unsigned number

# The size of tabs in the output (only used if align_with_tabs=true).
#
# Default: 8
output_tab_size = 4 # unsigned number

# Add or remove space between 'while' and '('.
sp_while_paren_open = add # ignore/add/remove/force

# Add or remove space around boolean operators '&&' and '||'.
sp_bool = force # ignore/add/remove/force

# Add or remove space inside '(' and ')'.
sp_inside_paren = remove # ignore/add/remove/force

# Add or remove space between nested parentheses, i.e. '((' vs. ') )'.
sp_paren_paren = remove # ignore/add/remove/force

# Add or remove space between ')' and '{'.
sp_paren_brace = force # ignore/add/remove/force

# Add or remove space between pointer stars '*'.
sp_between_ptr_star = remove # ignore/add/remove/force

# Add or remove space before '<'.
sp_before_angle = remove # ignore/add/remove/force

# Add or remove space inside '<' and '>'.
sp_inside_angle = remove # ignore/add/remove/force

# Add or remove space after '>'.
sp_after_angle = add # ignore/add/remove/force

# Add or remove space between '>' and '(' as found in 'new List<byte>(foo);'.
sp_angle_paren = remove # ignore/add/remove/force

# Add or remove space between '>' and a word as in 'List<byte> m;' or
# 'template <typename T> static ...'.
sp_angle_word = add # ignore/add/remove/force

# Add or remove space between '>' and '>' in '>>' (template stuff).
#
# Default: add
sp_angle_shift = ignore # ignore/add/remove/force

# (C++11) Permit removal of the space between '>>' in 'foo<bar<int> >'. Note
# that sp_angle_shift cannot remove the space without this option.
sp_permit_cpp11_shift = true # true/false

# Add or remove space before '(' of control statements ('if', 'for', 'switch',
# 'while', etc.).
sp_before_sparen = force # ignore/add/remove/force

# Add or remove space inside '(' and ')' of control statements.
sp_inside_sparen = remove # ignore/add/remove/force

# Add or remove space after ')' of control statements.
sp_after_sparen = force # ignore/add/remove/force

# Add or remove space between ')' and '{' of of control statements.
sp_sparen_brace = force # ignore/add/remove/force

# Add or remove space before ';' in non-empty 'for' statements.
sp_before_semi_for = remove # ignore/add/remove/force

# Add or remove space after the final semicolon of an empty part of a for
# statement, as in 'for ( ; ; <here> )'.
sp_after_semi_for_empty = remove # ignore/add/remove/force

# Add or remove space before '[]'.
sp_before_squares = remove # ignore/add/remove/force

# Add or remove space before C++17 structured bindings.
sp_cpp_before_struct_binding = ignore # ignore/add/remove/force

# Add or remove space inside a non-empty '[' and ']'.
sp_inside_square = remove # ignore/add/remove/force

# Add or remove space after class ':'.
sp_after_class_colon = force # ignore/add/remove/force

# Add or remove space before class ':'.
sp_before_class_colon = force # ignore/add/remove/force

# Add or remove space inside '{}'.
sp_inside_braces_empty = remove # ignore/add/remove/force

# Add or remove space between 'else' and '{' if on the same line.
sp_else_brace = force # ignore/add/remove/force

# Add or remove space between '}' and 'else' if on the same line.
sp_brace_else = force # ignore/add/remove/force

# Add or remove space before the '{' of a 'catch' statement, if the '{' and
# 'catch' are on the same line, as in 'catch (decl) <here> {'.
sp_catch_brace = force # ignore/add/remove/force

# Add or remove space between '}' and 'catch' if on the same line.
sp_brace_catch = force # ignore/add/remove/force

# The number of columns to indent per level. Usually 2, 3, 4, or 8.
#
# Default: 8
indent_columns = 4 # unsigned number

# How to use tabs when indenting code.
#
# 0: Spaces only
# 1: Indent with tabs to brace level, align with spaces (default)
# 2: Indent and align with tabs, using spaces when not on a tabstop
#
# Default: 1
indent_with_tabs = 0 # unsigned number

# Whether to indent the body of a 'namespace'.
indent_namespace = true # true/false

# Whether the 'class' body is indented.
indent_class = true # true/false

# How to indent access specifiers that are followed by a
# colon.
#
# >0: Absolute column where 1 is the leftmost column
# <=0: Subtract from brace indent
#
# Default: 1
indent_access_spec = -4 # number

# Whether to collapse empty blocks between '{' and '}' except for functions.
# Use nl_collapse_empty_body_functions to specify how empty function braces
# should be formatted.
nl_collapse_empty_body = true # true/false

# Whether to collapse empty blocks between '{' and '}' for functions only.
# If true, overrides nl_inside_empty_func.
nl_collapse_empty_body_functions = true # true/false

# Whether to convert all tabs to spaces in comments. If false, tabs in
# comments are left alone, unless used for indenting.
cmt_convert_tab_to_spaces = true # true/false

# An offset value that controls the indentation of the body of a multiline #define.
# 'body' refers to all the lines of a multiline #define except the first line.
# Requires 'pp_ignore_define_body = false'.
#
# <0: Absolute column: the body indentation starts off at the specified column
# (ex. -3 ==> the body is indented starting from column 3)
# >=0: Relative to the column of the '#' of '#define'
# (ex. 3 ==> the body is indented starting 3 columns at the right of '#')
#
# Default: 8
pp_multiline_define_body_indent = 4 # number

# The value might be used twice:
# - at the assignment
# - at the opening brace
#
# To prevent the double use of the indentation value, use this option with the
# value 'true'.
#
# true: indentation will be used only once
# false: indentation will be used every time (default)
indent_cpp_lambda_only_once = true # true/false
23 changes: 0 additions & 23 deletions runastyle

This file was deleted.

26 changes: 0 additions & 26 deletions runastyle.bat

This file was deleted.

39 changes: 39 additions & 0 deletions runformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash
#
# uncrustify-0.72 is used to format simplecpp and cppcheck source code.
#
# 1. Download source code: https://github.com/uncrustify/uncrustify/archive/refs/tags/uncrustify-0.72.0.zip
# It's important that all developers use the exact same version so we don't get a "format battle".
# 2. Building:
# - Linux: mkdir build && cd build && cmake -DCMAKE_BUILD_TYPE=Release .. && make
# - Windows: mkdir build && cd build && cmake -G"NMake Makefiles" -DCMAKE_BUILD_TYPE=Release .. && nmake
# 3. Ensure that the binary "uncrustify" is found by runformat. Either:
# - you can put uncrustify in your PATH
# - you can create an environment variable UNCRUSTIFY that has the full path of the binary

UNCRUSTIFY_VERSION="0.72.0"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is likely incorrect and inconsistent, inspecting danmar/cppcheck@3726ace seems to indicate that the version should be 0.80.1

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree. I copied the file directly from cppcheck main though. :-( maybe we need to update the script both in cppcheck and simplecpp..

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we need to update the script both in cppcheck and simplecpp..

would you have time to look at that maybe?

UNCRUSTIFY="${UNCRUSTIFY-uncrustify}"

DETECTED_VERSION=$("$UNCRUSTIFY" --version 2>&1 | grep -o -E '[0-9.]+')
if [ "$DETECTED_VERSION" != "${UNCRUSTIFY_VERSION}" ]; then
echo "You should use version: ${UNCRUSTIFY_VERSION}"
echo "Detected version: ${DETECTED_VERSION}"
exit 1
fi

# OS variables
[ $(uname -s) = "Darwin" ] && export OSX=1 && export UNIX=1
[ $(uname -s) = "Linux" ] && export LINUX=1 && export UNIX=1
uname -s | grep -q "_NT-" && export WINDOWS=1

if [ $OSX ]
then
export CPUCOUNT=$(sysctl -n hw.ncpu)
elif [ $LINUX ]
then
export CPUCOUNT=$(nproc)
else
export CPUCOUNT="1"
fi

$UNCRUSTIFY -c .uncrustify.cfg --no-backup *.cpp *.h
18 changes: 9 additions & 9 deletions simplecpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,18 +761,18 @@ void simplecpp::TokenList::readfile(Stream &stream, const std::string &filename,
while (stream.good() && ch != '\n') {
currentToken += ch;
ch = stream.readChar();
if(ch == '\\') {
if (ch == '\\') {
TokenString tmp;
char tmp_ch = ch;
while((stream.good()) && (tmp_ch == '\\' || tmp_ch == ' ' || tmp_ch == '\t')) {
while ((stream.good()) && (tmp_ch == '\\' || tmp_ch == ' ' || tmp_ch == '\t')) {
tmp += tmp_ch;
tmp_ch = stream.readChar();
}
if(!stream.good()) {
if (!stream.good()) {
break;
}

if(tmp_ch != '\n') {
if (tmp_ch != '\n') {
currentToken += tmp;
} else {
const TokenString check_portability = currentToken + tmp;
Expand Down Expand Up @@ -1667,7 +1667,7 @@ namespace simplecpp {
}

invalidHashHash(const Location &loc, const std::string &macroName, const std::string &message)
: Error(loc, format(macroName, message)) { }
: Error(loc, format(macroName, message)) {}

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

std::map<std::string, std::list<Location> > maybeUsedMacros;
std::map<std::string, std::list<Location>> maybeUsedMacros;

for (const Token *rawtok = nullptr; rawtok || !includetokenstack.empty();) {
if (rawtok == nullptr) {
Expand Down Expand Up @@ -3751,11 +3751,11 @@ simplecpp::cstd_t simplecpp::getCStd(const std::string &std)
{
if (std == "c90" || std == "c89" || std == "iso9899:1990" || std == "iso9899:199409" || std == "gnu90" || std == "gnu89")
return C89;
if (std == "c99" || std == "c9x" || std == "iso9899:1999" || std == "iso9899:199x" || std == "gnu99"|| std == "gnu9x")
if (std == "c99" || std == "c9x" || std == "iso9899:1999" || std == "iso9899:199x" || std == "gnu99" || std == "gnu9x")
return C99;
if (std == "c11" || std == "c1x" || std == "iso9899:2011" || std == "gnu11" || std == "gnu1x")
return C11;
if (std == "c17" || std == "c18" || std == "iso9899:2017" || std == "iso9899:2018" || std == "gnu17"|| std == "gnu18")
if (std == "c17" || std == "c18" || std == "iso9899:2017" || std == "iso9899:2018" || std == "gnu17" || std == "gnu18")
return C17;
if (std == "c23" || std == "gnu23" || std == "c2x" || std == "gnu2x")
return C23;
Expand Down
9 changes: 4 additions & 5 deletions simplecpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ namespace simplecpp {
}

Token(const Token &tok) :
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) {
}
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) {}

void flags() {
name = (std::isalpha(static_cast<unsigned char>(string[0])) || string[0] == '_' || string[0] == '$')
Expand Down Expand Up @@ -325,9 +324,9 @@ namespace simplecpp {
struct SIMPLECPP_LIB MacroUsage {
explicit MacroUsage(const std::vector<std::string> &f, bool macroValueKnown_) : macroLocation(f), useLocation(f), macroValueKnown(macroValueKnown_) {}
std::string macroName;
Location macroLocation;
Location useLocation;
bool macroValueKnown;
Location macroLocation;
Location useLocation;
bool macroValueKnown;
};

/** Tracking #if/#elif expressions */
Expand Down
Loading
Loading