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

Clang-Format 14 #1321

Merged
merged 4 commits into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone &
unzip \
vbindiff \
vim \
clang-tidy-11 \
clang-format-11 \
clang-tidy-14 \
clang-format-14 \
libpng-dev && \
apt clean && \
rm -rf /var/lib/apt/lists/*
Expand Down
4 changes: 2 additions & 2 deletions docs/BUILDING_MACOS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ For macOS, use Homebrew to install the following dependencies:
* python3
* libpng
* bash
* clang-format 11
* clang-format-14

You can install them with the following commands:

```bash
brew update
brew install coreutils make python3 libpng bash clang-format@11
brew install coreutils make python3 libpng bash clang-format@14
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just noticed a problem, the homebrew page for clang-format 14 doesn't seem to exist
https://formulae.brew.sh/formula/clang-format@14

As a reference this is version 11: https://formulae.brew.sh/formula/clang-format@11

```

(The repository expects Homebrew-installed programs to be either linked correctly in `$PATH` etc. or in their default locations.)
Expand Down
10 changes: 5 additions & 5 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,26 +198,26 @@ Fixes line endings in the repo to Linux style (LF), which is required for the bu

### `format.py`

Formats all C files in the repo using `clang-format-11`, `clang-tidy`, and `clang-apply-replacements` (when multiprocessing). This will touch all files in the repo, so the next `make` will take longer.
Formats all C files in the repo using `clang-format-14`, `clang-tidy`, and `clang-apply-replacements` (when multiprocessing). This will touch all files in the repo, so the next `make` will take longer.

You can specify how many threads you would like this to run with by adding the `-jN` flag. Where N is the number of threads. By default this will run using 1 thread (i.e. `-j1`).

`clang-11` is available in many native package managers, but if not try:
`clang-14` is available in many native package managers, but if not try:

Linux:
Download llvm's setup script, run it, than install normally
```bash
wget https://apt.llvm.org/llvm.sh
chmod +x llvm.sh
sudo ./llvm.sh 11
sudo ./llvm.sh 14
rm llvm.sh
sudo apt install clang-format-11 clang-tidy-11 clang-apply-replacements-11
sudo apt install clang-format-14 clang-tidy-14 clang-apply-replacements-14
```

Mac:
Install with brew, than create symlinks for `clang-tidy` and `clang-apply-replacements` to use properly
```bash
brew install llvm clang-format-11
brew install llvm clang-format-14
ln -s "$(brew --prefix llvm)/bin/clang-tidy" "/usr/local/bin/clang-tidy"
ln -s "$(brew --prefix llvm)/bin/clang-apply-replacements" "/usr/local/bin/clang-apply-replacements"
```
Expand Down
17 changes: 15 additions & 2 deletions format.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@


# clang-format, clang-tidy and clang-apply-replacements default version
# Version 11 is used when available for more consistency between contributors
CLANG_VER = 11
# This specific version is used when available, for more consistency between contributors
CLANG_VER = 14

# Clang-Format options (see .clang-format for rules applied)
FORMAT_OPTS = "-i -style=file"
Expand Down Expand Up @@ -145,6 +145,12 @@ def format_files(src_files: List[str], extra_files: List[str], nb_jobs: int):
def main():
parser = argparse.ArgumentParser(description="Format files in the codebase to enforce most style rules")
parser.add_argument("files", metavar="file", nargs="*")
parser.add_argument(
"--show-paths",
dest="show_paths",
action="store_true",
help="Print the paths to the clang-* binaries used",
)
parser.add_argument(
"-j",
dest="jobs",
Expand All @@ -155,6 +161,13 @@ def main():
)
args = parser.parse_args()

if args.show_paths:
import shutil

print("CLANG_FORMAT ->", shutil.which(CLANG_FORMAT))
print("CLANG_TIDY ->", shutil.which(CLANG_TIDY))
print("CLANG_APPLY_REPLACEMENTS ->", shutil.which(CLANG_APPLY_REPLACEMENTS))

nb_jobs = args.jobs or multiprocessing.cpu_count()
if nb_jobs > 1:
if CLANG_APPLY_REPLACEMENTS is None:
Expand Down
100 changes: 50 additions & 50 deletions src/code/z_DLF.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,35 @@ void Overlay_LoadGameState(GameStateOverlay* overlayEntry) {
(uintptr_t)vramStart, (uintptr_t)overlayEntry->vramEnd);
if (overlayEntry->loadedRamAddr != NULL) {

overlayEntry->unk_14 = (uintptr_t)(
(overlayEntry->unk_14 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_14 -
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->unk_14 = (void*)(uintptr_t)((overlayEntry->unk_14 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_14 -
(intptr_t)((uintptr_t)overlayEntry->vramStart -
(uintptr_t)overlayEntry->loadedRamAddr))
: NULL);

overlayEntry->init = (uintptr_t)(
(overlayEntry->init != NULL)
? (void*)((uintptr_t)overlayEntry->init -
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->init = (void*)(uintptr_t)((overlayEntry->init != NULL)
? (void*)((uintptr_t)overlayEntry->init -
(intptr_t)((uintptr_t)overlayEntry->vramStart -
(uintptr_t)overlayEntry->loadedRamAddr))
: NULL);

overlayEntry->destroy = (uintptr_t)(
(overlayEntry->destroy != NULL)
? (void*)((uintptr_t)overlayEntry->destroy -
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->destroy = (void*)(uintptr_t)((overlayEntry->destroy != NULL)
? (void*)((uintptr_t)overlayEntry->destroy -
(intptr_t)((uintptr_t)overlayEntry->vramStart -
(uintptr_t)overlayEntry->loadedRamAddr))
: NULL);

overlayEntry->unk_20 = (uintptr_t)(
(overlayEntry->unk_20 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_20 -
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->unk_20 = (void*)(uintptr_t)((overlayEntry->unk_20 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_20 -
(intptr_t)((uintptr_t)overlayEntry->vramStart -
(uintptr_t)overlayEntry->loadedRamAddr))
: NULL);

overlayEntry->unk_24 = (uintptr_t)(
(overlayEntry->unk_24 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_24 -
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->unk_24 = (void*)(uintptr_t)((overlayEntry->unk_24 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_24 -
(intptr_t)((uintptr_t)overlayEntry->vramStart -
(uintptr_t)overlayEntry->loadedRamAddr))
: NULL);

overlayEntry->unk_28 = 0;
}
Expand All @@ -57,35 +57,35 @@ void Overlay_FreeGameState(GameStateOverlay* overlayEntry) {
if (overlayEntry->loadedRamAddr != NULL) {
var_v0 = (overlayEntry->unk_28 != 0) ? -1 : 0;
if (var_v0 == 0) {
overlayEntry->unk_14 = (uintptr_t)(
(overlayEntry->unk_14 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_14 +
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->unk_14 = (void*)(uintptr_t)((overlayEntry->unk_14 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_14 +
(intptr_t)((uintptr_t)overlayEntry->vramStart -
(uintptr_t)overlayEntry->loadedRamAddr))
: NULL);

overlayEntry->init = (uintptr_t)(
(overlayEntry->init != NULL)
? (void*)((uintptr_t)overlayEntry->init +
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->init = (void*)(uintptr_t)((overlayEntry->init != NULL)
? (void*)((uintptr_t)overlayEntry->init +
(intptr_t)((uintptr_t)overlayEntry->vramStart -
(uintptr_t)overlayEntry->loadedRamAddr))
: NULL);

overlayEntry->destroy = (uintptr_t)(
(overlayEntry->destroy != NULL)
? (void*)((uintptr_t)overlayEntry->destroy +
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->destroy = (uintptr_t)((overlayEntry->destroy != NULL)
? (void*)((uintptr_t)overlayEntry->destroy +
(intptr_t)((uintptr_t)overlayEntry->vramStart -
(uintptr_t)overlayEntry->loadedRamAddr))
: NULL);

overlayEntry->unk_20 = (uintptr_t)(
(overlayEntry->unk_20 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_20 +
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->unk_20 = (void*)(uintptr_t)((overlayEntry->unk_20 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_20 +
(intptr_t)((uintptr_t)overlayEntry->vramStart -
(uintptr_t)overlayEntry->loadedRamAddr))
: NULL);

overlayEntry->unk_24 = (uintptr_t)(
(overlayEntry->unk_24 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_24 +
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
overlayEntry->unk_24 = (void*)(uintptr_t)((overlayEntry->unk_24 != NULL)
? (void*)((uintptr_t)overlayEntry->unk_24 +
(intptr_t)((uintptr_t)overlayEntry->vramStart -
(uintptr_t)overlayEntry->loadedRamAddr))
: NULL);

SystemArena_Free(overlayEntry->loadedRamAddr);
overlayEntry->loadedRamAddr = NULL;
Expand Down
10 changes: 5 additions & 5 deletions src/code/z_actor.c
Original file line number Diff line number Diff line change
Expand Up @@ -3185,11 +3185,11 @@ ActorInit* Actor_LoadOverlay(ActorContext* actorCtx, s16 index) {
overlayEntry->numLoaded = 0;
}

actorInit = (uintptr_t)(
(overlayEntry->initInfo != NULL)
? (void*)((uintptr_t)overlayEntry->initInfo -
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
actorInit = (void*)(uintptr_t)((overlayEntry->initInfo != NULL)
? (void*)((uintptr_t)overlayEntry->initInfo -
(intptr_t)((uintptr_t)overlayEntry->vramStart -
(uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
}

return actorInit;
Expand Down
10 changes: 5 additions & 5 deletions src/code/z_effect_soft_sprite.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,11 @@ void EffectSs_Spawn(PlayState* play, s32 type, s32 priority, void* initData) {
overlayEntry->loadedRamAddr);
}

initInfo = (uintptr_t)(
(overlayEntry->initInfo != NULL)
? (void*)((uintptr_t)overlayEntry->initInfo -
(intptr_t)((uintptr_t)overlayEntry->vramStart - (uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
initInfo = (void*)(uintptr_t)((overlayEntry->initInfo != NULL)
? (void*)((uintptr_t)overlayEntry->initInfo -
(intptr_t)((uintptr_t)overlayEntry->vramStart -
(uintptr_t)overlayEntry->loadedRamAddr))
: NULL);
}

if (initInfo->init != NULL) {
Expand Down
8 changes: 4 additions & 4 deletions src/overlays/actors/ovl_En_Bigslime/z_en_bigslime.c
Original file line number Diff line number Diff line change
Expand Up @@ -1740,10 +1740,10 @@ void EnBigslime_WindupThrowPlayer(EnBigslime* this, PlayState* play) {
// loop over x, y, z
for (j = 0; j < 3; j++) {
// Linearly interpolate dynamicVtx --> staticVtx * (1 - scale * vtxSurfacePerturbation)
dynamicVtx->n.ob[j] += (s16)(
((staticVtx->n.ob[j] - (s32)(scale * staticVtx->n.ob[j] * this->vtxSurfacePerturbation[i])) -
dynamicVtx->n.ob[j]) *
invWindupPunchTimer);
dynamicVtx->n.ob[j] += (s16)(((staticVtx->n.ob[j] - (s32)(scale * staticVtx->n.ob[j] *
this->vtxSurfacePerturbation[i])) -
dynamicVtx->n.ob[j]) *
invWindupPunchTimer);
}
} else {
// loop over x, y, z
Expand Down