Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2024-05-18 08:30:21

0001 /*
0002  * tclOOInt.h --
0003  *
0004  *  This file contains the structure definitions and some of the function
0005  *  declarations for the object-system (NB: not Tcl_Obj, but ::oo).
0006  *
0007  * Copyright (c) 2006-2012 by Donal K. Fellows
0008  *
0009  * See the file "license.terms" for information on usage and redistribution of
0010  * this file, and for a DISCLAIMER OF ALL WARRANTIES.
0011  */
0012 
0013 #ifndef TCL_OO_INTERNAL_H
0014 #define TCL_OO_INTERNAL_H 1
0015 
0016 #include "tclInt.h"
0017 #include "tclOO.h"
0018 
0019 /*
0020  * Hack to make things work with Objective C. Note that ObjC isn't really
0021  * supported, but we don't want to to be actively hostile to it. [Bug 2163447]
0022  */
0023 
0024 #ifdef __OBJC__
0025 #define Class   TclOOClass
0026 #define Object  TclOOObject
0027 #endif /* __OBJC__ */
0028 
0029 /*
0030  * Forward declarations.
0031  */
0032 
0033 struct CallChain;
0034 struct Class;
0035 struct Foundation;
0036 struct Object;
0037 
0038 /*
0039  * The data that needs to be stored per method. This record is used to collect
0040  * information about all sorts of methods, including forwards, constructors
0041  * and destructors.
0042  */
0043 
0044 typedef struct Method {
0045     const Tcl_MethodType *typePtr;
0046                 /* The type of method. If NULL, this is a
0047                  * special flag record which is just used for
0048                  * the setting of the flags field. */
0049     int refCount;
0050     ClientData clientData;  /* Type-specific data. */
0051     Tcl_Obj *namePtr;       /* Name of the method. */
0052     struct Object *declaringObjectPtr;
0053                 /* The object that declares this method, or
0054                  * NULL if it was declared by a class. */
0055     struct Class *declaringClassPtr;
0056                 /* The class that declares this method, or
0057                  * NULL if it was declared directly on an
0058                  * object. */
0059     int flags;          /* Assorted flags. Includes whether this
0060                  * method is public/exported or not. */
0061 } Method;
0062 
0063 /*
0064  * Pre- and post-call callbacks, to allow procedure-like methods to be fine
0065  * tuned in their behaviour.
0066  */
0067 
0068 typedef int (TclOO_PreCallProc)(ClientData clientData, Tcl_Interp *interp,
0069     Tcl_ObjectContext context, Tcl_CallFrame *framePtr, int *isFinished);
0070 typedef int (TclOO_PostCallProc)(ClientData clientData, Tcl_Interp *interp,
0071     Tcl_ObjectContext context, Tcl_Namespace *namespacePtr, int result);
0072 typedef void (TclOO_PmCDDeleteProc)(ClientData clientData);
0073 typedef ClientData (TclOO_PmCDCloneProc)(ClientData clientData);
0074 
0075 /*
0076  * Procedure-like methods have the following extra information.
0077  */
0078 
0079 typedef struct ProcedureMethod {
0080     int version;        /* Version of this structure. Currently must
0081                  * be 0. */
0082     Proc *procPtr;      /* Core of the implementation of the method;
0083                  * includes the argument definition and the
0084                  * body bytecodes. */
0085     int flags;          /* Flags to control features. */
0086     int refCount;
0087     ClientData clientData;
0088     TclOO_PmCDDeleteProc *deleteClientdataProc;
0089     TclOO_PmCDCloneProc *cloneClientdataProc;
0090     ProcErrorProc *errProc; /* Replacement error handler. */
0091     TclOO_PreCallProc *preCallProc;
0092                 /* Callback to allow for additional setup
0093                  * before the method executes. */
0094     TclOO_PostCallProc *postCallProc;
0095                 /* Callback to allow for additional cleanup
0096                  * after the method executes. */
0097     GetFrameInfoValueProc *gfivProc;
0098                 /* Callback to allow for fine tuning of how
0099                  * the method reports itself. */
0100 } ProcedureMethod;
0101 
0102 #define TCLOO_PROCEDURE_METHOD_VERSION 0
0103 
0104 /*
0105  * Flags for use in a ProcedureMethod.
0106  *
0107  * When the USE_DECLARER_NS flag is set, the method will use the namespace of
0108  * the object or class that declared it (or the clone of it, if it was from
0109  * such that the implementation of the method came to the particular use)
0110  * instead of the namespace of the object on which the method was invoked.
0111  * This flag must be distinct from all others that are associated with
0112  * methods.
0113  */
0114 
0115 #define USE_DECLARER_NS     0x80
0116 
0117 /*
0118  * Forwarded methods have the following extra information.
0119  */
0120 
0121 typedef struct ForwardMethod {
0122     Tcl_Obj *prefixObj;     /* The list of values to use to replace the
0123                  * object and method name with. Will be a
0124                  * non-empty list. */
0125 } ForwardMethod;
0126 
0127 /*
0128  * Helper definitions that declare a "list" array. The two varieties are
0129  * either optimized for simplicity (in the case that the whole array is
0130  * typically assigned at once) or efficiency (in the case that the array is
0131  * expected to be expanded over time). These lists are designed to be iterated
0132  * over with the help of the FOREACH macro (see later in this file).
0133  *
0134  * The "num" field always counts the number of listType_t elements used in the
0135  * "list" field. When a "size" field exists, it describes how many elements
0136  * are present in the list; when absent, exactly "num" elements are present.
0137  */
0138 
0139 #define LIST_STATIC(listType_t) \
0140     struct { int num; listType_t *list; }
0141 #define LIST_DYNAMIC(listType_t) \
0142     struct { int num, size; listType_t *list; }
0143 
0144 /*
0145  * Now, the definition of what an object actually is.
0146  */
0147 
0148 typedef struct Object {
0149     struct Foundation *fPtr;    /* The basis for the object system. Putting
0150                  * this here allows the avoidance of quite a
0151                  * lot of hash lookups on the critical path
0152                  * for object invocation and creation. */
0153     Tcl_Namespace *namespacePtr;/* This object's namespace. */
0154     Tcl_Command command;    /* Reference to this object's public
0155                  * command. */
0156     Tcl_Command myCommand;  /* Reference to this object's internal
0157                  * command. */
0158     struct Class *selfCls;  /* This object's class. */
0159     Tcl_HashTable *methodsPtr;  /* Object-local Tcl_Obj (method name) to
0160                  * Method* mapping. */
0161     LIST_STATIC(struct Class *) mixins;
0162                 /* Classes mixed into this object. */
0163     LIST_STATIC(Tcl_Obj *) filters;
0164                 /* List of filter names. */
0165     struct Class *classPtr; /* This is non-NULL for all classes, and NULL
0166                  *  for everything else. It points to the class
0167                  *  structure. */
0168     int refCount;       /* Number of strong references to this object.
0169                  * Note that there may be many more weak
0170                  * references; this mechanism exists to
0171                  * avoid Tcl_Preserve. */
0172     int flags;
0173     int creationEpoch;      /* Unique value to make comparisons of objects
0174                  * easier. */
0175     int epoch;          /* Per-object epoch, incremented when the way
0176                  * an object should resolve call chains is
0177                  * changed. */
0178     Tcl_HashTable *metadataPtr; /* Mapping from pointers to metadata type to
0179                  * the ClientData values that are the values
0180                  * of each piece of attached metadata. This
0181                  * field starts out as NULL and is only
0182                  * allocated if metadata is attached. */
0183     Tcl_Obj *cachedNameObj; /* Cache of the name of the object. */
0184     Tcl_HashTable *chainCache;  /* Place to keep unused contexts. This table
0185                  * is indexed by method name as Tcl_Obj. */
0186     Tcl_ObjectMapMethodNameProc *mapMethodNameProc;
0187                 /* Function to allow remapping of method
0188                  * names. For itcl-ng. */
0189     LIST_STATIC(Tcl_Obj *) variables;
0190 } Object;
0191 
0192 #define OBJECT_DESTRUCTING  1   /* Indicates that an object is being or has
0193                                  *  been destroyed  */
0194 #define DESTRUCTOR_CALLED 2 /* Indicates that evaluation of destructor script for the
0195                                object has began */
0196 #define OO_UNUSED_4 4   /* No longer used.  */
0197 #define ROOT_OBJECT 0x1000  /* Flag to say that this object is the root of
0198                  * the class hierarchy and should be treated
0199                  * specially during teardown. */
0200 #define FILTER_HANDLING 0x2000  /* Flag set when the object is processing a
0201                  * filter; when set, filters are *not*
0202                  * processed on the object, preventing nasty
0203                  * recursive filtering problems. */
0204 #define USE_CLASS_CACHE 0x4000  /* Flag set to say that the object is a pure
0205                  * instance of the class, and has had nothing
0206                  * added that changes the dispatch chain (i.e.
0207                  * no methods, mixins, or filters. */
0208 #define ROOT_CLASS 0x8000   /* Flag to say that this object is the root
0209                  * class of classes, and should be treated
0210                  * specially during teardown (and in a few
0211                  * other spots). */
0212 #define FORCE_UNKNOWN 0x10000   /* States that we are *really* looking up the
0213                  * unknown method handler at that point. */
0214 #define DONT_DELETE 0x20000 /* Inhibit deletion of this object. */
0215 
0216 /*
0217  * And the definition of a class. Note that every class also has an associated
0218  * object, through which it is manipulated.
0219  */
0220 
0221 typedef struct Class {
0222     Object *thisPtr;        /* Reference to the object associated with
0223                  * this class. */
0224     int flags;          /* Assorted flags. */
0225     LIST_STATIC(struct Class *) superclasses;
0226                 /* List of superclasses, used for generation
0227                  * of method call chains. */
0228     LIST_DYNAMIC(struct Class *) subclasses;
0229                 /* List of subclasses, used to ensure deletion
0230                  * of dependent entities happens properly when
0231                  * the class itself is deleted. */
0232     LIST_DYNAMIC(Object *) instances;
0233                 /* List of instances, used to ensure deletion
0234                  * of dependent entities happens properly when
0235                  * the class itself is deleted. */
0236     LIST_STATIC(Tcl_Obj *) filters;
0237                 /* List of filter names, used for generation
0238                  * of method call chains. */
0239     LIST_STATIC(struct Class *) mixins;
0240                 /* List of mixin classes, used for generation
0241                  * of method call chains. */
0242     LIST_DYNAMIC(struct Class *) mixinSubs;
0243                 /* List of classes that this class is mixed
0244                  * into, used to ensure deletion of dependent
0245                  * entities happens properly when the class
0246                  * itself is deleted. */
0247     Tcl_HashTable classMethods; /* Hash table of all methods. Hash maps from
0248                  * the (Tcl_Obj*) method name to the (Method*)
0249                  * method record. */
0250     Method *constructorPtr; /* Method record of the class constructor (if
0251                  * any). */
0252     Method *destructorPtr;  /* Method record of the class destructor (if
0253                  * any). */
0254     Tcl_HashTable *metadataPtr; /* Mapping from pointers to metadata type to
0255                  * the ClientData values that are the values
0256                  * of each piece of attached metadata. This
0257                  * field starts out as NULL and is only
0258                  * allocated if metadata is attached. */
0259     struct CallChain *constructorChainPtr;
0260     struct CallChain *destructorChainPtr;
0261     Tcl_HashTable *classChainCache;
0262                 /* Places where call chains are stored. For
0263                  * constructors, the class chain is always
0264                  * used. For destructors and ordinary methods,
0265                  * the class chain is only used when the
0266                  * object doesn't override with its own mixins
0267                  * (and filters and method implementations for
0268                  * when getting method chains). */
0269     LIST_STATIC(Tcl_Obj *) variables;
0270 } Class;
0271 
0272 /*
0273  * The foundation of the object system within an interpreter contains
0274  * references to the key classes and namespaces, together with a few other
0275  * useful bits and pieces. Probably ought to eventually go in the Interp
0276  * structure itself.
0277  */
0278 
0279 typedef struct ThreadLocalData {
0280     int nsCount;        /* Epoch counter is used for keeping
0281                  * the values used in Tcl_Obj internal
0282                  * representations sane. Must be thread-local
0283                  * because Tcl_Objs can cross interpreter
0284                  * boundaries within a thread (objects don't
0285                  * generally cross threads). */
0286 } ThreadLocalData;
0287 
0288 typedef struct Foundation {
0289     Tcl_Interp *interp;
0290     Class *objectCls;       /* The root of the object system. */
0291     Class *classCls;        /* The class of all classes. */
0292     Tcl_Namespace *ooNs;    /* ::oo namespace. */
0293     Tcl_Namespace *defineNs;    /* Namespace containing special commands for
0294                  * manipulating objects and classes. The
0295                  * "oo::define" command acts as a special kind
0296                  * of ensemble for this namespace. */
0297     Tcl_Namespace *objdefNs;    /* Namespace containing special commands for
0298                  * manipulating objects and classes. The
0299                  * "oo::objdefine" command acts as a special
0300                  * kind of ensemble for this namespace. */
0301     Tcl_Namespace *helpersNs;   /* Namespace containing the commands that are
0302                  * only valid when executing inside a
0303                  * procedural method. */
0304     int epoch;          /* Used to invalidate method chains when the
0305                  * class structure changes. */
0306     ThreadLocalData *tsdPtr;    /* Counter so we can allocate a unique
0307                  * namespace to each object. */
0308     Tcl_Obj *unknownMethodNameObj;
0309                 /* Shared object containing the name of the
0310                  * unknown method handler method. */
0311     Tcl_Obj *constructorName;   /* Shared object containing the "name" of a
0312                  * constructor. */
0313     Tcl_Obj *destructorName;    /* Shared object containing the "name" of a
0314                  * destructor. */
0315     Tcl_Obj *clonedName;    /* Shared object containing the name of a
0316                  * "<cloned>" pseudo-constructor. */
0317     Tcl_Obj *defineName;    /* Fully qualified name of oo::define. */
0318 } Foundation;
0319 
0320 /*
0321  * A call context structure is built when a method is called. It contains the
0322  * chain of method implementations that are to be invoked by a particular
0323  * call, and the process of calling walks the chain, with the [next] command
0324  * proceeding to the next entry in the chain.
0325  */
0326 
0327 #define CALL_CHAIN_STATIC_SIZE 4
0328 
0329 struct MInvoke {
0330     Method *mPtr;       /* Reference to the method implementation
0331                  * record. */
0332     int isFilter;       /* Whether this is a filter invocation. */
0333     Class *filterDeclarer;  /* What class decided to add the filter; if
0334                  * NULL, it was added by the object. */
0335 };
0336 
0337 typedef struct CallChain {
0338     int objectCreationEpoch;    /* The object's creation epoch. Note that the
0339                  * object reference is not stored in the call
0340                  * chain; it is in the call context. */
0341     int objectEpoch;        /* Local (object structure) epoch counter
0342                  * snapshot. */
0343     int epoch;          /* Global (class structure) epoch counter
0344                  * snapshot. */
0345     int flags;          /* Assorted flags, see below. */
0346     int refCount;       /* Reference count. */
0347     int numChain;       /* Size of the call chain. */
0348     struct MInvoke *chain;  /* Array of call chain entries. May point to
0349                  * staticChain if the number of entries is
0350                  * small. */
0351     struct MInvoke staticChain[CALL_CHAIN_STATIC_SIZE];
0352 } CallChain;
0353 
0354 typedef struct CallContext {
0355     Object *oPtr;       /* The object associated with this call. */
0356     int index;          /* Index into the call chain of the currently
0357                  * executing method implementation. */
0358     int skip;           /* Current number of arguments to skip; can
0359                  * vary depending on whether it is a direct
0360                  * method call or a continuation via the
0361                  * [next] command. */
0362     CallChain *callPtr;     /* The actual call chain. */
0363 } CallContext;
0364 
0365 /*
0366  * Bits for the 'flags' field of the call chain.
0367  */
0368 
0369 #define PUBLIC_METHOD     0x01  /* This is a public (exported) method. */
0370 #define PRIVATE_METHOD    0x02  /* This is a private (class's direct instances
0371                  * only) method. */
0372 #define OO_UNKNOWN_METHOD 0x04  /* This is an unknown method. */
0373 #define CONSTRUCTOR   0x08  /* This is a constructor. */
0374 #define DESTRUCTOR    0x10  /* This is a destructor. */
0375 
0376 /*
0377  * Structure containing definition information about basic class methods.
0378  */
0379 
0380 typedef struct {
0381     const char *name;       /* Name of the method in question. */
0382     int isPublic;       /* Whether the method is public by default. */
0383     Tcl_MethodType definition;  /* How to call the method. */
0384 } DeclaredClassMethod;
0385 
0386 /*
0387  *----------------------------------------------------------------
0388  * Commands relating to OO support.
0389  *----------------------------------------------------------------
0390  */
0391 
0392 MODULE_SCOPE int    TclOOInit(Tcl_Interp *interp);
0393 MODULE_SCOPE int    TclOODefineObjCmd(ClientData clientData,
0394                 Tcl_Interp *interp, int objc,
0395                 Tcl_Obj *const *objv);
0396 MODULE_SCOPE int    TclOOObjDefObjCmd(ClientData clientData,
0397                 Tcl_Interp *interp, int objc,
0398                 Tcl_Obj *const *objv);
0399 MODULE_SCOPE int    TclOODefineConstructorObjCmd(ClientData clientData,
0400                 Tcl_Interp *interp, int objc,
0401                 Tcl_Obj *const *objv);
0402 MODULE_SCOPE int    TclOODefineDeleteMethodObjCmd(ClientData clientData,
0403                 Tcl_Interp *interp, int objc,
0404                 Tcl_Obj *const *objv);
0405 MODULE_SCOPE int    TclOODefineDestructorObjCmd(ClientData clientData,
0406                 Tcl_Interp *interp, int objc,
0407                 Tcl_Obj *const *objv);
0408 MODULE_SCOPE int    TclOODefineExportObjCmd(ClientData clientData,
0409                 Tcl_Interp *interp, int objc,
0410                 Tcl_Obj *const *objv);
0411 MODULE_SCOPE int    TclOODefineForwardObjCmd(ClientData clientData,
0412                 Tcl_Interp *interp, int objc,
0413                 Tcl_Obj *const *objv);
0414 MODULE_SCOPE int    TclOODefineMethodObjCmd(ClientData clientData,
0415                 Tcl_Interp *interp, int objc,
0416                 Tcl_Obj *const *objv);
0417 MODULE_SCOPE int    TclOODefineRenameMethodObjCmd(ClientData clientData,
0418                 Tcl_Interp *interp, int objc,
0419                 Tcl_Obj *const *objv);
0420 MODULE_SCOPE int    TclOODefineUnexportObjCmd(ClientData clientData,
0421                 Tcl_Interp *interp, int objc,
0422                 Tcl_Obj *const *objv);
0423 MODULE_SCOPE int    TclOODefineClassObjCmd(ClientData clientData,
0424                 Tcl_Interp *interp, int objc,
0425                 Tcl_Obj *const *objv);
0426 MODULE_SCOPE int    TclOODefineSelfObjCmd(ClientData clientData,
0427                 Tcl_Interp *interp, int objc,
0428                 Tcl_Obj *const *objv);
0429 MODULE_SCOPE int    TclOOUnknownDefinition(ClientData clientData,
0430                 Tcl_Interp *interp, int objc,
0431                 Tcl_Obj *const *objv);
0432 MODULE_SCOPE int    TclOOCopyObjectCmd(ClientData clientData,
0433                 Tcl_Interp *interp, int objc,
0434                 Tcl_Obj *const *objv);
0435 MODULE_SCOPE int    TclOONextObjCmd(ClientData clientData,
0436                 Tcl_Interp *interp, int objc,
0437                 Tcl_Obj *const *objv);
0438 MODULE_SCOPE int    TclOONextToObjCmd(ClientData clientData,
0439                 Tcl_Interp *interp, int objc,
0440                 Tcl_Obj *const *objv);
0441 MODULE_SCOPE int    TclOOSelfObjCmd(ClientData clientData,
0442                 Tcl_Interp *interp, int objc,
0443                 Tcl_Obj *const *objv);
0444 
0445 /*
0446  * Method implementations (in tclOOBasic.c).
0447  */
0448 
0449 MODULE_SCOPE int    TclOO_Class_Constructor(ClientData clientData,
0450                 Tcl_Interp *interp, Tcl_ObjectContext context,
0451                 int objc, Tcl_Obj *const *objv);
0452 MODULE_SCOPE int    TclOO_Class_Create(ClientData clientData,
0453                 Tcl_Interp *interp, Tcl_ObjectContext context,
0454                 int objc, Tcl_Obj *const *objv);
0455 MODULE_SCOPE int    TclOO_Class_CreateNs(ClientData clientData,
0456                 Tcl_Interp *interp, Tcl_ObjectContext context,
0457                 int objc, Tcl_Obj *const *objv);
0458 MODULE_SCOPE int    TclOO_Class_New(ClientData clientData,
0459                 Tcl_Interp *interp, Tcl_ObjectContext context,
0460                 int objc, Tcl_Obj *const *objv);
0461 MODULE_SCOPE int    TclOO_Object_Destroy(ClientData clientData,
0462                 Tcl_Interp *interp, Tcl_ObjectContext context,
0463                 int objc, Tcl_Obj *const *objv);
0464 MODULE_SCOPE int    TclOO_Object_Eval(ClientData clientData,
0465                 Tcl_Interp *interp, Tcl_ObjectContext context,
0466                 int objc, Tcl_Obj *const *objv);
0467 MODULE_SCOPE int    TclOO_Object_LinkVar(ClientData clientData,
0468                 Tcl_Interp *interp, Tcl_ObjectContext context,
0469                 int objc, Tcl_Obj *const *objv);
0470 MODULE_SCOPE int    TclOO_Object_Unknown(ClientData clientData,
0471                 Tcl_Interp *interp, Tcl_ObjectContext context,
0472                 int objc, Tcl_Obj *const *objv);
0473 MODULE_SCOPE int    TclOO_Object_VarName(ClientData clientData,
0474                 Tcl_Interp *interp, Tcl_ObjectContext context,
0475                 int objc, Tcl_Obj *const *objv);
0476 
0477 /*
0478  * Private definitions, some of which perhaps ought to be exposed properly or
0479  * maybe just put in the internal stubs table.
0480  */
0481 
0482 MODULE_SCOPE void   TclOOAddToInstances(Object *oPtr, Class *clsPtr);
0483 MODULE_SCOPE void   TclOOAddToMixinSubs(Class *subPtr, Class *mixinPtr);
0484 MODULE_SCOPE void   TclOOAddToSubclasses(Class *subPtr, Class *superPtr);
0485 MODULE_SCOPE Class *    TclOOAllocClass(Tcl_Interp *interp,
0486                 Object *useThisObj);
0487 MODULE_SCOPE int    TclNRNewObjectInstance(Tcl_Interp *interp,
0488                 Tcl_Class cls, const char *nameStr,
0489                 const char *nsNameStr, int objc,
0490                 Tcl_Obj *const *objv, int skip,
0491                 Tcl_Object *objectPtr);
0492 MODULE_SCOPE Object *   TclNewObjectInstanceCommon(Tcl_Interp *interp,
0493                 Class *classPtr,
0494                 const char *nameStr,
0495                 const char *nsNameStr);
0496 MODULE_SCOPE int    TclOODecrRefCount(Object *oPtr);
0497 MODULE_SCOPE int    TclOOObjectDestroyed(Object *oPtr);
0498 MODULE_SCOPE int    TclOODefineSlots(Foundation *fPtr);
0499 MODULE_SCOPE void   TclOODeleteChain(CallChain *callPtr);
0500 MODULE_SCOPE void   TclOODeleteChainCache(Tcl_HashTable *tablePtr);
0501 MODULE_SCOPE void   TclOODeleteContext(CallContext *contextPtr);
0502 MODULE_SCOPE void   TclOODeleteDescendants(Tcl_Interp *interp,
0503                 Object *oPtr);
0504 MODULE_SCOPE void   TclOODelMethodRef(Method *method);
0505 MODULE_SCOPE CallContext *TclOOGetCallContext(Object *oPtr,
0506                 Tcl_Obj *methodNameObj, int flags,
0507                 Tcl_Obj *cacheInThisObj);
0508 MODULE_SCOPE CallChain *TclOOGetStereotypeCallChain(Class *clsPtr,
0509                 Tcl_Obj *methodNameObj, int flags);
0510 MODULE_SCOPE Foundation *TclOOGetFoundation(Tcl_Interp *interp);
0511 MODULE_SCOPE Tcl_Obj *  TclOOGetFwdFromMethod(Method *mPtr);
0512 MODULE_SCOPE Proc * TclOOGetProcFromMethod(Method *mPtr);
0513 MODULE_SCOPE Tcl_Obj *  TclOOGetMethodBody(Method *mPtr);
0514 MODULE_SCOPE int    TclOOGetSortedClassMethodList(Class *clsPtr,
0515                 int flags, const char ***stringsPtr);
0516 MODULE_SCOPE int    TclOOGetSortedMethodList(Object *oPtr, int flags,
0517                 const char ***stringsPtr);
0518 MODULE_SCOPE int    TclOOInit(Tcl_Interp *interp);
0519 MODULE_SCOPE void   TclOOInitInfo(Tcl_Interp *interp);
0520 MODULE_SCOPE int    TclOOInvokeContext(ClientData clientData,
0521                 Tcl_Interp *interp, int objc,
0522                 Tcl_Obj *const objv[]);
0523 MODULE_SCOPE int    TclNRObjectContextInvokeNext(Tcl_Interp *interp,
0524                 Tcl_ObjectContext context, int objc,
0525                 Tcl_Obj *const *objv, int skip);
0526 MODULE_SCOPE void   TclOONewBasicMethod(Tcl_Interp *interp, Class *clsPtr,
0527                 const DeclaredClassMethod *dcm);
0528 MODULE_SCOPE Tcl_Obj *  TclOOObjectName(Tcl_Interp *interp, Object *oPtr);
0529 MODULE_SCOPE void   TclOOReleaseClassContents(Tcl_Interp *interp,
0530                 Object *oPtr);
0531 MODULE_SCOPE int    TclOORemoveFromInstances(Object *oPtr, Class *clsPtr);
0532 MODULE_SCOPE int    TclOORemoveFromMixins(Class *mixinPtr, Object *oPtr);
0533 MODULE_SCOPE int    TclOORemoveFromMixinSubs(Class *subPtr,
0534                 Class *mixinPtr);
0535 MODULE_SCOPE int    TclOORemoveFromSubclasses(Class *subPtr,
0536                 Class *superPtr);
0537 MODULE_SCOPE Tcl_Obj *  TclOORenderCallChain(Tcl_Interp *interp,
0538                 CallChain *callPtr);
0539 MODULE_SCOPE void   TclOOStashContext(Tcl_Obj *objPtr,
0540                 CallContext *contextPtr);
0541 MODULE_SCOPE void   TclOOSetupVariableResolver(Tcl_Namespace *nsPtr);
0542 
0543 /*
0544  * Include all the private API, generated from tclOO.decls.
0545  */
0546 
0547 #include "tclOOIntDecls.h"
0548 
0549 /*
0550  * Alternatives to Tcl_Preserve/Tcl_EventuallyFree/Tcl_Release.
0551  */
0552 
0553 #define AddRef(ptr) ((ptr)->refCount++)
0554 
0555 /*
0556  * A convenience macro for iterating through the lists used in the internal
0557  * memory management of objects.
0558  * REQUIRES DECLARATION: int i;
0559  */
0560 
0561 #define FOREACH(var,ary) \
0562     for(i=0 ; i<(ary).num; i++) if ((ary).list[i] == NULL) { \
0563     continue; \
0564     } else if (var = (ary).list[i], 1)
0565 
0566 /*
0567  * Convenience macros for iterating through hash tables. FOREACH_HASH_DECLS
0568  * sets up the declarations needed for the main macro, FOREACH_HASH, which
0569  * does the actual iteration. FOREACH_HASH_VALUE is a restricted version that
0570  * only iterates over values.
0571  */
0572 
0573 #define FOREACH_HASH_DECLS \
0574     Tcl_HashEntry *hPtr;Tcl_HashSearch search
0575 #define FOREACH_HASH(key,val,tablePtr) \
0576     for(hPtr=Tcl_FirstHashEntry((tablePtr),&search); hPtr!=NULL ? \
0577         ((key)=(void *)Tcl_GetHashKey((tablePtr),hPtr),\
0578         (val)=Tcl_GetHashValue(hPtr),1):0; hPtr=Tcl_NextHashEntry(&search))
0579 #define FOREACH_HASH_VALUE(val,tablePtr) \
0580     for(hPtr=Tcl_FirstHashEntry((tablePtr),&search); hPtr!=NULL ? \
0581         ((val)=Tcl_GetHashValue(hPtr),1):0;hPtr=Tcl_NextHashEntry(&search))
0582 
0583 /*
0584  * Convenience macro for duplicating a list. Needs no external declaration,
0585  * but all arguments are used multiple times and so must have no side effects.
0586  */
0587 
0588 #undef DUPLICATE /* prevent possible conflict with definition in WINAPI nb30.h */
0589 #define DUPLICATE(target,source,type) \
0590     do { \
0591     size_t len = sizeof(type) * ((target).num=(source).num);\
0592     if (len != 0) { \
0593         memcpy(((target).list=(type*)ckalloc(len)), (source).list, len); \
0594     } else { \
0595         (target).list = NULL; \
0596     } \
0597     } while(0)
0598 
0599 #endif /* TCL_OO_INTERNAL_H */
0600 
0601 /*
0602  * Local Variables:
0603  * mode: c
0604  * c-basic-offset: 4
0605  * fill-column: 78
0606  * End:
0607  */