diff options
author | Iván Ávalos <avalos@disroot.org> | 2022-11-25 21:29:55 -0600 |
---|---|---|
committer | Iván Ávalos <avalos@disroot.org> | 2022-11-25 21:29:55 -0600 |
commit | 6b27930ef9c3eaede8d0c283ffa8376c40145f80 (patch) | |
tree | e2f2f8a25defb68283910edea33768054f435bc9 /compilador/astree/unit.py | |
parent | 4b2fad150a292f882cee408d7f9746715225f7cb (diff) | |
download | javanol-6b27930ef9c3eaede8d0c283ffa8376c40145f80.tar.gz javanol-6b27930ef9c3eaede8d0c283ffa8376c40145f80.tar.bz2 javanol-6b27930ef9c3eaede8d0c283ffa8376c40145f80.zip |
¡Otra vez hay renderizador de AST!
Diffstat (limited to 'compilador/astree/unit.py')
-rw-r--r-- | compilador/astree/unit.py | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/compilador/astree/unit.py b/compilador/astree/unit.py index 8ffdf19..c089214 100644 --- a/compilador/astree/unit.py +++ b/compilador/astree/unit.py @@ -1,9 +1,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: +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') |