Class PythonExporter

java.lang.Object
ca.mcscert.jpipe.visitor.AbstractModelExporter
ca.mcscert.jpipe.visitor.PythonExporter
All Implemented Interfaces:
JustificationVisitor<Void>

public class PythonExporter extends AbstractModelExporter
Serialises a single JustificationModel to a Python module: each element becomes a decorated function named after the element's label (snake_case via LabelEscaper), carrying:
  • one or more @jpipe_link("<id>"), linking the function back to the originating jPipe element. An element that resulted from a merge is linked by the ids it was merged from rather than by its own, transitively, so a composition of a composition still names the ids as the original source models had them; ids unification minted along the way (unified_0) are left out, having been written in no source file. Every id is then shortened to the least qualified form that still designates the element unambiguously, but never past container:id, because a bare id would leave a reader of the generated module unable to tell what it refers to; see AbstractModelExporter.minimalLink(String).
  • @jpipe(produce=[], consume=[]) — placeholder decorators to be filled in by the developer.

Each function carries a docstring with the original element label so the full text is always recoverable regardless of escaping.

This visitor operates on one model at a time. Use SelectModel in the compilation pipeline to extract the desired model from a

invalid reference
Unit
before invoking this exporter.
  • Constructor Details

    • PythonExporter

      public PythonExporter()
  • Method Details

    • export

      public String export(JustificationModel<?> model)
      Serialise model to Python source text without a file header.
      Parameters:
      model - the justification or template to serialise.
      Returns:
      Python source text.
    • export

      public String export(JustificationModel<?> model, String sourcePath)
      Serialise model to Python source text, optionally prefixed with a generated-file header comment.
      Parameters:
      model - the justification or template to serialise.
      sourcePath - path of the originating .jd file, included in the header comment; may be null to omit the header.
      Returns:
      Python source text.
    • visit

      public Void visit(Conclusion conclusion)
      Emits nothing. The runner never executes a conclusion: it concludes one from whatever supports it, so a function here could never run and there is nothing for a developer to implement. The conclusion remains in the JSON and DOT exports, which describe the model rather than its execution.
    • visit

      public Void visit(SubConclusion subConclusion)
    • visit

      public Void visit(Strategy strategy)
    • visit

      public Void visit(Evidence evidence)
    • visit

      public Void visit(AbstractSupport abstractSupport)
    • exportModel

      protected void exportModel(JustificationModel<?> model)
      Description copied from class: AbstractModelExporter
      Performs the actual serialisation of model. Implementations must set AbstractModelExporter.currentModelName= model.getName() before calling any element visit methods.
      Specified by:
      exportModel in class AbstractModelExporter