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