blob: 6f591179115503af18e83440b803a2b938018766 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
package AspectC::Repo;
use strict;
use warnings;
use 5.020;
use List::Util qw(first);
use XML::LibXML;
our $VERSION = '0.00';
my @source_loc_kind = (qw(none definition declaration));
my @function_kind = (
qw(unknown non_member static_non_member member
static_member virtual_member pure_virtual_member conctructor destructor
virtual_destructor pure_virtual_destructor)
);
my @pointcut_kind = (qw(normal virtual pure_virtual));
my @variable_kind
= (qw(unknown non_member static_non_member member static_member));
my @advice_code_kind = (qw(before after around));
my @advice_code_context
= (qw(none type obj type_obj vars type_vars obj_vars type_obj_vars));
my @cv_qualifiers = (qw(none const volatile const_volatile));
sub new {
my ( $class, %opt ) = @_;
my $self = \%opt;
$self->{xml}
= XML::LibXML->load_xml( location => '../kratos/src/repo.acp' );
bless( $self, $class );
$self->parse_xml;
return $self;
}
sub parse_xml {
my ($self) = @_;
my $xml = $self->{xml};
for my $node (
$xml->findnodes('/ac-model/files/TUnit | /ac-model/files/Header') )
{
my $filename = $node->getAttribute('filename');
my $id = $node->getAttribute('id');
if ( defined $id ) {
$self->{files}[$id] = $filename;
}
else {
say STDERR "repo.acp: File ${filename} has no ID";
}
}
for my $node (
$xml->findnodes('/ac-model/root/Namespace[@name="::"]/children/Class') )
{
my $class = {};
my $class_name = $node->getAttribute('name');
my $id = $node->getAttribute('id');
my @bases;
my @functions;
my @sources;
if ( my $base_str = $node->getAttribute('bases') ) {
@bases = split( qr{ }, $base_str );
}
for my $source ( $node->findnodes('./source/Source') ) {
push(
@sources,
{
file => $self->{files}[ $source->getAttribute('file') ],
kind => $source_loc_kind[ $source->getAttribute('kind') ],
}
);
}
$class->{name} = $class_name;
$class->{id} = $id;
$class->{sources} = [@sources];
for my $fnode ( $node->findnodes('./children/Function') ) {
my $name = $fnode->getAttribute('name');
my $id = $fnode->getAttribute('id') // q{?};
my $kind = $fnode->getAttribute('kind');
my $result_type = q{?};
my @args;
if ( my $typenode = ( $fnode->findnodes('./result_type/Type') )[0] )
{
$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 );
}
$self->{class}{$class_name} = $class;
}
for my $node (
$xml->findnodes(
'/ac-model/root/Namespace[@name="::"]/children/Variable')
)
{
my $sig_node = ( $node->findnodes('./type/Type') )[0];
my $kind = $node->getAttribute('kind');
my $name = $node->getAttribute('name');
my $signature = $sig_node->getAttribute('signature');
if ( $variable_kind[$kind] eq 'non_member' ) {
$self->{class_instance}{$signature} = $name;
}
}
return $self;
}
sub get_class_path_prefix {
my ( $self, $class_name ) = @_;
my $header = first { $_->{kind} eq 'definition' }
@{ $self->{class}{$class_name}{sources} };
$header = $header->{file};
$header =~ s{ \. h $ }{}x;
return $header;
}
sub get_class_instance {
my ( $self, $class_name ) = @_;
return $self->{class_instance}{$class_name};
}
1;
|