Skip to content

Commit e2a493d

Browse files
authored
Factor out helper for printing CSubst in KCFGShow (#4809)
Related: #4808 This is part of an effort to refactor the `[APRProof|KCFG]Show` (and `Viewer`) heirarchy to allow more control in how states are rendered. This refactoring makse future refactorings simpler, and can be merged standalone as being feature-preserving.
1 parent af96f5e commit e2a493d

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

pyk/src/pyk/kcfg/tui.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from textual.app import ComposeResult
2525
from textual.events import Click
2626

27+
from ..cterm import CSubst
2728
from ..kast import KInner
2829
from ..ktool.kprint import KPrint
2930
from .show import NodePrinter
@@ -277,13 +278,23 @@ def _boolify(c: KInner) -> KInner:
277278
else:
278279
return c
279280

281+
def _boolify_print(c: KInner) -> str:
282+
return self._kprint.pretty_print(_boolify(c))
283+
280284
def _cterm_text(cterm: CTerm) -> tuple[str, str]:
281285
config = cterm.config
282286
constraints = map(_boolify, cterm.constraints)
283287
if self._minimize:
284288
config = minimize_term(config)
285289
return (self._kprint.pretty_print(config), '\n'.join(self._kprint.pretty_print(c) for c in constraints))
286290

291+
def _csubst_text(csubst: CSubst) -> tuple[str, str]:
292+
equalities = map(
293+
_boolify_print, flatten_label('#And', csubst.pred(sort_with=self._kprint.definition, constraints=False))
294+
)
295+
constraints = map(_boolify_print, flatten_label('#And', csubst.constraint))
296+
return '\n'.join(equalities), '\n'.join(constraints)
297+
287298
term_str = 'Term'
288299
constraint_str = 'Constraint'
289300
custom_str = 'Custom'
@@ -309,30 +320,18 @@ def _cterm_text(cterm: CTerm) -> tuple[str, str]:
309320
term_str, constraint_str = _cterm_text(crewrite)
310321

311322
elif type(self._element) is KCFG.Cover:
312-
subst_equalities = map(
313-
_boolify,
314-
flatten_label(
315-
'#And', self._element.csubst.pred(sort_with=self._kprint.definition, constraints=False)
316-
),
317-
)
318-
constraints = map(_boolify, flatten_label('#And', self._element.csubst.constraint))
319-
term_str = '\n'.join(self._kprint.pretty_print(se) for se in subst_equalities)
320-
constraint_str = '\n'.join(self._kprint.pretty_print(c) for c in constraints)
323+
term_str, constraint_str = _csubst_text(self._element.csubst)
321324

322325
elif type(self._element) is KCFG.Split:
323326
term_strs = [f'split: {shorten_hashes(self._element.source.id)}']
324327
for target_id, csubst in self._element.splits.items():
325328
term_strs.append('')
326329
term_strs.append(f' - {shorten_hashes(target_id)}')
327-
if len(csubst.subst) > 0:
328-
subst_equalities = map(
329-
_boolify,
330-
flatten_label('#And', csubst.pred(sort_with=self._kprint.definition, constraints=False)),
331-
)
332-
term_strs.extend(f' {self._kprint.pretty_print(cline)}' for cline in subst_equalities)
333-
if len(csubst.constraints) > 0:
334-
constraints = map(_boolify, flatten_label('#And', csubst.constraint))
335-
term_strs.extend(f' {self._kprint.pretty_print(cline)}' for cline in constraints)
330+
equalities_str, constraints_str = _csubst_text(csubst)
331+
if equalities_str != '#Top':
332+
term_strs.extend([f' {es}' for es in equalities_str.split('\n')])
333+
if constraints_str != '#Top':
334+
term_strs.extend([f' {es}' for es in constraints_str.split('\n')])
336335
term_str = '\n'.join(term_strs)
337336

338337
elif type(self._element) is KCFG.NDBranch:

0 commit comments

Comments
 (0)