Index: generic/gentclAPI.decls =================================================================== diff -u -r1f0231a5c7cbb8dfef4eaf78335c9ad571863660 -r04747ba752ca2b7a4f30586348e39ab04f190da9 --- generic/gentclAPI.decls (.../gentclAPI.decls) (revision 1f0231a5c7cbb8dfef4eaf78335c9ad571863660) +++ generic/gentclAPI.decls (.../gentclAPI.decls) (revision 04747ba752ca2b7a4f30586348e39ab04f190da9) @@ -65,7 +65,7 @@ {-argName "object" -required 1 -type object} {-argName "methodName" -required 1} {-argName "-per-object"} - {-argName "methodproperty" -required 1 -type "protected|static|slotobj"} + {-argName "methodproperty" -required 1 -type "protected|public|static|slotobj"} {-argName "value" -type tclobj} } xotclCmd my XOTclMyCmd { @@ -145,7 +145,7 @@ } objectMethod method XOTclOMethodMethod { {-argName "-inner-namespace"} - {-argName "-protected"} + {-argName "-public"} {-argName "name" -required 1 -type tclobj} {-argName "args" -required 1 -type tclobj} {-argName "body" -required 1 -type tclobj} @@ -214,7 +214,7 @@ classMethod method XOTclCMethodMethod { {-argName "-inner-namespace" -type switch} {-argName "-per-object" -type switch} - {-argName "-protected"} + {-argName "-public"} {-argName "name" -required 1 -type tclobj} {-argName "args" -required 1 -type tclobj} {-argName "body" -required 1 -type tclobj} @@ -234,7 +234,7 @@ {-argName "args" -type args} } # todo -protected for XOTclCInstForwardMethod -classMethod invalidateobjectparameter XOTclCInvalidateObjectParameterMethod { +classMethod __invalidateobjectparameter XOTclCInvalidateObjectParameterMethod { } classMethod recreate XOTclCRecreateMethod { {-argName "name" -required 1 -type tclobj} @@ -307,6 +307,7 @@ {-argName "object" -type object} {-argName "-which"} {-argName "-methodtype" -nrargs 1 -type "all|scripted|system|alias|forwarder|object|setter"} + {-argName "-callprotection" -nrargs 1 -type "all|protected|public" -default all} {-argName "-nomixins"} {-argName "-incontext"} {-argName "pattern" -required 0} @@ -315,6 +316,7 @@ infoObjectMethod methods XOTclObjInfoMethodsMethod { {-argName "object" -type object} {-argName "-methodtype" -nrargs 1 -type "all|scripted|system|alias|forwarder|object|setter"} + {-argName "-callprotection" -nrargs 1 -type "all|protected|public" -default public} {-argName "-nomixins"} {-argName "-incontext"} {-argName "pattern"} @@ -323,6 +325,7 @@ infoClassMethod methods XOTclClassInfoMethodsMethod { {-argName "object" -type class} {-argName "-methodtype" -nrargs 1 -type "all|scripted|system|alias|forwarder|object|setter"} + {-argName "-callprotection" -nrargs 1 -type "all|protected|public" -default public} {-argName "-nomixins"} {-argName "-incontext"} {-argName "pattern"} Index: generic/gentclAPI.tcl =================================================================== diff -u -ra294781fe7f397f503c769668e13c7d7d4967dfc -r04747ba752ca2b7a4f30586348e39ab04f190da9 --- generic/gentclAPI.tcl (.../gentclAPI.tcl) (revision a294781fe7f397f503c769668e13c7d7d4967dfc) +++ generic/gentclAPI.tcl (.../gentclAPI.tcl) (revision 04747ba752ca2b7a4f30586348e39ab04f190da9) @@ -61,6 +61,13 @@ set (-argName) $type } } + # this does not work, since initializer element is not constant. +# if {[info exists (-default)]} { +# puts stderr "default of $argName = '$(-default)'" +# set default ", Tcl_NewStringObj(\"$(-default)\",-1)" +# } else { +# set default "" +# } lappend l "{\"$argName\", $(-required), $(-nrargs), convertTo$converter}" } join $l ",\n " Index: generic/predefined.h =================================================================== diff -u -r1f0231a5c7cbb8dfef4eaf78335c9ad571863660 -r04747ba752ca2b7a4f30586348e39ab04f190da9 --- generic/predefined.h (.../predefined.h) (revision 1f0231a5c7cbb8dfef4eaf78335c9ad571863660) +++ generic/predefined.h (.../predefined.h) (revision 04747ba752ca2b7a4f30586348e39ab04f190da9) @@ -8,6 +8,10 @@ "::xotcl::alias Object [namespace tail $cmd] $cmd}\n" "foreach cmd [info command ::xotcl::cmd::Class::*] {\n" "::xotcl::alias Class [namespace tail $cmd] $cmd}\n" +"foreach cmd [list __next cleanup noinit residualargs] {\n" +"::xotcl::methodproperty Object $cmd protected 1}\n" +"foreach cmd [list recreate] {\n" +"::xotcl::methodproperty Class $cmd protected 1}\n" "::xotcl::methodproperty Object destroy static true\n" "::xotcl::methodproperty Class alloc static true\n" "::xotcl::methodproperty Class dealloc static true\n" @@ -22,13 +26,12 @@ "Object method defaultmethod {} {::xotcl::self}\n" "Object method objectparameter {} {;}\n" "Class method -per-object __unknown {name} {}\n" -"::xotcl::alias Object $cmd -objscope ::$cmd\n" -"Object method alias {-objscope:switch -protected:switch methodName cmd} {\n" +"Object method -public alias {-objscope:switch -protected:switch methodName cmd} {\n" "::xotcl::alias [self] $methodName \\\n" "{*}[expr {${objscope} ? \"-objscope\" : \"\"}] \\\n" "{*}[expr {${protected} ? \"-protected\" : \"\"}] \\\n" "$cmd}\n" -"Class method alias {-objscope:switch -per-object:switch -protected:switch methodName cmd} {\n" +"Class method -public alias {-objscope:switch -per-object:switch -protected:switch methodName cmd} {\n" "::xotcl::alias [self] $methodName \\\n" "{*}[expr {${objscope} ? \"-objscope\" : \"\"}] \\\n" "{*}[expr {${per-object} ? \"-per-object\" : \"\"}] \\\n" @@ -38,7 +41,7 @@ "Object create ::xotcl2::classInfo\n" "::xotcl::dispatch objectInfo -objscope ::eval {\n" ".alias is ::xotcl::is\n" -".method info {obj} {\n" +".method -public info {obj} {\n" "set methods [list]\n" "foreach name [::xotcl::cmd::ObjectInfo::methods [self]] {\n" "if {$name eq \"unknown\"} continue\n" @@ -87,12 +90,12 @@ "namespace export Object Class}\n" "::xotcl2::Class create ::xotcl::MetaSlot\n" "::xotcl::relation ::xotcl::MetaSlot superclass ::xotcl2::Class\n" -"::xotcl::MetaSlot method new args {\n" +"::xotcl::MetaSlot method -public new args {\n" "set slotobject [::xotcl::self callingobject]::slot\n" "if {![::xotcl::is $slotobject object]} {::xotcls::Object create $slotobject}\n" "eval next -childof $slotobject $args}\n" "::xotcl::MetaSlot create ::xotcl::Slot\n" -"::xotcl::MetaSlot invalidateobjectparameter\n" +"::xotcl::MetaSlot __invalidateobjectparameter\n" "proc ::xotcl::parametersFromSlots {obj} {\n" "set parameterdefinitions [list]\n" "set slots [::xotcl2::objectInfo slotobjects $obj]\n" @@ -150,7 +153,7 @@ "set default [::xotcl::dispatch $i -objscope ::eval subst $default]}\n" "::xotcl::setinstvar $i $att $default}}\n" "unset default}}\n" -"$class invalidateobjectparameter}\n" +"$class __invalidateobjectparameter}\n" "createBootstrapAttributeSlots ::xotcl::Slot {\n" "{name \"[namespace tail [::xotcl::self]]\"}\n" "{domain \"[lindex [regexp -inline {^(.*)::slot::[^:]+$} [::xotcl::self]] 1]\"}\n" @@ -164,13 +167,13 @@ "type}\n" "::xotcl::alias ::xotcl::Slot get ::xotcl::setinstvar\n" "::xotcl::alias ::xotcl::Slot assign ::xotcl::setinstvar\n" -"::xotcl::Slot method add {obj prop value {pos 0}} {\n" +"::xotcl::Slot method -public add {obj prop value {pos 0}} {\n" "if {![set .multivalued]} {\n" "error \"Property $prop of [set .domain]->$obj ist not multivalued\"}\n" "if {[$obj exists $prop]} {\n" "::xotcl::setinstvar $obj $prop [linsert [::xotcl::setinstvar $obj $prop] $pos $value]} else {\n" "::xotcl::setinstvar $obj $prop [list $value]}}\n" -"::xotcl::Slot method delete {-nocomplain:switch obj prop value} {\n" +"::xotcl::Slot method -public delete {-nocomplain:switch obj prop value} {\n" "set old [::xotcl::setinstvar $obj $prop]\n" "set p [lsearch -glob $old $value]\n" "if {$p>-1} {::xotcl::setinstvar $obj $prop [lreplace $old $p $p]} else {\n" @@ -182,15 +185,15 @@ "if {[string match __* $m]} continue\n" "lappend methods $m}\n" "error \"Method '$method' unknown for slot [::xotcl::self]; valid are: {[lsort $methods]]}\"}\n" -"::xotcl::Slot method destroy {} {\n" +"::xotcl::Slot method -public destroy {} {\n" "if {${.domain} ne \"\"} {\n" -"${.domain} invalidateobjectparameter}\n" +"${.domain} __invalidateobjectparameter}\n" "next}\n" "::xotcl::Slot method init {args} {\n" "if {${.domain} eq \"\"} {\n" "set .domain [::xotcl::self callingobject]}\n" "if {${.domain} ne \"\"} {\n" -"${.domain} invalidateobjectparameter\n" +"${.domain} __invalidateobjectparameter\n" "::xotcl::dispatch ${.domain} ::xotcl::cmd::Class::forward \\\n" "{*}[expr {${.per-object} ? \"-per-object\" : \"\"}] ${.name} \\\n" "${.manager} [list %1 [${.manager} defaultmethods]] %self \\\n" @@ -201,14 +204,14 @@ "{multivalued true}\n" "{elementtype ::xotcl2::Class}}\n" "::xotcl::relation ::xotcl::InfoSlot superclass ::xotcl::Slot\n" -"::xotcl::InfoSlot method get {obj prop} {\n" +"::xotcl::InfoSlot method -public get {obj prop} {\n" "$obj info $prop}\n" -"::xotcl::InfoSlot method add {obj prop value {pos 0}} {\n" +"::xotcl::InfoSlot method -public add {obj prop value {pos 0}} {\n" "if {![set .multivalued]} {\n" "error \"Property $prop of ${.domain}->$obj ist not multivalued\"}\n" "puts stderr \"adding infoslot: $obj $prop [linsert [$obj info $prop] $pos $value]\"\n" "$obj $prop [linsert [$obj info $prop] $pos $value]}\n" -"::xotcl::InfoSlot method delete {-nocomplain:switch obj prop value} {\n" +"::xotcl::InfoSlot method -public delete {-nocomplain:switch obj prop value} {\n" "puts stderr infoslot-delete-[self args]\n" "set old [$obj info $prop]\n" "if {[string first * $value] > -1 || [string first \\[ $value] > -1} {\n" @@ -229,9 +232,9 @@ "::xotcl::relation ::xotcl::InterceptorSlot superclass ::xotcl::InfoSlot\n" "::xotcl::alias ::xotcl::InterceptorSlot set ::xotcl::relation ;# for backwards compatibility\n" "::xotcl::alias ::xotcl::InterceptorSlot assign ::xotcl::relation\n" -"::xotcl::InterceptorSlot method get {obj -per-object:switch prop} {\n" +"::xotcl::InterceptorSlot method -public get {obj -per-object:switch prop} {\n" "::xotcl::relation $obj {*}[expr {${per-object} ? \"-per-object\" : \"\"}] $prop}\n" -"::xotcl::InterceptorSlot method add {obj -per-object:switch prop value {pos 0}} {\n" +"::xotcl::InterceptorSlot method -public add {obj -per-object:switch prop value {pos 0}} {\n" "if {![set .multivalued]} {\n" "error \"Property $prop of ${.domain}->$obj ist not multivalued\"}\n" "set perObject [expr {${per-object} ? \"-per-object\" : \"\"}]\n" @@ -249,7 +252,7 @@ "::xotcl::InterceptorSlot create ${os}::Object::slot::filter \\\n" "-elementtype \"\" -type relation}\n" "::xotcl::register_system_slots ::xotcl2\n" -"::xotcl::MetaSlot invalidateobjectparameter\n" +"::xotcl::MetaSlot __invalidateobjectparameter\n" "::xotcl::MetaSlot create ::xotcl::Attribute -superclass ::xotcl::Slot\n" "createBootstrapAttributeSlots ::xotcl::Attribute {\n" "{value_check once}\n" @@ -306,10 +309,10 @@ ".method check_multiple_values args {;}\n" ".method mk_type_checker args {return \"\"}}\n" "::xotcl2::Class create ::xotcl::Slot::Optimizer {\n" -".method proc args {::xotcl::next; .optimize}\n" +".method method args {::xotcl::next; .optimize}\n" ".method forward args {::xotcl::next; .optimize}\n" ".method init args {::xotcl::next; .optimize}\n" -".method optimize {} {\n" +".method -public optimize {} {\n" "if {[set .multivalued]} return\n" "if {[set .defaultmethods] ne {get assign}} return\n" "if {[.info callable -which assign] ne \"::xotcl::Slot alias assign ::xotcl::setinstvar\"} return\n" @@ -321,12 +324,12 @@ "{withclass ::xotcl2::Object}\n" "inobject}\n" "::xotcl::ScopedNew method init {} {\n" -".method new {-childof args} {\n" +".method -public new {-childof args} {\n" "::xotcl::instvar -object [::xotcl::self class] {inobject object} withclass\n" "if {![::xotcl::is $object object]} {\n" "$withclass create $object}\n" "eval ::xotcl::next -childof $object $args}}\n" -"::xotcl2::Object method contains {\n" +"::xotcl2::Object method -public contains {\n" "{-withnew:boolean true}\n" "-object\n" "{-class ::xotcl2::Object}\n" @@ -343,7 +346,7 @@ "namespace eval $object $cmds}}\n" "::xotcl2::Class forward slots %self contains \\\n" "-object {%::xotcl::dispatch [::xotcl::self] -objscope ::subst [::xotcl::self]::slot}\n" -"::xotcl2::Class method parameter arglist {\n" +"::xotcl2::Class method -public parameter arglist {\n" "if {![::xotcl::is [::xotcl::self]::slot object]} {\n" "::xotcl2::Object create [::xotcl::self]::slot}\n" "foreach arg $arglist {\n" @@ -386,7 +389,7 @@ "if {![info exists setter]} {set setter set}\n" "if {![info exists getter]} {set getter set}\n" "if {![info exists access]} {set access ::xotcl::my}\n" -"$cl method $name args \"\n" +"$cl method -public $name args \"\n" "if {\\[llength \\$args] == 0} {\n" "return \\[$access $getter $extra $name\\]} else {\n" "return \\[eval $access $setter $extra $name \\$args $defaultParam \\]}\"\n" @@ -457,15 +460,15 @@ "set newslot ${dest}::slot::[namespace tail $oldslot]\n" "if {[$oldslot domain] eq $origin} {$newslot domain $cl}\n" "if {[$oldslot manager] eq $oldslot} {$newslot manager $newslot}}}}}\n" -".method copy {obj dest} {\n" +".method -public copy {obj dest} {\n" "set .objLength [string length $obj]\n" "set .dest $dest\n" ".makeTargetList $obj\n" ".copyTargets}}\n" -"::xotcl2::Object method copy newName {\n" +"::xotcl2::Object method -public copy newName {\n" "if {[string compare [string trimleft $newName :] [string trimleft [::xotcl::self] :]]} {\n" "[::xotcl::CopyHandler new -volatile] copy [::xotcl::self] $newName}}\n" -"::xotcl2::Object method move newName {\n" +"::xotcl2::Object method -public move newName {\n" "if {[string trimleft $newName :] ne [string trimleft [::xotcl::self] :]} {\n" "if {$newName ne \"\"} {\n" ".copy $newName}\n" Index: generic/predefined.xotcl =================================================================== diff -u -r1f0231a5c7cbb8dfef4eaf78335c9ad571863660 -r04747ba752ca2b7a4f30586348e39ab04f190da9 --- generic/predefined.xotcl (.../predefined.xotcl) (revision 1f0231a5c7cbb8dfef4eaf78335c9ad571863660) +++ generic/predefined.xotcl (.../predefined.xotcl) (revision 04747ba752ca2b7a4f30586348e39ab04f190da9) @@ -18,7 +18,7 @@ foreach cmd [info command ::xotcl::cmd::Object::*] { ::xotcl::alias Object [namespace tail $cmd] $cmd } - + # provide some Tcl-commands as methods for ::xotcl2::Object #foreach cmd {array append eval incr lappend set subst unset trace} { # ::xotcl::alias Object $cmd -objscope ::$cmd @@ -29,6 +29,15 @@ ::xotcl::alias Class [namespace tail $cmd] $cmd } + # set a few aliases as protected + foreach cmd [list __next cleanup noinit residualargs] { + ::xotcl::methodproperty Object $cmd protected 1 + } + foreach cmd [list recreate] { + ::xotcl::methodproperty Class $cmd protected 1 + } + # TODO: info methods shows finally "slots" and "slot". Wanted? + # protect some methods against redefinition ::xotcl::methodproperty Object destroy static true ::xotcl::methodproperty Class alloc static true @@ -66,16 +75,16 @@ # Add an alias method. cmdName for XOTcl method can be added via # [... info method name ] - ::xotcl::alias Object $cmd -objscope ::$cmd + #::xotcl::alias Object $cmd -objscope ::$cmd - Object method alias {-objscope:switch -protected:switch methodName cmd} { + Object method -public alias {-objscope:switch -protected:switch methodName cmd} { ::xotcl::alias [self] $methodName \ {*}[expr {${objscope} ? "-objscope" : ""}] \ {*}[expr {${protected} ? "-protected" : ""}] \ $cmd } - Class method alias {-objscope:switch -per-object:switch -protected:switch methodName cmd} { + Class method -public alias {-objscope:switch -per-object:switch -protected:switch methodName cmd} { ::xotcl::alias [self] $methodName \ {*}[expr {${objscope} ? "-objscope" : ""}] \ {*}[expr {${per-object} ? "-per-object" : ""}] \ @@ -96,7 +105,7 @@ ::xotcl::dispatch objectInfo -objscope ::eval { .alias is ::xotcl::is - .method info {obj} { + .method -public info {obj} { set methods [list] foreach name [::xotcl::cmd::ObjectInfo::methods [self]] { if {$name eq "unknown"} continue @@ -193,7 +202,7 @@ ::xotcl2::Class create ::xotcl::MetaSlot ::xotcl::relation ::xotcl::MetaSlot superclass ::xotcl2::Class -::xotcl::MetaSlot method new args { +::xotcl::MetaSlot method -public new args { set slotobject [::xotcl::self callingobject]::slot if {![::xotcl::is $slotobject object]} {::xotcls::Object create $slotobject} eval next -childof $slotobject $args @@ -202,7 +211,7 @@ ::xotcl::MetaSlot create ::xotcl::Slot # We have no working objectparameter yet. So invalidate MetaSlot to # avoid caching. -::xotcl::MetaSlot invalidateobjectparameter +::xotcl::MetaSlot __invalidateobjectparameter #foreach o {::xotcl::MetaSlot ::xotcl2::Slot} { # foreach r {object class metaclass} { @@ -313,8 +322,8 @@ unset default } } - #puts stderr "Bootstrapslot for $class calls invalidateobjectparameter" - $class invalidateobjectparameter + #puts stderr "Bootstrapslot for $class calls __invalidateobjectparameter" + $class __invalidateobjectparameter } @@ -341,7 +350,7 @@ ::xotcl::alias ::xotcl::Slot get ::xotcl::setinstvar ::xotcl::alias ::xotcl::Slot assign ::xotcl::setinstvar -::xotcl::Slot method add {obj prop value {pos 0}} { +::xotcl::Slot method -public add {obj prop value {pos 0}} { if {![set .multivalued]} { error "Property $prop of [set .domain]->$obj ist not multivalued" } @@ -350,9 +359,8 @@ } else { ::xotcl::setinstvar $obj $prop [list $value] } - #[set .domain] invalidateobjectparameter ;# TODO maybe not needed here } -::xotcl::Slot method delete {-nocomplain:switch obj prop value} { +::xotcl::Slot method -public delete {-nocomplain:switch obj prop value} { set old [::xotcl::setinstvar $obj $prop] set p [lsearch -glob $old $value] if {$p>-1} {::xotcl::setinstvar $obj $prop [lreplace $old $p $p]} else { @@ -370,9 +378,9 @@ error "Method '$method' unknown for slot [::xotcl::self]; valid are: {[lsort $methods]]}" } -::xotcl::Slot method destroy {} { +::xotcl::Slot method -public destroy {} { if {${.domain} ne ""} { - ${.domain} invalidateobjectparameter + ${.domain} __invalidateobjectparameter } next } @@ -382,7 +390,7 @@ set .domain [::xotcl::self callingobject] } if {${.domain} ne ""} { - ${.domain} invalidateobjectparameter + ${.domain} __invalidateobjectparameter # since the domain object might be xotcl1 or xotcl2, use dispatch ::xotcl::dispatch ${.domain} ::xotcl::cmd::Class::forward \ @@ -403,17 +411,17 @@ {elementtype ::xotcl2::Class} } ::xotcl::relation ::xotcl::InfoSlot superclass ::xotcl::Slot -::xotcl::InfoSlot method get {obj prop} { +::xotcl::InfoSlot method -public get {obj prop} { $obj info $prop } -::xotcl::InfoSlot method add {obj prop value {pos 0}} { +::xotcl::InfoSlot method -public add {obj prop value {pos 0}} { if {![set .multivalued]} { error "Property $prop of ${.domain}->$obj ist not multivalued" } puts stderr "adding infoslot: $obj $prop [linsert [$obj info $prop] $pos $value]" $obj $prop [linsert [$obj info $prop] $pos $value] } -::xotcl::InfoSlot method delete {-nocomplain:switch obj prop value} { +::xotcl::InfoSlot method -public delete {-nocomplain:switch obj prop value} { puts stderr infoslot-delete-[self args] set old [$obj info $prop] if {[string first * $value] > -1 || [string first \[ $value] > -1} { @@ -451,10 +459,10 @@ ::xotcl::alias ::xotcl::InterceptorSlot set ::xotcl::relation ;# for backwards compatibility ::xotcl::alias ::xotcl::InterceptorSlot assign ::xotcl::relation -::xotcl::InterceptorSlot method get {obj -per-object:switch prop} { +::xotcl::InterceptorSlot method -public get {obj -per-object:switch prop} { ::xotcl::relation $obj {*}[expr {${per-object} ? "-per-object" : ""}] $prop } -::xotcl::InterceptorSlot method add {obj -per-object:switch prop value {pos 0}} { +::xotcl::InterceptorSlot method -public add {obj -per-object:switch prop value {pos 0}} { if {![set .multivalued]} { error "Property $prop of ${.domain}->$obj ist not multivalued" } @@ -489,7 +497,7 @@ ############################################ # Attribute slots ############################################ -::xotcl::MetaSlot invalidateobjectparameter +::xotcl::MetaSlot __invalidateobjectparameter ::xotcl::MetaSlot create ::xotcl::Attribute -superclass ::xotcl::Slot createBootstrapAttributeSlots ::xotcl::Attribute { @@ -588,12 +596,10 @@ } # mixin class for optimizing slots ::xotcl2::Class create ::xotcl::Slot::Optimizer { - .method proc args {::xotcl::next; .optimize} + .method method args {::xotcl::next; .optimize} .method forward args {::xotcl::next; .optimize} .method init args {::xotcl::next; .optimize} - .method optimize {} { - #puts stderr "slot optimizer for ${.domain} calls invalidateobjectparameter" - #${.domain} invalidateobjectparameter + .method -public optimize {} { if {[set .multivalued]} return if {[set .defaultmethods] ne {get assign}} return #puts stderr assign=[.info callable -which assign] @@ -618,7 +624,7 @@ } ::xotcl::ScopedNew method init {} { - .method new {-childof args} { + .method -public new {-childof args} { ::xotcl::instvar -object [::xotcl::self class] {inobject object} withclass if {![::xotcl::is $object object]} { $withclass create $object @@ -632,7 +638,7 @@ # nested object structures. Optionally, creating new objects # in the specified scope can be turned off. # -::xotcl2::Object method contains { +::xotcl2::Object method -public contains { {-withnew:boolean true} -object {-class ::xotcl2::Object} @@ -658,7 +664,7 @@ # Define method "parameter" for backward # compatibility and convenience ############################################ -::xotcl2::Class method parameter arglist { +::xotcl2::Class method -public parameter arglist { if {![::xotcl::is [::xotcl::self]::slot object]} { ::xotcl2::Object create [::xotcl::self]::slot } @@ -715,7 +721,7 @@ if {![info exists setter]} {set setter set} if {![info exists getter]} {set getter set} if {![info exists access]} {set access ::xotcl::my} - $cl method $name args " + $cl method -public $name args " if {\[llength \$args] == 0} { return \[$access $getter $extra $name\] } else { @@ -853,7 +859,7 @@ } } - .method copy {obj dest} { + .method -public copy {obj dest} { #puts stderr "[::xotcl::self] copy <$obj> <$dest>" set .objLength [string length $obj] set .dest $dest @@ -862,13 +868,13 @@ } } -::xotcl2::Object method copy newName { +::xotcl2::Object method -public copy newName { if {[string compare [string trimleft $newName :] [string trimleft [::xotcl::self] :]]} { [::xotcl::CopyHandler new -volatile] copy [::xotcl::self] $newName } } -::xotcl2::Object method move newName { +::xotcl2::Object method -public move newName { if {[string trimleft $newName :] ne [string trimleft [::xotcl::self] :]} { if {$newName ne ""} { .copy $newName Index: generic/tclAPI.h =================================================================== diff -u -r1f0231a5c7cbb8dfef4eaf78335c9ad571863660 -r04747ba752ca2b7a4f30586348e39ab04f190da9 --- generic/tclAPI.h (.../tclAPI.h) (revision 1f0231a5c7cbb8dfef4eaf78335c9ad571863660) +++ generic/tclAPI.h (.../tclAPI.h) (revision 04747ba752ca2b7a4f30586348e39ab04f190da9) @@ -17,6 +17,15 @@ } enum MethodtypeIdx {MethodtypeNULL, MethodtypeAllIdx, MethodtypeScriptedIdx, MethodtypeSystemIdx, MethodtypeAliasIdx, MethodtypeForwarderIdx, MethodtypeObjectIdx, MethodtypeSetterIdx}; +static int convertToCallprotection(Tcl_Interp *interp, Tcl_Obj *objPtr, XOTclParam CONST *pPtr, ClientData *clientData) { + int index, result; + static CONST char *opts[] = {"all", "protected", "public", NULL}; + result = Tcl_GetIndexFromObj(interp, objPtr, opts, "-callprotection", 0, &index); + *clientData = (ClientData) index + 1; + return result; +} +enum CallprotectionIdx {CallprotectionNULL, CallprotectionAllIdx, CallprotectionProtectedIdx, CallprotectionPublicIdx}; + static int convertToConfigureoption(Tcl_Interp *interp, Tcl_Obj *objPtr, XOTclParam CONST *pPtr, ClientData *clientData) { int index, result; static CONST char *opts[] = {"filter", "softrecreate", "cacheinterface", NULL}; @@ -46,12 +55,12 @@ static int convertToMethodproperty(Tcl_Interp *interp, Tcl_Obj *objPtr, XOTclParam CONST *pPtr, ClientData *clientData) { int index, result; - static CONST char *opts[] = {"protected", "static", "slotobj", NULL}; + static CONST char *opts[] = {"protected", "public", "static", "slotobj", NULL}; result = Tcl_GetIndexFromObj(interp, objPtr, opts, "methodproperty", 0, &index); *clientData = (ClientData) index + 1; return result; } -enum MethodpropertyIdx {MethodpropertyNULL, MethodpropertyProtectedIdx, MethodpropertyStaticIdx, MethodpropertySlotobjIdx}; +enum MethodpropertyIdx {MethodpropertyNULL, MethodpropertyProtectedIdx, MethodpropertyPublicIdx, MethodpropertyStaticIdx, MethodpropertySlotobjIdx}; static int convertToRelationtype(Tcl_Interp *interp, Tcl_Obj *objPtr, XOTclParam CONST *pPtr, ClientData *clientData) { int index, result; @@ -184,7 +193,7 @@ static int XOTclCForwardMethod(Tcl_Interp *interp, XOTclClass *cl, int withPer_object, Tcl_Obj *name, Tcl_Obj *withDefault, int withEarlybinding, Tcl_Obj *withMethodprefix, int withObjscope, Tcl_Obj *withOnerror, int withVerbose, Tcl_Obj *target, int nobjc, Tcl_Obj *CONST nobjv[]); static int XOTclCInvalidateObjectParameterMethod(Tcl_Interp *interp, XOTclClass *cl); static int XOTclCInvariantsMethod(Tcl_Interp *interp, XOTclClass *cl, Tcl_Obj *invariantlist); -static int XOTclCMethodMethod(Tcl_Interp *interp, XOTclClass *cl, int withInner_namespace, int withPer_object, int withProtected, Tcl_Obj *name, Tcl_Obj *args, Tcl_Obj *body, Tcl_Obj *withPrecondition, Tcl_Obj *withPostcondition); +static int XOTclCMethodMethod(Tcl_Interp *interp, XOTclClass *cl, 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 XOTclCMixinGuardMethod(Tcl_Interp *interp, XOTclClass *cl, int withPer_object, char *mixin, Tcl_Obj *guard); static int XOTclCNewMethod(Tcl_Interp *interp, XOTclClass *cl, XOTclObject *withChildof, int nobjc, Tcl_Obj *CONST nobjv[]); static int XOTclCRecreateMethod(Tcl_Interp *interp, XOTclClass *cl, Tcl_Obj *name, int objc, Tcl_Obj *CONST objv[]); @@ -197,15 +206,15 @@ static int XOTclClassInfoInstmixinofMethod(Tcl_Interp *interp, XOTclClass *class, int withClosure, char *patternString, XOTclObject *patternObj); static int XOTclClassInfoInvarMethod(Tcl_Interp *interp, XOTclClass *class); static int XOTclClassInfoMethodMethod(Tcl_Interp *interp, XOTclClass *class, int infomethodsubcmd, char *name); -static int XOTclClassInfoMethodsMethod(Tcl_Interp *interp, XOTclClass *object, int withMethodtype, int withNomixins, int withIncontext, char *pattern); +static int XOTclClassInfoMethodsMethod(Tcl_Interp *interp, XOTclClass *object, int withMethodtype, int withCallprotection, int withNomixins, int withIncontext, char *pattern); static int XOTclClassInfoMixinMethod(Tcl_Interp *interp, XOTclClass *class, int withClosure, int withGuards, char *patternString, XOTclObject *patternObj); static int XOTclClassInfoMixinguardMethod(Tcl_Interp *interp, XOTclClass *class, char *mixin); static int XOTclClassInfoMixinofMethod(Tcl_Interp *interp, XOTclClass *class, int withClosure, char *patternString, XOTclObject *patternObj); static int XOTclClassInfoParameterMethod(Tcl_Interp *interp, XOTclClass *class); static int XOTclClassInfoSlotsMethod(Tcl_Interp *interp, XOTclClass *class); static int XOTclClassInfoSubclassMethod(Tcl_Interp *interp, XOTclClass *class, int withClosure, char *patternString, XOTclObject *patternObj); static int XOTclClassInfoSuperclassMethod(Tcl_Interp *interp, XOTclClass *class, int withClosure, Tcl_Obj *pattern); -static int XOTclObjInfoCallableMethod(Tcl_Interp *interp, XOTclObject *object, int withWhich, int withMethodtype, int withNomixins, int withIncontext, char *pattern); +static int XOTclObjInfoCallableMethod(Tcl_Interp *interp, XOTclObject *object, int withWhich, int withMethodtype, int withCallprotection, int withNomixins, int withIncontext, char *pattern); static int XOTclObjInfoCheckMethod(Tcl_Interp *interp, XOTclObject *object); static int XOTclObjInfoChildrenMethod(Tcl_Interp *interp, XOTclObject *object, char *pattern); static int XOTclObjInfoClassMethod(Tcl_Interp *interp, XOTclObject *object); @@ -215,7 +224,7 @@ static int XOTclObjInfoHasnamespaceMethod(Tcl_Interp *interp, XOTclObject *object); static int XOTclObjInfoInvarMethod(Tcl_Interp *interp, XOTclObject *object); static int XOTclObjInfoMethodMethod(Tcl_Interp *interp, XOTclObject *object, int infomethodsubcmd, char *name); -static int XOTclObjInfoMethodsMethod(Tcl_Interp *interp, XOTclObject *object, int withMethodtype, int withNomixins, int withIncontext, char *pattern); +static int XOTclObjInfoMethodsMethod(Tcl_Interp *interp, XOTclObject *object, int withMethodtype, int withCallprotection, int withNomixins, int withIncontext, char *pattern); static int XOTclObjInfoMixinMethod(Tcl_Interp *interp, XOTclObject *object, int withGuards, int withOrder, char *patternString, XOTclObject *patternObj); static int XOTclObjInfoMixinguardMethod(Tcl_Interp *interp, XOTclObject *object, char *mixin); static int XOTclObjInfoParentMethod(Tcl_Interp *interp, XOTclObject *object); @@ -233,7 +242,7 @@ static int XOTclOForwardMethod(Tcl_Interp *interp, XOTclObject *obj, Tcl_Obj *method, Tcl_Obj *withDefault, int withEarlybinding, Tcl_Obj *withMethodprefix, int withObjscope, Tcl_Obj *withOnerror, int withVerbose, Tcl_Obj *target, int nobjc, Tcl_Obj *CONST nobjv[]); static int XOTclOInstVarMethod(Tcl_Interp *interp, XOTclObject *obj, int objc, Tcl_Obj *CONST objv[]); static int XOTclOInvariantsMethod(Tcl_Interp *interp, XOTclObject *obj, Tcl_Obj *invariantlist); -static int XOTclOMethodMethod(Tcl_Interp *interp, XOTclObject *obj, int withInner_namespace, int withProtected, Tcl_Obj *name, Tcl_Obj *args, Tcl_Obj *body, Tcl_Obj *withPrecondition, Tcl_Obj *withPostcondition); +static int XOTclOMethodMethod(Tcl_Interp *interp, XOTclObject *obj, int withInner_namespace, int withPublic, Tcl_Obj *name, Tcl_Obj *args, Tcl_Obj *body, Tcl_Obj *withPrecondition, Tcl_Obj *withPostcondition); static int XOTclOMixinGuardMethod(Tcl_Interp *interp, XOTclObject *obj, char *mixin, Tcl_Obj *guard); static int XOTclONextMethod(Tcl_Interp *interp, XOTclObject *obj, int objc, Tcl_Obj *CONST objv[]); static int XOTclONoinitMethod(Tcl_Interp *interp, XOTclObject *obj); @@ -548,15 +557,15 @@ } else { int withInner_namespace = (int )pc.clientData[0]; int withPer_object = (int )pc.clientData[1]; - int withProtected = (int )pc.clientData[2]; + int withPublic = (int )pc.clientData[2]; Tcl_Obj *name = (Tcl_Obj *)pc.clientData[3]; Tcl_Obj *args = (Tcl_Obj *)pc.clientData[4]; Tcl_Obj *body = (Tcl_Obj *)pc.clientData[5]; Tcl_Obj *withPrecondition = (Tcl_Obj *)pc.clientData[6]; Tcl_Obj *withPostcondition = (Tcl_Obj *)pc.clientData[7]; parseContextRelease(&pc); - return XOTclCMethodMethod(interp, cl, withInner_namespace, withPer_object, withProtected, name, args, body, withPrecondition, withPostcondition); + return XOTclCMethodMethod(interp, cl, withInner_namespace, withPer_object, withPublic, name, args, body, withPrecondition, withPostcondition); } } @@ -836,12 +845,13 @@ } else { XOTclClass *object = (XOTclClass *)pc.clientData[0]; int withMethodtype = (int )pc.clientData[1]; - int withNomixins = (int )pc.clientData[2]; - int withIncontext = (int )pc.clientData[3]; - char *pattern = (char *)pc.clientData[4]; + int withCallprotection = (int )pc.clientData[2]; + int withNomixins = (int )pc.clientData[3]; + int withIncontext = (int )pc.clientData[4]; + char *pattern = (char *)pc.clientData[5]; parseContextRelease(&pc); - return XOTclClassInfoMethodsMethod(interp, object, withMethodtype, withNomixins, withIncontext, pattern); + return XOTclClassInfoMethodsMethod(interp, object, withMethodtype, withCallprotection, withNomixins, withIncontext, pattern); } } @@ -1037,12 +1047,13 @@ XOTclObject *object = (XOTclObject *)pc.clientData[0]; int withWhich = (int )pc.clientData[1]; int withMethodtype = (int )pc.clientData[2]; - int withNomixins = (int )pc.clientData[3]; - int withIncontext = (int )pc.clientData[4]; - char *pattern = (char *)pc.clientData[5]; + int withCallprotection = (int )pc.clientData[3]; + int withNomixins = (int )pc.clientData[4]; + int withIncontext = (int )pc.clientData[5]; + char *pattern = (char *)pc.clientData[6]; parseContextRelease(&pc); - return XOTclObjInfoCallableMethod(interp, object, withWhich, withMethodtype, withNomixins, withIncontext, pattern); + return XOTclObjInfoCallableMethod(interp, object, withWhich, withMethodtype, withCallprotection, withNomixins, withIncontext, pattern); } } @@ -1230,12 +1241,13 @@ } else { XOTclObject *object = (XOTclObject *)pc.clientData[0]; int withMethodtype = (int )pc.clientData[1]; - int withNomixins = (int )pc.clientData[2]; - int withIncontext = (int )pc.clientData[3]; - char *pattern = (char *)pc.clientData[4]; + int withCallprotection = (int )pc.clientData[2]; + int withNomixins = (int )pc.clientData[3]; + int withIncontext = (int )pc.clientData[4]; + char *pattern = (char *)pc.clientData[5]; parseContextRelease(&pc); - return XOTclObjInfoMethodsMethod(interp, object, withMethodtype, withNomixins, withIncontext, pattern); + return XOTclObjInfoMethodsMethod(interp, object, withMethodtype, withCallprotection, withNomixins, withIncontext, pattern); } } @@ -1583,15 +1595,15 @@ return TCL_ERROR; } else { int withInner_namespace = (int )pc.clientData[0]; - int withProtected = (int )pc.clientData[1]; + int withPublic = (int )pc.clientData[1]; Tcl_Obj *name = (Tcl_Obj *)pc.clientData[2]; Tcl_Obj *args = (Tcl_Obj *)pc.clientData[3]; Tcl_Obj *body = (Tcl_Obj *)pc.clientData[4]; Tcl_Obj *withPrecondition = (Tcl_Obj *)pc.clientData[5]; Tcl_Obj *withPostcondition = (Tcl_Obj *)pc.clientData[6]; parseContextRelease(&pc); - return XOTclOMethodMethod(interp, obj, withInner_namespace, withProtected, name, args, body, withPrecondition, withPostcondition); + return XOTclOMethodMethod(interp, obj, withInner_namespace, withPublic, name, args, body, withPrecondition, withPostcondition); } } @@ -2127,7 +2139,7 @@ {"target", 0, 0, convertToTclobj}, {"args", 0, 0, convertToNothing}} }, -{"::xotcl::cmd::Class::invalidateobjectparameter", XOTclCInvalidateObjectParameterMethodStub, 0, { +{"::xotcl::cmd::Class::__invalidateobjectparameter", XOTclCInvalidateObjectParameterMethodStub, 0, { } }, {"::xotcl::cmd::Class::instinvar", XOTclCInvariantsMethodStub, 1, { @@ -2136,7 +2148,7 @@ {"::xotcl::cmd::Class::method", XOTclCMethodMethodStub, 8, { {"-inner-namespace", 0, 0, convertToBoolean}, {"-per-object", 0, 0, convertToBoolean}, - {"-protected", 0, 0, convertToString}, + {"-public", 0, 0, convertToString}, {"name", 1, 0, convertToTclobj}, {"args", 1, 0, convertToTclobj}, {"body", 1, 0, convertToTclobj}, @@ -2196,9 +2208,10 @@ {"infomethodsubcmd", 0, 0, convertToInfomethodsubcmd}, {"name", 0, 0, convertToString}} }, -{"::xotcl::cmd::ClassInfo::methods", XOTclClassInfoMethodsMethodStub, 5, { +{"::xotcl::cmd::ClassInfo::methods", XOTclClassInfoMethodsMethodStub, 6, { {"object", 0, 0, convertToClass}, {"-methodtype", 0, 1, convertToMethodtype}, + {"-callprotection", 0, 1, convertToCallprotection}, {"-nomixins", 0, 0, convertToString}, {"-incontext", 0, 0, convertToString}, {"pattern", 0, 0, convertToString}} @@ -2234,10 +2247,11 @@ {"-closure", 0, 0, convertToString}, {"pattern", 0, 0, convertToTclobj}} }, -{"::xotcl::cmd::ObjectInfo::callable", XOTclObjInfoCallableMethodStub, 6, { +{"::xotcl::cmd::ObjectInfo::callable", XOTclObjInfoCallableMethodStub, 7, { {"object", 0, 0, convertToObject}, {"-which", 0, 0, convertToString}, {"-methodtype", 0, 1, convertToMethodtype}, + {"-callprotection", 0, 1, convertToCallprotection}, {"-nomixins", 0, 0, convertToString}, {"-incontext", 0, 0, convertToString}, {"pattern", 0, 0, convertToString}} @@ -2278,9 +2292,10 @@ {"infomethodsubcmd", 0, 0, convertToInfomethodsubcmd}, {"name", 0, 0, convertToString}} }, -{"::xotcl::cmd::ObjectInfo::methods", XOTclObjInfoMethodsMethodStub, 5, { +{"::xotcl::cmd::ObjectInfo::methods", XOTclObjInfoMethodsMethodStub, 6, { {"object", 0, 0, convertToObject}, {"-methodtype", 0, 1, convertToMethodtype}, + {"-callprotection", 0, 1, convertToCallprotection}, {"-nomixins", 0, 0, convertToString}, {"-incontext", 0, 0, convertToString}, {"pattern", 0, 0, convertToString}} @@ -2357,7 +2372,7 @@ }, {"::xotcl::cmd::Object::method", XOTclOMethodMethodStub, 7, { {"-inner-namespace", 0, 0, convertToString}, - {"-protected", 0, 0, convertToString}, + {"-public", 0, 0, convertToString}, {"name", 1, 0, convertToTclobj}, {"args", 1, 0, convertToTclobj}, {"body", 1, 0, convertToTclobj}, Index: generic/xotcl.c =================================================================== diff -u -r503b512a56d3e0a64153cbc19dc61c8a819b87b8 -r04747ba752ca2b7a4f30586348e39ab04f190da9 --- generic/xotcl.c (.../xotcl.c) (revision 503b512a56d3e0a64153cbc19dc61c8a819b87b8) +++ generic/xotcl.c (.../xotcl.c) (revision 04747ba752ca2b7a4f30586348e39ab04f190da9) @@ -5774,16 +5774,17 @@ we call as well the unknown method */ if ((Tcl_Command_flags(cmd) & XOTCL_CMD_PROTECTED_METHOD) && - (flags & XOTCL_CM_NO_UNKNOWN) == 0) { + (flags & (XOTCL_CM_NO_UNKNOWN|XOTCL_CM_NO_PROTECT)) == 0) { XOTclObject *o, *lastSelf = GetSelfObj(interp); /* we do not want to rely on clientData, so get obj from cmdObj */ GetObjectFromObj(interp, cmdObj, &o); - /*fprintf(stderr, "+++ %s is protected, therefore maybe unknown %p %s self=%p o=%p cd %p\n", - methodName, cmdObj, ObjStr(cmdObj), lastSelf, o, clientData);*/ if (o != lastSelf) { /*fprintf(stderr, "+++ protected method %s is not invoked\n", methodName);*/ unknown = 1; + fprintf(stderr, "+++ %s is protected, therefore maybe unknown %p %s lastself=%p o=%p cd %p flags = %.6x\n", + methodName, cmdObj, ObjStr(cmdObj), lastSelf, o, clientData, flags); + tcl85showStack(interp); } } @@ -6310,7 +6311,7 @@ static int MakeProc(Tcl_Namespace *nsPtr, XOTclAssertionStore *aStore, Tcl_Interp *interp, Tcl_Obj *nameObj, Tcl_Obj *args, Tcl_Obj *body, Tcl_Obj *precondition, - Tcl_Obj *postcondition, XOTclObject *obj, int withProtected, int clsns) { + Tcl_Obj *postcondition, XOTclObject *obj, int withPublic, int clsns) { TclCallFrame frame, *framePtr = &frame; char *procName = ObjStr(nameObj); XOTclParsedParam parsedParam; @@ -6382,7 +6383,7 @@ } ParamDefsStore(interp, (Tcl_Command)procPtr->cmdPtr, parsedParam.paramDefs); - if (withProtected) { + if (!withPublic) { Tcl_Command_flags((Tcl_Command)procPtr->cmdPtr) |= XOTCL_CMD_PROTECTED_METHOD; } } @@ -6406,7 +6407,7 @@ MakeMethod(Tcl_Interp *interp, XOTclObject *obj, XOTclClass *cl, Tcl_Obj *nameObj, Tcl_Obj *args, Tcl_Obj *body, Tcl_Obj *precondition, Tcl_Obj *postcondition, - int withProtected, int clsns) { + int withPublic, int clsns) { char *argsStr = ObjStr(args), *bodyStr = ObjStr(body), *nameStr = ObjStr(nameObj); int result; @@ -6439,7 +6440,7 @@ } result = MakeProc(cl ? cl->nsPtr : obj->nsPtr, aStore, interp, nameObj, args, body, precondition, postcondition, - obj, withProtected, clsns); + obj, withPublic, clsns); } if (cl) { @@ -7858,7 +7859,9 @@ /* * dispatch "cleanup" */ - result = callMethod((ClientData) newObj, interp, XOTclGlobalObjects[XOTE_CLEANUP], 2, 0, 0); + result = callMethod((ClientData) newObj, interp, + XOTclGlobalObjects[XOTE_CLEANUP], + 2, 0, XOTCL_CM_NO_PROTECT); } return result; } @@ -7904,7 +7907,7 @@ INCR_REF_COUNT(resultObj); Tcl_ListObjGetElements(interp, resultObj, &nobjc, &nobjv); result = callMethod((ClientData) obj, interp, XOTclGlobalObjects[XOTE_INIT], - nobjc+2, nobjv, 0); + nobjc+2, nobjv, XOTCL_CM_NO_PROTECT); obj->flags |= XOTCL_INIT_CALLED; DECR_REF_COUNT(resultObj); } @@ -8641,7 +8644,7 @@ if (tcd->verbose) { Tcl_Obj *cmd = Tcl_NewListObj(objc, objv); - fprintf(stderr, "calling %s\n", ObjStr(cmd)); + fprintf(stderr, "forwarder calls '%s'\n", ObjStr(cmd)); DECR_REF_COUNT(cmd); } if (tcd->objscope) { @@ -9132,7 +9135,7 @@ /* call recreate --> initialization */ result = callMethod((ClientData) cl, interp, - XOTclGlobalObjects[XOTE_RECREATE], objc+1, tov+1, 0); + XOTclGlobalObjects[XOTE_RECREATE], objc+1, tov+1, XOTCL_CM_NO_PROTECT); if (result != TCL_OK) goto create_method_exit; @@ -9813,6 +9816,21 @@ } static int +ProtectionMatches(Tcl_Interp *interp, int withCallprotection, Tcl_Command cmd) { + int result, isProtected = Tcl_Command_flags(cmd) & XOTCL_CMD_PROTECTED_METHOD; + if (withCallprotection == CallprotectionNULL) { + withCallprotection = CallprotectionPublicIdx; + } + switch (withCallprotection) { + case CallprotectionAllIdx: result = 1; break; + case CallprotectionPublicIdx: result = (isProtected == 0); break; + case CallprotectionProtectedIdx: result = (isProtected == 1); break; + default: result = 1; + } + return result; +} + +static int MethodTypeMatches(Tcl_Interp *interp, int methodType, Tcl_Command cmd, XOTclObject *object, char *key, int withPer_object) { Tcl_Command importedCmd; @@ -9850,7 +9868,8 @@ } static int -ListMethodKeys(Tcl_Interp *interp, Tcl_HashTable *table, char *pattern, int methodType, +ListMethodKeys(Tcl_Interp *interp, Tcl_HashTable *table, char *pattern, + int methodType, int withCallprotection, Tcl_HashTable *dups, XOTclObject *object, int withPer_object) { Tcl_HashSearch hSrch; Tcl_HashEntry *hPtr, *duphPtr; @@ -9866,7 +9885,9 @@ if (hPtr) { key = Tcl_GetHashKey(table, hPtr); cmd = (Tcl_Command)Tcl_GetHashValue(hPtr); - if (MethodTypeMatches(interp, methodType, cmd, object, key, withPer_object)) { + + if (ProtectionMatches(interp, withCallprotection, cmd) + && MethodTypeMatches(interp, methodType, cmd, object, key, withPer_object)) { if (dups) { duphPtr = Tcl_CreateHashEntry(dups, key, &new); if (new) { @@ -9875,7 +9896,7 @@ } else { Tcl_AppendElement(interp, key); } - } + } } return TCL_OK; @@ -9887,17 +9908,14 @@ cmd = (Tcl_Command)Tcl_GetHashValue(hPtr); if (pattern && !Tcl_StringMatch(key, pattern)) continue; - if (!MethodTypeMatches(interp, methodType, cmd, object, key, withPer_object)) continue; + if (!ProtectionMatches(interp, withCallprotection, cmd) + || !MethodTypeMatches(interp, methodType, cmd, object, key, withPer_object) + ) continue; if (dups) { duphPtr = Tcl_CreateHashEntry(dups, key, &new); if (!new) continue; } - - if (((Command *) cmd)->flags & XOTCL_CMD_PROTECTED_METHOD) { - /*fprintf(stderr, "--- dont list protected name '%s'\n", key);*/ - continue; - } Tcl_AppendElement(interp, key); } } @@ -9968,12 +9986,12 @@ } return XOTclVarErrMsg(interp, "'", pattern, "' is not a forwarder", (char *) NULL); } - return ListMethodKeys(interp, table, pattern, XOTCL_METHODTYPE_FORWARDER, NULL, NULL, 0); + return ListMethodKeys(interp, table, pattern, XOTCL_METHODTYPE_FORWARDER, CallprotectionAllIdx, NULL, NULL, 0); } static int ListDefinedMethods(Tcl_Interp *interp, XOTclObject *object, char *pattern, - int withPer_object, int methodType, + int withPer_object, int methodType, int withCallproctection, int noMixins, int inContext) { Tcl_HashTable *cmdTable; @@ -9982,13 +10000,14 @@ } else { cmdTable = object->nsPtr ? Tcl_Namespace_cmdTable(object->nsPtr) : NULL; } - ListMethodKeys(interp, cmdTable, pattern, methodType, NULL, object, withPer_object); + ListMethodKeys(interp, cmdTable, pattern, methodType, withCallproctection, + NULL, object, withPer_object); return TCL_OK; } static int ListCallableMethods(Tcl_Interp *interp, XOTclObject *object, char *pattern, - int withPer_object, int methodType, + int withPer_object, int methodType, int withCallprotection, int noMixins, int inContext) { XOTclClasses *pl; Tcl_HashTable *cmdTable, dupsTable, *dups = &dupsTable; @@ -9999,11 +10018,15 @@ * we wait, until the we decided about "info methods defined" * vs. "info method search" vs. "info defined" etc. */ + if (withCallprotection == CallprotectionNULL) { + withCallprotection = CallprotectionAllIdx; + } Tcl_InitHashTable(dups, TCL_STRING_KEYS); if (object->nsPtr) { cmdTable = Tcl_Namespace_cmdTable(object->nsPtr); - ListMethodKeys(interp, cmdTable, pattern, methodType, dups, object, withPer_object); + ListMethodKeys(interp, cmdTable, pattern, methodType, withCallprotection, + dups, object, withPer_object); } if (!noMixins) { @@ -10022,7 +10045,8 @@ } if (mixin && guardOk == TCL_OK) { Tcl_HashTable *cmdTable = Tcl_Namespace_cmdTable(mixin->nsPtr); - ListMethodKeys(interp, cmdTable, pattern, methodType, dups, object, withPer_object); + ListMethodKeys(interp, cmdTable, pattern, methodType, withCallprotection, + dups, object, withPer_object); } } } @@ -10031,7 +10055,8 @@ /* append per-class filters */ for (pl = ComputeOrder(object->cl, object->cl->order, Super); pl; pl = pl->nextPtr) { Tcl_HashTable *cmdTable = Tcl_Namespace_cmdTable(pl->cl->nsPtr); - ListMethodKeys(interp, cmdTable, pattern, methodType, dups, object, withPer_object); + ListMethodKeys(interp, cmdTable, pattern, methodType, withCallprotection, + dups, object, withPer_object); } Tcl_DeleteHashTable(dups); return TCL_OK; @@ -11577,7 +11602,9 @@ * There is no parameter definition available, get a new one in * the the string representation. */ - result = callMethod((ClientData) obj, interp, XOTclGlobalObjects[XOTE_OBJECTPARAMETER], 2, 0, 0); + /*fprintf(stderr, "calling %s objectparameter\n",objectName(obj));*/ + result = callMethod((ClientData) obj, interp, XOTclGlobalObjects[XOTE_OBJECTPARAMETER], + 2, 0, XOTCL_CM_NO_PROTECT); if (result == TCL_OK) { rawConfArgs = Tcl_GetObjResult(interp); INCR_REF_COUNT(rawConfArgs); @@ -12426,29 +12453,29 @@ /* TODO move me at the right place */ static int XOTclOMethodMethod(Tcl_Interp *interp, XOTclObject *obj, - int withInner_namespace, int withProtected, + int withInner_namespace, int withPublic, Tcl_Obj *name, Tcl_Obj *args, Tcl_Obj *body, Tcl_Obj *withPrecondition, Tcl_Obj *withPostcondition) { requireObjNamespace(interp, obj); return MakeMethod(interp, obj, NULL, name, args, body, withPrecondition, withPostcondition, - withProtected, withInner_namespace); + withPublic, withInner_namespace); } /* TODO move me at the right place */ static int XOTclCMethodMethod(Tcl_Interp *interp, XOTclClass *cl, - int withInner_namespace, int withPer_object, int withProtected, + int withInner_namespace, int withPer_object, int withPublic, Tcl_Obj *name, Tcl_Obj *args, Tcl_Obj *body, Tcl_Obj *withPrecondition, Tcl_Obj *withPostcondition) { if (withPer_object) { requireObjNamespace(interp, &cl->object); return MakeMethod(interp, &cl->object, NULL, name, args, body, withPrecondition, withPostcondition, - withProtected, withInner_namespace); + withPublic, withInner_namespace); } else { return MakeMethod(interp, &cl->object, cl, name, args, body, withPrecondition, withPostcondition, - withProtected, withInner_namespace); + withPublic, withInner_namespace); } } @@ -12633,25 +12660,26 @@ } static int XOTclClassInfoMethodsMethod(Tcl_Interp *interp, XOTclClass *class, - int withMethodtype, int withNomixins, - int withIncontext, char *pattern) { - + int withMethodtype, int withCallproctection, + int withNomixins, int withIncontext, char *pattern) { return ListDefinedMethods(interp, &class->object, pattern, 0 /* per-object */, - AggregatedMethodType(withMethodtype), withNomixins, withIncontext); + AggregatedMethodType(withMethodtype), withCallproctection, + withNomixins, withIncontext); } static int XOTclObjInfoMethodsMethod(Tcl_Interp *interp, XOTclObject *object, - int withMethodtype, int withNomixins, - int withIncontext, char *pattern) { - + int withMethodtype, int withCallproctection, + int withNomixins, int withIncontext, char *pattern) { return ListDefinedMethods(interp, object, pattern, 1 /* per-object */, - AggregatedMethodType(withMethodtype), withNomixins, withIncontext); + AggregatedMethodType(withMethodtype), withCallproctection, + withNomixins, withIncontext); } + /* todo move me to the right place cleanup withDefined (above always 1) xxxx */ static int XOTclObjInfoCallableMethod(Tcl_Interp *interp, XOTclObject *object, - int withWhich, int withMethodtype, int withNomixins, - int withIncontext, char *pattern) { + int withWhich, int withMethodtype, int withCallprotection, + int withNomixins, int withIncontext, char *pattern) { if (withWhich) { XOTclClass *pcl = NULL; Tcl_Command cmd = ObjectFindMethod(interp, object, pattern, &pcl); @@ -12664,7 +12692,8 @@ } return ListCallableMethods(interp, object, pattern, 1 /* per-object */, - AggregatedMethodType(withMethodtype), withNomixins, withIncontext); + AggregatedMethodType(withMethodtype), withCallprotection, + withNomixins, withIncontext); } static int XOTclObjInfoMethodMethod(Tcl_Interp *interp, XOTclObject *object, Index: generic/xotclInt.h =================================================================== diff -u -rf6be3f63eadda89d7f419a090d86669c6be84c3b -r04747ba752ca2b7a4f30586348e39ab04f190da9 --- generic/xotclInt.h (.../xotclInt.h) (revision f6be3f63eadda89d7f419a090d86669c6be84c3b) +++ generic/xotclInt.h (.../xotclInt.h) (revision 04747ba752ca2b7a4f30586348e39ab04f190da9) @@ -315,6 +315,7 @@ /* flags for call method */ #define XOTCL_CM_NO_UNKNOWN 1 #define XOTCL_CM_NO_SHIFT 2 +#define XOTCL_CM_NO_PROTECT 4 /* * Index: library/lib/test.xotcl =================================================================== diff -u -r666f7ad2cb2562f3d62fc9aea54efb9b0826f6b0 -r04747ba752ca2b7a4f30586348e39ab04f190da9 --- library/lib/test.xotcl (.../test.xotcl) (revision 666f7ad2cb2562f3d62fc9aea54efb9b0826f6b0) +++ library/lib/test.xotcl (.../test.xotcl) (revision 04747ba752ca2b7a4f30586348e39ab04f190da9) @@ -36,7 +36,7 @@ } { set .count 0 - .method -per-object new args { + .method -per-object -public new args { if {[info exists .case]} { if {![info exists .ccount(${.case})]} {set .ccount(${.case}) 0} set .name ${.case}.[format %.3d [incr .ccount(${.case})]] @@ -46,20 +46,20 @@ eval .create ${.name} -name ${.name} $args } - .method -per-object run {} { + .method -per-object -public run {} { set startTime [clock clicks -milliseconds] foreach example [lsort [.info instances -closure]] { $example run } puts stderr "Total Time: [expr {[clock clicks -milliseconds]-$startTime}] ms" } - .method call {msg cmd} { + .method -public call {msg cmd} { if {[.verbose]} {puts stderr "$msg: $cmd"} namespace eval [set .namespace] $cmd } - .method run args { + .method -public run args { if {[info exists .pre]} {.call "pre" ${.pre}} if {![info exists .msg]} {set .msg ${.cmd}} set r [.call "run" ${.cmd}] Index: library/lib/xotcl1.xotcl =================================================================== diff -u -r1f0231a5c7cbb8dfef4eaf78335c9ad571863660 -r04747ba752ca2b7a4f30586348e39ab04f190da9 --- library/lib/xotcl1.xotcl (.../xotcl1.xotcl) (revision 1f0231a5c7cbb8dfef4eaf78335c9ad571863660) +++ library/lib/xotcl1.xotcl (.../xotcl1.xotcl) (revision 04747ba752ca2b7a4f30586348e39ab04f190da9) @@ -32,21 +32,21 @@ ::xotcl::methodproperty Class dealloc static true ::xotcl::methodproperty Class create static true - Class method unknown {args} { + Class method -public unknown {args} { #puts stderr "use '[self] create $args', not '[self] $args'" eval my create $args } - Object method unknown {m args} { + Object method -public unknown {m args} { if {![self isnext]} { error "[self]: unable to dispatch method '$m'" } } # "init" must exist on Object. per default it is empty. - Object method init args {} + Object method -public init args {} - Object method self {} {::xotcl::self} + Object method -public self {} {::xotcl::self} # # object-parameter definition, backwards compatible @@ -121,7 +121,7 @@ Object forward info -onerror ::xotcl::infoError ::xotcl::objectInfo %1 {%@2 %self} Class forward info -onerror ::xotcl::infoError ::xotcl::classInfo %1 {%@2 %self} - objectInfo method info {obj} { + objectInfo method -public info {obj} { set methods [list] foreach m [::info commands ::xotcl::objectInfo::*] { set name [namespace tail $m] @@ -134,7 +134,7 @@ error "[::xotcl::self] unknown info option \"$method\"; [.info info]" } - classInfo method info {cl} { + classInfo method -public info {cl} { set methods [list] foreach m [::info commands ::xotcl::classInfo::*] { set name [namespace tail $m] @@ -237,55 +237,55 @@ error "procedure \"$method\" doesn't have an argument \"$varName\"" } classInfo eval { - .method instargs {o method} {::xotcl::info_args Class $o $method} - .method args {o method} {::xotcl::info_args Object $o $method} - .method instnonposargs {o method} {::xotcl::info_nonposargs Class $o $method} - .method nonposargs {o method} {::xotcl::info_nonposargs Object $o $method} - .method instdefault {o method arg var} {::xotcl::info_default Class $o $method $arg $var} - .method default {o method arg var} {::xotcl::info_default Object $o $method $arg $var} + .method -public instargs {o method} {::xotcl::info_args Class $o $method} + .method -public args {o method} {::xotcl::info_args Object $o $method} + .method -public instnonposargs {o method} {::xotcl::info_nonposargs Class $o $method} + .method -public nonposargs {o method} {::xotcl::info_nonposargs Object $o $method} + .method -public instdefault {o method arg var} {::xotcl::info_default Class $o $method $arg $var} + .method -public default {o method arg var} {::xotcl::info_default Object $o $method $arg $var} # info options emulated by "info method" - .method instbody {o methodName} { + .method -public instbody {o methodName} { lindex [::xotcl::cmd::ClassInfo::method $o definition $methodName] end } - .method instpre {o methodName} {::xotcl::cmd::ClassInfo::method $o precondition $methodName} - .method instpost {o methodName} {::xotcl::cmd::ClassInfo::method $o postcondition $methodName} + .method -public instpre {o methodName} {::xotcl::cmd::ClassInfo::method $o precondition $methodName} + .method -public instpost {o methodName} {::xotcl::cmd::ClassInfo::method $o postcondition $methodName} # info options emulated by "info methods" - .method instcommands {o {pattern:optional ""}} { + .method -public instcommands {o {pattern:optional ""}} { ::xotcl::cmd::ClassInfo::methods $o {*}$pattern } - .method instprocs {o {pattern:optional ""}} { + .method -public instprocs {o {pattern:optional ""}} { ::xotcl::cmd::ClassInfo::methods $o -methodtype scripted {*}$pattern } - .method parametercmd {o {pattern:optional ""}} { + .method -public parametercmd {o {pattern:optional ""}} { ::xotcl::cmd::ClassInfo::methods $o -per-object -methodtype setter {*}$pattern } - .method instparametercmd {o {pattern:optional ""}} { + .method -public instparametercmd {o {pattern:optional ""}} { ::xotcl::cmd::ClassInfo::methods $o -methodtype setter {*}$pattern } } objectInfo eval { - .method args {o method} {::xotcl::info_args Object $o $method} - .method nonposargs {o method} {::xotcl::info_nonposargs Object $o $method} - .method default {o method arg var} {::xotcl::info_default Object $o $method $arg $var} + .method -public args {o method} {::xotcl::info_args Object $o $method} + .method -public nonposargs {o method} {::xotcl::info_nonposargs Object $o $method} + .method -public default {o method arg var} {::xotcl::info_default Object $o $method $arg $var} # info options emulated by "info method" - .method body {o methodName} { + .method -public body {o methodName} { lindex [::xotcl::cmd::ObjectInfo::method $o definition $methodName] end } - .method pre {o methodName} {::xotcl::cmd::ObjectInfo::method $o pre $methodName} - .method post {o methodName} {::xotcl::cmd::ObjectInfo::method $o post $methodName} + .method -public pre {o methodName} {::xotcl::cmd::ObjectInfo::method $o pre $methodName} + .method -public post {o methodName} {::xotcl::cmd::ObjectInfo::method $o post $methodName} # info options emulated by "info methods" - .method commands {o {pattern:optional ""}} { + .method -public commands {o {pattern:optional ""}} { ::xotcl::cmd::ObjectInfo::methods $o {*}$pattern } - .method procs {o {pattern:optional ""}} { + .method -public procs {o {pattern:optional ""}} { ::xotcl::cmd::ObjectInfo::methods $o -methodtype scripted {*}$pattern } - .method methods { + .method -public methods { o -nocmds:switch -noprocs:switch -incontext:switch pattern:optional } { set methodtype all @@ -306,9 +306,8 @@ } foreach cmd [::info command ::xotcl::cmd::ClassInfo::*] { set cmdName [namespace tail $cmd] - if {$cmdName in [list "method" "methods" \ + if {$cmdName in [list "forward" "method" "methods" \ "filter" "filterguard" \ - "forward" \ "mixin" "mixinguard"]} continue ::xotcl::alias ::xotcl::classInfo $cmdName $cmd } @@ -333,11 +332,11 @@ # emulation of isobject, isclass ... - Object method isobject {{object:substdefault "[self]"}} {::xotcl::is $object object} - Object method isclass {{class:substdefault "[self]"}} {::xotcl::is $class class} - Object method ismetaclass {{class:substdefault "[self]"}} {::xotcl::is $class metaclass} - Object method ismixin {class} {::xotcl::is [self] mixin $class} - Object method istype {class} {::xotcl::is [self] type $class} + Object method -public isobject {{object:substdefault "[self]"}} {::xotcl::is $object object} + Object method -public isclass {{class:substdefault "[self]"}} {::xotcl::is $class class} + Object method -public ismetaclass {{class:substdefault "[self]"}} {::xotcl::is $class metaclass} + Object method -public ismixin {class} {::xotcl::is [self] mixin $class} + Object method -public istype {class} {::xotcl::is [self] type $class} ::xotcl::alias ::xotcl::Object contains ::xotcl::classes::xotcl2::Object::contains ::xotcl::Class forward slots %self contains \ @@ -349,22 +348,22 @@ # define parametercmd and instparametercmd in terms of setter # define mixinguard and instmixinguard in terms of mixinguard # - Object method proc {name arglist body precondition:optional postcondition:optional} { - set cmd [list my method $name $arglist $body] + Object method -public proc {name arglist body precondition:optional postcondition:optional} { + set cmd [list my method -public $name $arglist $body] if {[info exists precondition]} {lappend cmd -precondition $precondition} if {[info exists postcondition]} {lappend cmd -postcondition $postcondition} eval $cmd } ::xotcl::alias Object parametercmd ::xotcl::cmd::Object::setter - Class method proc {name arglist body precondition:optional postcondition:optional} { - set cmd [list my method -per-object $name $arglist $body] + Class method -public proc {name arglist body precondition:optional postcondition:optional} { + set cmd [list my method -public -per-object $name $arglist $body] if {[info exists precondition]} {lappend cmd -precondition $precondition} if {[info exists postcondition]} {lappend cmd -postcondition $postcondition} eval $cmd } - Class method instproc {name arglist body precondition:optional postcondition:optional} { - set cmd [list my method $name $arglist $body] + Class method -public instproc {name arglist body precondition:optional postcondition:optional} { + set cmd [list my method -public $name $arglist $body] if {[info exists precondition]} {lappend cmd -precondition $precondition} if {[info exists postcondition]} {lappend cmd -postcondition $postcondition} eval $cmd @@ -383,7 +382,7 @@ ::xotcl::alias Class instforward ::xotcl::cmd::Class::forward ::xotcl::alias Class forward ::xotcl::cmd::Object::forward - Object method abstract {methtype methname arglist} { + Object method -public abstract {methtype methname arglist} { if {$methtype ne "proc" && $methtype ne "instproc" && $methtype ne "method"} { error "invalid method type '$methtype', \ must be either 'proc', 'instproc' or 'method'." @@ -396,11 +395,11 @@ } # support for XOTcl 1.* specific convenience routines - Object method hasclass cl { + Object method -public hasclass cl { if {[::xotcl::is [self] mixin $cl]} {return 1} ::xotcl::is [self] type $cl } - Object method procsearch {name} { + Object method -public procsearch {name} { set definition [::xotcl::cmd::ObjectInfo::callable [self] -which $name] if {$definition ne ""} { foreach {obj kind arg} $definition break @@ -417,15 +416,15 @@ return [list $obj $kind $name] } } - Class method allinstances {} { + Class method -public allinstances {} { # TODO: mark it deprecated return [.info instances -closure] } # keep old object interface for xotcl 1.* - Object method -per-object unsetExitHandler {} {::xotcl::unsetExitHandler $newbody} - Object method -per-object setExitHandler {newbody} {::xotcl::setExitHandler $newbody} - Object method -per-object getExitHandler {} {:xotcl::getExitHandler} + Object method -public -per-object unsetExitHandler {} {::xotcl::unsetExitHandler $newbody} + Object method -public -per-object setExitHandler {newbody} {::xotcl::setExitHandler $newbody} + Object method -public -per-object getExitHandler {} {:xotcl::getExitHandler} # resue some definitions from ::xotcl2 ::xotcl::alias ::xotcl::Object copy ::xotcl::classes::xotcl2::Object::copy @@ -439,7 +438,7 @@ proc myvar {var} {.requireNamespace; return [::xotcl::self]::$var} Object create ::xotcl::config - config method load {obj file} { + config method -public load {obj file} { source $file foreach i [array names ::auto_index [list $obj *proc *]] { set type [lindex $i 1] @@ -450,7 +449,7 @@ } } - config method mkindex {meta dir args} { + config method -public mkindex {meta dir args} { set sp {[ ]+} set st {^[ ]*} set wd {([^ ;]+)} @@ -517,7 +516,7 @@ # # if cutTheArg not 0, it cut from upvar argsList # - Object method extractConfigureArg {al name {cutTheArg 0}} { + Object method -public extractConfigureArg {al name {cutTheArg 0}} { set value "" upvar $al argList set largs [llength $argList] @@ -539,10 +538,10 @@ } Object create ::xotcl::rcs - rcs method date string { + rcs method -public date string { lreplace [lreplace $string 0 0] end end } - rcs method version string { + rcs method -public version string { lindex $string 2 } @@ -551,7 +550,7 @@ # # puts this for the time being into xotcl 1.* # - ::xotcl::Class method uses list { + ::xotcl::Class method -public uses list { foreach package $list { ::xotcl::package import -into [::xotcl::self] $package puts stderr "*** using ${package}::* in [::xotcl::self]" @@ -564,18 +563,18 @@ {export {}} } { - .method -per-object create {name args} { + .method -public -per-object create {name args} { set nq [namespace qualifiers $name] if {$nq ne "" && ![namespace exists $nq]} {Object create $nq} next } - .method -per-object extend {name args} { + .method -public -per-object extend {name args} { .require $name eval $name configure $args } - .method -per-object contains script { + .method -public -per-object contains script { if {[.exists provide]} { package provide [set .provide] [set .version] } else { @@ -596,16 +595,16 @@ } } - .method -per-object unknown args { + .method -public -per-object unknown args { #puts stderr "unknown: package $args" eval [set .packagecmd] $args } - .method -per-object verbose value { + .method -public -per-object verbose value { set .verbose $value } - .method -per-object present args { + .method -public -per-object present args { if {$::tcl_version<8.3} { switch -exact -- [lindex $args 0] { -exact {set pkg [lindex $args 1]} @@ -621,7 +620,7 @@ } } - .method -per-object import {{-into ::} pkg} { + .method -public -per-object import {{-into ::} pkg} { .require $pkg namespace eval $into [subst -nocommands { #puts stderr "*** package import ${pkg}::* into [namespace current]" @@ -636,7 +635,7 @@ } } - .method -per-object require args { + .method -public -per-object require args { #puts "XOTCL package require $args, current=[namespace current]" set prevComponent ${.component} if {[catch {set v [eval package present $args]} msg]} { Index: tests/info-method.xotcl =================================================================== diff -u -r1f0231a5c7cbb8dfef4eaf78335c9ad571863660 -r04747ba752ca2b7a4f30586348e39ab04f190da9 --- tests/info-method.xotcl (.../info-method.xotcl) (revision 1f0231a5c7cbb8dfef4eaf78335c9ad571863660) +++ tests/info-method.xotcl (.../info-method.xotcl) (revision 04747ba752ca2b7a4f30586348e39ab04f190da9) @@ -35,9 +35,10 @@ } C create c1 -? {lsort [C info methods]} "a addOne m m-with-assertions s" -foreach m [lsort [C info methods]] { - ? {lsort [c1 info callable $m]} $m +? {lsort [C info methods -callprotection all]} "a addOne m m-with-assertions s" +? {lsort [C info methods]} "a addOne s" +foreach m [lsort [C info methods -callprotection all]] { + ? [subst -nocommands {lsort [c1 info callable $m]}] $m } ? {C info method definition a} "::C alias a ::set" ? {c1 info callable -which a} "::C alias a ::set"