Index: generic/predefined.h =================================================================== diff -u -r05f4b42f7615ea410b7ac33093f5b8382ce7e8c5 -r48d5751e9aeb6a4f388f6531a9248c1847b22cae --- generic/predefined.h (.../predefined.h) (revision 05f4b42f7615ea410b7ac33093f5b8382ce7e8c5) +++ generic/predefined.h (.../predefined.h) (revision 48d5751e9aeb6a4f388f6531a9248c1847b22cae) @@ -146,40 +146,39 @@ "::xotcl2::Class create ::xotcl::MetaSlot\n" "::xotcl::relation ::xotcl::MetaSlot superclass ::xotcl2::Class\n" "::xotcl::MetaSlot create ::xotcl::Slot\n" +"::xotcl::MetaSlot create ::xotcl::ObjectParameterSlot\n" +"::xotcl::relation ::xotcl::ObjectParameterSlot superclass ::xotcl::Slot\n" "::xotcl::MetaSlot __invalidateobjectparameter\n" -"proc ::xotcl::parameterFromSlot {slot name} {\n" +"::xotcl::ObjectParameterSlot method toParameterSyntax {name} {\n" "set objparamdefinition $name\n" "set methodparamdefinition \"\"\n" "set objopts [list]\n" "set methodopts [list]\n" -"if {[$slot exists required] && [$slot required]} {\n" +"if {[info exists :required] && ${:required}} {\n" "lappend objopts required\n" "lappend methodopts required}\n" -"if {[$slot exists type]} {\n" -"set type [$slot type]\n" -"if {[string match ::* $type]} {\n" -"lappend objopts object type=$type\n" -"lappend methodopts object type=$type} else {\n" -"lappend objopts $type\n" -"lappend methodopts $type}}\n" -"if {[$slot exists multivalued] && [$slot multivalued]} {\n" -"if {!([$slot exists type] && [$slot type] eq \"relation\")} {\n" +"if {[info exists :type]} {\n" +"if {[string match ::* ${:type}]} {\n" +"lappend objopts object type=${:type}\n" +"lappend methodopts object type=${:type}} else {\n" +"lappend objopts ${:type}\n" +"lappend methodopts ${:type}}}\n" +"if {[info exists :multivalued] && ${:multivalued}} {\n" +"if {!([info exists :type] && ${:type} eq \"relation\")} {\n" "lappend objopts multivalued} else {}}\n" -"if {[$slot exists arg]} {\n" -"lappend objopts arg=[$slot arg]\n" -"lappend methodopts arg=[$slot arg]}\n" -"if {[$slot exists default]} {\n" -"set arg [::xotcl::setinstvar $slot default]\n" +"if {[info exists :arg]} {\n" +"lappend objopts arg=${:arg}\n" +"lappend methodopts arg=${:arg}}\n" +"if {[info exists :default]} {\n" +"set arg ${:default}\n" "if {[string match {*\\[*\\]*} $arg]} {\n" -"lappend objopts substdefault}} elseif {[$slot exists initcmd]} {\n" -"set arg [::xotcl::setinstvar $slot initcmd]\n" +"lappend objopts substdefault}} elseif {[info exists :initcmd]} {\n" +"set arg ${:initcmd}\n" "lappend objopts initcmd}\n" -"if {[$slot exists methodname]} {\n" -"set methodname [$slot methodname]\n" -"set slotname [$slot name]\n" -"if {$methodname ne $slotname} {\n" -"lappend objopts arg=$methodname\n" -"lappend methodopts arg=$methodname}}\n" +"if {[info exists :methodname]} {\n" +"if {${:methodname} ne ${:name}} {\n" +"lappend objopts arg=${:methodname}\n" +"lappend methodopts arg=${:methodname}}}\n" "if {[llength $objopts] > 0} {\n" "append objparamdefinition :[join $objopts ,]}\n" "if {[llength $methodopts] > 0} {\n" @@ -189,12 +188,11 @@ "return [list oparam $objparamdefinition mparam $methodparamdefinition]}\n" "proc ::xotcl::parametersFromSlots {obj} {\n" "set parameterdefinitions [list]\n" -"set slots [::xotcl2::objectInfo slotobjects $obj]\n" -"foreach slot $slots {\n" +"foreach slot [::xotcl2::objectInfo slotobjects $obj] {\n" "if {[::xotcl::is $obj type ::xotcl::Object] &&\n" "([$slot name] eq \"mixin\" || [$slot name] eq \"filter\")} continue\n" "set name [namespace tail $slot]\n" -"array set \"\" [::xotcl::parameterFromSlot $slot $name]\n" +"array set \"\" [$slot toParameterSyntax $name]\n" "lappend parameterdefinitions -$(oparam)}\n" "return $parameterdefinitions}\n" "::xotcl2::Object protected method objectparameter {} {\n" @@ -207,6 +205,7 @@ "arg:initcmd,optional\n" "return $parameterdefinitions}\n" "::xotcl::MetaSlot create ::xotcl::MethodParameterSlot\n" +"::xotcl::relation ::xotcl::MethodParameterSlot superclass ::xotcl::Slot\n" "foreach cmd [info command ::xotcl::cmd::MethodParameterSlot::*] {\n" "::xotcl::alias ::xotcl::MethodParameterSlot [namespace tail $cmd] $cmd}\n" "::xotcl::MethodParameterSlot create ::xotcl::methodParameterSlot\n" @@ -215,7 +214,7 @@ "::xotcl2::Object create ${class}::slot}\n" "foreach att $definitions {\n" "if {[llength $att]>1} {foreach {att default} $att break}\n" -"::xotcl::Slot create ${class}::slot::$att\n" +"::xotcl::ObjectParameterSlot create ${class}::slot::$att\n" "if {[info exists default]} {\n" "::xotcl::setinstvar ${class}::slot::$att default $default\n" "unset default}\n" @@ -231,42 +230,43 @@ "unset default}}\n" "$class __invalidateobjectparameter}\n" "createBootstrapAttributeSlots ::xotcl::Slot {\n" +"{name}\n" +"{multivalued false}\n" +"{required false}\n" +"default\n" +"type}\n" +"createBootstrapAttributeSlots ::xotcl::ObjectParameterSlot {\n" "{name \"[namespace tail [::xotcl::self]]\"}\n" "{methodname}\n" "{domain \"[lindex [regexp -inline {^(.*)::slot::[^:]+$} [::xotcl::self]] 1]\"}\n" "{defaultmethods {get assign}}\n" "{manager \"[::xotcl::self]\"}\n" -"{multivalued false}\n" -"{per-object false}\n" -"{forward-per-object}\n" -"{required false}\n" -"default\n" -"type}\n" -"::xotcl::alias ::xotcl::Slot get ::xotcl::setinstvar\n" -"::xotcl::alias ::xotcl::Slot assign ::xotcl::setinstvar\n" -"::xotcl::Slot public method add {obj prop value {pos 0}} {\n" +"{per-object false}}\n" +"::xotcl::alias ::xotcl::ObjectParameterSlot get ::xotcl::setinstvar\n" +"::xotcl::alias ::xotcl::ObjectParameterSlot assign ::xotcl::setinstvar\n" +"::xotcl::ObjectParameterSlot public method 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 public method delete {-nocomplain:switch obj prop value} {\n" +"::xotcl::ObjectParameterSlot public method 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" "error \"$value is not a $prop of $obj (valid are: $old)\"}}\n" -"::xotcl::Slot method unknown {method args} {\n" +"::xotcl::ObjectParameterSlot method unknown {method args} {\n" "set methods [list]\n" "foreach m [:info callable] {\n" "if {[::xotcl2::Object info callable $m] ne \"\"} continue\n" "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 public method destroy {} {\n" +"::xotcl::ObjectParameterSlot public method destroy {} {\n" "if {${:domain} ne \"\" && [::xotcl::is ${:domain} object]} {\n" "${:domain} __invalidateobjectparameter}\n" "next}\n" -"::xotcl::Slot method init {args} {\n" +"::xotcl::ObjectParameterSlot protected method init {args} {\n" "if {${:domain} eq \"\"} {\n" "set :domain [::xotcl::self callingobject]}\n" "if {${:domain} ne \"\"} {\n" @@ -283,7 +283,7 @@ "{multivalued true}\n" "{type relation}\n" "{elementtype ::xotcl2::Class}}\n" -"::xotcl::relation ::xotcl::RelationSlot superclass ::xotcl::Slot\n" +"::xotcl::relation ::xotcl::RelationSlot superclass ::xotcl::ObjectParameterSlot\n" "::xotcl::alias ::xotcl::RelationSlot assign ::xotcl::relation\n" "::xotcl::RelationSlot protected method init {} {\n" "if {${:type} ne \"relation\"} {\n" @@ -322,26 +322,44 @@ "::xotcl::alias ${os}::Class::slot::superclass assign ::xotcl::relation\n" "::xotcl::RelationSlot create ${os}::Object::slot::class -multivalued false\n" "::xotcl::alias ${os}::Object::slot::class assign ::xotcl::relation\n" -"::xotcl::RelationSlot create ${os}::Object::slot::mixin \\\n" -"-methodname object-mixin\n" -"::xotcl::RelationSlot create ${os}::Object::slot::filter \\\n" -"-elementtype \"\"\n" -"::xotcl::RelationSlot create ${os}::Class::slot::mixin \\\n" -"-methodname class-mixin\n" -"::xotcl::RelationSlot create ${os}::Class::slot::filter \\\n" +"::xotcl::RelationSlot create ${os}::Object::slot::mixin -methodname object-mixin\n" +"::xotcl::RelationSlot create ${os}::Object::slot::filter -elementtype \"\"\n" +"::xotcl::RelationSlot create ${os}::Class::slot::mixin -methodname class-mixin\n" +"::xotcl::RelationSlot create ${os}::Class::slot::filter -elementtype \"\" \\\n" "-methodname filter-mixin\n" "::xotcl::RelationSlot create ${os}::Class::slot::object-mixin\n" -"::xotcl::RelationSlot create ${os}::Class::slot::object-filter \\\n" -"-elementtype \"\"}\n" +"::xotcl::RelationSlot create ${os}::Class::slot::object-filter -elementtype \"\"}\n" "::xotcl::register_system_slots ::xotcl2\n" +"proc ::xotcl::register_system_slots {} {}\n" "::xotcl::MetaSlot __invalidateobjectparameter\n" -"::xotcl::MetaSlot create ::xotcl::Attribute -superclass ::xotcl::Slot\n" +"::xotcl::MetaSlot create ::xotcl::Attribute -superclass ::xotcl::ObjectParameterSlot\n" "createBootstrapAttributeSlots ::xotcl::Attribute {\n" "{value_check once}\n" "initcmd\n" "valuecmd\n" "valuechangedcmd\n" "arg}\n" +"::xotcl::Attribute object method createFromParameterSyntax {target value default:optional} {\n" +"set opts [list]\n" +"set colonPos [string first : $value]\n" +"if {$colonPos == -1} {\n" +"set name $value} else {\n" +"set properties [string range $value [expr {$colonPos+1}] end]\n" +"set name [string range $value 0 [expr {$colonPos -1}]]\n" +"foreach property [split $properties ,] {\n" +"if {$property eq \"required\"} {\n" +"lappend opts -required 1} elseif {$property eq \"multivalued\"} {\n" +"lappend opts -multivalued 1} elseif {[string match type=* $property]} {\n" +"set type [string range $property 5 end]\n" +"if {![string match ::* $type]} {set type ::$type}} elseif {[string match arg=* $property]} {\n" +"set argument [string range $property 4 end]\n" +"lappend opts -arg $argument} else {\n" +"set type $property}}}\n" +"if {[info exists type]} {\n" +"lappend opts -type $type}\n" +"if {[info exists default]} {\n" +"lappend opts -default $default}\n" +"::xotcl::Attribute create ${target}::slot::$name {*}$opts}\n" "::xotcl::Attribute method __default_from_cmd {obj cmd var sub op} {\n" "$obj trace remove variable $var $op [list [::xotcl::self] [::xotcl::self proc] $obj $cmd]\n" "::xotcl::setinstvar $obj $var [$obj eval $cmd]}\n" @@ -375,15 +393,15 @@ "append __initcmd [subst -nocommands {\n" "if {[:exists ${:name}]} {set :__oldvalue(${:name}) [set :${:name}]}\\n}]}\n" "return $__initcmd}\n" -"::xotcl::Attribute method init {} {\n" +"::xotcl::Attribute protected method init {} {\n" "next ;# do first ordinary slot initialization\n" "set __initcmd \"\"\n" "if {[:exists default]} {} elseif [:exists initcmd] {\n" "append __initcmd \":trace add variable [list ${:name}] read \\\n" "\\[list [::xotcl::self] __default_from_cmd \\[::xotcl::self\\] [list [set :initcmd]]\\]\\n\"} elseif [:exists valuecmd] {\n" "append __initcmd \":trace add variable [list ${:name}] read \\\n" "\\[list [::xotcl::self] __value_from_cmd \\[::xotcl::self\\] [list [set :valuecmd]]\\]\"}\n" -"array set \"\" [::xotcl::parameterFromSlot [self] \"value\"]\n" +"array set \"\" [:toParameterSyntax \"value\"]\n" "if {$(mparam) ne \"\"} {\n" "if {[info exists :multivalued] && ${:multivalued}} {\n" ":method assign [list obj var value:$(mparam),multivalued] {::xotcl::setinstvar $obj $var $value}\n" @@ -394,83 +412,32 @@ "\\[list [::xotcl::self] __value_changed_cmd \\[::xotcl::self\\] [list [set :valuechangedcmd]]\\]\"}\n" "if {$__initcmd ne \"\"} {\n" "set :initcmd $__initcmd}}\n" -"::xotcl2::Class create ::xotcl::Slot::Nocheck {\n" +"::xotcl2::Class create ::xotcl::ObjectParameterSlot::Nocheck {\n" ":method check_single_value args {;}\n" ":method check_multiple_values args {;}\n" ":method mk_type_checker args {return \"\"}}\n" -"::xotcl2::Class create ::xotcl::Slot::Optimizer {\n" +"::xotcl2::Class create ::xotcl::ObjectParameterSlot::Optimizer {\n" ":method method args {::xotcl::next; :optimize}\n" ":method forward args {::xotcl::next; :optimize}\n" -":method init args {::xotcl::next; :optimize}\n" +":protected method init args {::xotcl::next; :optimize}\n" ":public method 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" -"if {[:info callable -which get] ne \"::xotcl::Slot alias get ::xotcl::setinstvar\"} return\n" +"if {[:info callable -which assign] ne \"::xotcl::ObjectParameterSlot alias assign ::xotcl::setinstvar\"} return\n" +"if {[:info callable -which get] ne \"::xotcl::ObjectParameterSlot alias get ::xotcl::setinstvar\"} return\n" "::xotcl::setter ${:domain} {*}[expr {${:per-object} ? \"-per-object\" : \"\"}] ${:name}}}\n" -"::xotcl::Attribute mixin add ::xotcl::Slot::Optimizer\n" +"::xotcl::Attribute mixin add ::xotcl::ObjectParameterSlot::Optimizer\n" "::xotcl2::Class public method parameter arglist {\n" "if {![::xotcl::is [::xotcl::self]::slot object]} {\n" "::xotcl2::Object create [::xotcl::self]::slot}\n" "foreach arg $arglist {\n" -"set l [llength $arg]\n" -"set name [lindex $arg 0]\n" -"set opts [list]\n" -"set colonPos [string first : $name]\n" -"if {$colonPos > -1} {\n" -"set properties [string range $name [expr {$colonPos+1}] end]\n" -"set name [string range $name 0 [expr {$colonPos -1}]]\n" -"foreach property [split $properties ,] {\n" -"if {$property eq \"required\"} {\n" -"lappend opts -required 1} elseif {$property eq \"multivalued\"} {\n" -"lappend opts -multivalued 1} elseif {[string match type=* $property]} {\n" -"set type [string range $property 5 end]\n" -"if {![string match ::* $type]} {set type ::$type}} elseif {[string match arg=* $property]} {\n" -"set argument [string range $property 4 end]\n" -"lappend opts -arg $argument} else {\n" -"set type $property}}}\n" -"if {[info exists type]} {\n" -"lappend opts -type $type\n" -"unset type}\n" -"set cmd [list ::xotcl::Attribute create [::xotcl::self]::slot::$name {*}$opts]\n" -"if {$l == 1} {\n" -"eval $cmd} elseif {$l == 2} {\n" -"lappend cmd -default [lindex $arg 1]\n" -"eval $cmd} elseif {$l == 3 && [lindex $arg 1] eq \"-default\"} {\n" -"lappend cmd -default [lindex $arg 2]\n" -"eval $cmd} else {\n" -"set paramstring [string range $arg [expr {[string length $name]+1}] end]\n" -"if {[string match {[$\\[]*} $paramstring]} {\n" -"lappend cmd -default $paramstring\n" -"eval $cmd\n" -"continue}\n" -"set po ::xotcl2::Class::Parameter\n" -"puts stderr \"deprecated parameter usage '$arg'; use '-slots {Attribute ...}' instead\"\n" -"set cl [::xotcl::self]\n" -"::xotcl::setinstvar $po name $name\n" -"::xotcl::setinstvar $po cl [::xotcl::self]\n" -"::eval $po configure [lrange $arg 1 end]\n" -"if {[$po exists extra] || [$po exists setter] ||\n" -"[$po exists getter] || [$po exists access]} {\n" -"::xotcl::importvar $po extra setter getter access defaultParam\n" -"if {![info exists extra]} {set extra \"\"}\n" -"if {![info exists defaultParam]} {set defaultParam \"\"}\n" -"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 public method $name args \"\n" -"if {\\[llength \\$args] == 0} {\n" -"return \\[$access $getter $extra $name\\]} else {\n" -"return \\[eval $access $setter $extra $name \\$args $defaultParam \\]}\"\n" -"foreach instvar {extra defaultParam setter getter access} {\n" -"$po unset -nocomplain $instvar}} else {\n" -".setter $name}}}\n" +"::xotcl::Attribute createFromParameterSyntax [self] {*}$arg}\n" "::xotcl::setinstvar [::xotcl::self]::slot __parameter $arglist}\n" "proc createBootstrapAttributeSlots {} {}}\n" "::xotcl2::Class create ::xotcl::ScopedNew -superclass ::xotcl2::Class -parameter {\n" "{withclass ::xotcl2::Object}\n" "inobject}\n" -"::xotcl::ScopedNew method init {} {\n" +"::xotcl::ScopedNew protected method init {} {\n" ":public method new {-childof args} {\n" "::xotcl::importvar [::xotcl::self class] {inobject object} withclass\n" "if {![::xotcl::is $object object]} {\n"