Module Name: src Committed By: rillig Date: Tue Aug 3 17:44:59 UTC 2021
Modified Files: src/usr.bin/xlint/common: emit.c externs.h tyname.c src/usr.bin/xlint/lint1: tree.c Log Message: lint: clean up and move 'sametype' This function is only used by lint1. That's good since the lint2 code was completely broken, as it would regard any two struct types as being the same. Remove the large switch statement since it is unlikely that there will be new type derivations in C anytime soon. No functional change. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/usr.bin/xlint/common/emit.c cvs rdiff -u -r1.17 -r1.18 src/usr.bin/xlint/common/externs.h cvs rdiff -u -r1.43 -r1.44 src/usr.bin/xlint/common/tyname.c cvs rdiff -u -r1.326 -r1.327 src/usr.bin/xlint/lint1/tree.c 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/common/emit.c diff -u src/usr.bin/xlint/common/emit.c:1.11 src/usr.bin/xlint/common/emit.c:1.12 --- src/usr.bin/xlint/common/emit.c:1.11 Sat Mar 27 11:08:00 2021 +++ src/usr.bin/xlint/common/emit.c Tue Aug 3 17:44:58 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: emit.c,v 1.11 2021/03/27 11:08:00 rillig Exp $ */ +/* $NetBSD: emit.c,v 1.12 2021/08/03 17:44:58 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -37,10 +37,9 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: emit.c,v 1.11 2021/03/27 11:08:00 rillig Exp $"); +__RCSID("$NetBSD: emit.c,v 1.12 2021/08/03 17:44:58 rillig Exp $"); #endif -#include <ctype.h> #include <stdio.h> #include <string.h> Index: src/usr.bin/xlint/common/externs.h diff -u src/usr.bin/xlint/common/externs.h:1.17 src/usr.bin/xlint/common/externs.h:1.18 --- src/usr.bin/xlint/common/externs.h:1.17 Sun Aug 1 18:13:53 2021 +++ src/usr.bin/xlint/common/externs.h Tue Aug 3 17:44:58 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: externs.h,v 1.17 2021/08/01 18:13:53 rillig Exp $ */ +/* $NetBSD: externs.h,v 1.18 2021/08/03 17:44:58 rillig Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -47,7 +47,6 @@ extern void inittyp(void); * tyname.c */ extern const char *type_name(const type_t *); -extern bool sametype(const type_t *, const type_t *); extern const char *tspec_name(tspec_t); /* Index: src/usr.bin/xlint/common/tyname.c diff -u src/usr.bin/xlint/common/tyname.c:1.43 src/usr.bin/xlint/common/tyname.c:1.44 --- src/usr.bin/xlint/common/tyname.c:1.43 Fri Jul 2 18:22:09 2021 +++ src/usr.bin/xlint/common/tyname.c Tue Aug 3 17:44:58 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tyname.c,v 1.43 2021/07/02 18:22:09 rillig Exp $ */ +/* $NetBSD: tyname.c,v 1.44 2021/08/03 17:44:58 rillig Exp $ */ /*- * Copyright (c) 2005 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include <sys/cdefs.h> #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: tyname.c,v 1.43 2021/07/02 18:22:09 rillig Exp $"); +__RCSID("$NetBSD: tyname.c,v 1.44 2021/08/03 17:44:58 rillig Exp $"); #endif #include <limits.h> @@ -59,7 +59,7 @@ __RCSID("$NetBSD: tyname.c,v 1.43 2021/0 /* A tree of strings. */ typedef struct name_tree_node { - char *ntn_name; + const char *ntn_name; struct name_tree_node *ntn_less; struct name_tree_node *ntn_greater; } name_tree_node; @@ -85,7 +85,7 @@ new_name_tree_node(const char *name) return n; } -/* Return the canonical instance of the string, with unlimited life time. */ +/* Return the canonical instance of the string, with unlimited lifetime. */ static const char * intern(const char *name) { @@ -189,70 +189,6 @@ tspec_name(tspec_t t) } } -bool -sametype(const type_t *t1, const type_t *t2) -{ - tspec_t t; - - if (t1->t_tspec != t2->t_tspec) - return false; - - /* Ignore const/volatile */ - - switch (t = t1->t_tspec) { - case BOOL: - case CHAR: - case UCHAR: - case SCHAR: - case SHORT: - case USHORT: - case INT: - case UINT: - case LONG: - case ULONG: - case QUAD: - case UQUAD: -#ifdef INT128_SIZE - case INT128: - case UINT128: -#endif - case FLOAT: - case DOUBLE: - case LDOUBLE: - case VOID: - case FUNC: - case COMPLEX: - case FCOMPLEX: - case DCOMPLEX: - case LCOMPLEX: - return true; - case ARRAY: - if (t1->t_dim != t2->t_dim) - return false; - /*FALLTHROUGH*/ - case PTR: - return sametype(t1->t_subt, t2->t_subt); - case ENUM: -#ifdef t_enum - return strcmp(t1->t_enum->en_tag->s_name, - t2->t_enum->en_tag->s_name) == 0; -#else - return true; -#endif - case STRUCT: - case UNION: -#ifdef t_str - return strcmp(t1->t_str->sou_tag->s_name, - t2->t_str->sou_tag->s_name) == 0; -#else - return true; -#endif - default: - INTERNAL_ERROR("tyname(%d)", t); - return false; - } -} - static void type_name_of_function(buffer *buf, const type_t *tp) { Index: src/usr.bin/xlint/lint1/tree.c diff -u src/usr.bin/xlint/lint1/tree.c:1.326 src/usr.bin/xlint/lint1/tree.c:1.327 --- src/usr.bin/xlint/lint1/tree.c:1.326 Sun Aug 1 19:11:54 2021 +++ src/usr.bin/xlint/lint1/tree.c Tue Aug 3 17:44:59 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.326 2021/08/01 19:11:54 rillig Exp $ */ +/* $NetBSD: tree.c,v 1.327 2021/08/03 17:44:59 rillig 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.326 2021/08/01 19:11:54 rillig Exp $"); +__RCSID("$NetBSD: tree.c,v 1.327 2021/08/03 17:44:59 rillig Exp $"); #endif #include <float.h> @@ -102,6 +102,36 @@ op_name(op_t op) return modtab[op].m_name; } +static bool +sametype(const type_t *t1, const type_t *t2) +{ + + /* Maybe this can be merged into 'eqtype'. */ + + if (t1->t_tspec != t2->t_tspec) + return false; + + /* Ignore const/volatile */ + + switch (t1->t_tspec) { + case ARRAY: + if (t1->t_dim != t2->t_dim) + return false; + /*FALLTHROUGH*/ + case PTR: + return sametype(t1->t_subt, t2->t_subt); + case ENUM: + return strcmp(t1->t_enum->en_tag->s_name, + t2->t_enum->en_tag->s_name) == 0; + case STRUCT: + case UNION: + return strcmp(t1->t_str->sou_tag->s_name, + t2->t_str->sou_tag->s_name) == 0; + default: + return true; + } +} + /* Build 'pointer to tp', 'array of tp' or 'function returning tp'. */ type_t * derive_type(type_t *tp, tspec_t t)