Skip to content

Commit 2f8b965

Browse files
fix broken astForAttributeSyntax (has been like this forever)
fix broken attribute diffgraph add
1 parent 11e4760 commit 2f8b965

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForDeclSyntaxCreator.scala

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -381,9 +381,6 @@ trait AstForDeclSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
381381
}
382382

383383
private def astForEnumCaseDeclSyntax(node: EnumCaseDeclSyntax): Ast = {
384-
val attributeAsts = node.attributes.children.map(astForNode)
385-
val modifiers = modifiersForDecl(node)
386-
387384
val bindingAsts = node.elements.children.map { binding =>
388385
val name = code(binding.name)
389386
val nLocalNode = localNode(binding, name, name, Defines.Any).order(0)
@@ -394,11 +391,15 @@ trait AstForDeclSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
394391
if (initAsts.isEmpty) {
395392
Ast()
396393
} else {
394+
val attributeAsts = node.attributes.children.map(astForNode)
395+
val modifiers = modifiersForDecl(node)
396+
397397
val patternAst = astForNode(binding.name)
398398
modifiers.foreach { mod =>
399399
patternAst.root.foreach { r => diffGraph.addEdge(r, mod, EdgeTypes.AST) }
400400
}
401401
attributeAsts.foreach { attrAst =>
402+
Ast.storeInDiffGraph(attrAst, diffGraph)
402403
patternAst.root.foreach { r => attrAst.root.foreach { attr => diffGraph.addEdge(r, attr, EdgeTypes.AST) } }
403404
}
404405
createAssignmentCallAst(binding, patternAst, initAsts.head, code(binding).stripSuffix(","))
@@ -962,14 +963,12 @@ trait AstForDeclSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
962963
diffGraph.addEdge(methodAstParentStack.head, methodNode_, EdgeTypes.AST)
963964
}
964965

965-
private def astForVariableDeclSyntax(node: VariableDeclSyntax, isTypeDeclMember: Boolean = false): Ast = {
966-
val attributeAsts = node.attributes.children.map(astForNode)
967-
val modifiers = node.modifiers.children.flatMap(c => astForNode(c).root.map(_.asInstanceOf[NewModifier]))
968-
val kind = code(node.bindingSpecifier)
966+
private def astForVariableDeclSyntax(variableDecl: VariableDeclSyntax, isTypeDeclMember: Boolean = false): Ast = {
967+
val kind = code(variableDecl.bindingSpecifier)
969968
val scopeType = if (kind == "let") { VariableScopeManager.ScopeType.BlockScope }
970969
else { VariableScopeManager.ScopeType.MethodScope }
971970

972-
val bindingAsts = node.bindings.children.flatMap { binding =>
971+
val bindingAsts = variableDecl.bindings.children.flatMap { binding =>
973972
val namesWithNode = binding.pattern match {
974973
case expr: ExpressionPatternSyntax =>
975974
notHandledYet(expr)
@@ -1015,12 +1014,17 @@ trait AstForDeclSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
10151014
Ast()
10161015
} else {
10171016
val patternAst = if (!isTypeDeclMember) {
1017+
val attributeAsts = variableDecl.attributes.children.map(astForNode)
1018+
val modifiers =
1019+
variableDecl.modifiers.children.flatMap(c => astForNode(c).root.map(_.asInstanceOf[NewModifier]))
1020+
10181021
val patternIdentifier = identifierNode(binding.pattern, cleanedName).typeFullName(typeFullName)
10191022
scope.addVariableReference(cleanedName, patternIdentifier, typeFullName, EvaluationStrategies.BY_REFERENCE)
10201023
modifiers.foreach { mod =>
10211024
diffGraph.addEdge(patternIdentifier, mod, EdgeTypes.AST)
10221025
}
10231026
attributeAsts.foreach { attrAst =>
1027+
Ast.storeInDiffGraph(attrAst, diffGraph)
10241028
attrAst.root.foreach { attr => diffGraph.addEdge(patternIdentifier, attr, EdgeTypes.AST) }
10251029
}
10261030
Ast(patternIdentifier)
@@ -1059,7 +1063,7 @@ trait AstForDeclSyntaxCreator(implicit withSchemaValidation: ValidationMode) {
10591063
case Nil => Ast()
10601064
case head :: Nil => head
10611065
case others =>
1062-
val block = blockNode(node, code(node), Defines.Any)
1066+
val block = blockNode(variableDecl, code(variableDecl), Defines.Any)
10631067
blockAst(block, others.toList)
10641068
}
10651069
}

joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForSyntaxCreator.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ trait AstForSyntaxCreator(implicit withSchemaValidation: ValidationMode) { this:
4545
val assign = NewAnnotationParameterAssign().code(code(argument))
4646
val assignChildren = List(Ast(parameter), argumentAst)
4747
setArgumentIndices(assignChildren)
48-
List(Ast(assign).withChild(Ast(parameter)).withChild(argumentAst))
48+
List(Ast(assign).withChildren(assignChildren))
4949
case None => Nil
5050
}
5151
val attributeCode = code(node)

0 commit comments

Comments
 (0)