NEURON
hocdec.h
Go to the documentation of this file.
1 #pragma once
2 #define INCLUDEHOCH 1
3 
5 #include "nrnapi.h"
6 #include "hocassrt.h" /* hoc_execerror instead of abort */
7 #include "nrnassrt.h" /* assert in case of side effects (eg. scanf) */
8 #include "wrap_sprintf.h"
9 
10 #include <iostream>
11 #include <cstdint>
12 #include <cstring>
13 #include <vector>
14 
15 
16 #define gargstr hoc_gargstr
17 #define getarg hoc_getarg
18 
19 /* the dec alpha cxx doesn't understand struct foo* inside a struct */
20 
21 struct Symbol;
22 struct Arrayinfo;
23 struct Proc;
24 struct Symlist;
25 struct cTemplate;
26 union Objectdata;
27 struct Object;
28 struct hoc_Item;
29 
30 typedef int (*Pfri)(void);
31 typedef void (*Pfrv)(void);
32 typedef double (*Pfrd)(void);
33 typedef struct Object** (*Pfro)(void);
34 typedef const char** (*Pfrs)(void);
35 
36 typedef int (*Pfri_vp)(void*);
37 typedef void (*Pfrv_vp)(void*);
38 typedef double (*Pfrd_vp)(void*);
39 typedef struct Object** (*Pfro_vp)(void*);
40 typedef const char** (*Pfrs_vp)(void*);
41 
42 union Inst { /* machine instruction list type */
51  Inst* in;
53  void* ptr;
54  int i;
55 };
56 
57 #define STOP (Inst*) 0
58 
59 struct Arrayinfo { /* subscript info for arrays */
60  unsigned* a_varn; /* dependent variable number for array elms */
61  int nsub; /* number of subscripts */
62  int refcount; /* because one object always uses symbol's */
63  int sub[1]; /* subscript range */
64 };
65 
66 struct Proc {
67  Inst defn; /* FUNCTION, PROCEDURE, FUN_BLTIN */
68  unsigned long size; /* length of instruction list */
69  Symlist* list; /* For constants and strings */
70  /* not used by FUN_BLTIN */
71  int nauto; /* total # local variables */
72  int nobjauto; /* the last of these are pointers to objects */
73 };
74 
75 struct Symlist {
78 };
79 
80 typedef char* Upoint;
81 
82 #define NOTUSER 0
83 #define USERINT 1 /* For subtype */
84 #define USERDOUBLE 2
85 #define USERPROPERTY 3 /* for newcable non-range variables */
86 #define USERFLOAT 4
87 #define SYMBOL 7 /* for stack type */
88 #define OBJECTTMP 8 /* temporary object on stack */
89 #define STKOBJ_UNREF 9 /* already unreffed temporary object on stack */
90 #define DYNAMICUNITS 10 /* {modern, legacy} units pair */
91 #define CPLUSOBJECT 16 /* c++ registered class */
92 #define JAVAOBJECT 32 /* c++ registered class */
93 /* above two are bits, next must start at 64 */
94 #define OBJECTALIAS 1
95 #define VARALIAS 2
96 
98  float* parmlimits; /* some variables have suggested bounds */
99  char* units;
100  float tolerance; /* some states have cvode absolute tolerance */
101 };
102 
103 struct Symbol { /* symbol table entry */
104  char* name;
105  short type;
106  short subtype; /* Flag for user integers */
107  short cpublic; /* flag set public variable. this was called `public` before C++ */
108  short defined_on_the_fly; /* moved here because otherwize gcc and borland do not align the same
109  way */
110  union {
111  int oboff; /* offset into object data pointer space */
112  double* pval; /* User defined doubles - also for alias to scalar */
113  Object* object_; /* alias to an object */
114  char* cstr; /* constant string */
115  double* pnum; /* Numbers */
116  int* pvalint; /* User defined integers */
117  float* pvalfloat; /* User defined floats */
118  int u_auto; /* stack offset # for AUTO variable */
119  double (*ptr)(double); /* if BLTIN */ // TODO: double as parameter?
121  struct {
122  short type; /* Membrane type to find Prop */
123  int index; /* prop->param[index] */
124  } rng;
125  Symbol** ppsym; /* Pointer to symbol pointer array */
127  Symbol* sym; /* for external */
128  } u;
129  unsigned s_varn; /* dependent variable number - 0 means indep */
130  Arrayinfo* arayinfo; /* ARRAY information if null then scalar */
131  HocSymExtension* extra; /* additions to symbol allow compatibility
132  with old nmodl dll's */
133  Symbol* next; /* to link to another */
134 };
135 
136 inline bool is_array(const Symbol& sym) {
137  return sym.arayinfo != nullptr;
138 }
139 
141 
142 /** @brief Type of pdata in mechanisms.
143  */
145 
146 struct cTemplate {
150  int is_point_; /* actually the pointtype > 0 if a point process */
151  Symbol* init; /* null if there is no initialization function */
152  Symbol* unref; /* null if there is no function to call when refcount is decremented */
153  int index; /* next unique integer used for name for section */
154  int count; /* how many of this kind of object */
155  hoc_List* olist; /* list of all instances */
156  int id;
157  void* observers; /* hook to c++ ClassObservable */
158  void* (*constructor)(struct Object*);
159  void (*destructor)(void*);
160  void (*steer)(void*); /* normally nullptr */
161 };
162 
163 union Objectdata {
164  double* pval; /* pointer to array of doubles, usually just 1 */
165  char** ppstr; /* pointer to pointer to string ,allows vectors someday*/
166  Object** pobj; /* pointer to array of object pointers, usually just 1*/
167  hoc_Item** psecitm; /* array of pointers to section items, usually just 1 */
168  hoc_List** plist; /* array of pointers to linked lists */
170  void* _pvoid; /* Point_process */
171 };
172 
173 struct Object {
174  int refcount; /* how many object variables point to this */
175  int index; /* unique integer used for names of sections */
176  union {
177  Objectdata* dataspace; /* Points to beginning of object's data */
178  void* this_pointer; /* the c++ object */
179  } u;
181  void* aliases; /* more convenient names for e.g. Vector or List elements dynamically created by
182  this object*/
183  hoc_Item* itm_me; /* this object in the template list */
184  hoc_Item* secelm_; /* last of a set of contiguous section_list items used by forall */
185  void* observers; /* hook to c++ ObjObservable */
186  short recurse; /* to stop infinite recursions */
187  short unref_recurse_cnt; /* free only after last return from unref callback */
188 };
189 
190 struct VoidFunc { /* User Functions */
191  const char* name;
192  void (*func)(void);
193 };
194 
195 struct DoubScal { /* User Double Scalars */
196  const char* name;
197  double* pdoub;
198 };
199 
200 struct DoubVec { /* User Vectors */
201  const char* name;
202  double* pdoub;
203  int index1;
204 };
205 
206 struct HocParmLimits { /* recommended limits for symbol values */
207  const char* name;
208  float bnd[2];
209 };
210 
211 struct HocStateTolerance { /* recommended tolerance for CVODE */
212  const char* name;
213  float tolerance;
214 };
215 
216 struct HocParmUnits { /* units for symbol values */
217  const char* name;
218  const char* units;
219 };
220 
221 #include "oc_ansi.h"
222 
224 extern Inst* hoc_pc;
225 
226 extern Objectdata* hoc_objectdata;
228 extern Object* hoc_thisobject;
229 extern Symlist* hoc_symlist;
232 extern Objectdata* hoc_objectdata_save(void);
234 #define OPVAL(sym) hoc_objectdata[sym->u.oboff].pval
235 #define OPSTR(sym) hoc_objectdata[sym->u.oboff].ppstr
236 #define OPOBJ(sym) hoc_objectdata[sym->u.oboff].pobj
237 #define OPSECITM(sym) hoc_objectdata[sym->u.oboff].psecitm
238 #define OPLIST(sym) hoc_objectdata[sym->u.oboff].plist
239 #define OPARINFO(sym) hoc_objectdata[sym->u.oboff + 1].arayinfo
240 
241 #if LINT
242 #undef assert
243 #define assert(arg) \
244  { \
245  if (arg) \
246  ; \
247  } /* so fprintf doesn't give lint */
248 #undef IGNORE
249 #define IGNORE(arg) \
250  { \
251  if (arg) \
252  ; \
253  }
254 #define LINTUSE(arg) \
255  { \
256  if (arg) \
257  ; \
258  }
259 char* cplint;
260 int ilint;
261 #define Strcat cplint = strcat
262 #define Strncat cplint = strncat
263 #define Strcpy cplint = strcpy
264 #define Strncpy cplint = strncpy
265 #else
266 #undef IGNORE
267 #define IGNORE(arg) arg
268 #define LINTUSE(arg)
269 #define Strcat strcat
270 #define Strncat strncat
271 #define Strcpy strcpy
272 #define Strncpy strncpy
273 #endif
274 using neuron::Sprintf;
275 using neuron::SprintfAsrt;
276 
277 // No longer used because of clang format difficulty
278 // #define IFGUI if (hoc_usegui) {
279 // #define ENDGUI }
280 
281 extern int hoc_usegui; /* when 0 does not make interviews calls */
282 extern int nrn_istty_;
283 
284 /* Enter handling for PVM NJP 11/21/94 */
285 #ifdef PVM
286 extern int init_parallel();
287 int num_procs;
288 int* tids;
289 int node_num;
290 int mytid;
291 #endif
int(* Pfri_vp)(void *)
Definition: hocdec.h:36
Objectdata * hoc_objectdata_save(void)
Definition: hoc_oop.cpp:132
Symlist * hoc_top_level_symlist
Definition: symdir.cpp:16
struct Object **(* Pfro_vp)(void *)
Definition: hocdec.h:39
const char **(* Pfrs)(void)
Definition: hocdec.h:34
Inst * hoc_prog_parse_recover
Definition: hocdec.h:223
double(* Pfrd)(void)
Definition: hocdec.h:32
int nrn_istty_
Definition: hoc.cpp:778
Inst * hoc_progp
Definition: code.cpp:77
struct Object **(* Pfro)(void)
Definition: hocdec.h:33
void(* Pfrv)(void)
Definition: hocdec.h:31
Objectdata * hoc_objectdata
Definition: hoc_oop.cpp:122
Objectdata * hoc_objectdata_restore(Objectdata *)
Definition: hoc_oop.cpp:142
bool is_array(const Symbol &sym)
Definition: hocdec.h:136
Inst * hoc_progbase
Definition: hocdec.h:223
char * Upoint
Definition: hocdec.h:80
Symlist * hoc_symlist
Definition: symbol.cpp:34
void(* Pfrv_vp)(void *)
Definition: hocdec.h:37
Inst * hoc_prog
Definition: hocdec.h:223
Objectdata * hoc_top_level_data
Definition: hoc_oop.cpp:123
const char **(* Pfrs_vp)(void *)
Definition: hocdec.h:40
Symlist * hoc_built_in_symlist
Definition: symbol.cpp:28
int hoc_usegui
Definition: hoc.cpp:121
double(* Pfrd_vp)(void *)
Definition: hocdec.h:38
int(* Pfri)(void)
Definition: hocdec.h:30
Object * hoc_thisobject
Definition: hoc_oop.cpp:121
Inst * hoc_pc
Definition: code.cpp:78
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
HOC interpreter function declarations (included by hocdec.h)
unsigned * a_varn
Definition: hocdec.h:60
int nsub
Definition: hocdec.h:61
int refcount
Definition: hocdec.h:62
int sub[1]
Definition: hocdec.h:63
double * pdoub
Definition: hocdec.h:197
const char * name
Definition: hocdec.h:196
const char * name
Definition: hocdec.h:201
double * pdoub
Definition: hocdec.h:202
int index1
Definition: hocdec.h:203
float bnd[2]
Definition: hocdec.h:208
const char * name
Definition: hocdec.h:207
const char * name
Definition: hocdec.h:217
const char * units
Definition: hocdec.h:218
const char * name
Definition: hocdec.h:212
float tolerance
Definition: hocdec.h:213
float * parmlimits
Definition: hocdec.h:98
char * units
Definition: hocdec.h:99
float tolerance
Definition: hocdec.h:100
Definition: hocdec.h:173
hoc_Item * itm_me
Definition: hocdec.h:183
void * aliases
Definition: hocdec.h:181
void * this_pointer
Definition: hocdec.h:178
Objectdata * dataspace
Definition: hocdec.h:177
int index
Definition: hocdec.h:175
short unref_recurse_cnt
Definition: hocdec.h:187
void * observers
Definition: hocdec.h:185
int refcount
Definition: hocdec.h:174
cTemplate * ctemplate
Definition: hocdec.h:180
hoc_Item * secelm_
Definition: hocdec.h:184
union Object::@47 u
short recurse
Definition: hocdec.h:186
Definition: hocdec.h:66
int nauto
Definition: hocdec.h:71
Inst defn
Definition: hocdec.h:67
unsigned long size
Definition: hocdec.h:68
Symlist * list
Definition: hocdec.h:69
int nobjauto
Definition: hocdec.h:72
Definition: model.h:47
Proc * u_proc
Definition: hocdec.h:120
Symbol * next
Definition: hocdec.h:133
union Symbol::@28 u
short cpublic
Definition: hocdec.h:107
Symbol ** ppsym
Definition: hocdec.h:125
int u_auto
Definition: hocdec.h:118
struct Symbol::@45::@46 rng
Object * object_
Definition: hocdec.h:113
short type
Definition: model.h:48
double * pnum
Definition: hocdec.h:115
double(* ptr)(double)
Definition: hocdec.h:119
int * pvalint
Definition: hocdec.h:116
float * pvalfloat
Definition: hocdec.h:117
Symbol * sym
Definition: hocdec.h:127
int index
Definition: hocdec.h:123
cTemplate * ctemplate
Definition: hocdec.h:126
char * cstr
Definition: hocdec.h:114
short subtype
Definition: hocdec.h:106
unsigned s_varn
Definition: hocdec.h:129
char * name
Definition: model.h:61
HocSymExtension * extra
Definition: hocdec.h:131
double * pval
Definition: hocdec.h:112
int oboff
Definition: hocdec.h:111
Arrayinfo * arayinfo
Definition: hocdec.h:130
short defined_on_the_fly
Definition: hocdec.h:108
Definition: hocdec.h:75
Symbol * last
Definition: hocdec.h:77
Symbol * first
Definition: hocdec.h:76
const char * name
Definition: hocdec.h:191
void(* func)(void)
Definition: hocdec.h:192
Symbol * sym
Definition: hocdec.h:147
int dataspace_size
Definition: hocdec.h:149
Symbol * unref
Definition: hocdec.h:152
Symlist * symtable
Definition: hocdec.h:148
Symbol * init
Definition: hocdec.h:151
int id
Definition: hocdec.h:156
hoc_List * olist
Definition: hocdec.h:155
void * observers
Definition: hocdec.h:157
int count
Definition: hocdec.h:154
void(* destructor)(void *)
Definition: hocdec.h:159
int is_point_
Definition: hocdec.h:150
int index
Definition: hocdec.h:153
void(* steer)(void *)
Definition: hocdec.h:160
Non-template stable handle to a generic value.
Definition: hocdec.h:42
Pfrv pf
Definition: hocdec.h:43
Pfrd pfd
Definition: hocdec.h:44
int i
Definition: hocdec.h:54
Pfrs_vp pfs_vp
Definition: hocdec.h:50
Pfro pfo
Definition: hocdec.h:45
Pfro_vp pfo_vp
Definition: hocdec.h:49
Pfrs pfs
Definition: hocdec.h:46
Symbol * sym
Definition: hocdec.h:52
Pfrv_vp pfv_vp
Definition: hocdec.h:47
Pfrd_vp pfd_vp
Definition: hocdec.h:48
void * ptr
Definition: hocdec.h:53
Inst * in
Definition: hocdec.h:51
char ** ppstr
Definition: hocdec.h:165
void * _pvoid
Definition: hocdec.h:170
hoc_Item ** psecitm
Definition: hocdec.h:167
hoc_List ** plist
Definition: hocdec.h:168
Arrayinfo * arayinfo
Definition: hocdec.h:169
double * pval
Definition: hocdec.h:164
Object ** pobj
Definition: hocdec.h:166