Mon Mar 6 23:04:52 2017 UTC ()
Accept PTR for addtype


(christos)
diff -r1.67 -r1.68 src/usr.bin/xlint/lint1/decl.c

cvs diff -r1.67 -r1.68 src/usr.bin/xlint/lint1/decl.c (expand / switch to unified diff)

--- src/usr.bin/xlint/lint1/decl.c 2016/12/27 21:52:35 1.67
+++ src/usr.bin/xlint/lint1/decl.c 2017/03/06 23:04:52 1.68
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: decl.c,v 1.67 2016/12/27 21:52:35 christos Exp $ */ 1/* $NetBSD: decl.c,v 1.68 2017/03/06 23:04:52 christos Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. 4 * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
5 * Copyright (c) 1994, 1995 Jochen Pohl 5 * Copyright (c) 1994, 1995 Jochen Pohl
6 * All Rights Reserved. 6 * All Rights Reserved.
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
11 * 1. Redistributions of source code must retain the above copyright 11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer. 12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright 13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the 14 * notice, this list of conditions and the following disclaimer in the
@@ -28,27 +28,27 @@ @@ -28,27 +28,27 @@
28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */ 33 */
34 34
35#if HAVE_NBTOOL_CONFIG_H 35#if HAVE_NBTOOL_CONFIG_H
36#include "nbtool_config.h" 36#include "nbtool_config.h"
37#endif 37#endif
38 38
39#include <sys/cdefs.h> 39#include <sys/cdefs.h>
40#if defined(__RCSID) && !defined(lint) 40#if defined(__RCSID) && !defined(lint)
41__RCSID("$NetBSD: decl.c,v 1.67 2016/12/27 21:52:35 christos Exp $"); 41__RCSID("$NetBSD: decl.c,v 1.68 2017/03/06 23:04:52 christos Exp $");
42#endif 42#endif
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <limits.h> 45#include <limits.h>
46#include <stdlib.h> 46#include <stdlib.h>
47#include <string.h> 47#include <string.h>
48 48
49#include "lint1.h" 49#include "lint1.h"
50 50
51const char *unnamed = "<unnamed>"; 51const char *unnamed = "<unnamed>";
52 52
53/* shared type structures for arithmtic types and void */ 53/* shared type structures for arithmtic types and void */
54static type_t *typetab; 54static type_t *typetab;
@@ -246,27 +246,27 @@ addscl(scl_t sc) @@ -246,27 +246,27 @@ addscl(scl_t sc)
246 * deftyp() to build the type used for all declarators in this 246 * deftyp() to build the type used for all declarators in this
247 * declaration. 247 * declaration.
248 * 248 *
249 * Is tp->t_typedef 1, the type comes from a previously defined typename. 249 * Is tp->t_typedef 1, the type comes from a previously defined typename.
250 * Otherwise it comes from a type specifier (int, long, ...) or a 250 * Otherwise it comes from a type specifier (int, long, ...) or a
251 * struct/union/enum tag. 251 * struct/union/enum tag.
252 */ 252 */
253void 253void
254addtype(type_t *tp) 254addtype(type_t *tp)
255{ 255{
256 tspec_t t; 256 tspec_t t;
257#ifdef DEBUG 257#ifdef DEBUG
258 char buf[1024]; 258 char buf[1024];
259 printf("addtype %s\n", tyname(buf, sizeof(buf), tp)); 259 printf("%s: %s\n", __func__, tyname(buf, sizeof(buf), tp));
260#endif 260#endif
261 if (tp->t_typedef) { 261 if (tp->t_typedef) {
262 if (dcs->d_type != NULL || dcs->d_atyp != NOTSPEC || 262 if (dcs->d_type != NULL || dcs->d_atyp != NOTSPEC ||
263 dcs->d_lmod != NOTSPEC || dcs->d_smod != NOTSPEC) { 263 dcs->d_lmod != NOTSPEC || dcs->d_smod != NOTSPEC) {
264 /* 264 /*
265 * something like "typedef int a; int a b;" 265 * something like "typedef int a; int a b;"
266 * This should not happen with current grammar. 266 * This should not happen with current grammar.
267 */ 267 */
268 LERROR("addtype()"); 268 LERROR("addtype()");
269 } 269 }
270 dcs->d_type = tp; 270 dcs->d_type = tp;
271 return; 271 return;
272 } 272 }
@@ -345,26 +345,28 @@ addtype(type_t *tp) @@ -345,26 +345,28 @@ addtype(type_t *tp)
345 dcs->d_terr = 1; 345 dcs->d_terr = 1;
346 dcs->d_lmod = t; 346 dcs->d_lmod = t;
347 } else if (t == FLOAT || t == DOUBLE) { 347 } else if (t == FLOAT || t == DOUBLE) {
348 if (dcs->d_lmod == NOTSPEC || dcs->d_lmod == LONG) { 348 if (dcs->d_lmod == NOTSPEC || dcs->d_lmod == LONG) {
349 if (dcs->d_cmod != NOTSPEC 349 if (dcs->d_cmod != NOTSPEC
350 || (t == FLOAT && dcs->d_lmod == LONG)) 350 || (t == FLOAT && dcs->d_lmod == LONG))
351 dcs->d_terr = 1; 351 dcs->d_terr = 1;
352 dcs->d_cmod = t; 352 dcs->d_cmod = t;
353 } else { 353 } else {
354 if (dcs->d_atyp != NOTSPEC) 354 if (dcs->d_atyp != NOTSPEC)
355 dcs->d_terr = 1; 355 dcs->d_terr = 1;
356 dcs->d_atyp = t; 356 dcs->d_atyp = t;
357 } 357 }
 358 } else if (t == PTR) {
 359 dcs->d_type = tp;
358 } else { 360 } else {
359 /* 361 /*
360 * remember specifiers "void", "char", "int", 362 * remember specifiers "void", "char", "int",
361 * or "_Complex" int dcs->d_atyp 363 * or "_Complex" int dcs->d_atyp
362 */ 364 */
363 if (dcs->d_atyp != NOTSPEC) 365 if (dcs->d_atyp != NOTSPEC)
364 /* more than one, print error in deftyp() */ 366 /* more than one, print error in deftyp() */
365 dcs->d_terr = 1; 367 dcs->d_terr = 1;
366 dcs->d_atyp = t; 368 dcs->d_atyp = t;
367 } 369 }
368} 370}
369 371
370/* 372/*
@@ -717,26 +719,30 @@ void @@ -717,26 +719,30 @@ void
717deftyp(void) 719deftyp(void)
718{ 720{
719 tspec_t t, s, l, c; 721 tspec_t t, s, l, c;
720 type_t *tp; 722 type_t *tp;
721 scl_t scl; 723 scl_t scl;
722 724
723 t = dcs->d_atyp; /* BOOL, CHAR, INT, COMPLEX, VOID */ 725 t = dcs->d_atyp; /* BOOL, CHAR, INT, COMPLEX, VOID */
724 s = dcs->d_smod; /* SIGNED, UNSIGNED */ 726 s = dcs->d_smod; /* SIGNED, UNSIGNED */
725 l = dcs->d_lmod; /* SHORT, LONG, QUAD */ 727 l = dcs->d_lmod; /* SHORT, LONG, QUAD */
726 c = dcs->d_cmod; /* FLOAT, DOUBLE */ 728 c = dcs->d_cmod; /* FLOAT, DOUBLE */
727 tp = dcs->d_type; 729 tp = dcs->d_type;
728 scl = dcs->d_scl; 730 scl = dcs->d_scl;
729 731
 732#ifdef DEBUG
 733 char buf[1024];
 734 printf("%s: %s\n", __func__, tyname(buf, sizeof(buf), tp));
 735#endif
730 if (t == NOTSPEC && s == NOTSPEC && l == NOTSPEC && c == NOTSPEC && 736 if (t == NOTSPEC && s == NOTSPEC && l == NOTSPEC && c == NOTSPEC &&
731 tp == NULL) 737 tp == NULL)
732 dcs->d_notyp = 1; 738 dcs->d_notyp = 1;
733 if (t == NOTSPEC && s == NOTSPEC && (l == NOTSPEC || l == LONG) && 739 if (t == NOTSPEC && s == NOTSPEC && (l == NOTSPEC || l == LONG) &&
734 tp == NULL) 740 tp == NULL)
735 t = c; 741 t = c;
736 742
737 if (tp != NULL && (t != NOTSPEC || s != NOTSPEC || l != NOTSPEC)) { 743 if (tp != NULL && (t != NOTSPEC || s != NOTSPEC || l != NOTSPEC)) {
738 /* should never happen */ 744 /* should never happen */
739 LERROR("deftyp()"); 745 LERROR("deftyp()");
740 } 746 }
741 747
742 if (tp == NULL) { 748 if (tp == NULL) {