Index: generic/gentclAPI.decls =================================================================== diff -u -r536cacc0e51390f46b6bde5874c823ea03e732e2 -rb1f416527fc1e567ff1db9ad5a720b3bbc5678ee --- generic/gentclAPI.decls (.../gentclAPI.decls) (revision 536cacc0e51390f46b6bde5874c823ea03e732e2) +++ generic/gentclAPI.decls (.../gentclAPI.decls) (revision b1f416527fc1e567ff1db9ad5a720b3bbc5678ee) @@ -86,6 +86,11 @@ {-argName "objectkind" -type "type|object|class|baseclass|metaclass|hasmixin"} {-argName "value" -required 0 -type tclobj} } +xotclCmd is2 XOTclIs2Cmd { + {-argName "constraint" -required 1 -type tclobj} + {-argName "value" -required 1 -type tclobj} + {-argName "arg" -required 0 -type tclobj} +} xotclCmd method XOTclMethodCmd { {-argName "object" -required 1 -type object} {-argName "-inner-namespace"} Index: generic/predefined.h =================================================================== diff -u -r4d21376ac1245e34cb5a5f52da893072f311d3a9 -rb1f416527fc1e567ff1db9ad5a720b3bbc5678ee --- generic/predefined.h (.../predefined.h) (revision 4d21376ac1245e34cb5a5f52da893072f311d3a9) +++ generic/predefined.h (.../predefined.h) (revision b1f416527fc1e567ff1db9ad5a720b3bbc5678ee) @@ -175,8 +175,7 @@ "set info ObjectInfo} else {\n" "set info ClassInfo}\n" ":create [:slotName $name $target] {*}$opts $initblock\n" -"puts stderr \"::xotcl::cmd::${info}::method $target name $name => [::xotcl::cmd::${info}::method $target name $name]\"\n" -"::xotcl::cmd::${info}::method $target name $name}\n" +"return [::xotcl::cmd::${info}::method $target name $name]}\n" "::xotcl::MetaSlot create ::xotcl::Slot\n" "::xotcl::MetaSlot create ::xotcl::ObjectParameterSlot\n" "::xotcl::relation ::xotcl::ObjectParameterSlot superclass ::xotcl::Slot\n" Index: generic/tclAPI.h =================================================================== diff -u -r536cacc0e51390f46b6bde5874c823ea03e732e2 -rb1f416527fc1e567ff1db9ad5a720b3bbc5678ee --- generic/tclAPI.h (.../tclAPI.h) (revision 536cacc0e51390f46b6bde5874c823ea03e732e2) +++ generic/tclAPI.h (.../tclAPI.h) (revision b1f416527fc1e567ff1db9ad5a720b3bbc5678ee) @@ -192,6 +192,7 @@ static int XOTclGetSelfObjCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int XOTclImportvarCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int XOTclInterpObjCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); +static int XOTclIs2CmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int XOTclIsCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int XOTclMethodCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int XOTclMethodPropertyCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); @@ -273,6 +274,7 @@ static int XOTclGetSelfObjCmd(Tcl_Interp *interp, int selfoption); static int XOTclImportvarCmd(Tcl_Interp *interp, XOTclObject *object, int nobjc, Tcl_Obj *CONST nobjv[]); static int XOTclInterpObjCmd(Tcl_Interp *interp, char *name, int objc, Tcl_Obj *CONST objv[]); +static int XOTclIs2Cmd(Tcl_Interp *interp, Tcl_Obj *constraint, Tcl_Obj *value, Tcl_Obj *arg); static int XOTclIsCmd(Tcl_Interp *interp, Tcl_Obj *object, int objectkind, Tcl_Obj *value); static int XOTclMethodCmd(Tcl_Interp *interp, XOTclObject *object, int withInner_namespace, int withPer_object, int withPublic, Tcl_Obj *name, Tcl_Obj *args, Tcl_Obj *body, Tcl_Obj *withPrecondition, Tcl_Obj *withPostcondition); static int XOTclMethodPropertyCmd(Tcl_Interp *interp, XOTclObject *object, int withPer_object, Tcl_Obj *methodName, int methodproperty, Tcl_Obj *value); @@ -355,6 +357,7 @@ XOTclGetSelfObjCmdIdx, XOTclImportvarCmdIdx, XOTclInterpObjCmdIdx, + XOTclIs2CmdIdx, XOTclIsCmdIdx, XOTclMethodCmdIdx, XOTclMethodPropertyCmdIdx, @@ -1734,6 +1737,26 @@ } static int +XOTclIs2CmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { + parseContext pc; + + if (ArgumentParse(interp, objc, objv, NULL, objv[0], + method_definitions[XOTclIs2CmdIdx].paramDefs, + method_definitions[XOTclIs2CmdIdx].nrParameters, + &pc) != TCL_OK) { + return TCL_ERROR; + } else { + Tcl_Obj *constraint = (Tcl_Obj *)pc.clientData[0]; + Tcl_Obj *value = (Tcl_Obj *)pc.clientData[1]; + Tcl_Obj *arg = (Tcl_Obj *)pc.clientData[2]; + + parseContextRelease(&pc); + return XOTclIs2Cmd(interp, constraint, value, arg); + + } +} + +static int XOTclIsCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { parseContext pc; @@ -2256,6 +2279,11 @@ {"name", 0, 0, convertToString}, {"args", 0, 0, convertToNothing}} }, +{"::xotcl::is2", XOTclIs2CmdStub, 3, { + {"constraint", 1, 0, convertToTclobj}, + {"value", 1, 0, convertToTclobj}, + {"arg", 0, 0, convertToTclobj}} +}, {"::xotcl::is", XOTclIsCmdStub, 3, { {"object", 1, 0, convertToTclobj}, {"objectkind", 0, 0, convertToObjectkind}, Index: generic/xotcl.c =================================================================== diff -u -rb3fff4e39a7ffb6079d07aa0aef4e0bc8dd419a0 -rb1f416527fc1e567ff1db9ad5a720b3bbc5678ee --- generic/xotcl.c (.../xotcl.c) (revision b3fff4e39a7ffb6079d07aa0aef4e0bc8dd419a0) +++ generic/xotcl.c (.../xotcl.c) (revision b1f416527fc1e567ff1db9ad5a720b3bbc5678ee) @@ -12478,7 +12478,7 @@ ClientData checkedData; XOTclParam *paramPtr; Tcl_Obj *outObjPtr; - int result, flags; + int result, flags = 0; if (objPtr->typePtr == ¶mObjType) { paramPtr = (XOTclParam *) objPtr->internalRep.twoPtrValue.ptr1; @@ -12515,6 +12515,51 @@ return result; } + +/* +xotclCmd is2 XOTclIs2Cmd { + {-argName "constraint" -required 1 -type tclobj} + {-argName "value" -required 1 -type tclobj} + {-argName "arg" -required 0 -type tclobj} +} +*/ +static int XOTclIs2Cmd(Tcl_Interp *interp, Tcl_Obj *constraintObj, Tcl_Obj *value, Tcl_Obj *arg) { + int result = TCL_OK; + char *constraintString = ObjStr(constraintObj); + XOTclObject *object; + XOTclClass *cl; + + if (value == NULL) return XOTclObjErrArgCnt(interp, NULL, NULL, " ??"); + + if (isTypeString(constraintString)) { + int success; + if (arg== NULL) return XOTclObjErrArgCnt(interp, NULL, NULL, "type "); + success = (GetObjectFromObj(interp, value, &object) == TCL_OK) + && (GetClassFromObj(interp, arg, &cl, 0) == TCL_OK) + && isSubType(object->cl, cl); + + Tcl_SetIntObj(Tcl_GetObjResult(interp), success); + + } else if (arg != NULL) { + Tcl_Obj *paramObj = Tcl_DuplicateObj(value); + + INCR_REF_COUNT(paramObj); + Tcl_AppendToObj(paramObj, ",arg=", 5); + Tcl_AppendObjToObj(paramObj, arg); + + result = XOTclValuecheckCmd(interp, 1, paramObj, value); + DECR_REF_COUNT(paramObj); + } else { + result = XOTclValuecheckCmd(interp, 1, constraintObj, value); + } + + return result; +} + + + + + /*************************** * End generated XOTcl commands ***************************/ Index: generic/xotclInt.h =================================================================== diff -u -rc0b363cae9d43d3cb564b230233cc211470acd7e -rb1f416527fc1e567ff1db9ad5a720b3bbc5678ee --- generic/xotclInt.h (.../xotclInt.h) (revision c0b363cae9d43d3cb564b230233cc211470acd7e) +++ generic/xotclInt.h (.../xotclInt.h) (revision b1f416527fc1e567ff1db9ad5a720b3bbc5678ee) @@ -137,8 +137,10 @@ #define isInitString(m) (\ *m == 'i' && m[1] == 'n' && m[2] == 'i' && m[3] == 't' && \ m[4] == '\0') +#define isTypeString(m) (\ + *m == 't' && m[1] == 'y' && m[2] == 'p' && m[3] == 'e' && \ + m[4] == '\0') - #if (defined(sun) || defined(__hpux)) && !defined(__GNUC__) # define USE_ALLOCA #endif Index: tests/parameters.xotcl =================================================================== diff -u -r4d21376ac1245e34cb5a5f52da893072f311d3a9 -rb1f416527fc1e567ff1db9ad5a720b3bbc5678ee --- tests/parameters.xotcl (.../parameters.xotcl) (revision 4d21376ac1245e34cb5a5f52da893072f311d3a9) +++ tests/parameters.xotcl (.../parameters.xotcl) (revision b1f416527fc1e567ff1db9ad5a720b3bbc5678ee) @@ -23,12 +23,19 @@ C create c1 ? {::xotcl::valuecheck object o1} 1 + ? {::xotcl::valuecheck integer 1} 1 ? {::xotcl::is o1 object} 1 + ? {::xotcl::is c1 type C} 1 + ? {::xotcl::is2 object o1} 1 + ? {::xotcl::is2 integer 1} 1 + ? {::xotcl::is2 type c1 C} 1 + ? {::xotcl::is2 type o C} 0 + ? {::xotcl::valuecheck class o1} {expected class but got "o1" for parameter value} ? {::xotcl::valuecheck -nocomplain class o1} 0 ? {::xotcl::valuecheck class Test} 1 ? {::xotcl::valuecheck object,multivalued [list o1 Test]} 1 - ? {::xotcl::valuecheck integer 1} 1 + ? {::xotcl::valuecheck integer,multivalued [list 1 2 3]} 1 ? {::xotcl::valuecheck integer,multivalued [list 1 2 3 a]} \ {invalid value in "1 2 3 a": expected integer but got "a" for parameter value}