Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name := "joern"
ThisBuild / organization := "io.joern"
ThisBuild / scalaVersion := "3.7.4"

val cpgVersion = "1.7.66"
val cpgVersion = "1.7.65"

lazy val joerncli = Projects.joerncli
lazy val querydb = Projects.querydb
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ object Path {
val methodName = method.name
val statement = cfgNode match {
case _: MethodParameterIn =>
val paramsPretty =
method.parameter.toList.sortBy(_.index.getOrElse(Int.MaxValue)).map(_.code).mkString(", ")
val paramsPretty = method.parameter.toList.sortBy(_.index).map(_.code).mkString(", ")
s"$methodName($paramsPretty)"
case _ => cfgNode.statement.repr
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class ReachingDefFlowGraph(val method: Method) extends FlowGraph[CfgNode] {
val entryNode: CfgNode = method
val exitNode: CfgNode = method.methodReturn

private val params = method.parameter.sortBy(_.index.getOrElse(Int.MaxValue))
private val params = method.parameter.sortBy(_.index)
private val firstParam = params.headOption
private val lastParam = params.lastOption
private val firstOutputParam = firstParam.flatMap(_.asOutput.headOption)
private val lastOutputParam = method.parameter.sortBy(_.index.getOrElse(Int.MaxValue)).asOutput.lastOption
private val lastOutputParam = method.parameter.sortBy(_.index).asOutput.lastOption

private val lastActualCfgNode = exitNode.cfgIn.nextOption

Expand Down Expand Up @@ -109,13 +109,13 @@ class ReachingDefFlowGraph(val method: Method) extends FlowGraph[CfgNode] {
n.out(EdgeTypes.CFG).map(_.asInstanceOf[CfgNode]).l

private def nextParamOrBody(param: MethodParameterIn): List[CfgNode] = {
val nextParam = param.method.parameter.indexIfPresent(param.index.map(_ + 1)).headOption
val nextParam = param.method.parameter.index(param.index + 1).headOption
if (nextParam.isDefined) { nextParam.toList }
else { param.method.cfgFirst.l }
}

private def nextParamOutOrExit(paramOut: MethodParameterOut): List[CfgNode] = {
val nextParam = paramOut.method.parameter.indexIfPresent(paramOut.index.map(_ + 1)).asOutput.headOption
val nextParam = paramOut.method.parameter.index(paramOut.index + 1).asOutput.headOption
if (nextParam.isDefined) { nextParam.toList }
else { List(exitNode) }
}
Expand All @@ -131,13 +131,13 @@ class ReachingDefFlowGraph(val method: Method) extends FlowGraph[CfgNode] {
}

private def previousParamOrEntry(param: MethodParameterIn): List[CfgNode] = {
val prevParam = param.method.parameter.indexIfPresent(param.index.map(_ - 1)).headOption
val prevParam = param.method.parameter.index(param.index - 1).headOption
if (prevParam.isDefined) { prevParam.toList }
else { List(method) }
}

private def previousOutputParamOrLastNodeOfBody(paramOut: MethodParameterOut): List[CfgNode] = {
val prevParam = paramOut.method.parameter.indexIfPresent(paramOut.index.map(_ - 1)).asOutput.headOption
val prevParam = paramOut.method.parameter.index(paramOut.index - 1).asOutput.headOption
if (prevParam.isDefined) { prevParam.toList }
else { lastActualCfgNode.toList }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ object UsageSlicing {
slices.get(resolvedMethod).flatMap { calleeSlices =>
calleeSlices.find { s =>
s.targetObj match {
case p: ParamDef => p.position.contains(argIdx)
case p: ParamDef => p.position == argIdx
case _ => false
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,18 @@ package object slicing {
/** Represents data introduced via a parameter.
*
* @param position
* the index of the parameter, or None if the parameter has no positional index (e.g. keyword-only params).
* the index of the parameter.
*/
case class ParamDef(
name: String,
typeFullName: String,
position: Option[Int],
position: Integer,
lineNumber: Option[Int] = None,
columnNumber: Option[Int] = None,
label: String = "PARAM"
) extends DefComponent
derives ReadWriter {
override def toString: String = super.toString + position.map(pos => s" @ pos #$pos").getOrElse("")
override def toString: String = super.toString + s" @ pos #$position"
}

/** Represents data introduced by the return value of a call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class AbapIntegrationTests extends Abap2CpgSuite {

"set order equal to index on parsed method parameters" in {
val cpg = code(abapCode, fileName)
cpg.parameter.filter(!_.method.isExternal).l.foreach(p => p.index shouldBe Some(p.order))
cpg.parameter.filter(!_.method.isExternal).l.foreach(p => p.order shouldBe p.index)
}

"set isVariadic to false on all parameters" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class AstCreatorTests extends AbapCpgFixture {
"set index starting at 1 for first parameter" in {
val cpg = cpgForProgram(programWithMethod("MY_METHOD", importing = Seq(Parameter("IV_INPUT", "string"))))
val param = cpg.method.nameExact("MY_METHOD").parameter.nameExact("IV_INPUT").head
param.index shouldBe Some(1)
param.index shouldBe 1
}

"set order equal to index" in {
Expand Down Expand Up @@ -218,11 +218,11 @@ class AstCreatorTests extends AbapCpgFixture {
"set sequential indices for multiple parameters" in {
val cpg =
cpgForProgram(programWithMethod("MY_METHOD", importing = Seq(Parameter("IV_A", "i"), Parameter("IV_B", "i"))))
val params = cpg.method.nameExact("MY_METHOD").parameter.l.sortBy(_.order)
val params = cpg.method.nameExact("MY_METHOD").parameter.l.sortBy(_.index)
params(0).name shouldBe "IV_A"
params(0).index shouldBe Some(1)
params(0).index shouldBe 1
params(1).name shouldBe "IV_B"
params(1).index shouldBe Some(2)
params(1).index shouldBe 2
}
}

Expand Down Expand Up @@ -256,8 +256,8 @@ class AstCreatorTests extends AbapCpgFixture {
programWithMethod("MY_METHOD", importing = Seq(Parameter("IV_FIRST", "string"), Parameter("IV_SECOND", "int")))
)
val params = cpg.method.nameExact("MY_METHOD").parameter.l
params.find(_.name == "IV_FIRST").flatMap(_.index) shouldBe Some(1)
params.find(_.name == "IV_SECOND").flatMap(_.index) shouldBe Some(2)
params.find(_.name == "IV_FIRST").map(_.index) shouldBe Some(1)
params.find(_.name == "IV_SECOND").map(_.index) shouldBe Some(2)
}

"create a method return node" in {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,8 +358,7 @@ trait AstForFunctionsCreator { this: AstCreator =>
}
variadicParam.map { p =>
p.isVariadic = false
// C/C++ parameters always have positional indices; None is not expected here.
val index = p.index.get + 1
val index = p.index + 1
new FunctionDeclNodePass.ParameterInfo(
s"<param>$index",
s"<param>$index...",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class Cpp17FeaturesTests extends AstC2CpgSuite(fileSuffix = FileDefaults.CppExt)
argsParam.name shouldBe "args"
argsParam.typeFullName shouldBe "Args"
argsParam.isVariadic shouldBe true
argsParam.index shouldBe Some(1)
argsParam.index shouldBe 1
val List(retExpr) = cpg.method.nameExact("logicalAnd").ast.isReturn.astChildren.isCall.l
retExpr.name shouldBe "<operator>.fold"
retExpr.typeFullName shouldBe "bool"
Expand All @@ -161,7 +161,7 @@ class Cpp17FeaturesTests extends AstC2CpgSuite(fileSuffix = FileDefaults.CppExt)
argsParam.name shouldBe "args"
argsParam.typeFullName shouldBe "Args"
argsParam.isVariadic shouldBe true
argsParam.index shouldBe Some(1)
argsParam.index shouldBe 1
val List(retExpr) = cpg.method.nameExact("sum").ast.isReturn.astChildren.isCall.l
retExpr.name shouldBe "<operator>.fold"
retExpr.typeFullName shouldBe "Args"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class AstCreationPassTests extends AstC2CpgSuite {
a1.name shouldBe "a"
a1.code shouldBe "const char *a"
a1.typeFullName shouldBe "char*"
a1.index shouldBe Some(1)
a1.index shouldBe 1
a1.isVariadic shouldBe false
ellipsis1.name shouldBe "<param>2"
ellipsis1.code shouldBe "<param>2..."
ellipsis1.typeFullName shouldBe "char*"
ellipsis1.index shouldBe Some(2)
ellipsis1.index shouldBe 2
ellipsis1.isVariadic shouldBe true

val List(bar) = cpg.method("bar").l
Expand All @@ -57,12 +57,12 @@ class AstCreationPassTests extends AstC2CpgSuite {
a2.name shouldBe "a"
a2.code shouldBe "const char *a"
a2.typeFullName shouldBe "char*"
a2.index shouldBe Some(1)
a2.index shouldBe 1
a2.isVariadic shouldBe false
ellipsis2.name shouldBe "<param>2"
ellipsis2.code shouldBe "<param>2..."
ellipsis2.typeFullName shouldBe "char*"
ellipsis2.index shouldBe Some(2)
ellipsis2.index shouldBe 2
ellipsis2.isVariadic shouldBe true
}

Expand All @@ -89,12 +89,12 @@ class AstCreationPassTests extends AstC2CpgSuite {
a1.name shouldBe "a"
a1.code shouldBe "const char *a"
a1.typeFullName shouldBe "char*"
a1.index shouldBe Some(1)
a1.index shouldBe 1
a1.isVariadic shouldBe false
ellipsis1.name shouldBe "<param>2"
ellipsis1.code shouldBe "<param>2..."
ellipsis1.typeFullName shouldBe "char*"
ellipsis1.index shouldBe Some(2)
ellipsis1.index shouldBe 2
ellipsis1.isVariadic shouldBe true

val List(bar) = cpg.method("bar").l
Expand All @@ -104,12 +104,12 @@ class AstCreationPassTests extends AstC2CpgSuite {
a2.name shouldBe "a"
a2.code shouldBe "const char *a"
a2.typeFullName shouldBe "char*"
a2.index shouldBe Some(1)
a2.index shouldBe 1
a2.isVariadic shouldBe false
ellipsis2.name shouldBe "<param>2"
ellipsis2.code shouldBe "<param>2..."
ellipsis2.typeFullName shouldBe "char*"
ellipsis2.index shouldBe Some(2)
ellipsis2.index shouldBe 2
ellipsis2.isVariadic shouldBe true
}

Expand Down Expand Up @@ -144,12 +144,12 @@ class AstCreationPassTests extends AstC2CpgSuite {
x.code shouldBe "int x"
x.typeFullName shouldBe "int"
x.isVariadic shouldBe false
x.index shouldBe Some(1)
x.index shouldBe 1
args.name shouldBe "args"
args.code shouldBe "int*... args"
args.typeFullName shouldBe "int*"
args.isVariadic shouldBe true
args.index shouldBe Some(2)
args.index shouldBe 2
}
}
}
Expand All @@ -163,17 +163,17 @@ class AstCreationPassTests extends AstC2CpgSuite {
x.code shouldBe "int x"
x.typeFullName shouldBe "int"
x.isVariadic shouldBe false
x.index shouldBe Some(1)
x.index shouldBe 1
args.name shouldBe "args"
args.code shouldBe "int args"
args.typeFullName shouldBe "int"
args.isVariadic shouldBe false
args.index shouldBe Some(2)
args.index shouldBe 2
param3.name shouldBe "<param>3"
param3.code shouldBe "<param>3..."
param3.typeFullName shouldBe "int"
param3.isVariadic shouldBe true
param3.index shouldBe Some(3)
param3.index shouldBe 3
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class MethodTests extends C2CpgSuite {

"should be correct for pointer dereference parameter" in {
inside(cpg.method("foo").parameter.l) { case List(data) =>
data.index shouldBe Some(1)
data.index shouldBe 1
data.name shouldBe "data"
data.code shouldBe "int &data"
data.typeFullName shouldBe "int&"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ class ClassTypeTests extends C2CpgSuite(FileDefaults.CppExt) {
val List(thisP, p1, p2) = constructor.parameter.l
thisP.name shouldBe Defines.This
thisP.typeFullName shouldBe "FooT*"
thisP.index shouldBe Some(0)
thisP.index shouldBe 0
p1.typ.fullName shouldBe "std.string&"
p1.index shouldBe Some(1)
p1.index shouldBe 1
p2.typ.fullName shouldBe "Bar.SomeClass&"
p2.index shouldBe Some(2)
p2.index shouldBe 2
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ExtensionMethodTests extends CSharpCode2CpgFixture {
}

"have correct parameters" in {
inside(cpg.method.nameExact("DoStuff").parameter.l) { case myClass :: Nil =>
inside(cpg.method.nameExact("DoStuff").parameter.sortBy(_.index).l) { case myClass :: Nil =>
myClass.typeFullName shouldBe "MyClass"
myClass.code shouldBe "this MyClass myClass"
myClass.name shouldBe "myClass"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class LambdaTests extends CSharpCode2CpgFixture {
inside(anon.parameter.l) { case x :: Nil =>
x.name shouldBe "x"
x.typeFullName shouldBe DotNetTypeMap(BuiltinTypes.Int)
x.index shouldBe Some(1)
x.index shouldBe 1
}

}
Expand Down Expand Up @@ -65,11 +65,11 @@ class LambdaTests extends CSharpCode2CpgFixture {
inside(anon.parameter.l) { case x :: y :: Nil =>
x.name shouldBe "x"
x.typeFullName shouldBe DotNetTypeMap(BuiltinTypes.Int)
x.index shouldBe Some(1)
x.index shouldBe 1

y.name shouldBe "y"
y.typeFullName shouldBe DotNetTypeMap(BuiltinTypes.Int)
y.index shouldBe Some(2)
y.index shouldBe 2
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ParameterTests extends CSharpCode2CpgFixture {
args.name shouldBe "args"
args.typeFullName shouldBe "System.String[]"
args.code shouldBe "string[] args"
args.index shouldBe Some(1)
args.index shouldBe 1
args.isVariadic shouldBe false
}

Expand Down Expand Up @@ -47,19 +47,19 @@ class ParameterTests extends CSharpCode2CpgFixture {
thisNode.name shouldBe "this"
thisNode.typeFullName shouldBe "HelloWorld.Program"
thisNode.code shouldBe "this"
thisNode.index shouldBe Some(0)
thisNode.index shouldBe 0
thisNode.isVariadic shouldBe false

a.name shouldBe "a"
a.typeFullName shouldBe "System.String"
a.code shouldBe "string a"
a.index shouldBe Some(1)
a.index shouldBe 1
a.isVariadic shouldBe false

b.name shouldBe "b"
b.typeFullName shouldBe "System.Int32"
b.code shouldBe "int b"
b.index shouldBe Some(2)
b.index shouldBe 2
b.isVariadic shouldBe false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ class PropertySetterTests extends CSharpCode2CpgFixture {
}

"have correct parameters" in {
inside(cpg.method.nameExact("set_MyProperty").parameter.sortBy(_.order).l) { case thisArg :: valueArg :: Nil =>
thisArg.index shouldBe Some(0)
inside(cpg.method.nameExact("set_MyProperty").parameter.sortBy(_.index).l) { case thisArg :: valueArg :: Nil =>
thisArg.index shouldBe 0
thisArg.name shouldBe "this"
thisArg.typeFullName shouldBe "C"

valueArg.index shouldBe Some(1)
valueArg.index shouldBe 1
valueArg.name shouldBe "value"
valueArg.typeFullName shouldBe "System.Int32"
}
Expand Down Expand Up @@ -70,8 +70,8 @@ class PropertySetterTests extends CSharpCode2CpgFixture {
}

"have correct parameters" in {
inside(cpg.method.nameExact("set_MyProperty").parameter.l) { case valueArg :: Nil =>
valueArg.index shouldBe Some(1)
inside(cpg.method.nameExact("set_MyProperty").parameter.sortBy(_.index).l) { case valueArg :: Nil =>
valueArg.index shouldBe 1
valueArg.name shouldBe "value"
valueArg.typeFullName shouldBe "System.Int32"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ class TypeDeclMembersAndMemberMethodsTest extends GoCodeToCpgSuite {
cpg.parameter.name("re").size shouldBe 2
val List(thisParam, thisParamsec) = cpg.parameter.name("re").l
thisParam.order shouldBe 0
thisParam.index shouldBe Some(0)
thisParam.index shouldBe 0
thisParamsec.order shouldBe 0
thisParamsec.index shouldBe Some(0)
thisParamsec.index shouldBe 0
}

"Traversal from 'this'/receiver parameter to method node" in {
Expand Down
Loading
Loading