File Coverage

blib/lib/PDLA/PP/SymTab.pm
Criterion Covered Total %
statement 24 24 100.0
branch 3 4 75.0
condition n/a
subroutine 6 7 85.7
pod 0 6 0.0
total 33 41 80.4


line stmt bran cond sub pod time code
1             # For making sure that no conflicts occur
2              
3             package PDLA::PP::SymTab;
4 2     2   71 use Carp;
  2         4  
  2         714  
5              
6             sub new {
7 2     2 0 42 my($type,%ids) = @_;
8 2         17 my($this) = bless {
9             Id2Sym => {},
10             Sym2Id => {},
11             IsPar => {},
12             }, $type;
13 2         20 $this->add_ids(%ids);
14 2         10 $this;
15             }
16              
17             sub add_ids {
18 4     4 0 12 my($this,%hash) = @_;
19 4         14 for(keys %hash) {
20 4         22 $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 PDLA::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 PDLA::PP. That invocation is
31             # called with %hash set as
32             #
33             # _PDLA_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     2 0 22 my($this,%hash) = @_;
44 2         11 $this->add_ids(%hash);
45 2         6 for(keys %hash) {
46 2         10 $this->{IsPar}{$_} = 1;
47             }
48             }
49              
50             sub decl_locals {
51 2     2 0 5 my($this) = @_;
52 2         4 my $str;
53 2         5 for(keys %{$this->{Id2Sym}}) {
  2         10  
54 4 100       13 if(!$this->{IsPar}{$_}) {
55             $str .= $this->{Id2Sym}{$_}[1]
56 2         7 ->get_decl($this->{Id2Sym}{$_}[0]).";";
57             }
58             }
59 2         10 $str;
60             }
61              
62       0 0   sub get_params {
63             }
64              
65             sub get_symname {
66 106     106 0 196 my($this,$id) = @_;
67 106 50       221 confess "Symbol not found: $id\n" if(!defined($this->{Id2Sym}{$id}));
68 106         723 return $this->{Id2Sym}{$id}[0];
69             }
70              
71             1;