From ca4cd4878617c8aaf15de1e90c93f507def5fe6d Mon Sep 17 00:00:00 2001 From: rlar Date: Sun, 11 Mar 2012 21:28:44 +0100 Subject: [PATCH] subs, pass global `subs' by reference, EXACT global subs0 used and modified in doit() passed to translate() translate() pass only to nunmodes() numnodes() doesn't modify --- src/frontend/subckt.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/src/frontend/subckt.c b/src/frontend/subckt.c index bfb1bcf32..fba78dc62 100644 --- a/src/frontend/subckt.c +++ b/src/frontend/subckt.c @@ -77,14 +77,15 @@ extern void line_free_x(struct line * deck, bool recurse); #define line_free(line,flag) { line_free_x(line,flag); line = NULL; } /* ----- static declarations ----- */ +struct subs; static struct line * doit(struct line *deck); static int translate(struct line *deck, char *formal, char *actual, char *scname, - char *subname); + char *subname, struct subs * const * const subs2); struct bxx_buffer; static void finishLine(struct bxx_buffer *dst, char *src, char *scname); static int settrans(char *formal, char *actual, char *subname); static char * gettrans(const char *name, const char *name_end); -static int numnodes(char *name); +static int numnodes(char *name, struct subs * const * const subs3); static int numdevs(char *s); static bool modtranslate(struct line *deck, char *subname); static void devmodtranslate(struct line *deck, char *subname); @@ -119,7 +120,7 @@ struct subs { */ static wordlist *modnames, *submod; -static struct subs *subs = NULL; +static struct subs *subs0 = NULL; static bool nobjthack = FALSE; /* flag indicating use of the experimental numparams library */ static bool use_numparams = FALSE; @@ -401,11 +402,11 @@ doit(struct line *deck) { bool gotone; wordlist *tmodnames = modnames; wordlist *tsubmod = submod; - struct subs *ts = subs; + struct subs *ts = subs0; int error; /* Save all the old stuff... */ - subs = NULL; + subs0 = NULL; submod = NULL; #ifdef TRACE @@ -509,8 +510,8 @@ doit(struct line *deck) { } } - sss->su_next = subs; - subs = sss; /* Now that sss is built, assign it to subs */ + sss->su_next = subs0; + subs0 = sss; /* Now that sss is built, assign it to subs */ last = c->li_next; @@ -536,10 +537,10 @@ doit(struct line *deck) { /* Otherwise, expand sub-subcircuits recursively. */ { struct subs *ks; - for (ks = sss = subs; sss; sss = sss->su_next) /* iterate through the list of subcircuits */ + for (ks = sss = subs0; sss; sss = sss->su_next) /* iterate through the list of subcircuits */ if ((sss->su_def = doit(sss->su_def)) == NULL) return (NULL); - subs = ks; /* ks has held pointer to start of subcircuits list. */ + subs0 = ks; /* ks has held pointer to start of subcircuits list. */ } #ifdef TRACE @@ -590,7 +591,7 @@ doit(struct line *deck) { s++; /* iterate through .subckt list and look for .subckt name invoked */ - for (sss = subs; sss; sss = sss->su_next) + for (sss = subs0; sss; sss = sss->su_next) if (eq(sss->su_name, s)) break; @@ -629,7 +630,7 @@ doit(struct line *deck) { /* now invoke translate, which handles the remainder of the * translation. */ - if (!translate(lcc, s, t, scname, subname)) + if (!translate(lcc, s, t, scname, subname, &subs0)) error = 1; tfree(subname); } @@ -690,7 +691,7 @@ doit(struct line *deck) { if (error) return NULL; /* error message already reported; should free( ) */ - subs = ts; + subs0 = ts; modnames = tmodnames; submod = tsubmod; /* @@ -891,7 +892,7 @@ bxx_buffer(struct bxx_buffer *t) * subname = copy of the subcircuit name *-------------------------------------------------------------------------------------------*/ static int -translate(struct line *deck, char *formal, char *actual, char *scname, char *subname) +translate(struct line *deck, char *formal, char *actual, char *scname, char *subname, struct subs * const * const subs2) { struct line *c; struct bxx_buffer buffer; @@ -1079,7 +1080,7 @@ translate(struct line *deck, char *formal, char *actual, char *scname, char *sub tfree(t); /* Next iterate over all nodes (netnames) found and translate them. */ - nnodes = numnodes(c->li_line); + nnodes = numnodes(c->li_line, subs2); while (nnodes-- > 0) { name = gettok_node(&s); @@ -1224,7 +1225,7 @@ translate(struct line *deck, char *formal, char *actual, char *scname, char *sub tfree(nametofree); /* Next iterate over all nodes (netnames) found and translate them. */ - nnodes = numnodes(c->li_line); + nnodes = numnodes(c->li_line, subs2); while (nnodes-- > 0) { name = gettok_node(&s); if (name == NULL ) { @@ -1504,7 +1505,7 @@ model_bin_match( char* token, char* model_name ) /*-------------------------------------------------------------------*/ /*-------------------------------------------------------------------*/ static int -numnodes(char *name) +numnodes(char *name, struct subs * const * const subs3) { /* gtri - comment - wbk - 10/23/90 - Do not modify this routine for */ /* 'A' type devices since the callers will not know how to find the */ @@ -1535,7 +1536,7 @@ numnodes(char *name) while ((*s != ' ') && (*s != '\t')) s--; s++; - for (sss = subs; sss; sss = sss->su_next) + for (sss = *subs3; sss; sss = sss->su_next) if (eq(sss->su_name, s)) return (sss->su_numargs); /*