From: Kris Van Hees <kris.van.hees@oracle.com>
To: Alan Maguire <alan.maguire@oracle.com>
Cc: dtrace@lists.linux.dev, dtrace-devel@oss.oracle.com
Subject: Re: [PATCH] enum: support declarations with a trailing comma
Date: Tue, 16 Sep 2025 16:45:52 -0400 [thread overview]
Message-ID: <aMnMgPzLHyRtDS7l@oracle.com> (raw)
In-Reply-To: <20250903145104.856314-1-alan.maguire@oracle.com>
Nice patch. But I think it should also have an error test that verifies that
having a missing enumerator (i.e. have ,, in the enumeration list) is indeed
still an error.
On Wed, Sep 03, 2025 at 03:51:04PM +0100, Alan Maguire wrote:
> When doing python tracing, it was recently observed that #include'ing
> a file with enum declarations with trailing commas fails; this is
> due to the D grammar being strict about the last enumerator value
> not having a trailing comma. So
>
> typedef enum foo {
> BAR,
> BAZ
> };
>
> is permitted, but
>
> typdef enum foo {
> BAR,
> BAZ,
> };
>
> is not. The latter pattern is used quite frequently in #include
> files, especially where conditional compilation of some enum
> values is done.
>
> Relax this constraint and add a test to validate that D compilation
> succeeds with the trailing comma in an enum declaration.
>
> Signed-off-by: Alan Maguire <alan.maguire@oracle.com>
> ---
> libdtrace/dt_grammar.y | 3 +-
> test/unittest/enum/tst.EnumTrailingComma.d | 36 ++++++++++++++++++++++
> 2 files changed, 38 insertions(+), 1 deletion(-)
> create mode 100644 test/unittest/enum/tst.EnumTrailingComma.d
>
> diff --git a/libdtrace/dt_grammar.y b/libdtrace/dt_grammar.y
> index 677cd869..7984b85d 100644
> --- a/libdtrace/dt_grammar.y
> +++ b/libdtrace/dt_grammar.y
> @@ -702,7 +702,8 @@ enum_definition:
>
> enumerator_list:
> enumerator
> - | enumerator_list DT_TOK_COMMA enumerator
> + | enumerator DT_TOK_COMMA enumerator_list
> + | enumerator DT_TOK_COMMA
> ;
>
> enumerator: DT_TOK_IDENT { dt_decl_enumerator($1, NULL); }
> diff --git a/test/unittest/enum/tst.EnumTrailingComma.d b/test/unittest/enum/tst.EnumTrailingComma.d
> new file mode 100644
> index 00000000..0414498b
> --- /dev/null
> +++ b/test/unittest/enum/tst.EnumTrailingComma.d
> @@ -0,0 +1,36 @@
> +/*
> + * Oracle Linux DTrace.
> + * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
> + * Licensed under the Universal Permissive License v 1.0 as shown at
> + * http://oss.oracle.com/licenses/upl.
> + */
> +
> +/*
> + * ASSERTION:
> + * Enumerations should support declaration with a trailing comma for
> + * the last enumeration value.
> + *
> + * SECTION: Type and Constant Definitions/Enumerations
> + *
> + * NOTES:
> + *
> + */
> +
> +#pragma D option quiet
> +
> +enum colors {
> + RED = 1,
> + GREEN = 2,
> + BLUE = 3,
> +};
> +
> +enum shapes {
> + CIRCLE,
> + SQUARE,
> + TRIANGLE,
> +};
> +
> +BEGIN
> +{
> + exit(0);
> +}
> --
> 2.43.5
>
next prev parent reply other threads:[~2025-09-16 20:46 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-03 14:51 [PATCH] enum: support declarations with a trailing comma Alan Maguire
2025-09-16 20:45 ` Kris Van Hees [this message]
2025-09-17 16:08 ` Kris Van Hees
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aMnMgPzLHyRtDS7l@oracle.com \
--to=kris.van.hees@oracle.com \
--cc=alan.maguire@oracle.com \
--cc=dtrace-devel@oss.oracle.com \
--cc=dtrace@lists.linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.