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 Add union casts.



details:   https://anonhg.NetBSD.org/src/rev/f1850029fb2e
branches:  trunk
changeset: 817390:f1850029fb2e
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Aug 19 10:19:45 2016 +0000

description:
Add union casts.

diffstat:

 usr.bin/xlint/lint1/err.c  |   6 ++++--
 usr.bin/xlint/lint1/tree.c |  27 ++++++++++++++++++++++++---
 2 files changed, 28 insertions(+), 5 deletions(-)

diffs (75 lines):

diff -r 1248e43f50a3 -r f1850029fb2e usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Fri Aug 19 10:19:15 2016 +0000
+++ b/usr.bin/xlint/lint1/err.c Fri Aug 19 10:19:45 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: err.c,v 1.50 2016/08/18 14:42:48 christos Exp $        */
+/*     $NetBSD: err.c,v 1.51 2016/08/19 10:19:45 christos Exp $        */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.50 2016/08/18 14:42:48 christos Exp $");
+__RCSID("$NetBSD: err.c,v 1.51 2016/08/19 10:19:45 christos Exp $");
 #endif
 
 #include <sys/types.h>
@@ -387,6 +387,8 @@
        "variable declaration in for loop",                           /* 325 */
        "%s attribute ignored for %s",                                /* 326 */
        "declarations after statements is a C9X feature",             /* 327 */
+       "union cast is a C9X feature",                                /* 328 */
+       "type '%s' is not a member of '%s'",                          /* 329 */
 };
 
 /*
diff -r 1248e43f50a3 -r f1850029fb2e usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Fri Aug 19 10:19:15 2016 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Fri Aug 19 10:19:45 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.82 2015/10/14 18:31:52 christos Exp $       */
+/*     $NetBSD: tree.c,v 1.83 2016/08/19 10:19:45 christos Exp $       */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -37,7 +37,7 @@
 
 #include <sys/cdefs.h>
 #if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.82 2015/10/14 18:31:52 christos Exp $");
+__RCSID("$NetBSD: tree.c,v 1.83 2016/08/19 10:19:45 christos Exp $");
 #endif
 
 #include <stdlib.h>
@@ -3143,7 +3143,28 @@
                 * XXX ANSI C requires scalar types or void (Plauger&Brodie).
                 * But this seams really questionable.
                 */
-       } else if (nt == STRUCT || nt == UNION || nt == ARRAY || nt == FUNC) {
+       } else if (nt == UNION) {
+               char buf[256], buf1[256];
+               sym_t *m;
+               str_t *str = tp->t_str;
+               if (!Sflag) {
+                       error(328);
+                       return NULL;
+               }
+               for (m = str->memb; m != NULL; m = m->s_nxt) {
+                       if (sametype(m->s_type, tn->tn_type)) {
+                               tn = getnode();
+                               tn->tn_op = CVT;
+                               tn->tn_type = tp;
+                               tn->tn_cast = 1;
+                               tn->tn_right = NULL;
+                               return tn;
+                       }
+               }
+               error(329, tyname(buf, sizeof(buf), tn->tn_type),
+                   tyname(buf1, sizeof(buf1), tp));
+               return NULL;
+       } else if (nt == STRUCT || nt == ARRAY || nt == FUNC) {
                /* invalid cast expression */
                error(147);
                return (NULL);



Home | Main Index | Thread Index | Old Index