tclOOInt.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  1. /*
  2. * tclOOInt.h --
  3. *
  4. * This file contains the structure definitions and some of the function
  5. * declarations for the object-system (NB: not Tcl_Obj, but ::oo).
  6. *
  7. * Copyright (c) 2006-2012 by Donal K. Fellows
  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. #ifndef TCL_OO_INTERNAL_H
  13. #define TCL_OO_INTERNAL_H 1
  14. #include "tclInt.h"
  15. #include "tclOO.h"
  16. /*
  17. * Hack to make things work with Objective C. Note that ObjC isn't really
  18. * supported, but we don't want to to be actively hostile to it. [Bug 2163447]
  19. */
  20. #ifdef __OBJC__
  21. #define Class TclOOClass
  22. #define Object TclOOObject
  23. #endif /* __OBJC__ */
  24. /*
  25. * Forward declarations.
  26. */
  27. struct CallChain;
  28. struct Class;
  29. struct Foundation;
  30. struct Object;
  31. /*
  32. * The data that needs to be stored per method. This record is used to collect
  33. * information about all sorts of methods, including forwards, constructors
  34. * and destructors.
  35. */
  36. typedef struct Method {
  37. const Tcl_MethodType *typePtr;
  38. /* The type of method. If NULL, this is a
  39. * special flag record which is just used for
  40. * the setting of the flags field. */
  41. int refCount;
  42. ClientData clientData; /* Type-specific data. */
  43. Tcl_Obj *namePtr; /* Name of the method. */
  44. struct Object *declaringObjectPtr;
  45. /* The object that declares this method, or
  46. * NULL if it was declared by a class. */
  47. struct Class *declaringClassPtr;
  48. /* The class that declares this method, or
  49. * NULL if it was declared directly on an
  50. * object. */
  51. int flags; /* Assorted flags. Includes whether this
  52. * method is public/exported or not. */
  53. } Method;
  54. /*
  55. * Pre- and post-call callbacks, to allow procedure-like methods to be fine
  56. * tuned in their behaviour.
  57. */
  58. typedef int (TclOO_PreCallProc)(ClientData clientData, Tcl_Interp *interp,
  59. Tcl_ObjectContext context, Tcl_CallFrame *framePtr, int *isFinished);
  60. typedef int (TclOO_PostCallProc)(ClientData clientData, Tcl_Interp *interp,
  61. Tcl_ObjectContext context, Tcl_Namespace *namespacePtr, int result);
  62. typedef void (TclOO_PmCDDeleteProc)(ClientData clientData);
  63. typedef ClientData (TclOO_PmCDCloneProc)(ClientData clientData);
  64. /*
  65. * Procedure-like methods have the following extra information.
  66. */
  67. typedef struct ProcedureMethod {
  68. int version; /* Version of this structure. Currently must
  69. * be 0. */
  70. Proc *procPtr; /* Core of the implementation of the method;
  71. * includes the argument definition and the
  72. * body bytecodes. */
  73. int flags; /* Flags to control features. */
  74. int refCount;
  75. ClientData clientData;
  76. TclOO_PmCDDeleteProc *deleteClientdataProc;
  77. TclOO_PmCDCloneProc *cloneClientdataProc;
  78. ProcErrorProc *errProc; /* Replacement error handler. */
  79. TclOO_PreCallProc *preCallProc;
  80. /* Callback to allow for additional setup
  81. * before the method executes. */
  82. TclOO_PostCallProc *postCallProc;
  83. /* Callback to allow for additional cleanup
  84. * after the method executes. */
  85. GetFrameInfoValueProc *gfivProc;
  86. /* Callback to allow for fine tuning of how
  87. * the method reports itself. */
  88. } ProcedureMethod;
  89. #define TCLOO_PROCEDURE_METHOD_VERSION 0
  90. /*
  91. * Flags for use in a ProcedureMethod.
  92. *
  93. * When the USE_DECLARER_NS flag is set, the method will use the namespace of
  94. * the object or class that declared it (or the clone of it, if it was from
  95. * such that the implementation of the method came to the particular use)
  96. * instead of the namespace of the object on which the method was invoked.
  97. * This flag must be distinct from all others that are associated with
  98. * methods.
  99. */
  100. #define USE_DECLARER_NS 0x80
  101. /*
  102. * Forwarded methods have the following extra information.
  103. */
  104. typedef struct ForwardMethod {
  105. Tcl_Obj *prefixObj; /* The list of values to use to replace the
  106. * object and method name with. Will be a
  107. * non-empty list. */
  108. } ForwardMethod;
  109. /*
  110. * Helper definitions that declare a "list" array. The two varieties are
  111. * either optimized for simplicity (in the case that the whole array is
  112. * typically assigned at once) or efficiency (in the case that the array is
  113. * expected to be expanded over time). These lists are designed to be iterated
  114. * over with the help of the FOREACH macro (see later in this file).
  115. *
  116. * The "num" field always counts the number of listType_t elements used in the
  117. * "list" field. When a "size" field exists, it describes how many elements
  118. * are present in the list; when absent, exactly "num" elements are present.
  119. */
  120. #define LIST_STATIC(listType_t) \
  121. struct { int num; listType_t *list; }
  122. #define LIST_DYNAMIC(listType_t) \
  123. struct { int num, size; listType_t *list; }
  124. /*
  125. * Now, the definition of what an object actually is.
  126. */
  127. typedef struct Object {
  128. struct Foundation *fPtr; /* The basis for the object system. Putting
  129. * this here allows the avoidance of quite a
  130. * lot of hash lookups on the critical path
  131. * for object invocation and creation. */
  132. Tcl_Namespace *namespacePtr;/* This object's namespace. */
  133. Tcl_Command command; /* Reference to this object's public
  134. * command. */
  135. Tcl_Command myCommand; /* Reference to this object's internal
  136. * command. */
  137. struct Class *selfCls; /* This object's class. */
  138. Tcl_HashTable *methodsPtr; /* Object-local Tcl_Obj (method name) to
  139. * Method* mapping. */
  140. LIST_STATIC(struct Class *) mixins;
  141. /* Classes mixed into this object. */
  142. LIST_STATIC(Tcl_Obj *) filters;
  143. /* List of filter names. */
  144. struct Class *classPtr; /* This is non-NULL for all classes, and NULL
  145. * for everything else. It points to the class
  146. * structure. */
  147. int refCount; /* Number of strong references to this object.
  148. * Note that there may be many more weak
  149. * references; this mechanism exists to
  150. * avoid Tcl_Preserve. */
  151. int flags;
  152. int creationEpoch; /* Unique value to make comparisons of objects
  153. * easier. */
  154. int epoch; /* Per-object epoch, incremented when the way
  155. * an object should resolve call chains is
  156. * changed. */
  157. Tcl_HashTable *metadataPtr; /* Mapping from pointers to metadata type to
  158. * the ClientData values that are the values
  159. * of each piece of attached metadata. This
  160. * field starts out as NULL and is only
  161. * allocated if metadata is attached. */
  162. Tcl_Obj *cachedNameObj; /* Cache of the name of the object. */
  163. Tcl_HashTable *chainCache; /* Place to keep unused contexts. This table
  164. * is indexed by method name as Tcl_Obj. */
  165. Tcl_ObjectMapMethodNameProc *mapMethodNameProc;
  166. /* Function to allow remapping of method
  167. * names. For itcl-ng. */
  168. LIST_STATIC(Tcl_Obj *) variables;
  169. } Object;
  170. #define OBJECT_DESTRUCTING 1 /* Indicates that an object is being or has
  171. * been destroyed */
  172. #define DESTRUCTOR_CALLED 2 /* Indicates that evaluation of destructor script for the
  173. object has began */
  174. #define OO_UNUSED_4 4 /* No longer used. */
  175. #define ROOT_OBJECT 0x1000 /* Flag to say that this object is the root of
  176. * the class hierarchy and should be treated
  177. * specially during teardown. */
  178. #define FILTER_HANDLING 0x2000 /* Flag set when the object is processing a
  179. * filter; when set, filters are *not*
  180. * processed on the object, preventing nasty
  181. * recursive filtering problems. */
  182. #define USE_CLASS_CACHE 0x4000 /* Flag set to say that the object is a pure
  183. * instance of the class, and has had nothing
  184. * added that changes the dispatch chain (i.e.
  185. * no methods, mixins, or filters. */
  186. #define ROOT_CLASS 0x8000 /* Flag to say that this object is the root
  187. * class of classes, and should be treated
  188. * specially during teardown (and in a few
  189. * other spots). */
  190. #define FORCE_UNKNOWN 0x10000 /* States that we are *really* looking up the
  191. * unknown method handler at that point. */
  192. #define DONT_DELETE 0x20000 /* Inhibit deletion of this object. */
  193. /*
  194. * And the definition of a class. Note that every class also has an associated
  195. * object, through which it is manipulated.
  196. */
  197. typedef struct Class {
  198. Object *thisPtr; /* Reference to the object associated with
  199. * this class. */
  200. int flags; /* Assorted flags. */
  201. LIST_STATIC(struct Class *) superclasses;
  202. /* List of superclasses, used for generation
  203. * of method call chains. */
  204. LIST_DYNAMIC(struct Class *) subclasses;
  205. /* List of subclasses, used to ensure deletion
  206. * of dependent entities happens properly when
  207. * the class itself is deleted. */
  208. LIST_DYNAMIC(Object *) instances;
  209. /* List of instances, used to ensure deletion
  210. * of dependent entities happens properly when
  211. * the class itself is deleted. */
  212. LIST_STATIC(Tcl_Obj *) filters;
  213. /* List of filter names, used for generation
  214. * of method call chains. */
  215. LIST_STATIC(struct Class *) mixins;
  216. /* List of mixin classes, used for generation
  217. * of method call chains. */
  218. LIST_DYNAMIC(struct Class *) mixinSubs;
  219. /* List of classes that this class is mixed
  220. * into, used to ensure deletion of dependent
  221. * entities happens properly when the class
  222. * itself is deleted. */
  223. Tcl_HashTable classMethods; /* Hash table of all methods. Hash maps from
  224. * the (Tcl_Obj*) method name to the (Method*)
  225. * method record. */
  226. Method *constructorPtr; /* Method record of the class constructor (if
  227. * any). */
  228. Method *destructorPtr; /* Method record of the class destructor (if
  229. * any). */
  230. Tcl_HashTable *metadataPtr; /* Mapping from pointers to metadata type to
  231. * the ClientData values that are the values
  232. * of each piece of attached metadata. This
  233. * field starts out as NULL and is only
  234. * allocated if metadata is attached. */
  235. struct CallChain *constructorChainPtr;
  236. struct CallChain *destructorChainPtr;
  237. Tcl_HashTable *classChainCache;
  238. /* Places where call chains are stored. For
  239. * constructors, the class chain is always
  240. * used. For destructors and ordinary methods,
  241. * the class chain is only used when the
  242. * object doesn't override with its own mixins
  243. * (and filters and method implementations for
  244. * when getting method chains). */
  245. LIST_STATIC(Tcl_Obj *) variables;
  246. } Class;
  247. /*
  248. * The foundation of the object system within an interpreter contains
  249. * references to the key classes and namespaces, together with a few other
  250. * useful bits and pieces. Probably ought to eventually go in the Interp
  251. * structure itself.
  252. */
  253. typedef struct ThreadLocalData {
  254. int nsCount; /* Epoch counter is used for keeping
  255. * the values used in Tcl_Obj internal
  256. * representations sane. Must be thread-local
  257. * because Tcl_Objs can cross interpreter
  258. * boundaries within a thread (objects don't
  259. * generally cross threads). */
  260. } ThreadLocalData;
  261. typedef struct Foundation {
  262. Tcl_Interp *interp;
  263. Class *objectCls; /* The root of the object system. */
  264. Class *classCls; /* The class of all classes. */
  265. Tcl_Namespace *ooNs; /* ::oo namespace. */
  266. Tcl_Namespace *defineNs; /* Namespace containing special commands for
  267. * manipulating objects and classes. The
  268. * "oo::define" command acts as a special kind
  269. * of ensemble for this namespace. */
  270. Tcl_Namespace *objdefNs; /* Namespace containing special commands for
  271. * manipulating objects and classes. The
  272. * "oo::objdefine" command acts as a special
  273. * kind of ensemble for this namespace. */
  274. Tcl_Namespace *helpersNs; /* Namespace containing the commands that are
  275. * only valid when executing inside a
  276. * procedural method. */
  277. int epoch; /* Used to invalidate method chains when the
  278. * class structure changes. */
  279. ThreadLocalData *tsdPtr; /* Counter so we can allocate a unique
  280. * namespace to each object. */
  281. Tcl_Obj *unknownMethodNameObj;
  282. /* Shared object containing the name of the
  283. * unknown method handler method. */
  284. Tcl_Obj *constructorName; /* Shared object containing the "name" of a
  285. * constructor. */
  286. Tcl_Obj *destructorName; /* Shared object containing the "name" of a
  287. * destructor. */
  288. Tcl_Obj *clonedName; /* Shared object containing the name of a
  289. * "<cloned>" pseudo-constructor. */
  290. Tcl_Obj *defineName; /* Fully qualified name of oo::define. */
  291. } Foundation;
  292. /*
  293. * A call context structure is built when a method is called. It contains the
  294. * chain of method implementations that are to be invoked by a particular
  295. * call, and the process of calling walks the chain, with the [next] command
  296. * proceeding to the next entry in the chain.
  297. */
  298. #define CALL_CHAIN_STATIC_SIZE 4
  299. struct MInvoke {
  300. Method *mPtr; /* Reference to the method implementation
  301. * record. */
  302. int isFilter; /* Whether this is a filter invocation. */
  303. Class *filterDeclarer; /* What class decided to add the filter; if
  304. * NULL, it was added by the object. */
  305. };
  306. typedef struct CallChain {
  307. int objectCreationEpoch; /* The object's creation epoch. Note that the
  308. * object reference is not stored in the call
  309. * chain; it is in the call context. */
  310. int objectEpoch; /* Local (object structure) epoch counter
  311. * snapshot. */
  312. int epoch; /* Global (class structure) epoch counter
  313. * snapshot. */
  314. int flags; /* Assorted flags, see below. */
  315. int refCount; /* Reference count. */
  316. int numChain; /* Size of the call chain. */
  317. struct MInvoke *chain; /* Array of call chain entries. May point to
  318. * staticChain if the number of entries is
  319. * small. */
  320. struct MInvoke staticChain[CALL_CHAIN_STATIC_SIZE];
  321. } CallChain;
  322. typedef struct CallContext {
  323. Object *oPtr; /* The object associated with this call. */
  324. int index; /* Index into the call chain of the currently
  325. * executing method implementation. */
  326. int skip; /* Current number of arguments to skip; can
  327. * vary depending on whether it is a direct
  328. * method call or a continuation via the
  329. * [next] command. */
  330. CallChain *callPtr; /* The actual call chain. */
  331. } CallContext;
  332. /*
  333. * Bits for the 'flags' field of the call chain.
  334. */
  335. #define PUBLIC_METHOD 0x01 /* This is a public (exported) method. */
  336. #define PRIVATE_METHOD 0x02 /* This is a private (class's direct instances
  337. * only) method. */
  338. #define OO_UNKNOWN_METHOD 0x04 /* This is an unknown method. */
  339. #define CONSTRUCTOR 0x08 /* This is a constructor. */
  340. #define DESTRUCTOR 0x10 /* This is a destructor. */
  341. /*
  342. * Structure containing definition information about basic class methods.
  343. */
  344. typedef struct {
  345. const char *name; /* Name of the method in question. */
  346. int isPublic; /* Whether the method is public by default. */
  347. Tcl_MethodType definition; /* How to call the method. */
  348. } DeclaredClassMethod;
  349. /*
  350. *----------------------------------------------------------------
  351. * Commands relating to OO support.
  352. *----------------------------------------------------------------
  353. */
  354. MODULE_SCOPE int TclOOInit(Tcl_Interp *interp);
  355. MODULE_SCOPE int TclOODefineObjCmd(ClientData clientData,
  356. Tcl_Interp *interp, int objc,
  357. Tcl_Obj *const *objv);
  358. MODULE_SCOPE int TclOOObjDefObjCmd(ClientData clientData,
  359. Tcl_Interp *interp, int objc,
  360. Tcl_Obj *const *objv);
  361. MODULE_SCOPE int TclOODefineConstructorObjCmd(ClientData clientData,
  362. Tcl_Interp *interp, int objc,
  363. Tcl_Obj *const *objv);
  364. MODULE_SCOPE int TclOODefineDeleteMethodObjCmd(ClientData clientData,
  365. Tcl_Interp *interp, int objc,
  366. Tcl_Obj *const *objv);
  367. MODULE_SCOPE int TclOODefineDestructorObjCmd(ClientData clientData,
  368. Tcl_Interp *interp, int objc,
  369. Tcl_Obj *const *objv);
  370. MODULE_SCOPE int TclOODefineExportObjCmd(ClientData clientData,
  371. Tcl_Interp *interp, int objc,
  372. Tcl_Obj *const *objv);
  373. MODULE_SCOPE int TclOODefineForwardObjCmd(ClientData clientData,
  374. Tcl_Interp *interp, int objc,
  375. Tcl_Obj *const *objv);
  376. MODULE_SCOPE int TclOODefineMethodObjCmd(ClientData clientData,
  377. Tcl_Interp *interp, int objc,
  378. Tcl_Obj *const *objv);
  379. MODULE_SCOPE int TclOODefineRenameMethodObjCmd(ClientData clientData,
  380. Tcl_Interp *interp, int objc,
  381. Tcl_Obj *const *objv);
  382. MODULE_SCOPE int TclOODefineUnexportObjCmd(ClientData clientData,
  383. Tcl_Interp *interp, int objc,
  384. Tcl_Obj *const *objv);
  385. MODULE_SCOPE int TclOODefineClassObjCmd(ClientData clientData,
  386. Tcl_Interp *interp, int objc,
  387. Tcl_Obj *const *objv);
  388. MODULE_SCOPE int TclOODefineSelfObjCmd(ClientData clientData,
  389. Tcl_Interp *interp, int objc,
  390. Tcl_Obj *const *objv);
  391. MODULE_SCOPE int TclOOUnknownDefinition(ClientData clientData,
  392. Tcl_Interp *interp, int objc,
  393. Tcl_Obj *const *objv);
  394. MODULE_SCOPE int TclOOCopyObjectCmd(ClientData clientData,
  395. Tcl_Interp *interp, int objc,
  396. Tcl_Obj *const *objv);
  397. MODULE_SCOPE int TclOONextObjCmd(ClientData clientData,
  398. Tcl_Interp *interp, int objc,
  399. Tcl_Obj *const *objv);
  400. MODULE_SCOPE int TclOONextToObjCmd(ClientData clientData,
  401. Tcl_Interp *interp, int objc,
  402. Tcl_Obj *const *objv);
  403. MODULE_SCOPE int TclOOSelfObjCmd(ClientData clientData,
  404. Tcl_Interp *interp, int objc,
  405. Tcl_Obj *const *objv);
  406. /*
  407. * Method implementations (in tclOOBasic.c).
  408. */
  409. MODULE_SCOPE int TclOO_Class_Constructor(ClientData clientData,
  410. Tcl_Interp *interp, Tcl_ObjectContext context,
  411. int objc, Tcl_Obj *const *objv);
  412. MODULE_SCOPE int TclOO_Class_Create(ClientData clientData,
  413. Tcl_Interp *interp, Tcl_ObjectContext context,
  414. int objc, Tcl_Obj *const *objv);
  415. MODULE_SCOPE int TclOO_Class_CreateNs(ClientData clientData,
  416. Tcl_Interp *interp, Tcl_ObjectContext context,
  417. int objc, Tcl_Obj *const *objv);
  418. MODULE_SCOPE int TclOO_Class_New(ClientData clientData,
  419. Tcl_Interp *interp, Tcl_ObjectContext context,
  420. int objc, Tcl_Obj *const *objv);
  421. MODULE_SCOPE int TclOO_Object_Destroy(ClientData clientData,
  422. Tcl_Interp *interp, Tcl_ObjectContext context,
  423. int objc, Tcl_Obj *const *objv);
  424. MODULE_SCOPE int TclOO_Object_Eval(ClientData clientData,
  425. Tcl_Interp *interp, Tcl_ObjectContext context,
  426. int objc, Tcl_Obj *const *objv);
  427. MODULE_SCOPE int TclOO_Object_LinkVar(ClientData clientData,
  428. Tcl_Interp *interp, Tcl_ObjectContext context,
  429. int objc, Tcl_Obj *const *objv);
  430. MODULE_SCOPE int TclOO_Object_Unknown(ClientData clientData,
  431. Tcl_Interp *interp, Tcl_ObjectContext context,
  432. int objc, Tcl_Obj *const *objv);
  433. MODULE_SCOPE int TclOO_Object_VarName(ClientData clientData,
  434. Tcl_Interp *interp, Tcl_ObjectContext context,
  435. int objc, Tcl_Obj *const *objv);
  436. /*
  437. * Private definitions, some of which perhaps ought to be exposed properly or
  438. * maybe just put in the internal stubs table.
  439. */
  440. MODULE_SCOPE void TclOOAddToInstances(Object *oPtr, Class *clsPtr);
  441. MODULE_SCOPE void TclOOAddToMixinSubs(Class *subPtr, Class *mixinPtr);
  442. MODULE_SCOPE void TclOOAddToSubclasses(Class *subPtr, Class *superPtr);
  443. MODULE_SCOPE Class * TclOOAllocClass(Tcl_Interp *interp,
  444. Object *useThisObj);
  445. MODULE_SCOPE int TclNRNewObjectInstance(Tcl_Interp *interp,
  446. Tcl_Class cls, const char *nameStr,
  447. const char *nsNameStr, int objc,
  448. Tcl_Obj *const *objv, int skip,
  449. Tcl_Object *objectPtr);
  450. MODULE_SCOPE Object * TclNewObjectInstanceCommon(Tcl_Interp *interp,
  451. Class *classPtr,
  452. const char *nameStr,
  453. const char *nsNameStr);
  454. MODULE_SCOPE int TclOODecrRefCount(Object *oPtr);
  455. MODULE_SCOPE int TclOOObjectDestroyed(Object *oPtr);
  456. MODULE_SCOPE int TclOODefineSlots(Foundation *fPtr);
  457. MODULE_SCOPE void TclOODeleteChain(CallChain *callPtr);
  458. MODULE_SCOPE void TclOODeleteChainCache(Tcl_HashTable *tablePtr);
  459. MODULE_SCOPE void TclOODeleteContext(CallContext *contextPtr);
  460. MODULE_SCOPE void TclOODeleteDescendants(Tcl_Interp *interp,
  461. Object *oPtr);
  462. MODULE_SCOPE void TclOODelMethodRef(Method *method);
  463. MODULE_SCOPE CallContext *TclOOGetCallContext(Object *oPtr,
  464. Tcl_Obj *methodNameObj, int flags,
  465. Tcl_Obj *cacheInThisObj);
  466. MODULE_SCOPE CallChain *TclOOGetStereotypeCallChain(Class *clsPtr,
  467. Tcl_Obj *methodNameObj, int flags);
  468. MODULE_SCOPE Foundation *TclOOGetFoundation(Tcl_Interp *interp);
  469. MODULE_SCOPE Tcl_Obj * TclOOGetFwdFromMethod(Method *mPtr);
  470. MODULE_SCOPE Proc * TclOOGetProcFromMethod(Method *mPtr);
  471. MODULE_SCOPE Tcl_Obj * TclOOGetMethodBody(Method *mPtr);
  472. MODULE_SCOPE int TclOOGetSortedClassMethodList(Class *clsPtr,
  473. int flags, const char ***stringsPtr);
  474. MODULE_SCOPE int TclOOGetSortedMethodList(Object *oPtr, int flags,
  475. const char ***stringsPtr);
  476. MODULE_SCOPE int TclOOInit(Tcl_Interp *interp);
  477. MODULE_SCOPE void TclOOInitInfo(Tcl_Interp *interp);
  478. MODULE_SCOPE int TclOOInvokeContext(ClientData clientData,
  479. Tcl_Interp *interp, int objc,
  480. Tcl_Obj *const objv[]);
  481. MODULE_SCOPE int TclNRObjectContextInvokeNext(Tcl_Interp *interp,
  482. Tcl_ObjectContext context, int objc,
  483. Tcl_Obj *const *objv, int skip);
  484. MODULE_SCOPE void TclOONewBasicMethod(Tcl_Interp *interp, Class *clsPtr,
  485. const DeclaredClassMethod *dcm);
  486. MODULE_SCOPE Tcl_Obj * TclOOObjectName(Tcl_Interp *interp, Object *oPtr);
  487. MODULE_SCOPE void TclOOReleaseClassContents(Tcl_Interp *interp,
  488. Object *oPtr);
  489. MODULE_SCOPE int TclOORemoveFromInstances(Object *oPtr, Class *clsPtr);
  490. MODULE_SCOPE int TclOORemoveFromMixins(Class *mixinPtr, Object *oPtr);
  491. MODULE_SCOPE int TclOORemoveFromMixinSubs(Class *subPtr,
  492. Class *mixinPtr);
  493. MODULE_SCOPE int TclOORemoveFromSubclasses(Class *subPtr,
  494. Class *superPtr);
  495. MODULE_SCOPE Tcl_Obj * TclOORenderCallChain(Tcl_Interp *interp,
  496. CallChain *callPtr);
  497. MODULE_SCOPE void TclOOStashContext(Tcl_Obj *objPtr,
  498. CallContext *contextPtr);
  499. MODULE_SCOPE void TclOOSetupVariableResolver(Tcl_Namespace *nsPtr);
  500. /*
  501. * Include all the private API, generated from tclOO.decls.
  502. */
  503. #include "tclOOIntDecls.h"
  504. /*
  505. * Alternatives to Tcl_Preserve/Tcl_EventuallyFree/Tcl_Release.
  506. */
  507. #define AddRef(ptr) ((ptr)->refCount++)
  508. /*
  509. * A convenience macro for iterating through the lists used in the internal
  510. * memory management of objects.
  511. * REQUIRES DECLARATION: int i;
  512. */
  513. #define FOREACH(var,ary) \
  514. for(i=0 ; i<(ary).num; i++) if ((ary).list[i] == NULL) { \
  515. continue; \
  516. } else if (var = (ary).list[i], 1)
  517. /*
  518. * Convenience macros for iterating through hash tables. FOREACH_HASH_DECLS
  519. * sets up the declarations needed for the main macro, FOREACH_HASH, which
  520. * does the actual iteration. FOREACH_HASH_VALUE is a restricted version that
  521. * only iterates over values.
  522. */
  523. #define FOREACH_HASH_DECLS \
  524. Tcl_HashEntry *hPtr;Tcl_HashSearch search
  525. #define FOREACH_HASH(key,val,tablePtr) \
  526. for(hPtr=Tcl_FirstHashEntry((tablePtr),&search); hPtr!=NULL ? \
  527. ((key)=(void *)Tcl_GetHashKey((tablePtr),hPtr),\
  528. (val)=Tcl_GetHashValue(hPtr),1):0; hPtr=Tcl_NextHashEntry(&search))
  529. #define FOREACH_HASH_VALUE(val,tablePtr) \
  530. for(hPtr=Tcl_FirstHashEntry((tablePtr),&search); hPtr!=NULL ? \
  531. ((val)=Tcl_GetHashValue(hPtr),1):0;hPtr=Tcl_NextHashEntry(&search))
  532. /*
  533. * Convenience macro for duplicating a list. Needs no external declaration,
  534. * but all arguments are used multiple times and so must have no side effects.
  535. */
  536. #undef DUPLICATE /* prevent possible conflict with definition in WINAPI nb30.h */
  537. #define DUPLICATE(target,source,type) \
  538. do { \
  539. size_t len = sizeof(type) * ((target).num=(source).num);\
  540. if (len != 0) { \
  541. memcpy(((target).list=(type*)ckalloc(len)), (source).list, len); \
  542. } else { \
  543. (target).list = NULL; \
  544. } \
  545. } while(0)
  546. #endif /* TCL_OO_INTERNAL_H */
  547. /*
  548. * Local Variables:
  549. * mode: c
  550. * c-basic-offset: 4
  551. * fill-column: 78
  552. * End:
  553. */