}
push @{$vars->{include}}, "$FindBin::Bin/../lib";
+push @INC, dirname($apidef);
print Dumper($vars) if $vars->{verbose};
@list = grep {
$api->{output}->{"$_->{type}:$_->{name}"}++;
$res->{seen}->{"$_->{type}:$_->{name}"}++ == 0
- } $api->findMatches($inc);
+ } $api->findMatches($inc, $res->{ctx});
if ($inc->{type} eq 'func') {
my $def = $api->{index}->{'func:<default>'};
} @membersOutput;
my $res = {
+ ctx => $s,
library => [],
func => [],
define => [],
my $library = findTemplateName($api, api::optionValue('template', 'code:class=library', $obj, $def));
my $res = {
+ ctx => $obj,
library => [],
func => [],
init => [],
# first those directly referenced
foreach my $obj (grep { $_->{type} =~ m/call|struct|union/ } @{$api->{api}}) {
- my @list = $api->findMatches($obj);
+ my @list = $api->findMatches($obj, $obj);
print "gen ".($#list+1)." $obj->{type} $obj->{name}\n" if ($api->{vars}->{verbose} > 0);
foreach my $s (@list) {
$self->{data} = { %{$self->{data}}, %{$info} };
}
+ foreach my $p (@{$conf->{pragmas}}) {
+ if ($p->[0] eq '%require') {
+ require $p->[1];
+ }
+ }
+
analyseAPI($self);
preprocess($self);
sub findMatches {
my $api = shift;
my $inc = shift;
+ my $ctx = shift;
my $data = $api->{data};
- if ($inc->{match} eq 'func:<match-function>') {
- my $match = eval $inc->{literal};
+ if ($inc->{match} eq 'func:<matcher>') {
+ # or just last option?
+ my $code;
+
+ if (defined($inc->{literal})) {
+ $code = 'sub { '.$inc->{literal}.' }';
+ } else {
+ my @options = @{$inc->{options}};
+ $code = 'sub { '.$options[$#options].'(@_) }';
+ }
+
+ my $match = eval $code;
if (!defined($match)) {
die "unable to parse match function $inc->{match} $! $@";
}
- grep { $match->($_) } values %$data;
+ grep { $match->($_, $ctx) } grep { $_->{type} eq $inc->{type} } values %$data;
} else {
my $s = $data->{$inc->{match}};
next if ($inc->{type} eq 'library');
#print "? $inc->{regex}\n";
- foreach my $s (findMatches($api, $inc)) {
+ foreach my $s (findMatches($api, $inc, $obj)) {
my $n = "$s->{type}:$s->{name}";
print "+ $n\n";
}
} elsif ($obj->{type} =~ m/^(struct|union|call|func|enum|define)$/) {
#foreach my $n (grep { $_ =~ m/$obj->{regex}/ } keys %data) {
- foreach my $s (findMatches($api, $obj)) {
+ foreach my $s (findMatches($api, $obj, $obj)) {
my $n = "$s->{type}:$s->{name}";
$seen{$n}++;
# handle other types included/mark them no-output
$seen->{"$s->{type}:$s->{name}"} = 0;
- processLibrary($api, $seen, $obj);
+ processLibrary($api, $seen, $obj, $s);
}
}
my $api = shift;
my $seen = shift;
my $lib = shift;
+ my $ctx = shift;
my $data = $api->{data};
return if ($seen->{"$lib->{type}:$lib->{name}"}++);
print " $inc->{match}\n" if ($api->{vars}->{verbose} > 1);
if ($inc->{type} =~ m/func|call/on) {
- my @list = findMatches($api, $inc);
+ my @list = findMatches($api, $inc, $ctx);
#print 'inc='.Dumper($inc);
#print "match $inc->{regex} .options=".Dumper($inc->{options});
foreach my $l (grep { "$_->{type}:$_->{name}" =~ m/$inc->{regex}/ } @{$api->{api}}) {
# included libraries are never output directly
$l->{output} = 0;
- processLibrary($api, $seen, $l);
+ processLibrary($api, $seen, $l, $ctx);
}
} elsif ($inc->{type} =~ m/define|enum/on) {
# suppress direct output of anything included
- foreach my $c (findMatches($api, $inc)) {
+ foreach my $c (findMatches($api, $inc, $ctx)) {
$c->{output} = 0;
}
}
# apply requested options to specific objects (not defaults)
foreach my $obj (grep {$_->{type} =~ m/^(func|call|struct|union)$/} @{$api->{api}}) {
- my @list = findMatches($api, $obj);
+ my @list = findMatches($api, $obj, $obj);
if ($obj->{type} =~ m/func|call/) {
processTypeFunc($api, $seen, $obj, @list);
foreach my $lib (grep {$_->{type} eq 'library'} @{$api->{api}}) {
next if defined($lib->{output});
$lib->{output} = 1;
- processLibrary($api, $seen, $lib);
+ processLibrary($api, $seen, $lib, $lib);
}
# apply options for default object types
options => $options,
objects => [],
includes => [],
+ pragmas => [],
};
foreach my $path (@_) {
while (my $t = $tokeniser->next()) {
#print " $state $t\n";
if ($state == 0) {
- if ($t eq 'include') {
- my $file = findInclude($self, $tokeniser->next());
+ if ($t =~ m/^%/) {
+ my @pragma = ( $t );
+ my $a = $tokeniser->next();
- push @{$self->{includes}}, $file;
- $tokeniser->include($file);
+ while (defined($a) && $a ne ';') {
+ push @pragma, $a;
+ $a = $tokeniser->next();
+ }
+
+ if ($t eq '%include') {
+ my $file = findInclude($self, $pragma[1]);
+
+ print "including $file\n";
+
+ push @{$self->{includes}}, $file;
+ $tokeniser->include($file);
+ } else {
+ push @{$self->{pragmas}}, \@pragma;
+ }
} elsif ($tokeniser->{type} eq 'token') {
$target = { type => $t, options => [], items => [] };
push @$list, $target;