Module Name:    src
Committed By:   rillig
Date:           Sat Mar 20 11:24:49 UTC 2021

Modified Files:
        src/tests/usr.bin/xlint/lint1: d_c99_compound_literal_comma.c
        src/usr.bin/xlint/lint1: cgram.y

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 \
    src/tests/usr.bin/xlint/lint1/d_c99_compound_literal_comma.c
cvs rdiff -u -r1.180 -r1.181 src/usr.bin/xlint/lint1/cgram.y

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/tests/usr.bin/xlint/lint1/d_c99_compound_literal_comma.c
diff -u src/tests/usr.bin/xlint/lint1/d_c99_compound_literal_comma.c:1.2 src/tests/usr.bin/xlint/lint1/d_c99_compound_literal_comma.c:1.3
--- src/tests/usr.bin/xlint/lint1/d_c99_compound_literal_comma.c:1.2	Sun Jan 31 14:39:31 2021
+++ src/tests/usr.bin/xlint/lint1/d_c99_compound_literal_comma.c	Sat Mar 20 11:24:49 2021
@@ -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 };
+
+	/* 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, };
 
-	return (struct bintime) {
-		.sec = us / 1000000U,
-		.frac = (((us % 1000000U) >> 32)/1000000U) >> 32,
-	};
+	/* Designators, trailing comma. */
+	return (struct point){ .x = point.x, .y = -point.y, };
 }

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.180 src/usr.bin/xlint/lint1/cgram.y:1.181
--- src/usr.bin/xlint/lint1/cgram.y:1.180	Sat Mar 20 11:05:16 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Sat Mar 20 11:24:49 2021
@@ -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 @@ initializer:			/* C99 6.7.8 "Initializat
 	| 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
 	;
 

Reply via email to