Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 lint: join grammar rules for initialization
details: https://anonhg.NetBSD.org/src/rev/81ce185849c9
branches: trunk
changeset: 1019784:81ce185849c9
user: rillig <rillig%NetBSD.org@localhost>
date: Sat Mar 20 11:24:49 2021 +0000
description:
lint: join grammar rules for initialization
The '%prec T_COMMA' is necessary to avoid lots of parse errors in the
lint1 unit tests. Curiously, further down in the grammar, for compound
literals, the '%prec T_COMMA' is not necessary, even though the context
looks very similar.
No functional change.
diffstat:
tests/usr.bin/xlint/lint1/d_c99_compound_literal_comma.c | 36 +++++++++++----
usr.bin/xlint/lint1/cgram.y | 7 +-
2 files changed, 29 insertions(+), 14 deletions(-)
diffs (76 lines):
diff -r 4f2a34cb6723 -r 81ce185849c9 tests/usr.bin/xlint/lint1/d_c99_compound_literal_comma.c
--- a/tests/usr.bin/xlint/lint1/d_c99_compound_literal_comma.c Sat Mar 20 11:05:16 2021 +0000
+++ b/tests/usr.bin/xlint/lint1/d_c99_compound_literal_comma.c Sat Mar 20 11:24:49 2021 +0000
@@ -1,17 +1,33 @@
-/* $NetBSD: d_c99_compound_literal_comma.c,v 1.2 2021/01/31 14:39:31 rillig Exp $ */
+/* $NetBSD: d_c99_compound_literal_comma.c,v 1.3 2021/03/20 11:24:49 rillig Exp $ */
# 3 "d_c99_compound_literal_comma.c"
-struct bintime {
- unsigned long long sec;
- unsigned long long frac;
+/*-
+ * Ensure that compound literals can be parsed.
+ *
+ * C99 6.5.2 "Postfix operators" for the syntax.
+ * C99 6.5.2.5 "Compound literals" for the semantics.
+ */
+
+struct point {
+ int x;
+ int y;
};
-struct bintime
-us2bintime(unsigned long long us)
+struct point
+point_abs(struct point point)
{
+ /* No designators, no trailing comma. */
+ if (point.x >= 0 && point.y >= 0)
+ return (struct point){ point.x, point.y };
- return (struct bintime) {
- .sec = us / 1000000U,
- .frac = (((us % 1000000U) >> 32)/1000000U) >> 32,
- };
+ /* Designators, no trailing comma. */
+ if (point.x >= 0)
+ return (struct point){ .x = point.x, .y = -point.y };
+
+ /* No designators, trailing comma. */
+ if (point.y >= 0)
+ return (struct point){ point.x, point.y, };
+
+ /* Designators, trailing comma. */
+ return (struct point){ .x = point.x, .y = -point.y, };
}
diff -r 4f2a34cb6723 -r 81ce185849c9 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Sat Mar 20 11:05:16 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Sat Mar 20 11:24:49 2021 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.180 2021/03/20 11:05:16 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.181 2021/03/20 11:24:49 rillig Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.180 2021/03/20 11:05:16 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.181 2021/03/20 11:24:49 rillig Exp $");
#endif
#include <limits.h>
@@ -1332,8 +1332,7 @@
| init_lbrace init_rbrace {
/* XXX: Empty braces are not covered by C99 6.7.8. */
}
- | init_lbrace initializer_list init_rbrace
- | init_lbrace initializer_list T_COMMA init_rbrace
+ | init_lbrace initializer_list %prec T_COMMA comma_opt init_rbrace
| error
;
Home |
Main Index |
Thread Index |
Old Index