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: use different tokens for operators...



details:   https://anonhg.NetBSD.org/src/rev/cd8178448e52
branches:  trunk
changeset: 379806:cd8178448e52
user:      rillig <rillig%NetBSD.org@localhost>
date:      Sun Jun 20 18:15:12 2021 +0000

description:
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.

diffstat:

 usr.bin/xlint/lint1/cgram.y |  27 +++++++++++----------------
 usr.bin/xlint/lint1/scan.l  |   8 ++++----
 2 files changed, 15 insertions(+), 20 deletions(-)

diffs (109 lines):

diff -r 1fae9ac7801f -r cd8178448e52 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Sun Jun 20 18:11:21 2021 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Sun Jun 20 18:15:12 2021 +0000
@@ -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;
          }
        ;
 
diff -r 1fae9ac7801f -r cd8178448e52 usr.bin/xlint/lint1/scan.l
--- a/usr.bin/xlint/lint1/scan.l        Sun Jun 20 18:11:21 2021 +0000
+++ b/usr.bin/xlint/lint1/scan.l        Sun Jun 20 18:15:12 2021 +0000
@@ -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 @@ 0[xX]{HD}+{HX}{TL}            |
 ">>"                           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;



Home | Main Index | Thread Index | Old Index