diff options
author | Daniel Friesel <derf@finalrewind.org> | 2017-05-16 15:48:34 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2017-05-16 15:48:34 +0200 |
commit | 458cf889e6ed331d9e5084cf8e199166ce983286 (patch) | |
tree | 11f070baffdb5589599d47985655881dc115681c /lib/AspectC | |
parent | 2531355bd6c7020904e889164efde3a5bb19631f (diff) |
autogenerate simple models (without args or parameters) from AC++ attributes
Diffstat (limited to 'lib/AspectC')
-rw-r--r-- | lib/AspectC/Repo.pm | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/lib/AspectC/Repo.pm b/lib/AspectC/Repo.pm index 6f59117..35bffbe 100644 --- a/lib/AspectC/Repo.pm +++ b/lib/AspectC/Repo.pm @@ -46,13 +46,33 @@ sub parse_xml { my $filename = $node->getAttribute('filename'); my $id = $node->getAttribute('id'); if ( defined $id ) { - $self->{files}[$id] = $filename; + $self->{files}{$id} = $filename; } else { say STDERR "repo.acp: File ${filename} has no ID"; } } + for my $aspect ( + $xml->findnodes( + '/ac-model/root/Namespace[@name="::"]/children/Aspect' + . ' | /ac-model/root/Namespace[@name="::"]/children/Namespace' + ) + ) + { + my $aspect_name = $aspect->getAttribute('name'); + for my $attr_node ( $aspect->findnodes('./children/Attribute') ) { + my $attr_name = $attr_node->getAttribute('name'); + my $attr_id = $attr_node->getAttribute('id'); + if ( defined $attr_id ) { + $self->{attributes}{$attr_id} = { + namespace => $aspect_name, + name => $attr_name, + }; + } + } + } + for my $node ( $xml->findnodes('/ac-model/root/Namespace[@name="::"]/children/Class') ) { @@ -70,7 +90,7 @@ sub parse_xml { push( @sources, { - file => $self->{files}[ $source->getAttribute('file') ], + file => $self->{files}{ $source->getAttribute('file') }, kind => $source_loc_kind[ $source->getAttribute('kind') ], } ); @@ -84,6 +104,7 @@ sub parse_xml { my $name = $fnode->getAttribute('name'); my $id = $fnode->getAttribute('id') // q{?}; my $kind = $fnode->getAttribute('kind'); + my $attributes = $fnode->getAttribute('attributes'); my $result_type = q{?}; my @args; @@ -92,12 +113,23 @@ sub parse_xml { $result_type = $typenode->getAttribute('signature'); } - #print "$id $name $kind $result_type <- "; for my $argnode ( $fnode->findnodes('./arg_types/Type') ) { push( @args, $argnode->getAttribute('signature') ); } - #say join( q{, }, @args ); + my $fun = { + name => $name, + returns => $result_type, + argtypes => [@args], + }; + + if ($attributes) { + $fun->{attributes} = [ + map { $self->{attributes}{$_}{name} } + split( qr{ \s+ }x, $attributes ) + ]; + } + $class->{function}{$name} = $fun; } $self->{class}{$class_name} = $class; } |