numparam, entry_type, #1/5, introduce typedef 'nupa_type'
This commit is contained in:
parent
21f2187530
commit
6a1c9f934c
|
|
@ -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.
|
||||
* ----------------------------------------------------------------- */
|
||||
|
||||
#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 {
|
||||
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;
|
||||
int level; /* subckt nesting level */
|
||||
double vl; /* float value if defined */
|
||||
|
|
@ -52,13 +63,13 @@ typedef struct { /* the input scanner data structure */
|
|||
void initdico(dico_t *);
|
||||
int donedico(dico_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);
|
||||
bool nupa_substitute(dico_t *, char *s, char *r, bool err);
|
||||
bool nupa_assignment(dico_t *, char *s, char mode);
|
||||
bool nupa_subcktcall(dico_t *, char *s, char *x, bool err);
|
||||
void nupa_subcktexit(dico_t *);
|
||||
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);
|
||||
void del_attrib(void *);
|
||||
|
|
|
|||
|
|
@ -224,7 +224,7 @@ findsubname(dico_t *dico, SPICE_DSTRINGPTR dstr_p)
|
|||
cadd(&name, upcase(s[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)
|
||||
{
|
||||
if (is_subckt)
|
||||
defsubckt(dicoS, card, 'U');
|
||||
defsubckt(dicoS, card, NUPA_SUBCKT);
|
||||
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_t *) nghash_enumerateRE(htable_p, &iter))
|
||||
{
|
||||
if (entry->tp == 'R') {
|
||||
if (entry->tp == NUPA_REAL) {
|
||||
spice_dstring_reinit(& dico->lookup_buf);
|
||||
scopy_lower(& dico->lookup_buf, entry->symbol);
|
||||
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');
|
||||
if (entry) {
|
||||
entry->vl = value;
|
||||
entry->tp = 'R';
|
||||
entry->tp = NUPA_REAL;
|
||||
entry->ivl = 0;
|
||||
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');
|
||||
if (entry) {
|
||||
entry->vl = value;
|
||||
entry->tp = 'R';
|
||||
entry->tp = NUPA_REAL;
|
||||
entry->ivl = 0;
|
||||
entry->sbbase = NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue