Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/config Give option definitions their own data struct...
details: https://anonhg.NetBSD.org/src/rev/9ee5e1d46c40
branches: trunk
changeset: 778007:9ee5e1d46c40
user: dholland <dholland%NetBSD.org@localhost>
date: Mon Mar 12 02:58:55 2012 +0000
description:
Give option definitions their own data structure instead of using nvlists.
(and using messy hacks to make up for nvlists not holding quite the right
things)
diffstat:
usr.bin/config/defs.h | 46 ++++++---
usr.bin/config/gram.y | 50 ++++++----
usr.bin/config/hash.c | 3 +-
usr.bin/config/lint.c | 49 ++++++++--
usr.bin/config/main.c | 201 +++++++++++++++++++++++++++++---------------
usr.bin/config/mkheaders.c | 37 ++++----
usr.bin/config/util.c | 53 +++++++++++-
7 files changed, 303 insertions(+), 136 deletions(-)
diffs (truncated from 881 to 300 lines):
diff -r b37c014cd0ce -r 9ee5e1d46c40 usr.bin/config/defs.h
--- a/usr.bin/config/defs.h Mon Mar 12 02:44:16 2012 +0000
+++ b/usr.bin/config/defs.h Mon Mar 12 02:58:55 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: defs.h,v 1.41 2012/03/12 00:20:30 dholland Exp $ */
+/* $NetBSD: defs.h,v 1.42 2012/03/12 02:58:55 dholland Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -139,6 +139,18 @@
};
/*
+ * Option definition list
+ */
+struct defoptlist {
+ struct defoptlist *dl_next;
+ const char *dl_name;
+ const char *dl_value;
+ const char *dl_lintvalue;
+ int dl_obsolete;
+ struct nvlist *dl_depends;
+};
+
+/*
* Attributes. These come in three flavors: "plain", "device class,"
* and "interface". Plain attributes (e.g., "ether") simply serve
* to pull in files. Device class attributes are like plain
@@ -460,12 +472,12 @@
struct hashtab *needcnttab; /* retains names marked "needs-count" */
struct hashtab *opttab; /* table of configured options */
struct hashtab *fsopttab; /* table of configured file systems */
-struct nvhash *defopttab; /* options that have been "defopt"'d */
-struct nvhash *defflagtab; /* options that have been "defflag"'d */
-struct nvhash *defparamtab; /* options that have been "defparam"'d */
-struct nvhash *defoptlint; /* lint values for options */
+struct dlhash *defopttab; /* options that have been "defopt"'d */
+struct dlhash *defflagtab; /* options that have been "defflag"'d */
+struct dlhash *defparamtab; /* options that have been "defparam"'d */
+struct dlhash *defoptlint; /* lint values for options */
struct nvhash *deffstab; /* defined file systems */
-struct nvhash *optfiletab; /* "defopt"'d option .h files */
+struct dlhash *optfiletab; /* "defopt"'d option .h files */
struct hashtab *attrtab; /* attributes (locators, etc.) */
struct hashtab *bdevmtab; /* block devm lookup */
struct hashtab *cdevmtab; /* character devm lookup */
@@ -541,6 +553,7 @@
int (*)(const char *, struct VT *, void *), \
void *)
DECLHASH(nvhash, nvlist);
+DECLHASH(dlhash, defoptlist);
/* lint.c */
void emit_instances(void);
@@ -554,25 +567,25 @@
void appendmkoption(const char *, const char *);
void appendcondmkoption(struct condexpr *, const char *, const char *);
void deffilesystem(struct nvlist *, struct nvlist *);
-void defoption(const char *, struct nvlist *, struct nvlist *);
-void defflag(const char *, struct nvlist *, struct nvlist *, int);
-void defparam(const char *, struct nvlist *, struct nvlist *, int);
+void defoption(const char *, struct defoptlist *, struct nvlist *);
+void defflag(const char *, struct defoptlist *, struct nvlist *, int);
+void defparam(const char *, struct defoptlist *, struct nvlist *, int);
void deloption(const char *);
void delfsoption(const char *);
void delmkoption(const char *);
int devbase_has_instances(struct devbase *, int);
-struct nvlist * find_declared_option(const char *);
+int is_declared_option(const char *);
int deva_has_instances(struct deva *, int);
void setupdirs(void);
const char *strtolower(const char *);
/* tests on option types */
#define OPT_FSOPT(n) (nvhash_lookup(deffstab, (n)) != NULL)
-#define OPT_DEFOPT(n) (nvhash_lookup(defopttab, (n)) != NULL)
-#define OPT_DEFFLAG(n) (nvhash_lookup(defflagtab, (n)) != NULL)
-#define OPT_DEFPARAM(n) (nvhash_lookup(defparamtab, (n)) != NULL)
-#define OPT_OBSOLETE(n) (nvhash_lookup(obsopttab, (n)) != NULL)
-#define DEFINED_OPTION(n) (find_declared_option((n)) != NULL)
+#define OPT_DEFOPT(n) (dlhash_lookup(defopttab, (n)) != NULL)
+#define OPT_DEFFLAG(n) (dlhash_lookup(defflagtab, (n)) != NULL)
+#define OPT_DEFPARAM(n) (dlhash_lookup(defparamtab, (n)) != NULL)
+#define OPT_OBSOLETE(n) (dlhash_lookup(obsopttab, (n)) != NULL)
+#define DEFINED_OPTION(n) (is_declared_option((n)))
/* main.c */
void logconfig_include(FILE *, const char *);
@@ -627,6 +640,9 @@
void nvfreel(struct nvlist *);
struct nvlist *nvcat(struct nvlist *, struct nvlist *);
void autogen_comment(FILE *, const char *);
+struct defoptlist *defoptlist_create(const char *, const char *, const char *);
+void defoptlist_destroy(struct defoptlist *);
+struct defoptlist *defoptlist_append(struct defoptlist *, struct defoptlist *);
struct attrlist *attrlist_create(void);
struct attrlist *attrlist_cons(struct attrlist *, struct attr *);
void attrlist_destroy(struct attrlist *);
diff -r b37c014cd0ce -r 9ee5e1d46c40 usr.bin/config/gram.y
--- a/usr.bin/config/gram.y Mon Mar 12 02:44:16 2012 +0000
+++ b/usr.bin/config/gram.y Mon Mar 12 02:58:55 2012 +0000
@@ -1,5 +1,5 @@
%{
-/* $NetBSD: gram.y,v 1.36 2012/03/11 21:16:08 dholland Exp $ */
+/* $NetBSD: gram.y,v 1.37 2012/03/12 02:58:55 dholland Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -70,9 +70,10 @@
* Allocation wrapper type codes
*/
#define WRAP_CODE_nvlist 1
-#define WRAP_CODE_loclist 2
-#define WRAP_CODE_attrlist 3
-#define WRAP_CODE_condexpr 4
+#define WRAP_CODE_defoptlist 2
+#define WRAP_CODE_loclist 3
+#define WRAP_CODE_attrlist 4
+#define WRAP_CODE_condexpr 5
/*
* The allocation wrappers themselves
@@ -80,6 +81,7 @@
#define DECL_ALLOCWRAP(t) static struct t *wrap_mk_##t(struct t *arg)
DECL_ALLOCWRAP(nvlist);
+DECL_ALLOCWRAP(defoptlist);
DECL_ALLOCWRAP(loclist);
DECL_ALLOCWRAP(attrlist);
DECL_ALLOCWRAP(condexpr);
@@ -121,6 +123,8 @@
* Data constructors
*/
+static struct defoptlist *mk_defoptlist(const char *, const char *,
+ const char *);
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 *);
@@ -148,6 +152,7 @@
struct devbase *devb;
struct deva *deva;
struct nvlist *list;
+ struct defoptlist *defoptlist;
struct loclist *loclist;
struct attrlist *attrlist;
struct condexpr *condexpr;
@@ -204,8 +209,8 @@
%type <val> device_flags
%type <str> deffs
%type <list> deffses
-%type <list> defopt
-%type <list> defopts
+%type <defoptlist> defopt
+%type <defoptlist> defopts
%type <str> optdepend
%type <list> optdepends
%type <list> optdepend_list
@@ -547,23 +552,15 @@
/* one or more defined options */
defopts:
defopt { $$ = $1; }
- | defopts defopt { $$ = nvcat($2, $1); }
+ | defopts defopt { $$ = defoptlist_append($2, $1); }
;
/* one defined option */
defopt:
- WORD { $$ = new_n($1); }
- | WORD '=' value { $$ = new_ns($1, $3); }
- | WORD COLONEQ value {
- struct nvlist *__nv = new_n($1);
-
- $$ = new_nsx("", $3, __nv);
- }
- | WORD '=' value COLONEQ value {
- struct nvlist *__nv = new_n($1);
-
- $$ = new_nsx("", $5, __nv);
- }
+ WORD { $$ = MK3(defoptlist, $1, NULL, NULL); }
+ | WORD '=' value { $$ = MK3(defoptlist, $1, $3, NULL); }
+ | WORD COLONEQ value { $$ = MK3(defoptlist, $1, NULL, $3); }
+ | WORD '=' value COLONEQ value { $$ = MK3(defoptlist, $1, $3, $5); }
;
/* list of conditional makeoptions */
@@ -977,6 +974,14 @@
case WRAP_CODE_nvlist:
nvfree(wrapstack[i].ptr);
break;
+ case WRAP_CODE_defoptlist:
+ {
+ struct defoptlist *dl = wrapstack[i].ptr;
+
+ dl->dl_next = NULL;
+ defoptlist_destroy(dl);
+ }
+ break;
case WRAP_CODE_loclist:
{
struct loclist *ll = wrapstack[i].ptr;
@@ -1028,6 +1033,7 @@
}
DEF_ALLOCWRAP(nvlist);
+DEF_ALLOCWRAP(defoptlist);
DEF_ALLOCWRAP(loclist);
DEF_ALLOCWRAP(attrlist);
DEF_ALLOCWRAP(condexpr);
@@ -1040,6 +1046,12 @@
* (These are *beneath* the allocation wrappers.)
*/
+static struct defoptlist *
+mk_defoptlist(const char *name, const char *val, const char *lintval)
+{
+ return defoptlist_create(name, val, lintval);
+}
+
static struct loclist *
mk_loc(const char *name, const char *str, long long num)
{
diff -r b37c014cd0ce -r 9ee5e1d46c40 usr.bin/config/hash.c
--- a/usr.bin/config/hash.c Mon Mar 12 02:44:16 2012 +0000
+++ b/usr.bin/config/hash.c Mon Mar 12 02:58:55 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: hash.c,v 1.7 2012/03/12 00:20:30 dholland Exp $ */
+/* $NetBSD: hash.c,v 1.8 2012/03/12 02:58:55 dholland Exp $ */
/*
* Copyright (c) 1992, 1993
@@ -387,3 +387,4 @@
}
DEFHASH(nvhash, nvlist);
+DEFHASH(dlhash, defoptlist);
diff -r b37c014cd0ce -r 9ee5e1d46c40 usr.bin/config/lint.c
--- a/usr.bin/config/lint.c Mon Mar 12 02:44:16 2012 +0000
+++ b/usr.bin/config/lint.c Mon Mar 12 02:58:55 2012 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lint.c,v 1.11 2012/03/12 00:20:30 dholland Exp $ */
+/* $NetBSD: lint.c,v 1.12 2012/03/12 02:58:55 dholland Exp $ */
/*
* Copyright (c) 2007 The NetBSD Foundation.
@@ -30,6 +30,7 @@
#include "nbtool_config.h"
#endif
+#include <assert.h>
#include <stdlib.h>
#include "defs.h"
@@ -62,39 +63,63 @@
};
static int
-do_emit_option(const char *name, struct nvlist *value, void *v)
+do_emit_option(const char *name, struct defoptlist *dl, void *v)
{
- struct nvlist *nv = value;
const struct opt_type *ot = v;
+ const char *value;
- if (nv->nv_flags & NV_OBSOLETE)
+ if (dl->dl_obsolete)
return 0;
if (ht_lookup(*(ot->ot_ht), name))
return 0;
- printf("%s\t%s", ot->ot_name, nv->nv_name);
+ printf("%s\t%s", ot->ot_name, dl->dl_name);
if (ot->ot_type == OT_PARAM) {
- struct nvlist *nv2 = nvhash_lookup(defoptlint, nv->nv_name);
- if (nv2 == NULL)
- nv2 = nv;
- printf("=\"%s\"", nv2->nv_str ? nv2->nv_str : "1");
+ struct defoptlist *dl2 = dlhash_lookup(defoptlint, dl->dl_name);
+ if (dl2 != NULL)
+ value = dl2->dl_lintvalue;
+ else
+ value = dl->dl_value;
+ assert(dl2 == dl);
+ printf("=\"%s\"", value ? value : "1");
}
printf("\n");
return 1;
}
+
+/*
+ * Same as do_emit_option but for filesystem definitions, which now
+ * have a different data type. XXX these should probably be unified
+ * again.
+ */
+static int
+do_emit_fs(const char *name, struct nvlist *nv, void *v)
Home |
Main Index |
Thread Index |
Old Index