Module Name: src Committed By: rillig Date: Sun Jun 20 18:15:12 UTC 2021
Modified Files: src/usr.bin/xlint/lint1: cgram.y scan.l Log Message: lint: use different tokens for operators '.' and '->' Before C99, these tokens were only used in member access expressions. C99 reused the operator '.' in initializations of structs and unions. Let the grammar check for syntax errors instead of writing custom code. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.229 -r1.230 src/usr.bin/xlint/lint1/cgram.y cvs rdiff -u -r1.133 -r1.134 src/usr.bin/xlint/lint1/scan.l 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.229 src/usr.bin/xlint/lint1/cgram.y:1.230 --- src/usr.bin/xlint/lint1/cgram.y:1.229 Sun Jun 20 11:42:25 2021 +++ src/usr.bin/xlint/lint1/cgram.y Sun Jun 20 18:15:12 2021 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.229 2021/06/20 11:42:25 rillig Exp $ */ +/* $NetBSD: cgram.y,v 1.230 2021/06/20 18:15:12 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.229 2021/06/20 11:42:25 rillig Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.230 2021/06/20 18:15:12 rillig Exp $"); #endif #include <limits.h> @@ -123,7 +123,7 @@ anonymize(sym_t *s) } %} -%expect 181 +%expect 182 %union { val_t *y_val; @@ -142,7 +142,7 @@ anonymize(sym_t *s) }; %token T_LBRACE T_RBRACE T_LBRACK T_RBRACK T_LPAREN T_RPAREN -%token <y_op> T_MEMBACC +%token T_POINT T_ARROW %token <y_op> T_UNARY %token <y_op> T_INCDEC %token T_SIZEOF @@ -269,7 +269,7 @@ anonymize(sym_t *s) %left T_ADDITIVE %left T_ASTERISK T_MULTIPLICATIVE %right T_UNARY T_INCDEC T_SIZEOF T_REAL T_IMAG -%left T_LPAREN T_LBRACK T_MEMBACC +%left T_LPAREN T_LBRACK T_POINT T_ARROW %token <y_sb> T_NAME %token <y_sb> T_TYPENAME @@ -1420,7 +1420,7 @@ designator: /* C99 6.7.8 "Initializati /* array initializer with des.s is a C9X feature */ warning(321); } - | point identifier { + | T_POINT identifier { if (!Sflag) /* struct or union member name in initializer is ... */ warning(313); @@ -2074,18 +2074,13 @@ func_arg_list: ; point_or_arrow: - T_MEMBACC { + T_POINT { symtyp = FMEMBER; - $$ = $1; + $$ = POINT; } - ; - -point: - T_MEMBACC { - if ($1 != POINT) { - /* syntax error '%s' */ - error(249, yytext); - } + | T_ARROW { + symtyp = FMEMBER; + $$ = ARROW; } ; Index: src/usr.bin/xlint/lint1/scan.l diff -u src/usr.bin/xlint/lint1/scan.l:1.133 src/usr.bin/xlint/lint1/scan.l:1.134 --- src/usr.bin/xlint/lint1/scan.l:1.133 Sun Mar 21 08:55:59 2021 +++ src/usr.bin/xlint/lint1/scan.l Sun Jun 20 18:15:12 2021 @@ -1,5 +1,5 @@ %{ -/* $NetBSD: scan.l,v 1.133 2021/03/21 08:55:59 rillig Exp $ */ +/* $NetBSD: scan.l,v 1.134 2021/06/20 18:15:12 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: scan.l,v 1.133 2021/03/21 08:55:59 rillig Exp $"); +__RCSID("$NetBSD: scan.l,v 1.134 2021/06/20 18:15:12 rillig Exp $"); #endif #include "lint1.h" @@ -94,8 +94,8 @@ TL ([fFlL]?[i]?) ">>" return lex_operator(T_SHIFT, SHR); "++" return lex_operator(T_INCDEC, INC); "--" return lex_operator(T_INCDEC, DEC); -"->" return lex_operator(T_MEMBACC, ARROW); -"." return lex_operator(T_MEMBACC, POINT); +"->" return T_ARROW; +"." return T_POINT; "+" return lex_operator(T_ADDITIVE, PLUS); "-" return lex_operator(T_ADDITIVE, MINUS); "*" return T_ASTERISK;