Skip to content

Commit

Permalink
Update reformatting settings, trace wrapping, and printf-format strin…
Browse files Browse the repository at this point in the history
…gs (#22)

* Add BEGIN_FUNC / CATCH / END_FUNC to macros

* Remove incorrect trailing '{'

* Update trace script to wrap H5TRACE macros at 110 characters and improve
comments for code that performs this operation.

* Clean up printf-formatting in H5public.h and correct some oversights in the code.

* Reformat with BEGIN_FUNC / END_FUNC handled correctly by clang-format

* Run clang-format on changes.

* Correct H5_SIZEOF_HSIZE_T/H5_SIZEOF_HSSIZE_T macros to match typedef.

* And make the undef value match also.

* Update comment

* Update clang-format actions to exclude generated files.

* Post-process generated H5LTparse.h file as well as H5LTparse.c file.

* Fix formatting

* Update version of github clang-format action
  • Loading branch information
qkoziol authored Oct 6, 2020
1 parent c0e087a commit 66bcfd9
Show file tree
Hide file tree
Showing 41 changed files with 14,438 additions and 14,558 deletions.
18 changes: 17 additions & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,27 @@ AlignConsecutiveMacros: true
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlwaysBreakAfterReturnType: AllDefinitions
# Can enable the following section when llvm 12.x is out
#AttributeMacros:
# - H5_ATTR_FORMAT
# - H5_ATTR_UNUSED
# - H5_ATTR_DEPRECATED_USED
# - H5_ATTR_NDEBUG_UNUSED
# - H5_ATTR_DEBUG_API_USED
# - H5_ATTR_PARALLEL_UNUSED
# - H5_ATTR_PARALLEL_USED
# - H5_ATTR_NORETURN
# - H5_ATTR_CONST
# - H5_ATTR_PURE
# - H5_ATTR_FALLTHROUGH
BraceWrapping:
AfterFunction: true
BeforeCatch: true
BeforeElse: true
BreakBeforeBraces: Stroustrup
BreakAfterJavaFieldAnnotations: true
BreakStringLiterals: true
ColumnLimit: 110
ColumnLimit: 110 # Update $max_trace_macro_line_len in bin/trace also
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 3
Expand All @@ -33,6 +46,8 @@ IncludeIsMainRegex: '(public)?$'
IndentCaseLabels: true
IndentGotoLabels: false
IndentWidth: 4
MacroBlockBegin: "^BEGIN_FUNC"
MacroBlockEnd: "^END_FUNC"
ObjCBlockIndentWidth: 4
ReflowComments: true
SortIncludes: false
Expand All @@ -58,5 +73,6 @@ StatementMacros:
- HMPI_GOTO_ERROR
- H5_GCC_DIAG_OFF
- H5_GCC_DIAG_ON
- CATCH
...

6 changes: 3 additions & 3 deletions .github/workflows/clang-format-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Run clang-format style check for C programs.
uses: DoozyX/clang-format-lint-action@v0.8
uses: DoozyX/clang-format-lint-action@v0.10
with:
source: '.'
extensions: 'c,h,cpp'
extensions: 'c,h,cpp,hpp'
clangFormatVersion: 10
style: file
exclude: './config ./hl/src/H5LTanalyze.c'
exclude: './config ./hl/src/H5LTanalyze.c ./hl/src/H5LTparse.c ./hl/src/H5LTparse.h ./src/H5Epubgen.h ./src/H5Einit.h ./src/H5Eterm.h ./src/H5Edefin.h ./src/H5version.h ./src/H5overflow.h'
24 changes: 22 additions & 2 deletions bin/format_source
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
#!/bin/bash
#
# Recursively format all C & C++ sources and header files, except those in the
# 'config' directory and generated files, such as H5LTanalyze.c, etc.
#
# Note that any files or directories that are excluded here should also be
# added to the 'exclude' list in .github/workflows/clang-format-check.yml
#
# (Remember to update both bin/format_source and bin/format_source_patch)

find . -type d \( -path ./config \) -prune \
-o -iname *.h -o -iname *.c -o -iname *.cpp -o -iname *.hpp \
-or \( \( \! \( \
-name H5LTanalyze.c \
-or -name H5LTparse.c \
-or -name H5LTparse.h \
-or -name H5Epubgen.h \
-or -name H5Einit.h \
-or -name H5Eterm.h \
-or -name H5Edefin.h \
-or -name H5version.h \
-or -name H5overflow.h \
\) \) \
-and \( -iname *.h -or -iname *.c -or -iname *.cpp -or -iname *.hpp \) \) \
| xargs clang-format -style=file -i -fallback-style=none

exit 0
exit 0
24 changes: 22 additions & 2 deletions bin/format_source_patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
#!/bin/bash
#
# Recursively format all C & C++ sources and header files, except those in the
# 'config' directory and generated files, such as H5LTanalyze.c, etc.
#
# Note that any files or directories that are excluded here should also be
# added to the 'exclude' list in .github/workflows/clang-format-check.yml
#
# (Remember to update both bin/format_source and bin/format_source_patch)

find . -type d \( -path ./config \) -prune \
-o -iname *.h -o -iname *.c -o -iname *.cpp -o -iname *.hpp \
-or \( \( \! \( \
-name H5LTanalyze.c \
-or -name H5LTparse.c \
-or -name H5LTparse.h \
-or -name H5Epubgen.h \
-or -name H5Einit.h \
-or -name H5Eterm.h \
-or -name H5Edefin.h \
-or -name H5version.h \
-or -name H5overflow.h \
\) \) \
-and \( -iname *.h -or -iname *.c -or -iname *.cpp -or -iname *.hpp \) \) \
| xargs clang-format -style=file -i -fallback-style=none

git diff > clang_format.patch
Expand All @@ -11,4 +31,4 @@ then
rm clang_format.patch
fi

exit 0
exit 0
7 changes: 5 additions & 2 deletions bin/genparser
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ if [ "$verbose" = true ] ; then
fi
${HDF5_FLEX} --nounistd -PH5LTyy -o ${path_to_hl_src}/H5LTanalyze.c ${path_to_hl_src}/H5LTanalyze.l

# fix H5LTparse.c to declare H5LTyyparse return type as an hid_t
# instead of int. Currently the generated function H5LTyyparse is
# fix H5LTparse.c and H5LTlparse.h to declare H5LTyyparse return type as an
# hid_t instead of int. Currently the generated function H5LTyyparse is
# generated with a return value of type int, which is a mapping to the
# flex yyparse function. The return value in the HL library should be
# an hid_t.
Expand All @@ -211,6 +211,9 @@ ${HDF5_FLEX} --nounistd -PH5LTyy -o ${path_to_hl_src}/H5LTanalyze.c ${path_to_hl
perl -0777 -pi -e 's/int yyparse/hid_t yyparse/igs' ${path_to_hl_src}/H5LTparse.c
perl -0777 -pi -e 's/int\nyyparse/hid_t\nyyparse/igs' ${path_to_hl_src}/H5LTparse.c
perl -0777 -pi -e 's/int H5LTyyparse/hid_t H5LTyyparse/igs' ${path_to_hl_src}/H5LTparse.c
perl -0777 -pi -e 's/int yyparse/hid_t yyparse/igs' ${path_to_hl_src}/H5LTparse.h
perl -0777 -pi -e 's/int\nyyparse/hid_t\nyyparse/igs' ${path_to_hl_src}/H5LTparse.h
perl -0777 -pi -e 's/int H5LTyyparse/hid_t H5LTyyparse/igs' ${path_to_hl_src}/H5LTparse.h

# Add code that disables warnings in the flex/bison-generated code.
#
Expand Down
38 changes: 31 additions & 7 deletions bin/trace
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ $Source = "";
"ssize_t" => "Zs",
);


##############################################################################
# Maximum length of H5TRACE macro line
# If the ColumnLimit in .clang-format is changed, this value will need to be updated
#
my $max_trace_macro_line_len = 110;


##############################################################################
# Print an error message.
#
Expand Down Expand Up @@ -287,7 +295,7 @@ sub rewrite_func ($$$$$) {

# Parse arguments
if ($args eq "void") {
$trace = "H5TRACE0(\"$rettype\",\"\");\n";
$trace = "H5TRACE0(\"$rettype\", \"\");\n";
} else {
# Split arguments. First convert `/*in,out*/' to get rid of the
# comma, then split the arguments on commas.
Expand Down Expand Up @@ -331,18 +339,34 @@ sub rewrite_func ($$$$$) {
}
}
}

# Compose the trace macro
$trace = "H5TRACE" . scalar(@arg_str) . "(\"$rettype\", \"";
$trace .= join("", @arg_str) . "\"";
my $len = 4 + length $trace;
my $len = 4 + length $trace; # Add 4, for indenting the line
for (@arg_name) {
if ($len + length >= 77) {
$trace .= ",\n $_";
$len = 13 + length;
# Wrap lines that will be longer than the limit, after ');' is added
if ($len + length >= ($max_trace_macro_line_len - 2)) {
# Wrap line, with indention
$trace .= ",\n ";
$len = 13; # Set to 13, for indention

# Indent an extra space to account for extra digit in 'H5TRACE' macro
if (scalar(@arg_str) >= 10) {
$trace .= " ";
$len++;
}
} else {
$trace .= ", $_";
$len += 1 + length;
$trace .= ", ";
$len += 2; # Add 2, for ', '
}

# Append argument
$trace .= "$_";
$len += length; # Add length of appended argument name
}

# Append final ');' for macro
$trace .= ");\n";
}
goto error if grep {/!/} @arg_str;
Expand Down
Loading

0 comments on commit 66bcfd9

Please sign in to comment.