Skip to content

Commit

Permalink
Emit more comments into the generated headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
angavrilov committed Jan 9, 2012
1 parent b880d22 commit 6586e72
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 14 deletions.
6 changes: 5 additions & 1 deletion Bitfield.pm
Expand Up @@ -28,6 +28,8 @@ sub render_bitfield_core {
my $mod = ($tag->nodeName eq 'ld:global-type' ? "$export_prefix extern" : 'static');
emit "$mod const bitfield_item_info ${name}_items_[sizeof($base)*8];";

emit_comment $tag, -attr => 1;

emit_block {
emit $base, ' whole;';

Expand All @@ -40,7 +42,9 @@ sub render_bitfield_core {
check_bad_attrs($item);
my $name = ensure_name $item->getAttribute('name');
my $size = $item->getAttribute('count') || 1;
emit "unsigned ", $name, " : ", $size, ";";

emit_comment $item;
emit "unsigned ", $name, " : ", $size, ";", get_comment($item);
}
} "struct ", " bits;";

Expand Down
43 changes: 43 additions & 0 deletions Common.pm
Expand Up @@ -26,6 +26,7 @@ BEGIN {
&ensure_name &with_anon
&fully_qualified_name
&get_comment &emit_comment
);
our %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
our @EXPORT_OK = qw( );
Expand Down Expand Up @@ -277,4 +278,46 @@ sub fully_qualified_name($$;$) {
return join('::',@names,$name);
}

# Comments

sub get_comment($) {
my ($tag) = @_;

return '' unless $tag;

if (my $val = $tag->getAttribute('comment')) {
return ' /*!< '.$val.' */';
} else {
return '';
}
}

sub emit_comment($;%) {
my ($tag,%flags) = @_;

return unless $tag;

my $val = $tag->findvalue('child::comment');

if ($flags{-attr}) {
my $attr = $tag->getAttribute('comment');
if ($attr && $val) {
$val = $attr."\n".$val;
} else {
$val ||= $attr;
}
}

if ($val) {
emit '/**';
for my $line (split(/\n/, $val)) {
$line =~ s/^\s*//;
$line =~ s/\s*$//;
next if $line eq '';
emit ' * ', $line;
}
emit ' */';
}
}

1;
5 changes: 4 additions & 1 deletion Enum.pm
Expand Up @@ -24,6 +24,8 @@ sub render_enum_core($$) {

my $base = 0;

emit_comment $tag, -attr => 1;

emit_block {
my @items = $tag->findnodes('child::enum-item');
my $idx = 0;
Expand All @@ -35,7 +37,8 @@ sub render_enum_core($$) {
$base = ($idx == 0) ? $value : undef if defined $value;
$idx++;

emit $name, (defined($value) ? ' = '.$value : ''), ',';
emit_comment $item;
emit $name, (defined($value) ? ' = '.$value : ''), ',', get_comment($item);
}

emit "_last_item_of_$name";
Expand Down
15 changes: 5 additions & 10 deletions StructFields.pm
Expand Up @@ -36,7 +36,9 @@ sub with_struct_block(&$;$%) {
my $kwd = (is_attr_true($tag,'is-union') ? "union" : "struct");
my $exp = $flags{-export} ? $export_prefix : '';
my $prefix = $kwd.' '.$exp.($name ? $name.' ' : '');


emit_comment $tag, -attr => 1;

emit_block {
local $_;
local $in_struct_body = 1;
Expand Down Expand Up @@ -208,19 +210,12 @@ sub render_struct_field($) {

# Otherwise, create the name if necessary, and render
my $field_name = $tag->getAttribute('name');
my $field_comment = $tag->getAttribute('comment');
my $name = ensure_name $field_name;
$tag->setAttribute('ld:anon-name', $name) unless $field_name;
with_anon {
my ($prefix, $postfix) = get_struct_field_type($tag, -local => 1);
if($field_comment)
{
emit $prefix, ' ', $name, $postfix, ';', ' /*!< ', $field_comment, ' */';
}
else
{
emit $prefix, ' ', $name, $postfix, ';';
}
emit_comment $tag;
emit $prefix, ' ', $name, $postfix, ';', get_comment($tag);
} "T_$name";
}

Expand Down
6 changes: 4 additions & 2 deletions StructType.pm
Expand Up @@ -164,11 +164,13 @@ sub render_virtual_methods {

my $ret_stmt = '';
unless ($ret_type eq 'void') {
$ret_stmt = ' return '.($ret_type =~ /\*$/ ? '0' : "$ret_type()").'; ';
$ret_stmt = ' return '.($ret_type =~ /\*$/ ? '0' : "$ret_type()").';';
}

emit_comment $method;
emit 'virtual ', ($is_destructor?'~':$ret_type.' '), $name,
'(', join(', ', @arg_strs), ') {', $ret_stmt, '}; //', $idx;
'(', join(', ', @arg_strs), ') {', $ret_stmt, ' /*', $idx, '*/ };',
get_comment($method);
} "anon_vmethod_$idx";
}
}
Expand Down

0 comments on commit 6586e72

Please sign in to comment.