blib/lib/PDL/PP/Dump.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 5 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 70 CC 8 SCAR 35.3
CC
8
Cov
0%
pp_def
56.0
import
6.0
printargs
2.0
CRAP 34.2
1  
2 =head1 NAME
3  
4 PDL::PP::Dump -- dump pp_xxx calls to stdout
5  
6 =head1 SYNOPSIS
7  
8 perl -MPDL::PP::Dump Basic/Ops/ops.pd
9  
10 =head1 DESCRIPTION
11  
12 The most basic PP script debugger thinkable.
13  
14 =head1 AUTHOR
15  
16 Christian Soeller <c.soeller@auckland.ac.nz> .
17  
18 =cut
19  
20 package PDL::PP::Dump;
21  
22 use Exporter;
23 @ISA = Exporter;
24  
25 @EXPORT = qw(pp_addhdr pp_addpm pp_bless pp_def pp_done pp_add_boot
26 pp_add_exported pp_addxs pp_add_isa pp_export_nothing
27 pp_core_importList pp_beginwrap pp_setversion
28 pp_addbegin pp_boundscheck pp_line_numbers
29 pp_deprecate_module);
30  
31 my $typecheck =0;
32  
33 sub import {
34 my ($pack,$arg) = @_;
35 $typecheck =1 if defined $arg && $arg =~ /^typecheck$/i;
36 @_ = ($pack);
37 goto &Exporter::import;
38 }
39
40 sub printargs {
41 my $name = shift;
42 print "$name(";
43 print join ',',map("'$_'",@_);
44 print ");\n";
45 }
46  
47 for (@EXPORT) {
48 if ($_ !~ /pp_def/) {
49 my $def = "sub $_ { printargs($_,\@_) unless \$typecheck }";
50 # print "defining =>\n$def\n";
51 eval($def);
52 }
53 }
54  
55 sub pp_def {
56 my($name,%hash) = @_;
57 use PDL::Types ':All';
58  
59 if ($typecheck) {
60 my @alltypes = ppdefs; my $jointypes = join '',@alltypes;
61 my $types = exists $hash{GenericTypes} ? $hash{GenericTypes} : [@alltypes];
62 for my $key (qw/Code BackCode/) {
63 if (exists $hash{$key}) {
64 while ($hash{$key} =~ s/\$T([a-zA-Z]+)\s*\(([^)]*)\)//) {
65 my ($mactypes,$alternatives) = ($1,$2);
66 # print "type macro ($mactypes) in $name\n";
67 my @mactypes = split '', $mactypes;
68 print "$name has extra types in macro: $mactypes vs $jointypes\n"
69 unless $mactypes =~ /^\s*[$jointypes]+\s*$/;
70 for my $gt (@$types) {
71 print "$name has no Macro for generic type $gt (has $mactypes)"
72 unless grep {$gt eq $_} @mactypes;
73 }
74 }
75 }
76 }
77 } else {
78 print "pp_def('$name',\n";
79 foreach (keys(%hash)) {
80 if ($_ =~ /(Generic)*Types/) {
81 print "$_ => [" . join(',',@{$hash{$_}}) . "]\n";
82 } else {
83 print "$_ =>\n'".$hash{$_}."',\n";
84 }
85 }
86 print ");\n";
87 }
88 }
89  
90 1;