NEURON
symbol.cpp
Go to the documentation of this file.
1 #include <../../nmodlconf.h>
2 /* /local/src/master/nrn/src/modlunit/symbol.c,v 1.1.1.1 1994/10/12 17:22:50 hines Exp */
3 
4 #include "model.h"
5 #include "parse1.hpp"
6 #include "symbol.h"
7 
8 List* symlist[128]; /* symbol table: linked list
9  first char gives which list to use,but*/
10 
11 List* symlistlist; /* for a stack of local symbol lists */
12 
13 void symbol_init() {
14  int i;
15  symlistlist = newlist();
16  for (i = 0; i < 128; i++) { /* more than we need */
17  symlist[i] = newlist();
18  }
19 }
20 
21 Symbol* lookup(char* s) /* find s in symbol table */
22 {
23  Item* sp;
24 
25  ITERATE(sp, symlist[s[0]]) {
26  if (strcmp(SYM(sp)->name, s) == 0) {
27  return SYM(sp);
28  }
29  }
30  return SYM0; /* 0 ==> not found */
31 }
32 
34  Item* sp;
35  List* sl;
36  char* s;
37 
38  s = sym->name;
39  /* look in local lists */
41  ITERATE(sp, (List*) sl->element) {
42  if (strcmp(SYM(sp)->name, s) == 0) {
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;
59  sl = (List*) (symlistlist->next->element);
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  sp->info = ITEM0;
68  sp->u.str = (char*) 0;
69  sp->used = 0;
70  sp->usage = 0;
71  sp->araydim = 0;
72  sp->discdim = 0;
73  sp->level = 100; /* larger than any reasonable submodel level */
74  Linsertsym(sl, sp); /*insert at head of list*/
75  return sp;
76 }
77 
78 void pushlocal(Item* q1, Item* qdim) {
79  Item* q;
80  q = linsertsym(symlistlist, SYM0); /*the type is irrelevant*/
81  q->element = (void*) newlist();
82  if (q1) {
83  install_local(q1, qdim);
84  }
85 }
86 
87 void poplocal() {
88  List* sl;
89  Item *i, *j;
90 
93  for (i = sl->next; i != sl; i = j) {
94  j = i->next;
95  remove(i);
96  }
98 }
99 
100 void install_local(Item* q, Item* qdim) {
101  Symbol* s;
102 
103  s = install(SYM(q)->name, -1);
104  s->subtype = LOCL;
105  if (qdim) {
106  decdim(s, qdim);
107  }
108 }
109 
110 /* symbol.c,v
111  * Revision 1.1.1.1 1994/10/12 17:22:50 hines
112  * NEURON 3.0 distribution
113  *
114  * Revision 1.5 91/01/25 09:31:37 hines
115  * botched last fix
116  *
117  * Revision 1.4 91/01/24 15:25:19 hines
118  * translation error when last token of LOCAL statement was the first token
119  * after the LOCAL statement. Fixed by changing symbols at the parser insteadof the lexical
120  * analyser.
121  *
122  * Revision 1.3 90/12/12 11:33:12 hines
123  * LOCAL vectors allowed. Some more NEURON syntax added
124  *
125  * Revision 1.2 90/11/13 16:10:23 hines
126  * *** empty log message ***
127  *
128  * Revision 1.1 90/07/04 09:21:27 hines
129  * Initial revision
130  * */
double t
Definition: cvodeobj.cpp:59
void decdim(Symbol *s, Item *q)
Definition: declare.cpp:112
#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 ITEM0
Definition: model.h:22
#define LOCL
Definition: model.h:133
#define SYM(q)
Definition: model.h:86
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 install_local(Item *q, Item *qdim)
Definition: symbol.cpp:100
void poplocal()
Definition: symbol.cpp:87
size_t q
for(i=0;i< n;i++)
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
void * element
Definition: model.h:18
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
Item * info
Definition: model.h:60
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