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: 4.0.131
Show newest version
package io.joern.macros

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

import scala.quoted.{Expr, Quotes}

object QueryMacros {

  inline def withStrRep(inline traversal: Cpg => Iterator[? <: StoredNode]): TraversalWithStrRep =
    ${ withStrRepImpl('{ traversal }) }

  private def withStrRepImpl(
    travExpr: Expr[Cpg => Iterator[? <: StoredNode]]
  )(using quotes: Quotes): Expr[TraversalWithStrRep] = {
    import quotes.reflect._
    val pos  = travExpr.asTerm.pos
    val code = Position(pos.sourceFile, pos.start, pos.end).sourceCode.getOrElse("N/A")
    '{ TraversalWithStrRep(${ travExpr }, ${ Expr(code) }) }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy