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