Skip to content

Commit 2b730f8

Browse files
jeremyltjedbrown
andauthored
Switch to clang-format (#1051)
* style - switch to clang-format * ci - use newer libxsmm * action - update format action * format - consistent use of {} for multi-line if/for * make - remove stray newline * make - simpler 'make format' target * ci - use newer libxsmm * doc - minor release note claification * minor - minor fix * minor - minor fix * minor - minor fix * minor - minor fix * make format * format - less aggressive alignment rules * tidy - check for argument name mismatches * fix newline * format - mirror Ratel update to .clang-format * fix merge error * fix merge conflict * fix merge error * drop style in .phony list * Update .clang-format Co-authored-by: Jed Brown <[email protected]> * apply updated format Co-authored-by: Jed Brown <[email protected]>
1 parent 6929379 commit 2b730f8

File tree

534 files changed

+43734
-53472
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

534 files changed

+43734
-53472
lines changed

.astylerc

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

.clang-format

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
BasedOnStyle: "Google"
2+
3+
AlignAfterOpenBracket: Align
4+
AlignArrayOfStructures: Left
5+
AlignConsecutiveAssignments: Consecutive
6+
AlignConsecutiveDeclarations: Consecutive
7+
AlignEscapedNewlines: true
8+
AlignOperands: Align
9+
AlignTrailingComments: true
10+
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
11+
ColumnLimit: 150
12+
CommentPragmas: 'TESTARGS'
13+
TabWidth: 4
14+
UseTab: Never

.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Checks: "clang-diagnostic-*,clang-analyzer-*,readability-inconsistent-declaration-parameter-name"
2+
HeaderFilterRegex: .*

.github/workflows/c-fortran-test-style.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ jobs:
1515
steps:
1616
- name: Environment setup
1717
uses: actions/checkout@v3
18-
- name: Install astyle
19-
run: sudo apt-get install astyle
18+
- name: Install clang-format
19+
run: sudo apt install clang-format-14
2020
- name: C style
2121
env:
2222
CC: ${{ matrix.compiler }}
2323
FC: gfortran-11
2424
run: |
2525
make info
26-
make style-c -j2 && git diff --exit-code
26+
make format-c -j2 && git diff --exit-code

.github/workflows/python-test-with-style.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ jobs:
4141
CC: ${{ matrix.compiler }}
4242
FC: gfortran-11
4343
run: |
44-
make style-py && git diff --exit-code
44+
make format-py && git diff --exit-code

Makefile

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ install : $(libceed) $(OBJDIR)/ceed.pc
676676
$(INSTALL_DATA) $(wildcard include/ceed/jit-source/hip/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/hip/"
677677
$(INSTALL_DATA) $(wildcard include/ceed/jit-source/gallery/*.h) "$(DESTDIR)$(includedir)/ceed/jit-source/gallery/"
678678

679-
.PHONY : all cln clean doxygen doc lib install par print test tst prove prv prove-all junit examples style style-c style-py tidy iwyu info info-backends info-backends-all
679+
.PHONY : all cln clean doxygen doc format lib install par print test tst prove prv prove-all junit examples tidy iwyu info info-backends info-backends-all
680680

681681
cln clean :
682682
$(RM) -r $(OBJDIR) $(LIBDIR) dist *egg* .pytest_cache *cffi*
@@ -687,6 +687,7 @@ cln clean :
687687
distclean : clean
688688
$(RM) -r doc/html doc/sphinx/build $(CONFIG)
689689

690+
# Documentation
690691
DOXYGEN ?= doxygen
691692
doxygen :
692693
$(DOXYGEN) -q Doxyfile
@@ -696,19 +697,24 @@ doc-html doc-latexpdf doc-epub doc-livehtml : doc-% : doxygen
696697

697698
doc : doc-html
698699

699-
style-c :
700-
@astyle --options=.astylerc \
701-
$(filter-out include/ceedf.h $(wildcard tests/t*-f.h), \
702-
$(wildcard include/*.h interface/*.[ch] tests/*.[ch] backends/*/*.[ch] \
703-
examples/*/*/*.[ch] examples/*/*.[ch] examples/*/*.[ch]pp gallery/*/*.[ch]))
700+
# Style/Format
701+
CLANG_FORMAT ?= clang-format
702+
703+
FORMAT_OPTS += -style=file -i
704+
705+
format.ch := $(filter-out include/ceedf.h $(wildcard tests/t*-f.h), $(shell git ls-files *.[ch]pp *.[ch]))
706+
707+
format-c :
708+
$(CLANG_FORMAT) $(FORMAT_OPTS) $(format.ch)
704709

705710
AUTOPEP8 = autopep8
706-
style-py : AUTOPEP8_ARGS = --in-place --aggressive
707-
style-py :
711+
format-py : AUTOPEP8_ARGS = --in-place --aggressive
712+
format-py :
708713
@$(AUTOPEP8) $(AUTOPEP8_ARGS) $(wildcard *.py python**/*.py python/tests/*.py examples**/*.py doc/sphinx/source**/*.py benchmarks/*.py)
709714

710-
style : style-c style-py
715+
format : format-c format-py
711716

717+
# Tidy
712718
CLANG_TIDY ?= clang-tidy
713719

714720
%.c.tidy : %.c
@@ -717,16 +723,17 @@ CLANG_TIDY ?= clang-tidy
717723
%.cpp.tidy : %.cpp
718724
$(CLANG_TIDY) $(TIDY_OPTS) $^ -- $(CPPFLAGS) --std=c++11 -I$(CUDA_DIR)/include -I$(OCCA_DIR)/include -I$(HIP_DIR)/include
719725

720-
tidy_c : $(libceed.c:%=%.tidy)
721-
tidy_cpp : $(libceed.cpp:%=%.tidy)
726+
tidy-c : $(libceed.c:%=%.tidy)
727+
tidy-cpp : $(libceed.cpp:%=%.tidy)
722728

723-
tidy : tidy_c tidy_cpp
729+
tidy : tidy-c tidy-cpp
724730

725731
ifneq ($(wildcard ../iwyu/*),)
726732
IWYU_DIR ?= ../iwyu
727733
IWYU_CC ?= $(IWYU_DIR)/build/bin/include-what-you-use
728734
endif
729735

736+
# IWYU
730737
iwyu : CC=$(IWYU_CC)
731738
iwyu : lib
732739

backends/avx/ceed-avx-blocked.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,34 @@
55
//
66
// This file is part of CEED: http://github.com/ceed
77

8-
#include <ceed/ceed.h>
98
#include <ceed/backend.h>
9+
#include <ceed/ceed.h>
1010
#include <stdbool.h>
1111
#include <string.h>
12+
1213
#include "ceed-avx.h"
1314

1415
//------------------------------------------------------------------------------
1516
// Backend Init
1617
//------------------------------------------------------------------------------
1718
static int CeedInit_Avx(const char *resource, Ceed ceed) {
18-
int ierr;
19-
if (strcmp(resource, "/cpu/self") && strcmp(resource, "/cpu/self/avx") &&
20-
strcmp(resource, "/cpu/self/avx/blocked"))
19+
if (strcmp(resource, "/cpu/self") && strcmp(resource, "/cpu/self/avx") && strcmp(resource, "/cpu/self/avx/blocked")) {
2120
// LCOV_EXCL_START
22-
return CeedError(ceed, CEED_ERROR_BACKEND,
23-
"AVX backend cannot use resource: %s", resource);
24-
// LCOV_EXCL_STOP
25-
ierr = CeedSetDeterministic(ceed, true); CeedChkBackend(ierr);
21+
return CeedError(ceed, CEED_ERROR_BACKEND, "AVX backend cannot use resource: %s", resource);
22+
// LCOV_EXCL_STOP
23+
}
24+
CeedCallBackend(CeedSetDeterministic(ceed, true));
2625

2726
// Create reference CEED that implementation will be dispatched
2827
// through unless overridden
2928
Ceed ceed_ref;
30-
CeedInit("/cpu/self/opt/blocked", &ceed_ref);
31-
ierr = CeedSetDelegate(ceed, ceed_ref); CeedChkBackend(ierr);
29+
CeedCallBackend(CeedInit("/cpu/self/opt/blocked", &ceed_ref));
30+
CeedCallBackend(CeedSetDelegate(ceed, ceed_ref));
3231

3332
if (CEED_SCALAR_TYPE == CEED_SCALAR_FP64) {
34-
ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate",
35-
CeedTensorContractCreate_f64_Avx);
36-
CeedChkBackend(ierr);
33+
CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f64_Avx));
3734
} else {
38-
ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate",
39-
CeedTensorContractCreate_f32_Avx);
40-
CeedChkBackend(ierr);
35+
CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f32_Avx));
4136
}
4237

4338
return CEED_ERROR_SUCCESS;
@@ -46,7 +41,5 @@ static int CeedInit_Avx(const char *resource, Ceed ceed) {
4641
//------------------------------------------------------------------------------
4742
// Backend Register
4843
//------------------------------------------------------------------------------
49-
CEED_INTERN int CeedRegister_Avx_Blocked(void) {
50-
return CeedRegister("/cpu/self/avx/blocked", CeedInit_Avx, 30);
51-
}
44+
CEED_INTERN int CeedRegister_Avx_Blocked(void) { return CeedRegister("/cpu/self/avx/blocked", CeedInit_Avx, 30); }
5245
//------------------------------------------------------------------------------

backends/avx/ceed-avx-serial.c

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,34 @@
55
//
66
// This file is part of CEED: http://github.com/ceed
77

8-
#include <ceed/ceed.h>
98
#include <ceed/backend.h>
9+
#include <ceed/ceed.h>
1010
#include <stdbool.h>
1111
#include <string.h>
12+
1213
#include "ceed-avx.h"
1314

1415
//------------------------------------------------------------------------------
1516
// Backend Init
1617
//------------------------------------------------------------------------------
1718
static int CeedInit_Avx(const char *resource, Ceed ceed) {
18-
int ierr;
19-
if (strcmp(resource, "/cpu/self")
20-
&& strcmp(resource, "/cpu/self/avx/serial"))
19+
if (strcmp(resource, "/cpu/self") && strcmp(resource, "/cpu/self/avx/serial")) {
2120
// LCOV_EXCL_START
22-
return CeedError(ceed, CEED_ERROR_BACKEND,
23-
"AVX backend cannot use resource: %s", resource);
24-
// LCOV_EXCL_STOP
25-
ierr = CeedSetDeterministic(ceed, true); CeedChkBackend(ierr);
21+
return CeedError(ceed, CEED_ERROR_BACKEND, "AVX backend cannot use resource: %s", resource);
22+
// LCOV_EXCL_STOP
23+
}
24+
CeedCallBackend(CeedSetDeterministic(ceed, true));
2625

2726
// Create reference CEED that implementation will be dispatched
2827
// through unless overridden
2928
Ceed ceed_ref;
30-
CeedInit("/cpu/self/opt/serial", &ceed_ref);
31-
ierr = CeedSetDelegate(ceed, ceed_ref); CeedChkBackend(ierr);
29+
CeedCallBackend(CeedInit("/cpu/self/opt/serial", &ceed_ref));
30+
CeedCallBackend(CeedSetDelegate(ceed, ceed_ref));
3231

3332
if (CEED_SCALAR_TYPE == CEED_SCALAR_FP64) {
34-
ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate",
35-
CeedTensorContractCreate_f64_Avx);
36-
CeedChkBackend(ierr);
33+
CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f64_Avx));
3734
} else {
38-
ierr = CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate",
39-
CeedTensorContractCreate_f32_Avx);
40-
CeedChkBackend(ierr);
35+
CeedCallBackend(CeedSetBackendFunction(ceed, "Ceed", ceed, "TensorContractCreate", CeedTensorContractCreate_f32_Avx));
4136
}
4237

4338
return CEED_ERROR_SUCCESS;
@@ -46,7 +41,5 @@ static int CeedInit_Avx(const char *resource, Ceed ceed) {
4641
//------------------------------------------------------------------------------
4742
// Backend Register
4843
//------------------------------------------------------------------------------
49-
CEED_INTERN int CeedRegister_Avx_Serial(void) {
50-
return CeedRegister("/cpu/self/avx/serial", CeedInit_Avx, 35);
51-
}
44+
CEED_INTERN int CeedRegister_Avx_Serial(void) { return CeedRegister("/cpu/self/avx/serial", CeedInit_Avx, 35); }
5245
//------------------------------------------------------------------------------

0 commit comments

Comments
 (0)