22
33from typing import Dict , List , AbstractSet , Tuple , Optional , Hashable
44
5- from ..objects .cfg_objects import Variable , CFGObjectConvertible
5+ from ..objects .formal_object import FormalObject
6+ from ..objects .cfg_objects import Variable
67
78
89class CFGVariableConverter :
910 """A CFG Variable Converter"""
1011
1112 def __init__ (self ,
12- states : AbstractSet [CFGObjectConvertible ],
13- stack_symbols : AbstractSet [CFGObjectConvertible ]) -> None :
13+ states : AbstractSet [FormalObject ],
14+ stack_symbols : AbstractSet [FormalObject ]) -> None :
1415 self ._counter = 0
15- self ._inverse_states_d : Dict [CFGObjectConvertible , int ] = {}
16+ self ._inverse_states_d : Dict [FormalObject , int ] = {}
1617 self ._counter_state = 0
1718 for self ._counter_state , state in enumerate (states ):
1819 self ._inverse_states_d [state ] = self ._counter_state
19- state .index_cfg_converter = self ._counter_state
20+ state .index = self ._counter_state
2021 self ._counter_state += 1
21- self ._inverse_stack_symbol_d : Dict [CFGObjectConvertible , int ] = {}
22+ self ._inverse_stack_symbol_d : Dict [FormalObject , int ] = {}
2223 self ._counter_symbol = 0
2324 for self ._counter_symbol , symbol in enumerate (stack_symbols ):
2425 self ._inverse_stack_symbol_d [symbol ] = self ._counter_symbol
25- symbol .index_cfg_converter = self ._counter_symbol
26+ symbol .index = self ._counter_symbol
2627 self ._counter_symbol += 1
2728 self ._conversions : List [List [List [Tuple [bool , Optional [Variable ]]]]] \
2829 = [[[(False , None ) for _ in range (len (states ))]
2930 for _ in range (len (stack_symbols ))] for _ in
3031 range (len (states ))]
3132
32- def _get_state_index (self , state : CFGObjectConvertible ) -> int :
33+ def _get_state_index (self , state : FormalObject ) -> int :
3334 """Get the state index"""
34- if state .index_cfg_converter is None :
35+ if state .index is None :
3536 if state not in self ._inverse_states_d :
3637 self ._inverse_states_d [state ] = self ._counter_state
3738 self ._counter_state += 1
38- state .index_cfg_converter = self ._inverse_states_d [state ]
39- return state .index_cfg_converter
39+ state .index = self ._inverse_states_d [state ]
40+ return state .index
4041
41- def _get_symbol_index (self , symbol : CFGObjectConvertible ) -> int :
42+ def _get_symbol_index (self , symbol : FormalObject ) -> int :
4243 """Get the symbol index"""
43- if symbol .index_cfg_converter is None :
44+ if symbol .index is None :
4445 if symbol not in self ._inverse_stack_symbol_d :
4546 self ._inverse_stack_symbol_d [symbol ] = self ._counter_symbol
4647 self ._counter_symbol += 1
47- symbol .index_cfg_converter = self ._inverse_stack_symbol_d [symbol ]
48- return symbol .index_cfg_converter
48+ symbol .index = self ._inverse_stack_symbol_d [symbol ]
49+ return symbol .index
4950
5051 def to_cfg_combined_variable (self ,
51- state0 : CFGObjectConvertible ,
52- stack_symbol : CFGObjectConvertible ,
53- state1 : CFGObjectConvertible ) -> Variable :
52+ state0 : FormalObject ,
53+ stack_symbol : FormalObject ,
54+ state1 : FormalObject ) -> Variable :
5455 """ Conversion used in the to_pda method """
5556 i_stack_symbol , i_state0 , i_state1 = self ._get_indexes (
5657 stack_symbol , state0 , state1 )
@@ -74,19 +75,19 @@ def _create_new_variable(self,
7475 return temp
7576
7677 def set_valid (self ,
77- state0 : CFGObjectConvertible ,
78- stack_symbol : CFGObjectConvertible ,
79- state1 : CFGObjectConvertible ) -> None :
78+ state0 : FormalObject ,
79+ stack_symbol : FormalObject ,
80+ state1 : FormalObject ) -> None :
8081 """Set valid"""
8182 i_stack_symbol , i_state0 , i_state1 = self ._get_indexes (
8283 stack_symbol , state0 , state1 )
8384 prev = self ._conversions [i_state0 ][i_stack_symbol ][i_state1 ]
8485 self ._conversions [i_state0 ][i_stack_symbol ][i_state1 ] = (True , prev [1 ])
8586
8687 def is_valid_and_get (self ,
87- state0 : CFGObjectConvertible ,
88- stack_symbol : CFGObjectConvertible ,
89- state1 : CFGObjectConvertible ) -> Optional [Variable ]:
88+ state0 : FormalObject ,
89+ stack_symbol : FormalObject ,
90+ state1 : FormalObject ) -> Optional [Variable ]:
9091 """Check if valid and get"""
9192 i_state0 = self ._get_state_index (state0 )
9293 i_stack_symbol = self ._get_symbol_index (stack_symbol )
@@ -102,9 +103,9 @@ def is_valid_and_get(self,
102103 return current [1 ]
103104
104105 def _get_indexes (self ,
105- stack_symbol : CFGObjectConvertible ,
106- state0 : CFGObjectConvertible ,
107- state1 : CFGObjectConvertible ) \
106+ stack_symbol : FormalObject ,
107+ state0 : FormalObject ,
108+ state1 : FormalObject ) \
108109 -> Tuple [int , int , int ]:
109110 i_state0 = self ._get_state_index (state0 )
110111 i_stack_symbol = self ._get_symbol_index (stack_symbol )
0 commit comments