Index: TODO =================================================================== diff -u -rf858f142f5fab4f88996b3eb709c3afa55114be9 -rb531a50ecc43d0c13e2432b099a436c3260c7a49 --- TODO (.../TODO) (revision f858f142f5fab4f88996b3eb709c3afa55114be9) +++ TODO (.../TODO) (revision b531a50ecc43d0c13e2432b099a436c3260c7a49) @@ -4292,6 +4292,8 @@ /cls/ object mixin add ... /obj/ object mixin add ... /obj/ require object method ... + /obj/ object property ... + /obj/ object variable ... The same change propagated as well to the "info" method. Now we have: @@ -4317,6 +4319,8 @@ "/obj/ class method require public method ..." "/obj/ class method require protected method ..." "/obj/ class method require private method ..." + "/cls/ class property ..." + "/cls/ class variable ..." were dropped b) "/obj/ method ....", @@ -4340,18 +4344,15 @@ - added package nx::plain-object-method to allow optionally plain method b) "/obj/ method ...." (and friends, see (b)) -- add support to slots to use ensemble methods as setters +- added support to slots to use ensemble methods as setters +- added "/obj/ object variable" and "/obj/ object property" ======================================================================== TODO: - reconsider #? {c1 cget -mixin} "" ? {c1 cget -object-mixin} "" -- handle - o object property foo - o object variable foo - - test cases complete tests/plain-object-method.test provide tests/class.test Index: library/nx/nx.tcl =================================================================== diff -u -rf858f142f5fab4f88996b3eb709c3afa55114be9 -rb531a50ecc43d0c13e2432b099a436c3260c7a49 --- library/nx/nx.tcl (.../nx.tcl) (revision f858f142f5fab4f88996b3eb709c3afa55114be9) +++ library/nx/nx.tcl (.../nx.tcl) (revision b531a50ecc43d0c13e2432b099a436c3260c7a49) @@ -1902,10 +1902,10 @@ ###################################################################### - # Define method "property" for convenience + # Define methods "property" and "variable" ###################################################################### - nx::Object method variable { + nx::Object method "object variable" { {-accessor "none"} {-incremental:switch} {-class ""} @@ -1996,7 +1996,7 @@ return [::nsf::directdispatch [self] ::nsf::methods::object::info::method registrationhandle $name] } - Object method property { + Object method "object property" { {-accessor ""} {-config:boolean true} {-incremental:switch} @@ -2011,7 +2011,7 @@ #puts stderr "OBJECT got default accessor ${accessor}" } - set r [[self] ::nsf::classes::nx::Object::variable \ + set r [[self] object variable \ -accessor $accessor \ -incremental=$incremental \ -class $class \ @@ -2071,15 +2071,7 @@ return $r } - # - # provide aliases for "object property" and "object variable" - # - ::nx::Class eval { - :alias "object property" ::nsf::classes::nx::Object::property - :alias "object variable" ::nsf::classes::nx::Object::variable - } - ###################################################################### # Define method "properties" for convenience to define multiple # properties based on a list of parameter specifications. Index: library/nx/plain-object-method.tcl =================================================================== diff -u -rf858f142f5fab4f88996b3eb709c3afa55114be9 -rb531a50ecc43d0c13e2432b099a436c3260c7a49 --- library/nx/plain-object-method.tcl (.../plain-object-method.tcl) (revision f858f142f5fab4f88996b3eb709c3afa55114be9) +++ library/nx/plain-object-method.tcl (.../plain-object-method.tcl) (revision b531a50ecc43d0c13e2432b099a436c3260c7a49) @@ -8,28 +8,37 @@ name arguments:parameter,0..* -returns body -precondition -postcondition } { puts stderr "LEGACY CMD: [self] [current method] [current args]" - :public object method {*}[current args] + :public object [current method] {*}[current args] } :public method alias args { puts stderr "LEGACY CMD: [self] [current method] [current args]" - :public object alias {*}$args + :public object [current method] {*}$args } :public method forward args { puts stderr "LEGACY CMD: [self] [current method] [current args]" - :public object forward {*}$args + :public object [current method] {*}$args } :public method mixin args { puts stderr "LEGACY CMD: [self] [current method] [current args]" - :object mixin {*}$args + :object [current method] {*}$args } :public method filter args { puts stderr "LEGACY CMD: [self] [current method] [current args]" - :object filter {*}$args + :object [current method] {*}$args } + :public method property args { + puts stderr "LEGACY CMD: [self] [current method] [current args]" + :object [current method] {*}$args + } + :public method variable args { + puts stderr "LEGACY CMD: [self] [current method] [current args]" + :object [current method] {*}$args + } + :public alias "info method" ::nsf::methods::object::info::method :public alias "info methods" ::nsf::methods::object::info::methods :public alias "info filter guard" ::nsf::methods::object::info::filterguard Index: tests/info-method.test =================================================================== diff -u -rf858f142f5fab4f88996b3eb709c3afa55114be9 -rb531a50ecc43d0c13e2432b099a436c3260c7a49 --- tests/info-method.test (.../info-method.test) (revision f858f142f5fab4f88996b3eb709c3afa55114be9) +++ tests/info-method.test (.../info-method.test) (revision b531a50ecc43d0c13e2432b099a436c3260c7a49) @@ -128,7 +128,7 @@ ? {::nx::Object info lookup methods -source application} "" ? {::nx::Class info lookup methods -source application} "" - set object_methods "cget configure contains copy delete destroy eval info move object private property protected public require variable volatile" + set object_methods "cget configure contains copy delete destroy eval info move object private protected public require volatile" set class_methods "alias cget configure contains copy create delete destroy eval filter forward info method mixin move new object private property protected public require variable volatile" ? {lsort [::nx::Object info lookup methods -source baseclasses]} $class_methods @@ -375,13 +375,13 @@ ? {o object method foo {} {return o.foo}} "::o::foo" ? {o object alias is ::nsf::is} "::o::is" #? {o object property x} {variable definition for 'x' (without value and accessor) is useless} - ? {o property x} "::o::x" - ? {o property -accessor public x} "::o::x" + ? {o object property x} "::o::x" + ? {o object property -accessor public x} "::o::x" ? {lsort [o info object methods]} "foo is x" - #? {o property A} {variable definition for 'A' (without value and accessor) is useless} - ? {o property A} ::o::A - ? {o property -accessor public A} ::o::A + #? {o object property A} {variable definition for 'A' (without value and accessor) is useless} + ? {o object property A} ::o::A + ? {o object property -accessor public A} ::o::A ? {o object forward fwd ::set} ::o::fwd ? {lsort [o info object methods]} "A foo fwd is x" @@ -471,7 +471,7 @@ :object property -accessor public {a2 ""} :method "sub foo" args {;} :create d1 { - :property -accessor public {a3 ""} + :object property -accessor public {a3 ""} } } Index: tests/methods.test =================================================================== diff -u -rf858f142f5fab4f88996b3eb709c3afa55114be9 -rb531a50ecc43d0c13e2432b099a436c3260c7a49 --- tests/methods.test (.../methods.test) (revision f858f142f5fab4f88996b3eb709c3afa55114be9) +++ tests/methods.test (.../methods.test) (revision b531a50ecc43d0c13e2432b099a436c3260c7a49) @@ -56,9 +56,9 @@ :protected object forward protected_object_forward %self protected_object_method # setter - :property {plain_object_setter ""} - :property -accessor public {public_object_setter ""} - :property -accessor protected protected_object_setter + :object property {plain_object_setter ""} + :object property -accessor public {public_object_setter ""} + :object property -accessor protected protected_object_setter # alias :object alias plain_object_alias [:info object method registrationhandle plain_object_method] @@ -296,13 +296,13 @@ ? {C D} "method 'D' unknown for ::C; consider '::C create D ' instead of '::C D '" nx::Object create o { - set x [:property -accessor public a] + set x [:object property -accessor public a] ? [list set _ $x] "::o::a" # property with default - :property {b b1} - :property -accessor public {c c1} - :property -accessor protected {d d1} + :object property {b b1} + :object property -accessor public {c c1} + :object property -accessor protected {d d1} } ? {o a 2} 2 #? {o b} {::o: unable to dispatch method 'b'} @@ -424,7 +424,7 @@ nx::Object create o { # property defines a setter, we need a current object - :property -accessor public {a v} + :object property -accessor public {a v} # the other methods don't require them as strong :object forward b ::o2 bar :object method foo {} {return [nx::self]} @@ -550,8 +550,8 @@ # nx::Test case delete-per-object { nx::Object create o1 { - :property -accessor public a1 - :property -accessor public a2 + :object property -accessor public a1 + :object property -accessor public a2 :public object method foo {} {return [namespace current]-[namespace which info]} :public object method "info foo" {} {return [namespace current]-[namespace which info]} :public object method "info bar foo" {} {return [namespace current]-[namespace which info]} Index: tests/parameters.test =================================================================== diff -u -rf858f142f5fab4f88996b3eb709c3afa55114be9 -rb531a50ecc43d0c13e2432b099a436c3260c7a49 --- tests/parameters.test (.../parameters.test) (revision f858f142f5fab4f88996b3eb709c3afa55114be9) +++ tests/parameters.test (.../parameters.test) (revision b531a50ecc43d0c13e2432b099a436c3260c7a49) @@ -1303,9 +1303,9 @@ nx::Test case slot-traces { ::nx::Object create o { - :property a {set :defaultcmd { set _ 4 } } - :property b {set :valuecmd { set _ 44 } } - :property c {set :valuechangedcmd { ::nsf::var::set $obj $var 999 }} + :object property a {set :defaultcmd { set _ 4 } } + :object property b {set :valuecmd { set _ 44 } } + :object property c {set :valuechangedcmd { ::nsf::var::set $obj $var 999 }} } ? {o a} 4 @@ -1356,20 +1356,20 @@ Object create o ? {o eval {info exists :a}} 0 - ? {o property {a 0} { + ? {o object property {a 0} { set :defaultcmd {set _ 4} }} "defaultcmd can't be used together with default value" ? {o eval {info exists :a}} 0 ? {o eval {info exists :b}} 0 - ? {o property {b 0} { + ? {o object property {b 0} { set :valuecmd {set _ 44} }} "valuecmd can't be used together with default value" ? {o eval {info exists :b}} 0 ? {o eval {info exists :c}} 0 - ? {o property c { + ? {o object property c { set :defaultcmd {set _ 4} set :valuecmd {set _ 44} }} "valuecmd can't be used together with defaultcmd" @@ -1380,7 +1380,7 @@ # ? {o eval {info exists :a}} 0 - o property {a 0} { + o object property {a 0} { set :valuechangedcmd {::nsf::var::set $obj $var [expr [list [::nsf::var::set $obj $var] + 1]]} } ? {o eval {info exists :a}} 1 @@ -1919,9 +1919,9 @@ # We have the per-object cache; adding a per-object property should # flush the cache # - c1 property bo1 + c1 object property bo1 ? {lsort [c1 info lookup parameter names b*]} "b1 bo1" - c1 property bo2 + c1 object property bo2 ? {lsort [c1 info lookup parameter names b*]} "b1 bo1 bo2" # # property deletion should invalidate the cache as well @@ -1939,7 +1939,7 @@ nx::Class create C { :property a1 :create c1 { - :property a2 + :object property a2 } } nx::Class create D -superclass C @@ -2061,7 +2061,7 @@ nx::Test case reconfigure-perobj-default { nx::Object create o ? {o eval {info exists :a}} 0 - o property {a oldvalue} + o object property {a oldvalue} ? {o eval {info exists :a}} 1 ? {o a} oldvalue # @@ -2074,7 +2074,7 @@ # # re-assignment of the default is handled by init # - o property {a newvalue} + o object property {a newvalue} ? {o eval {info exists :a}} 1 ? {o a} newvalue o eval {unset :a} @@ -2137,8 +2137,8 @@ ? [list [self] eval {set :dummy 1}] "1" # set 2 variables, one via variable, one via property - ? [list [self] variable -nocomplain captain1 "James Kirk"] "" - ? [list [self] property -nocomplain [list captain2 "Jean Luc"]] "::enterprise::captain2" + ? [list [self] object variable -nocomplain captain1 "James Kirk"] "" + ? [list [self] object property -nocomplain [list captain2 "Jean Luc"]] "::enterprise::captain2" # in both cases, we expect instance variables ? [list [self] eval {set :captain1}] "James Kirk" @@ -2149,33 +2149,33 @@ ? [list [self] info lookup method captain2] "::enterprise::captain2" # set variable with a value checker - ? [list [self] variable -nocomplain x1:int 1] "" - ? [list [self] property -nocomplain [list x2:int 2]] "::enterprise::x2" + ? [list [self] object variable -nocomplain x1:int 1] "" + ? [list [self] object property -nocomplain [list x2:int 2]] "::enterprise::x2" # set variable with a value checker and an invalid value - ? [list [self] variable y1:int a] {expected integer but got "a"} - ? [list [self] property [list y2:int b]] {expected integer but got "b"} + ? [list [self] object variable y1:int a] {expected integer but got "a"} + ? [list [self] object property [list y2:int b]] {expected integer but got "b"} # set variable again, without -nocomplain - ? [list [self] variable x1:int 1] {object ::enterprise has already an instance variable named 'x1'} - ? [list [self] property [list x2:int 2]] {object ::enterprise has already an instance variable named 'x2'} + ? [list [self] object variable x1:int 1] {object ::enterprise has already an instance variable named 'x1'} + ? [list [self] object property [list x2:int 2]] {object ::enterprise has already an instance variable named 'x2'} # set variable with a value checker, multiple - ? [list [self] variable -nocomplain xm1:int,1..n {1 2 3}] "" - ? [list [self] property -nocomplain [list xm2:int,1..n {1 2 3}]] "::enterprise::xm2" + ? [list [self] object variable -nocomplain xm1:int,1..n {1 2 3}] "" + ? [list [self] object property -nocomplain [list xm2:int,1..n {1 2 3}]] "::enterprise::xm2" # in both cases, we expect instance variables ? [list [self] eval {set :xm1}] "1 2 3" ? [list [self] eval {set :xm2}] "1 2 3" # set variable with a value checker, multiple with invalid value - ? [list [self] variable -nocomplain xm1:int,1..n {1 2a 3}] \ + ? [list [self] object variable -nocomplain xm1:int,1..n {1 2a 3}] \ {invalid value in "1 2a 3": expected integer but got "2a"} - ? [list [self] property -nocomplain [list xm2:int,1..n {1 2a 3}]] \ + ? [list [self] object property -nocomplain [list xm2:int,1..n {1 2a 3}]] \ {invalid value in "1 2a 3": expected integer but got "2a"} # useless definition - ? [list [self] variable dummy:int] \ + ? [list [self] object variable dummy:int] \ {variable definition for 'dummy' (without value and accessor) is useless} # @@ -2192,19 +2192,19 @@ # # Test usage of application specific converter in "variable" and # "property"; invalid value - ? [list [self] variable -nocomplain r1:range,arg=1-10 11] \ + ? [list [self] object variable -nocomplain r1:range,arg=1-10 11] \ {value '11' of parameter value not between 1 and 10} - ? [list [self] property -nocomplain [list r2:range,arg=1-10 11]] \ + ? [list [self] object property -nocomplain [list r2:range,arg=1-10 11]] \ {value '11' of parameter value not between 1 and 10} # valid value - ? [list [self] variable -nocomplain r1:range,arg=1-10 5] "" - ? [list [self] property -nocomplain [list r2:range,arg=1-10 5]] \ + ? [list [self] object variable -nocomplain r1:range,arg=1-10 5] "" + ? [list [self] object property -nocomplain [list r2:range,arg=1-10 5]] \ {::enterprise::r2} # testing incremental - ? [list [self] variable -incremental -nocomplain i:int,0..* {}] "::enterprise::i" - ? [list [self] property -incremental -nocomplain j:int,0..* {}] "::enterprise::j" + ? [list [self] object variable -incremental -nocomplain i:int,0..* {}] "::enterprise::i" + ? [list [self] object property -incremental -nocomplain j:int,0..* {}] "::enterprise::j" :i add 1 :j add 1 ? [list [self] i] "1" @@ -2340,8 +2340,8 @@ nx::Object create o { # define 2 object-level variables, one via variable, one via property - :variable v v0 - :property {a a0} + :object variable v v0 + :object property {a a0} } # the instance of C will have the two variables set ... @@ -2415,8 +2415,8 @@ # boolean, except that without the specified value argument # (variable foo below), it sets the the variable to "false". ? {::nx::Object create o1 { - :variable foo:switch - :variable bar:switch 1 + :object variable foo:switch + :object variable bar:switch 1 }} ::o1 ? {o1 eval {set :foo}} 0 ? {o1 eval {set :bar}} 1 @@ -2472,22 +2472,22 @@ # nx::Object create o1 { # plain object variable has no slot object - :variable v0 100 + :object variable v0 100 # In case we require an accessor or e.g. incremental, slot objects # are created; incremental implies accessor - :variable -accessor public v1 100 - :variable -incremental v2 100 + :object variable -accessor public v1 100 + :object variable -incremental v2 100 } # only the variables with slots show up in "info slot ..." ? {o1 info slot objects} "::o1::per-object-slot::v2 ::o1::per-object-slot::v1" ? {o1 info slot definitions} "{::o1 variable -accessor public v2:0..n 100} {::o1 variable -accessor public v1 100}" nx::Object create o2 { - :property {p0 200} - :property -accessor none {p1 201} - :property -accessor none {p2:noconfig 202} - :property {p3:noconfig 203} + :object property {p0 200} + :object property -accessor none {p1 201} + :object property -accessor none {p2:noconfig 202} + :object property {p3:noconfig 203} } # "p1" and "p2" do NOT show up in "info methods" @@ -2732,16 +2732,16 @@ # 'invalid value constraints # "slot=::objekt::per-object-slot::a,slotassign"' # - nx::Object create objekt - ? {objekt eval {info exists :a}} 0 + nx::Object create o + ? {o eval {info exists :a}} 0 ? {catch { - objekt variable -accessor public -initblock { + o object variable -accessor public -initblock { :public object method assign args { incr :assignCalled next } } a 1}} 0 - ? {objekt eval {info exists :a}} 1 - ? {objekt eval {info exists :assignCalled}} 0; # !!! should be 1 - ? {objekt a} 1 + ? {o eval {info exists :a}} 1 + ? {o eval {info exists :assignCalled}} 0; # !!! should be 1 + ? {o a} 1 } \ No newline at end of file Index: tests/properties.test =================================================================== diff -u -rf858f142f5fab4f88996b3eb709c3afa55114be9 -rb531a50ecc43d0c13e2432b099a436c3260c7a49 --- tests/properties.test (.../properties.test) (revision f858f142f5fab4f88996b3eb709c3afa55114be9) +++ tests/properties.test (.../properties.test) (revision b531a50ecc43d0c13e2432b099a436c3260c7a49) @@ -365,17 +365,17 @@ nx::Test case object-level { nx::Object create o1 { - :property {a a1} - :property -accessor public {b b1} - :property -accessor protected {c c1} - :property -accessor private {d d1} - :property -accessor none {e e1} + :object property {a a1} + :object property -accessor public {b b1} + :object property -accessor protected {c c1} + :object property -accessor private {d d1} + :object property -accessor none {e e1} - :variable va va1 - :variable -accessor public vb vb1 - :variable -accessor protected vc vc1 - :variable -accessor private vd vd1 - :variable -accessor none ve ve1 + :object variable va va1 + :object variable -accessor public vb vb1 + :object variable -accessor protected vc vc1 + :object variable -accessor private vd vd1 + :object variable -accessor none ve ve1 :public object method call-local {v} {: -local $v} @@ -490,7 +490,7 @@ # # check error message # - ? {o1 property -accessor proceted {b b1}} {accessor value 'proceted' invalid; might be one of public|protected|private or none} + ? {o1 object property -accessor proceted {b b1}} {accessor value 'proceted' invalid; might be one of public|protected|private or none} } # @@ -499,17 +499,17 @@ nx::Test case object-level-incremental { nx::Object create o1 { - :property -incremental {a a1} - :property -accessor public -incremental {b b1} - :property -accessor protected -incremental {c c1} - :property -accessor private -incremental {d d1} - :property -accessor none -incremental {e e1} + :object property -incremental {a a1} + :object property -accessor public -incremental {b b1} + :object property -accessor protected -incremental {c c1} + :object property -accessor private -incremental {d d1} + :object property -accessor none -incremental {e e1} - :variable -incremental va va1 - :variable -accessor public -incremental vb vb1 - :variable -accessor protected -incremental vc vc1 - :variable -accessor private -incremental vd vd1 - :variable -accessor none -incremental ve ve1 + :object variable -incremental va va1 + :object variable -accessor public -incremental vb vb1 + :object variable -accessor protected -incremental vc vc1 + :object variable -accessor private -incremental vd vd1 + :object variable -accessor none -incremental ve ve1 :public object method call-local {v} {: -local $v} :public object method add-local {var value} {: -local $var add $value} @@ -649,7 +649,7 @@ # # check error message # - ? {o1 property -accessor proceted {b b1}} {accessor value 'proceted' invalid; might be one of public|protected|private or none} + ? {o1 object property -accessor proceted {b b1}} {accessor value 'proceted' invalid; might be one of public|protected|private or none} # # The accessor is deleted due to the error @@ -783,17 +783,17 @@ nx::Test case object-level-perf { nx::Object create o1 { - :property {a a1} - :property -accessor public {b b1} - :property -accessor protected {c c1} - :property -accessor private {d d1} - :property -accessor none {e e1} + :object property {a a1} + :object property -accessor public {b b1} + :object property -accessor protected {c c1} + :object property -accessor private {d d1} + :object property -accessor none {e e1} - :variable va va1 - :variable -accessor public vb vb1 - :variable -accessor protected vc vc1 - :variable -accessor private vd vd1 - :variable -accessor none ve ve1 + :object variable va va1 + :object variable -accessor public vb vb1 + :object variable -accessor protected vc vc1 + :object variable -accessor private vd vd1 + :object variable -accessor none ve ve1 } # Index: tests/protected.test =================================================================== diff -u -rf858f142f5fab4f88996b3eb709c3afa55114be9 -rb531a50ecc43d0c13e2432b099a436c3260c7a49 --- tests/protected.test (.../protected.test) (revision f858f142f5fab4f88996b3eb709c3afa55114be9) +++ tests/protected.test (.../protected.test) (revision b531a50ecc43d0c13e2432b099a436c3260c7a49) @@ -491,7 +491,7 @@ :public object method info {} {return "overloads system info"} :public object method destroy {} {return "overloads system destroy"} :public object method "object method" args {return "overloads method 'object method'"} - :variable v 1 + :object variable v 1 } ? {o1 info} "overloads system info" @@ -738,7 +738,7 @@ :property -accessor private {c c1d} :public method bard {p} {return [: -local $p]} :create d1 { - :property {c c1o} + :object property {c c1o} } } @@ -757,7 +757,7 @@ :property -accessor public {c c1d} :public method bard {p} {return [: -local $p]} :create d1 { - :property -accessor private {c c1o} + :object property -accessor private {c c1o} :public object method bard1 {p} {return [: -local $p]} } } @@ -796,10 +796,10 @@ # nx::Test case protected-priv-object-property { nx::Object create o { - :property -accessor public {a a1} - :property -accessor protected {b b1} - :property -accessor private {c c1} - :property -accessor private {d:integer 1} + :object property -accessor public {a a1} + :object property -accessor protected {b b1} + :object property -accessor private {c c1} + :object property -accessor private {d:integer 1} :public object method foo {p} {return [: $p]} :public object method bar {p} {return [: -local $p]} :public object method baz {p v} {return [: -local $p $v]} Index: tests/serialize.test =================================================================== diff -u -rf858f142f5fab4f88996b3eb709c3afa55114be9 -rb531a50ecc43d0c13e2432b099a436c3260c7a49 --- tests/serialize.test (.../serialize.test) (revision f858f142f5fab4f88996b3eb709c3afa55114be9) +++ tests/serialize.test (.../serialize.test) (revision b531a50ecc43d0c13e2432b099a436c3260c7a49) @@ -6,7 +6,7 @@ nx::Test case deepSerialize-map-filter { Object create ::a { - :property ref:object,type=[:info class] + :object property ref:object,type=[:info class] Object create [self]::b { [:info parent] ref [Object create [self]::c] } @@ -38,7 +38,7 @@ Object create ::a ::x::y::c eval { - :variable parentRef [[:info parent] info parent] + :object variable parentRef [[:info parent] info parent] } set script [::a eval { ::Serializer deepSerialize -map [list ::x::y [self] ::x [self]] ::x::y::c