Skip to content

Commit

Permalink
[swiftsrc2cpg] Added support for more missing operators and expressio…
Browse files Browse the repository at this point in the history
…ns (#4257)
  • Loading branch information
max-leuthaeuser authored Mar 1, 2024
1 parent a02559d commit f1a8fad
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,24 @@ 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)

private def astForClosureExprSyntax(node: ClosureExprSyntax): Ast = {
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)
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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 = {
Expand All @@ -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
Expand Down Expand Up @@ -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)
"<operator>.unknown"
Expand Down Expand Up @@ -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 "..." => "<operator>.splat"
case _ =>
notHandledYet(node.operator)
"<operator>.unknown"
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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 = {
Expand All @@ -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 =
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit f1a8fad

Please sign in to comment.