|
|
|
@ -389,7 +389,7 @@ entrynb(dico_t *dico, char *s) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
char |
|
|
|
nupa_type |
|
|
|
getidtype(dico_t *dico, char *s) |
|
|
|
/* 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) |
|
|
|
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); |
|
|
|
|
|
|
|
while (entry && (entry->tp == 'P')) |
|
|
|
while (entry && (entry->tp == NUPA_POINTER)) |
|
|
|
entry = entry->pointer; |
|
|
|
|
|
|
|
if (entry && (entry->tp == 'R')) |
|
|
|
if (entry && (entry->tp == NUPA_REAL)) |
|
|
|
return entry->vl; |
|
|
|
|
|
|
|
*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); |
|
|
|
if (entry && (op == 'N') && |
|
|
|
(entry->level < dico->stack_depth) && (entry->tp != '?')) |
|
|
|
(entry->level < dico->stack_depth) && (entry->tp != NUPA_UNKNOWN)) |
|
|
|
{ |
|
|
|
entry = NULL; |
|
|
|
} |
|
|
|
@ -438,7 +438,7 @@ attrib(dico_t *dico, NGHASHPTR htable_p, char *t, char op) |
|
|
|
if (!entry) { |
|
|
|
entry = TMALLOC(entry_t, 1); |
|
|
|
entry->symbol = strdup(t); |
|
|
|
entry->tp = '?'; /* signal Unknown */ |
|
|
|
entry->tp = NUPA_UNKNOWN; /* signal Unknown */ |
|
|
|
entry->level = dico->stack_depth; |
|
|
|
nghash_insert(htable_p, t, entry); |
|
|
|
} |
|
|
|
@ -467,7 +467,7 @@ static bool |
|
|
|
nupa_define(dico_t *dico, |
|
|
|
char *t, /* identifier to define */ |
|
|
|
char op, /* option */ |
|
|
|
char tpe, /* type marker */ |
|
|
|
nupa_type tpe, /* type marker */ |
|
|
|
double z, /* float value if any */ |
|
|
|
int w, /* integer value 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 mark each id with its subckt level, and warn if write at higher one. |
|
|
|
*/ |
|
|
|
char c; |
|
|
|
nupa_type c; |
|
|
|
bool warn; |
|
|
|
entry_t *entry; /* spice table entry */ |
|
|
|
NGHASHPTR htable_p; /* hash table */ |
|
|
|
@ -496,22 +496,22 @@ nupa_define(dico_t *dico, |
|
|
|
if (!entry) |
|
|
|
return message(dico, " Symbol table overflow\n"); |
|
|
|
|
|
|
|
if (entry->tp == 'P') |
|
|
|
if (entry->tp == NUPA_POINTER) |
|
|
|
entry = entry->pointer; /* pointer indirection */ |
|
|
|
|
|
|
|
if (entry) |
|
|
|
c = entry->tp; |
|
|
|
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->tp = tpe; |
|
|
|
entry->ivl = w; |
|
|
|
entry->sbbase = base; |
|
|
|
/* if ((c != '?') && (i <= dico->stack[dico->tos])) { */ |
|
|
|
if (c == '?') |
|
|
|
if (c == NUPA_UNKNOWN) |
|
|
|
entry->level = dico->stack_depth; /* promote! */ |
|
|
|
|
|
|
|
/* warn about re-write to a global scope! */ |
|
|
|
@ -533,7 +533,7 @@ nupa_define(dico_t *dico, |
|
|
|
|
|
|
|
|
|
|
|
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, |
|
|
|
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); |
|
|
|
entry = entrynb(dico, spice_dstring_value(&ustr)); |
|
|
|
|
|
|
|
if (entry && (entry->tp == 'U')) { |
|
|
|
if (entry && (entry->tp == NUPA_SUBCKT)) { |
|
|
|
line = entry->ivl; |
|
|
|
scopyd(subname, &ustr); |
|
|
|
} 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 */ |
|
|
|
double u = 0.0; |
|
|
|
int j, lq; |
|
|
|
char dt; |
|
|
|
nupa_type dt; |
|
|
|
entry_t *entry; |
|
|
|
bool numeric, done, nolookup; |
|
|
|
bool err; |
|
|
|
@ -1129,7 +1129,7 @@ evaluate(dico_t *dico, SPICE_DSTRINGPTR qstr_p, char *t, unsigned char mode) |
|
|
|
entry = entrynb(dico, t); |
|
|
|
nolookup = !entry; |
|
|
|
|
|
|
|
while (entry && (entry->tp == 'P')) |
|
|
|
while (entry && (entry->tp == NUPA_POINTER)) |
|
|
|
entry = entry->pointer; /* follow pointer chain */ |
|
|
|
|
|
|
|
if (!entry) |
|
|
|
@ -1140,10 +1140,10 @@ evaluate(dico_t *dico, SPICE_DSTRINGPTR qstr_p, char *t, unsigned char mode) |
|
|
|
dt = entry->tp; |
|
|
|
|
|
|
|
/* data type: Real or String */ |
|
|
|
if (dt == 'R') { |
|
|
|
if (dt == NUPA_REAL) { |
|
|
|
u = entry->vl; |
|
|
|
numeric = 1; |
|
|
|
} else if (dt == 'S') { |
|
|
|
} else if (dt == NUPA_STRING) { |
|
|
|
/* suppose source text "..." at */ |
|
|
|
j = entry->ivl; |
|
|
|
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) |
|
|
|
/* returns expression-like string until next 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 ia, ls, level; |
|
|
|
char c, d, tpe; |
|
|
|
char c, d; |
|
|
|
nupa_type tpe; |
|
|
|
|
|
|
|
ls = length(s); |
|
|
|
ia = i + 1; |
|
|
|
@ -1408,7 +1409,7 @@ getexpress(char *s, SPICE_DSTRINGPTR tstr_p, int *pi) |
|
|
|
while ((i < ls) && (s[i - 1] != '"')) |
|
|
|
i++; |
|
|
|
|
|
|
|
tpe = 'S'; |
|
|
|
tpe = NUPA_STRING; |
|
|
|
|
|
|
|
do |
|
|
|
i++; |
|
|
|
@ -1452,7 +1453,7 @@ getexpress(char *s, SPICE_DSTRINGPTR tstr_p, int *pi) |
|
|
|
|
|
|
|
} while (!(cpos (c, ",;)}") >= 0)); /* legal separators */ |
|
|
|
|
|
|
|
tpe = 'R'; |
|
|
|
tpe = NUPA_REAL; |
|
|
|
} |
|
|
|
|
|
|
|
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] == '}') |
|
|
|
i++; |
|
|
|
|
|
|
|
if (tpe == 'S') |
|
|
|
if (tpe == NUPA_STRING) |
|
|
|
i++; /* beyond quote */ |
|
|
|
|
|
|
|
*pi = i; |
|
|
|
@ -1480,7 +1481,7 @@ nupa_assignment(dico_t *dico, char *s, char mode) |
|
|
|
/* s has the format: ident = expression; ident= expression ... */ |
|
|
|
int i, ls; |
|
|
|
bool error, err; |
|
|
|
char dtype; |
|
|
|
nupa_type dtype; |
|
|
|
int wval = 0; |
|
|
|
double rval = 0.0; |
|
|
|
char *t_p; /* dstring contents value */ |
|
|
|
@ -1520,14 +1521,14 @@ nupa_assignment(dico_t *dico, char *s, char mode) |
|
|
|
|
|
|
|
dtype = getexpress(s, &ustr, &i); |
|
|
|
|
|
|
|
if (dtype == 'R') { |
|
|
|
if (dtype == NUPA_REAL) { |
|
|
|
const char *tmp = spice_dstring_value(&ustr); |
|
|
|
rval = formula(dico, tmp, tmp + strlen(tmp), &error); |
|
|
|
if (error) |
|
|
|
message(dico, |
|
|
|
" Formula() error.\n" |
|
|
|
" %s\n", s); |
|
|
|
} else if (dtype == 'S') { |
|
|
|
} else if (dtype == NUPA_STRING) { |
|
|
|
wval = i; |
|
|
|
} |
|
|
|
|
|
|
|
|