ruby: name nested compounds, to allow cpp_new etc

develop
jj 2012-04-27 17:59:54 +02:00
parent bc218db596
commit a7afe04f3b
2 changed files with 10 additions and 7 deletions

@ -328,8 +328,13 @@ sub render_item_compound {
my $cppns = $pns . '::' . $item->getAttribute('ld:typedef-name');
my $subtype = $item->getAttribute('ld:subtype');
my @namecomponents = split('::', $cppns);
shift @namecomponents;
my $classname = join('_', map { rb_ucase($_) } @namecomponents);
if (!$subtype || $subtype eq 'bitfield') {
push @lines_rb, "compound {";
push @lines_rb, "compound(:$classname) {";
indent_rb {
if (!$subtype) {
render_struct_fields($item, $cppns);
@ -339,10 +344,7 @@ sub render_item_compound {
};
push @lines_rb, "}"
} elsif ($subtype eq 'enum') {
my @namecomponents = split('::', $cppns);
shift @namecomponents;
my $enumclassname = join('_', map { rb_ucase($_) } @namecomponents);
push @lines_rb, "class ::DFHack::$enumclassname";
push @lines_rb, "class ::DFHack::$classname";
indent_rb {
# declare constants
render_enum_fields($item);
@ -350,7 +352,7 @@ sub render_item_compound {
push @lines_rb, "end\n";
# actual field
render_item_number($item, $enumclassname);
render_item_number($item, $classname);
} else {
print "no render compound $subtype\n";
}

@ -82,8 +82,9 @@ class Compound < MemStruct
def global(glob)
Global.new(glob)
end
def compound(&b)
def compound(name=nil, &b)
m = Class.new(Compound)
DFHack.const_set(name, m) if name
m.instance_eval(&b)
m.new
end