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 add C9X/GCC compound literal expressions.
details: https://anonhg.NetBSD.org/src/rev/bfaca82730b4
branches: trunk
changeset: 538562:bfaca82730b4
user: christos <christos%NetBSD.org@localhost>
date: Tue Oct 22 18:15:00 2002 +0000
description:
add C9X/GCC compound literal expressions.
diffstat:
usr.bin/xlint/lint1/cgram.y | 13 +++++++--
usr.bin/xlint/lint1/err.c | 5 ++-
usr.bin/xlint/lint1/externs1.h | 4 ++-
usr.bin/xlint/lint1/scan.l | 28 ++++++++++++++++++-
usr.bin/xlint/lint1/tree.c | 60 +++++++++++++++++++++++------------------
5 files changed, 76 insertions(+), 34 deletions(-)
diffs (231 lines):
diff -r 386ac4e66358 -r bfaca82730b4 usr.bin/xlint/lint1/cgram.y
--- a/usr.bin/xlint/lint1/cgram.y Tue Oct 22 17:58:45 2002 +0000
+++ b/usr.bin/xlint/lint1/cgram.y Tue Oct 22 18:15:00 2002 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: cgram.y,v 1.27 2002/10/22 13:48:51 christos Exp $ */
+/* $NetBSD: cgram.y,v 1.28 2002/10/22 18:15:00 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.27 2002/10/22 13:48:51 christos Exp $");
+__RCSID("$NetBSD: cgram.y,v 1.28 2002/10/22 18:15:00 christos Exp $");
#endif
#include <stdlib.h>
@@ -1593,6 +1593,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:
@@ -1655,7 +1663,6 @@
int
yyerror(char *msg)
{
-
error(249);
if (++sytxerr >= 5)
norecover();
diff -r 386ac4e66358 -r bfaca82730b4 usr.bin/xlint/lint1/err.c
--- a/usr.bin/xlint/lint1/err.c Tue Oct 22 17:58:45 2002 +0000
+++ b/usr.bin/xlint/lint1/err.c Tue Oct 22 18:15:00 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: err.c,v 1.22 2002/10/22 13:48:50 christos Exp $ */
+/* $NetBSD: err.c,v 1.23 2002/10/22 18:15:00 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.22 2002/10/22 13:48:50 christos Exp $");
+__RCSID("$NetBSD: err.c,v 1.23 2002/10/22 18:15:00 christos Exp $");
#endif
#include <sys/types.h>
@@ -374,6 +374,7 @@
"__FUNCTION__ is a GCC extension", /* 316 */
"__func__ is a C9X feature", /* 317 */
"variable array dimension is a GCC extension", /* 318 */
+ "compound literals are a C9X/GCC extension", /* 319 */
};
/*
diff -r 386ac4e66358 -r bfaca82730b4 usr.bin/xlint/lint1/externs1.h
--- a/usr.bin/xlint/lint1/externs1.h Tue Oct 22 17:58:45 2002 +0000
+++ b/usr.bin/xlint/lint1/externs1.h Tue Oct 22 18:15:00 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: externs1.h,v 1.17 2002/10/22 13:48:52 christos Exp $ */
+/* $NetBSD: externs1.h,v 1.18 2002/10/22 18:15:00 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -81,6 +81,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 *);
@@ -196,6 +197,7 @@
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(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 *);
diff -r 386ac4e66358 -r bfaca82730b4 usr.bin/xlint/lint1/scan.l
--- a/usr.bin/xlint/lint1/scan.l Tue Oct 22 17:58:45 2002 +0000
+++ b/usr.bin/xlint/lint1/scan.l Tue Oct 22 18:15:00 2002 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: scan.l,v 1.28 2002/09/13 14:59:25 christos Exp $ */
+/* $NetBSD: scan.l,v 1.29 2002/10/22 18:15:01 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: scan.l,v 1.28 2002/09/13 14:59:25 christos Exp $");
+__RCSID("$NetBSD: scan.l,v 1.29 2002/10/22 18:15:01 christos Exp $");
#endif
#include <stdlib.h>
@@ -1331,6 +1331,30 @@
}
/*
+ * 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;
+ if ((sym->s_link = symtab[h]) != NULL)
+ symtab[h]->s_rlink = &sym->s_link;
+ (symtab[h] = sym)->s_rlink = &symtab[h];
+ 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.
diff -r 386ac4e66358 -r bfaca82730b4 usr.bin/xlint/lint1/tree.c
--- a/usr.bin/xlint/lint1/tree.c Tue Oct 22 17:58:45 2002 +0000
+++ b/usr.bin/xlint/lint1/tree.c Tue Oct 22 18:15:00 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tree.c,v 1.31 2002/10/22 13:48:51 christos Exp $ */
+/* $NetBSD: tree.c,v 1.32 2002/10/22 18:15:01 christos Exp $ */
/*
* Copyright (c) 1994, 1995 Jochen Pohl
@@ -33,7 +33,7 @@
#include <sys/cdefs.h>
#if defined(__RCSID) && !defined(lint)
-__RCSID("$NetBSD: tree.c,v 1.31 2002/10/22 13:48:51 christos Exp $");
+__RCSID("$NetBSD: tree.c,v 1.32 2002/10/22 18:15:01 christos Exp $");
#endif
#include <stdlib.h>
@@ -2239,6 +2239,36 @@
}
const char *
+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;
@@ -2248,30 +2278,8 @@
if ((t = tp->t_tspec) == INT && tp->t_isenum)
t = ENUM;
- 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;
- default:
- LERROR("tyname()");
- }
+ s = basictyname(t);
+
switch (t) {
case CHAR:
Home |
Main Index |
Thread Index |
Old Index