* [PATCH] enum: support declarations with a trailing comma
@ 2025-09-03 14:51 Alan Maguire
2025-09-16 20:45 ` Kris Van Hees
0 siblings, 1 reply; 3+ messages in thread
From: Alan Maguire @ 2025-09-03 14:51 UTC (permalink / raw)
To: dtrace; +Cc: dtrace-devel, Alan Maguire
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] enum: support declarations with a trailing comma
2025-09-03 14:51 [PATCH] enum: support declarations with a trailing comma Alan Maguire
@ 2025-09-16 20:45 ` Kris Van Hees
2025-09-17 16:08 ` Kris Van Hees
0 siblings, 1 reply; 3+ messages in thread
From: Kris Van Hees @ 2025-09-16 20:45 UTC (permalink / raw)
To: Alan Maguire; +Cc: dtrace, dtrace-devel
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
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] enum: support declarations with a trailing comma
2025-09-16 20:45 ` Kris Van Hees
@ 2025-09-17 16:08 ` Kris Van Hees
0 siblings, 0 replies; 3+ messages in thread
From: Kris Van Hees @ 2025-09-17 16:08 UTC (permalink / raw)
To: Kris Van Hees; +Cc: Alan Maguire, dtrace, dtrace-devel
On Tue, Sep 16, 2025 at 04:45:52PM -0400, Kris Van Hees wrote:
> 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.
Also, it seems to be triggering a failure on OL10. We suspect it may be a
bison bug, but it needs further investigation (Nick will take a look).
> 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
> >
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-09-17 16:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-03 14:51 [PATCH] enum: support declarations with a trailing comma Alan Maguire
2025-09-16 20:45 ` Kris Van Hees
2025-09-17 16:08 ` Kris Van Hees
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox