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 {
34  Item *sp;
35  List *sl;
36  char *s;
37 
38  s = sym->name;
39  /* look in local lists */
40  ITERATE(sl, symlistlist)
41  ITERATE(sp, LST(sl)) {
42  if (strcmp(SYM(sp)->name+2, s) == 0) { /*get past _l*/
43  return SYM(sp);
44  }
45  }
46  return sym;
47 }
48 
49 Symbol *install(char* s, int t) /* install s in the list symbol table with type t*/
50 {
51  Symbol *sp;
52  List *sl;
53 
54  if (t == STRING) {
55  sl = symlist[0];
56  }else if (t == -1) { /*install on top local list see below*/
57  t = NAME;
58  assert(symlistlist->next != symlistlist);
59  sl = LST(symlistlist->next);
60  }else{
61  sl = symlist[s[0]];
62  }
63  sp = (Symbol *) emalloc(sizeof(Symbol));
64  sp->name = stralloc(s, (char *)0);
65  sp->type = t;
66  sp->subtype = 0;
67 #if NMODL
68  sp->nrntype = 0;
69  sp->assigned_to_ = 0;
70  sp->no_threadargs = 0;
71 #if CVODE
72  sp->slist_info_ = (int*)0;
73 #endif
74 #endif
75  sp->u.str = (char *)0;
76  sp->used = 0;
77  sp->usage = 0;
78  sp->araydim = 0;
79  sp->discdim = 0;
80  sp->level = 100; /* larger than any reasonable submodel level */
81  Linsertsym(sl, sp); /*insert at head of list*/
82  return sp;
83 }
84 
85 void pushlocal()
86 {
87  Item * q;
88  q = linsertsym(symlistlist, SYM0); /*the type is irrelevant*/
89  LST(q) = newlist();
90 }
91 
92 void poplocal() /* a lot of storage leakage here for symbols we are guaranteed
93  not to need */
94 {
95  List *sl;
96  Item *i, *j;
97 
98  assert(symlistlist->next != symlistlist);
99  sl = LST(symlistlist->next);
100  for (i = sl->next; i != sl; i = j) {
101  j = i->next;
102  remove(i);
103  }
104  remove(symlistlist->next);
105 }
106 
108 {
109  if (s->name[0] == '_') {
110  Sprintf(buf, "%s", s->name);
111  }else{
112  Sprintf(buf, "_l%s", s->name);
113  }
114  return install(buf, -1);
115 }
116 
char * stralloc(char *buf, char *rel)
Definition: list.cpp:208
#define assert(ex)
Definition: hocassrt.h:26
int usage
Definition: model.h:66
short type
Definition: model.h:58
int discdim
Definition: model.h:68
#define ITERATE(itm, lst)
Definition: model.h:25
#define SYM(q)
Definition: model.h:86
Symbol * lookup(char *s)
Definition: symbol.cpp:22
char * name
Definition: model.h:72
Symbol * copylocal(Symbol *s)
Definition: symbol.cpp:107
struct Item * next
Definition: model.h:19
void pushlocal(Item *q1, Item *qdim)
Definition: symbol.cpp:82
Symbol * install(char *s, int t)
Definition: symbol.cpp:53
Definition: model.h:15
void poplocal()
Definition: symbol.cpp:92
sl
Definition: seclist.cpp:186
Symbol * checklocal(Symbol *sym)
Definition: symbol.cpp:35
_CONST char * s
Definition: system.cpp:74
#define Linsertsym
Definition: model.h:257
void * emalloc(size_t n)
Definition: symbol.cpp:203
#define STRING
Definition: bbslsrv.cpp:9
void symbol_init()
Definition: symbol.cpp:13
size_t j
Definition: model.h:57
char * name
Definition: init.cpp:16
#define LST(q)
Definition: model.h:90
List * newlist()
Definition: list.cpp:50
short level
Definition: model.h:71
NMODL parser global flags / functions.
long subtype
Definition: model.h:59
Item * linsertsym(List *list, Symbol *sym)
Definition: list.cpp:155
int used
Definition: model.h:65
int araydim
Definition: model.h:67
#define i
Definition: md1redef.h:12
List * symlist[128]
Definition: symbol.cpp:8
char buf[512]
Definition: init.cpp:13
#define Sprintf
Definition: model.h:248
union Symbol::@18 u
#define SYM0
Definition: model.h:74
double t
Definition: init.cpp:123
size_t q
char * str
Definition: model.h:63
List * symlistlist
Definition: symbol.cpp:11