NEURON
symbol.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 /* /local/src/master/nrn/src/modlunit/symbol.c,v 1.1.1.1 1994/10/12 17:22:50 hines Exp */
3 #include <cstring>
4 
5 #include "model.h"
6 #include "parse1.hpp"
7 #include "symbol.h"
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, (List*) sl->element) {
43  if (strcmp(SYM(sp)->name, s) == 0) {
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 = (List*) (symlistlist->next->element);
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->info = ITEM0;
69  sp->u.str = (char*) 0;
70  sp->used = 0;
71  sp->usage = 0;
72  sp->araydim = 0;
73  sp->discdim = 0;
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 
92  sl = (List*) symlistlist->next->element;
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  * */
#define STRING
Definition: bbslsrv.cpp:9
#define i
Definition: md1redef.h:19
void decdim(Symbol *s, Item *q)
Definition: declare.cpp:91
#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 ITEM0
Definition: model.h:15
#define LOCL
Definition: model.h:121
#define SYM(q)
Definition: model.h:75
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
void install_local(Item *q, Item *qdim)
Definition: symbol.cpp:100
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
size_t q
for(i=0;i< n;i++)
size_t j
s
Definition: multisend.cpp:521
static double remove(void *v)
Definition: ocdeck.cpp:205
Definition: model.h:8
void * element
Definition: model.h:11
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
int araydim
Definition: model.h:57
long subtype
Definition: model.h:49
const char * str
Definition: model.h:53
Item * info
Definition: model.h:50
char * name
Definition: model.h:61
int discdim
Definition: model.h:58
int used
Definition: model.h:55