aboutsummaryrefslogtreecommitdiff
path: root/compilador/astree/unit.py
blob: c0892148ddd6cbe7e0b27d146c05ac8f1290a3d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import uuid
import graphviz as gv
from dataclasses import dataclass
from typing import List

from astree.graphable import Graphable
from astree.decl import Decl

# A single compilation unit, representing all of the members of a namespace.
@dataclass
class Unit(Graphable):
    decls: List[Decl]

    def graph(self, dot: gv.Digraph, parent: str = None, edge: str = None) -> None:
        name = uuid.uuid1().hex
        dot.node(name, 'Unit')
        if parent:
            dot.edge(name, parent, label = edge)
        for d in self.decls:
            if isinstance(d, Graphable):
                d.graph(dot, name, 'decl')