blib/lib/PDL/PP/SymTab.pm

filter: Statementstmt 100% 25 / 25 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 85.7% 6 / 7 Podpod n/a totaltotal 94.4% 34 / 36 CC 6 SCAR 7.0
CC
6
Cov
97%
decl_locals
3.0
get_symname
2.0
add_ids
2.0
CRAP 2.0
« blib/lib/PDL/Ops.pm ↑ Summary blib/lib/PDL/Config.pm »
1 # For making sure that no conflicts occur
2  
3 package SymTab;
4 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 sub new {
7 2 ▶ my($type,%ids) = @_;
Subroutine new: called CC=1 SCAR=0.0
8 2 my($this) = bless {
9 Id2Sym => {},
10 Sym2Id => {},
11 IsPar => {},
12 }, $type;
13 2 $this->add_ids(%ids);
14 2 $this;
15 }
16  
17 sub add_ids {
18 4 ▶ my($this,%hash) = @_;
Subroutine add_ids: called CC=2 SCAR=6.9
19 4 for(keys %hash) {
20 4 $this->{Id2Sym}{$_} = $hash{$_};
21
22 # This usually sets the 'undef' key to whatever is in $_, because the
23 # object in $hash{$_} is usually a scalar, not an array. I know this
24 # becuase this function is called by AddArgsyms in PDL::PP, which
25 # conructs the %hash to be
26 #
27 # sym_name => sym_name
28 #
29 # The only other place that invokes this code is the constructor,
30 # which itself is called by MkDefSyms in PDL::PP. That invocation is
31 # called with %hash set as
32 #
33 # _PDL_ThisTrans => ["__privtrans",C::Type->new(undef,"$_[0] *foo")]
34 #
35 # AFAIK, Sym2Id is never used anywhere in the code generation, and
36 # the setting of undef throws warning messages, so I am going to
37 # comment-out this line for now. --David Mertens, 12-12-2011
38 #$this->{Sym2Id}{$hash{$_}->[0]} = $_;
39 }
40 }
41  
42 sub add_params {
43 2 ▶ my($this,%hash) = @_;
Subroutine add_params: called CC=2 SCAR=6.9
44 2 $this->add_ids(%hash);
45 2 for(keys %hash) {
46 2 $this->{IsPar}{$_} = 1;
47 }
48 }
49  
50 sub decl_locals {
51 2 ▶ my($this) = @_;
Subroutine decl_locals: called CC=3 SCAR=11.0
52 2 my $str;
53 2 for(keys %{$this->{Id2Sym}}) {
54 4 ▶ if(!$this->{IsPar}{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($this->{"IsPar"}{$_}) 2 2 4
55 $str .= $this->{Id2Sym}{$_}[1]
56 2 ->get_decl($this->{Id2Sym}{$_}[0]).";";
57 }
58 }
59 2 $str;
60 }
61  
62 ▶sub get_params {
Subroutine get_params: not called CC=1 SCAR=0.0
63 }
64  
65 sub get_symname {
66 106 ▶ my($this,$id) = @_;
Subroutine get_symname: called CC=2 SCAR=7.1
67 106 ▶ confess "Symbol not found: $id\n" if(!defined($this->{Id2Sym}{$id}));
Branch: 1 branch
BranchTrueFalseTotal
unless defined $this->{"Id2Sym"}{$id} 0 106 106
68 106 return $this->{Id2Sym}{$id}[0];
69 }
70  
71 2 1;
« blib/lib/PDL/Ops.pm ↑ Summary blib/lib/PDL/Config.pm »