Skip to content

Commit

Permalink
minify the flatgraph diff by bringing various things in before the bi…
Browse files Browse the repository at this point in the history
…g merge (#4737)

* minify the flatgraph diff by bringing various things in before the big merge

* fmt

* revert accidental change
  • Loading branch information
mpollmeier committed Jul 5, 2024
1 parent 7abe33a commit dd3fb0d
Show file tree
Hide file tree
Showing 17 changed files with 41 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package io.joern.dataflowengineoss.queryengine

import io.shiftleft.codepropertygraph.generated.nodes.*
import io.shiftleft.semanticcpg.accesspath.*
import io.shiftleft.semanticcpg.language.{AccessPathHandling, toCallMethods}
import io.shiftleft.semanticcpg.language.*
import io.shiftleft.semanticcpg.utils.MemberAccess
import org.slf4j.LoggerFactory

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class CallTests extends C2CpgSuite {
"have the correct callIn" in {
val List(m) = cpg.method.nameNot("<global>").where(_.ast.isReturn.code(".*nullptr.*")).l
val List(c) = cpg.call.codeExact("b->GetObj()").l
c.callee.head shouldBe m
c.callee.l should contain(m)
val List(callIn) = m.callIn.l
callIn.code shouldBe "b->GetObj()"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type NamespaceToTypeMap = mutable.Map[String, mutable.Set[CSharpType]]
* @see
* [[CSharpProgramSummary.jsonToInitialMapping]] for generating initial mappings.
*/
case class CSharpProgramSummary(val namespaceToType: NamespaceToTypeMap, val imports: Set[String])
case class CSharpProgramSummary(namespaceToType: NamespaceToTypeMap, imports: Set[String])
extends ProgramSummary[CSharpType, CSharpMethod, CSharpField] {

def findGlobalTypes: Set[CSharpType] = namespaceToType.getOrElse(Constants.Global, Set.empty).toSet
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ abstract class FunctionPass(

override def generateParts(): Array[Function] = functions.toArray

implicit def intToIntegerOption(intOption: Option[Int]): Option[Integer] = intOption.map(intValue => {
implicit def intToIntegerOption(intOption: Option[Int]): Option[Int] = intOption.map(intValue => {
val integerValue = intValue
integerValue
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import ghidra.program.util.DefinedDataIterator
import io.joern.ghidra2cpg.*
import io.joern.ghidra2cpg.utils.Utils.*
import io.joern.ghidra2cpg.utils.{Decompiler, PCodeMapper}
import io.shiftleft.codepropertygraph.generated.Cpg
import io.shiftleft.codepropertygraph.generated.nodes.{NewBlock, NewMethod}
import io.shiftleft.codepropertygraph.generated.{EdgeTypes, nodes}
import io.shiftleft.codepropertygraph.generated.{Cpg, EdgeTypes, nodes}
import io.shiftleft.passes.ForkJoinParallelCpgPass

import scala.jdk.CollectionConverters.*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ import io.joern.ghidra2cpg.utils.Decompiler
import io.joern.ghidra2cpg.passes.FunctionPass
import io.joern.ghidra2cpg.processors.ArmProcessor
import io.joern.ghidra2cpg.utils.Utils.{checkIfExternal, createMethodNode, createReturnNode}
import io.shiftleft.codepropertygraph.generated.Cpg
import io.shiftleft.codepropertygraph.generated.nodes.NewBlock
import io.shiftleft.codepropertygraph.generated.{EdgeTypes, nodes}
import io.shiftleft.codepropertygraph.generated.{Cpg, EdgeTypes, nodes}

class ArmFunctionPass(
currentProgram: Program,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import io.shiftleft.semanticcpg.language.*
import io.shiftleft.semanticcpg.language.dotextension.ImageViewer
import io.shiftleft.semanticcpg.layers.*

import scala.compiletime.uninitialized
import scala.sys.process.Process
import scala.util.Try

class DataFlowBinToCpgSuite extends GhidraBinToCpgSuite {

implicit var context: EngineContext = scala.compiletime.uninitialized
implicit var context: EngineContext = uninitialized

override def beforeAll(): Unit = {
super.beforeAll()
Expand All @@ -33,7 +34,7 @@ class DataFlowBinToCpgSuite extends GhidraBinToCpgSuite {
new OssDataFlow(options).run(context)
}

protected implicit def int2IntegerOption(x: Int): Option[Integer] =
protected implicit def int2IntegerOption(x: Int): Option[Int] =
Some(x)

protected def getMemberOfType(cpg: Cpg, typeName: String, memberName: String): Iterator[Member] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,10 @@ class AstCreator(
.removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_COMMENTS))
.removeOption(new DefaultConfigurationOption(ConfigOption.PRINT_JAVADOC))

protected def line(node: Node): Option[Int] = node.getBegin.map(x => x.line).toScala
protected def column(node: Node): Option[Int] = node.getBegin.map(x => x.column).toScala
protected def lineEnd(node: Node): Option[Int] = node.getEnd.map(x => x.line).toScala
protected def columnEnd(node: Node): Option[Int] = node.getEnd.map(x => x.column).toScala
protected def line(node: Node): Option[Int] = node.getBegin.map(_.line).toScala
protected def column(node: Node): Option[Int] = node.getBegin.map(_.column).toScala
protected def lineEnd(node: Node): Option[Int] = node.getEnd.map(_.line).toScala
protected def columnEnd(node: Node): Option[Int] = node.getEnd.map(_.column).toScala
protected def code(node: Node): String = node.toString(codePrinterOptions)

private val lineOffsetTable = OffsetUtils.getLineOffsetTable(fileContent)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,7 @@ package io.joern.javasrc2cpg.util

import com.github.javaparser.resolution.declarations.ResolvedReferenceTypeDeclaration
import com.github.javaparser.resolution.types.ResolvedReferenceType
import io.joern.javasrc2cpg.typesolvers.TypeInfoCalculator.TypeConstants
import io.joern.x2cpg.{Ast, Defines}
import io.shiftleft.codepropertygraph.generated.{DispatchTypes, PropertyNames}
import io.shiftleft.codepropertygraph.generated.nodes.{NewCall, NewFieldIdentifier, NewMember}
import io.joern.x2cpg.Defines
import org.slf4j.LoggerFactory

import scala.collection.mutable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@ import org.scalatest.matchers.should.Matchers.*
import org.scalatest.wordspec.AnyWordSpec

import java.nio.file.{Files, Path, Paths}
import scala.compiletime.uninitialized
import scala.util.{Failure, Success, Try}

class JarUnpackingTests extends AnyWordSpec with Matchers with BeforeAndAfterAll {

var recurseCpgs: Map[String, Cpg] = scala.compiletime.uninitialized
var noRecurseCpgs: Map[String, Cpg] = scala.compiletime.uninitialized
var depthsCpgs: Map[String, Cpg] = scala.compiletime.uninitialized
var slippyCpg: Cpg = scala.compiletime.uninitialized
var recurseCpgs: Map[String, Cpg] = uninitialized
var noRecurseCpgs: Map[String, Cpg] = uninitialized
var depthsCpgs: Map[String, Cpg] = uninitialized
var slippyCpg: Cpg = uninitialized

override protected def beforeAll(): Unit = {
super.beforeAll()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.joern.rubysrc2cpg.astcreation

import io.shiftleft.codepropertygraph.generated.DiffGraphBuilder
import io.joern.rubysrc2cpg.astcreation.RubyIntermediateAst.*
import io.joern.rubysrc2cpg.datastructures.{BlockScope, NamespaceScope, RubyProgramSummary, RubyScope, RubyStubbedType}
import io.joern.rubysrc2cpg.parser.{RubyNodeCreator, RubyParser}
Expand Down Expand Up @@ -43,7 +44,7 @@ class AstCreator(
.map(_.stripPrefix(java.io.File.separator))
.getOrElse(fileName)

private def internalLineAndColNum: Option[Integer] = Option(1)
private def internalLineAndColNum: Option[Int] = Option(1)

/** The relative file name, in a unix path delimited format.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import io.joern.x2cpg.passes.frontend.XTypeRecovery.AllNodeTypesFromNodeExt
import io.shiftleft.codepropertygraph.generated.{Cpg, Operators, PropertyNames}
import io.shiftleft.codepropertygraph.generated.nodes.*
import io.shiftleft.semanticcpg.language.operatorextension.OpNodes.FieldAccess
import io.shiftleft.semanticcpg.language.{types, *}
import io.shiftleft.semanticcpg.language.*
import io.shiftleft.codepropertygraph.generated.DiffGraphBuilder

class RubyTypeRecoveryPassGenerator(cpg: Cpg, config: XTypeRecoveryConfig = XTypeRecoveryConfig())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class SingleAssignmentTests extends RubyCode2CpgFixture(withPostProcessing = tru
|""".stripMargin)
val source = cpg.literal.l
val sink = cpg.method.name("puts").callIn.argument.l
val flows = sink.reachableByFlows(source).map(flowToResultPairs).distinct.sortBy(_.length).l
val List(flow1, flow2, flow3, flow4, flow5) = flows
flow1 shouldBe List(("y = 1", 2), ("puts y", 3))
flow2 shouldBe List(("y = 1", 2), ("x = y = 1", 2), ("puts x", 4))
flow3 shouldBe List(("y = 1", 2), ("puts y", 3), ("puts x", 4))
flow4 shouldBe List(("y = 1", 2), ("x = y = 1", 2), ("z = x = y = 1", 2), ("puts z", 5))
flow5 shouldBe List(("y = 1", 2), ("x = y = 1", 2), ("puts x", 4), ("puts z", 5))
val flows = sink.reachableByFlows(source).map(flowToResultPairs).distinct.l
flows.size shouldBe 5
flows should contain(List(("y = 1", 2), ("puts y", 3)))
flows should contain(List(("y = 1", 2), ("x = y = 1", 2), ("puts x", 4)))
flows should contain(List(("y = 1", 2), ("puts y", 3), ("puts x", 4)))
flows should contain(List(("y = 1", 2), ("x = y = 1", 2), ("z = x = y = 1", 2), ("puts z", 5)))
flows should contain(List(("y = 1", 2), ("x = y = 1", 2), ("puts x", 4), ("puts z", 5)))
}

"flow through expressions" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ class MetaDataPassTests extends AnyWordSpec with Matchers {

"create a metadata node with correct language" in {
File.usingTemporaryDirectory("rubysrc2cpgTest") { dir =>
val config = Config().withInputPath(dir.pathAsString).withOutputPath(dir.pathAsString)
val cpg = new RubySrc2Cpg().createCpg(config).get
val config = Config()
.withInputPath(dir.createChild("dummyinputfile").pathAsString)
.withOutputPath(dir.createChild("dummyoutputfile").pathAsString)
val cpg = new RubySrc2Cpg().createCpg(config).get
cpg.metaData.language.l shouldBe List(Languages.RUBYSRC)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CallCpgTests extends RubyCode2CpgFixture(withPostProcessing = true, useDep

"test astChildren" taggedAs SameInNewFrontend in {
val callNode = cpg.call.name("foo").head
val children = callNode.astChildren
val children = callNode.astChildren.l
children.size shouldBe 2

val firstChild = children.head
Expand Down Expand Up @@ -62,7 +62,7 @@ class CallCpgTests extends RubyCode2CpgFixture(withPostProcessing = true, useDep

"test astChildren" in {
val callNode = cpg.call.name("foo").head
val children = callNode.astChildren
val children = callNode.astChildren.l
children.size shouldBe 3

val firstChild = children.head
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ class AstCreator(val config: Config, val global: Global, val parserResult: Parse
case null => notHandledYet(node)
}

override protected def line(node: SwiftNode): Option[Int] = node.startLine.map(Integer.valueOf)
override protected def column(node: SwiftNode): Option[Int] = node.startColumn.map(Integer.valueOf)
override protected def lineEnd(node: SwiftNode): Option[Int] = node.endLine.map(Integer.valueOf)
override protected def columnEnd(node: SwiftNode): Option[Int] = node.endColumn.map(Integer.valueOf)
override protected def line(node: SwiftNode): Option[Int] = node.startLine
override protected def column(node: SwiftNode): Option[Int] = node.startColumn
override protected def lineEnd(node: SwiftNode): Option[Int] = node.endLine
override protected def columnEnd(node: SwiftNode): Option[Int] = node.endColumn

private val lineOffsetTable =
OffsetUtils.getLineOffsetTable(Option(parserResult.fileContent))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,8 @@
package io.shiftleft.semanticcpg.language

import io.shiftleft.codepropertygraph.generated.nodes.{
Call,
Identifier,
Literal,
Local,
Method,
MethodParameterIn,
MethodParameterOut,
MethodRef,
MethodReturn,
StoredNode
}
import io.shiftleft.codepropertygraph.generated.nodes.*
import io.shiftleft.semanticcpg.NodeExtension
import io.shiftleft.semanticcpg.language.nodemethods.{
CallMethods,
IdentifierMethods,
LiteralMethods,
LocalMethods,
MethodMethods,
MethodParameterInMethods,
MethodParameterOutMethods,
MethodRefMethods,
MethodReturnMethods
}
import io.shiftleft.semanticcpg.language.nodemethods.*

trait NodeExtensionFinder {
def apply(n: StoredNode): Option[NodeExtension]
Expand Down

0 comments on commit dd3fb0d

Please sign in to comment.