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

io.joern.macros.QueryMacros.scala Maven / Gradle / Ivy

There is a newer version: 1.2.44
Show newest version
package io.joern.macros

import io.shiftleft.codepropertygraph.Cpg
import io.shiftleft.codepropertygraph.generated.nodes.StoredNode
import io.joern.console.TraversalWithStrRep
import overflowdb.traversal.Traversal

import scala.language.experimental.macros
import scala.reflect.macros.whitebox

object QueryMacros {

  def withStrRep(traversal: Cpg => Traversal[_ <: StoredNode]): TraversalWithStrRep = macro withStrRepImpl

  def withStrRepImpl(c: whitebox.Context)(traversal: c.Tree): c.Expr[TraversalWithStrRep] = {
    import c.universe._
    val fileContent               = new String(traversal.pos.source.content)
    val start                     = traversal.pos.start
    val end                       = traversal.pos.end
    val traversalAsString: String = fileContent.slice(start, end)

    c.Expr(q"""
        TraversalWithStrRep($traversal, $traversalAsString)
       """)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy