The variable table frame. A frame of variable table stores the variables created in one block or scope. Parameters ---------- vars : Set[str] The set of variable names in the variable table frame.
| 171 | |
| 172 | |
| 173 | class VarTableFrame: |
| 174 | """The variable table frame. |
| 175 | A frame of variable table stores the variables created in one block or scope. |
| 176 | |
| 177 | Parameters |
| 178 | ---------- |
| 179 | vars : Set[str] |
| 180 | The set of variable names in the variable table frame. |
| 181 | """ |
| 182 | |
| 183 | vars: set[str] |
| 184 | |
| 185 | def __init__(self): |
| 186 | self.vars = set() |
| 187 | |
| 188 | def add(self, var: str): |
| 189 | """Add a new variable into variable table frame. |
| 190 | |
| 191 | Parameters |
| 192 | ---------- |
| 193 | var : str |
| 194 | The name of new variable. |
| 195 | """ |
| 196 | if var in self.vars: |
| 197 | raise ValueError(f"Variable {var} already defined in current scope") |
| 198 | self.vars.add(var) |
| 199 | |
| 200 | def pop_all(self, fn_pop: Callable[[str], None]): |
| 201 | """Pop out all variable in variable table frame. |
| 202 | |
| 203 | Parameters |
| 204 | ---------- |
| 205 | fn_pop : Callable[[str], None] |
| 206 | The methods to call when popping each variable. |
| 207 | """ |
| 208 | for var in self.vars: |
| 209 | fn_pop(var) |
| 210 | self.vars.clear() |
| 211 | |
| 212 | |
| 213 | class VarTable: |
no outgoing calls
no test coverage detected
searching dependent graphs…