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 fix typeof, add __builtin_offsetof



details:   https://anonhg.NetBSD.org/src/rev/4ef8c6830559
branches:  trunk
changeset: 822198:4ef8c6830559
user:      christos <christos%NetBSD.org@localhost>
date:      Mon Mar 06 21:01:39 2017 +0000

description:
fix typeof, add __builtin_offsetof

diffstat:

 usr.bin/xlint/lint1/cgram.y    |  20 +++++++++++++-------
 usr.bin/xlint/lint1/externs1.h |   3 ++-
 usr.bin/xlint/lint1/scan.l     |   5 +++--
 usr.bin/xlint/lint1/tree.c     |  24 ++++++++++++++++++++++--
 4 files changed, 40 insertions(+), 12 deletions(-)

diffs (159 lines):

diff -r 50ee6bae4a51 -r 4ef8c6830559 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y       Mon Mar 06 17:19:21 2017 +0000
+++ b/usr.bin/xlint/lint1/cgram.y       Mon Mar 06 21:01:39 2017 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: cgram.y,v 1.93 2017/03/06 11:58:31 christos Exp $ */
+/* $NetBSD: cgram.y,v 1.94 2017/03/06 21:01:39 christos 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.93 2017/03/06 11:58:31 christos Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.94 2017/03/06 21:01:39 christos Exp $");
 #endif
 
 #include <stdlib.h>
@@ -140,6 +140,7 @@
 %token <y_op>          T_UNOP
 %token <y_op>          T_INCDEC
 %token                 T_SIZEOF
+%token                 T_BUILTIN_OFFSETOF
 %token                 T_TYPEOF
 %token                 T_EXTENSION
 %token                 T_ALIGNOF
@@ -245,7 +246,7 @@
 %left  T_SHFTOP
 %left  T_ADDOP
 %left  T_MULT T_DIVOP
-%right T_UNOP T_INCDEC T_SIZEOF T_ALIGNOF T_REAL T_IMAG
+%right T_UNOP T_INCDEC T_SIZEOF TBUILTIN_SIZEOF T_ALIGNOF T_REAL T_IMAG
 %left  T_LPARN T_LBRACK T_STROP
 
 %token <y_sb>          T_NAME
@@ -1362,10 +1363,7 @@
        ;
 
 type_name:
-         T_TYPEOF term  {
-               $$ = $2->tn_type;
-         }
-       | {
+         {
                pushdecl(ABSTRACT);
          } abstract_declaration {
                popdecl();
@@ -1398,6 +1396,9 @@
        | pointer direct_abs_decl {
                $$ = addptr($2, $1);
          }
+       | T_TYPEOF term {
+               $$ = mktempsym($2->tn_type);
+         }
        ;
 
 direct_abs_decl:
@@ -1905,6 +1906,11 @@
        | T_IMAG T_LPARN term T_RPARN {
                $$ = build(IMAG, $3, NULL);
          }
+       | T_BUILTIN_OFFSETOF T_LPARN type_name T_COMMA identifier T_RPARN
+                                                   %prec T_BUILTIN_OFFSETOF {
+               symtyp = FMOS;
+               $$ = bldoffsetof($3, getsym($5));
+         }
        | T_SIZEOF term                                 %prec T_SIZEOF {
                if (($$ = $2 == NULL ? NULL : bldszof($2->tn_type)) != NULL)
                        chkmisc($2, 0, 0, 0, 0, 0, 1);
diff -r 50ee6bae4a51 -r 4ef8c6830559 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h    Mon Mar 06 17:19:21 2017 +0000
+++ b/usr.bin/xlint/lint1/externs1.h    Mon Mar 06 21:01:39 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: externs1.h,v 1.34 2016/12/27 21:52:35 christos Exp $   */
+/*     $NetBSD: externs1.h,v 1.35 2017/03/06 21:01:39 christos Exp $   */
 
 /*
  * Copyright (c) 1994, 1995 Jochen Pohl
@@ -204,6 +204,7 @@
 extern tnode_t *convert(op_t, int, type_t *, tnode_t *);
 extern void    cvtcon(op_t, int, type_t *, val_t *, val_t *);
 extern tnode_t *bldszof(type_t *);
+extern tnode_t *bldoffsetof(type_t *, sym_t *);
 extern tnode_t *bldalof(type_t *);
 extern tnode_t *cast(tnode_t *, type_t *);
 extern tnode_t *funcarg(tnode_t *, tnode_t *);
diff -r 50ee6bae4a51 -r 4ef8c6830559 usr.bin/xlint/lint1/scan.l
--- a/usr.bin/xlint/lint1/scan.l        Mon Mar 06 17:19:21 2017 +0000
+++ b/usr.bin/xlint/lint1/scan.l        Mon Mar 06 21:01:39 2017 +0000
@@ -1,5 +1,5 @@
 %{
-/* $NetBSD: scan.l,v 1.78 2017/01/15 21:10:24 christos Exp $ */
+/* $NetBSD: scan.l,v 1.79 2017/03/06 21:01:39 christos 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.78 2017/01/15 21:10:24 christos Exp $");
+__RCSID("$NetBSD: scan.l,v 1.79 2017/03/06 21:01:39 christos Exp $");
 #endif
 
 #include <stdlib.h>
@@ -218,6 +218,7 @@
        { "bounded",    T_AT_BOUNDED,   0,      0,      0,        0,0,1,1,5 },
        { "break",      T_BREAK,        0,      0,      0,        0,0,0,0,1 },
        { "buffer",     T_AT_BUFFER,    0,      0,      0,        0,0,1,1,5 },
+       { "builtin_offsetof", T_BUILTIN_OFFSETOF, 0, 0, 0,        0,0,1,0,2 },
        { "case",       T_CASE,         0,      0,      0,        0,0,0,0,1 },
        { "char",       T_TYPE,         0,      CHAR,   0,        0,0,0,0,1 },
        { "cold",       T_AT_COLD,      0,      0,      0,        0,0,1,1,5 },
diff -r 50ee6bae4a51 -r 4ef8c6830559 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c        Mon Mar 06 17:19:21 2017 +0000
+++ b/usr.bin/xlint/lint1/tree.c        Mon Mar 06 21:01:39 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: tree.c,v 1.83 2016/08/19 10:19:45 christos Exp $       */
+/*     $NetBSD: tree.c,v 1.84 2017/03/06 21:01:39 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.83 2016/08/19 10:19:45 christos Exp $");
+__RCSID("$NetBSD: tree.c,v 1.84 2017/03/06 21:01:39 christos Exp $");
 #endif
 
 #include <stdlib.h>
@@ -3012,6 +3012,26 @@
        return getinode(st, tsize(tp) / CHAR_BIT);
 }
 
+/*
+ * Create a constant node for offsetof.
+ */
+tnode_t *
+bldoffsetof(type_t *tp, sym_t *sym)
+{
+       tspec_t st;
+#if SIZEOF_IS_ULONG
+       st = ULONG;
+#else
+       st = UINT;
+#endif
+       tspec_t t = tp->t_tspec;
+       if (t != STRUCT && t != UNION)
+               error(111, "offsetof");
+               
+       // XXX: wrong size, no checking for sym fixme
+       return getinode(st, tsize(tp) / CHAR_BIT);
+}
+
 int64_t
 tsize(type_t *tp)
 {



Home | Main Index | Thread Index | Old Index