NEURON
model.h
Go to the documentation of this file.
1 /* /local/src/master/nrn/src/modlunit/model.h,v 1.2 1997/11/24 16:19:13 hines Exp */
2 #include "wrap_sprintf.h"
3 #include <stdio.h>
4 #include <assert.h>
5 
6 #define NRN_BUFSIZE 8192
7 
8 typedef struct Item {
9  short itemtype;
10  short itemsubtype;
11  void* element; /* pointer to the actual item */
12  struct Item* next;
13  struct Item* prev;
14 } Item;
15 #define ITEM0 (Item*) 0
16 
17 typedef Item List; /* list of mixed items */
18 #define ITERATE(itm, lst) for (itm = (lst)->next; itm != (lst); itm = itm->next)
19 
20 /*-
21 The symbol structure gives info about tokens. Not all tokens need all
22 elements. Eg. the STRING uses only type and name. Much storage could be
23 saved and much greater clarity could be attained if each type had its own
24 sub stucture. Currently many of the structure elements serve very different
25 purposes depending on the type.
26 The following is a list of the current element usage:
27  type token number from parse1.ypp
28  subtype see definitions below
29  u.i integration method - flag for variable step
30  equation block - function number for generating variables
31  u.str scop variables - max,min,units for .var file
32  used state variable - temporary flag that it is used in an equation
33  equation block - number of state variables used (# unknowns)
34  in parout.c - the numeric order in the .var file. Generated
35  and used in parout.c for the plotlist.
36  usage a token is used as a variable (DEP) or function (FUNC)
37  Another field, EXPLICIT_DECL, is used to determine if a
38  variable appears in the input file or is automatically
39  created, thus helping to organize the .var file.
40  araydim arrays - dimension
41  discdim discrete variable - dimension
42  varnum state variable - during processing of a block containing
43  equations in which simultaneous equations result; column
44  number of state variable in the matrix.
45  name token name
46 */
47 typedef struct Symbol {
48  short type;
49  long subtype;
51  union {
52  int i;
53  const char* str;
54  } u;
55  int used;
56  int usage;
57  int araydim;
58  int discdim;
59  int varnum; /* column number of state variable in
60  * equations */
61  char* name;
63 #define SYM0 (Symbol*) 0
64 
65 /*
66  * this is convenient way to get the element pointer if you know what type
67  * the item is
68  */
69 #if DEBUG || 1
70 extern Symbol* _SYM(Item*, char*, int);
71 extern char* _STR(Item* q, char* file, int line);
72 extern Item* _ITM(Item* q, char* file, int line);
73 extern Item** _ITMA(Item* q, char* file, int line); /* array of item pointers */
74 extern List* _LST(Item* q, char* file, int line);
75 #define SYM(q) _SYM(q, (char*) __FILE__, __LINE__)
76 #define STR(q) _STR(q, (char*) __FILE__, __LINE__)
77 #define ITM(q) _ITM(q, (char*) __FILE__, __LINE__)
78 #define ITMA(q) _ITMA(q, (char*) __FILE__, __LINE__)
79 #define LST(q) _LST(q, (char*) __FILE__, __LINE__)
80 #else
81 #define SYM(q) ((Symbol*) ((q)->element))
82 #define STR(q) ((char*) ((q)->element))
83 #define ITM(q) ((Item*) ((q)->element))
84 #define ITMA(q) ((Item**) ((q)->element))
85 #define LST(q) ((List*) ((q)->element))
86 #endif
87 
88 /* types not defined in parser */
89 #define SPECIAL 1
90 /* itemtype of 0 is used by list implementation */
91 #define SYMBOL 1
92 #define ITEM 2
93 #define LIST 3
94 #define ITEMARRAY 4
95 /*
96  * An item type, STRING is also used as an item type
97  * An item type, VERBATIM is also used as an item type which is to be
98  * treated the same as a STRING but with no prepended space on output.
99  */
100 
101 /* subtypes */
102 #define KEYWORD 01L
103 #define modlunitCONST 02L
104 #define INDEP 04L
105 #define DEP 010L /* also in usage field */
106 #define STAT 020L
107 #define ARRAY 040L
108 #define FUNCT 0100L /* also in usage field */
109 #define PROCED 0200L
110 #define NEGATIVE 0400L
111 #define SEMI 01L /* ";" */
112 #define BEGINBLK 02L /* "{" */
113 #define ENDBLK 04L /* "}" */
114 #define DERF 01000L
115 #define LINF 02000L
116 #define NLINF 04000L
117 #define DISCF 010000L
118 #define PARF 040000L
119 #define EXTDEF 0100000L
120 #define KINF 0200000L
121 #define LOCL 0400000L
122 #define CNVFAC 01000000L
123 #define UFACTOR 02000000L
124 #define RANGEOBJ 04000000L
125 
126 #define EXPLICIT_DECL 01 /* usage field, variable occurs in input file */
127 
128 extern char* emalloc(unsigned); /* malloc with out of space checking */
129 extern char* stralloc(const char*, char*); /* copies string to new space */
130 
131 extern char *inputline(), /* used only by parser to get title line */
132  *inputtopar(), /* used only by parser to get units */
133  *Gets(char*); /* used only in io.c to get string from fin. */
134 const char* unit_str();
135 extern const char* decode_units(Symbol*);
136 
137 extern List *makelist(int narg, ...),
138  *itemarray(int narg, ...), /* item ITEMARRAY, array of item pointers */
139  *prepend(), *newlist(), /* begins new empty list */
140  *inputtext(); /* used by parser to get block text from
141  * VERBATIM and COMMENT */
142 extern Item *putintoken(const char*s, short type, short), /* construct symbol and store input tokens
143  */
144  *insertstr(Item*item, const char*str), /* before a known Item */
145  *insertsym(List*list, Symbol*sym), *linsertstr(List*list, char*str), /* prepend to list */
146  *lappendstr(List*list, const char*str), /* append to list */
147  *linsertsym(List*list, Symbol*sym), *lappendsym(List*list, Symbol*sym),
149  *car(List*), *next(Item*), *prev(Item*);
150 
151 
152 #include "modlunit.h" /* void functions */
153 
154 extern Symbol *install(const char*, int), /* Install token in symbol table */
155  *lookup(const char*), /* lookup name in symbol table */
156  *ifnew_constinstall(); /* new .var info only if
157  * not already done. */
158 
159 extern int unitonflag;
160 
161 extern char finname[NRN_BUFSIZE], /* the input file prefix */
162  buf[512]; /* general purpose temporary buffer */
163 
164 extern Item *parseroot, *lex_tok; /* intoken pointer for nonzero parse passes */
165 
166 extern List *intoken, /* Main list of input tokens */
167  *initfunc, /* see discussion above */
169  *misc; /* place to stick isolated items */
170 
171 extern FILE *fin, /* .mod input file descriptor */
172  *fparout, /* .var file */
173  *fcout; /* .c file */
174 
175 extern Symbol *indepsym, /* The model independent variable */
176  *semi, /* ';'. When seen on output, causes newline */
177  *beginblk, /* '{'. Used for rudimentary indentation */
178  *endblk; /* on output. */
179 
180 
181 /* the following is to get lint to shut up */
182 #if LINT
183 #undef assert
184 #define assert(arg) \
185  { \
186  if (arg) \
187  ; \
188  } /* so fprintf doesn't give lint */
189 extern char* clint;
190 extern int ilint;
191 extern Item* qlint;
192 #define Fprintf ilint = fprintf
193 #define Fclose ilint = fclose
194 #define Fflush ilint = fflush
195 #define Printf ilint = printf
196 #define Strcpy clint = strcpy
197 #define Strcat clint = strcat
198 #define Insertstr qlint = insertstr
199 #define Insertsym qlint = insertsym
200 #define Linsertsym qlint = linsertsym
201 #define Linsertstr qlint = linsertstr
202 #define Lappendsym qlint = lappendsym
203 #define Lappendstr qlint = lappendstr
204 #define Lappenditem qlint = lappenditem
205 #define IGNORE(arg) \
206  { \
207  if (arg) \
208  ; \
209  }
210 #else
211 #define Fprintf fprintf
212 #define Fclose fclose
213 #define Fflush fflush
214 #define Printf printf
215 #define Strcpy strcpy
216 #define Strcat strcat
217 #define Insertstr insertstr
218 #define Insertsym insertsym
219 #define Linsertsym linsertsym
220 #define Linsertstr linsertstr
221 #define Lappendsym lappendsym
222 #define Lappendstr lappendstr
223 #define Lappenditem lappenditem
224 #define IGNORE(arg) arg
225 #endif
226 using neuron::Sprintf;
227 using neuron::SprintfAsrt;
228 
229 /* model.h,v
230  * Revision 1.2 1997/11/24 16:19:13 hines
231  * modlunit port to MAC (not complete)
232  *
233  * Revision 1.1.1.1 1994/10/12 17:22:45 hines
234  * NEURON 3.0 distribution
235  *
236  * Revision 1.5 1993/11/04 15:52:23 hines
237  * port to solaris2 (no more warnings)
238  *
239  * Revision 1.4 1991/08/13 10:05:08 hines
240  * to work on rs6000
241  *
242  * Revision 1.3 90/11/20 15:33:05 hines
243  * added 4 varieties of unit factors. They are
244  * name = (real)
245  * name = ((unit) -> (unit)) must be conformable
246  * name = (physical_constant)
247  * name = (physical_constant (unit)) must be conformable
248  *
249  * Revision 1.2 90/11/15 13:01:17 hines
250  * function units and number units work. accepts NEURON block
251  *
252  * Revision 1.1 90/11/13 16:12:00 hines
253  * Initial revision
254  * */
char buf[512]
Definition: model.h:162
char * emalloc(unsigned)
Definition: list.cpp:161
char * stralloc(const char *, char *)
Definition: list.cpp:178
Symbol * semi
Definition: model.h:176
static int narg()
Definition: ivocvect.cpp:121
Item * linsertstr(List *list, char *str)
char * Gets(char *)
Definition: io.cpp:91
List * _LST(Item *q, char *file, int line)
Definition: io.cpp:200
List * plotlist
Definition: model.h:168
List * initfunc
Definition: model.h:167
Item * lappendsym(List *list, Symbol *sym)
Item * insertsym(List *list, Symbol *sym)
List * procfunc
Definition: model.h:168
Item * putintoken(const char *s, short type, short)
FILE * fcout
Definition: model.h:173
Item * lappenditem(List *list, Item *item)
Item * lappendstr(List *list, const char *str)
int unitonflag
Definition: units.cpp:34
List * makelist(int narg,...)
Item List
Definition: model.h:17
Symbol * beginblk
Definition: model.h:177
const char * unit_str()
Definition: units.cpp:319
Item * _ITM(Item *q, char *file, int line)
Definition: io.cpp:186
List * firstlist
Definition: model.h:168
struct Item Item
Item * prev(Item *)
Definition: list.cpp:94
Item * car(List *)
char finname[NRN_BUFSIZE]
Definition: model.cpp:38
Item * parseroot
Definition: model.cpp:39
char * inputline()
char * _STR(Item *q, char *file, int line)
Definition: io.cpp:179
List * initlist
Definition: model.h:168
Item * insertstr(Item *item, const char *str)
List * misc
Definition: model.h:169
FILE * fparout
Definition: model.h:172
Symbol * _SYM(Item *, char *, int)
Definition: io.cpp:172
List * intoken
Definition: init.cpp:12
Item * lex_tok
Definition: model.h:164
List * itemarray(int narg,...)
List * termfunc
Definition: model.h:168
Item * listtype()
FILE * fin
Definition: model.cpp:33
Symbol * endblk
Definition: model.h:178
Item ** _ITMA(Item *q, char *file, int line)
Definition: io.cpp:193
Item * prev_parstok(Item *)
struct Symbol Symbol
const char * decode_units(Symbol *)
Definition: units1.cpp:11
char * inputtopar()
Item * next_parstok(Item *)
List * inputtext()
Symbol * lookup(const char *)
List * newlist()
Item * linsertsym(List *list, Symbol *sym)
Symbol * ifnew_constinstall()
#define NRN_BUFSIZE
Definition: model.h:6
List * prepend()
Symbol * indepsym
Definition: declare.cpp:8
List * modelfunc
Definition: model.h:168
Symbol * install(const char *, int)
Item * next(Item *)
void SprintfAsrt(char(&buf)[N], const char *fmt, Args &&... args)
assert if the Sprintf format data does not fit into buf
Definition: wrap_sprintf.h:27
int Sprintf(char(&buf)[N], const char *fmt, Args &&... args)
Redirect sprintf to snprintf if the buffer size can be deduced.
Definition: wrap_sprintf.h:14
size_t q
s
Definition: multisend.cpp:521
short type
Definition: cabvars.h:10
Definition: model.h:8
struct Item * prev
Definition: model.h:13
void * element
Definition: model.h:11
short itemtype
Definition: model.h:9
short itemsubtype
Definition: model.h:10
struct Item * next
Definition: model.h:12
Definition: model.h:47
union Symbol::@28 u
int i
Definition: model.h:52
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
int varnum
Definition: model.h:59