Compiler upto invocation completed.
[trinary.git] / extended / Records.py
blobd1d312bfd24bf2e038e0264372b07cf7acbb4edc
2 import sys
3 import Node
5 class Records(object):
7 def __init__(self):
8 self.global_table = {}
9 self.local_table = {}
10 self.counter = 0
11 self.label_counter = 0
12 self.start_node = Node()
13 self.end_node = Node()
14 self.crnt_node = self.start_node
16 # counter access functions
17 def increment_counter(self):
18 self.counter = self.counter + 1
20 def reset_counter(self):
21 self.counter = 0
23 def get_counter(self):
24 return self.counter
26 def increment_label_counter(self):
27 self.label_counter = self.label_counter + 1
29 def get_label_counter(self):
30 return self.label_counter
32 # add to table functions
33 def add_to_global(self, key, value):
34 if key in self.global_table:
35 return False
36 self.global_table[key] = value
37 return True
39 def add_to_local(self, key, value):
40 return self.crnt_function.add_to_members(key, value)
42 # set local table
43 def set_local(self, function):
44 self.local_table = function.get_table()
45 self.crnt_function = function
47 # return the value of 'key' (if present) from the tables
48 def get_value(self, key, structure = False):
50 # find in structure
51 if structure != False and key in structure.in_members(key):
52 return structure.get_member(key)
54 # find in local table
55 elif key in self.local_table:
56 return self.local_table[key]
58 # find in global table
59 elif key in self.global_table:
60 return self.global_table[key]
62 else:
63 print "id '" + key + "' not defined"
64 raise SystemExit
66 # Function return value access functions
67 def get_func_ret(self):
68 return self.function_return_type
70 def set_func_ret(self, rtn_type):
71 self.fuction_return_type = rtn_type
73 # Number of parameters access functions
74 def set_num_params(self, num_params):
75 self.crnt_function.set_num_params(num_params)
77 def get_num_params(self):
78 return self.crnt_fuctions.get_num_params()
80 # current node access methods
81 def set_crnt_node(self, node):
82 self.crnt_node = node
84 def get_crnt_node(self):
85 return self.crnt_node
87 def get_start_node(self):
88 return self.start_node
90 def get_end_node(self):
91 return self.end_node