Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/xlint/lint1 support for c99 style and gnu style stru...
details: https://anonhg.NetBSD.org/src/rev/79f92725d4bc
branches: trunk
changeset: 538501:79f92725d4bc
user: christos <christos%NetBSD.org@localhost>
date: Mon Oct 21 21:14:51 2002 +0000
description:
support for c99 style and gnu style structure and union named initializers.
diffstat:
usr.bin/xlint/lint1/cgram.y | 25 ++++++-
usr.bin/xlint/lint1/err.c | 11 ++-
usr.bin/xlint/lint1/externs1.h | 4 +-
usr.bin/xlint/lint1/init.c | 135 ++++++++++++++++++++++++++++++++++++++--
usr.bin/xlint/lint1/lint1.h | 3 +-
usr.bin/xlint/lint1/main1.c | 11 ++-
6 files changed, 170 insertions(+), 19 deletions(-)
diffs (truncated from 472 to 300 lines):
diff -r 6580d38c9bc3 -r 79f92725d4bc usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Mon Oct 21 21:10:59 2002 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Mon Oct 21 21:14:51 2002 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.25 2002/09/13 14:59:24 christos Exp $ */
+/* $NetBSD: cgram.y,v 1.26 2002/10/21 21:14:51 christos Exp $ */
/*
* Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: cgram.y,v 1.25 2002/09/13 14:59:24 christos Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.26 2002/10/21 21:14:51 christos Exp $");
#endif
#include <stdlib.h>
@@ -1120,6 +1120,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
@@ -1130,6 +1131,19 @@
| init_expr_list T_COMMA init_expr
;
+
+init_by_name:
+ point T_NAME T_ASSIGN {
+ if (!Sflag)
+ warning(313);
+ memberpush($2);
+ }
+ | T_NAME T_COLON {
+ gnuism(315);
+ memberpush($1);
+ }
+ ;
+
init_lbrace:
T_LBRACE {
initlbr();
@@ -1619,6 +1633,13 @@
}
;
+point:
+ T_STROP {
+ if ($1 != POINT)
+ error(249);
+ }
+ ;
+
identifier:
T_NAME {
$$ = $1;
diff -r 6580d38c9bc3 -r 79f92725d4bc usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Mon Oct 21 21:10:59 2002 +0000
+++ b/usr.bin/xlint/lint1/err.c Mon Oct 21 21:14:51 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: err.c,v 1.19 2002/09/13 14:59:24 christos Exp $ */
+/* $NetBSD: err.c,v 1.20 2002/10/21 21:14:51 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -33,7 +33,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: err.c,v 1.19 2002/09/13 14:59:24 christos Exp $");
+__RCSID("$NetBSD: err.c,v 1.20 2002/10/21 21:14:51 christos Exp $");
#endif
#include <sys/types.h>
@@ -368,6 +368,9 @@
"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 */
};
/*
@@ -457,8 +460,8 @@
va_start(ap, msg);
fn = lbasename(curr_pos.p_file);
- (void)fprintf(stderr, "%s(%d): lint error: %s, %d", fn, curr_pos.p_line,
- file, 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);
diff -r 6580d38c9bc3 -r 79f92725d4bc usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h Mon Oct 21 21:10:59 2002 +0000
+++ b/usr.bin/xlint/lint1/externs1.h Mon Oct 21 21:14:51 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.15 2002/09/13 14:59:24 christos Exp $ */
+/* $NetBSD: externs1.h,v 1.16 2002/10/21 21:14:52 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -50,6 +50,7 @@
extern int yflag;
extern int wflag;
extern int zflag;
+extern int Sflag;
extern void norecover(void);
@@ -273,6 +274,7 @@
extern void initrbr(void);
extern void initlbr(void);
extern void mkinit(tnode_t *);
+extern void memberpush(sbuf_t *);
/*
* emit.c
diff -r 6580d38c9bc3 -r 79f92725d4bc usr.bin/xlint/lint1/init.c
--- a/usr.bin/xlint/lint1/init.c Mon Oct 21 21:10:59 2002 +0000
+++ b/usr.bin/xlint/lint1/init.c Mon Oct 21 21:14:51 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: init.c,v 1.11 2002/09/13 14:59:24 christos Exp $ */
+/* $NetBSD: init.c,v 1.12 2002/10/21 21:14:52 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -33,7 +33,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: init.c,v 1.11 2002/09/13 14:59:24 christos Exp $");
+__RCSID("$NetBSD: init.c,v 1.12 2002/10/21 21:14:52 christos Exp $");
#endif
#include <stdlib.h>
@@ -53,6 +53,15 @@
/* 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);
@@ -60,6 +69,53 @@
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
+}
/*
@@ -96,6 +152,9 @@
static void
popi2(void)
{
+#ifdef DEBUG
+ char buf[64];
+#endif
istk_t *istk;
sym_t *m;
@@ -110,11 +169,30 @@
if (istk->i_cnt < 0)
LERROR("popi2()");
+ 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)
@@ -127,6 +205,7 @@
static void
popinit(int brace)
{
+ DPRINTF(("popinit(%d)\n", brace));
if (brace) {
/*
@@ -153,6 +232,9 @@
static void
pushinit(void)
{
+#ifdef DEBUG
+ char buf[64];
+#endif
istk_t *istk;
int cnt;
sym_t *m;
@@ -161,6 +243,8 @@
/* 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.
@@ -186,8 +270,10 @@
if (initstk->i_type->t_tspec == FUNC)
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 (incompl(istk->i_type) && istk->i_nxt->i_nxt != NULL) {
@@ -213,14 +299,37 @@
return;
}
cnt = 0;
+ DPRINTF(("2. member lookup %s\n",
+ tyname(buf, sizeof(buf), istk->i_type)));
for (m = istk->i_type->t_str->memb; m != NULL; m = m->s_nxt) {
Home |
Main Index |
Thread Index |
Old Index