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 *
22 lookup(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 
34 Symbol *
36 {
37  Item *sp;
38  List *sl;
39  char *s;
40 
41  s = sym->name;
42  /* look in local lists */
43  ITERATE(sl, symlistlist)
44  ITERATE(sp, (List *)sl->element) {
45  if (strcmp(SYM(sp)->name, s) == 0) {
46  return SYM(sp);
47  }
48  }
49  return sym;
50 }
51 
52 Symbol *
53 install(char* s, int t) /* install s in the list symbol table with type t*/
54 {
55  Symbol *sp;
56  List *sl;
57 
58  if (t == STRING) {
59  sl = symlist[0];
60  }else if (t == -1) { /*install on top local list see below*/
61  t = NAME;
62  assert(symlistlist->next != symlistlist);
63  sl = (List *)(symlistlist->next->element);
64  }else{
65  sl = symlist[s[0]];
66  }
67  sp = (Symbol *) emalloc(sizeof(Symbol));
68  sp->name = stralloc(s, (char *)0);
69  sp->type = t;
70  sp->subtype = 0;
71  sp->info = ITEM0;
72  sp->u.str = (char *)0;
73  sp->used = 0;
74  sp->usage = 0;
75  sp->araydim = 0;
76  sp->discdim = 0;
77  sp->level = 100; /* larger than any reasonable submodel level */
78  Linsertsym(sl, sp); /*insert at head of list*/
79  return sp;
80 }
81 
82 void pushlocal(Item* q1, Item* qdim)
83 {
84  Item * q;
85  q = linsertsym(symlistlist, SYM0); /*the type is irrelevant*/
86  q->element = (void *)newlist();
87  if (q1) {
88  install_local(q1, qdim);
89  }
90 }
91 
92 void poplocal()
93 {
94  List *sl;
95  Item *i, *j;
96 
97  assert(symlistlist->next != symlistlist);
98  sl = (List *)symlistlist->next->element;
99  for (i = sl->next; i != sl; i = j) {
100  j = i->next;
101  remove(i);
102  }
103  remove(symlistlist->next);
104 }
105 
106 void install_local(Item* q, Item* qdim)
107 {
108  Symbol *s;
109 
110  s = install(SYM(q)->name, -1);
111  s->subtype = LOCL;
112  if (qdim) {
113  decdim(s, qdim);
114  }
115 }
116 
117 /* symbol.c,v
118  * Revision 1.1.1.1 1994/10/12 17:22:50 hines
119  * NEURON 3.0 distribution
120  *
121  * Revision 1.5 91/01/25 09:31:37 hines
122  * botched last fix
123  *
124  * Revision 1.4 91/01/24 15:25:19 hines
125  * translation error when last token of LOCAL statement was the first token
126  * after the LOCAL statement. Fixed by changing symbols at the parser insteadof the lexical analyser.
127  *
128  * Revision 1.3 90/12/12 11:33:12 hines
129  * LOCAL vectors allowed. Some more NEURON syntax added
130  *
131  * Revision 1.2 90/11/13 16:10:23 hines
132  * *** empty log message ***
133  *
134  * Revision 1.1 90/07/04 09:21:27 hines
135  * Initial revision
136  * */
137 
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
#define ITEM0
Definition: model.h:22
char * name
Definition: model.h:72
void decdim(Symbol *s, Item *q)
Definition: declare.cpp:117
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
void * element
Definition: model.h:18
List * newlist()
Definition: list.cpp:50
void install_local(Item *q, Item *qdim)
Definition: symbol.cpp:106
short level
Definition: model.h:71
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
Item * info
Definition: model.h:60
union Symbol::@18 u
#define SYM0
Definition: model.h:74
double t
Definition: init.cpp:123
for(i=0;i< n;i++)
size_t q
#define LOCL
Definition: model.h:133
char * str
Definition: model.h:63
List * symlistlist
Definition: symbol.cpp:11