Index: ChangeLog =================================================================== diff -u -r6cea71632dc3d32fabb894f5de7c803145261102 -rdc0040a6ddddf73e61c2a7d733ad7e15127e6bc1 --- ChangeLog (.../ChangeLog) (revision 6cea71632dc3d32fabb894f5de7c803145261102) +++ ChangeLog (.../ChangeLog) (revision dc0040a6ddddf73e61c2a7d733ad7e15127e6bc1) @@ -65,7 +65,10 @@ 2009-06-27 - changed method name "instdestroy" into "dealloc" + - replaced occurances of "instdestroy" by "dealloc" in documentation - new file: tclAPI.h + - added generator for tclAPI.h + - defined 8 info methods based on the new objv parseing infrastructure 2009-06-25 - new command: Index: Makefile.in =================================================================== diff -u -r43e8ea0de59e32655b41cbd6c8a47acf8ada443a -rdc0040a6ddddf73e61c2a7d733ad7e15127e6bc1 --- Makefile.in (.../Makefile.in) (revision 43e8ea0de59e32655b41cbd6c8a47acf8ada443a) +++ Makefile.in (.../Makefile.in) (revision dc0040a6ddddf73e61c2a7d733ad7e15127e6bc1) @@ -465,9 +465,12 @@ $(src_generic_dir)/predefined.h: $(src_generic_dir)/mk_predefined.xotcl $(src_generic_dir)/predefined.xotcl (cd $(src_generic_dir); $(TCLSH) mk_predefined.xotcl > predefined.h) +$(src_generic_dir)/tclAPI.h: $(src_generic_dir)/gentclAPI.tcl + $(TCLSH) $(src_generic_dir)/gentclAPI.tcl > $(src_generic_dir)/tclAPI.h + xotclStubInit.$(OBJEXT): $(PKG_HEADERS) xotclStubLib.$(OBJEXT): $(src_generic_dir)/xotclStubLib.c $(PKG_HEADERS) -xotcl.$(OBJEXT): $(src_generic_dir)/xotcl.c $(src_generic_dir)/predefined.h $(PKG_HEADERS) +xotcl.$(OBJEXT): $(src_generic_dir)/xotcl.c $(src_generic_dir)/predefined.h $(src_generic_dir)/tclAPI.h $(PKG_HEADERS) xotclError.$(OBJEXT): $(src_generic_dir)/xotclError.c $(PKG_HEADERS) xotclMetaData.$(OBJEXT): $(src_generic_dir)/xotclMetaData.c $(PKG_HEADERS) xotclObjectData.$(OBJEXT): $(src_generic_dir)/xotclObjectData.c $(PKG_HEADERS) Index: doc/langRef.xotcl =================================================================== diff -u -r2111020b49da8ce57758e51accf0b6073037f0d2 -rdc0040a6ddddf73e61c2a7d733ad7e15127e6bc1 --- doc/langRef.xotcl (.../langRef.xotcl) (revision 2111020b49da8ce57758e51accf0b6073037f0d2) +++ doc/langRef.xotcl (.../langRef.xotcl) (revision dc0040a6ddddf73e61c2a7d733ad7e15127e6bc1) @@ -356,10 +356,10 @@ Description { Standard destructor. Can be overloaded for customized destruction process. Actual destruction - is done by instdestroy. "destroy" in principal does: + is done by dealloc. "destroy" in principal does: <@pre class='code'> Object instproc destroy args { - [my info class] instdestroy [self] + [my info class] dealloc [self] } } return "empty string" @@ -1216,12 +1216,12 @@ return "Value of introspected option as a string." } -@ Class instproc instdestroy { +@ Class instproc dealloc { obj "obj/class name" ?args? "arguments passed to the destructor" } { Description { - Standard destructor. Destroys XOTcl object physically from the memory. + Destroys XOTcl object physically from the memory. Can be overloaded for customized destruction process. <@p> In XOTcl objects are not directly destroyed, when a destroy is Index: doc/tutorial.html =================================================================== diff -u -r2111020b49da8ce57758e51accf0b6073037f0d2 -rdc0040a6ddddf73e61c2a7d733ad7e15127e6bc1 --- doc/tutorial.html (.../tutorial.html) (revision 2111020b49da8ce57758e51accf0b6073037f0d2) +++ doc/tutorial.html (.../tutorial.html) (revision dc0040a6ddddf73e61c2a7d733ad7e15127e6bc1) @@ -1689,7 +1689,7 @@ my incr counter next } - CountedClass instproc instdestroy args { + CountedClass instproc dealloc args { my incr counter -1 next } @@ -1749,14 +1749,14 @@ className create [self]

-are used for creating an instance. A similar method instdestroy +are used for creating an instance. A similar method dealloc exists on Class that handles physical destruction of an object. The method destroy on Object which lets an object destroy itself in fact has the following behavior:

   Object instproc destroy args {
-   [my info class] instdestroy [self]
+   [my info class] dealloc [self]
   }
 

@@ -1799,7 +1799,7 @@

Each step has a method call that can be changed, intercepted, etc. Of -course, cleanup, recreate, instdestroy, +course, cleanup, recreate, dealloc, etc. can also be overloaded or intercepted.

Index: generic/gentclAPI.tcl =================================================================== diff -u --- generic/gentclAPI.tcl (revision 0) +++ generic/gentclAPI.tcl (revision dc0040a6ddddf73e61c2a7d733ad7e15127e6bc1) @@ -0,0 +1,111 @@ + + + + +# objectMethod +# classMethod +# infoObjectMethod +# infoClassMethod +# checkMethod + +set objCmdProc "(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv \[\]);" +proc genifd {argDefinitions} { + set l [list] + foreach argDefinition $argDefinitions { + array set "" $argDefinition + if {$(-type) eq ""} {set type NULL} {set type "\"$(-type)\""} + lappend l "{\"$(-argName)\", $(-required), $(-nrArgs), $type}" + } + join $l ",\n " +} + +proc genc {} { + set decls "" + set enums [list] + set ifds [list] + foreach key [lsort [array names ::definitions]] { + array set d $::definitions($key) + append decls "static int $d(implementation)$::objCmdProc\n" + lappend enums $d(idx) + lappend ifds "{\"$d(methodName)\", $d(implementation), {\n [genifd $d(argDefintions)]}\n}" + } + puts { +typedef struct { + char *methodName; + Tcl_ObjCmdProc *proc; + interfaceDefinition ifd; +} methodDefinition2; + } + puts $decls + set enumString [join $enums ",\n "] + puts "enum {\n $enumString\n} XOTclMethods;\n" + set definitionString [join $ifds ",\n"] + puts "static methodDefinition2 methodDefinitons\[\] = \{\n$definitionString\n\};\n" +} + +proc methodDefinition {methodName methodType implementation argDefinitions} { + set d(methodName) $methodName + set d(implementation) $implementation + set d(methodType) $methodType + set d(idx) ${implementation}Idx + set completed [list] + foreach argDefinition $argDefinitions { + array set "" {-required 0 -nrArgs 0 -type ""} + array set "" $argDefinition + lappend completed [array get ""] + } + set d(argDefintions) $completed + set ::definitions($d(methodType)-$d(implementation)-$d(methodName)) [array get d] +} + +proc infoClassMethod {methodName implementation argDefinitions} { + methodDefinition $methodName infoClassMethod $implementation $argDefinitions +} + +infoClassMethod instances XOTclClassInfoHeritageMethod { + {-argName "class" -required 1 -nrargs 0 -type class} + {-argName "pattern"} +} + +infoClassMethod instances XOTclClassInfoInstancesMethod { + {-argName "class" -required 1 -nrargs 0 -type class} + {-argName "-closure"} + {-argName "pattern" -type objpattern} +} + +infoClassMethod instargs XOTclClassInfoInstargsMethod { + {-argName "class" -required 1 -type class} + {-argName "methodName" -required 1} +} + +infoClassMethod instbody XOTclClassInfoInstbodyMethod { + {-argName "class" -required 1 -type class} + {-argName "methodName" -required 1} +} + +infoClassMethod instances XOTclClassInfoInstcommandsMethod { + {-argName "class" -required 1 -nrargs 0 -type class} + {-argName "pattern"} +} + +infoClassMethod instdefault XOTclClassInfoInstdefaultMethod { + {-argName "class" -required 1 -nrargs 0 -type class} + {-argName "methodName" -required 1} + {-argName "arg" -required 1} + {-argName "var" -required 1} +} + +infoClassMethod instfilter XOTclClassInfoInstfilterMethod { + {-argName "class" -required 1 -nrargs 0 -type class} + {-argName "-guards"} + {-argName "pattern"} +} + +infoClassMethod instfilterguard XOTclClassInfoInstfilterguardMethod { + {-argName "class" -required 1 -nrargs 0 -type class} + {-argName "filter" -required 1} +} + + + +genc \ No newline at end of file Index: generic/predefined.h =================================================================== diff -u -r91e9b1a3b1c3e60a8538156b4aa37d5a664d5133 -rdc0040a6ddddf73e61c2a7d733ad7e15127e6bc1 --- generic/predefined.h (.../predefined.h) (revision 91e9b1a3b1c3e60a8538156b4aa37d5a664d5133) +++ generic/predefined.h (.../predefined.h) (revision dc0040a6ddddf73e61c2a7d733ad7e15127e6bc1) @@ -8,7 +8,7 @@ "::xotcl::createobjectsystem ::oo::object ::oo::class\n" "if {[info command ::oo::object] ne \"\"} {\n" "::xotcl::alias ::oo::object destroy ::xotcl::cmd::Object::destroy\n" -"::xotcl::alias ::oo::class instdestroy ::xotcl::cmd::Class::instdestroy\n" +"::xotcl::alias ::oo::class dealloc ::xotcl::cmd::Class::dealloc\n" "::xotcl::createobjectsystem ::xotcl::Object ::xotcl::Class}\n" "set bootstrap 1\n" "foreach cmd [info command ::xotcl::cmd::Object::*] {\n" Index: generic/predefined.xotcl =================================================================== diff -u -r91e9b1a3b1c3e60a8538156b4aa37d5a664d5133 -rdc0040a6ddddf73e61c2a7d733ad7e15127e6bc1 --- generic/predefined.xotcl (.../predefined.xotcl) (revision 91e9b1a3b1c3e60a8538156b4aa37d5a664d5133) +++ generic/predefined.xotcl (.../predefined.xotcl) (revision dc0040a6ddddf73e61c2a7d733ad7e15127e6bc1) @@ -13,12 +13,12 @@ # When the system shuts down, destroy is called for every # available object. When ::xotcl::Object and ::xotcl::Class are # destroyed, there would be no means to delete other objects, when - # "destroy" and "instdestroy" are only defined on these + # "destroy" and "dealloc" are only defined on these # objects. So, we register these on ::oo::object and ::oo::class # for the time being, since these two classes are deleted last. # ::xotcl::alias ::oo::object destroy ::xotcl::cmd::Object::destroy - ::xotcl::alias ::oo::class instdestroy ::xotcl::cmd::Class::instdestroy + ::xotcl::alias ::oo::class dealloc ::xotcl::cmd::Class::dealloc # # Perform the basic setup of XOTcl. First, let us allocate the Index: generic/tclAPI.h =================================================================== diff -u -r6cea71632dc3d32fabb894f5de7c803145261102 -rdc0040a6ddddf73e61c2a7d733ad7e15127e6bc1 --- generic/tclAPI.h (.../tclAPI.h) (revision 6cea71632dc3d32fabb894f5de7c803145261102) +++ generic/tclAPI.h (.../tclAPI.h) (revision dc0040a6ddddf73e61c2a7d733ad7e15127e6bc1) @@ -1,123 +1,66 @@ -enum { - /* Object method definitions (1) */ - XOTclOAutonameMethodIdx, - XOTclOCheckMethodIdx, - XOTclOCleanupMethodIdx, - XOTclOConfigureMethodIdx, - XOTclODestroyMethodIdx, - XOTclOExistsMethodIdx, - XOTclOFilterGuardMethodIdx, - XOTclOFilterSearchMethodIdx, - XOTclOInstVarMethodIdx, - XOTclOInvariantsMethodIdx, - XOTclOIsClassMethodIdx, - XOTclOIsMetaClassMethodIdx, - XOTclOIsObjectMethodIdx, - XOTclOIsTypeMethodIdx, - XOTclOIsMixinMethodIdx, - XOTclOMixinGuardMethodIdx, - XOTclONextMethodIdx, - XOTclONoinitMethodIdx, - XOTclCParameterCmdMethodIdx, - XOTclOProcMethodIdx, - XOTclOProcSearchMethodIdx, - XOTclORequireNamespaceMethodIdx, - XOTclOSetMethodIdx, /***??**/ - XOTclOSetvaluesMethodIdx, - XOTclOForwardMethodIdx, - XOTclOUplevelMethodIdx, - XOTclOUpvarMethodIdx, - XOTclOVolatileMethodIdx, - XOTclOVwaitMethodIdx, +typedef struct { + char *methodName; + Tcl_ObjCmdProc *proc; + interfaceDefinition ifd; +} methodDefinition2; + +static int XOTclClassInfoHeritageMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); +static int XOTclClassInfoInstancesMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); +static int XOTclClassInfoInstargsMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); +static int XOTclClassInfoInstbodyMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); +static int XOTclClassInfoInstcommandsMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); +static int XOTclClassInfoInstdefaultMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); +static int XOTclClassInfoInstfilterMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); +static int XOTclClassInfoInstfilterguardMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); - /* Class method definitions (2) */ - XOTclCAllocMethodIdx, - XOTclCCreateMethodIdx, - XOTclCDeallocMethodIdx, - XOTclCNewMethodIdx, - XOTclCInstFilterGuardMethodIdx, - XOTclCInvariantsMethodIdx, - XOTclCInstMixinGuardMethodIdx, - XOTclCInstParameterCmdMethodIdx, - XOTclCInstProcMethodIdx, - XOTclCInstProcMethodCIdx, - XOTclCInstForwardMethodIdx, - XOTclCRecreateMethodIdx, - XOTclCUnknownMethodIdx, - - /* Check method definitions (3) */ - XOTclCheckRequiredArgsIdx, - /*XOTclCheckBooleanArgsIdx, for boolean and switch, we use the same checker */ - XOTclCheckBooleanArgsIdx, - - /* Object info definitions (4) */ - XOTclObjInfoArgsMethodIdx, - XOTclObjInfoBodyMethodIdx, - XOTclObjInfoClassMethodIdx, - XOTclObjInfoCommandsMethodIdx, - XOTclObjInfoChildrenMethodIdx, - XOTclObjInfoCheckMethodIdx, - XOTclObjInfoDefaultMethodIdx, - XOTclObjInfoFilterMethodIdx, - XOTclObjInfoFilterguardMethodIdx, - XOTclObjInfoForwardMethodIdx, - XOTclObjInfoHasnamespaceMethodIdx, - XOTclObjInfoInvarMethodIdx, - XOTclObjInfoMethodsMethodIdx, - XOTclObjInfoMixinMethodIdx, - XOTclObjInfoMixinguardMethodIdx, - XOTclObjInfoNonposargsMethodIdx, - XOTclObjInfoParentMethodIdx, - XOTclObjInfoParametercmdMethodIdx, - XOTclObjInfoPostMethodIdx, - XOTclObjInfoPreMethodIdx, - XOTclObjInfoProcsMethodIdx, - XOTclObjInfoPrecedenceMethodIdx, - XOTclObjInfoSlotObjectsMethodIdx, - XOTclObjInfoVarsMethodIdx, - - /* Class info definitions (5) */ - XOTclClassInfoHeritageMethodIdx, - XOTclClassInfoInstancesMethodIdx, - XOTclClassInfoInstargsMethodIdx, - XOTclClassInfoInstbodyMethodIdx, - XOTclClassInfoInstcommandsMethodIdx, - XOTclClassInfoInstdefaultMethodIdx, - XOTclClassInfoInstfilterMethodIdx, - XOTclClassInfoInstfilterguardMethodIdx, - XOTclClassInfoInstforwardMethodIdx, - XOTclClassInfoInstinvarMethodIdx, - XOTclClassInfoInstmixinMethodIdx, - XOTclClassInfoInstmixinguardMethodIdx, - XOTclClassInfoInstmixinofMethodIdx, - XOTclClassInfoInstprocsMethodIdx, - XOTclClassInfoInstnonposargsMethodIdx, - XOTclClassInfoInstparametercmdMethodIdx, - XOTclClassInfoInstpreMethodIdx, - XOTclClassInfoInstpostMethodIdx, - XOTclClassInfoMixinofMethodIdx, - XOTclClassInfoParameterMethodIdx, - XOTclClassInfoSubclassMethodIdx, - XOTclClassInfoSuperclassMethodIdx, - XOTclClassInfoSlotsMethodIdx, - - methodIdxEND +enum { + XOTclClassInfoHeritageMethodIdx, + XOTclClassInfoInstancesMethodIdx, + XOTclClassInfoInstargsMethodIdx, + XOTclClassInfoInstbodyMethodIdx, + XOTclClassInfoInstcommandsMethodIdx, + XOTclClassInfoInstdefaultMethodIdx, + XOTclClassInfoInstfilterMethodIdx, + XOTclClassInfoInstfilterguardMethodIdx } XOTclMethods; -static interfaceDefinition methodDefinitions[methodIdxEND]; - -interfaceDefinition xxx = { - {"class", 1,0, "class"}, - {"-closure"}, - {"pattern", 0,0, "objpattern"} +static methodDefinition2 methodDefinitons[] = { +{"instances", XOTclClassInfoHeritageMethod, { + {"class", 1, 0, "class"}, + {"pattern", 0, 0, NULL}} +}, +{"instances", XOTclClassInfoInstancesMethod, { + {"class", 1, 0, "class"}, + {"-closure", 0, 0, NULL}, + {"pattern", 0, 0, "objpattern"}} +}, +{"instargs", XOTclClassInfoInstargsMethod, { + {"class", 1, 0, "class"}, + {"methodName", 1, 0, NULL}} +}, +{"instbody", XOTclClassInfoInstbodyMethod, { + {"class", 1, 0, "class"}, + {"methodName", 1, 0, NULL}} +}, +{"instances", XOTclClassInfoInstcommandsMethod, { + {"class", 1, 0, "class"}, + {"pattern", 0, 0, NULL}} +}, +{"instdefault", XOTclClassInfoInstdefaultMethod, { + {"class", 1, 0, "class"}, + {"methodName", 1, 0, NULL}, + {"arg", 1, 0, NULL}, + {"var", 1, 0, NULL}} +}, +{"instfilter", XOTclClassInfoInstfilterMethod, { + {"class", 1, 0, "class"}, + {"-guards", 0, 0, NULL}, + {"pattern", 0, 0, NULL}} +}, +{"instfilterguard", XOTclClassInfoInstfilterguardMethod, { + {"class", 1, 0, "class"}, + {"filter", 1, 0, NULL}} +} }; -methodDefinitions[XOTclClassInfoInstancesMethodIdx] = xxx; -/* -methodDefinitions[XOTclClassInfoInstancesMethodIdx] = { - {"class", 1,0, "class"}, - {"-closure"}, - {"pattern", 0,0, "objpattern"} -}; -*/ Index: generic/xotcl.c =================================================================== diff -u -r6cea71632dc3d32fabb894f5de7c803145261102 -rdc0040a6ddddf73e61c2a7d733ad7e15127e6bc1 --- generic/xotcl.c (.../xotcl.c) (revision 6cea71632dc3d32fabb894f5de7c803145261102) +++ generic/xotcl.c (.../xotcl.c) (revision dc0040a6ddddf73e61c2a7d733ad7e15127e6bc1) @@ -11876,19 +11876,7 @@ -static int -XOTclClassInfoHeritageMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]) { - XOTclClass *cl; - - if (objc < 2 || objc > 3) return XOTclObjErrArgCnt(interp, objv[0], NULL, " ?pattern?"); - if (GetXOTclClassFromObj(interp, objv[1], &cl, 0) != TCL_OK) - return XOTclObjErrType(interp, objv[1], "Class"); - - return ListHeritage(interp, cl, objc == 3 ? ObjStr(objv[2]) : NULL); -} - - -struct parseContext { +typedef struct { ClientData clientData[10]; Tcl_Obj *objv[10]; int flags; @@ -11899,10 +11887,10 @@ char *pattern; XOTclObject *matchObject; Tcl_DString ds; -}; +} parseContext; static int -getMatchObject2(Tcl_Interp *interp, struct parseContext *pc) { +getMatchObject2(Tcl_Interp *interp, parseContext *pc) { if (pc->pattern && noMetaChars(pc->pattern)) { pc->matchObject = XOTclpGetObject(interp, pc->pattern); if (pc->matchObject) { @@ -11980,7 +11968,7 @@ static int parse(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], - CONST char *options[], int flags, struct parseContext *pc) { + CONST char *options[], int flags, parseContext *pc) { int modifiers = getModifiers(objc, 2, objv, options, &pc->set); int args = objc-modifiers; @@ -12062,14 +12050,17 @@ return TCL_OK; } +#include "tclAPI.h" + static int parse2(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[], - interfaceDefinition *ifdPtr, struct parseContext *pc) { + int idx, parseContext *pc) { int i, o, args, flagCount = 0, nrReq = 0, nrOpt = 0; argDefinition *aPtr, *bPtr; + interfaceDefinition *ifdPtr = &methodDefinitons[idx].ifd; + + memset(pc, 0, sizeof(parseContext)); - memset(pc, 0, sizeof(struct parseContext)); - for (i=0, o=1, aPtr=ifdPtr[0]; aPtr->name && oname,o);*/ if (*aPtr->name == '-') { @@ -12116,6 +12107,9 @@ return TCL_ERROR; } } else { + /* If no type is specified, return the string in clientData; + * objv is always passed via pc->objv + */ pc->clientData[i] = ObjStr(objv[o]); } pc->objv[i] = objv[o]; @@ -12147,7 +12141,7 @@ } static int -getMatchObject3(Tcl_Interp *interp, Tcl_Obj *patternObj, struct parseContext *pc, +getMatchObject3(Tcl_Interp *interp, Tcl_Obj *patternObj, parseContext *pc, XOTclObject **matchObject, char **pattern) { if (patternObj) { *pattern = ObjStr(patternObj); @@ -12164,18 +12158,23 @@ return 0; } -#include "tclApi.h" +static int +XOTclClassInfoHeritageMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj * CONST objv[]) { + parseContext pc; + if (parse2(clientData, interp, objc, objv, XOTclClassInfoHeritageMethodIdx, &pc) != TCL_OK) { + return TCL_ERROR; + } else { + XOTclClass *cl = (XOTclClass *)pc.clientData[0]; + char *pattern = (char *)pc.clientData[1]; + return ListHeritage(interp, cl, pattern); + } +} + static int XOTclClassInfoInstancesMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - struct parseContext pc; - interfaceDefinition d = { - {"class", 1,0, "class"}, - {"-closure"}, - {"pattern", 0,0, "objpattern"} - }; - - if (parse2(clientData, interp, objc, objv, &d, &pc) != TCL_OK) { + parseContext pc; + if (parse2(clientData, interp, objc, objv, XOTclClassInfoInstancesMethodIdx, &pc) != TCL_OK) { return TCL_ERROR; } else { XOTclClass *cl = (XOTclClass *)pc.clientData[0]; @@ -12198,142 +12197,103 @@ return TCL_OK; } -#if 0 static int -XOTclClassInfoInstancesMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - struct parseContext pc; - static CONST char *options[] = {"-closure", NULL}; - int rc, withClosure; - - if ((rc = parse(clientData, interp, objc, objv, options, - parseClass|parsePattern|parseMatchObject, &pc)) != TCL_OK || pc.resultIsSet) { - return rc; - } - withClosure = pc.set & 1 << 0; - - rc = listInstances(interp, pc.cl, pc.pattern, withClosure, pc.matchObject); - - if (pc.matchObject) { - Tcl_SetObjResult(interp, rc ? pc.matchObject->cmdName : XOTclGlobalObjects[XOTE_EMPTY]); - } - DSTRING_FREE(&pc.ds); - return TCL_OK; -} -#endif - - -static int XOTclClassInfoInstargsMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - XOTclClass *cl; - Tcl_Namespace *nsp; + parseContext pc; + if (parse2(clientData, interp, objc, objv, XOTclClassInfoInstargsMethodIdx, &pc) != TCL_OK) { + return TCL_ERROR; + } else { + XOTclClass *cl = (XOTclClass *)pc.clientData[0]; + char *methodName = (char *)pc.clientData[1]; + Tcl_Namespace *nsp = cl->nsPtr; - if (objc != 3) return XOTclObjErrArgCnt(interp, objv[0], NULL, " "); - if (GetXOTclClassFromObj(interp, objv[1], &cl, 0) != TCL_OK) - return XOTclObjErrType(interp, objv[1], "Class"); - - if (cl->nonposArgsTable) { - XOTclNonposArgs *nonposArgs = NonposArgsGet(cl->nonposArgsTable, ObjStr(objv[2])); - if (nonposArgs && nonposArgs->ordinaryArgs) { - return ListArgsFromOrdinaryArgs(interp, nonposArgs); + if (cl->nonposArgsTable) { + XOTclNonposArgs *nonposArgs = NonposArgsGet(cl->nonposArgsTable, methodName); + if (nonposArgs && nonposArgs->ordinaryArgs) { + return ListArgsFromOrdinaryArgs(interp, nonposArgs); + } } + return ListProcArgs(interp, Tcl_Namespace_cmdTable(nsp), methodName); } - nsp = cl->nsPtr; - return ListProcArgs(interp, Tcl_Namespace_cmdTable(nsp), ObjStr(objv[2])); } static int XOTclClassInfoInstbodyMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - XOTclClass *cl; - Tcl_Namespace *nsp; - - if (objc != 3) return XOTclObjErrArgCnt(interp, objv[0], NULL, " "); - if (GetXOTclClassFromObj(interp, objv[1], &cl, 0) != TCL_OK) - return XOTclObjErrType(interp, objv[1], "Class"); - - nsp = cl->nsPtr; - return ListProcBody(interp, Tcl_Namespace_cmdTable(nsp), ObjStr(objv[2])); + parseContext pc; + if (parse2(clientData, interp, objc, objv, XOTclClassInfoInstbodyMethodIdx, &pc) != TCL_OK) { + return TCL_ERROR; + } else { + XOTclClass *cl = (XOTclClass *)pc.clientData[0]; + char *methodName = (char *)pc.clientData[1]; + Tcl_Namespace *nsp = cl->nsPtr; + return ListProcBody(interp, Tcl_Namespace_cmdTable(nsp), methodName); + } } static int XOTclClassInfoInstcommandsMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - XOTclClass *cl; - Tcl_Namespace *nsp; - - if (objc < 2 || objc > 3) return XOTclObjErrArgCnt(interp, objv[0], NULL, " ?pattern?"); - if (GetXOTclClassFromObj(interp, objv[1], &cl, 0) != TCL_OK) - return XOTclObjErrType(interp, objv[1], "Class"); - - nsp = cl->nsPtr; - return ListKeys(interp, Tcl_Namespace_cmdTable(nsp), objc == 3 ? ObjStr(objv[2]) : NULL); + parseContext pc; + if (parse2(clientData, interp, objc, objv, XOTclClassInfoInstcommandsMethodIdx, &pc) != TCL_OK) { + return TCL_ERROR; + } else { + XOTclClass *cl = (XOTclClass *)pc.clientData[0]; + char *pattern = (char *)pc.clientData[1]; + Tcl_Namespace *nsp = cl->nsPtr; + return ListKeys(interp, Tcl_Namespace_cmdTable(nsp), pattern); + } } static int XOTclClassInfoInstdefaultMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - XOTclClass *cl; - Tcl_Namespace *nsp; + parseContext pc; + if (parse2(clientData, interp, objc, objv, XOTclClassInfoInstdefaultMethodIdx, &pc) != TCL_OK) { + return TCL_ERROR; + } else { + XOTclClass *cl = (XOTclClass *)pc.clientData[0]; + char *methodName = (char *)pc.clientData[1]; + char *arg = (char *)pc.clientData[2]; + Tcl_Obj *varObj = (Tcl_Obj *)pc.objv[3]; + Tcl_Namespace *nsp = cl->nsPtr; - if (objc != 5) return XOTclObjErrArgCnt(interp, objv[0], NULL, " "); - if (GetXOTclClassFromObj(interp, objv[1], &cl, 0) != TCL_OK) - return XOTclObjErrType(interp, objv[1], "Class"); - - if (cl->nonposArgsTable) { - XOTclNonposArgs *nonposArgs = NonposArgsGet(cl->nonposArgsTable, ObjStr(objv[2])); - if (nonposArgs && nonposArgs->ordinaryArgs) { - return ListDefaultFromOrdinaryArgs(interp, ObjStr(objv[2]), nonposArgs, ObjStr(objv[3]), objv[4]); + if (cl->nonposArgsTable) { + XOTclNonposArgs *nonposArgs = NonposArgsGet(cl->nonposArgsTable, methodName); + if (nonposArgs && nonposArgs->ordinaryArgs) { + return ListDefaultFromOrdinaryArgs(interp, methodName, nonposArgs, arg, varObj); + } } + return nsp ? + ListProcDefault(interp, Tcl_Namespace_cmdTable(nsp), methodName, arg, varObj) : + TCL_OK; } - nsp = cl->nsPtr; - return nsp ? - ListProcDefault(interp, Tcl_Namespace_cmdTable(nsp), ObjStr(objv[2]), ObjStr(objv[3]), objv[4]) : - TCL_OK; } static int XOTclClassInfoInstfilterMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - XOTclClass *cl; - XOTclClassOpt *opt; - int idx, nobjc, withGuards = 0; - static CONST char *options[] = {"-guards", NULL}; - enum options {guardsIdx}; + parseContext pc; + if (parse2(clientData, interp, objc, objv, XOTclClassInfoInstfilterMethodIdx, &pc) != TCL_OK) { + return TCL_ERROR; + } else { + XOTclClass *cl = (XOTclClass *)pc.clientData[0]; + int withGuards = (int) pc.clientData[1]; + char *pattern = (char *)pc.clientData[2]; + XOTclClassOpt *opt = cl->opt; - if (GetXOTclClassFromObj(interp, objv[1], &cl, 0) != TCL_OK) - return XOTclObjErrType(interp, objv[1], "Class"); - - for (idx = 2; idx < objc; idx++) { - char *name; - int index; - - name = Tcl_GetString(objv[idx]); - if (name[0] != '-') { - break; - } - if (Tcl_GetIndexFromObj(interp, objv[idx], options, "switch", TCL_EXACT, &index) != TCL_OK) { - return TCL_ERROR; - } - switch ((enum options) index) { - case guardsIdx: withGuards = 1; break; - } + return opt ? FilterInfo(interp, opt->instfilters, pattern, withGuards, 0) : TCL_OK; } - nobjc = objc - idx; - - if (objc < 2 || nobjc > 1 || objc > 4) - return XOTclObjErrArgCnt(interp, objv[0], NULL, " ?-guards? ?pattern?"); - - opt = cl->opt; - return opt ? FilterInfo(interp, opt->instfilters, idx < objc ? ObjStr(objv[idx]) : NULL, withGuards, 0) : TCL_OK; } static int XOTclClassInfoInstfilterguardMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - XOTclClass *cl; - XOTclClassOpt *opt; + parseContext pc; + if (parse2(clientData, interp, objc, objv, XOTclClassInfoInstfilterguardMethodIdx, &pc) != TCL_OK) { + return TCL_ERROR; + } else { + XOTclClass *cl = (XOTclClass *)pc.clientData[0]; + char *filter = (char *)pc.clientData[1]; + XOTclClassOpt *opt = cl->opt; - if (objc != 3) return XOTclObjErrArgCnt(interp, objv[0], NULL, " filter"); - if (GetXOTclClassFromObj(interp, objv[1], &cl, 0) != TCL_OK) - return XOTclObjErrType(interp, objv[1], "Class"); - - opt = cl->opt; - return opt ? GuardList(interp, opt->instfilters, ObjStr(objv[2])) : TCL_OK; + return opt ? GuardList(interp, opt->instfilters, filter) : TCL_OK; + } } static int @@ -12361,7 +12321,7 @@ static int XOTclClassInfoInstinvarMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - struct parseContext pc; + parseContext pc; XOTclClassOpt *opt; int rc; @@ -12379,7 +12339,7 @@ static int XOTclClassInfoInstmixinMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - struct parseContext pc; + parseContext pc; static CONST char *options[] = {"-closure", "-guards", NULL}; int rc, withGuards, withClosure; XOTclClassOpt *opt; @@ -12426,7 +12386,7 @@ static int XOTclClassInfoMixinofMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - struct parseContext pc; + parseContext pc; static CONST char *options[] = {"-closure", NULL}; int rc, withClosure; @@ -12457,7 +12417,7 @@ static int XOTclClassInfoInstmixinofMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - struct parseContext pc; + parseContext pc; static CONST char *options[] = {"-closure", NULL}; int rc, withClosure; @@ -12505,7 +12465,7 @@ static int XOTclClassInfoInstprocsMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - struct parseContext pc; + parseContext pc; if (parse(clientData, interp, objc, objv, NULL, parseClass|parsePattern, &pc) != TCL_OK) { return TCL_ERROR; @@ -12516,7 +12476,7 @@ static int XOTclClassInfoInstparametercmdMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - struct parseContext pc; + parseContext pc; if ((parse(clientData, interp, objc, objv, NULL, parseClass|parsePattern, &pc)) != TCL_OK) { return TCL_ERROR; @@ -12589,7 +12549,7 @@ static int XOTclClassInfoSuperclassMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - struct parseContext pc; + parseContext pc; static CONST char *options[] = {"-closure", NULL}; int rc, withClosure; @@ -12604,7 +12564,7 @@ static int XOTclClassInfoSubclassMethod(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - struct parseContext pc; + parseContext pc; static CONST char *options[] = {"-closure", NULL}; int rc, withClosure; Index: tests/testx.xotcl =================================================================== diff -u -r91e9b1a3b1c3e60a8538156b4aa37d5a664d5133 -rdc0040a6ddddf73e61c2a7d733ad7e15127e6bc1 --- tests/testx.xotcl (.../testx.xotcl) (revision 91e9b1a3b1c3e60a8538156b4aa37d5a664d5133) +++ tests/testx.xotcl (.../testx.xotcl) (revision dc0040a6ddddf73e61c2a7d733ad7e15127e6bc1) @@ -2750,7 +2750,7 @@ set recreateMixinResult "" set recreateFilterResult "" Class RecreateObserve - foreach ip {create destroy instdestroy init configure + foreach ip {create destroy dealloc init configure recreate cleanup alloc class} { RecreateObserve instproc $ip args { append ::recreateMixinResult " [self]+[self class]->[self proc]" @@ -2775,11 +2775,11 @@ "recreateObj - recreateFilterResult" if {$i == 0} { errorCheck [set ::recreateMixinResult] \ - " ::Recreated+::RecreateObserve->create ::Recreated+::RecreateObserve->alloc ::recreateObj+::RecreateObserve->configure ::recreateObj+::RecreateObserve->init ::Recreated+::RecreateObserve->create ::Recreated+::RecreateObserve->recreate ::recreateObj+::RecreateObserve->cleanup ::recreateObj+::RecreateObserve->configure ::recreateObj+::RecreateObserve->init ::recreateObj+::RecreateObserve->destroy ::Recreated+::RecreateObserve->instdestroy" \ + " ::Recreated+::RecreateObserve->create ::Recreated+::RecreateObserve->alloc ::recreateObj+::RecreateObserve->configure ::recreateObj+::RecreateObserve->init ::Recreated+::RecreateObserve->create ::Recreated+::RecreateObserve->recreate ::recreateObj+::RecreateObserve->cleanup ::recreateObj+::RecreateObserve->configure ::recreateObj+::RecreateObserve->init ::recreateObj+::RecreateObserve->destroy ::Recreated+::RecreateObserve->dealloc" \ "recreateObj - recreateMixinResult (0)" } else { errorCheck [set ::recreateMixinResult] \ - " ::Recreated+::RecreateObserve->cleanup ::Recreated+::RecreateObserve->create ::Recreated+::RecreateObserve->alloc ::recreateObj+::RecreateObserve->configure ::recreateObj+::RecreateObserve->init ::Recreated+::RecreateObserve->create ::Recreated+::RecreateObserve->recreate ::recreateObj+::RecreateObserve->cleanup ::recreateObj+::RecreateObserve->configure ::recreateObj+::RecreateObserve->init ::recreateObj+::RecreateObserve->destroy ::Recreated+::RecreateObserve->instdestroy" \ + " ::Recreated+::RecreateObserve->cleanup ::Recreated+::RecreateObserve->create ::Recreated+::RecreateObserve->alloc ::recreateObj+::RecreateObserve->configure ::recreateObj+::RecreateObserve->init ::Recreated+::RecreateObserve->create ::Recreated+::RecreateObserve->recreate ::recreateObj+::RecreateObserve->cleanup ::recreateObj+::RecreateObserve->configure ::recreateObj+::RecreateObserve->init ::recreateObj+::RecreateObserve->destroy ::Recreated+::RecreateObserve->dealloc" \ "recreateObj - recreateMixinResult (n)" } } @@ -2792,7 +2792,7 @@ catch {META destroy} Class A - A proc instdestroy args {append ::cleanupResult " [self]+[self class]->[self proc]"; next} + A proc dealloc args {append ::cleanupResult " [self]+[self class]->[self proc]"; next} A proc recreate args {append ::cleanupResult " [self]+[self class]->[self proc]"; next} A instproc destroy args {append ::cleanupResult " [self]+[self class]->[self proc]"; next} A instproc cleanup args {append ::cleanupResult " [self]+[self class]->[self proc]"; next} @@ -2805,7 +2805,7 @@ A a::b errorCheck [set ::cleanupResult] \ - " ::A+->recreate ::a+::A->cleanup ::a::b+::A->destroy ::A+->instdestroy" \ + " ::A+->recreate ::a+::A->cleanup ::a::b+::A->destroy ::A+->dealloc" \ "Cleanup a/a::b Failed (n)" a destroy; set ::cleanupResult "" @@ -2827,7 +2827,7 @@ Class META -superclass Class - META proc instdestroy args {append ::cleanupResult " [self]+[self class]->[self proc]"; next} + META proc dealloc args {append ::cleanupResult " [self]+[self class]->[self proc]"; next} META proc recreate args {append ::cleanupResult " [self]+[self class]->[self proc]"; next} META instproc destroy args {append ::cleanupResult " [self]+[self class]->[self proc]"; next} META instproc cleanup args {append ::cleanupResult " [self]+[self class]->[self proc]"; next} @@ -2839,7 +2839,7 @@ errorCheck [X info classchildren] "" "Class Cleanup Class Children Destroy Failed" META X::Y errorCheck [set ::cleanupResult] \ - " ::META+->recreate ::X+::META->cleanup ::X::Y+::META->destroy ::META+->instdestroy" \ + " ::META+->recreate ::X+::META->cleanup ::X::Y+::META->destroy ::META+->dealloc" \ "Class Cleanup X/X::Y Failed" X destroy