ruby: generate accessors for refers-to and vector of ref-target

develop
jj 2012-06-27 14:52:34 +02:00
parent c2c29af959
commit 24aa3827c1
2 changed files with 59 additions and 10 deletions

@ -261,8 +261,7 @@ sub render_struct_fields {
};
push @lines_rb, "}";
my $reftg = $field->getAttribute('ref-target');
render_field_reftarget($type, $field, $name, $reftg) if ($reftg);
render_struct_field_refs($type, $field, $name);
}
}
@ -270,6 +269,24 @@ sub render_struct_fields {
}
}
# handle generating accessor for xml attributes ref-target, refers-to etc
sub render_struct_field_refs {
my ($parent, $field, $name) = @_;
my $reftg = $field->getAttribute('ref-target');
render_field_reftarget($parent, $field, $name, $reftg) if ($reftg);
my $refto = $field->getAttribute('refers-to');
render_field_refto($parent, $name, $refto) if ($refto);
my $meta = $field->getAttribute('ld:meta');
my $item = $field->findnodes('child::ld:item')->[0];
if ($meta and $meta eq 'container' and $item) {
my $itemreftg = $item->getAttribute('ref-target');
render_container_reftarget($parent, $item, $name, $itemreftg) if $itemreftg;
}
}
sub render_field_reftarget {
my ($parent, $field, $name, $reftg) = @_;
@ -280,20 +297,52 @@ sub render_field_reftarget {
return if (!$tg);
my $tgvec = $tg->getAttribute('instance-vector');
return if (!$tgvec);
$tgvec =~ s/\$global/df/;
render_field_refto($parent, $name, $tgvec);
}
sub render_field_refto {
my ($parent, $name, $tgvec) = @_;
$tgvec =~ s/^\$global/df/;
$tgvec =~ s/\[\$\]$//;
return if $tgvec !~ /^[\w\.]+$/;
my $tgname = "${name}_tg";
$tgname =~ s/_id_tg//;
$tgname =~ s/_id(.?.?)_tg/_tg$1/;
for my $otherfield ($parent->findnodes('child::ld:field')) {
my $othername = $otherfield->getAttribute('name');
for my $othername (map { $_->getAttribute('name') } $parent->findnodes('child::ld:field')) {
$tgname .= '_' if ($othername and $tgname eq $othername);
}
push @lines_rb, "def $tgname ; ${tgvec}[$name] ; end";
}
sub render_container_reftarget {
my ($parent, $item, $name, $reftg) = @_;
my $aux = $item->getAttribute('aux-value');
return if ($aux); # TODO
my $tg = $global_types{$reftg};
return if (!$tg);
my $tgvec = $tg->getAttribute('instance-vector');
return if (!$tgvec);
$tgvec =~ s/^\$global/df/;
$tgvec =~ s/\[\$\]$//;
return if $tgvec !~ /^[\w\.]+$/;
my $tgname = "${name}_tg";
$tgname =~ s/_id(.?.?)_tg/_tg$1/;
for my $othername (map { $_->getAttribute('name') } $parent->findnodes('child::ld:field')) {
$tgname .= '_' if ($othername and $tgname eq $othername);
}
push @lines_rb, "def $tgname ; $name.map { |i| ${tgvec}[i] } ; end";
}
sub render_class_vmethods {
my ($vms) = @_;
my $voff = 0;