<commit_before>package edu.utsa.tl13

import edu.utsa.tl13
import Parse._
import TypeCheck._

/** Contains code related to the DOT language */
object DOT {

  /** Represents a DOT graph
    *
    * @param name The name of the graph
    * @param items The attributes and relationships in the graph
    */
  case class Graph(val name: String, val items: Item*) {
    override def toString = ("digraph %s {\n"                          +
                             "  ordering=out;\n"                       +
                             "  node [shape = box, style = filled];\n" +
                             "%s"                                      +
                             "}").format(name, items.mkString)
  }

  /** Represents either a relationship or an attribute in a DOT graph */
  sealed abstract class Item

  /** Represents an attribute in a DOT graph
    *
    * @param node The name of the node
    * @param label The node's label
    * @param color The node color
    */
  case class Attribute(node: String, label: String, color: String) extends Item {
    override def toString =
      "  %s [label=\"%s\",fillcolor=\"%s\",shape=box]\n".format(node, label, color)
  }

  /** Represents a relationship in a DOT graph
    *
    * @param nodes The nodes in the graph
    */
  case class Relationship(nodes: String*) extends Item {
    override def toString = "  %s\n".format(nodes.mkString(" -> "))
  }

  /** Creates a map of [[Parse.Node]]'s to their children */
  private def mkLinkMap(node: Node): Map[Node,Seq[Node]] =
    node.prewalk(Map[Node,Seq[Node]]()) { (m,n) => m + (n -> n.children) }

  /** Gets a label for a DOT graph node */
  private def label(node: Node): String = node match {
      case _: ReadInt      => ":= readInt"
      case _: AsgnExpr     => ":="
      case _: If           => "if"
      case _: While        => "while"
      case _: WriteInt     => "writeInt"
      case _: Program      => "program"
      case _: TL13Int      => "int"
      case _: TL13Bool     => "bool"
      case _: TL13None     => "none"
      case _: StatementSeq => "stmt list"
      case _: Decls        => "decl list"
      case Ident(v)        => v
      case Op(v,_,_)       => v
      case Decl(v,_)       => v
      case Num(v)          => v
    }

  /** Gets a string representation of a [[Parse.Node]] suitable for use in a DOT graph */
  private def mkDOTNode(node: Node): String = ("n" + node.hashCode).replaceAll("n-", "n_")

  /** Creates DOT notation for a [[Parse.Program]]
    *
    * @param program The program
    * @param graphName Title for the graph<commit_msg>Fixed missing match case<commit_after>package edu.utsa.tl13

import edu.utsa.tl13
import Parse._
import TypeCheck._

/** Contains code related to the DOT language */
object DOT {

  /** Represents a DOT graph
    *
    * @param name The name of the graph
    * @param items The attributes and relationships in the graph
    */
  case class Graph(val name: String, val items: Item*) {
    override def toString = ("digraph %s {\n"                          +
                             "  ordering=out;\n"                       +
                             "  node [shape = box, style = filled];\n" +
                             "%s"                                      +
                             "}").format(name, items.mkString)
  }

  /** Represents either a relationship or an attribute in a DOT graph */
  sealed abstract class Item

  /** Represents an attribute in a DOT graph
    *
    * @param node The name of the node
    * @param label The node's label
    * @param color The node color
    */
  case class Attribute(node: String, label: String, color: String) extends Item {
    override def toString =
      "  %s [label=\"%s\",fillcolor=\"%s\",shape=box]\n".format(node, label, color)
  }

  /** Represents a relationship in a DOT graph
    *
    * @param nodes The nodes in the graph
    */
  case class Relationship(nodes: String*) extends Item {
    override def toString = "  %s\n".format(nodes.mkString(" -> "))
  }

  /** Creates a map of [[Parse.Node]]'s to their children */
  private def mkLinkMap(node: Node): Map[Node,Seq[Node]] =
    node.prewalk(Map[Node,Seq[Node]]()) { (m,n) => m + (n -> n.children) }

  /** Gets a label for a DOT graph node */
  private def label(node: Node): String = node match {
      case _: ReadInt      => ":= readInt"
      case _: AsgnExpr     => ":="
      case _: If           => "if"
      case _: While        => "while"
      case _: WriteInt     => "writeInt"
      case _: Program      => "program"
      case _: TL13Int      => "int"
      case _: TL13Bool     => "bool"
      case _: TL13None     => "none"
      case _: StatementSeq => "stmt list"
      case _: Decls        => "decl list"
      case BoolLit(v)      => v
      case Ident(v)        => v
      case Op(v,_,_)       => v
      case Decl(v,_)       => v
      case Num(v)          => v
    }

  /** Gets a string representation of a [[Parse.Node]] suitable for use in a DOT graph */
  private def mkDOTNode(node: Node): String = ("n" + node.hashCode).replaceAll("n-", "n_")

  /** Creates DOT notation for a [[Parse.Program]]
    *
    * @param program The program
    * @param graphName Title for the graph
{'fraction_non_alphanumeric': 0.12650028576871786, 'fraction_numerical': 0.0038102495713469233, 'mean_word_length': 1.87986834887548, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2341080', 'n_tokens_mistral': 1575, 'n_tokens_neox': 1534, 'n_words': 519}