Index: TODO =================================================================== diff -u -r27e11788125901ff468955117d165f70d3871ce0 -r1e3a84fd851f93ae3116130a530fae5e8bd63336 --- TODO (.../TODO) (revision 27e11788125901ff468955117d165f70d3871ce0) +++ TODO (.../TODO) (revision 1e3a84fd851f93ae3116130a530fae5e8bd63336) @@ -1324,8 +1324,11 @@ - removed some obsolete functions - changed "info available" into "info lookup" - (and accordingly c definitions) + (and accordingly c definitions, migration guide) +- pass tclobj instead of string to NsfObjInfoMethodMethod and NsfObjInfoMethodsMethod +- first part of ensemble name resolver + TODO: - check equivalence of the following two commands Index: generic/gentclAPI.decls =================================================================== diff -u -r27e11788125901ff468955117d165f70d3871ce0 -r1e3a84fd851f93ae3116130a530fae5e8bd63336 --- generic/gentclAPI.decls (.../gentclAPI.decls) (revision 27e11788125901ff468955117d165f70d3871ce0) +++ generic/gentclAPI.decls (.../gentclAPI.decls) (revision 1e3a84fd851f93ae3116130a530fae5e8bd63336) @@ -6,12 +6,12 @@ # namespaces for types of methods array set ns { - nsfCmd "::nsf" - objectMethod "::nsf::cmd::Object" + nsfCmd "::nsf" + objectMethod "::nsf::cmd::Object" objectInfoMethod "::nsf::cmd::ObjectInfo" - classMethod "::nsf::cmd::Class" - classInfoMethod "::nsf::cmd::ClassInfo" - checkMethod "::nsf::cmd::ParameterType" + classMethod "::nsf::cmd::Class" + classInfoMethod "::nsf::cmd::ClassInfo" + checkMethod "::nsf::cmd::ParameterType" } # @@ -262,7 +262,7 @@ } objectInfoMethod method NsfObjInfoMethodMethod { {-argName "infomethodsubcmd" -type "args|body|definition|handle|parameter|parametersyntax|type|precondition|postcondition"} - {-argName "name"} + {-argName "name" -type tclobj} } objectInfoMethod methods NsfObjInfoMethodsMethod { {-argName "-methodtype" -nrargs 1 -type "all|scripted|builtin|alias|forwarder|object|setter"} @@ -314,7 +314,7 @@ classInfoMethod method NsfClassInfoMethodMethod { {-argName "infomethodsubcmd" -type "args|body|definition|handle|parameter|parametersyntax|type|precondition|postcondition"} - {-argName "name"} + {-argName "name" -type tclobj} } classInfoMethod methods NsfClassInfoMethodsMethod { {-argName "-methodtype" -nrargs 1 -type "all|scripted|builtin|alias|forwarder|object|setter"} Index: generic/nsf.c =================================================================== diff -u -r27e11788125901ff468955117d165f70d3871ce0 -r1e3a84fd851f93ae3116130a530fae5e8bd63336 --- generic/nsf.c (.../nsf.c) (revision 27e11788125901ff468955117d165f70d3871ce0) +++ generic/nsf.c (.../nsf.c) (revision 1e3a84fd851f93ae3116130a530fae5e8bd63336) @@ -1099,6 +1099,98 @@ /* *---------------------------------------------------------------------- + * GetEnsembeObjectFromName -- + * + * Get an ensemble object from a method name. If the method name + * is fully qualified, just use a Tcl lookup, otherwise get it from + * the provided namespace, + * + * Results: + * ensemble object or NULL + * + * Side effects: + * none + * + *---------------------------------------------------------------------- + */ +static NsfObject * +GetEnsembeObjectFromName(Tcl_Interp *interp, Tcl_Namespace *nsPtr, Tcl_Obj *name) { + NsfObject *object; + Tcl_Command cmd; + char *nameString = ObjStr(name); + + if (*nameString == ':') { + cmd = Tcl_GetCommandFromObj(interp, name); + } else { + cmd = FindMethod(nsPtr, nameString); + } + + object = cmd ? NsfGetObjectFromCmdPtr(cmd) : NULL; + /*fprintf(stderr, "GetEnsembeObjectFromName returns %p\n", object);*/ + return object; +} + +/* + *---------------------------------------------------------------------- + * ResolveMethodName -- + * + * Resolve a method name relative to a provided namespace. + * The method name can be + * a) a fully qualified name + * b) a list of method name and subcommands + * c) a simple name + * + * Results: + * Tcl_Command or NULL on failure + * + * Side effects: + * none + * + *---------------------------------------------------------------------- + */ + +static Tcl_Command +ResolveMethodName(Tcl_Interp *interp, Tcl_Namespace *nsPtr, Tcl_Obj *methodObj) { + Tcl_Command cmd; + char* methodName = ObjStr(methodObj); + + if (nsPtr && strchr(methodName, ' ') > 0) { + Tcl_Obj *methodHandleObj; + NsfObject *referencedObject; + Tcl_Obj **ov; + int oc=0, result, i; + + /*fprintf(stderr, "name '%s' contains space \n", methodName);*/ + if ((result = Tcl_ListObjGetElements(interp, methodObj, &oc, &ov) != TCL_OK) + || ((referencedObject = GetEnsembeObjectFromName(interp, nsPtr, ov[0])) == NULL) + ) { + return NULL; + } + /*fprintf(stderr, "... referenced object '%s' \n", objectName(referencedObject));*/ + methodHandleObj = Tcl_DuplicateObj(referencedObject->cmdName); + + for (i = 1; iorder = saved; } +/* + *---------------------------------------------------------------------- + * MethodHandleObj -- + * + * Builds a methodHandle from a method name. In case the method + * name is fully qualified, it is simply returned. + * + * Results: + * fresh Tcl_Obj + * + * Side effects: + * none + * + *---------------------------------------------------------------------- + */ static Tcl_Obj * MethodHandleObj(NsfObject *object, int withPer_object, CONST char *methodName) { - Tcl_Obj *resultObj = Tcl_NewStringObj(withPer_object ? "" : "::nsf::classes", -1); - assert(object); - Tcl_AppendObjToObj(resultObj, object->cmdName); - Tcl_AppendStringsToObj(resultObj, "::", methodName, (char *) NULL); + Tcl_Obj *resultObj; + if (*methodName == ':') { + /* + * if we have a methodname starting with ":" and we made it so far, + * we assume it is correct + */ + resultObj = Tcl_NewStringObj(methodName, -1); + } else { + resultObj = Tcl_NewStringObj(withPer_object ? "" : "::nsf::classes", -1); + assert(object); + Tcl_AppendObjToObj(resultObj, object->cmdName); + Tcl_AppendStringsToObj(resultObj, "::", methodName, (char *) NULL); + } return resultObj; } @@ -14201,6 +14317,7 @@ if (cmd) { NsfObject *pobj = pcl ? &pcl->object : object; int perObject = (pcl == NULL); + ListMethod(interp, pobj, name, cmd, InfomethodsubcmdHandleIdx, perObject); } return TCL_OK; @@ -14312,19 +14429,14 @@ {-argName "name"} } */ + static int NsfObjInfoMethodMethod(Tcl_Interp *interp, NsfObject *object, - int subcmd, CONST char *methodName) { - Tcl_Namespace *nsPtr = object->nsPtr; - Tcl_Command cmd; + int subcmd, Tcl_Obj *methodName) { - if (*methodName == ':') { - Tcl_Obj *methodObj = Tcl_NewStringObj(methodName, -1); - cmd = Tcl_GetCommandFromObj(interp, methodObj); - } else { - cmd = nsPtr ? FindMethod(nsPtr, methodName) : NULL; - } - return ListMethod(interp, object, methodName, cmd, subcmd, 1); + return ListMethod(interp, object, ObjStr(methodName), + ResolveMethodName(interp, object->nsPtr, methodName), + subcmd, 1); } /* @@ -14549,19 +14661,14 @@ {-argName "name"} } */ + static int NsfClassInfoMethodMethod(Tcl_Interp *interp, NsfClass *class, - int subcmd, CONST char *methodName) { - Tcl_Namespace *nsPtr = class->nsPtr; - Tcl_Command cmd; + int subcmd, Tcl_Obj *methodName) { - if (*methodName == ':') { - Tcl_Obj *methodObj = Tcl_NewStringObj(methodName, -1); - cmd = Tcl_GetCommandFromObj(interp, methodObj); - } else { - cmd = nsPtr ? FindMethod(nsPtr, methodName) : NULL; - } - return ListMethod(interp, &class->object, methodName, cmd, subcmd, 0); + return ListMethod(interp, &class->object, ObjStr(methodName), + ResolveMethodName(interp, class->nsPtr, methodName), + subcmd, 0); } /* Index: generic/tclAPI.h =================================================================== diff -u -r27e11788125901ff468955117d165f70d3871ce0 -r1e3a84fd851f93ae3116130a530fae5e8bd63336 --- generic/tclAPI.h (.../tclAPI.h) (revision 27e11788125901ff468955117d165f70d3871ce0) +++ generic/tclAPI.h (.../tclAPI.h) (revision 1e3a84fd851f93ae3116130a530fae5e8bd63336) @@ -227,7 +227,7 @@ static int NsfClassInfoForwardMethod(Tcl_Interp *interp, NsfClass *cl, int withDefinition, CONST char *name); static int NsfClassInfoHeritageMethod(Tcl_Interp *interp, NsfClass *cl, CONST char *pattern); static int NsfClassInfoInstancesMethod(Tcl_Interp *interp, NsfClass *cl, int withClosure, CONST char *patternString, NsfObject *patternObj); -static int NsfClassInfoMethodMethod(Tcl_Interp *interp, NsfClass *cl, int infomethodsubcmd, CONST char *name); +static int NsfClassInfoMethodMethod(Tcl_Interp *interp, NsfClass *cl, int infomethodsubcmd, Tcl_Obj *name); static int NsfClassInfoMethodsMethod(Tcl_Interp *interp, NsfClass *cl, int withMethodtype, int withCallprotection, int withNomixins, int withIncontext, CONST char *pattern); static int NsfClassInfoMixinOfMethod(Tcl_Interp *interp, NsfClass *cl, int withClosure, int withScope, CONST char *patternString, NsfObject *patternObj); static int NsfClassInfoMixinclassesMethod(Tcl_Interp *interp, NsfClass *cl, int withClosure, int withGuards, CONST char *patternString, NsfObject *patternObj); @@ -287,7 +287,7 @@ static int NsfObjInfoLookupMethodMethod(Tcl_Interp *interp, NsfObject *obj, CONST char *name); static int NsfObjInfoLookupMethodsMethod(Tcl_Interp *interp, NsfObject *obj, int withMethodtype, int withCallprotection, int withApplication, int withNomixins, int withIncontext, CONST char *pattern); static int NsfObjInfoLookupSlotsMethod(Tcl_Interp *interp, NsfObject *obj, NsfClass *withType); -static int NsfObjInfoMethodMethod(Tcl_Interp *interp, NsfObject *obj, int infomethodsubcmd, CONST char *name); +static int NsfObjInfoMethodMethod(Tcl_Interp *interp, NsfObject *obj, int infomethodsubcmd, Tcl_Obj *name); static int NsfObjInfoMethodsMethod(Tcl_Interp *interp, NsfObject *obj, int withMethodtype, int withCallprotection, int withNomixins, int withIncontext, CONST char *pattern); static int NsfObjInfoMixinclassesMethod(Tcl_Interp *interp, NsfObject *obj, int withGuards, int withOrder, CONST char *patternString, NsfObject *patternObj); static int NsfObjInfoMixinguardMethod(Tcl_Interp *interp, NsfObject *obj, CONST char *mixin); @@ -637,7 +637,7 @@ return TCL_ERROR; } else { int infomethodsubcmd = (int )PTR2INT(pc.clientData[0]); - CONST char *name = (CONST char *)pc.clientData[1]; + Tcl_Obj *name = (Tcl_Obj *)pc.clientData[1]; ParseContextRelease(&pc); return NsfClassInfoMethodMethod(interp, cl, infomethodsubcmd, name); @@ -1811,7 +1811,7 @@ return TCL_ERROR; } else { int infomethodsubcmd = (int )PTR2INT(pc.clientData[0]); - CONST char *name = (CONST char *)pc.clientData[1]; + Tcl_Obj *name = (Tcl_Obj *)pc.clientData[1]; ParseContextRelease(&pc); return NsfObjInfoMethodMethod(interp, obj, infomethodsubcmd, name); @@ -2001,7 +2001,7 @@ }, {"::nsf::cmd::ClassInfo::method", NsfClassInfoMethodMethodStub, 2, { {"infomethodsubcmd", 0, 0, ConvertToInfomethodsubcmd}, - {"name", 0, 0, ConvertToString}} + {"name", 0, 0, ConvertToTclobj}} }, {"::nsf::cmd::ClassInfo::methods", NsfClassInfoMethodsMethodStub, 5, { {"-methodtype", 0, 1, ConvertToMethodtype}, @@ -2257,7 +2257,7 @@ }, {"::nsf::cmd::ObjectInfo::method", NsfObjInfoMethodMethodStub, 2, { {"infomethodsubcmd", 0, 0, ConvertToInfomethodsubcmd}, - {"name", 0, 0, ConvertToString}} + {"name", 0, 0, ConvertToTclobj}} }, {"::nsf::cmd::ObjectInfo::methods", NsfObjInfoMethodsMethodStub, 5, { {"-methodtype", 0, 1, ConvertToMethodtype},