[Midnightbsd-cvs] src [10778] trunk/usr.bin/xlint/lint1/tree.c: tag
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Jun 9 22:40:46 EDT 2018
Revision: 10778
http://svnweb.midnightbsd.org/src/?rev=10778
Author: laffer1
Date: 2018-06-09 22:40:46 -0400 (Sat, 09 Jun 2018)
Log Message:
-----------
tag
Modified Paths:
--------------
trunk/usr.bin/xlint/lint1/Makefile
trunk/usr.bin/xlint/lint1/cgram.y
trunk/usr.bin/xlint/lint1/decl.c
trunk/usr.bin/xlint/lint1/emit.c
trunk/usr.bin/xlint/lint1/emit1.c
trunk/usr.bin/xlint/lint1/err.c
trunk/usr.bin/xlint/lint1/externs1.h
trunk/usr.bin/xlint/lint1/func.c
trunk/usr.bin/xlint/lint1/init.c
trunk/usr.bin/xlint/lint1/lint.h
trunk/usr.bin/xlint/lint1/lint1.h
trunk/usr.bin/xlint/lint1/main1.c
trunk/usr.bin/xlint/lint1/makeman
trunk/usr.bin/xlint/lint1/mem1.c
trunk/usr.bin/xlint/lint1/op.h
trunk/usr.bin/xlint/lint1/param.h
trunk/usr.bin/xlint/lint1/scan.l
trunk/usr.bin/xlint/lint1/tree.c
Property Changed:
----------------
trunk/usr.bin/xlint/lint1/cgram.y
trunk/usr.bin/xlint/lint1/makeman
trunk/usr.bin/xlint/lint1/scan.l
Modified: trunk/usr.bin/xlint/lint1/Makefile
===================================================================
--- trunk/usr.bin/xlint/lint1/Makefile 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/Makefile 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,5 +1,6 @@
+# $MidnightBSD$
# $NetBSD: Makefile,v 1.3 1995/07/04 01:53:05 cgd Exp $
-# $MidnightBSD$
+# $FreeBSD: stable/10/usr.bin/xlint/lint1/Makefile 291819 2015-12-04 19:16:56Z bdrewery $
PROG= lint1
SRCS= cgram.y scan.l mem1.c mem.c err.c main1.c decl.c tree.c func.c \
@@ -12,7 +13,7 @@
CFLAGS+= -I. -I${.CURDIR}
LINTFLAGS=-aehpz
-BINDIR= /usr/libexec
+BINDIR= ${LIBEXECDIR}
.PATH: ${.CURDIR}/../common
Modified: trunk/usr.bin/xlint/lint1/cgram.y
===================================================================
--- trunk/usr.bin/xlint/lint1/cgram.y 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/cgram.y 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
%{
-/* $NetBSD: cgram.y,v 1.23 2002/01/31 19:36:53 tv Exp $ */
+/* $NetBSD: cgram.y,v 1.40 2008/04/25 17:18:24 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,9 +36,9 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.23 2002/01/31 19:36:53 tv Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.40 2008/04/25 17:18:24 christos Exp $");
#endif
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/xlint/lint1/cgram.y 281168 2015-04-06 19:56:27Z pfg $");
#include <stdlib.h>
#include <string.h>
@@ -65,13 +66,13 @@
*/
static int onowarn = -1;
-static int toicon(tnode_t *);
+static int toicon(tnode_t *, int);
static void idecl(sym_t *, int, sbuf_t *);
static void ignuptorp(void);
#ifdef DEBUG
-static __inline void CLRWFLGS(void);
-static __inline void CLRWFLGS(void)
+static inline void CLRWFLGS(void);
+static inline void CLRWFLGS(void)
{
printf("%s, %d: clear flags %s %d\n", curr_pos.p_file,
curr_pos.p_line, __FILE__, __LINE__);
@@ -79,8 +80,8 @@
onowarn = -1;
}
-static __inline void SAVE(void);
-static __inline void SAVE(void)
+static inline void SAVE(void);
+static inline void SAVE(void)
{
if (onowarn != -1)
abort();
@@ -89,8 +90,8 @@
onowarn = nowarn;
}
-static __inline void RESTORE(void);
-static __inline void RESTORE(void)
+static inline void RESTORE(void);
+static inline void RESTORE(void)
{
if (onowarn != -1) {
nowarn = onowarn;
@@ -107,6 +108,8 @@
#endif
%}
+%expect 1
+
%union {
int y_int;
val_t *y_val;
@@ -118,6 +121,7 @@
tqual_t y_tqual;
type_t *y_type;
tnode_t *y_tnode;
+ range_t y_range;
strg_t *y_strg;
pqinf_t *y_pqinf;
};
@@ -243,6 +247,8 @@
%type <y_sym> parameter_type_list
%type <y_sym> parameter_declaration
%type <y_tnode> expr
+%type <y_tnode> expr_stmnt_val
+%type <y_tnode> expr_stmnt_list
%type <y_tnode> term
%type <y_tnode> func_arg_list
%type <y_op> point_or_arrow
@@ -253,6 +259,8 @@
%type <y_strg> string
%type <y_strg> string2
%type <y_sb> opt_asm_or_symbolrename
+%type <y_range> range
+%type <y_range> lorange
%%
@@ -682,12 +690,12 @@
$$ = $1;
}
| notype_decl T_COLON constant {
- $$ = bitfield($1, toicon($3));
+ $$ = bitfield($1, toicon($3, 1));
}
| {
symtyp = FVFT;
} T_COLON constant {
- $$ = bitfield(NULL, toicon($3));
+ $$ = bitfield(NULL, toicon($3, 1));
}
;
@@ -696,12 +704,12 @@
$$ = $1;
}
| type_decl T_COLON constant {
- $$ = bitfield($1, toicon($3));
+ $$ = bitfield($1, toicon($3, 1));
}
| {
symtyp = FVFT;
} T_COLON constant {
- $$ = bitfield(NULL, toicon($3));
+ $$ = bitfield(NULL, toicon($3, 1));
}
;
@@ -784,7 +792,7 @@
$$ = ename($1, enumval, 1);
}
| ename T_ASSIGN constant {
- $$ = ename($1, toicon($3), 0);
+ $$ = ename($1, toicon($3, 1), 0);
}
;
@@ -849,7 +857,7 @@
$$ = addarray($1, 0, 0);
}
| notype_direct_decl T_LBRACK constant T_RBRACK {
- $$ = addarray($1, 1, toicon($3));
+ $$ = addarray($1, 1, toicon($3, 0));
}
| notype_direct_decl param_list {
$$ = addfunc($1, $2);
@@ -878,7 +886,7 @@
$$ = addarray($1, 0, 0);
}
| type_direct_decl T_LBRACK constant T_RBRACK {
- $$ = addarray($1, 1, toicon($3));
+ $$ = addarray($1, 1, toicon($3, 0));
}
| type_direct_decl param_list {
$$ = addfunc($1, $2);
@@ -914,7 +922,7 @@
$$ = addarray($1, 0, 0);
}
| direct_param_decl T_LBRACK constant T_RBRACK {
- $$ = addarray($1, 1, toicon($3));
+ $$ = addarray($1, 1, toicon($3, 0));
}
| direct_param_decl param_list {
$$ = addfunc($1, $2);
@@ -943,7 +951,7 @@
$$ = addarray($1, 0, 0);
}
| direct_notype_param_decl T_LBRACK constant T_RBRACK {
- $$ = addarray($1, 1, toicon($3));
+ $$ = addarray($1, 1, toicon($3, 0));
}
| direct_notype_param_decl param_list {
$$ = addfunc($1, $2);
@@ -1121,6 +1129,7 @@
expr %prec T_COMMA {
mkinit($1);
}
+ | init_by_name init_expr %prec T_COMMA
| init_lbrace init_expr_list init_rbrace
| init_lbrace init_expr_list T_COMMA init_rbrace
| error
@@ -1131,6 +1140,38 @@
| init_expr_list T_COMMA init_expr
;
+lorange:
+ constant T_ELLIPSE {
+ $$.lo = toicon($1, 1);
+ }
+ ;
+range:
+ constant {
+ $$.lo = toicon($1, 1);
+ $$.hi = $$.lo + 1;
+ }
+ | lorange constant {
+ $$.lo = $1.lo;
+ $$.hi = toicon($2, 1);
+ }
+ ;
+
+init_by_name:
+ T_LBRACK range T_RBRACK T_ASSIGN {
+ if (!Sflag)
+ warning(321);
+ }
+ | point identifier T_ASSIGN {
+ if (!Sflag)
+ warning(313);
+ memberpush($2);
+ }
+ | identifier T_COLON {
+ gnuism(315);
+ memberpush($1);
+ }
+ ;
+
init_lbrace:
T_LBRACE {
initlbr();
@@ -1187,13 +1228,13 @@
$$ = addarray(aname(), 0, 0);
}
| T_LBRACK constant T_RBRACK {
- $$ = addarray(aname(), 1, toicon($2));
+ $$ = addarray(aname(), 1, toicon($2, 0));
}
| direct_abs_decl T_LBRACK T_RBRACK {
$$ = addarray($1, 0, 0);
}
| direct_abs_decl T_LBRACK constant T_RBRACK {
- $$ = addarray($1, 1, toicon($3));
+ $$ = addarray($1, 1, toicon($3, 0));
}
| abs_decl_param_list {
$$ = addfunc(aname(), $1);
@@ -1207,9 +1248,8 @@
}
;
-stmnt:
+non_expr_stmnt:
labeled_stmnt
- | expr_stmnt
| comp_stmnt
| selection_stmnt
| iteration_stmnt
@@ -1217,6 +1257,10 @@
ftflg = 0;
}
| asm_stmnt
+
+stmnt:
+ expr_stmnt
+ | non_expr_stmnt
;
labeled_stmnt:
@@ -1231,7 +1275,12 @@
| T_CASE constant T_COLON {
label(T_CASE, NULL, $2);
ftflg = 1;
- }
+ }
+ | T_CASE constant T_ELLIPSE constant T_COLON {
+ /* XXX: We don't fill all cases */
+ label(T_CASE, NULL, $2);
+ ftflg = 1;
+ }
| T_DEFAULT T_COLON {
label(T_DEFAULT, NULL, NULL);
ftflg = 1;
@@ -1239,11 +1288,11 @@
;
comp_stmnt:
- compstmnt_lbrace declaration_list opt_stmnt_list compstmnt_rbrace
- | compstmnt_lbrace opt_stmnt_list compstmnt_rbrace
+ comp_stmnt_lbrace declaration_list opt_stmnt_list comp_stmnt_rbrace
+ | comp_stmnt_lbrace opt_stmnt_list comp_stmnt_rbrace
;
-compstmnt_lbrace:
+comp_stmnt_lbrace:
T_LBRACE {
blklev++;
mblklev++;
@@ -1251,7 +1300,7 @@
}
;
-compstmnt_rbrace:
+comp_stmnt_rbrace:
T_RBRACE {
popdecl();
freeblk();
@@ -1276,7 +1325,7 @@
expr_stmnt:
expr T_SEMI {
- expr($1, 0, 0);
+ expr($1, 0, 0, 1);
ftflg = 0;
}
| T_SEMI {
@@ -1284,6 +1333,34 @@
}
;
+/*
+ * The following two productions are used to implement
+ * ({ [[decl-list] stmt-list] }).
+ * XXX: This is not well tested.
+ */
+expr_stmnt_val:
+ expr T_SEMI {
+ /* XXX: We should really do that only on the last name */
+ if ($1->tn_op == NAME)
+ $1->tn_sym->s_used = 1;
+ $$ = $1;
+ expr($1, 0, 0, 0);
+ ftflg = 0;
+ }
+ | non_expr_stmnt {
+ $$ = getnode();
+ $$->tn_type = gettyp(VOID);
+ }
+ ;
+
+expr_stmnt_list:
+ expr_stmnt_val
+ | expr_stmnt_list expr_stmnt_val {
+ $$ = $2;
+ }
+ | expr_stmnt_list expr_stmnt_val
+ ;
+
selection_stmnt:
if_without_else {
SAVE();
@@ -1525,6 +1602,26 @@
$2->tn_parn = 1;
$$ = $2;
}
+ | T_LPARN comp_stmnt_lbrace declaration_list expr_stmnt_list {
+ blklev--;
+ mblklev--;
+ initsym = mktempsym(duptyp($4->tn_type));
+ mblklev++;
+ blklev++;
+ gnuism(320);
+ } comp_stmnt_rbrace T_RPARN {
+ $$ = getnnode(initsym, 0);
+ }
+ | T_LPARN comp_stmnt_lbrace expr_stmnt_list {
+ blklev--;
+ mblklev--;
+ initsym = mktempsym($3->tn_type);
+ mblklev++;
+ blklev++;
+ gnuism(320);
+ } comp_stmnt_rbrace T_RPARN {
+ $$ = getnnode(initsym, 0);
+ }
| term T_INCDEC {
$$ = build($2 == INC ? INCAFT : DECAFT, $1, NULL);
}
@@ -1580,6 +1677,14 @@
| T_LPARN type_name T_RPARN term %prec T_UNOP {
$$ = cast($4, $2);
}
+ | T_LPARN type_name T_RPARN %prec T_UNOP {
+ sym_t *tmp = mktempsym($2);
+ idecl(tmp, 1, NULL);
+ } init_lbrace init_expr_list init_rbrace {
+ if (!Sflag)
+ gnuism(319);
+ $$ = getnnode(initsym, 0);
+ }
;
string:
@@ -1620,6 +1725,13 @@
}
;
+point:
+ T_STROP {
+ if ($1 != POINT)
+ error(249);
+ }
+ ;
+
identifier:
T_NAME {
$$ = $1;
@@ -1635,7 +1747,6 @@
int
yyerror(char *msg)
{
-
error(249);
if (++sytxerr >= 5)
norecover();
@@ -1670,13 +1781,13 @@
* expressions, it frees the memory used for the expression.
*/
static int
-toicon(tnode_t *tn)
+toicon(tnode_t *tn, int required)
{
int i;
tspec_t t;
val_t *v;
- v = constant(tn);
+ v = constant(tn, required);
/*
* Abstract declarations are used inside expression. To free
@@ -1721,7 +1832,7 @@
case EXTERN:
if (rename != NULL) {
if (decl->s_rename != NULL)
- lerror("idecl() 1");
+ LERROR("idecl()");
s = getlblk(1, rename->sb_len + 1);
(void)memcpy(s, rename->sb_name, rename->sb_len + 1);
@@ -1749,7 +1860,7 @@
decl1loc(decl, initflg);
break;
default:
- lerror("idecl() 2");
+ LERROR("idecl()");
}
if (initflg && !initerr)
Property changes on: trunk/usr.bin/xlint/lint1/cgram.y
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/xlint/lint1/decl.c
===================================================================
--- trunk/usr.bin/xlint/lint1/decl.c 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/decl.c 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,4 +1,5 @@
-/* $NetBSD: decl.c,v 1.29 2002/01/18 21:01:39 thorpej Exp $ */
+/* $MidnightBSD$ */
+/* $NetBSD: decl.c,v 1.33 2004/06/20 22:20:16 jmc Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -34,9 +35,9 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: decl.c,v 1.29 2002/01/18 21:01:39 thorpej Exp $");
+__RCSID("$NetBSD: decl.c,v 1.33 2004/06/20 22:20:16 jmc Exp $");
#endif
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/xlint/lint1/decl.c 281168 2015-04-06 19:56:27Z pfg $");
#include <sys/param.h>
#include <limits.h>
@@ -197,7 +198,7 @@
tp->t_str->sincompl = ic;
} else {
if (t != ENUM)
- lerror("setcompl() 1");
+ LERROR("setcompl()");
tp->t_enum->eincompl = ic;
}
}
@@ -256,7 +257,7 @@
* something like "typedef int a; int a b;"
* This should not happen with current grammar.
*/
- lerror("addtype()");
+ LERROR("addtype()");
}
dcs->d_type = tp;
return;
@@ -297,7 +298,7 @@
dcs->d_lmod = NOTSPEC;
if (!quadflg)
/* %s C does not support 'long long' */
- (void)gnuism(265, tflag ? "traditional" : "ANSI");
+ (void)c99ism(265, tflag ? "traditional" : "c89");
}
if (dcs->d_type != NULL && dcs->d_type->t_typedef) {
@@ -308,7 +309,7 @@
/* now it can be only a combination of arithmetic types and void */
if (t == SIGNED || t == UNSIGN) {
- /* remeber specifiers "signed" and "unsigned" in dcs->d_smod */
+ /* remember specifiers "signed" and "unsigned" in dcs->d_smod */
if (dcs->d_smod != NOTSPEC)
/*
* more than one "signed" and/or "unsigned"; print
@@ -466,7 +467,7 @@
dcs->d_const = 1;
} else {
if (q != VOLATILE)
- lerror("addqual() 1");
+ LERROR("addqual()");
if (dcs->d_volatile) {
/* duplicate "%s" */
warning(10, "volatile");
@@ -508,13 +509,13 @@
(void)printf("popdecl(%d)\n", (int)dcs->d_ctx);
if (dcs->d_nxt == NULL)
- lerror("popdecl() 1");
+ LERROR("popdecl()");
di = dcs;
dcs = di->d_nxt;
switch (di->d_ctx) {
case EXTERN:
/* there is nothing after external declarations */
- lerror("popdecl() 2");
+ LERROR("popdecl()");
/* NOTREACHED */
case MOS:
case MOU:
@@ -545,7 +546,7 @@
/*
* casts and sizeof
* Append all symbols declared in the abstract declaration
- * to the list of symbols declared in the surounding decl.
+ * to the list of symbols declared in the surrounding decl.
* or block.
* XXX I'm not sure whether they should be removed from the
* symbol table now or later.
@@ -562,7 +563,7 @@
rmsyms(di->d_dlsyms);
break;
default:
- lerror("popdecl() 3");
+ LERROR("popdecl()");
}
free(di);
}
@@ -635,7 +636,7 @@
if (tp != NULL && (t != NOTSPEC || s != NOTSPEC || l != NOTSPEC)) {
/* should never happen */
- lerror("deftyp() 1");
+ LERROR("deftyp()");
}
if (tp == NULL) {
@@ -674,7 +675,7 @@
case VOID:
break;
default:
- lerror("deftyp() 2");
+ LERROR("deftyp()");
}
if (t != INT && t != CHAR && (s != NOTSPEC || l != NOTSPEC)) {
dcs->d_terr = 1;
@@ -712,13 +713,13 @@
if (dcs->d_const && dcs->d_type->t_const) {
if (!dcs->d_type->t_typedef)
- lerror("deftyp() 3");
+ LERROR("deftyp()");
/* typedef already qualified with "%s" */
warning(68, "const");
}
if (dcs->d_volatile && dcs->d_type->t_volatile) {
if (!dcs->d_type->t_typedef)
- lerror("deftyp() 4");
+ LERROR("deftyp()");
/* typedef already qualified with "%s" */
warning(68, "volatile");
}
@@ -777,7 +778,7 @@
switch (tp->t_tspec) {
case FUNC:
/* compiler takes size of function */
- lerror("%s", msgs[12]);
+ LERROR("%s", msgs[12]);
/* NOTREACHED */
case STRUCT:
case UNION:
@@ -796,7 +797,7 @@
default:
elsz = size(tp->t_tspec);
if (elsz <= 0)
- lerror("length()");
+ LERROR("length()");
break;
}
return (elem * elsz);
@@ -831,7 +832,7 @@
}
}
if (a < CHAR_BIT || a > LINT_ALIGN(1) * CHAR_BIT)
- lerror("getbound() 1");
+ LERROR("getbound()");
return (a);
}
@@ -925,7 +926,7 @@
if (dcs->d_ctx == PARG) {
if (sym->s_scl != ABSTRACT) {
if (sym->s_name == unnamed)
- lerror("chktyp()");
+ LERROR("chktyp()");
/* void param cannot have name: %s */
error(61, sym->s_name);
*tpp = gettyp(INT);
@@ -963,12 +964,12 @@
scl_t sc;
if ((sc = dsym->s_scl) != MOS && sc != MOU)
- lerror("decl1str() 1");
+ LERROR("decl1str()");
if (dcs->d_rdcsym != NULL) {
if ((sc = dcs->d_rdcsym->s_scl) != MOS && sc != MOU)
/* should be ensured by storesym() */
- lerror("decl1str() 2");
+ LERROR("decl1str()");
if (dsym->s_styp == dcs->d_rdcsym->s_styp) {
/* duplicate member name: %s */
error(33, dsym->s_name);
@@ -991,11 +992,13 @@
t == SHORT || t == USHORT || t == ENUM) {
if (bitfieldtype_ok == 0) {
if (sflag) {
+ char buf[64];
/*
* bit-field type '%s' invalid in
* ANSI C
*/
- warning(273, tyname(tp));
+ warning(273,
+ tyname(buf, sizeof(buf), tp));
} else if (pflag) {
/* nonportable bit-field type */
warning(34);
@@ -1051,7 +1054,7 @@
if ((sz = length(dsym->s_type, dsym->s_name)) == 0) {
if (t == ARRAY && dsym->s_type->t_dim == 0) {
/* illegal zero sized structure member: %s */
- warning(39, dsym->s_name);
+ c99ism(39, dsym->s_name);
}
}
@@ -1221,12 +1224,12 @@
tp->t_dim = n;
if (n < 0) {
- /* zero or negative array dimension */
- error(20);
+ /* negative array dimension */
+ error(20, n);
n = 0;
} else if (n == 0 && dim) {
- /* zero or negative array dimension */
- warning(20);
+ /* zero array dimension */
+ c99ism(322, dim);
} else if (n == 0 && !dim) {
/* is incomplete type */
setcompl(tp, 1);
@@ -1417,7 +1420,7 @@
} else if (sc == EXTERN) {
sym->s_def = DECL;
} else {
- lerror("dname() 1");
+ LERROR("dname()");
}
break;
case PARG:
@@ -1430,7 +1433,7 @@
sym->s_reg = 1;
sc = AUTO;
} else {
- lerror("dname() 2");
+ LERROR("dname()");
}
sym->s_def = DEF;
break;
@@ -1453,11 +1456,11 @@
} else if (sc == EXTERN) {
sym->s_def = DECL;
} else {
- lerror("dname() 3");
+ LERROR("dname()");
}
break;
default:
- lerror("dname() 4");
+ LERROR("dname()");
}
sym->s_scl = sc;
@@ -1481,7 +1484,7 @@
/* redeclaration of formal parameter %s */
error(21, sym->s_name);
if (!sym->s_defarg)
- lerror("iname()");
+ LERROR("iname()");
}
sym = pushdown(sym);
}
@@ -1514,7 +1517,7 @@
} else if (kind == ENUM) {
scl = ENUMTAG;
} else {
- lerror("mktag()");
+ LERROR("mktag()");
}
if (tag != NULL) {
@@ -1636,7 +1639,7 @@
case STRTAG: s = "struct"; break;
case UNIONTAG: s = "union"; break;
case ENUMTAG: s = "enum"; break;
- default: lerror("tagttoa()");
+ default: LERROR("tagttoa()");
}
return (s);
}
@@ -1664,7 +1667,7 @@
sp->memb = fmem;
if (sp->size == 0) {
/* zero sized %s */
- (void)gnuism(47, ttab[t].tt_name);
+ (void)c99ism(47, ttab[t].tt_name);
} else {
n = 0;
for (mem = fmem; mem != NULL; mem = mem->s_nxt) {
@@ -2143,7 +2146,7 @@
while ((dst = *dstp) != NULL) {
if (src == NULL || dst->t_tspec != src->t_tspec)
- lerror("compltyp() 1");
+ LERROR("compltyp()");
if (dst->t_tspec == ARRAY) {
if (dst->t_dim == 0 && src->t_dim != 0) {
*dstp = dst = duptyp(dst);
@@ -2472,7 +2475,7 @@
*/
break;
default:
- lerror("decl1loc() 1");
+ LERROR("decl1loc()");
}
} else if (dcs->d_rdcsym->s_blklev == blklev) {
@@ -2580,8 +2583,8 @@
}
/*
- * Print an error or a warning if the symbol cant be initialized due
- * to type/storage class. Returnvalue is 1 if an error has been
+ * Print an error or a warning if the symbol can't be initialized due
+ * to type/storage class. Return value is 1 if an error has been
* detected.
*/
static int
@@ -2613,7 +2616,7 @@
}
/*
- * Create a symbole for an abstract declaration.
+ * Create a symbol for an abstract declaration.
*/
sym_t *
aname(void)
@@ -2621,7 +2624,7 @@
sym_t *sym;
if (dcs->d_ctx != ABSTRACT && dcs->d_ctx != PARG)
- lerror("aname()");
+ LERROR("aname()");
sym = getblk(sizeof (sym_t));
@@ -2791,7 +2794,7 @@
{
if (!arg->s_set)
- lerror("chkausg() 1");
+ LERROR("chkausg()");
if (novar)
return;
@@ -2810,7 +2813,7 @@
sym_t *xsym;
if (blklev == 0 || sym->s_blklev == 0)
- lerror("chkvusg() 1");
+ LERROR("chkvusg()");
/* errors in expressions easily cause lots of these warnings */
if (nerr != 0)
@@ -2875,7 +2878,7 @@
{
if (blklev != 1 || lab->s_blklev != 1)
- lerror("chklusg() 1");
+ LERROR("chklusg()");
if (lab->s_set && !lab->s_used) {
STRUCT_ASSIGN(curr_pos, lab->s_spos);
@@ -2895,7 +2898,7 @@
if (!incompl(sym->s_type))
return;
- /* complain alwasy about incomplet tags declared inside blocks */
+ /* complain always about incomplete tags declared inside blocks */
if (!zflag || dcs->d_ctx != EXTERN)
return;
@@ -2914,7 +2917,7 @@
warning(235, sym->s_name);
break;
default:
- lerror("chktusg() 1");
+ LERROR("chktusg()");
}
}
@@ -2946,7 +2949,7 @@
chktusg(sym);
} else {
if (sym->s_kind != FMOS)
- lerror("chkglsyms() 1");
+ LERROR("chkglsyms()");
}
}
@@ -2961,7 +2964,7 @@
return;
if (sym->s_scl != EXTERN && sym->s_scl != STATIC)
- lerror("chkglvar() 1");
+ LERROR("chkglvar()");
glchksz(sym);
Modified: trunk/usr.bin/xlint/lint1/emit.c
===================================================================
--- trunk/usr.bin/xlint/lint1/emit.c 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/emit.c 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: emit.c,v 1.2 1995/07/03 21:24:00 cgd Exp $ */
/*
@@ -30,7 +31,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.bin/xlint/lint1/emit.c 165628 2006-12-29 13:08:46Z yar $
*/
#ifndef lint
Modified: trunk/usr.bin/xlint/lint1/emit1.c
===================================================================
--- trunk/usr.bin/xlint/lint1/emit1.c 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/emit1.c 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,4 +1,5 @@
-/* $NetBSD: emit1.c,v 1.11 2002/01/31 19:36:54 tv Exp $ */
+/* $MidnightBSD$ */
+/* $NetBSD: emit1.c,v 1.14 2004/06/20 22:20:16 jmc Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -34,9 +35,9 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: emit1.c,v 1.11 2002/01/31 19:36:54 tv Exp $");
+__RCSID("$NetBSD: emit1.c,v 1.14 2004/06/20 22:20:16 jmc Exp $");
#endif
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/xlint/lint1/emit1.c 281168 2015-04-06 19:56:27Z pfg $");
#include <ctype.h>
@@ -81,7 +82,7 @@
* 2 n typename only type name
*
* spaces are only for better readability
- * additionaly it is possible to prepend the characters 'c' (for const)
+ * additionally it is possible to prepend the characters 'c' (for const)
* and 'v' (for volatile)
*/
void
@@ -117,7 +118,7 @@
case STRUCT: t = 'T'; s = 's'; break;
case UNION: t = 'T'; s = 'u'; break;
default:
- lerror("outtyp() 1");
+ LERROR("outtyp()");
}
if (tp->t_const)
outchar('c');
@@ -257,7 +258,7 @@
outchar('e');
break;
default:
- lerror("outsym() 2");
+ LERROR("outsym()");
}
if (llibflg && def != DECL) {
/*
@@ -485,7 +486,7 @@
u_char *cp;
if (strg->st_tspec != CHAR)
- lerror("outfstrg() 1");
+ LERROR("outfstrg()");
cp = strg->st_cp;
Modified: trunk/usr.bin/xlint/lint1/err.c
===================================================================
--- trunk/usr.bin/xlint/lint1/err.c 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/err.c 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,4 +1,5 @@
-/* $NetBSD: err.c,v 1.17 2002/01/31 19:36:54 tv Exp $ */
+/* $MidnightBSD$ */
+/* $NetBSD: err.c,v 1.40 2009/04/15 01:20:57 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -33,9 +34,9 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.17 2002/01/31 19:36:54 tv Exp $");
+__RCSID("$NetBSD: err.c,v 1.40 2009/04/15 01:20:57 christos Exp $");
#endif
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/xlint/lint1/err.c 281168 2015-04-06 19:56:27Z pfg $");
#include <sys/types.h>
#include <stdlib.h>
@@ -76,7 +77,7 @@
"null dimension", /* 17 */
"illegal use of 'void'", /* 18 */
"void type for %s", /* 19 */
- "zero or negative array dimension", /* 20 */
+ "negative array dimension (%d)", /* 20 */
"redeclaration of formal parameter %s", /* 21 */
"incomplete or misplaced function definition", /* 22 */
"undefined label %s", /* 23 */
@@ -95,7 +96,7 @@
"illegal bit-field size", /* 36 */
"zero size bit-field", /* 37 */
"function illegal in structure or union", /* 38 */
- "illegal zero sized structure member: %s", /* 39 */
+ "zero sized array in struct is a C99 extension: %s", /* 39 */
"unknown size: %s", /* 40 */
"illegal use of bit-field", /* 41 */
"forward reference to enum type", /* 42 */
@@ -103,7 +104,7 @@
"declaration introduces new type in ANSI C: %s %s", /* 44 */
"base type is really '%s %s'", /* 45 */
"(%s) tag redeclared", /* 46 */
- "zero sized %s", /* 47 */
+ "zero sized %s is a C9X feature", /* 47 */
"overflow in enumeration values: %s", /* 48 */
"struct or union member must be named", /* 49 */
"a function is declared as an argument: %s", /* 50 */
@@ -188,7 +189,7 @@
"expression has null effect", /* 129 */
"enum type mismatch, op %s", /* 130 */
"conversion to '%s' may sign-extend incorrectly", /* 131 */
- "conversion from '%s' may lose accuracy", /* 132 */
+ "conversion from '%s' to '%s' may lose accuracy", /* 132 */
"conversion of pointer to '%s' loses bits", /* 133 */
"conversion of pointer to '%s' may lose bits", /* 134 */
"possible pointer alignment problem", /* 135 */
@@ -232,7 +233,7 @@
"too many array initializers", /* 173 */
"too many initializers", /* 174 */
"initialisation of an incomplete type", /* 175 */
- "invalid initializer", /* 176 */
+ "invalid initializer type %s", /* 176 */
"non-constant initializer", /* 177 */
"initializer does not fit", /* 178 */
"cannot initialize struct/union with no named member", /* 179 */
@@ -354,7 +355,7 @@
"conversion of '%s' to '%s' is out of range, arg #%d", /* 295 */
"conversion of negative constant to unsigned type, arg #%d", /* 296 */
"conversion to '%s' may sign-extend incorrectly, arg #%d", /* 297 */
- "conversion from '%s' may lose accuracy, arg #%d", /* 298 */
+ "conversion from '%s' to '%s' may lose accuracy, arg #%d", /* 298 */
"prototype does not match old style definition, arg #%d", /* 299 */
"old style definition", /* 300 */
"array of incomplete type", /* 301 */
@@ -369,6 +370,16 @@
"symbol renaming can't be used on function arguments", /* 310 */
"symbol renaming can't be used on automatic variables", /* 311 */
"%s C does not support // comments", /* 312 */
+ "struct or union member name in initializer is a C9X feature",/* 313 */
+ "%s is not a structure or a union", /* 314 */
+ "GCC style struct or union member name in initializer", /* 315 */
+ "__FUNCTION__ is a GCC extension", /* 316 */
+ "__func__ is a C9X feature", /* 317 */
+ "variable array dimension is a C99/GCC extension", /* 318 */
+ "compound literals are a C9X/GCC extension", /* 319 */
+ "({ }) is a GCC extension", /* 320 */
+ "array initializer with designators is a C9X feature", /* 321 */
+ "zero sized array is a C99 extension", /* 322 */
};
/*
@@ -377,10 +388,10 @@
void
msglist(void)
{
- int i;
+ size_t i;
for (i = 0; i < sizeof(msgs) / sizeof(msgs[0]); i++)
- printf("%d\t%s\n", i, msgs[i]);
+ printf("%zu\t%s\n", i, msgs[i]);
}
/*
@@ -451,7 +462,7 @@
}
void
-lerror(const char *msg, ...)
+lerror(const char *file, int line, const char *msg, ...)
{
va_list ap;
const char *fn;
@@ -458,7 +469,8 @@
va_start(ap, msg);
fn = lbasename(curr_pos.p_file);
- (void)fprintf(stderr, "%s(%d): lint error: ", fn, curr_pos.p_line);
+ (void)fprintf(stderr, "%s(%d): lint error: %s, %d", fn, curr_pos.p_line,
+ file, line);
(void)vfprintf(stderr, msg, ap);
(void)fprintf(stderr, "\n");
va_end(ap);
@@ -492,7 +504,34 @@
va_end(ap);
}
+/*
+ * XXX I think the logic is possibly somewhat screwed up here. The
+ * question is, how do we want to interpret the -s and -S flags going
+ * forward? We need to answer that and then we can fix this to be
+ * "right"... [perry, 2 Nov 2002]
+*/
int
+c99ism(int n, ...)
+{
+ va_list ap;
+ int msg;
+
+ va_start(ap, n);
+ if (sflag && !(Sflag || gflag)) {
+ verror(n, ap);
+ msg = 1;
+ } else if (!sflag && (Sflag || gflag)) {
+ msg = 0;
+ } else {
+ vwarning(n, ap);
+ msg = 1;
+ }
+ va_end(ap);
+
+ return (msg);
+}
+
+int
gnuism(int n, ...)
{
va_list ap;
Modified: trunk/usr.bin/xlint/lint1/externs1.h
===================================================================
--- trunk/usr.bin/xlint/lint1/externs1.h 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/externs1.h 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,4 +1,5 @@
-/* $NetBSD: externs1.h,v 1.13 2002/01/18 21:01:39 thorpej Exp $ */
+/* $MidnightBSD$ */
+/* $NetBSD: externs1.h,v 1.20 2002/11/02 20:09:27 perry Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -29,6 +30,8 @@
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/usr.bin/xlint/lint1/externs1.h 281168 2015-04-06 19:56:27Z pfg $
*/
/*
@@ -50,6 +53,7 @@
extern int yflag;
extern int wflag;
extern int zflag;
+extern int Sflag;
extern void norecover(void);
@@ -80,6 +84,7 @@
extern sym_t *getsym(sbuf_t *);
extern void cleanup(void);
extern sym_t *pushdown(sym_t *);
+extern sym_t *mktempsym(type_t *);
extern void rmsym(sym_t *);
extern void rmsyms(sym_t *);
extern void inssym(int, sym_t *);
@@ -118,8 +123,9 @@
extern void warning(int, ...);
extern void message(int, ...);
extern int gnuism(int, ...);
-extern void lerror(const char *, ...)
- __attribute__((__noreturn__,__format__(__printf__, 1, 2)));
+extern int c99ism(int, ...);
+extern void lerror(const char *, int, const char *, ...)
+ __attribute__((__noreturn__,__format__(__printf__, 3, 4)));
/*
* decl.c
@@ -194,13 +200,14 @@
extern tnode_t *promote(op_t, int, tnode_t *);
extern tnode_t *convert(op_t, int, type_t *, tnode_t *);
extern void cvtcon(op_t, int, type_t *, val_t *, val_t *);
-extern const char *tyname(type_t *);
+extern const char *tyname(char *, size_t, type_t *);
+extern const char *basictyname(tspec_t);
extern tnode_t *bldszof(type_t *);
extern tnode_t *cast(tnode_t *, type_t *);
extern tnode_t *funcarg(tnode_t *, tnode_t *);
extern tnode_t *funccall(tnode_t *, tnode_t *);
-extern val_t *constant(tnode_t *);
-extern void expr(tnode_t *, int, int);
+extern val_t *constant(tnode_t *, int);
+extern void expr(tnode_t *, int, int, int);
extern void chkmisc(tnode_t *, int, int, int, int, int, int);
extern int conaddr(tnode_t *, sym_t **, ptrdiff_t *);
extern strg_t *catstrg(strg_t *, strg_t *);
@@ -273,6 +280,7 @@
extern void initrbr(void);
extern void initlbr(void);
extern void mkinit(tnode_t *);
+extern void memberpush(sbuf_t *);
/*
* emit.c
Modified: trunk/usr.bin/xlint/lint1/func.c
===================================================================
--- trunk/usr.bin/xlint/lint1/func.c 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/func.c 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,4 +1,5 @@
-/* $NetBSD: func.c,v 1.16 2002/01/03 04:25:15 thorpej Exp $ */
+/* $MidnightBSD$ */
+/* $NetBSD: func.c,v 1.22 2005/09/24 15:30:35 perry Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -35,7 +36,7 @@
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: func.c,v 1.16 2002/01/03 04:25:15 thorpej Exp $");
#endif
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/xlint/lint1/func.c 281168 2015-04-06 19:56:27Z pfg $");
#include <stdlib.h>
#include <string.h>
@@ -59,15 +60,15 @@
int rchflg;
/*
- * In conjunction with reached ontrols printing of "fallthrough on ..."
+ * In conjunction with reached controls printing of "fallthrough on ..."
* warnings.
* Reset by each statement and set by FALLTHROUGH, switch (switch1())
* and case (label()).
*
* Control statements if, for, while and switch do not reset ftflg because
- * this must be done by the controled statement. At least for if this is
+ * this must be done by the controlled statement. At least for if this is
* important because ** FALLTHROUGH ** after "if (expr) stmnt" is evaluated
- * befor the following token, wich causes reduction of above, is read.
+ * before the following token, which causes reduction of above, is read.
* This means that ** FALLTHROUGH ** after "if ..." would always be ignored.
*/
int ftflg;
@@ -107,13 +108,13 @@
pos_t scflpos;
/*
- * Are both plibflg and llibflg set, prototypes are writen as function
+ * Are both plibflg and llibflg set, prototypes are written as function
* definitions to the output file.
*/
int plibflg;
/*
- * Nonzero means that no warnings about constands in conditional
+ * Nonzero means that no warnings about constants in conditional
* context are printed.
*/
int ccflg;
@@ -167,7 +168,7 @@
clst_t *cl;
if (cstk == NULL || cstk->c_env != env)
- lerror("popctrl() 1");
+ LERROR("popctrl()");
cstk = (ci = cstk)->c_nxt;
@@ -220,7 +221,7 @@
for (sym = dcs->d_fpsyms; sym != NULL; sym = sym->s_dlnxt) {
if (sym->s_blklev != -1) {
if (sym->s_blklev != 1)
- lerror("funcdef() 1");
+ LERROR("funcdef()");
inssym(1, sym);
}
}
@@ -264,12 +265,12 @@
for (arg = fsym->s_type->t_args; arg != NULL; arg = arg->s_nxt) {
if (arg->s_scl == ABSTRACT) {
if (arg->s_name != unnamed)
- lerror("funcdef() 2");
+ LERROR("funcdef()");
/* formal parameter lacks name: param #%d */
error(59, n);
} else {
if (arg->s_name == unnamed)
- lerror("funcdef() 3");
+ LERROR("funcdef()");
}
n++;
}
@@ -323,7 +324,7 @@
if (fsym->s_osdef && !fsym->s_type->t_proto) {
if (sflag && hflag && strcmp(fsym->s_name, "main") != 0)
- /* function definition is not a prototyp */
+ /* function definition is not a prototype */
warning(286);
}
@@ -353,7 +354,7 @@
}
/*
- * This warning is printed only if the return value was implizitly
+ * This warning is printed only if the return value was implicitly
* declared to be int. Otherwise the wrong return statement
* has already printed a warning.
*/
@@ -389,7 +390,7 @@
* the symbol table
*/
if (dcs->d_nxt != NULL || dcs->d_ctx != EXTERN)
- lerror("funcend() 1");
+ LERROR("funcend()");
rmsyms(dcs->d_fpsyms);
/* must be set on level 0 */
@@ -446,7 +447,7 @@
if (tn != NULL) {
if (ci->c_swtype == NULL)
- lerror("label() 1");
+ LERROR("label()");
if (reached && !ftflg) {
if (hflag)
@@ -466,7 +467,7 @@
* get the value of the expression and convert it
* to the type of the switch expression
*/
- v = constant(tn);
+ v = constant(tn, 1);
(void) memset(&nv, 0, sizeof nv);
cvtcon(CASE, 0, ci->c_swtype, &nv, v);
free(v);
@@ -532,7 +533,7 @@
tn = cconv(tn);
if (tn != NULL)
tn = promote(NOOP, 0, tn);
- expr(tn, 0, 1);
+ expr(tn, 0, 1, 1);
pushctrl(T_IF);
}
@@ -606,7 +607,7 @@
tp->t_tspec = INT;
}
- expr(tn, 1, 0);
+ expr(tn, 1, 0, 1);
pushctrl(T_SWITCH);
cstk->c_switch = 1;
@@ -627,7 +628,7 @@
clst_t *cl;
if (cstk->c_swtype == NULL)
- lerror("switch2() 1");
+ LERROR("switch2()");
/*
* If the switch expression was of type enumeration, count the case
@@ -637,7 +638,7 @@
if (cstk->c_swtype->t_isenum) {
nenum = nclab = 0;
if (cstk->c_swtype->t_enum == NULL)
- lerror("switch2() 2");
+ LERROR("switch2()");
for (esym = cstk->c_swtype->t_enum->elem;
esym != NULL; esym = esym->s_nxt) {
nenum++;
@@ -704,7 +705,7 @@
}
}
- expr(tn, 0, 1);
+ expr(tn, 0, 1, 1);
}
/*
@@ -775,7 +776,7 @@
}
}
- expr(tn, 0, 1);
+ expr(tn, 0, 1, 1);
/*
* The end of the loop is only reached if it is no endless loop
@@ -818,7 +819,7 @@
STRUCT_ASSIGN(cstk->c_cfpos, csrc_pos);
if (tn1 != NULL)
- expr(tn1, 0, 0);
+ expr(tn1, 0, 0, 1);
if (tn2 != NULL)
tn2 = cconv(tn2);
@@ -830,7 +831,7 @@
tn2 = NULL;
}
if (tn2 != NULL)
- expr(tn2, 0, 1);
+ expr(tn2, 0, 1, 1);
if (tn2 == NULL) {
cstk->c_infinite = 1;
@@ -877,7 +878,7 @@
}
if (tn3 != NULL) {
- expr(tn3, 0, 0);
+ expr(tn3, 0, 0, 1);
} else {
tfreeblk();
}
@@ -1014,7 +1015,7 @@
}
}
- expr(tn, 1, 0);
+ expr(tn, 1, 0, 1);
} else {
Modified: trunk/usr.bin/xlint/lint1/init.c
===================================================================
--- trunk/usr.bin/xlint/lint1/init.c 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/init.c 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,4 +1,5 @@
-/* $NetBSD: init.c,v 1.9 2001/09/18 18:15:54 wiz Exp $ */
+/* $MidnightBSD$ */
+/* $NetBSD: init.c,v 1.10 2002/01/31 19:36:54 tv Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -33,11 +34,13 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.9 2001/09/18 18:15:54 wiz Exp $");
+__RCSID("$NetBSD: init.c,v 1.10 2002/01/31 19:36:54 tv Exp $");
#endif
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/xlint/lint1/init.c 281168 2015-04-06 19:56:27Z pfg $");
+#include <ctype.h>
#include <stdlib.h>
+#include <string.h>
#include "lint1.h"
@@ -54,7 +57,16 @@
/* Points to the top element of the initialisation stack. */
istk_t *initstk;
+typedef struct namlist {
+ const char *n_name;
+ struct namlist *n_prev;
+ struct namlist *n_next;
+} namlist_t;
+/* Points to a c9x named member; */
+namlist_t *namedmem = NULL;
+
+
static void popi2(void);
static void popinit(int);
static void pushinit(void);
@@ -61,8 +73,55 @@
static void testinit(void);
static void nextinit(int);
static int strginit(tnode_t *);
+static void memberpop(void);
+#ifndef DEBUG
+#define DPRINTF(a)
+#else
+#define DPRINTF(a) printf a
+#endif
+void
+memberpush(sb)
+ sbuf_t *sb;
+{
+ namlist_t *nam = xcalloc(1, sizeof (namlist_t));
+ nam->n_name = sb->sb_name;
+ DPRINTF(("memberpush = %s\n", nam->n_name));
+ if (namedmem == NULL) {
+ nam->n_prev = nam->n_next = nam;
+ namedmem = nam;
+ } else {
+ namedmem->n_prev->n_next = nam;
+ nam->n_prev = namedmem->n_prev;
+ nam->n_next = namedmem;
+ namedmem->n_prev = nam;
+ }
+#if 0
+ nam->n_next = namedmem;
+ namedmem = nam;
+#endif
+}
+
+static void
+memberpop()
+{
+ DPRINTF(("memberpop = %s\n", namedmem->n_name));
+ if (namedmem->n_next == namedmem) {
+ free(namedmem);
+ namedmem = NULL;
+ } else {
+ namlist_t *nam = namedmem;
+ namedmem = namedmem->n_next;
+ free(nam);
+ }
+#if 0
+ namedmem = namedmem->n_next;
+ free(nam);
+#endif
+}
+
+
/*
* Initialize the initialisation stack by putting an entry for the variable
* which is to be initialized on it.
@@ -97,12 +156,15 @@
static void
popi2(void)
{
+#ifdef DEBUG
+ char buf[64];
+#endif
istk_t *istk;
sym_t *m;
initstk = (istk = initstk)->i_nxt;
if (initstk == NULL)
- lerror("popi2() 1");
+ LERROR("popi2()");
free(istk);
istk = initstk;
@@ -109,17 +171,38 @@
istk->i_cnt--;
if (istk->i_cnt < 0)
- lerror("popi2() 3");
+ LERROR("popi2()");
+ DPRINTF(("popi2(): %d %s\n", istk->i_cnt,
+ namedmem ? namedmem->n_name : "*null*"));
+ if (istk->i_cnt >= 0 && namedmem != NULL) {
+ DPRINTF(("popi2(): %d %s %s\n", istk->i_cnt,
+ tyname(buf, sizeof(buf), istk->i_type), namedmem->n_name));
+ for (m = istk->i_type->t_str->memb; m != NULL; m = m->s_nxt) {
+ if (m->s_field && m->s_name == unnamed)
+ continue;
+ if (strcmp(m->s_name, namedmem->n_name) == 0) {
+ istk->i_subt = m->s_type;
+ istk->i_cnt++;
+ memberpop();
+ return;
+ }
+ }
+ error(101, namedmem->n_name);
+ memberpop();
+ istk->i_namedmem = 1;
+ return;
+ }
/*
* If the removed element was a structure member, we must go
* to the next structure member.
*/
- if (istk->i_cnt > 0 && istk->i_type->t_tspec == STRUCT) {
+ if (istk->i_cnt > 0 && istk->i_type->t_tspec == STRUCT &&
+ !istk->i_namedmem) {
do {
m = istk->i_mem = istk->i_mem->s_nxt;
if (m == NULL)
- lerror("popi2() 2");
+ LERROR("popi2()");
} while (m->s_field && m->s_name == unnamed);
istk->i_subt = m->s_type;
}
@@ -128,6 +211,7 @@
static void
popinit(int brace)
{
+ DPRINTF(("popinit(%d)\n", brace));
if (brace) {
/*
@@ -154,6 +238,9 @@
static void
pushinit(void)
{
+#ifdef DEBUG
+ char buf[64];
+#endif
istk_t *istk;
int cnt;
sym_t *m;
@@ -162,15 +249,17 @@
/* Extend an incomplete array type by one element */
if (istk->i_cnt == 0) {
+ DPRINTF(("pushinit(extend) %s\n", tyname(buf, sizeof(buf),
+ istk->i_type)));
/*
* Inside of other aggregate types must not be an incomplete
* type.
*/
if (istk->i_nxt->i_nxt != NULL)
- lerror("pushinit() 1");
+ LERROR("pushinit()");
istk->i_cnt = 1;
if (istk->i_type->t_tspec != ARRAY)
- lerror("pushinit() 2");
+ LERROR("pushinit()");
istk->i_type->t_dim++;
/* from now its a complete type */
setcompl(istk->i_type, 0);
@@ -177,20 +266,28 @@
}
if (istk->i_cnt <= 0)
- lerror("pushinit() 3");
+ LERROR("pushinit()");
if (istk->i_type != NULL && issclt(istk->i_type->t_tspec))
- lerror("pushinit() 4");
+ LERROR("pushinit() 4");
initstk = xcalloc(1, sizeof (istk_t));
initstk->i_nxt = istk;
initstk->i_type = istk->i_subt;
if (initstk->i_type->t_tspec == FUNC)
- lerror("pushinit() 5");
+ LERROR("pushinit()");
+again:
istk = initstk;
+ DPRINTF(("pushinit(%s)\n", tyname(buf, sizeof(buf), istk->i_type)));
switch (istk->i_type->t_tspec) {
case ARRAY:
+ if (namedmem) {
+ DPRINTF(("pushinit ARRAY %s\n", namedmem->n_name));
+ free(istk);
+ initstk = initstk->i_nxt;
+ goto again;
+ }
if (incompl(istk->i_type) && istk->i_nxt->i_nxt != NULL) {
/* initialisation of an incomplete type */
error(175);
@@ -200,6 +297,9 @@
istk->i_subt = istk->i_type->t_subt;
istk->i_nolimit = incompl(istk->i_type);
istk->i_cnt = istk->i_type->t_dim;
+ DPRINTF(("elements array %s[%d] %s\n",
+ tyname(buf, sizeof(buf), istk->i_subt), istk->i_cnt,
+ namedmem ? namedmem->n_name : "*none*"));
break;
case UNION:
if (tflag)
@@ -214,14 +314,38 @@
return;
}
cnt = 0;
+ DPRINTF(("2. member lookup %s %s\n",
+ tyname(buf, sizeof(buf), istk->i_type),
+ namedmem ? namedmem->n_name : "*none*"));
for (m = istk->i_type->t_str->memb; m != NULL; m = m->s_nxt) {
if (m->s_field && m->s_name == unnamed)
continue;
+ if (namedmem != NULL) {
+ DPRINTF(("pushinit():[member:%s, looking:%s]\n",
+ m->s_name, namedmem->n_name));
+ if (strcmp(m->s_name, namedmem->n_name) == 0) {
+ cnt++;
+ break;
+ } else
+ continue;
+ }
if (++cnt == 1) {
istk->i_mem = m;
istk->i_subt = m->s_type;
}
}
+ if (namedmem != NULL) {
+ istk->i_namedmem = 1;
+ if (m == NULL) {
+ error(101, namedmem->n_name);
+ initerr = 1;
+ } else {
+ istk->i_mem = m;
+ istk->i_subt = m->s_type;
+ }
+ memberpop();
+ cnt = istk->i_type->t_tspec == STRUCT ? 2 : 1;
+ }
if (cnt == 0) {
/* cannot init. struct/union with no named member */
error(179);
@@ -231,6 +355,12 @@
istk->i_cnt = istk->i_type->t_tspec == STRUCT ? cnt : 1;
break;
default:
+ if (namedmem) {
+ DPRINTF(("pushinit(): pop\n"));
+ free(istk);
+ initstk = initstk->i_nxt;
+ goto again;
+ }
istk->i_cnt = 1;
break;
}
@@ -247,7 +377,7 @@
* If a closing brace is expected we have at least one initializer
* too much.
*/
- if (istk->i_cnt == 0 && !istk->i_nolimit) {
+ if (istk->i_cnt == 0 && !istk->i_nolimit && !istk->i_namedmem) {
switch (istk->i_type->t_tspec) {
case ARRAY:
/* too many array initializers */
@@ -270,7 +400,9 @@
static void
nextinit(int brace)
{
+ char buf[64];
+ DPRINTF(("nextinit(%d)\n", brace));
if (!brace) {
if (initstk->i_type == NULL &&
!issclt(initstk->i_subt->t_tspec)) {
@@ -346,7 +478,11 @@
tnode_t *ln;
struct mbl *tmem;
scl_t sc;
+#ifdef DEBUG
+ char buf[64];
+#endif
+ DPRINTF(("mkinit(%s)\n", tyname(buf, sizeof(buf), tn->tn_type)));
if (initerr || tn == NULL)
goto end;
@@ -353,7 +489,7 @@
sc = initsym->s_scl;
/*
- * Do not test for automatic aggregat initialisation. If the
+ * Do not test for automatic aggregate initialisation. If the
* initializer starts with a brace we have the warning already.
* If not, an error will be printed that the initializer must
* be enclosed by braces.
@@ -369,7 +505,7 @@
ln->tn_type = tduptyp(ln->tn_type);
ln->tn_type->t_const = 0;
tn = build(ASSIGN, ln, tn);
- expr(tn, 0, 0);
+ expr(tn, 0, 0, 1);
goto end;
}
@@ -388,7 +524,7 @@
goto end;
initstk->i_cnt--;
-
+ DPRINTF(("mkinit() cnt=%d tn=%p\n", initstk->i_cnt, tn));
/* Create a temporary node for the left side. */
ln = tgetblk(sizeof (tnode_t));
ln->tn_op = NAME;
@@ -403,7 +539,7 @@
rt = tn->tn_type->t_tspec;
if (!issclt(lt))
- lerror("mkinit() 1");
+ LERROR("mkinit()");
if (!typeok(INIT, 0, ln, tn))
goto end;
@@ -413,7 +549,7 @@
* expr() would free it.
*/
tmem = tsave();
- expr(tn, 1, 0);
+ expr(tn, 1, 0, 1);
trestor(tmem);
if (isityp(lt) && ln->tn_type->t_isfield && !isityp(rt)) {
@@ -444,7 +580,13 @@
}
end:
- tfreeblk();
+ /*
+ * We only free the block, if we are not a compound declaration
+ * We know that the only symbols that start with a digit are the
+ * ones we allocate with mktempsym() for compound declarations
+ */
+ if (!isdigit((unsigned char)initsym->s_name[0]))
+ tfreeblk();
}
@@ -466,7 +608,7 @@
* Check if we have an array type which can be initialized by
* the string.
*/
- if (istk->i_subt->t_tspec == ARRAY) {
+ if (istk->i_subt != NULL && istk->i_subt->t_tspec == ARRAY) {
t = istk->i_subt->t_subt->t_tspec;
if (!((strg->st_tspec == CHAR &&
(t == CHAR || t == UCHAR || t == SCHAR)) ||
Modified: trunk/usr.bin/xlint/lint1/lint.h
===================================================================
--- trunk/usr.bin/xlint/lint1/lint.h 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/lint.h 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: lint.h,v 1.2 1995/07/03 21:24:18 cgd Exp $ */
/*
Modified: trunk/usr.bin/xlint/lint1/lint1.h
===================================================================
--- trunk/usr.bin/xlint/lint1/lint1.h 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/lint1.h 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,4 +1,5 @@
-/* $NetBSD: lint1.h,v 1.12 2002/01/31 19:33:27 tv Exp $ */
+/* $MidnightBSD$ */
+/* $NetBSD: lint1.h,v 1.16 2002/10/21 22:44:08 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -32,7 +33,7 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/xlint/lint1/lint1.h 281168 2015-04-06 19:56:27Z pfg $");
#include "lint.h"
#include "op.h"
@@ -106,7 +107,7 @@
* Structures of type str_t uniqely identify structures. This can't
* be done in structures of type type_t, because these are copied
* if they must be modified. So it would not be possible to check
- * if to structures are identical by comparing the pointers to
+ * if two structures are identical by comparing the pointers to
* the type structures.
*
* The typename is used if the structure is unnamed to identify
@@ -141,7 +142,7 @@
u_int t_const : 1; /* const modifier */
u_int t_volatile : 1; /* volatile modifier */
u_int t_proto : 1; /* function prototype (t_args valid) */
- u_int t_vararg : 1; /* protoype with ... */
+ u_int t_vararg : 1; /* prototype with ... */
u_int t_typedef : 1; /* type defined with typedef */
u_int t_isfield : 1; /* type is bitfield */
u_int t_isenum : 1; /* type is (or was) enum (t_enum valid) */
@@ -221,7 +222,7 @@
u_int s_reg : 1; /* symbol is register variable */
u_int s_defarg : 1; /* undefined symbol in old style function
definition */
- u_int s_rimpl : 1; /* return value of function implizit decl. */
+ u_int s_rimpl : 1; /* return value of function implicit decl. */
u_int s_osdef : 1; /* symbol stems from old style function def. */
u_int s_inline : 1; /* true if this is an inline function */
struct sym *s_xsym; /* for local declared external symbols pointer
@@ -347,6 +348,7 @@
type_t *i_subt; /* type of next level */
u_int i_brace : 1; /* need } for pop */
u_int i_nolimit : 1; /* incomplete array type */
+ u_int i_namedmem : 1; /* has c9x named members */
sym_t *i_mem; /* next structure member */
int i_cnt; /* # of remaining elements */
struct istk *i_nxt; /* previous level */
@@ -396,6 +398,11 @@
struct cstk *c_nxt; /* outer control statement */
} cstk_t;
+typedef struct {
+ size_t lo;
+ size_t hi;
+} range_t;
+
#include "externs1.h"
#define ERR_SETSIZE 1024
@@ -413,4 +420,6 @@
((p)->errs_bits[(n)/__NERRBITS] & (1 << ((n) % __NERRBITS)))
#define ERR_ZERO(p) (void)memset((p), 0, sizeof(*(p)))
+#define LERROR(fmt, args...) lerror(__FILE__, __LINE__, fmt, ##args)
+
extern err_set msgset;
Modified: trunk/usr.bin/xlint/lint1/main1.c
===================================================================
--- trunk/usr.bin/xlint/lint1/main1.c 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/main1.c 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,4 +1,5 @@
-/* $NetBSD: main1.c,v 1.11 2002/01/29 02:43:38 tv Exp $ */
+/* $MidnightBSD$ */
+/* $NetBSD: main1.c,v 1.17 2006/11/08 18:31:15 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -33,9 +34,9 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: main1.c,v 1.11 2002/01/29 02:43:38 tv Exp $");
+__RCSID("$NetBSD: main1.c,v 1.17 2006/11/08 18:31:15 christos Exp $");
#endif
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/xlint/lint1/main1.c 281168 2015-04-06 19:56:27Z pfg $");
#include <sys/types.h>
#include <stdio.h>
@@ -53,7 +54,7 @@
/*
* Print warnings if an assignment of an integertype to another integertype
- * causes an implizit narrowing conversion. If aflag is 1, these warnings
+ * causes an implicit narrowing conversion. If aflag is 1, these warnings
* are printed only if the source type is at least as wide as long. If aflag
* is greater than 1, they are always printed.
*/
@@ -101,6 +102,8 @@
/* Traditional C mode. */
int tflag;
+/* Enable C9X extensions */
+int Sflag;
/*
* Complain about functions and external variables used and not defined,
* or defined and not used.
@@ -126,7 +129,7 @@
char *ptr;
ERR_ZERO(&msgset);
- while ((c = getopt(argc, argv, "abcdeghmprstuvwyzFX:")) != -1) {
+ while ((c = getopt(argc, argv, "abcdeghmprstuvwyzFSX:")) != -1) {
switch (c) {
case 'a': aflag++; break;
case 'b': bflag = 1; break;
@@ -139,6 +142,7 @@
case 'p': pflag = 1; break;
case 'r': rflag = 1; break;
case 's': sflag = 1; break;
+ case 'S': Sflag = 1; break;
case 't': tflag = 1; break;
case 'u': uflag = 0; break;
case 'w': wflag = 1; break;
@@ -154,7 +158,10 @@
for (ptr = strtok(optarg, ","); ptr;
ptr = strtok(NULL, ",")) {
char *eptr;
- long msg = strtol(ptr, &eptr, 0);
+ long msg;
+
+ errno = 0;
+ msg = strtol(ptr, &eptr, 0);
if ((msg == LONG_MIN || msg == LONG_MAX) &&
errno == ERANGE)
err(1, "invalid error message id '%s'",
@@ -197,7 +204,9 @@
/* Following warnings cannot be suppressed by LINTED */
nowarn = 0;
-
+#ifdef DEBUG
+ printf("%s, %d: nowarn = 0\n", curr_pos.p_file, curr_pos.p_line);
+#endif
chkglsyms();
outclose();
@@ -209,7 +218,7 @@
usage(void)
{
(void)fprintf(stderr,
- "usage: lint1 [-abcdeghmprstuvwyzF] [-X <id>[,<id>]... src dest\n");
+ "usage: lint1 [-abcdeghmprstuvwyzFS] [-X <id>[,<id>]... src dest\n");
exit(1);
}
Modified: trunk/usr.bin/xlint/lint1/makeman
===================================================================
--- trunk/usr.bin/xlint/lint1/makeman 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/makeman 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,5 +1,5 @@
#!/bin/sh
-# $NetBSD$
+# $MidnightBSD$
#
# Copyright (c) 2000 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -46,13 +46,6 @@
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the NetBSD
-.\" Foundation, Inc. and its contributors.
-.\" 4. Neither the name of The NetBSD Foundation nor the names of its
-.\" contributors may be used to endorse or promote products derived
-.\" from this software without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -66,7 +59,7 @@
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/usr.bin/xlint/lint1/makeman 281168 2015-04-06 19:56:27Z pfg $
.\"
.Dd July 5, 2000
.Dt LINT 7
@@ -81,7 +74,7 @@
.Fl X
flag of
.Xr lint 1 .
-.Bl -column -offset indent "Id#" "Message"
+.Bl -column -offset indent "XXXX"
__EOF
"$@" | sed -e 's/\\/\\e/g' -e "s/'/\\'/"
echo ".El"
Property changes on: trunk/usr.bin/xlint/lint1/makeman
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/xlint/lint1/mem1.c
===================================================================
--- trunk/usr.bin/xlint/lint1/mem1.c 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/mem1.c 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: mem1.c,v 1.7 2002/01/31 19:36:54 tv Exp $ */
/*
@@ -35,7 +36,7 @@
#if defined(__RCSID) && !defined(lint)
__RCSID("$NetBSD: mem1.c,v 1.7 2002/01/31 19:36:54 tv Exp $");
#endif
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/xlint/lint1/mem1.c 228992 2011-12-30 11:02:40Z uqs $");
#include <sys/types.h>
#include <sys/mman.h>
@@ -133,7 +134,7 @@
/*
* Memory for declarations and other things which must be available
* until the end of a block (or the end of the translation unit)
- * are assoziated with the level (mblklev) of the block (or wiht 0).
+ * are associated with the level (mblklev) of the block (or with 0).
* Because these memory is allocated in large blocks associated with
* a given level it can be freed easily at the end of a block.
*/
Modified: trunk/usr.bin/xlint/lint1/op.h
===================================================================
--- trunk/usr.bin/xlint/lint1/op.h 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/op.h 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: op.h,v 1.2 1995/07/03 21:24:27 cgd Exp $ */
/*
Modified: trunk/usr.bin/xlint/lint1/param.h
===================================================================
--- trunk/usr.bin/xlint/lint1/param.h 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/param.h 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $NetBSD: param.h,v 1.4 1995/07/23 18:14:41 ragge Exp $ */
/*
@@ -30,7 +31,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/usr.bin/xlint/lint1/param.h 177927 2008-04-04 21:35:13Z imp $
*/
/*
Modified: trunk/usr.bin/xlint/lint1/scan.l
===================================================================
--- trunk/usr.bin/xlint/lint1/scan.l 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/scan.l 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
%{
-/* $NetBSD: scan.l,v 1.26 2002/01/31 22:30:21 tv Exp $ */
+/* $NetBSD: scan.l,v 1.37 2007/02/06 00:08:31 he Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,9 +36,9 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: scan.l,v 1.26 2002/01/31 22:30:21 tv Exp $");
+__RCSID("$NetBSD: scan.l,v 1.37 2007/02/06 00:08:31 he Exp $");
#endif
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/xlint/lint1/scan.l 281168 2015-04-06 19:56:27Z pfg $");
#include <stdlib.h>
#include <string.h>
@@ -52,7 +53,6 @@
#include "cgram.h"
#define CHAR_MASK (~(~0 << CHAR_BIT))
-#define YY_NO_UNPUT
/* Current position (its also updated when an included file is parsed) */
pos_t curr_pos = { 1, "", 0 };
@@ -86,6 +86,8 @@
%}
+%option nounput
+
L [_A-Za-z]
D [0-9]
NZD [1-9]
@@ -95,12 +97,13 @@
%%
-{L}({L}|{D})* return (name());
+{L}({L}|{D})* return (name());
0{OD}*[lLuU]* return (icon(8));
{NZD}{D}*[lLuU]* return (icon(10));
0[xX]{HD}+[lLuU]* return (icon(16));
{D}+\.{D}*{EX}?[fFlL]? |
{D}+{EX}[fFlL]? |
+0[xX]{HD}+p{HD}+[fFlL]? |
\.{D}+{EX}?[fFlL]? return (fcon());
"=" return (operator(T_ASSIGN, ASSIGN));
"*=" return (operator(T_OPASS, MULASS));
@@ -190,55 +193,56 @@
scl_t kw_scl; /* storage class if kw_token T_SCLASS */
tspec_t kw_tspec; /* type spec. if kw_token T_TYPE or T_SOU */
tqual_t kw_tqual; /* type qual. fi kw_token T_QUAL */
- u_int kw_stdc : 1; /* STDC keyword */
- u_int kw_gcc : 1; /* GCC keyword */
+ u_int kw_c89; /* c89 keyword */
+ u_int kw_c99; /* c99 keyword */
+ u_int kw_gcc; /* GCC keyword */
} kwtab[] = {
- { "asm", T_ASM, 0, 0, 0, 0, 1 },
- { "__asm", T_ASM, 0, 0, 0, 0, 0 },
- { "__asm__", T_ASM, 0, 0, 0, 0, 0 },
- { "auto", T_SCLASS, AUTO, 0, 0, 0, 0 },
- { "break", T_BREAK, 0, 0, 0, 0, 0 },
- { "case", T_CASE, 0, 0, 0, 0, 0 },
- { "char", T_TYPE, 0, CHAR, 0, 0, 0 },
- { "const", T_QUAL, 0, 0, CONST, 1, 0 },
- { "__const__", T_QUAL, 0, 0, CONST, 0, 0 },
- { "__const", T_QUAL, 0, 0, CONST, 0, 0 },
- { "continue", T_CONTINUE, 0, 0, 0, 0, 0 },
- { "default", T_DEFAULT, 0, 0, 0, 0, 0 },
- { "do", T_DO, 0, 0, 0, 0, 0 },
- { "double", T_TYPE, 0, DOUBLE, 0, 0, 0 },
- { "else", T_ELSE, 0, 0, 0, 0, 0 },
- { "enum", T_ENUM, 0, 0, 0, 0, 0 },
- { "extern", T_SCLASS, EXTERN, 0, 0, 0, 0 },
- { "float", T_TYPE, 0, FLOAT, 0, 0, 0 },
- { "for", T_FOR, 0, 0, 0, 0, 0 },
- { "goto", T_GOTO, 0, 0, 0, 0, 0 },
- { "if", T_IF, 0, 0, 0, 0, 0 },
- { "inline", T_SCLASS, INLINE, 0, 0, 0, 1 },
- { "__inline__", T_SCLASS, INLINE, 0, 0, 0, 0 },
- { "__inline", T_SCLASS, INLINE, 0, 0, 0, 0 },
- { "int", T_TYPE, 0, INT, 0, 0, 0 },
- { "__symbolrename", T_SYMBOLRENAME, 0, 0, 0, 0, 0 },
- { "long", T_TYPE, 0, LONG, 0, 0, 0 },
- { "register", T_SCLASS, REG, 0, 0, 0, 0 },
- { "return", T_RETURN, 0, 0, 0, 0, 0 },
- { "short", T_TYPE, 0, SHORT, 0, 0, 0 },
- { "signed", T_TYPE, 0, SIGNED, 0, 1, 0 },
- { "__signed__", T_TYPE, 0, SIGNED, 0, 0, 0 },
- { "__signed", T_TYPE, 0, SIGNED, 0, 0, 0 },
- { "sizeof", T_SIZEOF, 0, 0, 0, 0, 0 },
- { "static", T_SCLASS, STATIC, 0, 0, 0, 0 },
- { "struct", T_SOU, 0, STRUCT, 0, 0, 0 },
- { "switch", T_SWITCH, 0, 0, 0, 0, 0 },
- { "typedef", T_SCLASS, TYPEDEF, 0, 0, 0, 0 },
- { "union", T_SOU, 0, UNION, 0, 0, 0 },
- { "unsigned", T_TYPE, 0, UNSIGN, 0, 0, 0 },
- { "void", T_TYPE, 0, VOID, 0, 0, 0 },
- { "volatile", T_QUAL, 0, 0, VOLATILE, 1, 0 },
- { "__volatile__", T_QUAL, 0, 0, VOLATILE, 0, 0 },
- { "__volatile", T_QUAL, 0, 0, VOLATILE, 0, 0 },
- { "while", T_WHILE, 0, 0, 0, 0, 0 },
- { NULL, 0, 0, 0, 0, 0, 0 }
+ { "asm", T_ASM, 0, 0, 0, 0, 0, 1 },
+ { "__asm", T_ASM, 0, 0, 0, 0, 0, 0 },
+ { "__asm__", T_ASM, 0, 0, 0, 0, 0, 0 },
+ { "auto", T_SCLASS, AUTO, 0, 0, 0, 0, 0 },
+ { "break", T_BREAK, 0, 0, 0, 0, 0, 0 },
+ { "case", T_CASE, 0, 0, 0, 0, 0, 0 },
+ { "char", T_TYPE, 0, CHAR, 0, 0, 0, 0 },
+ { "const", T_QUAL, 0, 0, CONST, 1, 0, 0 },
+ { "__const__", T_QUAL, 0, 0, CONST, 0, 0, 0 },
+ { "__const", T_QUAL, 0, 0, CONST, 0, 0, 0 },
+ { "continue", T_CONTINUE, 0, 0, 0, 0, 0, 0 },
+ { "default", T_DEFAULT, 0, 0, 0, 0, 0, 0 },
+ { "do", T_DO, 0, 0, 0, 0, 0, 0 },
+ { "double", T_TYPE, 0, DOUBLE, 0, 0, 0, 0 },
+ { "else", T_ELSE, 0, 0, 0, 0, 0, 0 },
+ { "enum", T_ENUM, 0, 0, 0, 0, 0, 0 },
+ { "extern", T_SCLASS, EXTERN, 0, 0, 0, 0, 0 },
+ { "float", T_TYPE, 0, FLOAT, 0, 0, 0, 0 },
+ { "for", T_FOR, 0, 0, 0, 0, 0, 0 },
+ { "goto", T_GOTO, 0, 0, 0, 0, 0, 0 },
+ { "if", T_IF, 0, 0, 0, 0, 0, 0 },
+ { "inline", T_SCLASS, INLINE, 0, 0, 0, 1, 0 },
+ { "__inline__", T_SCLASS, INLINE, 0, 0, 0, 0, 0 },
+ { "__inline", T_SCLASS, INLINE, 0, 0, 0, 0, 0 },
+ { "int", T_TYPE, 0, INT, 0, 0, 0, 0 },
+ { "__symbolrename", T_SYMBOLRENAME, 0, 0, 0, 0, 0, 0 },
+ { "long", T_TYPE, 0, LONG, 0, 0, 0, 0 },
+ { "register", T_SCLASS, REG, 0, 0, 0, 0, 0 },
+ { "return", T_RETURN, 0, 0, 0, 0, 0, 0 },
+ { "short", T_TYPE, 0, SHORT, 0, 0, 0, 0 },
+ { "signed", T_TYPE, 0, SIGNED, 0, 1, 0, 0 },
+ { "__signed__", T_TYPE, 0, SIGNED, 0, 0, 0, 0 },
+ { "__signed", T_TYPE, 0, SIGNED, 0, 0, 0, 0 },
+ { "sizeof", T_SIZEOF, 0, 0, 0, 0, 0, 0 },
+ { "static", T_SCLASS, STATIC, 0, 0, 0, 0, 0 },
+ { "struct", T_SOU, 0, STRUCT, 0, 0, 0, 0 },
+ { "switch", T_SWITCH, 0, 0, 0, 0, 0, 0 },
+ { "typedef", T_SCLASS, TYPEDEF, 0, 0, 0, 0, 0 },
+ { "union", T_SOU, 0, UNION, 0, 0, 0, 0 },
+ { "unsigned", T_TYPE, 0, UNSIGN, 0, 0, 0, 0 },
+ { "void", T_TYPE, 0, VOID, 0, 0, 0, 0 },
+ { "volatile", T_QUAL, 0, 0, VOLATILE, 1, 0, 0 },
+ { "__volatile__", T_QUAL, 0, 0, VOLATILE, 0, 0, 0 },
+ { "__volatile", T_QUAL, 0, 0, VOLATILE, 0, 0, 0 },
+ { "while", T_WHILE, 0, 0, 0, 0, 0, 0 },
+ { NULL, 0, 0, 0, 0, 0, 0, 0 }
};
/* Symbol table */
@@ -273,8 +277,10 @@
uint64_t uq;
for (kw = kwtab; kw->kw_name != NULL; kw++) {
- if (kw->kw_stdc && tflag)
+ if ((kw->kw_c89 || kw->kw_c99) && tflag)
continue;
+ if (kw->kw_c99 && !(Sflag || gflag))
+ continue;
if (kw->kw_gcc && !gflag)
continue;
sym = getblk(sizeof (sym_t));
@@ -399,7 +405,7 @@
if (sym != NULL) {
if (blklev < sym->s_blklev)
- lerror("name() 1");
+ LERROR("name()");
sb->sb_name = sym->s_name;
sb->sb_len = strlen(sym->s_name);
tok = sym->s_scl == TYPEDEF ? T_TYPENAME : T_NAME;
@@ -507,7 +513,7 @@
uq = strtouq(cp, &eptr, base);
}
if (eptr != cp + len)
- lerror("icon() 1");
+ LERROR("icon()");
if (errno != 0)
/* integer constant out of range */
warning(252);
@@ -523,8 +529,10 @@
/* ok */
} else if (ul <= (unsigned)UINT_MAX && base != 10) {
typ = UINT;
+#if INT_MAX != LONG_MAX
} else if (ul <= LONG_MAX) {
typ = LONG;
+#endif
} else {
typ = ULONG;
}
@@ -680,8 +688,24 @@
errno = 0;
d = strtod(cp, &eptr);
- if (eptr != cp + len)
- lerror("fcon() 1");
+ if (eptr != cp + len) {
+ switch (*eptr) {
+ /*
+ * XXX: non-native non-current strtod() may not handle hex
+ * floats, ignore the rest if we find traces of hex float
+ * syntax...
+ */
+ case 'p':
+ case 'P':
+ case 'x':
+ case 'X':
+ d = 0;
+ errno = 0;
+ break;
+ default:
+ LERROR("fcon()");
+ }
+ }
if (errno != 0)
/* floating-point constant out of range */
warning(248);
@@ -1139,7 +1163,7 @@
{
int c;
- if (sflag < 2 && !gflag)
+ if (!Sflag && !gflag)
/* // comments only supported in C99 */
(void)gnuism(312, tflag ? "traditional" : "ANSI");
@@ -1298,7 +1322,7 @@
if (sym != NULL) {
if (sym->s_kind != symtyp)
- lerror("storesym() 1");
+ LERROR("storesym()");
symtyp = FVFT;
freesb(sb);
return (sym);
@@ -1317,7 +1341,7 @@
while (di->d_nxt != NULL && di->d_nxt->d_nxt != NULL)
di = di->d_nxt;
if (di->d_ctx != AUTO)
- lerror("storesym() 2");
+ LERROR("storesym()");
} else {
sym = getblk(sizeof (sym_t));
sym->s_name = sb->sb_name;
@@ -1343,6 +1367,39 @@
}
/*
+ * Construct a temporary symbol. The symbol starts with a digit, so that
+ * it is illegal.
+ */
+sym_t *
+mktempsym(type_t *t)
+{
+ static int n = 0;
+ int h;
+ char *s = getlblk(blklev, 64);
+ sym_t *sym = getblk(sizeof (sym_t));
+
+ (void)snprintf(s, 64, "%.8d_tmp", n++);
+ h = hash(s);
+
+ sym->s_name = s;
+ sym->s_type = t;
+ sym->s_blklev = blklev;
+ sym->s_scl = AUTO;
+ sym->s_kind = FVFT;
+ sym->s_used = 1;
+ sym->s_set = 1;
+
+ if ((sym->s_link = symtab[h]) != NULL)
+ symtab[h]->s_rlink = &sym->s_link;
+ (symtab[h] = sym)->s_rlink = &symtab[h];
+
+ *dcs->d_ldlsym = sym;
+ dcs->d_ldlsym = &sym->s_dlnxt;
+
+ return sym;
+}
+
+/*
* Remove a symbol forever from the symbol table. s_blklev
* is set to -1 to avoid that the symbol will later be put
* back to the symbol table.
@@ -1390,7 +1447,7 @@
(symtab[h] = sym)->s_rlink = &symtab[h];
sym->s_blklev = bl;
if (sym->s_link != NULL && sym->s_blklev < sym->s_link->s_blklev)
- lerror("inssym()");
+ LERROR("inssym()");
}
/*
@@ -1431,7 +1488,7 @@
h = hash(sym->s_name);
nsym = getblk(sizeof (sym_t));
if (sym->s_blklev > blklev)
- lerror("pushdown()");
+ LERROR("pushdown()");
nsym->s_name = sym->s_name;
UNIQUE_CURR_POS(nsym->s_dpos);
nsym->s_kind = sym->s_kind;
@@ -1468,7 +1525,7 @@
} else if (strg->st_tspec == WCHAR) {
free(strg->st_wcp);
} else {
- lerror("fryylv() 1");
+ LERROR("fryylv()");
}
free(strg);
}
Property changes on: trunk/usr.bin/xlint/lint1/scan.l
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.bin/xlint/lint1/tree.c
===================================================================
--- trunk/usr.bin/xlint/lint1/tree.c 2018-06-10 02:40:14 UTC (rev 10777)
+++ trunk/usr.bin/xlint/lint1/tree.c 2018-06-10 02:40:46 UTC (rev 10778)
@@ -1,4 +1,5 @@
-/* $NetBSD: tree.c,v 1.24 2002/01/31 22:30:20 tv Exp $ */
+/* $MidnightBSD$ */
+/* $NetBSD: tree.c,v 1.45 2008/03/04 02:41:46 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -33,9 +34,9 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.24 2002/01/31 22:30:20 tv Exp $");
+__RCSID("$NetBSD: tree.c,v 1.45 2008/03/04 02:41:46 christos Exp $");
#endif
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/usr.bin/xlint/lint1/tree.c 281168 2015-04-06 19:56:27Z pfg $");
#include <stdlib.h>
#include <string.h>
@@ -302,13 +303,32 @@
*/
sym->s_type = incref(sym->s_type, FUNC);
} else {
- /* %s undefined */
- error(99, sym->s_name);
+ if (!blklev) {
+ /* %s undefined */
+ error(99, sym->s_name);
+ } else {
+ int fixtype;
+ if (strcmp(sym->s_name, "__FUNCTION__") == 0) {
+ gnuism(316);
+ fixtype = 1;
+ } else if (strcmp(sym->s_name, "__func__") == 0) {
+ if (!Sflag)
+ warning(317);
+ fixtype = 1;
+ } else {
+ error(99, sym->s_name);
+ fixtype = 0;
+ }
+ if (fixtype) {
+ sym->s_type = incref(gettyp(CHAR), PTR);
+ sym->s_type->t_const = 1;
+ }
+ }
}
}
if (sym->s_kind != FVFT && sym->s_kind != FMOS)
- lerror("getnnode() 1");
+ LERROR("getnnode()");
n = getnode();
n->tn_type = sym->s_type;
@@ -382,6 +402,7 @@
*/
if (msym->s_scl == NOSCL) {
/* undefined struct/union member: %s */
+ fprintf(stderr, "3. %s\n", msym->s_name);
error(101, msym->s_name);
rmsym(msym);
msym->s_kind = FMOS;
@@ -651,7 +672,7 @@
default:
rtp = mp->m_logop ? gettyp(INT) : ln->tn_type;
if (!mp->m_binary && rn != NULL)
- lerror("build() 1");
+ LERROR("build()");
ntn = mktnode(op, rtp, ln, rn);
break;
}
@@ -757,10 +778,15 @@
mp = &modtab[op];
- if ((lt = (ltp = ln->tn_type)->t_tspec) == PTR)
+ if ((ltp = ln->tn_type) == NULL)
+ LERROR("typeok()");
+
+ if ((lt = ltp->t_tspec) == PTR)
lst = (lstp = ltp->t_subt)->t_tspec;
if (mp->m_binary) {
- if ((rt = (rtp = rn->tn_type)->t_tspec) == PTR)
+ if ((rtp = rn->tn_type) == NULL)
+ LERROR("typeok()");
+ if ((rt = rtp->t_tspec) == PTR)
rst = (rstp = rtp->t_subt)->t_tspec;
}
@@ -1009,8 +1035,10 @@
error(170);
return (0);
}
+ while (rn->tn_op == CVT)
+ rn = rn->tn_left;
if (rn->tn_op != COLON)
- lerror("typeok() 2");
+ LERROR("typeok()");
break;
case COLON:
@@ -1149,9 +1177,9 @@
if (mp->m_badeop &&
(ltp->t_isenum || (mp->m_binary && rtp->t_isenum))) {
chkbeop(op, ln, rn);
- } else if (mp->m_enumop && (ltp->t_isenum && rtp->t_isenum)) {
+ } else if (mp->m_enumop && (ltp->t_isenum && rtp && rtp->t_isenum)) {
chkeop2(op, arg, ln, rn);
- } else if (mp->m_enumop && (ltp->t_isenum || rtp->t_isenum)) {
+ } else if (mp->m_enumop && (ltp->t_isenum || (rtp &&rtp->t_isenum))) {
chkeop1(op, arg, ln, rn);
}
@@ -1409,6 +1437,7 @@
static void
chkeop1(op_t op, int arg, tnode_t *ln, tnode_t *rn)
{
+ char lbuf[64], rbuf[64];
if (!eflag)
return;
@@ -1425,20 +1454,24 @@
return;
}
/* initialisation of '%s' with '%s' */
- warning(277, tyname(ln->tn_type), tyname(rn->tn_type));
+ warning(277, tyname(lbuf, sizeof(lbuf), ln->tn_type),
+ tyname(rbuf, sizeof(rbuf), rn->tn_type));
break;
case FARG:
/* combination of '%s' and '%s', arg #%d */
- warning(278, tyname(ln->tn_type), tyname(rn->tn_type), arg);
+ warning(278, tyname(lbuf, sizeof(lbuf), ln->tn_type),
+ tyname(rbuf, sizeof(rbuf), rn->tn_type), arg);
break;
case RETURN:
/* combination of '%s' and '%s' in return */
- warning(279, tyname(ln->tn_type), tyname(rn->tn_type));
+ warning(279, tyname(lbuf, sizeof(lbuf), ln->tn_type),
+ tyname(rbuf, sizeof(rbuf), rn->tn_type));
break;
default:
/* combination of '%s' and %s, op %s */
- warning(242, tyname(ln->tn_type), tyname(rn->tn_type),
- modtab[op].m_name);
+ warning(242, tyname(lbuf, sizeof(lbuf), ln->tn_type),
+ tyname(rbuf, sizeof(rbuf), rn->tn_type),
+ modtab[op].m_name);
break;
}
}
@@ -1465,7 +1498,7 @@
if (t != FUNC && t != VOID)
ntn->tn_lvalue = 1;
} else {
- lerror("mktnode() 2");
+ LERROR("mktnode()");
}
}
@@ -1503,7 +1536,7 @@
t = INT;
} else {
if (size(INT) != len)
- lerror("promote() 1");
+ LERROR("promote()");
if (isutyp(t)) {
t = UINT;
} else {
@@ -1636,7 +1669,7 @@
tspec_t nt, ot, ost = NOTSPEC;
if (tn->tn_lvalue)
- lerror("convert() 1");
+ LERROR("convert()");
nt = tp->t_tspec;
if ((ot = tn->tn_type->t_tspec) == PTR)
@@ -1682,6 +1715,7 @@
ptconv(int arg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn)
{
tnode_t *ptn;
+ char buf[64];
if (!isatyp(nt) || !isatyp(ot))
return;
@@ -1704,9 +1738,10 @@
if (isftyp(nt) != isftyp(ot) || psize(nt) != psize(ot)) {
/* representation and/or width change */
- if (styp(nt) != SHORT || !isityp(ot) || psize(ot) > psize(INT))
+ if (!isityp(ot) || psize(ot) > psize(INT)) {
/* conversion to '%s' due to prototype, arg #%d */
- warning(259, tyname(tp), arg);
+ warning(259, tyname(buf, sizeof(buf), tp), arg);
+ }
} else if (hflag) {
/*
* they differ in sign or base type (char, short, int,
@@ -1720,7 +1755,7 @@
/* ok */
} else {
/* conversion to '%s' due to prototype, arg #%d */
- warning(259, tyname(tp), arg);
+ warning(259, tyname(buf, sizeof(buf), tp), arg);
}
}
}
@@ -1733,6 +1768,7 @@
static void
iiconv(op_t op, int arg, tspec_t nt, tspec_t ot, type_t *tp, tnode_t *tn)
{
+ char lbuf[64], rbuf[64];
if (tn->tn_op == CON)
return;
@@ -1744,9 +1780,10 @@
/* conversion to %s may sign-extend incorrectly (, arg #%d) */
if (aflag && pflag) {
if (op == FARG) {
- warning(297, tyname(tp), arg);
+ warning(297, tyname(lbuf, sizeof(lbuf), tp),
+ arg);
} else {
- warning(131, tyname(tp));
+ warning(131, tyname(lbuf, sizeof(lbuf), tp));
}
}
}
@@ -1758,9 +1795,14 @@
/* conversion from '%s' may lose accuracy */
if (aflag) {
if (op == FARG) {
- warning(298, tyname(tn->tn_type), arg);
+ warning(298,
+ tyname(rbuf, sizeof(rbuf), tn->tn_type),
+ tyname(lbuf, sizeof(lbuf), tp),
+ arg);
} else {
- warning(132, tyname(tn->tn_type));
+ warning(132,
+ tyname(rbuf, sizeof(rbuf), tn->tn_type),
+ tyname(lbuf, sizeof(lbuf), tp));
}
}
}
@@ -1772,6 +1814,7 @@
static void
piconv(op_t op, tspec_t nt, type_t *tp, tnode_t *tn)
{
+ char buf[64];
if (tn->tn_op == CON)
return;
@@ -1784,10 +1827,10 @@
if (psize(nt) < psize(PTR)) {
if (pflag && size(nt) >= size(PTR)) {
/* conv. of pointer to %s may lose bits */
- warning(134, tyname(tp));
+ warning(134, tyname(buf, sizeof(buf), tp));
} else {
/* conv. of pointer to %s loses bits */
- warning(133, tyname(tp));
+ warning(133, tyname(buf, sizeof(buf), tp));
}
}
}
@@ -1855,6 +1898,7 @@
void
cvtcon(op_t op, int arg, type_t *tp, val_t *nv, val_t *v)
{
+ char lbuf[64], rbuf[64];
tspec_t ot, nt;
ldbl_t max = 0.0, min = 0.0;
int sz, rchk;
@@ -1899,18 +1943,21 @@
case LDOUBLE:
max = LDBL_MAX; min = -LDBL_MAX; break;
default:
- lerror("cvtcon() 1");
+ LERROR("cvtcon()");
}
if (v->v_ldbl > max || v->v_ldbl < min) {
if (nt == LDOUBLE)
- lerror("cvtcon() 2");
+ LERROR("cvtcon()");
if (op == FARG) {
/* conv. of %s to %s is out of rng., arg #%d */
- warning(295, tyname(gettyp(ot)), tyname(tp),
- arg);
+ warning(295, tyname(lbuf, sizeof(lbuf),
+ gettyp(ot)), tyname(rbuf, sizeof(rbuf), tp),
+ arg);
} else {
/* conversion of %s to %s is out of range */
- warning(119, tyname(gettyp(ot)), tyname(tp));
+ warning(119, tyname(lbuf, sizeof(lbuf),
+ gettyp(ot)),
+ tyname(rbuf, sizeof(rbuf), tp));
}
v->v_ldbl = v->v_ldbl > 0 ? max : min;
}
@@ -1988,8 +2035,9 @@
* extra bits set to 0 in conversion
* of '%s' to '%s', op %s
*/
- warning(309, tyname(gettyp(ot)),
- tyname(tp), modtab[op].m_name);
+ warning(309, tyname(lbuf, sizeof(lbuf),
+ gettyp(ot)), tyname(rbuf, sizeof(rbuf), tp),
+ modtab[op].m_name);
} else if (nsz < osz &&
(v->v_quad & xmask) != xmask &&
(v->v_quad & xmask) != 0) {
@@ -2049,11 +2097,14 @@
warning(196);
} else if (op == FARG) {
/* conv. of %s to %s is out of rng., arg #%d */
- warning(295, tyname(gettyp(ot)), tyname(tp),
- arg);
+ warning(295, tyname(lbuf, sizeof(lbuf),
+ gettyp(ot)), tyname(rbuf, sizeof(rbuf), tp),
+ arg);
} else {
/* conversion of %s to %s is out of range */
- warning(119, tyname(gettyp(ot)), tyname(tp));
+ warning(119, tyname(lbuf, sizeof(lbuf),
+ gettyp(ot)),
+ tyname(rbuf, sizeof(rbuf), tp));
}
} else if (nv->v_quad != v->v_quad) {
if (op == ASSIGN && tp->t_isfield) {
@@ -2067,11 +2118,14 @@
warning(196);
} else if (op == FARG) {
/* conv. of %s to %s is out of rng., arg #%d */
- warning(295, tyname(gettyp(ot)), tyname(tp),
- arg);
+ warning(295, tyname(lbuf, sizeof(lbuf),
+ gettyp(ot)), tyname(rbuf, sizeof(rbuf), tp),
+ arg);
} else {
/* conversion of %s to %s is out of range */
- warning(119, tyname(gettyp(ot)), tyname(tp));
+ warning(119, tyname(lbuf, sizeof(lbuf),
+ gettyp(ot)),
+ tyname(rbuf, sizeof(rbuf), tp));
}
}
}
@@ -2119,7 +2173,7 @@
tspec_t lt, rt;
if (ltp->t_tspec != PTR || rtp->t_tspec != PTR)
- lerror("illptrc() 1");
+ LERROR("illptrc()");
lt = ltp->t_subt->t_tspec;
rt = rtp->t_subt->t_tspec;
@@ -2153,7 +2207,7 @@
if ((*tpp)->t_tspec != PTR ||
tp1->t_tspec != PTR || tp2->t_tspec != PTR) {
- lerror("mrgqual()");
+ LERROR("mrgqual()");
}
if ((*tpp)->t_subt->t_const ==
@@ -2182,7 +2236,7 @@
tspec_t t;
if ((t = tp->t_tspec) != STRUCT && t != UNION)
- lerror("conmemb()");
+ LERROR("conmemb()");
for (m = tp->t_str->memb; m != NULL; m = m->s_nxt) {
tp = m->s_type;
if (tp->t_const)
@@ -2196,39 +2250,87 @@
}
const char *
-tyname(type_t *tp)
+basictyname(tspec_t t)
{
+ switch (t) {
+ case CHAR: return "char";
+ case UCHAR: return "unsigned char";
+ case SCHAR: return "signed char";
+ case SHORT: return "short";
+ case USHORT: return "unsigned short";
+ case INT: return "int";
+ case UINT: return "unsigned int";
+ case LONG: return "long";
+ case ULONG: return "unsigned long";
+ case QUAD: return "long long";
+ case UQUAD: return "unsigned long long";
+ case FLOAT: return "float";
+ case DOUBLE: return "double";
+ case LDOUBLE: return "long double";
+ case PTR: return "pointer";
+ case ENUM: return "enum";
+ case STRUCT: return "struct";
+ case UNION: return "union";
+ case FUNC: return "function";
+ case ARRAY: return "array";
+ default:
+ LERROR("basictyname()");
+ return NULL;
+ }
+}
+
+const char *
+tyname(char *buf, size_t bufsiz, type_t *tp)
+{
tspec_t t;
const char *s;
+ char lbuf[64];
if ((t = tp->t_tspec) == INT && tp->t_isenum)
t = ENUM;
+ s = basictyname(t);
+
+
switch (t) {
- case CHAR: s = "char"; break;
- case UCHAR: s = "unsigned char"; break;
- case SCHAR: s = "signed char"; break;
- case SHORT: s = "short"; break;
- case USHORT: s = "unsigned short"; break;
- case INT: s = "int"; break;
- case UINT: s = "unsigned int"; break;
- case LONG: s = "long"; break;
- case ULONG: s = "unsigned long"; break;
- case QUAD: s = "long long"; break;
- case UQUAD: s = "unsigned long long"; break;
- case FLOAT: s = "float"; break;
- case DOUBLE: s = "double"; break;
- case LDOUBLE: s = "long double"; break;
- case PTR: s = "pointer"; break;
- case ENUM: s = "enum"; break;
- case STRUCT: s = "struct"; break;
- case UNION: s = "union"; break;
- case FUNC: s = "function"; break;
- case ARRAY: s = "array"; break;
+ case CHAR:
+ case UCHAR:
+ case SCHAR:
+ case SHORT:
+ case USHORT:
+ case INT:
+ case UINT:
+ case LONG:
+ case ULONG:
+ case QUAD:
+ case UQUAD:
+ case FLOAT:
+ case DOUBLE:
+ case LDOUBLE:
+ case FUNC:
+ (void)snprintf(buf, bufsiz, "%s", s);
+ break;
+ case PTR:
+ (void)snprintf(buf, bufsiz, "%s to %s", s,
+ tyname(lbuf, sizeof(lbuf), tp->t_subt));
+ break;
+ case ENUM:
+ (void)snprintf(buf, bufsiz, "%s %s", s,
+ tp->t_enum->etag->s_name);
+ break;
+ case STRUCT:
+ case UNION:
+ (void)snprintf(buf, bufsiz, "%s %s", s,
+ tp->t_str->stag->s_name);
+ break;
+ case ARRAY:
+ (void)snprintf(buf, bufsiz, "%s of %s[%d]", s,
+ tyname(lbuf, sizeof(lbuf), tp->t_subt), tp->t_dim);
+ break;
default:
- lerror("tyname()");
+ LERROR("tyname()");
}
- return (s);
+ return (buf);
}
/*
@@ -2241,11 +2343,11 @@
int nolval;
if (rn->tn_op != NAME)
- lerror("bldstr() 1");
+ LERROR("bldstr()");
if (rn->tn_sym->s_value.v_tspec != INT)
- lerror("bldstr() 2");
+ LERROR("bldstr()");
if (rn->tn_sym->s_scl != MOS && rn->tn_sym->s_scl != MOU)
- lerror("bldstr() 3");
+ LERROR("bldstr()");
/*
* Remember if the left operand is an lvalue (structure members
@@ -2257,7 +2359,7 @@
ln = bldamper(ln, 1);
} else if (ln->tn_type->t_tspec != PTR) {
if (!tflag || !isityp(ln->tn_type->t_tspec))
- lerror("bldstr() 4");
+ LERROR("bldstr()");
ln = convert(NOOP, 0, tincref(gettyp(VOID), PTR), ln);
}
@@ -2292,7 +2394,7 @@
tnode_t *cn, *ntn;
if (ln == NULL)
- lerror("bldincdec() 1");
+ LERROR("bldincdec()");
if (ln->tn_type->t_tspec == PTR) {
cn = plength(ln->tn_type);
@@ -2351,7 +2453,7 @@
if (ln->tn_type->t_tspec == PTR && rn->tn_type->t_tspec != PTR) {
if (!isityp(rn->tn_type->t_tspec))
- lerror("bldplmi() 1");
+ LERROR("bldplmi()");
ctn = plength(ln->tn_type);
if (rn->tn_type->t_tspec != ctn->tn_type->t_tspec)
@@ -2364,7 +2466,7 @@
} else if (rn->tn_type->t_tspec == PTR) {
if (ln->tn_type->t_tspec != PTR || op != MINUS)
- lerror("bldplmi() 2");
+ LERROR("bldplmi()");
#if PTRDIFF_IS_LONG
tp = gettyp(LONG);
#else
@@ -2429,9 +2531,9 @@
} else if (lt == STRUCT || lt == UNION) {
/* Both types must be identical. */
if (rt != STRUCT && rt != UNION)
- lerror("bldcol() 1");
+ LERROR("bldcol()");
if (ln->tn_type->t_str != rn->tn_type->t_str)
- lerror("bldcol() 2");
+ LERROR("bldcol()");
if (incompl(ln->tn_type)) {
/* unknown operand size, op %s */
error(138, modtab[COLON].m_name);
@@ -2452,17 +2554,17 @@
rtp = rn->tn_type;
} else if (lt == PTR && ln->tn_type->t_subt->t_tspec == VOID) {
if (rt != PTR)
- lerror("bldcol() 4");
+ LERROR("bldcol()");
rtp = ln->tn_type;
mrgqual(&rtp, ln->tn_type, rn->tn_type);
} else if (rt == PTR && rn->tn_type->t_subt->t_tspec == VOID) {
if (lt != PTR)
- lerror("bldcol() 5");
+ LERROR("bldcol()");
rtp = rn->tn_type;
mrgqual(&rtp, ln->tn_type, rn->tn_type);
} else {
if (lt != PTR || rt != PTR)
- lerror("bldcol() 6");
+ LERROR("bldcol()");
/*
* XXX For now we simply take the left type. This is
* probably wrong, if one type contains a functionprototype
@@ -2488,7 +2590,7 @@
tnode_t *ntn, *ctn;
if (ln == NULL || rn == NULL)
- lerror("bldasgn() 1");
+ LERROR("bldasgn()");
lt = ln->tn_type->t_tspec;
rt = rn->tn_type->t_tspec;
@@ -2495,7 +2597,7 @@
if ((op == ADDASS || op == SUBASS) && lt == PTR) {
if (!isityp(rt))
- lerror("bldasgn() 2");
+ LERROR("bldasgn()");
ctn = plength(ln->tn_type);
if (rn->tn_type->t_tspec != ctn->tn_type->t_tspec)
rn = convert(NOOP, 0, ctn->tn_type, rn);
@@ -2506,7 +2608,7 @@
if ((op == ASSIGN || op == RETURN) && (lt == STRUCT || rt == STRUCT)) {
if (rt != lt || ln->tn_type->t_str != rn->tn_type->t_str)
- lerror("bldasgn() 3");
+ LERROR("bldasgn()");
if (incompl(ln->tn_type)) {
if (op == RETURN) {
/* cannot return incomplete type */
@@ -2519,12 +2621,13 @@
}
}
- if (op == SHLASS || op == SHRASS) {
- if (rt != INT) {
- rn = convert(NOOP, 0, gettyp(INT), rn);
- rt = INT;
+ if (op == SHLASS) {
+ if (psize(lt) < psize(rt)) {
+ if (hflag)
+ /* semantics of %s change in ANSI C; use ... */
+ warning(118, "<<=");
}
- } else {
+ } else if (op != SHRASS) {
if (op == ASSIGN || lt != PTR) {
if (lt != rt ||
(ln->tn_type->t_isfield && rn->tn_op == CON)) {
@@ -2549,7 +2652,7 @@
tspec_t st;
if (tp->t_tspec != PTR)
- lerror("plength() 1");
+ LERROR("plength()");
tp = tp->t_subt;
elem = 1;
@@ -2586,7 +2689,7 @@
/* cannot do pointer arithmetic on operand of ... */
error(136);
} else if (elsz == -1) {
- lerror("plength() 2");
+ LERROR("plength()");
}
break;
}
@@ -2743,7 +2846,7 @@
q = utyp ? ul | ur : sl | sr;
break;
default:
- lerror("fold() 5");
+ LERROR("fold()");
}
/* XXX does not work for quads. */
@@ -2773,7 +2876,7 @@
nomem();
v->v_tspec = tn->tn_type->t_tspec;
if (tn->tn_type->t_tspec != INT)
- lerror("foldtst() 1");
+ LERROR("foldtst()");
if (isftyp(tn->tn_left->tn_type->t_tspec)) {
l = tn->tn_left->tn_val->v_ldbl != 0.0;
@@ -2803,7 +2906,7 @@
v->v_quad = l || r;
break;
default:
- lerror("foldtst() 1");
+ LERROR("foldtst()");
}
return (getcnode(tn->tn_type, v));
@@ -2824,12 +2927,12 @@
v->v_tspec = t = tn->tn_type->t_tspec;
if (!isftyp(t))
- lerror("foldflt() 1");
+ LERROR("foldflt()");
if (t != tn->tn_left->tn_type->t_tspec)
- lerror("foldflt() 2");
+ LERROR("foldflt()");
if (modtab[tn->tn_op].m_binary && t != tn->tn_right->tn_type->t_tspec)
- lerror("foldflt() 3");
+ LERROR("foldflt()");
l = tn->tn_left->tn_val->v_ldbl;
if (modtab[tn->tn_op].m_binary)
@@ -2885,11 +2988,11 @@
v->v_quad = l != r;
break;
default:
- lerror("foldflt() 4");
+ LERROR("foldflt()");
}
if (isnan((double)v->v_ldbl))
- lerror("foldflt() 5");
+ LERROR("foldflt()");
if (!finite((double)v->v_ldbl) ||
(t == FLOAT &&
(v->v_ldbl > FLT_MAX || v->v_ldbl < -FLT_MAX)) ||
@@ -2962,7 +3065,7 @@
} else {
elsz = size(tp->t_tspec);
if (elsz <= 0)
- lerror("bldszof() 1");
+ LERROR("bldszof()");
}
break;
}
@@ -3199,7 +3302,7 @@
* type, an error message is printed.
*/
val_t *
-constant(tnode_t *tn)
+constant(tnode_t *tn, int required)
{
val_t *v;
@@ -3213,7 +3316,7 @@
if (tn == NULL) {
if (nerr == 0)
- lerror("constant() 1");
+ LERROR("constant()");
v->v_tspec = INT;
v->v_quad = 1;
return (v);
@@ -3223,7 +3326,7 @@
if (tn->tn_op == CON) {
if (tn->tn_type->t_tspec != tn->tn_val->v_tspec)
- lerror("constant() 2");
+ LERROR("constant()");
if (isityp(tn->tn_val->v_tspec)) {
v->v_ansiu = tn->tn_val->v_ansiu;
v->v_quad = tn->tn_val->v_quad;
@@ -3235,7 +3338,10 @@
}
/* integral constant expression expected */
- error(55);
+ if (required)
+ error(55);
+ else
+ c99ism(318);
if (!isityp(v->v_tspec))
v->v_tspec = INT;
@@ -3252,11 +3358,11 @@
* for the expression.
*/
void
-expr(tnode_t *tn, int vctx, int tctx)
+expr(tnode_t *tn, int vctx, int tctx, int freeblk)
{
if (tn == NULL && nerr == 0)
- lerror("expr() 1");
+ LERROR("expr()");
if (tn == NULL) {
tfreeblk();
@@ -3289,7 +3395,8 @@
displexpr(tn, 0);
/* free the tree memory */
- tfreeblk();
+ if (freeblk)
+ tfreeblk();
}
static void
@@ -3361,7 +3468,7 @@
(long)uq & 0xffffffffl);
} else if (tn->tn_op == CON) {
if (tn->tn_type->t_tspec != PTR)
- lerror("displexpr() 1");
+ LERROR("displexpr()");
(void)printf("0x%0*lx ", (int)(sizeof (void *) * CHAR_BIT / 4),
(u_long)tn->tn_val->v_quad);
} else if (tn->tn_op == STRING) {
@@ -3477,7 +3584,7 @@
break;
case CALL:
if (ln->tn_op != AMPER || ln->tn_left->tn_op != NAME)
- lerror("chkmisc() 1");
+ LERROR("chkmisc()");
if (!szof)
outcall(tn, vctx || tctx, rvdisc);
break;
@@ -3632,6 +3739,7 @@
static void
chkcomp(op_t op, tnode_t *ln, tnode_t *rn)
{
+ char buf[64];
tspec_t lt, rt;
mod_t *mp;
@@ -3663,11 +3771,12 @@
rn->tn_op == CON && rn->tn_val->v_quad <= 0) {
if (rn->tn_val->v_quad < 0) {
/* comparison of %s with %s, op %s */
- warning(162, tyname(ln->tn_type), "negative constant",
- mp->m_name);
+ warning(162, tyname(buf, sizeof(buf), ln->tn_type),
+ "negative constant", mp->m_name);
} else if (op == LT || op == GE || (hflag && op == LE)) {
/* comparison of %s with %s, op %s */
- warning(162, tyname(ln->tn_type), "0", mp->m_name);
+ warning(162, tyname(buf, sizeof(buf), ln->tn_type),
+ "0", mp->m_name);
}
return;
}
@@ -3675,11 +3784,12 @@
ln->tn_op == CON && ln->tn_val->v_quad <= 0) {
if (ln->tn_val->v_quad < 0) {
/* comparison of %s with %s, op %s */
- warning(162, "negative constant", tyname(rn->tn_type),
- mp->m_name);
+ warning(162, "negative constant",
+ tyname(buf, sizeof(buf), rn->tn_type), mp->m_name);
} else if (op == GT || op == LE || (hflag && op == GE)) {
/* comparison of %s with %s, op %s */
- warning(162, "0", tyname(rn->tn_type), mp->m_name);
+ warning(162, "0", tyname(buf, sizeof(buf), rn->tn_type),
+ mp->m_name);
}
return;
}
@@ -3689,7 +3799,7 @@
* Takes an expression an returns 0 if this expression can be used
* for static initialisation, otherwise -1.
*
- * Constant initialisation expressions must be costant or an address
+ * Constant initialisation expressions must be constant or an address
* of a static object with an optional offset. In the first case,
* the result is returned in *offsp. In the second case, the static
* object is returned in *symp and the offset in *offsp.
@@ -3707,7 +3817,9 @@
switch (tn->tn_op) {
case MINUS:
- if (tn->tn_right->tn_op != CON)
+ if (tn->tn_right->tn_op == CVT)
+ return conaddr(tn->tn_right, symp, offsp);
+ else if (tn->tn_right->tn_op != CON)
return (-1);
/* FALLTHROUGH */
case PLUS:
@@ -3743,9 +3855,9 @@
case CVT:
t = tn->tn_type->t_tspec;
ot = tn->tn_left->tn_type->t_tspec;
- if ((!isityp(t) && t != PTR) || (!isityp(ot) && ot != PTR)) {
+ if ((!isityp(t) && t != PTR) || (!isityp(ot) && ot != PTR))
return (-1);
- } else if (psize(t) != psize(ot)) {
+ else if (psize(t) != psize(ot)) {
return (-1);
}
if (conaddr(tn->tn_left, symp, offsp) == -1)
More information about the Midnightbsd-cvs
mailing list