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   58 use Carp;
  2         7  
  2         708  
5              
6             sub new {
7 2     2 0 11 my($type,%ids) = @_;
8 2         24 my($this) = bless {
9             Id2Sym => {},
10             Sym2Id => {},
11             IsPar => {},
12             }, $type;
13 2         13 $this->add_ids(%ids);
14 2         8 $this;
15             }
16              
17             sub add_ids {
18 4     4 0 13 my($this,%hash) = @_;
19 4         12 for(keys %hash) {
20 4         18 $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 8 my($this,%hash) = @_;
44 2         8 $this->add_ids(%hash);
45 2         7 for(keys %hash) {
46 2         8 $this->{IsPar}{$_} = 1;
47             }
48             }
49              
50             sub decl_locals {
51 2     2 0 6 my($this) = @_;
52 2         3 my $str;
53 2         4 for(keys %{$this->{Id2Sym}}) {
  2         18  
54 4 100       15 if(!$this->{IsPar}{$_}) {
55             $str .= $this->{Id2Sym}{$_}[1]
56 2         9 ->get_decl($this->{Id2Sym}{$_}[0]).";";
57             }
58             }
59 2         9 $str;
60             }
61              
62       0 0   sub get_params {
63             }
64              
65             sub get_symname {
66 106     106 0 181 my($this,$id) = @_;
67 106 50       209 confess "Symbol not found: $id\n" if(!defined($this->{Id2Sym}{$id}));
68 106         748 return $this->{Id2Sym}{$id}[0];
69             }
70              
71             1;