File: SymTab.pm

package info (click to toggle)
pdl 2.005-4
  • links: PTS
  • area: main
  • in suites: potato
  • size: 4,200 kB
  • ctags: 3,301
  • sloc: perl: 14,876; ansic: 7,223; fortran: 3,417; makefile: 54; sh: 16
file content (54 lines) | stat: -rw-r--r-- 839 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# For making sure that no conflicts occur

package SymTab;
use Carp;

sub new {
	my($type,%ids) = @_;
	my($this) = bless {
		Id2Sym => {},
		Sym2Id => {},
		IsPar => {},
	}, $type;
	$this->add_ids(%ids);
	$this;
}

sub add_ids {
	my($this,%hash) = @_;
	for(keys %hash) {
		$this->{Id2Sym}{$_} = $hash{$_};
		$this->{Sym2Id}{$hash{$_}->[0]} = $_;
	}
}

sub add_params {
	my($this,%hash) = @_;
	$this->add_ids(%hash);
	for(keys %hash) {
		$this->{IsPar}{$_} = 1;
	}
}

sub decl_locals {
	my($this) = @_;
	my $str;
	for(keys %{$this->{Id2Sym}}) {
		if(!$this->{IsPar}{$_}) {
			$str .= $this->{Id2Sym}{$_}[1]
				   ->get_decl($this->{Id2Sym}{$_}[0]).";";
		}
	}
	$str;
}

sub get_params {
}

sub get_symname {
	my($this,$id) = @_;
	confess "Symbol not found: $id\n" if(!defined($this->{Id2Sym}{$id}));
	return $this->{Id2Sym}{$id}[0];
}

1;