Coverage for lobster/tools/trlc/hierarchy_tree.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.10.5, created at 2025-08-27 13:02 +0000

1from collections import defaultdict 

2from typing import Dict, Set 

3from trlc import ast 

4 

5 

6HierarchyTree = Dict[ast.Record_Type, Set[ast.Record_Type]] 

7 

8 

9def build_children_lookup(symbol_table: ast.Symbol_Table) -> HierarchyTree: 

10 """Builds a lookup dictionary for child record types of each record type in the 

11 symbol table.""" 

12 lookup = defaultdict(set) 

13 for n_pkg in symbol_table.values(ast.Package): 

14 for n_typ in n_pkg.symbols.values(ast.Record_Type): 

15 if n_typ.parent: 

16 lookup[n_typ.parent].add(n_typ) 

17 return dict(lookup)