Index: TODO =================================================================== diff -u -r5fa7f2e825f97323378a15442605543055ce2655 -r761c9758221eb84b88a328e659523c4773aa5dfe --- TODO (.../TODO) (revision 5fa7f2e825f97323378a15442605543055ce2655) +++ TODO (.../TODO) (revision 761c9758221eb84b88a328e659523c4773aa5dfe) @@ -1242,6 +1242,9 @@ - fixed reference counting problem with user-defined converters +- added flag -complain to ::nsf::is +- removed ::nsf::parametercheck + TODO: - reflect changes in /is/objectproperty/info has/info is/ in migration guide - implement built-in-converter for "baseclass" and "metaclass"? Index: generic/gentclAPI.decls =================================================================== diff -u -rf20a7f81bcae20a40c4990afd431615ca1914c51 -r761c9758221eb84b88a328e659523c4773aa5dfe --- generic/gentclAPI.decls (.../gentclAPI.decls) (revision f20a7f81bcae20a40c4990afd431615ca1914c51) +++ generic/gentclAPI.decls (.../gentclAPI.decls) (revision 761c9758221eb84b88a328e659523c4773aa5dfe) @@ -86,6 +86,7 @@ {-argName "class" -type class} } xotclCmd is XOTclIsCmd { + {-argName "-complain"} {-argName "constraint" -required 1 -type tclobj} {-argName "value" -required 1 -type tclobj} } @@ -124,11 +125,6 @@ {-argName "fromNs" -required 1 -type tclobj} {-argName "toNs" -required 1 -type tclobj} } -xotclCmd parametercheck XOTclParametercheckCmd { - {-argName "-nocomplain"} - {-argName "param" -type tclobj} - {-argName "value" -required 1 -type tclobj} -} xotclCmd __qualify XOTclQualifyObjCmd { {-argName "name" -required 1 -type tclobj} } Index: generic/tclAPI.h =================================================================== diff -u -rf20a7f81bcae20a40c4990afd431615ca1914c51 -r761c9758221eb84b88a328e659523c4773aa5dfe --- generic/tclAPI.h (.../tclAPI.h) (revision f20a7f81bcae20a40c4990afd431615ca1914c51) +++ generic/tclAPI.h (.../tclAPI.h) (revision 761c9758221eb84b88a328e659523c4773aa5dfe) @@ -219,7 +219,6 @@ static int XOTclMyCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int XOTclNSCopyCmdsStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int XOTclNSCopyVarsStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); -static int XOTclParametercheckCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int XOTclQualifyObjCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int XOTclRelationCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); static int XOTclSetVarCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv []); @@ -292,14 +291,13 @@ static int XOTclImportvarCmd(Tcl_Interp *interp, XOTclObject *object, int nobjc, Tcl_Obj *CONST nobjv[]); static int XOTclInterpObjCmd(Tcl_Interp *interp, CONST char *name, int objc, Tcl_Obj *CONST objv[]); static int XOTclInvalidateObjectParameterCmd(Tcl_Interp *interp, XOTclClass *class); -static int XOTclIsCmd(Tcl_Interp *interp, Tcl_Obj *constraint, Tcl_Obj *value); +static int XOTclIsCmd(Tcl_Interp *interp, int withComplain, Tcl_Obj *constraint, Tcl_Obj *value); static int XOTclIsObjectCmd(Tcl_Interp *interp, Tcl_Obj *object); 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); static int XOTclMyCmd(Tcl_Interp *interp, int withLocal, Tcl_Obj *method, int nobjc, Tcl_Obj *CONST nobjv[]); static int XOTclNSCopyCmds(Tcl_Interp *interp, Tcl_Obj *fromNs, Tcl_Obj *toNs); static int XOTclNSCopyVars(Tcl_Interp *interp, Tcl_Obj *fromNs, Tcl_Obj *toNs); -static int XOTclParametercheckCmd(Tcl_Interp *interp, int withNocomplain, Tcl_Obj *param, Tcl_Obj *value); static int XOTclQualifyObjCmd(Tcl_Interp *interp, Tcl_Obj *name); static int XOTclRelationCmd(Tcl_Interp *interp, XOTclObject *object, int relationtype, Tcl_Obj *value); static int XOTclSetVarCmd(Tcl_Interp *interp, XOTclObject *object, Tcl_Obj *variable, Tcl_Obj *value); @@ -380,7 +378,6 @@ XOTclMyCmdIdx, XOTclNSCopyCmdsIdx, XOTclNSCopyVarsIdx, - XOTclParametercheckCmdIdx, XOTclQualifyObjCmdIdx, XOTclRelationCmdIdx, XOTclSetVarCmdIdx, @@ -1734,11 +1731,12 @@ &pc) != TCL_OK) { return TCL_ERROR; } else { - Tcl_Obj *constraint = (Tcl_Obj *)pc.clientData[0]; - Tcl_Obj *value = (Tcl_Obj *)pc.clientData[1]; + int withComplain = (int )PTR2INT(pc.clientData[0]); + Tcl_Obj *constraint = (Tcl_Obj *)pc.clientData[1]; + Tcl_Obj *value = (Tcl_Obj *)pc.clientData[2]; parseContextRelease(&pc); - return XOTclIsCmd(interp, constraint, value); + return XOTclIsCmd(interp, withComplain, constraint, value); } } @@ -1867,26 +1865,6 @@ } static int -XOTclParametercheckCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { - parseContext pc; - - if (ArgumentParse(interp, objc, objv, NULL, objv[0], - method_definitions[XOTclParametercheckCmdIdx].paramDefs, - method_definitions[XOTclParametercheckCmdIdx].nrParameters, - &pc) != TCL_OK) { - return TCL_ERROR; - } else { - int withNocomplain = (int )PTR2INT(pc.clientData[0]); - Tcl_Obj *param = (Tcl_Obj *)pc.clientData[1]; - Tcl_Obj *value = (Tcl_Obj *)pc.clientData[2]; - - parseContextRelease(&pc); - return XOTclParametercheckCmd(interp, withNocomplain, param, value); - - } -} - -static int XOTclQualifyObjCmdStub(ClientData clientData, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]) { parseContext pc; @@ -2234,7 +2212,8 @@ {"::nsf::invalidateobjectparameter", XOTclInvalidateObjectParameterCmdStub, 1, { {"class", 0, 0, convertToClass}} }, -{"::nsf::is", XOTclIsCmdStub, 2, { +{"::nsf::is", XOTclIsCmdStub, 3, { + {"-complain", 0, 0, convertToString}, {"constraint", 1, 0, convertToTclobj}, {"value", 1, 0, convertToTclobj}} }, @@ -2272,11 +2251,6 @@ {"fromNs", 1, 0, convertToTclobj}, {"toNs", 1, 0, convertToTclobj}} }, -{"::nsf::parametercheck", XOTclParametercheckCmdStub, 3, { - {"-nocomplain", 0, 0, convertToString}, - {"param", 0, 0, convertToTclobj}, - {"value", 1, 0, convertToTclobj}} -}, {"::nsf::__qualify", XOTclQualifyObjCmdStub, 1, { {"name", 1, 0, convertToTclobj}} }, Index: generic/xotcl.c =================================================================== diff -u -r5fa7f2e825f97323378a15442605543055ce2655 -r761c9758221eb84b88a328e659523c4773aa5dfe --- generic/xotcl.c (.../xotcl.c) (revision 5fa7f2e825f97323378a15442605543055ce2655) +++ generic/xotcl.c (.../xotcl.c) (revision 761c9758221eb84b88a328e659523c4773aa5dfe) @@ -11542,12 +11542,38 @@ /* xotclCmd is XOTclIsCmd { + {-argName "-complain"} {-argName "constraint" -required 1 -type tclobj} {-argName "value" -required 1 -type tclobj} } */ -static int XOTclIsCmd(Tcl_Interp *interp, Tcl_Obj *constraintObj, Tcl_Obj *valueObj) { - return XOTclParametercheckCmd(interp, 1, constraintObj, valueObj); +static int XOTclIsCmd(Tcl_Interp *interp, int withComplain, Tcl_Obj *constraintObj, Tcl_Obj *valueObj) { + XOTclParam *paramPtr = NULL; + int result; + + result = Parametercheck(interp, constraintObj, valueObj, "value:", ¶mPtr); + + if (paramPtr == NULL) { + /* + * We could not convert the arguments. Even with noComplain, we + * report the invalid converter spec as exception + */ + return TCL_ERROR; + } + + if (paramPtr->converter == convertViaCmd + && (withComplain == 0 || result == TCL_OK)) { + Tcl_ResetResult(interp); + } + + if (withComplain == 0) { + Tcl_SetIntObj(Tcl_GetObjResult(interp), (result == TCL_OK)); + result = TCL_OK; + } else if (result == TCL_OK) { + Tcl_SetIntObj(Tcl_GetObjResult(interp), 1); + } + + return result; } /* @@ -12642,7 +12668,7 @@ ClientData checkedData; int result, flags = 0; - /*fprintf(stderr, "XOTclParametercheckCmd %s value %p %s\n", + /*fprintf(stderr, "ParamSetFromAny %s value %p %s\n", ObjStr(objPtr), valueObj, ObjStr(valueObj));*/ if (objPtr->typePtr == ¶mObjType) { @@ -12661,11 +12687,11 @@ if (paramPtrPtr) *paramPtrPtr = paramPtr; result = ArgumentCheck(interp, valueObj, paramPtr, &flags, &checkedData, &outObjPtr); - /*fprintf(stderr, "XOTclParametercheckCmd paramPtr %p final refcount of wrapper %d can free %d\n", + /*fprintf(stderr, "ParamSetFromAny paramPtr %p final refcount of wrapper %d can free %d\n", paramPtr, paramWrapperPtr->refCount, paramWrapperPtr->canFree);*/ if (paramWrapperPtr->refCount == 0) { - /* fprintf(stderr, "XOTclParametercheckCmd paramPtr %p manual free\n",paramPtr);*/ + /* fprintf(stderr, "ParamSetFromAny paramPtr %p manual free\n",paramPtr);*/ ParamsFree(paramWrapperPtr->paramPtr); FREE(XOTclParamWrapper, paramWrapperPtr); } else { @@ -12679,42 +12705,6 @@ return result; } -/* -xotclCmd parametercheck XOTclParametercheckCmd { - {-argName "param" -type tclobj} - {-argName "-nocomplain"} - {-argName "value" -required 0 -type tclobj} - } -*/ -static int XOTclParametercheckCmd(Tcl_Interp *interp, int withNocomplain, Tcl_Obj *objPtr, Tcl_Obj *valueObj) { - XOTclParam *paramPtr = NULL; - int result; - - result = Parametercheck(interp, objPtr, valueObj, "value:", ¶mPtr); - - if (paramPtr == NULL) { - /* - * We could not convert the arguments. Even with noComplain, we - * report the invalid converter spec as exception - */ - return TCL_ERROR; - } - - if (paramPtr->converter == convertViaCmd - && (withNocomplain || result == TCL_OK)) { - Tcl_ResetResult(interp); - } - - if (withNocomplain) { - Tcl_SetIntObj(Tcl_GetObjResult(interp), (result == TCL_OK)); - result = TCL_OK; - } else if (result == TCL_OK) { - Tcl_SetIntObj(Tcl_GetObjResult(interp), 1); - } - - return result; -} - /*************************** * End generated XOTcl commands ***************************/ @@ -13425,11 +13415,6 @@ return TCL_OK; } -/* todo temporary, remove me yyy */ -static int XOTclOVarsMethod(Tcl_Interp *interp, XOTclObject *object, CONST char *pattern) { - return XOTclObjInfoVarsMethod(interp, object, pattern); -} - /*************************** * End Object Methods ***************************/ Index: tests/parameters.tcl =================================================================== diff -u -r5e70792b640c7d8b9a7235ba529dbfc0af2b84ad -r761c9758221eb84b88a328e659523c4773aa5dfe --- tests/parameters.tcl (.../parameters.tcl) (revision 5e70792b640c7d8b9a7235ba529dbfc0af2b84ad) +++ tests/parameters.tcl (.../parameters.tcl) (revision 761c9758221eb84b88a328e659523c4773aa5dfe) @@ -24,7 +24,6 @@ Class create M c1 mixin M - ? {::nsf::isobject o1} 1 ? {::nsf::isobject o1000} 0 @@ -39,17 +38,17 @@ ? {::nsf::is class ::nx::Object} 1 ? {::nsf::is ::nx::Object class} {invalid value constraints "::nx::Object"} - ? {::nsf::parametercheck object o1} 1 - ? {::nsf::parametercheck -nocomplain object o1} 1 - ? {::nsf::parametercheck -nocomplain object o1000} 0 - ? {::nsf::parametercheck integer 1} 1 - ? {::nsf::parametercheck object,type=::C c1} 1 - ? {::nsf::parametercheck object,type=::C o} {expected object but got "o" for parameter value} - ? {::nsf::parametercheck -nocomplain object,type=::C o} 0 + ? {::nsf::is object o1} 1 + ? {::nsf::is object o1} 1 + ? {::nsf::is object o1000} 0 + ? {::nsf::is -complain object o1000} {expected object but got "o1000" for parameter value} + ? {::nsf::is integer 1} 1 + ? {::nsf::is object,type=::C c1} 1 + ? {::nsf::is -complain object,type=::C o} {expected object but got "o" for parameter value} + ? {::nsf::is object,type=::C o} 0 ? {c1 info has mixin ::M} 1 ? {c1 info has mixin ::M1} {expected class but got "::M1" for parameter class} - #? {::nsf::parametercheck hasmixin,arg=::M c1} 1 #? {::nsf::is type c1 C} 1 ? {c1 info has type C} 1 @@ -72,32 +71,32 @@ #? {::nsf::is object o -type C} 0 #? {::nsf::is object o -hasmixin C} 0 #exit - ? {::nsf::parametercheck class o1} {expected class but got "o1" for parameter value} - ? {::nsf::parametercheck -nocomplain class o1} 0 - ? {::nsf::parametercheck class Test} 1 - ? {::nsf::parametercheck object,multivalued [list o1 Test]} 1 + ? {::nsf::is -complain class o1} {expected class but got "o1" for parameter value} + ? {::nsf::is class o1} 0 + ? {::nsf::is -complain class Test} 1 + ? {::nsf::is -complain object,multivalued [list o1 Test]} 1 - ? {::nsf::parametercheck integer,multivalued [list 1 2 3]} 1 - ? {::nsf::parametercheck integer,multivalued [list 1 2 3 a]} \ + ? {::nsf::is -complain integer,multivalued [list 1 2 3]} 1 + ? {::nsf::is -complain integer,multivalued [list 1 2 3 a]} \ {invalid value in "1 2 3 a": expected integer but got "a" for parameter value} - ? {::nsf::parametercheck object,type=::C c1} 1 - ? {::nsf::parametercheck object,type=::C o} \ + ? {::nsf::is -complain object,type=::C c1} 1 + ? {::nsf::is -complain object,type=::C o} \ {expected object but got "o" for parameter value} \ "object, but different type" - ? {::nsf::parametercheck object,type=::C c} \ + ? {::nsf::is -complain object,type=::C c} \ {expected object but got "c" for parameter value} \ "no object" - ? {::nsf::parametercheck object,type=::nx::Object c1} 1 "general type" + ? {::nsf::is -complain object,type=::nx::Object c1} 1 "general type" # do not allow "currently unknown" user defined types in parametercheck - ? {::nsf::parametercheck in1 aaa} {invalid value constraints "in1"} + ? {::nsf::is -complain in1 aaa} {invalid value constraints "in1"} - ? {::nsf::parametercheck lower c} 1 "lower case char" - ? {::nsf::parametercheck lower abc} 1 "lower case chars" - ? {::nsf::parametercheck lower Abc} {expected lower but got "Abc" for parameter value} + ? {::nsf::is -complain lower c} 1 "lower case char" + ? {::nsf::is -complain lower abc} 1 "lower case chars" + ? {::nsf::is -complain lower Abc} {expected lower but got "Abc" for parameter value} ? {string is lower abc} 1 "tcl command 'string is lower'" - ? {::nsf::parametercheck {i:integer 1} 2} {invalid value constraints "i:integer 1"} + ? {::nsf::is -complain {i:integer 1} 2} {invalid value constraints "i:integer 1"} } ####################################################### @@ -112,7 +111,7 @@ } } - ? {::nsf::parametercheck sex,slot=::paramManager female} "1" + ? {::nsf::is -complain sex,slot=::paramManager female} "1" } ####################################################### # cononical feature table @@ -902,11 +901,11 @@ # Note that this converter does NOT return a value; it converts all # values into emtpy strings. } - ? {::nsf::parametercheck mType,slot=::tmpObj,multivalued {1 0}} \ + ? {::nsf::is -complain mType,slot=::tmpObj,multivalued {1 0}} \ {invalid value in "1 0": expected false but got 1} \ "fail on first value" - ? {::nsf::parametercheck mType,slot=::tmpObj,multivalued {0 0 0}} 1 "all pass" - ? {::nsf::parametercheck mType,slot=::tmpObj,multivalued {0 1}} \ + ? {::nsf::is -complain mType,slot=::tmpObj,multivalued {0 0 0}} 1 "all pass" + ? {::nsf::is -complain mType,slot=::tmpObj,multivalued {0 1}} \ {invalid value in "0 1": expected false but got 1} \ "fail o last value" } @@ -926,7 +925,7 @@ } } - ? {::nsf::parametercheck integer,slot=::mySlot 1} 1 + ? {::nsf::is -complain integer,slot=::mySlot 1} 1 ? {o foo 3} 4 }