diff --git a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForExprSyntaxCreator.scala b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForExprSyntaxCreator.scala index fe16e1bb3a13..cf0d07b65927 100644 --- a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForExprSyntaxCreator.scala +++ b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForExprSyntaxCreator.scala @@ -65,7 +65,10 @@ trait AstForExprSyntaxCreator(implicit withSchemaValidation: ValidationMode) { astForNode(node.literal) } - private def astForBorrowExprSyntax(node: BorrowExprSyntax): Ast = notHandledYet(node) + private def astForBorrowExprSyntax(node: BorrowExprSyntax): Ast = { + astForNodeWithFunctionReference(node.expression) + } + private def astForCanImportExprSyntax(node: CanImportExprSyntax): Ast = notHandledYet(node) private def astForCanImportVersionInfoSyntax(node: CanImportVersionInfoSyntax): Ast = notHandledYet(node) @@ -73,8 +76,13 @@ trait AstForExprSyntaxCreator(implicit withSchemaValidation: ValidationMode) { astForNodeWithFunctionReference(node) } - private def astForConsumeExprSyntax(node: ConsumeExprSyntax): Ast = notHandledYet(node) - private def astForCopyExprSyntax(node: CopyExprSyntax): Ast = notHandledYet(node) + private def astForConsumeExprSyntax(node: ConsumeExprSyntax): Ast = { + astForNodeWithFunctionReference(node.expression) + } + + private def astForCopyExprSyntax(node: CopyExprSyntax): Ast = { + astForNodeWithFunctionReference(node.expression) + } private def astForDeclReferenceExprSyntax(node: DeclReferenceExprSyntax): Ast = { val name = code(node) @@ -108,7 +116,7 @@ trait AstForExprSyntaxCreator(implicit withSchemaValidation: ValidationMode) { } private def astForForceUnwrapExprSyntax(node: ForceUnwrapExprSyntax): Ast = { - astForNode(node.expression) + astForNodeWithFunctionReference(node.expression) } private def createBuiltinStaticCall(callExpr: FunctionCallExprSyntax, callee: ExprSyntax, fullName: String): Ast = { @@ -220,7 +228,7 @@ trait AstForExprSyntaxCreator(implicit withSchemaValidation: ValidationMode) { } private def astForInOutExprSyntax(node: InOutExprSyntax): Ast = { - astForNode(node.expression) + astForNodeWithFunctionReference(node.expression) } private def astForInfixOperatorExprSyntax(node: InfixOperatorExprSyntax): Ast = { @@ -241,8 +249,12 @@ trait AstForExprSyntaxCreator(implicit withSchemaValidation: ValidationMode) { case "||=" => Operators.assignmentOr case "||" => Operators.logicalOr case "^=" => Operators.assignmentXor + case "&<<" => Operators.shiftLeft case "<<" => Operators.shiftLeft + case "&>>=" => Operators.assignmentArithmeticShiftRight + case "&>>" => Operators.arithmeticShiftRight case ">>" => Operators.arithmeticShiftRight + case "&<<=" => Operators.assignmentShiftLeft case "<<=" => Operators.assignmentShiftLeft case ">>=" => Operators.assignmentArithmeticShiftRight case ">>>=" => Operators.assignmentLogicalShiftRight @@ -272,6 +284,7 @@ trait AstForExprSyntaxCreator(implicit withSchemaValidation: ValidationMode) { case "!" => Operators.logicalNot case "^" => Operators.xor case "??" => Operators.elvis + case "~=" => Operators.in case _ => notHandledYet(node.operator) ".unknown" @@ -426,14 +439,17 @@ trait AstForExprSyntaxCreator(implicit withSchemaValidation: ValidationMode) { private def astForPrefixOperatorExprSyntax(node: PrefixOperatorExprSyntax): Ast = { val operatorMethod = code(node.operator) match { - case "-" => Operators.preDecrement - case "+" => Operators.preIncrement - case "~" => Operators.not - case "!" => Operators.logicalNot - case "<" => Operators.lessThan - case ">" => Operators.greaterThan - case "==" => Operators.equals - case "%" => Operators.modulo + case "-" => Operators.preDecrement + case "+" => Operators.preIncrement + case "~" => Operators.not + case "!" => Operators.logicalNot + case "..<" => Operators.lessThan + case "<" => Operators.lessThan + case "..>" => Operators.greaterThan + case ">" => Operators.greaterThan + case "==" => Operators.equals + case "%" => Operators.modulo + case "..." => ".splat" case _ => notHandledYet(node.operator) ".unknown" @@ -443,9 +459,15 @@ trait AstForExprSyntaxCreator(implicit withSchemaValidation: ValidationMode) { callAst(unaryCall, List(expressionAst)) } - private def astForRegexLiteralExprSyntax(node: RegexLiteralExprSyntax): Ast = notHandledYet(node) - private def astForSequenceExprSyntax(node: SequenceExprSyntax): Ast = notHandledYet(node) - private def astForSimpleStringLiteralExprSyntax(node: SimpleStringLiteralExprSyntax): Ast = notHandledYet(node) + private def astForRegexLiteralExprSyntax(node: RegexLiteralExprSyntax): Ast = notHandledYet(node) + + private def astForSequenceExprSyntax(node: SequenceExprSyntax): Ast = { + astForNode(node.elements) + } + + private def astForSimpleStringLiteralExprSyntax(node: SimpleStringLiteralExprSyntax): Ast = { + astForNode(node.segments) + } private def astForStringLiteralExprSyntax(node: StringLiteralExprSyntax): Ast = { astForNode(node.segments) @@ -566,7 +588,12 @@ trait AstForExprSyntaxCreator(implicit withSchemaValidation: ValidationMode) { } } - private def astForTypeExprSyntax(node: TypeExprSyntax): Ast = notHandledYet(node) + private def astForTypeExprSyntax(node: TypeExprSyntax): Ast = { + val nodeCode = code(node) + registerType(nodeCode) + Ast(identifierNode(node, nodeCode, dynamicTypeHints = Seq(nodeCode))) + } + private def astForUnresolvedAsExprSyntax(node: UnresolvedAsExprSyntax): Ast = notHandledYet(node) private def astForUnresolvedIsExprSyntax(node: UnresolvedIsExprSyntax): Ast = notHandledYet(node) private def astForUnresolvedTernaryExprSyntax(node: UnresolvedTernaryExprSyntax): Ast = notHandledYet(node) diff --git a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForSyntaxCollectionCreator.scala b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForSyntaxCollectionCreator.scala index 5335ce49fbd1..cfe26ec416d3 100644 --- a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForSyntaxCollectionCreator.scala +++ b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForSyntaxCollectionCreator.scala @@ -71,14 +71,21 @@ trait AstForSyntaxCollectionCreator(implicit withSchemaValidation: ValidationMod private def astForDifferentiabilityArgumentListSyntax(node: DifferentiabilityArgumentListSyntax): Ast = notHandledYet( node ) - private def astForDocumentationAttributeArgumentListSyntax(node: DocumentationAttributeArgumentListSyntax): Ast = - notHandledYet(node) - private def astForEffectsAttributeArgumentListSyntax(node: EffectsAttributeArgumentListSyntax): Ast = notHandledYet( - node - ) - private def astForEnumCaseElementListSyntax(node: EnumCaseElementListSyntax): Ast = notHandledYet(node) - private def astForEnumCaseParameterListSyntax(node: EnumCaseParameterListSyntax): Ast = notHandledYet(node) - private def astForExprListSyntax(node: ExprListSyntax): Ast = notHandledYet(node) + private def astForDocumentationAttributeArgumentListSyntax(node: DocumentationAttributeArgumentListSyntax): Ast = { + Ast(literalNode(node, code(node), Option(Defines.String))) + } + + private def astForEffectsAttributeArgumentListSyntax(node: EffectsAttributeArgumentListSyntax): Ast = { + Ast(literalNode(node, code(node), Option(Defines.String))) + } + + private def astForEnumCaseElementListSyntax(node: EnumCaseElementListSyntax): Ast = notHandledYet(node) + private def astForEnumCaseParameterListSyntax(node: EnumCaseParameterListSyntax): Ast = notHandledYet(node) + + private def astForExprListSyntax(node: ExprListSyntax): Ast = { + astForListSyntaxChildren(node, node.children) + } + private def astForFunctionParameterListSyntax(node: FunctionParameterListSyntax): Ast = notHandledYet(node) private def astForGenericArgumentListSyntax(node: GenericArgumentListSyntax): Ast = notHandledYet(node) private def astForGenericParameterListSyntax(node: GenericParameterListSyntax): Ast = notHandledYet(node) @@ -106,10 +113,14 @@ trait AstForSyntaxCollectionCreator(implicit withSchemaValidation: ValidationMod ) private def astForPrecedenceGroupNameListSyntax(node: PrecedenceGroupNameListSyntax): Ast = notHandledYet(node) private def astForPrimaryAssociatedTypeListSyntax(node: PrimaryAssociatedTypeListSyntax): Ast = notHandledYet(node) - private def astForSimpleStringLiteralSegmentListSyntax(node: SimpleStringLiteralSegmentListSyntax): Ast = - notHandledYet(node) - private def astForSpecializeAttributeArgumentListSyntax(node: SpecializeAttributeArgumentListSyntax): Ast = - notHandledYet(node) + + private def astForSimpleStringLiteralSegmentListSyntax(node: SimpleStringLiteralSegmentListSyntax): Ast = { + astForListSyntaxChildren(node, node.children) + } + + private def astForSpecializeAttributeArgumentListSyntax(node: SpecializeAttributeArgumentListSyntax): Ast = { + Ast(literalNode(node, code(node), Option(Defines.String))) + } private def astForStringLiteralSegmentListSyntax(node: StringLiteralSegmentListSyntax): Ast = { astForListSyntaxChildren(node, node.children) diff --git a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForSyntaxCreator.scala b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForSyntaxCreator.scala index 848ee14fbef1..5793b18ca912 100644 --- a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForSyntaxCreator.scala +++ b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForSyntaxCreator.scala @@ -75,8 +75,9 @@ trait AstForSyntaxCreator(implicit withSchemaValidation: ValidationMode) { this: private def astForAvailabilityLabeledArgumentSyntax(node: AvailabilityLabeledArgumentSyntax): Ast = notHandledYet( node ) - private def astForBackDeployedAttributeArgumentsSyntax(node: BackDeployedAttributeArgumentsSyntax): Ast = - notHandledYet(node) + private def astForBackDeployedAttributeArgumentsSyntax(node: BackDeployedAttributeArgumentsSyntax): Ast = { + Ast(literalNode(node, code(node), Option(Defines.String))) + } private def astForCatchClauseSyntax(node: CatchClauseSyntax): Ast = { astForListSyntaxChildren(node, List(node.catchItems, node.body)) @@ -166,9 +167,11 @@ trait AstForSyntaxCreator(implicit withSchemaValidation: ValidationMode) { this: private def astForDeinitializerEffectSpecifiersSyntax(node: DeinitializerEffectSpecifiersSyntax): Ast = notHandledYet( node ) - private def astForDerivativeAttributeArgumentsSyntax(node: DerivativeAttributeArgumentsSyntax): Ast = notHandledYet( - node - ) + + private def astForDerivativeAttributeArgumentsSyntax(node: DerivativeAttributeArgumentsSyntax): Ast = { + Ast(literalNode(node, code(node), Option(Defines.String))) + } + private def astForDesignatedTypeSyntax(node: DesignatedTypeSyntax): Ast = notHandledYet(node) private def astForDictionaryElementSyntax(node: DictionaryElementSyntax): Ast = { @@ -183,8 +186,11 @@ trait AstForSyntaxCreator(implicit withSchemaValidation: ValidationMode) { this: private def astForDifferentiabilityWithRespectToArgumentSyntax( node: DifferentiabilityWithRespectToArgumentSyntax ): Ast = notHandledYet(node) - private def astForDifferentiableAttributeArgumentsSyntax(node: DifferentiableAttributeArgumentsSyntax): Ast = - notHandledYet(node) + + private def astForDifferentiableAttributeArgumentsSyntax(node: DifferentiableAttributeArgumentsSyntax): Ast = { + Ast(literalNode(node, code(node), Option(Defines.String))) + } + private def astForDocumentationAttributeArgumentSyntax(node: DocumentationAttributeArgumentSyntax): Ast = notHandledYet(node) private def astForDynamicReplacementAttributeArgumentsSyntax(node: DynamicReplacementAttributeArgumentsSyntax): Ast = @@ -231,9 +237,11 @@ trait AstForSyntaxCreator(implicit withSchemaValidation: ValidationMode) { this: private def astForGenericRequirementSyntax(node: GenericRequirementSyntax): Ast = notHandledYet(node) private def astForGenericWhereClauseSyntax(node: GenericWhereClauseSyntax): Ast = notHandledYet(node) private def astForIfConfigClauseSyntax(node: IfConfigClauseSyntax): Ast = notHandledYet(node) - private def astForImplementsAttributeArgumentsSyntax(node: ImplementsAttributeArgumentsSyntax): Ast = notHandledYet( - node - ) + + private def astForImplementsAttributeArgumentsSyntax(node: ImplementsAttributeArgumentsSyntax): Ast = { + Ast(literalNode(node, code(node), Option(Defines.String))) + } + private def astForImportPathComponentSyntax(node: ImportPathComponentSyntax): Ast = notHandledYet(node) private def astForInheritanceClauseSyntax(node: InheritanceClauseSyntax): Ast = notHandledYet(node) private def astForInheritedTypeSyntax(node: InheritedTypeSyntax): Ast = notHandledYet(node) @@ -370,9 +378,13 @@ trait AstForSyntaxCreator(implicit withSchemaValidation: ValidationMode) { this: private def astForTypeAnnotationSyntax(node: TypeAnnotationSyntax): Ast = notHandledYet(node) private def astForTypeEffectSpecifiersSyntax(node: TypeEffectSpecifiersSyntax): Ast = notHandledYet(node) private def astForTypeInitializerClauseSyntax(node: TypeInitializerClauseSyntax): Ast = notHandledYet(node) + private def astForUnavailableFromAsyncAttributeArgumentsSyntax( node: UnavailableFromAsyncAttributeArgumentsSyntax - ): Ast = notHandledYet(node) + ): Ast = { + Ast(literalNode(node, code(node.message), Option(Defines.String))) + } + private def astForUnderscorePrivateAttributeArgumentsSyntax(node: UnderscorePrivateAttributeArgumentsSyntax): Ast = notHandledYet(node) private def astForVersionComponentSyntax(node: VersionComponentSyntax): Ast = notHandledYet(node) diff --git a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForTypeSyntaxCreator.scala b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForTypeSyntaxCreator.scala index 9e559e85403b..ceaea5e401d9 100644 --- a/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForTypeSyntaxCreator.scala +++ b/joern-cli/frontends/swiftsrc2cpg/src/main/scala/io/joern/swiftsrc2cpg/astcreation/AstForTypeSyntaxCreator.scala @@ -36,8 +36,11 @@ trait AstForTypeSyntaxCreator(implicit withSchemaValidation: ValidationMode) { private def astForMemberTypeSyntax(node: MemberTypeSyntax): Ast = notHandledYet(node) - private def astForMetatypeTypeSyntax(node: MetatypeTypeSyntax): Ast = - notHandledYet(node) + private def astForMetatypeTypeSyntax(node: MetatypeTypeSyntax): Ast = { + val nodeCode = code(node) + registerType(nodeCode) + Ast(identifierNode(node, nodeCode, dynamicTypeHints = Seq(nodeCode))) + } private def astForMissingTypeSyntax(node: MissingTypeSyntax): Ast = notHandledYet(node)