Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add clang-formating for c sources and headers. #790

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#

---
BasedOnStyle: Microsoft
Language: Cpp

AlignAfterOpenBracket: Align
AlignOperands: Align
AlwaysBreakAfterReturnType: TopLevel
BraceWrapping:
AfterCaseLabel: true
BreakBeforeBinaryOperators: true
ColumnLimit: 80
IndentCaseBlocks: true
IndentCaseLabels: true
IndentWidth: 2
PointerAlignment: Right
13 changes: 13 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,19 @@ function(check_script_style script_full_path)
endif()
endfunction()

#------------------------------------------------------------
# Setup clang-format if present for testing/linting c sources
#------------------------------------------------------------
find_program(CLANGFORMAT_EXE clang-format
DOC "Path to clang-format executable for linting c sources/headers"
)
if (CAF_RUN_DEVELOPER_TESTS OR $ENV{OPENCOARRAYS_DEVELOPER})
if(NOT CLANGFORMAT_EXE)
message( AUTHOR_WARNING "OpenCoarrays developers should install clang-format to test/lint all C sources and headers.
See https://releases.llvm.org/download.html for info on obtaining clang-format as part of clang.")
endif()
endif()

#------------------------------------------------------------------------------
# Add custom properties on targets for controling number of images during tests
#------------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions developer-scripts/git-hooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ for f in $(git diff-index --name-status --cached $against | grep -v ^D | cut -c3
status=1
fi
fi
if [[ "$f" =~ ([.](h|c))$ ]] ; then
if ! clang-format --dry-run --Werror "$f" >&/dev/null; then
echo "Format violation of file: $f"
echo "Use clang-format to fix it."
echo ""
status=1
fi
fi
done

# If there are whitespace errors, print the offending file names and fail.
Expand Down
120 changes: 73 additions & 47 deletions src/application-binary-interface/libcaf-gfortran-descriptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,18 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
/* GNU Fortran's array descriptor. Keep in sync with libgfortran.h. */

enum
{ BT_UNKNOWN = 0, BT_INTEGER, BT_LOGICAL, BT_REAL, BT_COMPLEX,
BT_DERIVED, BT_CHARACTER, BT_CLASS, BT_PROCEDURE, BT_HOLLERITH, BT_VOID,
{
BT_UNKNOWN = 0,
BT_INTEGER,
BT_LOGICAL,
BT_REAL,
BT_COMPLEX,
BT_DERIVED,
BT_CHARACTER,
BT_CLASS,
BT_PROCEDURE,
BT_HOLLERITH,
BT_VOID,
BT_ASSUMED
};

Expand All @@ -43,22 +53,21 @@ typedef struct descriptor_dimension
ptrdiff_t _stride;
ptrdiff_t lower_bound;
ptrdiff_t _ubound;
}
descriptor_dimension;
} descriptor_dimension;

#ifdef GCC_GE_8
typedef struct dtype_type
{
size_t elem_len;
int version;
signed char rank;
signed char type;
signed short attribute;
}
dtype_type;
typedef struct dtype_type
{
size_t elem_len;
int version;
signed char rank;
signed char type;
signed short attribute;
} dtype_type;
#endif

typedef struct gfc_descriptor_t {
typedef struct gfc_descriptor_t
{
void *base_addr;
size_t offset;
#ifdef GCC_GE_8
Expand All @@ -81,8 +90,10 @@ typedef struct gfc_descriptor_t {
#define GFC_DESCRIPTOR_RANK(desc) (desc)->dtype.rank
#define GFC_DESCRIPTOR_TYPE(desc) (desc)->dtype.type
#define GFC_DESCRIPTOR_SIZE(desc) (desc)->dtype.elem_len
#define GFC_DTYPE_TYPE_SIZE(desc) (( ((desc)->dtype.type << GFC_DTYPE_TYPE_SHIFT) \
| ((desc)->dtype.elem_len << GFC_DTYPE_SIZE_SHIFT) ) & GFC_DTYPE_TYPE_SIZE_MASK)
#define GFC_DTYPE_TYPE_SIZE(desc) \
((((desc)->dtype.type << GFC_DTYPE_TYPE_SHIFT) \
| ((desc)->dtype.elem_len << GFC_DTYPE_SIZE_SHIFT)) \
& GFC_DTYPE_TYPE_SIZE_MASK)

#else

Expand All @@ -93,87 +104,102 @@ typedef struct gfc_descriptor_t {
#define GFC_DTYPE_SIZE_SHIFT 6

#define GFC_DESCRIPTOR_RANK(desc) ((desc)->dtype & GFC_DTYPE_RANK_MASK)
#define GFC_DESCRIPTOR_TYPE(desc) (((desc)->dtype & GFC_DTYPE_TYPE_MASK) \
>> GFC_DTYPE_TYPE_SHIFT)
#define GFC_DESCRIPTOR_TYPE(desc) \
(((desc)->dtype & GFC_DTYPE_TYPE_MASK) >> GFC_DTYPE_TYPE_SHIFT)
#define GFC_DESCRIPTOR_SIZE(desc) ((desc)->dtype >> GFC_DTYPE_SIZE_SHIFT)
#define GFC_DTYPE_TYPE_SIZE(desc) ((desc)->dtype & GFC_DTYPE_TYPE_SIZE_MASK)

#endif

#define GFC_DTYPE_SIZE_MASK \
( ~((ptrdiff_t)(1 << GFC_DTYPE_SIZE_SHIFT) - 1)) // least significant bits to 0
#define GFC_DTYPE_SIZE_MASK \
(~((ptrdiff_t)(1 << GFC_DTYPE_SIZE_SHIFT) - 1)) // least significant bits to 0
#define GFC_DTYPE_TYPE_SIZE_MASK (GFC_DTYPE_SIZE_MASK | GFC_DTYPE_TYPE_MASK)

#define GFC_DTYPE_INTEGER_1 ((BT_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
#define GFC_DTYPE_INTEGER_1 \
((BT_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(int8_t) << GFC_DTYPE_SIZE_SHIFT))
#define GFC_DTYPE_INTEGER_2 ((BT_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
#define GFC_DTYPE_INTEGER_2 \
((BT_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(int16_t) << GFC_DTYPE_SIZE_SHIFT))
#define GFC_DTYPE_INTEGER_4 ((BT_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
#define GFC_DTYPE_INTEGER_4 \
((BT_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(int32_t) << GFC_DTYPE_SIZE_SHIFT))
#define GFC_DTYPE_INTEGER_8 ((BT_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
#define GFC_DTYPE_INTEGER_8 \
((BT_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(int64_t) << GFC_DTYPE_SIZE_SHIFT))
#if HAVE_INT128_T
#define GFC_DTYPE_INTEGER_16 ((BT_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
#define GFC_DTYPE_INTEGER_16 \
((BT_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(__int128_t) << GFC_DTYPE_SIZE_SHIFT))
#endif

#define GFC_DTYPE_LOGICAL_4 ((BT_LOGICAL << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(int) << GFC_DTYPE_SIZE_SHIFT))
#define GFC_DTYPE_LOGICAL_4 \
((BT_LOGICAL << GFC_DTYPE_TYPE_SHIFT) | (sizeof(int) << GFC_DTYPE_SIZE_SHIFT))

#if 0
#define GFC_DTYPE_LOGICAL_1 ((BT_LOGICAL << GFC_DTYPE_TYPE_SHIFT) \
#define GFC_DTYPE_LOGICAL_1 \
((BT_LOGICAL << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(GFC_LOGICAL_1) << GFC_DTYPE_SIZE_SHIFT))
#define GFC_DTYPE_LOGICAL_2 ((BT_LOGICAL << GFC_DTYPE_TYPE_SHIFT) \
#define GFC_DTYPE_LOGICAL_2 \
((BT_LOGICAL << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(GFC_LOGICAL_2) << GFC_DTYPE_SIZE_SHIFT))
#define GFC_DTYPE_LOGICAL_8 ((BT_LOGICAL << GFC_DTYPE_TYPE_SHIFT) \
#define GFC_DTYPE_LOGICAL_8 \
((BT_LOGICAL << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(double) << GFC_DTYPE_SIZE_SHIFT))
#define GFC_DTYPE_LOGICAL_16 ((BT_LOGICAL << GFC_DTYPE_TYPE_SHIFT)\
#define GFC_DTYPE_LOGICAL_16 \
((BT_LOGICAL << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(GFC_LOGICAL_16) << GFC_DTYPE_SIZE_SHIFT))
#endif

#define GFC_DTYPE_REAL_4 ((BT_REAL << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(float) << GFC_DTYPE_SIZE_SHIFT))
#define GFC_DTYPE_REAL_8 ((BT_REAL << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(double) << GFC_DTYPE_SIZE_SHIFT))
#define GFC_DTYPE_REAL_4 \
((BT_REAL << GFC_DTYPE_TYPE_SHIFT) | (sizeof(float) << GFC_DTYPE_SIZE_SHIFT))
#define GFC_DTYPE_REAL_8 \
((BT_REAL << GFC_DTYPE_TYPE_SHIFT) | (sizeof(double) << GFC_DTYPE_SIZE_SHIFT))
#if 0
#ifdef HAVE_GFC_REAL_10
#define GFC_DTYPE_REAL_10 ((BT_REAL << GFC_DTYPE_TYPE_SHIFT) \
#define GFC_DTYPE_REAL_10 \
((BT_REAL << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(GFC_REAL_10) << GFC_DTYPE_SIZE_SHIFT))
#endif
#ifdef HAVE_GFC_REAL_16
#define GFC_DTYPE_REAL_16 ((BT_REAL << GFC_DTYPE_TYPE_SHIFT) \
#define GFC_DTYPE_REAL_16 \
((BT_REAL << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(GFC_REAL_16) << GFC_DTYPE_SIZE_SHIFT))
#endif
#endif

#define GFC_DTYPE_COMPLEX_4 ((BT_COMPLEX << GFC_DTYPE_TYPE_SHIFT) \
#define GFC_DTYPE_COMPLEX_4 \
((BT_COMPLEX << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(_Complex float) << GFC_DTYPE_SIZE_SHIFT))
#define GFC_DTYPE_COMPLEX_8 ((BT_COMPLEX << GFC_DTYPE_TYPE_SHIFT) \
#define GFC_DTYPE_COMPLEX_8 \
((BT_COMPLEX << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(_Complex double) << GFC_DTYPE_SIZE_SHIFT))
#if 0
#ifdef HAVE_GFC_COMPLEX_10
#define GFC_DTYPE_COMPLEX_10 ((BT_COMPLEX << GFC_DTYPE_TYPE_SHIFT) \
#define GFC_DTYPE_COMPLEX_10 \
((BT_COMPLEX << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(GFC_COMPLEX_10) << GFC_DTYPE_SIZE_SHIFT))
#endif
#ifdef HAVE_GFC_COMPLEX_16
#define GFC_DTYPE_COMPLEX_16 ((BT_COMPLEX << GFC_DTYPE_TYPE_SHIFT) \
#define GFC_DTYPE_COMPLEX_16 \
((BT_COMPLEX << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(GFC_COMPLEX_16) << GFC_DTYPE_SIZE_SHIFT))
#endif
#endif

/* FIXME: Hardwiring these values to what the mpi_caf.c macro GFC_DTYPE_TYPE_SIZE(desc)
receives in the dtype component its gf_descriptor_t argument for character(kind=c_char)
and logical(kind=c_bool) data:
/* FIXME: Hardwiring these values to what the mpi_caf.c macro
GFC_DTYPE_TYPE_SIZE(desc) receives in the dtype component its gf_descriptor_t
argument for character(kind=c_char) and logical(kind=c_bool) data:
*/

#ifdef GCC_GE_8

#define GFC_DTYPE_CHARACTER ((BT_CHARACTER << GFC_DTYPE_TYPE_SHIFT) \
#define GFC_DTYPE_CHARACTER \
((BT_CHARACTER << GFC_DTYPE_TYPE_SHIFT) \
| (sizeof(char) << GFC_DTYPE_SIZE_SHIFT))

#else
#define GFC_DTYPE_CHARACTER 48
#endif


#endif /* LIBCAF_GFORTRAN_DESCRIPTOR_H. */
#endif /* LIBCAF_GFORTRAN_DESCRIPTOR_H. */
Loading
Loading