Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/config Keep track where more objects are declared so...



details:   https://anonhg.NetBSD.org/src/rev/c2aa2a3d1e48
branches:  trunk
changeset: 1007992:c2aa2a3d1e48
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Mar 07 19:26:13 2020 +0000

description:
Keep track where more objects are declared so that we can print where things
have been redefined.

diffstat:

 usr.bin/config/defs.h  |  31 ++++++++++++-----------
 usr.bin/config/files.c |  66 ++++++++++++++++++++++++++-----------------------
 usr.bin/config/gram.y  |   6 ++--
 usr.bin/config/main.c  |  41 +++++++++++++++++-------------
 usr.bin/config/scan.l  |  15 +++++------
 usr.bin/config/sem.c   |  60 +++++++++++++++++++++++++++++---------------
 usr.bin/config/util.c  |  10 ++++++-
 7 files changed, 131 insertions(+), 98 deletions(-)

diffs (truncated from 709 to 300 lines):

diff -r bf30fd8e3afb -r c2aa2a3d1e48 usr.bin/config/defs.h
--- a/usr.bin/config/defs.h     Sat Mar 07 18:49:49 2020 +0000
+++ b/usr.bin/config/defs.h     Sat Mar 07 19:26:13 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: defs.h,v 1.104 2018/08/27 16:04:45 riastradh Exp $     */
+/*     $NetBSD: defs.h,v 1.105 2020/03/07 19:26:13 christos Exp $      */
 
 /*
  * Copyright (c) 1992, 1993
@@ -110,6 +110,10 @@
 #define CONFIG_VERSION         20180827
 #define CONFIG_MINVERSION      0
 
+struct where {
+       const char *w_srcfile;          /* file name where we are defined */
+       u_short w_srcline;              /* line number where we are defined */
+};
 /*
  * Name/value lists.  Values can be strings or pointers and/or can carry
  * integers.  The names can be NULL, resulting in simple value lists.
@@ -123,6 +127,7 @@
        int             nv_ifunit;              /* XXX XXX XXX */
        int             nv_flags;
 #define        NV_DEPENDED     1
+       struct where    nv_where;
 };
 
 /*
@@ -131,10 +136,10 @@
 struct config {
        TAILQ_ENTRY(config) cf_next;
        const char *cf_name;            /* "netbsd" */
-       int     cf_lineno;              /* source line */
        const char *cf_fstype;          /* file system type */
        struct  nvlist *cf_root;        /* "root on ra0a" */
        struct  nvlist *cf_dump;        /* "dumps on ra0b" */
+       struct where    cf_where;
 };
 
 /*
@@ -147,6 +152,7 @@
        const char *dl_lintvalue;
        int dl_obsolete;
        struct nvlist *dl_depends;
+       struct where    dl_where;
 };
 
 struct files;
@@ -199,6 +205,7 @@
 
        /* "device class" */
        const char *a_devclass;         /* device class described */
+       struct where a_where;
 };
 
 /*
@@ -277,8 +284,7 @@
        struct  deva *d_ahead;          /* first attachment, if any */
        struct  deva **d_app;           /* used for tacking on attachments */
        struct  attr *d_classattr;      /* device class attribute (if any) */
-       const char *d_srcfile;          /* file name where we are defined */
-       u_short d_srcline;              /* line number where we are defined */
+       struct  where d_where;
 };
 
 struct deva {
@@ -291,8 +297,7 @@
        struct  attrlist *d_attrs;      /* attributes, if any */
        struct  devi *d_ihead;          /* first instance, if any */
        struct  devi **d_ipp;           /* used for tacking on more instances */
-       const char *d_srcfile;          /* file name where we are defined */
-       u_short d_srcline;              /* line number where we are defined */
+       struct  where d_where;
 };
 
 /*
@@ -319,8 +324,6 @@
        struct  deva *i_atdeva;
        const char **i_locs;    /* locators (as given by pspec's iattr) */
        int     i_cfflags;      /* flags from config line */
-       int     i_lineno;       /* line # in config, for later errors */
-       const char *i_srcfile;  /* file it appears in */
        int     i_level;        /* position between negated instances */
        int     i_active;
 #define        DEVI_ORPHAN     0       /* instance has no active parent */
@@ -333,7 +336,7 @@
        short   i_collapsed;    /* set => this alias no longer needed */
        u_short i_cfindex;      /* our index in cfdata */
        int     i_locoff;       /* offset in locators.vec */
-
+       struct  where i_where;
 };
 /* special units */
 #define        STAR    (-1)            /* unit number for, e.g., "sd*" */
@@ -346,8 +349,7 @@
 struct files {
        TAILQ_ENTRY(files) fi_next;
        TAILQ_ENTRY(files) fi_snext;    /* per-suffix list */
-       const char *fi_srcfile; /* the name of the "files" file that got us */
-       u_short fi_srcline;     /* and the line number */
+       struct  where fi_where;
        u_char fi_flags;        /* as below */
        const char *fi_tail;    /* name, i.e., strrchr(fi_path, '/') + 1 */
        const char *fi_base;    /* tail minus ".c" (or whatever) */
@@ -418,13 +420,12 @@
  */
 struct devm {
        TAILQ_ENTRY(devm) dm_next;
-       const char      *dm_srcfile;    /* the name of the "majors" file */
-       u_short         dm_srcline;     /* the line number */
        const char      *dm_name;       /* [bc]devsw name */
        devmajor_t      dm_cmajor;      /* character major */
        devmajor_t      dm_bmajor;      /* block major */
        struct condexpr *dm_opts;       /* options */
        struct nvlist   *dm_devnodes;   /* information on /dev nodes */
+       struct where dm_where;
 };
 
 /*
@@ -581,7 +582,7 @@
 void   delfsoption(const char *, int);
 void   delmkoption(const char *, int);
 int    devbase_has_instances(struct devbase *, int);
-int    is_declared_option(const char *);
+struct where *find_declared_option(const char *);
 int    deva_has_instances(struct deva *, int);
 void   setupdirs(void);
 void   fixmaxusers(void);
@@ -594,7 +595,7 @@
 #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)))
+#define DEFINED_OPTION(n) (find_declared_option((n)))
 
 /* main.c */
 void   logconfig_include(FILE *, const char *);
diff -r bf30fd8e3afb -r c2aa2a3d1e48 usr.bin/config/files.c
--- a/usr.bin/config/files.c    Sat Mar 07 18:49:49 2020 +0000
+++ b/usr.bin/config/files.c    Sat Mar 07 19:26:13 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: files.c,v 1.36 2016/09/09 21:09:11 christos Exp $      */
+/*     $NetBSD: files.c,v 1.37 2020/03/07 19:26:13 christos Exp $      */
 
 /*
  * Copyright (c) 1992, 1993
@@ -45,7 +45,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: files.c,v 1.36 2016/09/09 21:09:11 christos Exp $");
+__RCSID("$NetBSD: files.c,v 1.37 2020/03/07 19:26:13 christos Exp $");
 
 #include <sys/param.h>
 #include <assert.h>
@@ -158,19 +158,19 @@
                 * options for specific files.
                 */
                if (rule != NULL && optx == NULL && flags == 0 &&
-                   yyfile != fi->fi_srcfile) {
+                   yyfile != fi->fi_where.w_srcfile) {
                        fi->fi_mkrule = rule;
                        return;
                }
                cfgerror("duplicate file %s", path);
-               cfgxerror(fi->fi_srcfile, fi->fi_srcline,
+               cfgxerror(fi->fi_where.w_srcfile, fi->fi_where.w_srcline,
                    "here is the original definition");
                goto bad;
        }
        memcpy(base, tail, baselen);
        base[baselen] = '\0';
-       fi->fi_srcfile = yyfile;
-       fi->fi_srcline = currentline();
+       fi->fi_where.w_srcfile = yyfile;
+       fi->fi_where.w_srcline = currentline();
        fi->fi_flags = flags;
        fi->fi_path = path;
        fi->fi_tail = tail;
@@ -204,7 +204,7 @@
                TAILQ_INSERT_TAIL(&allfiles, fi, fi_next);
                break;
        default:
-               cfgxerror(fi->fi_srcfile, fi->fi_srcline,
+               cfgxerror(fi->fi_where.w_srcfile, fi->fi_where.w_srcline,
                    "unknown suffix");
                break;
        }
@@ -262,7 +262,7 @@
        struct files *fi = context;
 
        if (ht_lookup(devbasetab, name) == NULL) {
-               cfgxerror(fi->fi_srcfile, fi->fi_srcline,
+               cfgxerror(fi->fi_where.w_srcfile, fi->fi_where.w_srcline,
                    "`%s' is not a countable device",
                    name);
                /* keep fixfiles() from complaining again */
@@ -356,10 +356,10 @@
                                ofi->fi_flags &= (u_char)~FI_SEL;
                                ofi->fi_flags |= FI_HIDDEN;
                        } else {
-                               cfgxerror(fi->fi_srcfile, fi->fi_srcline,
+                               cfgxerror(fi->fi_where.w_srcfile, fi->fi_where.w_srcline,
                                    "object file collision on %s.o, from %s",
                                    fi->fi_base, fi->fi_path);
-                               cfgxerror(ofi->fi_srcfile, ofi->fi_srcline,
+                               cfgxerror(ofi->fi_where.w_srcfile, ofi->fi_where.w_srcline,
                                    "here is the previous file: %s",
                                    ofi->fi_path);
                                err = 1;
@@ -412,22 +412,25 @@
                if (res != NULL) {
                        if (res->dm_cmajor != dm->dm_cmajor ||
                            res->dm_bmajor != dm->dm_bmajor) {
-                               cfgxerror(res->dm_srcfile, res->dm_srcline,
-                                       "device-major '%s' "
-                                       "block %d, char %d redefined"
-                                       " at %s:%d as block %d, char %d",
-                                       res->dm_name,
-                                       res->dm_bmajor, res->dm_cmajor,
-                                       dm->dm_srcfile, dm->dm_srcline,
-                                       dm->dm_bmajor, dm->dm_cmajor);
+                               cfgxerror(res->dm_where.w_srcfile,
+                                   res->dm_where.w_srcline,
+                                   "device-major '%s' "
+                                   "block %d, char %d redefined"
+                                   " at %s:%d as block %d, char %d",
+                                   res->dm_name,
+                                   res->dm_bmajor, res->dm_cmajor,
+                                   dm->dm_where.w_srcfile, dm->dm_where.w_srcline,
+                                   dm->dm_bmajor, dm->dm_cmajor);
                        } else {
-                               cfgxerror(res->dm_srcfile, res->dm_srcline,
-                                       "device-major '%s' "
-                                       "(block %d, char %d) duplicated"
-                                       " at %s:%d",
-                                       dm->dm_name, dm->dm_bmajor,
-                                       dm->dm_cmajor,
-                                       dm->dm_srcfile, dm->dm_srcline);
+                               cfgxerror(res->dm_where.w_srcfile,
+                                   res->dm_where.w_srcline,
+                                   "device-major '%s' "
+                                   "(block %d, char %d) duplicated"
+                                   " at %s:%d",
+                                   dm->dm_name, dm->dm_bmajor,
+                                   dm->dm_cmajor,
+                                   dm->dm_where.w_srcfile,
+                                   dm->dm_where.w_srcline);
                        }
                        error = 1;
                        goto out;
@@ -443,15 +446,16 @@
 
                if (dm->dm_cmajor != NODEVMAJOR) {
                        if (ht_lookup(cdevmtab, intern(dm->dm_name)) != NULL) {
-                               cfgxerror(dm->dm_srcfile, dm->dm_srcline,
-                                      "device-major of character device '%s' "
-                                      "is already defined", dm->dm_name);
+                               cfgxerror(dm->dm_where.w_srcfile,
+                                   dm->dm_where.w_srcline,
+                                  "device-major of character device '%s' "
+                                  "is already defined", dm->dm_name);
                                error = 1;
                                goto out;
                        }
                        (void)snprintf(mstr, sizeof(mstr), "%d", dm->dm_cmajor);
                        if (ht_lookup(cdevmtab, intern(mstr)) != NULL) {
-                               cfgxerror(dm->dm_srcfile, dm->dm_srcline,
+                               cfgxerror(dm->dm_where.w_srcfile, dm->dm_where.w_srcline,
                                       "device-major of character major '%d' "
                                       "is already defined", dm->dm_cmajor);
                                error = 1;
@@ -465,7 +469,7 @@
                }
                if (dm->dm_bmajor != NODEVMAJOR) {
                        if (ht_lookup(bdevmtab, intern(dm->dm_name)) != NULL) {
-                               cfgxerror(dm->dm_srcfile, dm->dm_srcline,
+                               cfgxerror(dm->dm_where.w_srcfile, dm->dm_where.w_srcline,
                                       "device-major of block device '%s' "
                                       "is already defined", dm->dm_name);
                                error = 1;
@@ -473,7 +477,7 @@
                        }
                        (void)snprintf(mstr, sizeof(mstr), "%d", dm->dm_bmajor);
                        if (ht_lookup(bdevmtab, intern(mstr)) != NULL) {
-                               cfgxerror(dm->dm_srcfile, dm->dm_srcline,
+                               cfgxerror(dm->dm_where.w_srcfile, dm->dm_where.w_srcline,
                                       "device-major of block major '%d' "
                                       "is already defined", dm->dm_bmajor);
                                error = 1;
diff -r bf30fd8e3afb -r c2aa2a3d1e48 usr.bin/config/gram.y
--- a/usr.bin/config/gram.y     Sat Mar 07 18:49:49 2020 +0000
+++ b/usr.bin/config/gram.y     Sat Mar 07 19:26:13 2020 +0000
@@ -1,5 +1,5 @@
 %{
-/*     $NetBSD: gram.y,v 1.54 2016/08/07 10:37:24 christos Exp $       */
+/*     $NetBSD: gram.y,v 1.55 2020/03/07 19:26:13 christos Exp $       */
 
 /*
  * Copyright (c) 1992, 1993



Home | Main Index | Thread Index | Old Index