Browse Source

numparam, entry_type, #1/5, introduce typedef 'nupa_type'

pre-master-46
rlar 9 years ago
parent
commit
6a1c9f934c
  1. 17
      src/frontend/numparam/numparam.h
  2. 12
      src/frontend/numparam/spicenum.c
  3. 53
      src/frontend/numparam/xpressn.c

17
src/frontend/numparam/numparam.h

@ -19,8 +19,19 @@ typedef enum {Psp = '{'} _nPsp; /* Ps expression */
* I believe the entry_t should be a union of type but I need more info. * I believe the entry_t should be a union of type but I need more info.
* ----------------------------------------------------------------- */ * ----------------------------------------------------------------- */
#define NUPA_REAL 'R'
#define NUPA_STRING 'S'
#define NUPA_POINTER 'P'
#define NUPA_SUBCKT 'U'
#define NUPA_SPACE ' '
#define NUPA_UNKNOWN '?'
#define NUPA_MODEL 'O'
typedef char nupa_type;
typedef struct entry_s { typedef struct entry_s {
char tp; /* type: I)nt R)eal S)tring F)unction M)acro P)ointer */
nupa_type tp; /* type: I)nt R)eal S)tring F)unction M)acro P)ointer */
char *symbol; char *symbol;
int level; /* subckt nesting level */ int level; /* subckt nesting level */
double vl; /* float value if defined */ double vl; /* float value if defined */
@ -52,13 +63,13 @@ typedef struct { /* the input scanner data structure */
void initdico(dico_t *); void initdico(dico_t *);
int donedico(dico_t *); int donedico(dico_t *);
void dico_free_entry(entry_t *); void dico_free_entry(entry_t *);
bool defsubckt(dico_t *, struct card *, char categ);
bool defsubckt(dico_t *, struct card *, nupa_type categ);
int findsubckt(dico_t *, char *s, SPICE_DSTRINGPTR subname); int findsubckt(dico_t *, char *s, SPICE_DSTRINGPTR subname);
bool nupa_substitute(dico_t *, char *s, char *r, bool err); bool nupa_substitute(dico_t *, char *s, char *r, bool err);
bool nupa_assignment(dico_t *, char *s, char mode); bool nupa_assignment(dico_t *, char *s, char mode);
bool nupa_subcktcall(dico_t *, char *s, char *x, bool err); bool nupa_subcktcall(dico_t *, char *s, char *x, bool err);
void nupa_subcktexit(dico_t *); void nupa_subcktexit(dico_t *);
dico_t *nupa_fetchinstance(void); dico_t *nupa_fetchinstance(void);
char getidtype(dico_t *, char *s);
nupa_type getidtype(dico_t *, char *s);
entry_t *attrib(dico_t *, NGHASHPTR htable, char *t, char op); entry_t *attrib(dico_t *, NGHASHPTR htable, char *t, char op);
void del_attrib(void *); void del_attrib(void *);

12
src/frontend/numparam/spicenum.c

@ -224,7 +224,7 @@ findsubname(dico_t *dico, SPICE_DSTRINGPTR dstr_p)
cadd(&name, upcase(s[j])); cadd(&name, upcase(s[j]));
j++; j++;
} }
found = (getidtype(dico, spice_dstring_value(&name)) == 'U');
found = (getidtype(dico, spice_dstring_value(&name)) == NUPA_SUBCKT);
} }
} }
@ -532,9 +532,9 @@ void
nupa_scan(struct card *card, int is_subckt) nupa_scan(struct card *card, int is_subckt)
{ {
if (is_subckt) if (is_subckt)
defsubckt(dicoS, card, 'U');
defsubckt(dicoS, card, NUPA_SUBCKT);
else else
defsubckt(dicoS, card, 'O');
defsubckt(dicoS, card, NUPA_MODEL);
} }
@ -553,7 +553,7 @@ dump_symbol_table(dico_t *dico, NGHASHPTR htable_p, FILE *fp)
entry; entry;
entry = (entry_t *) nghash_enumerateRE(htable_p, &iter)) entry = (entry_t *) nghash_enumerateRE(htable_p, &iter))
{ {
if (entry->tp == 'R') {
if (entry->tp == NUPA_REAL) {
spice_dstring_reinit(& dico->lookup_buf); spice_dstring_reinit(& dico->lookup_buf);
scopy_lower(& dico->lookup_buf, entry->symbol); scopy_lower(& dico->lookup_buf, entry->symbol);
name = spice_dstring_value(& dico->lookup_buf); name = spice_dstring_value(& dico->lookup_buf);
@ -660,7 +660,7 @@ nupa_add_param(char *param_name, double value)
entry = attrib(dico, htable_p, up_name, 'N'); entry = attrib(dico, htable_p, up_name, 'N');
if (entry) { if (entry) {
entry->vl = value; entry->vl = value;
entry->tp = 'R';
entry->tp = NUPA_REAL;
entry->ivl = 0; entry->ivl = 0;
entry->sbbase = NULL; entry->sbbase = NULL;
} }
@ -687,7 +687,7 @@ nupa_add_inst_param(char *param_name, double value)
entry = attrib(dico, dico->inst_symbols, up_name, 'N'); entry = attrib(dico, dico->inst_symbols, up_name, 'N');
if (entry) { if (entry) {
entry->vl = value; entry->vl = value;
entry->tp = 'R';
entry->tp = NUPA_REAL;
entry->ivl = 0; entry->ivl = 0;
entry->sbbase = NULL; entry->sbbase = NULL;
} }

53
src/frontend/numparam/xpressn.c

@ -389,7 +389,7 @@ entrynb(dico_t *dico, char *s)
} }
char
nupa_type
getidtype(dico_t *dico, char *s) getidtype(dico_t *dico, char *s)
/* test if identifier s is known. Answer its type, or '?' if not in table */ /* test if identifier s is known. Answer its type, or '?' if not in table */
{ {
@ -398,7 +398,7 @@ getidtype(dico_t *dico, char *s)
if (entry) if (entry)
return entry->tp; return entry->tp;
return '?';
return NUPA_UNKNOWN;
} }
@ -407,10 +407,10 @@ fetchnumentry(dico_t *dico, char *s, bool *perr)
{ {
entry_t *entry = entrynb(dico, s); entry_t *entry = entrynb(dico, s);
while (entry && (entry->tp == 'P'))
while (entry && (entry->tp == NUPA_POINTER))
entry = entry->pointer; entry = entry->pointer;
if (entry && (entry->tp == 'R'))
if (entry && (entry->tp == NUPA_REAL))
return entry->vl; return entry->vl;
*perr = message(dico, "Undefined number [%s]\n", s); *perr = message(dico, "Undefined number [%s]\n", s);
@ -430,7 +430,7 @@ attrib(dico_t *dico, NGHASHPTR htable_p, char *t, char op)
entry = (entry_t *) nghash_find(htable_p, t); entry = (entry_t *) nghash_find(htable_p, t);
if (entry && (op == 'N') && if (entry && (op == 'N') &&
(entry->level < dico->stack_depth) && (entry->tp != '?'))
(entry->level < dico->stack_depth) && (entry->tp != NUPA_UNKNOWN))
{ {
entry = NULL; entry = NULL;
} }
@ -438,7 +438,7 @@ attrib(dico_t *dico, NGHASHPTR htable_p, char *t, char op)
if (!entry) { if (!entry) {
entry = TMALLOC(entry_t, 1); entry = TMALLOC(entry_t, 1);
entry->symbol = strdup(t); entry->symbol = strdup(t);
entry->tp = '?'; /* signal Unknown */
entry->tp = NUPA_UNKNOWN; /* signal Unknown */
entry->level = dico->stack_depth; entry->level = dico->stack_depth;
nghash_insert(htable_p, t, entry); nghash_insert(htable_p, t, entry);
} }
@ -467,7 +467,7 @@ static bool
nupa_define(dico_t *dico, nupa_define(dico_t *dico,
char *t, /* identifier to define */ char *t, /* identifier to define */
char op, /* option */ char op, /* option */
char tpe, /* type marker */
nupa_type tpe, /* type marker */
double z, /* float value if any */ double z, /* float value if any */
int w, /* integer value if any */ int w, /* integer value if any */
char *base) /* string pointer if any */ char *base) /* string pointer if any */
@ -480,7 +480,7 @@ nupa_define(dico_t *dico,
we already make symbol entries which are dummy globals ! we already make symbol entries which are dummy globals !
we mark each id with its subckt level, and warn if write at higher one. we mark each id with its subckt level, and warn if write at higher one.
*/ */
char c;
nupa_type c;
bool warn; bool warn;
entry_t *entry; /* spice table entry */ entry_t *entry; /* spice table entry */
NGHASHPTR htable_p; /* hash table */ NGHASHPTR htable_p; /* hash table */
@ -496,22 +496,22 @@ nupa_define(dico_t *dico,
if (!entry) if (!entry)
return message(dico, " Symbol table overflow\n"); return message(dico, " Symbol table overflow\n");
if (entry->tp == 'P')
if (entry->tp == NUPA_POINTER)
entry = entry->pointer; /* pointer indirection */ entry = entry->pointer; /* pointer indirection */
if (entry) if (entry)
c = entry->tp; c = entry->tp;
else else
c = ' ';
c = NUPA_SPACE;
if ((c == 'R') || (c == 'S') || (c == '?')) {
if ((c == NUPA_REAL) || (c == NUPA_STRING) || (c == NUPA_UNKNOWN)) {
entry->vl = z; entry->vl = z;
entry->tp = tpe; entry->tp = tpe;
entry->ivl = w; entry->ivl = w;
entry->sbbase = base; entry->sbbase = base;
/* if ((c != '?') && (i <= dico->stack[dico->tos])) { */ /* if ((c != '?') && (i <= dico->stack[dico->tos])) { */
if (c == '?')
if (c == NUPA_UNKNOWN)
entry->level = dico->stack_depth; /* promote! */ entry->level = dico->stack_depth; /* promote! */
/* warn about re-write to a global scope! */ /* warn about re-write to a global scope! */
@ -533,7 +533,7 @@ nupa_define(dico_t *dico,
bool bool
defsubckt(dico_t *dico, struct card *card, char categ)
defsubckt(dico_t *dico, struct card *card, nupa_type categ)
/* called on 1st pass of spice source code, /* called on 1st pass of spice source code,
to enter subcircuit (categ=U) and model (categ=O) names to enter subcircuit (categ=U) and model (categ=O) names
*/ */
@ -601,7 +601,7 @@ findsubckt(dico_t *dico, char *s, SPICE_DSTRINGPTR subname)
pscopy_up(&ustr, s, k + 1, j - k); pscopy_up(&ustr, s, k + 1, j - k);
entry = entrynb(dico, spice_dstring_value(&ustr)); entry = entrynb(dico, spice_dstring_value(&ustr));
if (entry && (entry->tp == 'U')) {
if (entry && (entry->tp == NUPA_SUBCKT)) {
line = entry->ivl; line = entry->ivl;
scopyd(subname, &ustr); scopyd(subname, &ustr);
} else { } else {
@ -1114,7 +1114,7 @@ evaluate(dico_t *dico, SPICE_DSTRINGPTR qstr_p, char *t, unsigned char mode)
/* transform t to result q. mode 0: expression, mode 1: simple variable */ /* transform t to result q. mode 0: expression, mode 1: simple variable */
double u = 0.0; double u = 0.0;
int j, lq; int j, lq;
char dt;
nupa_type dt;
entry_t *entry; entry_t *entry;
bool numeric, done, nolookup; bool numeric, done, nolookup;
bool err; bool err;
@ -1129,7 +1129,7 @@ evaluate(dico_t *dico, SPICE_DSTRINGPTR qstr_p, char *t, unsigned char mode)
entry = entrynb(dico, t); entry = entrynb(dico, t);
nolookup = !entry; nolookup = !entry;
while (entry && (entry->tp == 'P'))
while (entry && (entry->tp == NUPA_POINTER))
entry = entry->pointer; /* follow pointer chain */ entry = entry->pointer; /* follow pointer chain */
if (!entry) if (!entry)
@ -1140,10 +1140,10 @@ evaluate(dico_t *dico, SPICE_DSTRINGPTR qstr_p, char *t, unsigned char mode)
dt = entry->tp; dt = entry->tp;
/* data type: Real or String */ /* data type: Real or String */
if (dt == 'R') {
if (dt == NUPA_REAL) {
u = entry->vl; u = entry->vl;
numeric = 1; numeric = 1;
} else if (dt == 'S') {
} else if (dt == NUPA_STRING) {
/* suppose source text "..." at */ /* suppose source text "..." at */
j = entry->ivl; j = entry->ivl;
lq = 0; lq = 0;
@ -1383,7 +1383,7 @@ getword(char *s, SPICE_DSTRINGPTR tstr_p, int after, int *pi)
} }
static char
static nupa_type
getexpress(char *s, SPICE_DSTRINGPTR tstr_p, int *pi) getexpress(char *s, SPICE_DSTRINGPTR tstr_p, int *pi)
/* returns expression-like string until next separator /* returns expression-like string until next separator
Input i=position before expr, output i=just after expr, on separator. Input i=position before expr, output i=just after expr, on separator.
@ -1392,7 +1392,8 @@ getexpress(char *s, SPICE_DSTRINGPTR tstr_p, int *pi)
{ {
int i = *pi; int i = *pi;
int ia, ls, level; int ia, ls, level;
char c, d, tpe;
char c, d;
nupa_type tpe;
ls = length(s); ls = length(s);
ia = i + 1; ia = i + 1;
@ -1408,7 +1409,7 @@ getexpress(char *s, SPICE_DSTRINGPTR tstr_p, int *pi)
while ((i < ls) && (s[i - 1] != '"')) while ((i < ls) && (s[i - 1] != '"'))
i++; i++;
tpe = 'S';
tpe = NUPA_STRING;
do do
i++; i++;
@ -1452,7 +1453,7 @@ getexpress(char *s, SPICE_DSTRINGPTR tstr_p, int *pi)
} while (!(cpos (c, ",;)}") >= 0)); /* legal separators */ } while (!(cpos (c, ",;)}") >= 0)); /* legal separators */
tpe = 'R';
tpe = NUPA_REAL;
} }
pscopy(tstr_p, s, ia-1, i - ia); pscopy(tstr_p, s, ia-1, i - ia);
@ -1460,7 +1461,7 @@ getexpress(char *s, SPICE_DSTRINGPTR tstr_p, int *pi)
if (s[i - 1] == '}') if (s[i - 1] == '}')
i++; i++;
if (tpe == 'S')
if (tpe == NUPA_STRING)
i++; /* beyond quote */ i++; /* beyond quote */
*pi = i; *pi = i;
@ -1480,7 +1481,7 @@ nupa_assignment(dico_t *dico, char *s, char mode)
/* s has the format: ident = expression; ident= expression ... */ /* s has the format: ident = expression; ident= expression ... */
int i, ls; int i, ls;
bool error, err; bool error, err;
char dtype;
nupa_type dtype;
int wval = 0; int wval = 0;
double rval = 0.0; double rval = 0.0;
char *t_p; /* dstring contents value */ char *t_p; /* dstring contents value */
@ -1520,14 +1521,14 @@ nupa_assignment(dico_t *dico, char *s, char mode)
dtype = getexpress(s, &ustr, &i); dtype = getexpress(s, &ustr, &i);
if (dtype == 'R') {
if (dtype == NUPA_REAL) {
const char *tmp = spice_dstring_value(&ustr); const char *tmp = spice_dstring_value(&ustr);
rval = formula(dico, tmp, tmp + strlen(tmp), &error); rval = formula(dico, tmp, tmp + strlen(tmp), &error);
if (error) if (error)
message(dico, message(dico,
" Formula() error.\n" " Formula() error.\n"
" %s\n", s); " %s\n", s);
} else if (dtype == 'S') {
} else if (dtype == NUPA_STRING) {
wval = i; wval = i;
} }

Loading…
Cancel
Save