diff mbox

astyle: Formatting rules for QEMU

Message ID CAAu8pHsMm0PUbFnhw5LWKJuu_fSa1a5px3Wykd0X4ennwtKYWA@mail.gmail.com
State New
Headers show

Commit Message

Blue Swirl Feb. 18, 2012, 10:10 a.m. UTC
On Sat, Feb 18, 2012 at 09:07, Stefan Weil <sw@weilnetz.de> wrote:
> These AStyle rules try to implement the QEMU coding style.
>
> AStyle can also fix only certain aspects of the coding style,
> for example indentation.
>
> Signed-off-by: Stefan Weil <sw@weilnetz.de>
> ---
>
> Hi Blue,
>
> maybe this AStyle rules work better. I tried them with target-sparc,
> and the result does look quite good.

There are still indentation problems when expressions continue to next
line, also this does not look OK:
Overall astyle seems to be a better tool than GNU indent.

I also tried to use Emacs to perform the indenting with the attached
scripts, but the result is not that great either, especially some
macros and helper.h confuse indentation.

> Regards,
> Stefan
>
>  scripts/astylerc |   19 +++++++++++++++++++
>  1 files changed, 19 insertions(+), 0 deletions(-)
>  create mode 100644 scripts/astylerc
>
> diff --git a/scripts/astylerc b/scripts/astylerc
> new file mode 100644
> index 0000000..dfbfd41
> --- /dev/null
> +++ b/scripts/astylerc
> @@ -0,0 +1,19 @@
> +# Artistic Style (astyle) options for qemu source code.
> +
> +# Usage:
> +# astyle --options=scripts/astylerc {source files}
> +
> +# For best results, use latest astyle from http://astyle.sourceforge.net/.
> +
> +add-brackets
> +align-pointer=name
> +convert-tabs
> +max-code-length=80

This is only supported by the SVN HEAD, not even the download tarball offered.

> +style=otbs
> +brackets=linux
> +indent=spaces=4
> +max-code-length=80
> +max-instatement-indent=60
> +pad-oper
> +pad-header
> +unpad-paren
> --
> 1.7.9
>

Comments

Stefan Weil Feb. 18, 2012, 11:13 a.m. UTC | #1
Am 18.02.2012 11:10, schrieb Blue Swirl:
> There are still indentation problems when expressions continue to next
> line, also this does not look OK:
> --- a/target-sparc/translate.c
> +++ b/target-sparc/translate.c
> @@ -36,7 +36,7 @@
>
> #define DYNAMIC_PC 1 /* dynamic pc value */
> #define JUMP_PC 2 /* dynamic pc value which takes only two values
> - according to jump_pc[T2] */
> +according to jump_pc[T2] */

Writing comments like this looks nice, but needs more work when
the comments are written. Maintenance of the code is also more
difficult: any time a new line with a longer name is added, you
have to reformat all other lines to preserve the good look.

Just add this line to the code given above to see what I mean:
     #define ANY_LONG_PC 3 /* just an example */

This is why I usually write comments in an extra line before the
code statement.

Regards,
Stefan
diff mbox

Patch

--- a/target-sparc/translate.c
+++ b/target-sparc/translate.c
@@ -36,7 +36,7 @@ 

 #define DYNAMIC_PC  1 /* dynamic pc value */
 #define JUMP_PC     2 /* dynamic pc value which takes only two values
-                         according to jump_pc[T2] */
+according to jump_pc[T2] */

Moving the brace to same line as switch case should not be necessary.