Module Name:    src
Committed By:   rillig
Date:           Tue Sep 14 19:44:40 UTC 2021

Modified Files:
        src/usr.bin/xlint/lint1: cgram.y lint1.h

Log Message:
lint: allow [*] everywhere where [] and [integer] are allowed

It's a seldom used feature, but now it's at least consistent.


To generate a diff of this commit:
cvs rdiff -u -r1.363 -r1.364 src/usr.bin/xlint/lint1/cgram.y
cvs rdiff -u -r1.128 -r1.129 src/usr.bin/xlint/lint1/lint1.h

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

Modified files:

Index: src/usr.bin/xlint/lint1/cgram.y
diff -u src/usr.bin/xlint/lint1/cgram.y:1.363 src/usr.bin/xlint/lint1/cgram.y:1.364
--- src/usr.bin/xlint/lint1/cgram.y:1.363	Tue Sep 14 19:06:27 2021
+++ src/usr.bin/xlint/lint1/cgram.y	Tue Sep 14 19:44:40 2021
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.363 2021/09/14 19:06:27 rillig Exp $ */
+/* $NetBSD: cgram.y,v 1.364 2021/09/14 19:44:40 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.363 2021/09/14 19:06:27 rillig Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.364 2021/09/14 19:44:40 rillig Exp $");
 #endif
 
 #include <limits.h>
@@ -143,6 +143,7 @@ anonymize(sym_t *s)
 	qual_ptr *y_qual_ptr;
 	bool	y_seen_statement;
 	struct generic_association *y_generic;
+	struct array_size y_array_size;
 };
 
 %token			T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN
@@ -335,6 +336,7 @@ anonymize(sym_t *s)
 %type	<y_sym>		direct_param_declarator
 %type	<y_sym>		direct_notype_param_declarator
 %type	<y_sym>		param_list
+%type	<y_array_size>	array_size_opt
 %type	<y_tnode>	array_size
 %type	<y_sym>		identifier_list
 %type	<y_type>	type_name
@@ -1225,11 +1227,8 @@ notype_direct_declarator:
 	| type_attribute notype_direct_declarator {
 		$$ = $2;
 	  }
-	| notype_direct_declarator T_LBRACK T_RBRACK {
-		$$ = add_array($1, false, 0);
-	  }
-	| notype_direct_declarator T_LBRACK array_size T_RBRACK {
-		$$ = add_array($1, true, to_int_constant($3, false));
+	| notype_direct_declarator T_LBRACK array_size_opt T_RBRACK {
+		$$ = add_array($1, $3.has_dim, $3.dim);
 	  }
 	| notype_direct_declarator param_list asm_or_symbolrename_opt {
 		$$ = add_function(symbolrename($1, $3), $2);
@@ -1249,11 +1248,8 @@ type_direct_declarator:
 	| type_attribute type_direct_declarator {
 		$$ = $2;
 	  }
-	| type_direct_declarator T_LBRACK T_RBRACK {
-		$$ = add_array($1, false, 0);
-	  }
-	| type_direct_declarator T_LBRACK array_size T_RBRACK {
-		$$ = add_array($1, true, to_int_constant($3, false));
+	| type_direct_declarator T_LBRACK array_size_opt T_RBRACK {
+		$$ = add_array($1, $3.has_dim, $3.dim);
 	  }
 	| type_direct_declarator param_list asm_or_symbolrename_opt {
 		$$ = add_function(symbolrename($1, $3), $2);
@@ -1294,12 +1290,9 @@ direct_param_declarator:
 	| T_LPAREN notype_param_declarator T_RPAREN {
 		$$ = $2;
 	  }
-	| direct_param_declarator T_LBRACK T_RBRACK gcc_attribute_list_opt {
-		$$ = add_array($1, false, 0);
-	  }
-	| direct_param_declarator T_LBRACK array_size T_RBRACK
+	| direct_param_declarator T_LBRACK array_size_opt T_RBRACK
 	    gcc_attribute_list_opt {
-		$$ = add_array($1, true, to_int_constant($3, false));
+		$$ = add_array($1, $3.has_dim, $3.dim);
 	  }
 	| direct_param_declarator param_list asm_or_symbolrename_opt {
 		$$ = add_function(symbolrename($1, $3), $2);
@@ -1315,11 +1308,8 @@ direct_notype_param_declarator:
 	| T_LPAREN notype_param_declarator T_RPAREN {
 		$$ = $2;
 	  }
-	| direct_notype_param_declarator T_LBRACK T_RBRACK {
-		$$ = add_array($1, false, 0);
-	  }
-	| direct_notype_param_declarator T_LBRACK array_size T_RBRACK {
-		$$ = add_array($1, true, to_int_constant($3, false));
+	| direct_notype_param_declarator T_LBRACK array_size_opt T_RBRACK {
+		$$ = add_array($1, $3.has_dim, $3.dim);
 	  }
 	| direct_notype_param_declarator param_list asm_or_symbolrename_opt {
 		$$ = add_function(symbolrename($1, $3), $2);
@@ -1342,6 +1332,22 @@ id_list_lparen:
 	  }
 	;
 
+array_size_opt:
+	  /* empty */ {
+		$$.has_dim = false;
+		$$.dim = 0;
+	  }
+	| T_ASTERISK {
+		/* since C99; variable length array of unspecified size */
+		$$.has_dim = false; /* TODO: maybe change to true */
+		$$.dim = 0;	/* just as a placeholder */
+	  }
+	| array_size {
+		$$.has_dim = true;
+		$$.dim = to_int_constant($1, false);
+	  }
+	;
+
 array_size:
 	  type_qualifier_list_opt T_SCLASS constant_expr {
 		/* C11 6.7.6.3p7 */
@@ -1407,29 +1413,14 @@ direct_abstract_declarator:
 	  T_LPAREN abstract_declarator T_RPAREN {
 		$$ = $2;
 	  }
-	| T_LBRACK T_RBRACK {
-		$$ = add_array(abstract_name(), false, 0);
-	  }
-	| T_LBRACK T_ASTERISK T_RBRACK {
-		/* since C99 */
-		$$ = add_array(abstract_name(), false, 0);
-	  }
-	| T_LBRACK array_size T_RBRACK {
-		$$ = add_array(abstract_name(), true,
-		    to_int_constant($2, false));
+	| T_LBRACK array_size_opt T_RBRACK {
+		$$ = add_array(abstract_name(), $2.has_dim, $2.dim);
 	  }
 	| type_attribute direct_abstract_declarator {
 		$$ = $2;
 	  }
-	| direct_abstract_declarator T_LBRACK T_RBRACK {
-		$$ = add_array($1, false, 0);
-	  }
-	| direct_abstract_declarator T_LBRACK T_ASTERISK T_RBRACK {
-		/* since C99 */
-		$$ = add_array($1, false, 0);
-	  }
-	| direct_abstract_declarator T_LBRACK array_size T_RBRACK {
-		$$ = add_array($1, true, to_int_constant($3, false));
+	| direct_abstract_declarator T_LBRACK array_size_opt T_RBRACK {
+		$$ = add_array($1, $3.has_dim, $3.dim);
 	  }
 	| abstract_decl_param_list asm_or_symbolrename_opt {
 		$$ = add_function(symbolrename(abstract_name(), $2), $1);

Index: src/usr.bin/xlint/lint1/lint1.h
diff -u src/usr.bin/xlint/lint1/lint1.h:1.128 src/usr.bin/xlint/lint1/lint1.h:1.129
--- src/usr.bin/xlint/lint1/lint1.h:1.128	Tue Aug 31 17:51:30 2021
+++ src/usr.bin/xlint/lint1/lint1.h	Tue Sep 14 19:44:40 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lint1.h,v 1.128 2021/08/31 17:51:30 rillig Exp $ */
+/* $NetBSD: lint1.h,v 1.129 2021/09/14 19:44:40 rillig Exp $ */
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou.  All Rights Reserved.
@@ -335,6 +335,11 @@ struct generic_association {
 	struct generic_association *ga_prev;
 };
 
+struct array_size {
+	bool has_dim;
+	int dim;
+};
+
 /*
  * For nested declarations a stack exists, which holds all information
  * needed for the current level. dcs points to the innermost element of this

Reply via email to