itclInt.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  1. /*
  2. * itclInt.h --
  3. *
  4. * This file contains internal definitions for the C-implemented part of a
  5. * Itcl
  6. *
  7. * Copyright (c) 2007 by Arnulf P. Wiedemann
  8. *
  9. * See the file "license.terms" for information on usage and redistribution of
  10. * this file, and for a DISCLAIMER OF ALL WARRANTIES.
  11. */
  12. #ifdef HAVE_UNISTD_H
  13. #include <unistd.h>
  14. #endif
  15. #ifdef HAVE_STDINT_H
  16. #include <stdint.h>
  17. #endif
  18. /*
  19. * Used to tag functions that are only to be visible within the module being
  20. * built and not outside it (where this is supported by the linker).
  21. */
  22. #ifndef MODULE_SCOPE
  23. # ifdef __cplusplus
  24. # define MODULE_SCOPE extern "C"
  25. # else
  26. # define MODULE_SCOPE extern
  27. # endif
  28. #endif
  29. #include <string.h>
  30. #include <ctype.h>
  31. #include <tclOO.h>
  32. #include "itcl.h"
  33. #include "itclMigrate2TclCore.h"
  34. #include "itclTclIntStubsFcn.h"
  35. /*
  36. * Utility macros: STRINGIFY takes an argument and wraps it in "" (double
  37. * quotation marks).
  38. */
  39. #ifndef STRINGIFY
  40. # define STRINGIFY(x) STRINGIFY1(x)
  41. # define STRINGIFY1(x) #x
  42. #endif
  43. /*
  44. * MSVC 8.0 started to mark many standard C library functions depreciated
  45. * including the *printf family and others. Tell it to shut up.
  46. * (_MSC_VER is 1200 for VC6, 1300 or 1310 for vc7.net, 1400 for 8.0)
  47. */
  48. #if defined(_MSC_VER)
  49. # pragma warning(disable:4244)
  50. # if _MSC_VER >= 1400
  51. # pragma warning(disable:4267)
  52. # pragma warning(disable:4996)
  53. # endif
  54. #endif
  55. #ifndef JOIN
  56. # define JOIN(a,b) JOIN1(a,b)
  57. # define JOIN1(a,b) a##b
  58. #endif
  59. #ifndef TCL_UNUSED
  60. # if defined(__cplusplus)
  61. # define TCL_UNUSED(T) T
  62. # else
  63. # define TCL_UNUSED(T) T JOIN(dummy, __LINE__)
  64. # endif
  65. #endif
  66. /*
  67. * Since the Tcl/Tk distribution doesn't perform any asserts,
  68. * dynamic loading can fail to find the __assert function.
  69. * As a workaround, we'll include our own.
  70. */
  71. #undef assert
  72. #if defined(NDEBUG) && !defined(DEBUG)
  73. #define assert(EX) ((void)0)
  74. #else /* !NDEBUG || DEBUG */
  75. #define assert(EX) (void)((EX) || (Itcl_Assert(STRINGIFY(EX), __FILE__, __LINE__), 0))
  76. #endif
  77. #define ITCL_INTERP_DATA "itcl_data"
  78. #define ITCL_TK_VERSION "8.6"
  79. /*
  80. * Convenience macros for iterating through hash tables. FOREACH_HASH_DECLS
  81. * sets up the declarations needed for the main macro, FOREACH_HASH, which
  82. * does the actual iteration. FOREACH_HASH_VALUE is a restricted version that
  83. * only iterates over values.
  84. */
  85. #define FOREACH_HASH_DECLS \
  86. Tcl_HashEntry *hPtr;Tcl_HashSearch search
  87. #define FOREACH_HASH(key,val,tablePtr) \
  88. for(hPtr=Tcl_FirstHashEntry((tablePtr),&search); hPtr!=NULL ? \
  89. (*(void **)&(key)=Tcl_GetHashKey((tablePtr),hPtr),\
  90. *(void **)&(val)=Tcl_GetHashValue(hPtr),1):0; hPtr=Tcl_NextHashEntry(&search))
  91. #define FOREACH_HASH_VALUE(val,tablePtr) \
  92. for(hPtr=Tcl_FirstHashEntry((tablePtr),&search); hPtr!=NULL ? \
  93. (*(void **)&(val)=Tcl_GetHashValue(hPtr),1):0;hPtr=Tcl_NextHashEntry(&search))
  94. /*
  95. * What sort of size of things we like to allocate.
  96. */
  97. #define ALLOC_CHUNK 8
  98. #define ITCL_INT_NAMESPACE ITCL_NAMESPACE"::internal"
  99. #define ITCL_INTDICTS_NAMESPACE ITCL_INT_NAMESPACE"::dicts"
  100. #define ITCL_VARIABLES_NAMESPACE ITCL_INT_NAMESPACE"::variables"
  101. #define ITCL_COMMANDS_NAMESPACE ITCL_INT_NAMESPACE"::commands"
  102. typedef struct ItclFoundation {
  103. Itcl_Stack methodCallStack;
  104. Tcl_Command dispatchCommand;
  105. } ItclFoundation;
  106. typedef struct ItclArgList {
  107. struct ItclArgList *nextPtr; /* pointer to next argument */
  108. Tcl_Obj *namePtr; /* name of the argument */
  109. Tcl_Obj *defaultValuePtr; /* default value or NULL if none */
  110. } ItclArgList;
  111. /*
  112. * Common info for managing all known objects.
  113. * Each interpreter has one of these data structures stored as
  114. * clientData in the "itcl" namespace. It is also accessible
  115. * as associated data via the key ITCL_INTERP_DATA.
  116. */
  117. struct ItclClass;
  118. struct ItclObject;
  119. struct ItclMemberFunc;
  120. struct EnsembleInfo;
  121. struct ItclDelegatedOption;
  122. struct ItclDelegatedFunction;
  123. typedef struct ItclObjectInfo {
  124. Tcl_Interp *interp; /* interpreter that manages this info */
  125. Tcl_HashTable objects; /* list of all known objects key is
  126. * ioPtr */
  127. Tcl_HashTable objectCmds; /* list of known objects using accessCmd */
  128. Tcl_HashTable unused5; /* list of known objects using namePtr */
  129. Tcl_HashTable classes; /* list of all known classes,
  130. * key is iclsPtr */
  131. Tcl_HashTable nameClasses; /* maps from fullNamePtr to iclsPtr */
  132. Tcl_HashTable namespaceClasses; /* maps from nsPtr to iclsPtr */
  133. Tcl_HashTable procMethods; /* maps from procPtr to mFunc */
  134. Tcl_HashTable instances; /* maps from instanceNumber to ioPtr */
  135. Tcl_HashTable unused8; /* maps from ioPtr to instanceNumber */
  136. Tcl_HashTable frameContext; /* maps frame to context stack */
  137. Tcl_HashTable classTypes; /* maps from class type i.e. "widget"
  138. * to define value i.e. ITCL_WIDGET */
  139. int protection; /* protection level currently in effect */
  140. int useOldResolvers; /* whether to use the "old" style
  141. * resolvers or the CallFrame resolvers */
  142. Itcl_Stack clsStack; /* stack of class definitions currently
  143. * being parsed */
  144. Itcl_Stack unused; /* Removed */
  145. Itcl_Stack unused6; /* obsolete field */
  146. struct ItclObject *currIoPtr; /* object currently being constructed
  147. * set only during calling of constructors
  148. * otherwise NULL */
  149. Tcl_ObjectMetadataType *class_meta_type;
  150. /* type for getting the Itcl class info
  151. * from a TclOO Tcl_Object */
  152. const Tcl_ObjectMetadataType *object_meta_type;
  153. /* type for getting the Itcl object info
  154. * from a TclOO Tcl_Object */
  155. Tcl_Object clazzObjectPtr; /* the root object of Itcl */
  156. Tcl_Class clazzClassPtr; /* the root class of Itcl */
  157. struct EnsembleInfo *ensembleInfo;
  158. struct ItclClass *currContextIclsPtr;
  159. /* context class for delegated option
  160. * handling */
  161. int currClassFlags; /* flags for the class just in creation */
  162. int buildingWidget; /* set if in construction of a widget */
  163. int unparsedObjc; /* number options not parsed by
  164. ItclExtendedConfigure/-Cget function */
  165. Tcl_Obj **unparsedObjv; /* options not parsed by
  166. ItclExtendedConfigure/-Cget function */
  167. int functionFlags; /* used for creating of ItclMemberCode */
  168. int unused7;
  169. struct ItclDelegatedOption *currIdoPtr;
  170. /* the current delegated option info */
  171. int inOptionHandling; /* used to indicate for type/widget ...
  172. * that there is an option processing
  173. * and methods are allowed to be called */
  174. /* these are the Tcl_Obj Ptrs for the clazz unknown procedure */
  175. /* need to store them to be able to free them at the end */
  176. int itclWidgetInitted; /* set to 1 if itclWidget.tcl has already
  177. * been called
  178. */
  179. int itclHullCmdsInitted; /* set to 1 if itclHullCmds.tcl has already
  180. * been called
  181. */
  182. Tcl_Obj *unused2;
  183. Tcl_Obj *unused3;
  184. Tcl_Obj *unused4;
  185. Tcl_Obj *infoVarsPtr;
  186. Tcl_Obj *unused9;
  187. Tcl_Obj *infoVars4Ptr;
  188. Tcl_Obj *typeDestructorArgumentPtr;
  189. struct ItclObject *lastIoPtr; /* last object constructed */
  190. Tcl_Command infoCmd;
  191. } ItclObjectInfo;
  192. typedef struct EnsembleInfo {
  193. Tcl_HashTable ensembles; /* list of all known ensembles */
  194. Tcl_HashTable subEnsembles; /* list of all known subensembles */
  195. int numEnsembles;
  196. Tcl_Namespace *ensembleNsPtr;
  197. } EnsembleInfo;
  198. /*
  199. * Representation for each [incr Tcl] class.
  200. */
  201. #define ITCL_CLASS 0x1
  202. #define ITCL_TYPE 0x2
  203. #define ITCL_WIDGET 0x4
  204. #define ITCL_WIDGETADAPTOR 0x8
  205. #define ITCL_ECLASS 0x10
  206. #define ITCL_NWIDGET 0x20
  207. #define ITCL_WIDGET_FRAME 0x40
  208. #define ITCL_WIDGET_LABEL_FRAME 0x80
  209. #define ITCL_WIDGET_TOPLEVEL 0x100
  210. #define ITCL_WIDGET_TTK_FRAME 0x200
  211. #define ITCL_WIDGET_TTK_LABEL_FRAME 0x400
  212. #define ITCL_WIDGET_TTK_TOPLEVEL 0x800
  213. #define ITCL_CLASS_IS_DELETED 0x1000
  214. #define ITCL_CLASS_IS_DESTROYED 0x2000
  215. #define ITCL_CLASS_NS_IS_DESTROYED 0x4000
  216. #define ITCL_CLASS_IS_RENAMED 0x8000 /* unused */
  217. #define ITCL_CLASS_IS_FREED 0x10000
  218. #define ITCL_CLASS_DERIVED_RELEASED 0x20000
  219. #define ITCL_CLASS_NS_TEARDOWN 0x40000
  220. #define ITCL_CLASS_NO_VARNS_DELETE 0x80000
  221. #define ITCL_CLASS_SHOULD_VARNS_DELETE 0x100000
  222. #define ITCL_CLASS_DESTRUCTOR_CALLED 0x400000
  223. typedef struct ItclClass {
  224. Tcl_Obj *namePtr; /* class name */
  225. Tcl_Obj *fullNamePtr; /* fully qualified class name */
  226. Tcl_Interp *interp; /* interpreter that manages this info */
  227. Tcl_Namespace *nsPtr; /* namespace representing class scope */
  228. Tcl_Command accessCmd; /* access command for creating instances */
  229. Tcl_Command thisCmd; /* needed for deletion of class */
  230. struct ItclObjectInfo *infoPtr;
  231. /* info about all known objects
  232. * and other stuff like stacks */
  233. Itcl_List bases; /* list of base classes */
  234. Itcl_List derived; /* list of all derived classes */
  235. Tcl_HashTable heritage; /* table of all base classes. Look up
  236. * by pointer to class definition. This
  237. * provides fast lookup for inheritance
  238. * tests. */
  239. Tcl_Obj *initCode; /* initialization code for new objs */
  240. Tcl_HashTable variables; /* definitions for all data members
  241. in this class. Look up simple string
  242. names and get back ItclVariable* ptrs */
  243. Tcl_HashTable options; /* definitions for all option members
  244. in this class. Look up simple string
  245. names and get back ItclOption* ptrs */
  246. Tcl_HashTable components; /* definitions for all component members
  247. in this class. Look up simple string
  248. names and get back ItclComponent* ptrs */
  249. Tcl_HashTable functions; /* definitions for all member functions
  250. in this class. Look up simple string
  251. names and get back ItclMemberFunc* ptrs */
  252. Tcl_HashTable delegatedOptions; /* definitions for all delegated options
  253. in this class. Look up simple string
  254. names and get back
  255. ItclDelegatedOption * ptrs */
  256. Tcl_HashTable delegatedFunctions; /* definitions for all delegated methods
  257. or procs in this class. Look up simple
  258. string names and get back
  259. ItclDelegatedFunction * ptrs */
  260. Tcl_HashTable methodVariables; /* definitions for all methodvariable members
  261. in this class. Look up simple string
  262. names and get back
  263. ItclMethodVariable* ptrs */
  264. int numInstanceVars; /* number of instance vars in variables
  265. table */
  266. Tcl_HashTable classCommons; /* used for storing variable namespace
  267. * string for Tcl_Resolve */
  268. Tcl_HashTable resolveVars; /* all possible names for variables in
  269. * this class (e.g., x, foo::x, etc.) */
  270. Tcl_HashTable resolveCmds; /* all possible names for functions in
  271. * this class (e.g., x, foo::x, etc.) */
  272. Tcl_HashTable contextCache; /* cache for function contexts */
  273. struct ItclMemberFunc *unused2;
  274. /* the class constructor or NULL */
  275. struct ItclMemberFunc *unused3;
  276. /* the class destructor or NULL */
  277. struct ItclMemberFunc *unused1;
  278. Tcl_Resolve *resolvePtr;
  279. Tcl_Obj *widgetClassPtr; /* class name for widget if class is a
  280. * ::itcl::widget */
  281. Tcl_Obj *hullTypePtr; /* hulltype name for widget if class is a
  282. * ::itcl::widget */
  283. Tcl_Object oPtr; /* TclOO class object */
  284. Tcl_Class clsPtr; /* TclOO class */
  285. int numCommons; /* number of commons in this class */
  286. int numVariables; /* number of variables in this class */
  287. int numOptions; /* number of options in this class */
  288. int unique; /* unique number for #auto generation */
  289. int flags; /* maintains class status */
  290. int callRefCount; /* prevent deleting of class if refcount>1 */
  291. Tcl_Obj *typeConstructorPtr; /* initialization for types */
  292. int destructorHasBeenCalled; /* prevent multiple invocations of destrcutor */
  293. int refCount;
  294. } ItclClass;
  295. typedef struct ItclHierIter {
  296. ItclClass *current; /* current position in hierarchy */
  297. Itcl_Stack stack; /* stack used for traversal */
  298. } ItclHierIter;
  299. #define ITCL_OBJECT_IS_DELETED 0x01
  300. #define ITCL_OBJECT_IS_DESTRUCTED 0x02
  301. #define ITCL_OBJECT_IS_DESTROYED 0x04
  302. #define ITCL_OBJECT_IS_RENAMED 0x08
  303. #define ITCL_OBJECT_CLASS_DESTRUCTED 0x10
  304. #define ITCL_TCLOO_OBJECT_IS_DELETED 0x20
  305. #define ITCL_OBJECT_DESTRUCT_ERROR 0x40
  306. #define ITCL_OBJECT_SHOULD_VARNS_DELETE 0x80
  307. #define ITCL_OBJECT_ROOT_METHOD 0x8000
  308. /*
  309. * Representation for each [incr Tcl] object.
  310. */
  311. typedef struct ItclObject {
  312. ItclClass *iclsPtr; /* most-specific class */
  313. Tcl_Command accessCmd; /* object access command */
  314. Tcl_HashTable* constructed; /* temp storage used during construction */
  315. Tcl_HashTable* destructed; /* temp storage used during destruction */
  316. Tcl_HashTable objectVariables;
  317. /* used for storing Tcl_Var entries for
  318. * variable resolving, key is ivPtr of
  319. * variable, value is varPtr */
  320. Tcl_HashTable objectOptions; /* definitions for all option members
  321. in this object. Look up option namePtr
  322. names and get back ItclOption* ptrs */
  323. Tcl_HashTable objectComponents; /* definitions for all component members
  324. in this object. Look up component namePtr
  325. names and get back ItclComponent* ptrs */
  326. Tcl_HashTable objectMethodVariables;
  327. /* definitions for all methodvariable members
  328. in this object. Look up methodvariable
  329. namePtr names and get back
  330. ItclMethodVariable* ptrs */
  331. Tcl_HashTable objectDelegatedOptions;
  332. /* definitions for all delegated option
  333. members in this object. Look up option
  334. namePtr names and get back
  335. ItclOption* ptrs */
  336. Tcl_HashTable objectDelegatedFunctions;
  337. /* definitions for all delegated function
  338. members in this object. Look up function
  339. namePtr names and get back
  340. ItclMemberFunc * ptrs */
  341. Tcl_HashTable contextCache; /* cache for function contexts */
  342. Tcl_Obj *namePtr;
  343. Tcl_Obj *origNamePtr; /* the original name before any rename */
  344. Tcl_Obj *createNamePtr; /* the temp name before any rename
  345. * mostly used for widgetadaptor
  346. * because that hijackes the name
  347. * often when installing the hull */
  348. Tcl_Interp *interp;
  349. ItclObjectInfo *infoPtr;
  350. Tcl_Obj *varNsNamePtr;
  351. Tcl_Object oPtr; /* the TclOO object */
  352. Tcl_Resolve *resolvePtr;
  353. int flags;
  354. int callRefCount; /* prevent deleting of object if refcount > 1 */
  355. Tcl_Obj *hullWindowNamePtr; /* the window path name for the hull
  356. * (before renaming in installhull) */
  357. int destructorHasBeenCalled; /* is set when the destructor is called
  358. * to avoid callin destructor twice */
  359. int noComponentTrace; /* don't call component traces if
  360. * setting components in DelegationInstall */
  361. int hadConstructorError; /* needed for multiple calls of CallItclObjectCmd */
  362. } ItclObject;
  363. #define ITCL_IGNORE_ERRS 0x002 /* useful for construction/destruction */
  364. typedef struct ItclResolveInfo {
  365. int flags;
  366. ItclClass *iclsPtr;
  367. ItclObject *ioPtr;
  368. } ItclResolveInfo;
  369. #define ITCL_RESOLVE_CLASS 0x01
  370. #define ITCL_RESOLVE_OBJECT 0x02
  371. /*
  372. * Implementation for any code body in an [incr Tcl] class.
  373. */
  374. typedef struct ItclMemberCode {
  375. int flags; /* flags describing implementation */
  376. int argcount; /* number of args in arglist */
  377. int maxargcount; /* max number of args in arglist */
  378. Tcl_Obj *usagePtr; /* usage string for error messages */
  379. Tcl_Obj *argumentPtr; /* the function arguments */
  380. Tcl_Obj *bodyPtr; /* the function body */
  381. ItclArgList *argListPtr; /* the parsed arguments */
  382. union {
  383. Tcl_CmdProc *argCmd; /* (argc,argv) C implementation */
  384. Tcl_ObjCmdProc *objCmd; /* (objc,objv) C implementation */
  385. } cfunc;
  386. ClientData clientData; /* client data for C implementations */
  387. } ItclMemberCode;
  388. /*
  389. * Flag bits for ItclMemberCode:
  390. */
  391. #define ITCL_IMPLEMENT_NONE 0x001 /* no implementation */
  392. #define ITCL_IMPLEMENT_TCL 0x002 /* Tcl implementation */
  393. #define ITCL_IMPLEMENT_ARGCMD 0x004 /* (argc,argv) C implementation */
  394. #define ITCL_IMPLEMENT_OBJCMD 0x008 /* (objc,objv) C implementation */
  395. #define ITCL_IMPLEMENT_C 0x00c /* either kind of C implementation */
  396. #define Itcl_IsMemberCodeImplemented(mcode) \
  397. (((mcode)->flags & ITCL_IMPLEMENT_NONE) == 0)
  398. /*
  399. * Flag bits for ItclMember: functions and variables
  400. */
  401. #define ITCL_COMMON 0x010 /* non-zero => is a "proc" or common
  402. * variable */
  403. /*
  404. * Flag bits for ItclMember: functions
  405. */
  406. #define ITCL_CONSTRUCTOR 0x020 /* non-zero => is a constructor */
  407. #define ITCL_DESTRUCTOR 0x040 /* non-zero => is a destructor */
  408. #define ITCL_ARG_SPEC 0x080 /* non-zero => has an argument spec */
  409. #define ITCL_BODY_SPEC 0x100 /* non-zero => has an body spec */
  410. #define ITCL_BUILTIN 0x400 /* non-zero => built-in method */
  411. #define ITCL_COMPONENT 0x800 /* non-zero => component */
  412. #define ITCL_TYPE_METHOD 0x1000 /* non-zero => typemethod */
  413. #define ITCL_METHOD 0x2000 /* non-zero => method */
  414. /*
  415. * Flag bits for ItclMember: variables
  416. */
  417. #define ITCL_THIS_VAR 0x20 /* non-zero => built-in "this" variable */
  418. #define ITCL_OPTIONS_VAR 0x40 /* non-zero => built-in "itcl_options"
  419. * variable */
  420. #define ITCL_TYPE_VAR 0x80 /* non-zero => built-in "type" variable */
  421. /* no longer used ??? */
  422. #define ITCL_SELF_VAR 0x100 /* non-zero => built-in "self" variable */
  423. #define ITCL_SELFNS_VAR 0x200 /* non-zero => built-in "selfns"
  424. * variable */
  425. #define ITCL_WIN_VAR 0x400 /* non-zero => built-in "win" variable */
  426. #define ITCL_COMPONENT_VAR 0x800 /* non-zero => component variable */
  427. #define ITCL_HULL_VAR 0x1000 /* non-zero => built-in "itcl_hull"
  428. * variable */
  429. #define ITCL_OPTION_READONLY 0x2000 /* non-zero => readonly */
  430. #define ITCL_VARIABLE 0x4000 /* non-zero => normal variable */
  431. #define ITCL_TYPE_VARIABLE 0x8000 /* non-zero => typevariable */
  432. #define ITCL_OPTION_INITTED 0x10000 /* non-zero => option has been initialized */
  433. #define ITCL_OPTION_COMP_VAR 0x20000 /* variable to collect option components of extendedclass */
  434. /*
  435. * Instance components.
  436. */
  437. struct ItclVariable;
  438. typedef struct ItclComponent {
  439. Tcl_Obj *namePtr; /* member name */
  440. struct ItclVariable *ivPtr; /* variable for this component */
  441. int flags;
  442. int haveKeptOptions;
  443. Tcl_HashTable keptOptions; /* table of options to keep */
  444. } ItclComponent;
  445. #define ITCL_COMPONENT_INHERIT 0x01
  446. #define ITCL_COMPONENT_PUBLIC 0x02
  447. typedef struct ItclDelegatedFunction {
  448. Tcl_Obj *namePtr;
  449. ItclComponent *icPtr;
  450. Tcl_Obj *asPtr;
  451. Tcl_Obj *usingPtr;
  452. Tcl_HashTable exceptions;
  453. int flags;
  454. } ItclDelegatedFunction;
  455. /*
  456. * Representation of member functions in an [incr Tcl] class.
  457. */
  458. typedef struct ItclMemberFunc {
  459. Tcl_Obj* namePtr; /* member name */
  460. Tcl_Obj* fullNamePtr; /* member name with "class::" qualifier */
  461. ItclClass* iclsPtr; /* class containing this member */
  462. int protection; /* protection level */
  463. int flags; /* flags describing member (see above) */
  464. ItclObjectInfo *infoPtr;
  465. ItclMemberCode *codePtr; /* code associated with member */
  466. Tcl_Command accessCmd; /* Tcl command installed for this function */
  467. int argcount; /* number of args in arglist */
  468. int maxargcount; /* max number of args in arglist */
  469. Tcl_Obj *usagePtr; /* usage string for error messages */
  470. Tcl_Obj *argumentPtr; /* the function arguments */
  471. Tcl_Obj *builtinArgumentPtr; /* the function arguments for builtin functions */
  472. Tcl_Obj *origArgsPtr; /* the argument string of the original definition */
  473. Tcl_Obj *bodyPtr; /* the function body */
  474. ItclArgList *argListPtr; /* the parsed arguments */
  475. ItclClass *declaringClassPtr; /* the class which declared the method/proc */
  476. ClientData tmPtr; /* TclOO methodPtr */
  477. ItclDelegatedFunction *idmPtr;
  478. /* if the function is delegated != NULL */
  479. } ItclMemberFunc;
  480. /*
  481. * Instance variables.
  482. */
  483. typedef struct ItclVariable {
  484. Tcl_Obj *namePtr; /* member name */
  485. Tcl_Obj *fullNamePtr; /* member name with "class::" qualifier */
  486. ItclClass *iclsPtr; /* class containing this member */
  487. ItclObjectInfo *infoPtr;
  488. ItclMemberCode *codePtr; /* code associated with member */
  489. Tcl_Obj *init; /* initial value */
  490. Tcl_Obj *arrayInitPtr; /* initial value if variable should be array */
  491. int protection; /* protection level */
  492. int flags; /* flags describing member (see below) */
  493. int initted; /* is set when first time initted, to check
  494. * for example itcl_hull var, which can be only
  495. * initialized once */
  496. } ItclVariable;
  497. struct ItclOption;
  498. typedef struct ItclDelegatedOption {
  499. Tcl_Obj *namePtr;
  500. Tcl_Obj *resourceNamePtr;
  501. Tcl_Obj *classNamePtr;
  502. struct ItclOption *ioptPtr; /* the option name or null for "*" */
  503. ItclComponent *icPtr; /* the component where the delegation goes
  504. * to */
  505. Tcl_Obj *asPtr;
  506. Tcl_HashTable exceptions; /* exceptions from delegation */
  507. } ItclDelegatedOption;
  508. /*
  509. * Instance options.
  510. */
  511. typedef struct ItclOption {
  512. /* within a class hierarchy there must be only
  513. * one option with the same name !! */
  514. Tcl_Obj *namePtr; /* member name */
  515. Tcl_Obj *fullNamePtr; /* member name with "class::" qualifier */
  516. Tcl_Obj *resourceNamePtr;
  517. Tcl_Obj *classNamePtr;
  518. ItclClass *iclsPtr; /* class containing this member */
  519. int protection; /* protection level */
  520. int flags; /* flags describing member (see below) */
  521. ItclMemberCode *codePtr; /* code associated with member */
  522. Tcl_Obj *defaultValuePtr; /* initial value */
  523. Tcl_Obj *cgetMethodPtr;
  524. Tcl_Obj *cgetMethodVarPtr;
  525. Tcl_Obj *configureMethodPtr;
  526. Tcl_Obj *configureMethodVarPtr;
  527. Tcl_Obj *validateMethodPtr;
  528. Tcl_Obj *validateMethodVarPtr;
  529. ItclDelegatedOption *idoPtr;
  530. /* if the option is delegated != NULL */
  531. } ItclOption;
  532. /*
  533. * Instance methodvariables.
  534. */
  535. typedef struct ItclMethodVariable {
  536. Tcl_Obj *namePtr; /* member name */
  537. Tcl_Obj *fullNamePtr; /* member name with "class::" qualifier */
  538. ItclClass *iclsPtr; /* class containing this member */
  539. int protection; /* protection level */
  540. int flags; /* flags describing member (see below) */
  541. Tcl_Obj *defaultValuePtr;
  542. Tcl_Obj *callbackPtr;
  543. } ItclMethodVariable;
  544. #define VAR_TYPE_VARIABLE 1
  545. #define VAR_TYPE_COMMON 2
  546. #define CMD_TYPE_METHOD 1
  547. #define CMD_TYPE_PROC 2
  548. typedef struct ItclClassCmdInfo {
  549. int type;
  550. int protection;
  551. int cmdNum;
  552. Tcl_Namespace *nsPtr;
  553. Tcl_Namespace *declaringNsPtr;
  554. } ItclClassCmdInfo;
  555. /*
  556. * Instance variable lookup entry.
  557. */
  558. typedef struct ItclVarLookup {
  559. ItclVariable* ivPtr; /* variable definition */
  560. int usage; /* number of uses for this record */
  561. int accessible; /* non-zero => accessible from class with
  562. * this lookup record in its resolveVars */
  563. char *leastQualName; /* simplist name for this variable, with
  564. * the fewest qualifiers. This string is
  565. * taken from the resolveVars table, so
  566. * it shouldn't be freed. */
  567. int varNum;
  568. Tcl_Var varPtr;
  569. } ItclVarLookup;
  570. /*
  571. * Instance command lookup entry.
  572. */
  573. typedef struct ItclCmdLookup {
  574. ItclMemberFunc* imPtr; /* function definition */
  575. int cmdNum;
  576. ItclClassCmdInfo *classCmdInfoPtr;
  577. Tcl_Command cmdPtr;
  578. } ItclCmdLookup;
  579. typedef struct ItclCallContext {
  580. int objectFlags;
  581. Tcl_Namespace *nsPtr;
  582. ItclObject *ioPtr;
  583. ItclMemberFunc *imPtr;
  584. int refCount;
  585. } ItclCallContext;
  586. /*
  587. * The macro below is used to modify a "char" value (e.g. by casting
  588. * it to an unsigned character) so that it can be used safely with
  589. * macros such as isspace.
  590. */
  591. #define UCHAR(c) ((unsigned char) (c))
  592. /*
  593. * Macros used to cast between pointers and integers (e.g. when storing an int
  594. * in ClientData), on 64-bit architectures they avoid gcc warning about "cast
  595. * to/from pointer from/to integer of different size".
  596. */
  597. #if !defined(INT2PTR) && !defined(PTR2INT)
  598. # if defined(HAVE_INTPTR_T) || defined(intptr_t)
  599. # define INT2PTR(p) ((void*)(intptr_t)(p))
  600. # define PTR2INT(p) ((int)(intptr_t)(p))
  601. # else
  602. # define INT2PTR(p) ((void*)(p))
  603. # define PTR2INT(p) ((int)(p))
  604. # endif
  605. #endif
  606. #ifdef ITCL_DEBUG
  607. MODULE_SCOPE int _itcl_debug_level;
  608. MODULE_SCOPE void ItclShowArgs(int level, const char *str, int objc,
  609. Tcl_Obj * const* objv);
  610. #else
  611. #define ItclShowArgs(a,b,c,d) do {(void)(c);(void)(d);} while(0)
  612. #endif
  613. MODULE_SCOPE Tcl_ObjCmdProc ItclCallCCommand;
  614. MODULE_SCOPE Tcl_ObjCmdProc ItclObjectUnknownCommand;
  615. MODULE_SCOPE int ItclCheckCallProc(ClientData clientData, Tcl_Interp *interp,
  616. Tcl_ObjectContext contextPtr, Tcl_CallFrame *framePtr, int *isFinished);
  617. MODULE_SCOPE void ItclPreserveClass(ItclClass *iclsPtr);
  618. MODULE_SCOPE void ItclReleaseClass(ClientData iclsPtr);
  619. MODULE_SCOPE ItclFoundation *ItclGetFoundation(Tcl_Interp *interp);
  620. MODULE_SCOPE Tcl_ObjCmdProc ItclClassCommandDispatcher;
  621. MODULE_SCOPE Tcl_Command Itcl_CmdAliasProc(Tcl_Interp *interp,
  622. Tcl_Namespace *nsPtr, const char *cmdName, ClientData clientData);
  623. MODULE_SCOPE Tcl_Var Itcl_VarAliasProc(Tcl_Interp *interp,
  624. Tcl_Namespace *nsPtr, const char *VarName, ClientData clientData);
  625. MODULE_SCOPE int ItclIsClass(Tcl_Interp *interp, Tcl_Command cmd);
  626. MODULE_SCOPE int ItclCheckCallMethod(ClientData clientData, Tcl_Interp *interp,
  627. Tcl_ObjectContext contextPtr, Tcl_CallFrame *framePtr, int *isFinished);
  628. MODULE_SCOPE int ItclAfterCallMethod(ClientData clientData, Tcl_Interp *interp,
  629. Tcl_ObjectContext contextPtr, Tcl_Namespace *nsPtr, int result);
  630. MODULE_SCOPE void ItclReportObjectUsage(Tcl_Interp *interp,
  631. ItclObject *contextIoPtr, Tcl_Namespace *callerNsPtr,
  632. Tcl_Namespace *contextNsPtr);
  633. MODULE_SCOPE int ItclMapMethodNameProc(Tcl_Interp *interp, Tcl_Object oPtr,
  634. Tcl_Class *startClsPtr, Tcl_Obj *methodObj);
  635. MODULE_SCOPE int ItclCreateArgList(Tcl_Interp *interp, const char *str,
  636. int *argcPtr, int *maxArgcPtr, Tcl_Obj **usagePtr,
  637. ItclArgList **arglistPtrPtr, ItclMemberFunc *imPtr,
  638. const char *commandName);
  639. MODULE_SCOPE int ItclObjectCmd(ClientData clientData, Tcl_Interp *interp,
  640. Tcl_Object oPtr, Tcl_Class clsPtr, int objc, Tcl_Obj *const *objv);
  641. MODULE_SCOPE int ItclCreateObject (Tcl_Interp *interp, const char* name,
  642. ItclClass *iclsPtr, int objc, Tcl_Obj *const objv[]);
  643. MODULE_SCOPE void ItclDeleteObjectVariablesNamespace(Tcl_Interp *interp,
  644. ItclObject *ioPtr);
  645. MODULE_SCOPE void ItclDeleteClassVariablesNamespace(Tcl_Interp *interp,
  646. ItclClass *iclsPtr);
  647. MODULE_SCOPE int ItclInfoInit(Tcl_Interp *interp, ItclObjectInfo *infoPtr);
  648. MODULE_SCOPE Tcl_HashEntry *ItclResolveVarEntry(
  649. ItclClass* iclsPtr, const char *varName);
  650. struct Tcl_ResolvedVarInfo;
  651. MODULE_SCOPE int Itcl_ClassCmdResolver(Tcl_Interp *interp, const char* name,
  652. Tcl_Namespace *nsPtr, int flags, Tcl_Command *rPtr);
  653. MODULE_SCOPE int Itcl_ClassVarResolver(Tcl_Interp *interp, const char* name,
  654. Tcl_Namespace *nsPtr, int flags, Tcl_Var *rPtr);
  655. MODULE_SCOPE int Itcl_ClassCompiledVarResolver(Tcl_Interp *interp,
  656. const char* name, int length, Tcl_Namespace *nsPtr,
  657. struct Tcl_ResolvedVarInfo **rPtr);
  658. MODULE_SCOPE int Itcl_ClassCmdResolver2(Tcl_Interp *interp, const char* name,
  659. Tcl_Namespace *nsPtr, int flags, Tcl_Command *rPtr);
  660. MODULE_SCOPE int Itcl_ClassVarResolver2(Tcl_Interp *interp, const char* name,
  661. Tcl_Namespace *nsPtr, int flags, Tcl_Var *rPtr);
  662. MODULE_SCOPE int Itcl_ClassCompiledVarResolver2(Tcl_Interp *interp,
  663. const char* name, int length, Tcl_Namespace *nsPtr,
  664. struct Tcl_ResolvedVarInfo **rPtr);
  665. MODULE_SCOPE int ItclSetParserResolver(Tcl_Namespace *nsPtr);
  666. MODULE_SCOPE void ItclProcErrorProc(Tcl_Interp *interp, Tcl_Obj *procNameObj);
  667. MODULE_SCOPE int Itcl_CreateOption (Tcl_Interp *interp, ItclClass *iclsPtr,
  668. ItclOption *ioptPtr);
  669. MODULE_SCOPE int ItclCreateMethodVariable(Tcl_Interp *interp,
  670. ItclVariable *ivPtr, Tcl_Obj* defaultPtr, Tcl_Obj* callbackPtr,
  671. ItclMethodVariable** imvPtrPtr);
  672. MODULE_SCOPE int DelegationInstall(Tcl_Interp *interp, ItclObject *ioPtr,
  673. ItclClass *iclsPtr);
  674. MODULE_SCOPE ItclClass *ItclNamespace2Class(Tcl_Namespace *nsPtr);
  675. MODULE_SCOPE const char* ItclGetCommonInstanceVar(Tcl_Interp *interp,
  676. const char *name, const char *name2, ItclObject *contextIoPtr,
  677. ItclClass *contextIclsPtr);
  678. MODULE_SCOPE int ItclCreateMethod(Tcl_Interp* interp, ItclClass *iclsPtr,
  679. Tcl_Obj *namePtr, const char* arglist, const char* body,
  680. ItclMemberFunc **imPtrPtr);
  681. MODULE_SCOPE int Itcl_WidgetParseInit(Tcl_Interp *interp,
  682. ItclObjectInfo *infoPtr);
  683. MODULE_SCOPE void ItclDeleteObjectMetadata(ClientData clientData);
  684. MODULE_SCOPE void ItclDeleteClassMetadata(ClientData clientData);
  685. MODULE_SCOPE void ItclDeleteArgList(ItclArgList *arglistPtr);
  686. MODULE_SCOPE int Itcl_ClassOptionCmd(ClientData clientData, Tcl_Interp *interp,
  687. int objc, Tcl_Obj *const objv[]);
  688. MODULE_SCOPE int DelegatedOptionsInstall(Tcl_Interp *interp,
  689. ItclClass *iclsPtr);
  690. MODULE_SCOPE int Itcl_HandleDelegateOptionCmd(Tcl_Interp *interp,
  691. ItclObject *ioPtr, ItclClass *iclsPtr, ItclDelegatedOption **idoPtrPtr,
  692. int objc, Tcl_Obj *const objv[]);
  693. MODULE_SCOPE int Itcl_HandleDelegateMethodCmd(Tcl_Interp *interp,
  694. ItclObject *ioPtr, ItclClass *iclsPtr,
  695. ItclDelegatedFunction **idmPtrPtr, int objc, Tcl_Obj *const objv[]);
  696. MODULE_SCOPE int DelegateFunction(Tcl_Interp *interp, ItclObject *ioPtr,
  697. ItclClass *iclsPtr, Tcl_Obj *componentNamePtr,
  698. ItclDelegatedFunction *idmPtr);
  699. MODULE_SCOPE int ItclInitObjectMethodVariables(Tcl_Interp *interp,
  700. ItclObject *ioPtr, ItclClass *iclsPtr, const char *name);
  701. MODULE_SCOPE int InitTclOOFunctionPointers(Tcl_Interp *interp);
  702. MODULE_SCOPE ItclOption* ItclNewOption(Tcl_Interp *interp, ItclObject *ioPtr,
  703. ItclClass *iclsPtr, Tcl_Obj *namePtr, const char *resourceName,
  704. const char *className, char *init, ItclMemberCode *mCodePtr);
  705. MODULE_SCOPE int ItclParseOption(ItclObjectInfo *infoPtr, Tcl_Interp *interp,
  706. int objc, Tcl_Obj *const objv[], ItclClass *iclsPtr,
  707. ItclObject *ioPtr, ItclOption **ioptPtrPtr);
  708. MODULE_SCOPE void ItclDestroyClassNamesp(ClientData cdata);
  709. MODULE_SCOPE int ExpandDelegateAs(Tcl_Interp *interp, ItclObject *ioPtr,
  710. ItclClass *iclsPtr, ItclDelegatedFunction *idmPtr,
  711. const char *funcName, Tcl_Obj *listPtr);
  712. MODULE_SCOPE int ItclCheckForInitializedComponents(Tcl_Interp *interp,
  713. ItclClass *iclsPtr, ItclObject *ioPtr);
  714. MODULE_SCOPE int ItclCreateDelegatedFunction(Tcl_Interp *interp,
  715. ItclClass *iclsPtr, Tcl_Obj *methodNamePtr, ItclComponent *icPtr,
  716. Tcl_Obj *targetPtr, Tcl_Obj *usingPtr, Tcl_Obj *exceptionsPtr,
  717. ItclDelegatedFunction **idmPtrPtr);
  718. MODULE_SCOPE void ItclDeleteDelegatedOption(char *cdata);
  719. MODULE_SCOPE void Itcl_FinishList();
  720. MODULE_SCOPE void ItclDeleteDelegatedFunction(ItclDelegatedFunction *idmPtr);
  721. MODULE_SCOPE void ItclFinishEnsemble(ItclObjectInfo *infoPtr);
  722. MODULE_SCOPE int Itcl_EnsembleDeleteCmd(ClientData clientData,
  723. Tcl_Interp *interp, int objc, Tcl_Obj *const objv[]);
  724. MODULE_SCOPE int ItclAddClassesDictInfo(Tcl_Interp *interp, ItclClass *iclsPtr);
  725. MODULE_SCOPE int ItclDeleteClassesDictInfo(Tcl_Interp *interp,
  726. ItclClass *iclsPtr);
  727. MODULE_SCOPE int ItclAddObjectsDictInfo(Tcl_Interp *interp, ItclObject *ioPtr);
  728. MODULE_SCOPE int ItclDeleteObjectsDictInfo(Tcl_Interp *interp,
  729. ItclObject *ioPtr);
  730. MODULE_SCOPE int ItclAddOptionDictInfo(Tcl_Interp *interp, ItclClass *iclsPtr,
  731. ItclOption *ioptPtr);
  732. MODULE_SCOPE int ItclAddDelegatedOptionDictInfo(Tcl_Interp *interp,
  733. ItclClass *iclsPtr, ItclDelegatedOption *idoPtr);
  734. MODULE_SCOPE int ItclAddClassComponentDictInfo(Tcl_Interp *interp,
  735. ItclClass *iclsPtr, ItclComponent *icPtr);
  736. MODULE_SCOPE int ItclAddClassVariableDictInfo(Tcl_Interp *interp,
  737. ItclClass *iclsPtr, ItclVariable *ivPtr);
  738. MODULE_SCOPE int ItclAddClassFunctionDictInfo(Tcl_Interp *interp,
  739. ItclClass *iclsPtr, ItclMemberFunc *imPtr);
  740. MODULE_SCOPE int ItclAddClassDelegatedFunctionDictInfo(Tcl_Interp *interp,
  741. ItclClass *iclsPtr, ItclDelegatedFunction *idmPtr);
  742. MODULE_SCOPE int ItclClassCreateObject(ClientData clientData, Tcl_Interp *interp,
  743. int objc, Tcl_Obj *const objv[]);
  744. MODULE_SCOPE void ItclRestoreInfoVars(ClientData clientData);
  745. MODULE_SCOPE Tcl_ObjCmdProc Itcl_BiMyProcCmd;
  746. MODULE_SCOPE Tcl_ObjCmdProc Itcl_BiInstallComponentCmd;
  747. MODULE_SCOPE Tcl_ObjCmdProc Itcl_BiCallInstanceCmd;
  748. MODULE_SCOPE Tcl_ObjCmdProc Itcl_BiGetInstanceVarCmd;
  749. MODULE_SCOPE Tcl_ObjCmdProc Itcl_BiMyTypeMethodCmd;
  750. MODULE_SCOPE Tcl_ObjCmdProc Itcl_BiMyMethodCmd;
  751. MODULE_SCOPE Tcl_ObjCmdProc Itcl_BiMyTypeVarCmd;
  752. MODULE_SCOPE Tcl_ObjCmdProc Itcl_BiMyVarCmd;
  753. MODULE_SCOPE Tcl_ObjCmdProc Itcl_BiItclHullCmd;
  754. MODULE_SCOPE Tcl_ObjCmdProc Itcl_ThisCmd;
  755. MODULE_SCOPE Tcl_ObjCmdProc Itcl_ExtendedClassCmd;
  756. MODULE_SCOPE Tcl_ObjCmdProc Itcl_TypeClassCmd;
  757. MODULE_SCOPE Tcl_ObjCmdProc Itcl_AddObjectOptionCmd;
  758. MODULE_SCOPE Tcl_ObjCmdProc Itcl_AddDelegatedOptionCmd;
  759. MODULE_SCOPE Tcl_ObjCmdProc Itcl_AddDelegatedFunctionCmd;
  760. MODULE_SCOPE Tcl_ObjCmdProc Itcl_SetComponentCmd;
  761. MODULE_SCOPE Tcl_ObjCmdProc Itcl_ClassHullTypeCmd;
  762. MODULE_SCOPE Tcl_ObjCmdProc Itcl_ClassWidgetClassCmd;
  763. typedef int (ItclRootMethodProc)(ItclObject *ioPtr, Tcl_Interp *interp,
  764. int objc, Tcl_Obj *const objv[]);
  765. MODULE_SCOPE const Tcl_MethodType itclRootMethodType;
  766. MODULE_SCOPE ItclRootMethodProc ItclUnknownGuts;
  767. MODULE_SCOPE ItclRootMethodProc ItclConstructGuts;
  768. MODULE_SCOPE ItclRootMethodProc ItclInfoGuts;
  769. #include "itcl2TclOO.h"
  770. /*
  771. * Include all the private API, generated from itcl.decls.
  772. */
  773. #include "itclIntDecls.h"