Index: TODO =================================================================== diff -u -r89714df5a6af5799a4444805cf1f82b4b2b21af2 -r8c3c5565c2904e379350494cd40675d1aad6a46c --- TODO (.../TODO) (revision 89714df5a6af5799a4444805cf1f82b4b2b21af2) +++ TODO (.../TODO) (revision 8c3c5565c2904e379350494cd40675d1aad6a46c) @@ -3437,13 +3437,20 @@ * added "private" to migration guide * some textual improvements in migration guide + - nx: + * added namespace "nx::internal" + * delete procs via "rename to emtpy" instead of + "defining procs with empty argumentes and body" + * provided "-properties" as a replacement for -attributes, + but without magic variable + * extended regression test + TODO: - private: * document private in tutorial - - nx: - * maybe provide a replacement for -attributes, but without the magic variable. + - naming of slot classes * should we switch from "-class" to "-slotclass"? Index: library/nx/nx.tcl =================================================================== diff -u -r8046b1da6bc0689f73d4dbdc3f8d1e03fd23acaf -r8c3c5565c2904e379350494cd40675d1aad6a46c --- library/nx/nx.tcl (.../nx.tcl) (revision 8046b1da6bc0689f73d4dbdc3f8d1e03fd23acaf) +++ library/nx/nx.tcl (.../nx.tcl) (revision 8c3c5565c2904e379350494cd40675d1aad6a46c) @@ -4,6 +4,7 @@ namespace eval ::nx { namespace eval ::nsf {}; # make pkg indexer happy namespace eval ::nsf::object {}; # make pkg indexer happy + namespace eval ::nx::internal {}; # make pkg indexer happy # # By setting the variable bootstrap, we can check later, whether we @@ -416,10 +417,10 @@ } # - # The function nx::setSlotContainerProperties set the method + # The function nx::internal::setSlotContainerProperties set the method # properties for slot containers # - proc ::nx::setSlotContainerProperties {baseObject containerName} { + proc ::nx::internal::setSlotContainerProperties {baseObject containerName} { set slotContainer ${baseObject}::$containerName $slotContainer ::nsf::methods::object::requirenamespace ::nsf::method::property $baseObject -per-object $containerName call-protected true @@ -434,12 +435,12 @@ # slotContainer (when no slot name was provided) or the fully # qualified name of the slot object. # - nsf::proc ::nx::slotObj {{-container slot} baseObject name:optional} { + ::nsf::proc ::nx::slotObj {{-container slot} baseObject name:optional} { # Create slot container object if needed set slotContainer ${baseObject}::$container if {![::nsf::object::exists $slotContainer]} { ::nx::Object ::nsf::methods::class::alloc $slotContainer - ::nx::setSlotContainerProperties $baseObject $container + ::nx::internal::setSlotContainerProperties $baseObject $container } if {[info exists name]} { return ${slotContainer}::$name @@ -703,7 +704,7 @@ # Define "info info" and "info unknown" ###################################################################### - proc ::nx::infoOptions {obj} { + proc ::nx::internal::infoOptions {obj} { #puts stderr "INFO INFO $obj -> '[::nsf::directdispatch $obj ::nsf::methods::object::info::methods -methodtype all]'" set methods [list] foreach name [::nsf::directdispatch $obj ::nsf::methods::object::info::methods] { @@ -717,8 +718,8 @@ error "[::nsf::self] unknown info option \"$method\"; [$obj info info]" } - Object method "info info" {} {::nx::infoOptions ::nx::Object::slot::__info} - Class method "info info" {} {::nx::infoOptions ::nx::Class::slot::__info} + Object method "info info" {} {::nx::internal::infoOptions ::nx::Object::slot::__info} + Class method "info info" {} {::nx::internal::infoOptions ::nx::Class::slot::__info} # finally register method "method" (otherwise, we cannot use "method" above) Object alias "info method" ::nsf::methods::object::info::method @@ -926,8 +927,9 @@ # value checkers MethodParameterSlot create ::nx::methodParameterSlot - # use low level interface for defining slot values. Normally, this is - # done via slot objects, which are defined later. + # Define a temporary, low level interface for defining slot + # values. Normally, this is done via slot objects, which are defined + # later. The proc is removed later in this script. proc createBootstrapVariableSlots {class definitions} { foreach att $definitions { @@ -1318,6 +1320,9 @@ # Register system slots ###################################################################### + # Define a temporary, low level interface for defining system slots. + # The proc is removed later in this script. + proc register_system_slots {os} { # # Most system slots are RelationSlots @@ -1342,9 +1347,8 @@ -methodname "::nsf::classes::nx::Object::filter" -elementtype filterreg # - # Create object parameter slots for "attributes", "noninit" and "volatile" + # Create object parameter slots for "noninit" and "volatile" # - #::nx::ObjectParameterSlot create ${os}::Class::slot::attributes ::nx::ObjectParameterSlot create ${os}::Object::slot::noinit \ -methodname ::nsf::methods::object::noinit -noarg true ::nx::ObjectParameterSlot create ${os}::Object::slot::volatile -noarg true @@ -1423,7 +1427,9 @@ register_system_slots ::nx - proc ::nx::register_system_slots {} {} + + # remove helper proc + rename register_system_slots "" # # With a special purpose eval, we could avoid the need for @@ -1822,27 +1828,16 @@ ###################################################################### - # Define method "attributes" for convenience to define multiple - # attributes based on a list of parameter specifications. + # Define method "properties" for convenience to define multiple + # properties based on a list of parameter specifications. ###################################################################### - # Class public method attributes arglist { - # set slotContainer [::nx::slotObj [::nsf::self]] - # foreach arg $arglist { - # [self] ::nsf::classes::nx::Class::property $arg - # } - # ::nsf::var::set $slotContainer __parameter $arglist - # } + proc ::nx::internal::addProperties {arglist} { + foreach arg $arglist {:property $arg} + } + ::nx::ObjectParameterSlot create ::nx::Class::slot::properties \ + -methodname "::nx::internal::addProperties" - # Class method "info attributes" {} { - # set slotContainer [::nx::slotObj [::nsf::self]] - # if {[::nsf::var::exists $slotContainer __parameter]} { - # return [::nsf::var::set $slotContainer __parameter] - # } - # return "" - # } - - ###################################################################### # Minimal definition of a value checker that permits every value # without warnings. The primary purpose of this value checker is to @@ -1859,9 +1854,8 @@ ###################################################################### # remove helper proc - proc createBootstrapVariableSlots {} {} + rename ::nx::createBootstrapVariableSlots "" - ###################################################################### # Create a mixin class to overload method "new" such it does not # allocate new objects in ::nx::*, but in the specified object @@ -2030,7 +2024,7 @@ if {[::nsf::object::exists $base] && [::nsf::method::property $base -per-object $container slotcontainer] } { - ::nx::setSlotContainerProperties [$dest ::nsf::methods::object::info::parent] $container + ::nx::internal::setSlotContainerProperties [$dest ::nsf::methods::object::info::parent] $container } # Index: library/xotcl/library/xotcl2.tcl =================================================================== diff -u -r8046b1da6bc0689f73d4dbdc3f8d1e03fd23acaf -r8c3c5565c2904e379350494cd40675d1aad6a46c --- library/xotcl/library/xotcl2.tcl (.../xotcl2.tcl) (revision 8046b1da6bc0689f73d4dbdc3f8d1e03fd23acaf) +++ library/xotcl/library/xotcl2.tcl (.../xotcl2.tcl) (revision 8c3c5565c2904e379350494cd40675d1aad6a46c) @@ -430,7 +430,8 @@ -elementtype filterreg -multiplicity 0..n } register_system_slots ::xotcl - proc ::xotcl::register_system_slots {} {} + # remove temporary proc + rename register_system_slots "" ######################## # Info definition @@ -741,8 +742,8 @@ } # define "info info" - objectInfo method info {} {::nx::infoOptions ::xotcl::objectInfo} - classInfo method info {} {::nx::infoOptions ::xotcl::classInfo} + objectInfo method info {} {::nx::internal::infoOptions ::xotcl::objectInfo} + classInfo method info {} {::nx::internal::infoOptions ::xotcl::classInfo} # define "info unknown" objectInfo proc unknown {method args} { Index: tests/info-method.test =================================================================== diff -u -rac96e6ce975fe5864b64dee9d66bc701a31e113b -r8c3c5565c2904e379350494cd40675d1aad6a46c --- tests/info-method.test (.../info-method.test) (revision ac96e6ce975fe5864b64dee9d66bc701a31e113b) +++ tests/info-method.test (.../info-method.test) (revision 8c3c5565c2904e379350494cd40675d1aad6a46c) @@ -322,7 +322,7 @@ :method "sub foo" args {;} } - ? {D info lookup slots} "::D::per-object-slot::a2 ::nx::Class::slot::superclass ::nx::Class::slot::object-mixin ::nx::Class::slot::mixin ::nx::Class::slot::object-filter ::nx::Class::slot::filter ::nx::Object::slot::volatile ::nx::Object::slot::noinit ::nx::Object::slot::__initcmd ::nx::Object::slot::class" + ? {D info lookup slots} "::D::per-object-slot::a2 ::nx::Class::slot::properties ::nx::Class::slot::superclass ::nx::Class::slot::object-mixin ::nx::Class::slot::mixin ::nx::Class::slot::object-filter ::nx::Class::slot::filter ::nx::Object::slot::volatile ::nx::Object::slot::noinit ::nx::Object::slot::__initcmd ::nx::Object::slot::class" C create c1 ? {c1 info precedence} "::C ::nx::Object" Index: tests/parameters.test =================================================================== diff -u -r042715c36e6ca53a9712922a03de958476258e02 -r8c3c5565c2904e379350494cd40675d1aad6a46c --- tests/parameters.test (.../parameters.test) (revision 042715c36e6ca53a9712922a03de958476258e02) +++ tests/parameters.test (.../parameters.test) (revision 8c3c5565c2904e379350494cd40675d1aad6a46c) @@ -1199,16 +1199,6 @@ ? {c1 a 1} 1 ? {c1 b 1} 1 ? {c1 c 1} 1 - - # before: 1st case: setter, 2&3: forward - #slot-optimizer.001: 1.50 mms, c1 a 1 - #slot-optimizer.002: 3.30 mms, c1 b 1 - #slot-optimizer.003: 3.40 mms, c1 c 1 - # - # after: 1st, 2nd, 3rd case: setter - #slot-optimizer.001: 1.50 mms, c1 a 1 - #slot-optimizer.002: 1.50 mms, c1 b 1 - #slot-optimizer.003: 1.60 mms, c1 c 1 } Test parameter count 10 @@ -2238,4 +2228,38 @@ ? {o2 info slot definition} "{p0:noconfig 200} {p1:noaccessor,noconfig 201} {p2:noaccessor,noconfig 202} {p3:noconfig 203}" ? {o2 info properties} "{p0:noconfig 200} {p1:noaccessor,noconfig 201} {p2:noaccessor,noconfig 202} {p3:noconfig 203}" +} + +# +# testing method properties +# +nx::Test case properties { + + # simple properties + Class create Foo -properties {a {b 1}} + + ? {Foo info properties} "a {b 1}" + + # properties with value checker + Class create Foo -properties { + a:boolean + {b:integer 1} + } + ? {Foo info properties} "a:boolean {b:integer 1}" + + # required/optional properties + Class create Foo -properties { + a:required + b:boolean,required + } + ? {Foo info properties} "a:required b:boolean,required" + + # properties with multiplicity + Class create Foo -properties { + {ints:integer,0..n ""} + objs:object,1..n + obj:object,0..1 + } + ? {Foo info properties} "objs:object,1..n {ints:integer,0..n {}} obj:object,0..1" + } \ No newline at end of file