* recognize that pointers to identical unnamed and untyped structs,

unions, and enums are, in fact, identical.  This is done by tagging
  each of unnamed and untyped structure, union and enum with a unique
  position of creation, which is used as a unique identifier that
  when determine whether or not a pair of structures, unions, or enums
  are identical.
This commit is contained in:
cgd 1996-12-22 11:31:05 +00:00
parent e8685ee836
commit 0cde55a411
7 changed files with 156 additions and 26 deletions

View File

@ -1,6 +1,7 @@
/* $NetBSD: decl.c,v 1.11 1995/10/02 17:34:16 jpo Exp $ */
/* $NetBSD: decl.c,v 1.12 1996/12/22 11:31:05 cgd Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -32,7 +33,7 @@
*/
#ifndef lint
static char rcsid[] = "$NetBSD: decl.c,v 1.11 1995/10/02 17:34:16 jpo Exp $";
static char rcsid[] = "$NetBSD: decl.c,v 1.12 1996/12/22 11:31:05 cgd Exp $";
#endif
#include <sys/param.h>
@ -1590,7 +1591,7 @@ mktag(tag, kind, decl, semi)
} else {
tag = getblk(sizeof (sym_t));
tag->s_name = unnamed;
STRUCT_ASSIGN(tag->s_dpos, curr_pos);
UNIQUE_CURR_POS(tag->s_dpos);
tag->s_kind = FTAG;
tag->s_scl = scl;
tag->s_blklev = -1;
@ -2786,7 +2787,7 @@ setsflg(sym)
{
if (!sym->s_set) {
sym->s_set = 1;
STRUCT_ASSIGN(sym->s_spos, curr_pos);
UNIQUE_CURR_POS(sym->s_spos);
}
}
@ -2800,7 +2801,7 @@ setuflg(sym, fcall, szof)
{
if (!sym->s_used) {
sym->s_used = 1;
STRUCT_ASSIGN(sym->s_upos, curr_pos);
UNIQUE_CURR_POS(sym->s_upos);
}
/*
* for function calls another record is written

View File

@ -1,6 +1,7 @@
/* $NetBSD: emit1.c,v 1.4 1995/10/02 17:21:28 jpo Exp $ */
/* $NetBSD: emit1.c,v 1.5 1996/12/22 11:31:06 cgd Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -32,7 +33,7 @@
*/
#ifndef lint
static char rcsid[] = "$NetBSD: emit1.c,v 1.4 1995/10/02 17:21:28 jpo Exp $";
static char rcsid[] = "$NetBSD: emit1.c,v 1.5 1996/12/22 11:31:06 cgd Exp $";
#endif
#include <ctype.h>
@ -187,6 +188,10 @@ static void
outtt(tag, tdef)
sym_t *tag, *tdef;
{
/*
* 0 is no longer used.
*/
if (tag->s_name != unnamed) {
outint(1);
outname(tag->s_name);
@ -194,7 +199,12 @@ outtt(tag, tdef)
outint(2);
outname(tdef->s_name);
} else {
outint(0);
outint(3);
outint(tag->s_dpos.p_line);
outchar('.');
outint(getfnid(tag->s_dpos.p_file));
outchar('.');
outint(tag->s_dpos.p_uniq);
}
}

View File

@ -1,6 +1,7 @@
/* $NetBSD: lint1.h,v 1.6 1995/10/02 17:31:41 jpo Exp $ */
/* $NetBSD: lint1.h,v 1.7 1996/12/22 11:31:07 cgd Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -40,8 +41,18 @@
typedef struct {
int p_line;
const char *p_file;
int p_uniq; /* uniquifier */
} pos_t;
/* Copies curr_pos, keeping things unique. */
#define UNIQUE_CURR_POS(pos) \
do { \
STRUCT_ASSIGN((pos), curr_pos); \
curr_pos.p_uniq++; \
if (curr_pos.p_file == csrc_pos.p_file) \
csrc_pos.p_uniq++; \
} while (0)
/*
* Strings cannot be referenced to simply by a pointer to its first
* char. This is because strings can contain NUL characters other than the

View File

@ -1,6 +1,7 @@
/* $NetBSD: emit2.c,v 1.2 1995/07/03 21:24:44 cgd Exp $ */
/* $NetBSD: emit2.c,v 1.3 1996/12/22 11:31:08 cgd Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -32,7 +33,7 @@
*/
#ifndef lint
static char rcsid[] = "$NetBSD: emit2.c,v 1.2 1995/07/03 21:24:44 cgd Exp $";
static char rcsid[] = "$NetBSD: emit2.c,v 1.3 1996/12/22 11:31:08 cgd Exp $";
#endif
#include <err.h>
@ -42,6 +43,7 @@ static char rcsid[] = "$NetBSD: emit2.c,v 1.2 1995/07/03 21:24:44 cgd Exp $";
static void outtype __P((type_t *));
static void outdef __P((hte_t *, sym_t *));
static void dumpname __P((hte_t *));
static void outfiles __P(());
/*
* Write type into the output buffer.
@ -105,9 +107,15 @@ outtype(tp)
} else if (tp->t_istynam) {
outint(2);
outname(tp->t_tynam->h_name);
} else {
outint(0);
}
} else if (tp->t_isuniqpos) {
outint(3);
outint(tp->t_uniqpos.p_line);
outchar('.');
outint(tp->t_uniqpos.p_file);
outchar('.');
outint(tp->t_uniqpos.p_uniq);
} else
errx(1, "internal error: outtype() 2");
} else if (ts == FUNC && tp->t_args != NULL) {
na = 0;
for (ap = tp->t_args; *ap != NULL; ap++)
@ -228,9 +236,68 @@ outlib(name)
outchar('s');
outstrg(name);
/*
* print the names of all files references by unnamed
* struct/union/enum declarations.
*/
outfiles();
/* write all definitions with external linkage */
forall(dumpname);
/* close the output */
outclose();
}
/*
* Write out the name of a file referenced by a type.
*/
struct outflist {
short ofl_num;
struct outflist *ofl_next;
};
static struct outflist *outflist;
int
addoutfile(num)
short num;
{
struct outflist *ofl, **pofl;
int i;
ofl = outflist;
pofl = &outflist;
i = 1; /* library is 0 */
while (ofl != NULL) {
if (ofl->ofl_num == num)
break;
pofl = &ofl->ofl_next;
ofl = ofl->ofl_next;
i++;
}
if (ofl == NULL) {
ofl = *pofl = xmalloc(sizeof (struct outflist));
ofl->ofl_num = num;
ofl->ofl_next = NULL;
}
return (i);
}
void
outfiles()
{
struct outflist *ofl;
int i;
for (ofl = outflist, i = 1; ofl != NULL; ofl = ofl->ofl_next, i++) {
/* reset output buffer */
outclr();
outint(i);
outchar('s');
outstrg(fnames[ofl->ofl_num]);
}
}

View File

@ -1,6 +1,7 @@
/* $NetBSD: externs2.h,v 1.2 1995/07/03 21:24:46 cgd Exp $ */
/* $NetBSD: externs2.h,v 1.3 1996/12/22 11:31:09 cgd Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -85,3 +86,4 @@ extern const char *mkpos __P((pos_t *));
* emit2.c
*/
extern void outlib __P((const char *));
extern int addoutfile __P((short));

View File

@ -1,6 +1,7 @@
/* $NetBSD: lint2.h,v 1.2 1995/07/03 21:24:49 cgd Exp $ */
/* $NetBSD: lint2.h,v 1.3 1996/12/22 11:31:10 cgd Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -45,6 +46,7 @@ typedef struct type {
u_int t_proto : 1; /* this is a prototype */
u_int t_istag : 1; /* tag with _t_tag valid */
u_int t_istynam : 1; /* tag with _t_tynam valid */
u_int t_isuniqpos : 1; /* tag with _t_uniqpos valid */
union {
int _t_dim; /* if the type is an ARRAY than this
is the dimension of the array. */
@ -52,6 +54,13 @@ typedef struct type {
t_isenum, STRUCT or UNION */
struct hte *_t_tynam; /* hash table entry of typename if
t_isenum, STRUCT or UNION */
struct {
int p_line;
short p_file;
int p_uniq;
} _t_uniqpos; /* unique position, for untagged
untyped STRUCTs, UNIONS, and ENUMs,
if t_isuniqpos */
struct type **_t_args; /* list of argument types if this
is a prototype */
} t_u;
@ -59,10 +68,11 @@ typedef struct type {
type, type of return value) */
} type_t;
#define t_dim t_u._t_dim
#define t_tag t_u._t_tag
#define t_tynam t_u._t_tynam
#define t_args t_u._t_args
#define t_dim t_u._t_dim
#define t_tag t_u._t_tag
#define t_tynam t_u._t_tynam
#define t_uniqpos t_u._t_uniqpos
#define t_args t_u._t_args
/*
* argument information

View File

@ -1,6 +1,7 @@
/* $NetBSD: read.c,v 1.2 1995/07/03 21:24:59 cgd Exp $ */
/* $NetBSD: read.c,v 1.3 1996/12/22 11:31:10 cgd Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
* Copyright (c) 1994, 1995 Jochen Pohl
* All Rights Reserved.
*
@ -32,7 +33,7 @@
*/
#ifndef lint
static char rcsid[] = "$NetBSD: read.c,v 1.2 1995/07/03 21:24:59 cgd Exp $";
static char rcsid[] = "$NetBSD: read.c,v 1.3 1996/12/22 11:31:10 cgd Exp $";
#endif
#include <stdio.h>
@ -600,8 +601,6 @@ inptype(cp, epp)
case STRUCT:
case UNION:
switch (*cp++) {
case '0':
break;
case '1':
tp->t_istag = 1;
tp->t_tag = hsearch(inpname(cp, &cp), 1);
@ -610,6 +609,19 @@ inptype(cp, epp)
tp->t_istynam = 1;
tp->t_tynam = hsearch(inpname(cp, &cp), 1);
break;
case '3':
tp->t_isuniqpos = 1;
tp->t_uniqpos.p_line = strtol(cp, &eptr, 10);
cp = eptr;
cp++;
/* xlate to 'global' file name. */
tp->t_uniqpos.p_file =
addoutfile(inpfns[strtol(cp, &eptr, 10)]);
cp = eptr;
cp++;
tp->t_uniqpos.p_uniq = strtol(cp, &eptr, 10);
cp = eptr;
break;
}
break;
/* LINTED (enumeration value(s) not handled in switch) */
@ -769,14 +781,31 @@ gettlen(cp, epp)
case STRUCT:
case UNION:
switch (*cp++) {
case '0':
break;
case '1':
(void)inpname(cp, &cp);
break;
case '2':
(void)inpname(cp, &cp);
break;
case '3':
/* unique position: line.file.uniquifier */
(void)strtol(cp, &eptr, 10);
if (cp == eptr)
inperr();
cp = eptr;
if (*cp++ != '.')
inperr();
(void)strtol(cp, &eptr, 10);
if (cp == eptr)
inperr();
cp = eptr;
if (*cp++ != '.')
inperr();
(void)strtol(cp, &eptr, 10);
if (cp == eptr)
inperr();
cp = eptr;
break;
default:
inperr();
}