with some modifications, notably the absence of a space before the parenthesis
for a function call or declaration.
*One exception is made to the GNU coding style:* in a function call or declaration, it is not necessary to insert a space between a function name and the parenthesis preceding the arguments. In GNU coding style, one should normally write `printf ("string")`, but in Dynare one should stick to `printf("string")`.
The CI pipeline includes a test with `clang-format` to verify that the style is
correct, and will fail otherwise. This means that you should run `clang-format`
locally before pushing any change to the C++ codebase.
Since the behaviour of `clang-format` varies slightly across versions, it is
necessary to stick to a specific version. We currently use version 15 of
`clang-format`.
### Installing clang-format locally
Under Debian, use the `clang-format-15` package. Make sure that the generic
`clang-format` package is not installed, nor any more recent version of
`clang-format`, otherwise selection of the correct binary may fail (see below).
Under MSYS2, the package `mingw-w64-x86_64-clang-15` provides the right
version of `clang-format`, under the `/mingw64/opt/llvm-15/bin/` directory.
That latter directory is not in the `PATH` by default, so it should probably be
added first in the `PATH` in order to make sure that it is used preferably to
others (untested).
Homebrew currently does not provide version 15 of `clang-format`.
### Applying the style with Meson
When `clang-format` is installed, Meson is able to autodetect it and then
creates a rule for reformatting the whole git repository (NB: this does not
recurse into submodules). That rule can be invoked with:
Here is a source code example for a class declaration:
```
```
class ABC
ninja -C <builddir> clang-format
{
public:
int foo(string a);
private:
void bar();
};
```
```
The keywords `public` and `private` should be on the same column as the `class` keyword, and function declarations indented with two spaces.
Here is a source code example for a function body:
It is also possible to check whether the correct style has been applied
(without doing any reformatting):
```
```
int
ninja -C <builddir> clang-format-check
class_name::function_name(int arg1, int arg2)
{
if (x < foo(y, z))
haha = bar[4] + 5;
else
{
while (z)
{
haha += foo(z, z);
z--;
}
return (++x + bar());
}
do
{
a = foo(a);
}
while (a > 0);
switch (c)
{
case 'a':
return (0);
default:
return (1);
}
}
```
```
The basic indentation level is of 2 spaces. Braces are always put on the following line, and are indented with 2 spaces (except for namespace, class and function declarations). Note that the function name should be placed on the first column.
### Applying the style with Emacs
There exists a `clang-format` package, available through MELPA. Under Debian,
that package is installed automatically whenever `clang-format` is installed.
It can be loaded with `(require 'clang-format)`.
The package provides two main functions, whose names are self-explanatory:
`clang-format-buffer` and `clang-format-region`.
## Copyright notice
## Copyright notice
...
@@ -196,7 +200,7 @@ You should add the following notice at the very beginning of your all your sourc
...
@@ -196,7 +200,7 @@ You should add the following notice at the very beginning of your all your sourc