Skip to content

Commit

Permalink
[c2cpg] Fix code string for locals from ICPPASTNamedTypeSpecifier (#5233
Browse files Browse the repository at this point in the history
)
  • Loading branch information
max-leuthaeuser authored Jan 17, 2025
1 parent 3ce044f commit fef49d1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,10 @@ trait AstCreatorHelper(implicit withSchemaValidation: ValidationMode) { this: As
}

private def typeForCPPAstNamedTypeSpecifier(s: ICPPASTNamedTypeSpecifier, stripKeywords: Boolean): String = {
val tpe = safeGetBinding(s).map(_.toString).getOrElse(s.getRawSignature)
val tpe = safeGetBinding(s) match {
case Some(binding) if stripKeywords => binding.toString
case _ => s.getRawSignature
}
cleanType(tpe, stripKeywords)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ class LocalQueryTests extends C2CpgSuite {
}

"local query example 2" should {
"allow to query for the local" in {
val cpg = code(
"""
|class Foo {
| static Foo* foo() {
| static Foo bar;
| return &bar;
| }
|}
|""".stripMargin,
"test.cpp"
)
val List(barLocal) = cpg.method.name("foo").local.nameExact("bar").l
barLocal.typeFullName shouldBe "Foo"
barLocal.code shouldBe "static Foo bar"
}
}

"local query example 3" should {
val cpg = code("""
| struct node {
| int value;
Expand Down

0 comments on commit fef49d1

Please sign in to comment.