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