From 8c326659c6d7de0ddbdad1dc9eb71c691f0155a8 Mon Sep 17 00:00:00 2001 From: christos Date: Tue, 22 Oct 2002 13:48:50 +0000 Subject: [PATCH] add variable array dimension. --- usr.bin/xlint/lint1/cgram.y | 32 ++++++++++++++++---------------- usr.bin/xlint/lint1/err.c | 5 +++-- usr.bin/xlint/lint1/externs1.h | 4 ++-- usr.bin/xlint/lint1/func.c | 6 +++--- usr.bin/xlint/lint1/tree.c | 11 +++++++---- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/usr.bin/xlint/lint1/cgram.y b/usr.bin/xlint/lint1/cgram.y index 3d619a1bb313..a4d1355efc88 100644 --- a/usr.bin/xlint/lint1/cgram.y +++ b/usr.bin/xlint/lint1/cgram.y @@ -1,5 +1,5 @@ %{ -/* $NetBSD: cgram.y,v 1.26 2002/10/21 21:14:51 christos Exp $ */ +/* $NetBSD: cgram.y,v 1.27 2002/10/22 13:48:51 christos Exp $ */ /* * Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved. @@ -35,7 +35,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: cgram.y,v 1.26 2002/10/21 21:14:51 christos Exp $"); +__RCSID("$NetBSD: cgram.y,v 1.27 2002/10/22 13:48:51 christos Exp $"); #endif #include @@ -64,7 +64,7 @@ int mblklev; */ 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); @@ -681,12 +681,12 @@ notype_member_decl: $$ = $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)); } ; @@ -695,12 +695,12 @@ type_member_decl: $$ = $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)); } ; @@ -783,7 +783,7 @@ enumerator: $$ = ename($1, enumval, 1); } | ename T_ASSIGN constant { - $$ = ename($1, toicon($3), 0); + $$ = ename($1, toicon($3, 1), 0); } ; @@ -848,7 +848,7 @@ notype_direct_decl: $$ = 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); @@ -877,7 +877,7 @@ type_direct_decl: $$ = 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); @@ -913,7 +913,7 @@ direct_param_decl: $$ = 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); @@ -942,7 +942,7 @@ direct_notype_param_decl: $$ = 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); @@ -1200,13 +1200,13 @@ direct_abs_decl: $$ = 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); @@ -1691,13 +1691,13 @@ q_gt(int64_t a, int64_t b) * 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 diff --git a/usr.bin/xlint/lint1/err.c b/usr.bin/xlint/lint1/err.c index 994a80ff6cd4..395413d22a9d 100644 --- a/usr.bin/xlint/lint1/err.c +++ b/usr.bin/xlint/lint1/err.c @@ -1,4 +1,4 @@ -/* $NetBSD: err.c,v 1.21 2002/10/22 13:31:34 christos Exp $ */ +/* $NetBSD: err.c,v 1.22 2002/10/22 13:48:50 christos Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -33,7 +33,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: err.c,v 1.21 2002/10/22 13:31:34 christos Exp $"); +__RCSID("$NetBSD: err.c,v 1.22 2002/10/22 13:48:50 christos Exp $"); #endif #include @@ -373,6 +373,7 @@ const char *msgs[] = { "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 GCC extension", /* 318 */ }; /* diff --git a/usr.bin/xlint/lint1/externs1.h b/usr.bin/xlint/lint1/externs1.h index 6499257b8b97..30927ace00d5 100644 --- a/usr.bin/xlint/lint1/externs1.h +++ b/usr.bin/xlint/lint1/externs1.h @@ -1,4 +1,4 @@ -/* $NetBSD: externs1.h,v 1.16 2002/10/21 21:14:52 christos Exp $ */ +/* $NetBSD: externs1.h,v 1.17 2002/10/22 13:48:52 christos Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -200,7 +200,7 @@ 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 val_t *constant(tnode_t *, int); extern void expr(tnode_t *, int, int); extern void chkmisc(tnode_t *, int, int, int, int, int, int); extern int conaddr(tnode_t *, sym_t **, ptrdiff_t *); diff --git a/usr.bin/xlint/lint1/func.c b/usr.bin/xlint/lint1/func.c index 374f5ede2c39..ab38442eaa60 100644 --- a/usr.bin/xlint/lint1/func.c +++ b/usr.bin/xlint/lint1/func.c @@ -1,4 +1,4 @@ -/* $NetBSD: func.c,v 1.18 2002/09/13 14:59:24 christos Exp $ */ +/* $NetBSD: func.c,v 1.19 2002/10/22 13:48:50 christos Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -33,7 +33,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: func.c,v 1.18 2002/09/13 14:59:24 christos Exp $"); +__RCSID("$NetBSD: func.c,v 1.19 2002/10/22 13:48:50 christos Exp $"); #endif #include @@ -464,7 +464,7 @@ label(int typ, sym_t *sym, tnode_t *tn) * 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); diff --git a/usr.bin/xlint/lint1/tree.c b/usr.bin/xlint/lint1/tree.c index bdadc2812d21..3a346166d3d0 100644 --- a/usr.bin/xlint/lint1/tree.c +++ b/usr.bin/xlint/lint1/tree.c @@ -1,4 +1,4 @@ -/* $NetBSD: tree.c,v 1.30 2002/10/22 13:31:34 christos Exp $ */ +/* $NetBSD: tree.c,v 1.31 2002/10/22 13:48:51 christos Exp $ */ /* * Copyright (c) 1994, 1995 Jochen Pohl @@ -33,7 +33,7 @@ #include #if defined(__RCSID) && !defined(lint) -__RCSID("$NetBSD: tree.c,v 1.30 2002/10/22 13:31:34 christos Exp $"); +__RCSID("$NetBSD: tree.c,v 1.31 2002/10/22 13:48:51 christos Exp $"); #endif #include @@ -3278,7 +3278,7 @@ parg( int n, /* pos of arg */ * type, an error message is printed. */ val_t * -constant(tnode_t *tn) +constant(tnode_t *tn, int required) { val_t *v; @@ -3313,7 +3313,10 @@ constant(tnode_t *tn) } /* integral constant expression expected */ - error(55); + if (required) + error(55); + else + gnuism(318); if (!isityp(v->v_tspec)) v->v_tspec = INT;