NEURON
symbol.cpp
Go to the documentation of this file.
1 #include <../../nmodlconf.h>
2 
3 #include "modl.h"
4 #include "parse1.hpp"
5 #include "symbol.h"
6 
7 List* symlist[128]; /* symbol table: linked list
8  first char gives which list to use,but*/
9 
10 List* symlistlist; /* for a stack of local symbol lists */
11 
12 void symbol_init() {
13  int i;
14  symlistlist = newlist();
15  for (i = 0; i < 128; i++) { /* more than we need */
16  symlist[i] = newlist();
17  }
18 }
19 
20 Symbol* lookup(char* s) /* find s in symbol table */
21 {
22  Item* sp;
23 
24  ITERATE(sp, symlist[s[0]]) {
25  if (strcmp(SYM(sp)->name, s) == 0) {
26  return SYM(sp);
27  }
28  }
29  return SYM0; /* 0 ==> not found */
30 }
31 
33  Item* sp;
34  List* sl;
35  char* s;
36 
37  s = sym->name;
38  /* look in local lists */
40  ITERATE(sp, LST(sl)) {
41  if (strcmp(SYM(sp)->name + 2, s) == 0) { /*get past _l*/
42  return SYM(sp);
43  }
44  }
45  return sym;
46 }
47 
48 Symbol* install(char* s, int t) /* install s in the list symbol table with type t*/
49 {
50  Symbol* sp;
51  List* sl;
52 
53  if (t == STRING) {
54  sl = symlist[0];
55  } else if (t == -1) { /*install on top local list see below*/
56  t = NAME;
58  sl = LST(symlistlist->next);
59  } else {
60  sl = symlist[s[0]];
61  }
62  sp = (Symbol*) emalloc(sizeof(Symbol));
63  sp->name = stralloc(s, (char*) 0);
64  sp->type = t;
65  sp->subtype = 0;
66 #if NMODL
67  sp->nrntype = 0;
68  sp->assigned_to_ = 0;
69  sp->no_threadargs = 0;
70 #if CVODE
71  sp->slist_info_ = (int*) 0;
72 #endif
73 #endif
74  sp->u.str = (char*) 0;
75  sp->used = 0;
76  sp->usage = 0;
77  sp->araydim = 0;
78  sp->discdim = 0;
79  sp->level = 100; /* larger than any reasonable submodel level */
80  Linsertsym(sl, sp); /*insert at head of list*/
81  return sp;
82 }
83 
84 void pushlocal() {
85  Item* q;
86  q = linsertsym(symlistlist, SYM0); /*the type is irrelevant*/
87  LST(q) = newlist();
88 }
89 
90 void poplocal() /* a lot of storage leakage here for symbols we are guaranteed
91  not to need */
92 {
93  List* sl;
94  Item *i, *j;
95 
97  sl = LST(symlistlist->next);
98  for (i = sl->next; i != sl; i = j) {
99  j = i->next;
100  remove(i);
101  }
103 }
104 
106  if (s->name[0] == '_') {
107  Sprintf(buf, "%s", s->name);
108  } else {
109  Sprintf(buf, "_l%s", s->name);
110  }
111  return install(buf, -1);
112 }
double t
Definition: cvodeobj.cpp:59
char buf[512]
Definition: init.cpp:13
#define assert(ex)
Definition: hocassrt.h:32
#define i
Definition: md1redef.h:12
#define SYM0
Definition: model.h:74
#define ITERATE(itm, lst)
Definition: model.h:25
#define Linsertsym
Definition: model.h:242
#define SYM(q)
Definition: model.h:86
#define Sprintf
Definition: model.h:233
#define LST(q)
Definition: model.h:90
NMODL parser global flags / functions.
char * name
Definition: init.cpp:16
char * stralloc(char *buf, char *rel)
Definition: list.cpp:184
List * newlist()
Definition: list.cpp:47
Item * linsertsym(List *list, Symbol *sym)
Definition: list.cpp:138
List * symlistlist
Definition: symbol.cpp:11
void symbol_init()
Definition: symbol.cpp:13
Symbol * checklocal(Symbol *sym)
Definition: symbol.cpp:33
Symbol * install(char *s, int t)
Definition: symbol.cpp:49
List * symlist[128]
Definition: symbol.cpp:8
Symbol * lookup(char *s)
Definition: symbol.cpp:21
void pushlocal(Item *q1, Item *qdim)
Definition: symbol.cpp:78
void poplocal()
Definition: symbol.cpp:87
Symbol * copylocal(Symbol *s)
Definition: symbol.cpp:105
size_t q
size_t j
void * emalloc(size_t n)
Definition: symbol.cpp:197
static double remove(void *v)
Definition: ocdeck.cpp:207
#define STRING
Definition: bbslsrv.cpp:9
sl
Definition: seclist.cpp:181
Definition: model.h:15
struct Item * next
Definition: model.h:19
Definition: model.h:57
int usage
Definition: model.h:66
short type
Definition: model.h:58
short level
Definition: model.h:71
int araydim
Definition: model.h:67
long subtype
Definition: model.h:59
union Symbol::@18 u
char * name
Definition: model.h:72
char * str
Definition: model.h:63
int discdim
Definition: model.h:68
int used
Definition: model.h:65