Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/config Move locator lists to their own data structur...
details: https://anonhg.NetBSD.org/src/rev/668f9ded9084
branches: trunk
changeset: 777997:668f9ded9084
user: dholland <dholland%NetBSD.org@localhost>
date: Sun Mar 11 21:16:07 2012 +0000
description:
Move locator lists to their own data structure. This can use more tidying;
it is not clear to me at the moment what the "string" and "num" values
pushed around in locator lists are supposed to actually mean.
diffstat:
usr.bin/config/defs.h | 20 +++++-
usr.bin/config/gram.y | 153 +++++++++++++++++++++++++++++++-------------
usr.bin/config/lint.c | 13 ++-
usr.bin/config/mkheaders.c | 16 ++--
usr.bin/config/mkioconf.c | 26 +++---
usr.bin/config/sem.c | 68 ++++++++++---------
usr.bin/config/sem.h | 8 +-
usr.bin/config/util.c | 32 +++++++++-
8 files changed, 224 insertions(+), 112 deletions(-)
diffs (truncated from 771 to 300 lines):
diff -r 2e8c170a065a -r 668f9ded9084 usr.bin/config/defs.h
--- a/usr.bin/config/defs.h Sun Mar 11 21:15:25 2012 +0000
+++ b/usr.bin/config/defs.h Sun Mar 11 21:16:07 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.39 2012/03/11 08:21:53 dholland Exp $ */
+/* $NetBSD: defs.h,v 1.40 2012/03/11 21:16:07 dholland Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -157,7 +157,7 @@
const char *a_name; /* name of this attribute */
int a_iattr; /* true => allows children */
const char *a_devclass; /* device class described */
- struct nvlist *a_locs; /* locators required */
+ struct loclist *a_locs; /* locators required */
int a_loclen; /* length of above list */
struct nvlist *a_devs; /* children */
struct nvlist *a_refs; /* parents */
@@ -174,6 +174,20 @@
};
/*
+ * List of locators. (Either definitions or uses...)
+ *
+ * XXX it would be nice if someone could clarify wtf ll_string and ll_num
+ * are actually holding. (This stuff was previously stored in a very ad
+ * hoc fashion, and the code is far from clear.)
+ */
+struct loclist {
+ const char *ll_name;
+ const char *ll_string;
+ long long ll_num;
+ struct loclist *ll_next;
+};
+
+/*
* Parent specification. Multiple device instances may share a
* given parent spec. Parent specs are emitted only if there are
* device instances which actually reference it.
@@ -604,6 +618,8 @@
struct attrlist *attrlist_cons(struct attrlist *, struct attr *);
void attrlist_destroy(struct attrlist *);
void attrlist_destroyall(struct attrlist *);
+struct loclist *loclist_create(const char *, const char *, long long);
+void loclist_destroy(struct loclist *);
struct condexpr *condexpr_create(enum condexpr_types);
void condexpr_destroy(struct condexpr *);
diff -r 2e8c170a065a -r 668f9ded9084 usr.bin/config/gram.y
--- a/usr.bin/config/gram.y Sun Mar 11 21:15:25 2012 +0000
+++ b/usr.bin/config/gram.y Sun Mar 11 21:16:07 2012 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: gram.y,v 1.35 2012/03/11 19:27:26 dholland Exp $ */
+/* $NetBSD: gram.y,v 1.36 2012/03/11 21:16:08 dholland Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -70,8 +70,9 @@
* Allocation wrapper type codes
*/
#define WRAP_CODE_nvlist 1
-#define WRAP_CODE_attrlist 2
-#define WRAP_CODE_condexpr 3
+#define WRAP_CODE_loclist 2
+#define WRAP_CODE_attrlist 3
+#define WRAP_CODE_condexpr 4
/*
* The allocation wrappers themselves
@@ -79,10 +80,12 @@
#define DECL_ALLOCWRAP(t) static struct t *wrap_mk_##t(struct t *arg)
DECL_ALLOCWRAP(nvlist);
+DECL_ALLOCWRAP(loclist);
DECL_ALLOCWRAP(attrlist);
DECL_ALLOCWRAP(condexpr);
/* allow shorter names */
+#define wrap_mk_loc(p) wrap_mk_loclist(p)
#define wrap_mk_cx(p) wrap_mk_condexpr(p)
/*
@@ -108,6 +111,7 @@
#define MK0(t) wrap_mk_##t(mk_##t())
#define MK1(t, a0) wrap_mk_##t(mk_##t(a0))
#define MK2(t, a0, a1) wrap_mk_##t(mk_##t(a0, a1))
+#define MK3(t, a0, a1, a2) wrap_mk_##t(mk_##t(a0, a1, a2))
#define MKF0(t, f) wrap_mk_##t(mk_##t##_##f())
#define MKF1(t, f, a0) wrap_mk_##t(mk_##t##_##f(a0))
@@ -117,6 +121,8 @@
* Data constructors
*/
+static struct loclist *mk_loc(const char *, const char *, long long);
+static struct loclist *mk_loc_val(const char *, struct loclist *);
static struct attrlist *mk_attrlist(struct attrlist *, struct attr *);
static struct condexpr *mk_cx_atom(const char *);
static struct condexpr *mk_cx_not(struct condexpr *);
@@ -130,10 +136,10 @@
static void setmachine(const char *, const char *, struct nvlist *, int);
static void check_maxpart(void);
-static void app(struct nvlist *, struct nvlist *);
-
-static struct nvlist *mk_nsis(const char *, int, struct nvlist *, int);
-static struct nvlist *mk_ns(const char *, struct nvlist *);
+static struct loclist *present_loclist(struct loclist *ll);
+static void app(struct loclist *, struct loclist *);
+static struct loclist *locarray(const char *, int, struct loclist *, int);
+static struct loclist *namelocvals(const char *, struct loclist *);
%}
@@ -142,6 +148,7 @@
struct devbase *devb;
struct deva *deva;
struct nvlist *list;
+ struct loclist *loclist;
struct attrlist *attrlist;
struct condexpr *condexpr;
const char *str;
@@ -180,13 +187,14 @@
%type <attr> depend
%type <devb> devbase
%type <deva> devattach_opt
-%type <list> atlist interface_opt
+%type <list> atlist
+%type <loclist> interface_opt
%type <str> atname
-%type <list> loclist locdef
+%type <loclist> loclist locdef
%type <str> locdefault
-%type <list> values locdefaults
+%type <loclist> values locdefaults
%type <attrlist> depend_list depends
-%type <list> locators locator
+%type <loclist> locators locator
%type <list> dev_spec
%type <str> device_instance
%type <str> attachment
@@ -442,8 +450,8 @@
/* optional locator specification */
interface_opt:
/* empty */ { $$ = NULL; }
- | '{' '}' { $$ = new_nx("", NULL); }
- | '{' loclist '}' { $$ = new_nx("", $2); }
+ | '{' '}' { $$ = present_loclist(NULL); }
+ | '{' loclist '}' { $$ = present_loclist($2); }
;
/*
@@ -463,14 +471,14 @@
/* one locator definition */
locdef:
- locname locdefault { $$ = new_nsi($1, $2, 0); }
- | locname { $$ = new_nsi($1, NULL, 0); }
- | '[' locname locdefault ']' { $$ = new_nsi($2, $3, 1); }
- | locname '[' NUMBER ']' { $$ = mk_nsis($1, $3.val, NULL, 0); }
+ locname locdefault { $$ = MK3(loc, $1, $2, 0); }
+ | locname { $$ = MK3(loc, $1, NULL, 0); }
+ | '[' locname locdefault ']' { $$ = MK3(loc, $2, $3, 1); }
+ | locname '[' NUMBER ']' { $$ = locarray($1, $3.val, NULL, 0); }
| locname '[' NUMBER ']' locdefaults
- { $$ = mk_nsis($1, $3.val, $5, 0); }
+ { $$ = locarray($1, $3.val, $5, 0); }
| '[' locname '[' NUMBER ']' locdefaults ']'
- { $$ = mk_nsis($2, $4.val, $6, 1); }
+ { $$ = locarray($2, $4.val, $6, 1); }
;
/* locator name */
@@ -779,8 +787,8 @@
/* one locator */
locator:
- WORD '?' { $$ = new_ns($1, NULL); }
- | WORD values { $$ = mk_ns($1, $2); }
+ WORD '?' { $$ = MK3(loc, $1, NULL, 0); }
+ | WORD values { $$ = namelocvals($1, $2); }
;
/* optional device flags */
@@ -880,8 +888,8 @@
/* comma-separated list of values */
/* XXX why right-recursive? */
values:
- value { $$ = new_s($1); }
- | value ',' values { $$ = new_sx($1, $3); }
+ value { $$ = MKF2(loc, val, $1, NULL); }
+ | value ',' values { $$ = MKF2(loc, val, $1, $3); }
;
/* possibly negative number */
@@ -956,24 +964,45 @@
{
unsigned i;
+ /*
+ * Destroy each item. Note that because everything allocated
+ * is entered on the list separately, lists and trees need to
+ * have their links blanked before being destroyed. Also note
+ * that strings are interned elsewhere and not handled by this
+ * mechanism.
+ */
+
for (i=0; i<wrap_depth; i++) {
switch (wrapstack[i].typecode) {
case WRAP_CODE_nvlist:
nvfree(wrapstack[i].ptr);
break;
+ case WRAP_CODE_loclist:
+ {
+ struct loclist *ll = wrapstack[i].ptr;
+
+ ll->ll_next = NULL;
+ loclist_destroy(ll);
+ }
+ break;
case WRAP_CODE_attrlist:
{
struct attrlist *al = wrapstack[i].ptr;
- /*
- * Contents got wrapped separately;
- * just blank it out to destroy.
- */
al->al_next = NULL;
al->al_this = NULL;
attrlist_destroy(al);
}
break;
+ case WRAP_CODE_condexpr:
+ {
+ struct condexpr *cx = wrapstack[i].ptr;
+
+ cx->cx_type = CX_ATOM;
+ cx->cx_atom = NULL;
+ condexpr_destroy(cx);
+ }
+ break;
default:
panic("invalid code %u on allocation wrapper stack",
wrapstack[i].typecode);
@@ -999,6 +1028,7 @@
}
DEF_ALLOCWRAP(nvlist);
+DEF_ALLOCWRAP(loclist);
DEF_ALLOCWRAP(attrlist);
DEF_ALLOCWRAP(condexpr);
@@ -1006,8 +1036,26 @@
/*
* Data constructors
+ *
+ * (These are *beneath* the allocation wrappers.)
*/
+static struct loclist *
+mk_loc(const char *name, const char *str, long long num)
+{
+ return loclist_create(name, str, num);
+}
+
+static struct loclist *
+mk_loc_val(const char *str, struct loclist *next)
+{
+ struct loclist *ll;
+
+ ll = mk_loc(NULL, str, 0);
+ ll->ll_next = next;
+ return ll;
+}
+
static struct attrlist *
mk_attrlist(struct attrlist *next, struct attr *a)
{
@@ -1148,19 +1196,34 @@
stop("your sources are out of date -- please update.");
}
-static void
-app(struct nvlist *p, struct nvlist *q)
+/*
+ * Prepend a blank entry to the locator definitions so the code in
+ * sem.c can distinguish "empty locator list" from "no locator list".
+ * XXX gross.
+ */
+static struct loclist *
+present_loclist(struct loclist *ll)
{
- while (p->nv_next)
- p = p->nv_next;
- p->nv_next = q;
+ struct loclist *ret;
+
Home |
Main Index |
Thread Index |
Old Index