From c9517c397b70f24ac006ca6fffa591c72bf8369c Mon Sep 17 00:00:00 2001 From: h_vogt Date: Fri, 4 Nov 2016 22:01:55 +0100 Subject: [PATCH] lists struct pt_temper *modtlist and struct pt_temper *devtlist contain parse trees handling TEMPER equations in model or instance lines. Create new lists upon entering inp_parse_temper(). Save pointers to lists in current circuit ft_curckt. Upon changing circuit, reload lists from ft_curckt. Upon removing current circuit, delete lists. --- src/frontend/inp.c | 44 +++++++++++++++++++++++++---------- src/frontend/runcoms.c | 2 ++ src/frontend/runcoms2.c | 2 ++ src/include/ngspice/ftedefs.h | 17 ++++++++++++-- src/include/ngspice/fteext.h | 6 +++-- 5 files changed, 55 insertions(+), 16 deletions(-) diff --git a/src/frontend/inp.c b/src/frontend/inp.c index f0b738142..78fba68cc 100644 --- a/src/frontend/inp.c +++ b/src/frontend/inp.c @@ -69,18 +69,6 @@ void inp_evaluate_temper(void); extern bool ft_batchmode; -/* structure used to save expression parse trees for .model and - * device instance lines - */ - -struct pt_temper { - char *expression; - wordlist *wl; - wordlist *wlend; - INPparseTree *pt; - struct pt_temper *next; -}; - /* * create an unique artificial *unusable* FILE ptr * meant to be used with Xprintf() only to eventually @@ -1697,9 +1685,13 @@ inp_parse_temper(struct line *card) { int error = 0; char *end_tstr, *beg_tstr, *beg_pstr, *str_ptr, *devmodname, *paramname; + /* reset lists */ + modtlist = NULL; + devtlist = NULL; /* skip title line */ card = card->li_next; + for (; card; card = card->li_next) { char *curr_line = card->li_line; @@ -1830,11 +1822,39 @@ inp_parse_temper_trees(void) for(d = devtlist; d; d = d->next) INPgetTree(&d->expression, &d->pt, ft_curckt->ci_ckt, NULL); + ft_curckt->devtlist = devtlist; for(d = modtlist; d; d = d->next) INPgetTree(&d->expression, &d->pt, ft_curckt->ci_ckt, NULL); + ft_curckt->modtlist = modtlist; } + /* set modtlist and devtlist. Called from com_scirc(), when another circuit is selected */ +void +set_tlist(struct circ *curckt) +{ + modtlist = curckt->modtlist; + devtlist = curckt->devtlist; + expr_w_temper = (modtlist || devtlist); +} + +/* remove the actual modtlist and devtlist */ +void +rem_tlist(void) +{ + if (devtlist) { + // tfree(devtlist->expression); + wl_free(devtlist->wl); + /*should we remove the parse tree pt ?*/ + tfree(devtlist); + } + if (modtlist) { + // tfree(modtlist->expression); + wl_free(modtlist->wl); + /*should we remove the parse tree pt ?*/ + tfree(modtlist); + } +} void inp_evaluate_temper(void) diff --git a/src/frontend/runcoms.c b/src/frontend/runcoms.c index 1b58e0215..31c299e6f 100644 --- a/src/frontend/runcoms.c +++ b/src/frontend/runcoms.c @@ -112,6 +112,8 @@ com_scirc(wordlist *wl) dbs = ft_curckt->ci_dbs; /* set the numparam dicos structure for use with measure */ nupa_set_dicoslist(ft_curckt->ci_dicos); + /* set the temper lists */ + set_tlist(ft_curckt); } diff --git a/src/frontend/runcoms2.c b/src/frontend/runcoms2.c index 1bce6bfce..756a85a94 100644 --- a/src/frontend/runcoms2.c +++ b/src/frontend/runcoms2.c @@ -259,6 +259,7 @@ com_remcirc(wordlist *wl) tfree(ft_curckt->ci_name); if (ft_curckt->ci_filename) tfree(ft_curckt->ci_filename); + rem_tlist(); /* delete the actual circuit entry from ft_circuits */ for (p = ft_circuits; p; p = p->ci_next) { @@ -284,5 +285,6 @@ com_remcirc(wordlist *wl) modtab = ft_curckt->ci_modtab; dbs = ft_curckt->ci_dbs; nupa_set_dicoslist(ft_curckt->ci_dicos); + set_tlist(ft_curckt); } } diff --git a/src/include/ngspice/ftedefs.h b/src/include/ngspice/ftedefs.h index e4206cea2..540f04556 100644 --- a/src/include/ngspice/ftedefs.h +++ b/src/include/ngspice/ftedefs.h @@ -25,7 +25,19 @@ struct save_info { int used; }; -/* The curcuits that are currently available to the user. */ + +/* structure used to save expression parse trees for .model and +* device instance lines +*/ +struct pt_temper { + char *expression; + wordlist *wl; + wordlist *wlend; + INPparseTree *pt; + struct pt_temper *next; +}; + +/* The circuits that are currently available to the user. */ struct circ { char *ci_name; /* What the circuit can be called. */ @@ -54,7 +66,8 @@ struct circ { JOB *ci_curOpt; /* the most recent options anal. for the circuit */ char *ci_last_an; /* name of last analysis run */ int ci_dicos; /* index to the numparam dicoS structure for this circuit*/ - + struct pt_temper *modtlist; /* List of all expressions with 'temper' in .model lines */ + struct pt_temper *devtlist; /* List of all expressions with 'temper' in device instance lines */ FTESTATistics *FTEstats; /* Statistics for the front end */ } ; diff --git a/src/include/ngspice/fteext.h b/src/include/ngspice/fteext.h index 946ee6965..a885c7d3c 100644 --- a/src/include/ngspice/fteext.h +++ b/src/include/ngspice/fteext.h @@ -207,7 +207,7 @@ extern bool gr_circular; /* inp.c */ void inp_dodeck(struct line *deck, char *tt, wordlist *end, bool reuse, - struct line *options, char *filename); + struct line *options, char *filename); extern void inp_source(char *file); void inp_spsource(FILE *fp, bool comfile, char *filename, bool intfile); extern void inp_casefix(char *string); @@ -221,12 +221,14 @@ extern void mc_free(void); void eval_seed_opt(struct line *deck); extern char** circarray; +extern void set_tlist(struct circ *curckt); +extern void rem_tlist(void); /* nutinp.c */ void inp_nutsource(FILE *fp, bool comfile, char *filename); void nutinp_dodeck(struct line *deck, char *tt, wordlist *end, bool reuse, - struct line *options, char *filename); + struct line *options, char *filename); extern void nutcom_source(wordlist *wl); /* interpolate.c */