All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.joern.x2cpg.layers.DumpAst.scala Maven / Gradle / Ivy

There is a newer version: 4.0.131
Show newest version
package io.joern.x2cpg.layers

import better.files.File
import io.shiftleft.semanticcpg.language.*
import io.shiftleft.semanticcpg.layers.{LayerCreator, LayerCreatorContext, LayerCreatorOptions}

case class AstDumpOptions(var outDir: String) extends LayerCreatorOptions {}

object DumpAst {

  val overlayName = "dumpAst"

  val description = "Dump abstract syntax trees to out/"

  def defaultOpts: AstDumpOptions = AstDumpOptions("out")
}

class DumpAst(options: AstDumpOptions) extends LayerCreator {
  override val overlayName: String       = DumpAst.overlayName
  override val description: String       = DumpAst.description
  override val storeOverlayName: Boolean = false

  override def create(context: LayerCreatorContext): Unit = {
    val cpg = context.cpg
    cpg.method.zipWithIndex.foreach { case (method, i) =>
      val str = method.dotAst.head
      (File(options.outDir) / s"$i-ast.dot").write(str)
    }
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy