Skip to content

Commit

Permalink
More cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto committed Sep 17, 2023
1 parent 572c7bd commit e00167f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import de.fraunhofer.aisec.cpg.graph.statements.expressions.CallExpression
import de.fraunhofer.aisec.cpg.graph.statements.expressions.MemberExpression
import de.fraunhofer.aisec.cpg.graph.types.Type
import de.fraunhofer.aisec.cpg.passes.SymbolResolver
import java.util.regex.Pattern

/**
* A language trait is a feature or trait that is common to a group of programming languages. Any
Expand Down Expand Up @@ -130,7 +129,7 @@ interface HasComplexCallResolution : LanguageTrait {
fun refineInvocationCandidatesFromRecord(
recordDeclaration: RecordDeclaration,
call: CallExpression,
namePattern: Pattern,
name: String,
ctx: TranslationContext
): List<FunctionDeclaration>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ import de.fraunhofer.aisec.cpg.passes.inference.startInference
import de.fraunhofer.aisec.cpg.passes.order.DependsOn
import de.fraunhofer.aisec.cpg.processing.strategy.Strategy
import java.util.*
import java.util.regex.Pattern
import org.slf4j.Logger
import org.slf4j.LoggerFactory

Expand Down Expand Up @@ -804,35 +803,30 @@ open class SymbolResolver(ctx: TranslationContext) : ComponentPass(ctx) {

fun getInvocationCandidatesFromRecord(
recordDeclaration: RecordDeclaration?,
name: String?,
name: String,
call: CallExpression
): List<FunctionDeclaration> {
if (recordDeclaration == null) return listOf()

val namePattern =
Pattern.compile(
"(" +
Pattern.quote(recordDeclaration.name.toString()) +
Regex.escape(recordDeclaration.language?.namespaceDelimiter ?: "") +
")?" +
Pattern.quote(name)
)
return if (call.language is HasComplexCallResolution) {
(call.language as HasComplexCallResolution).refineInvocationCandidatesFromRecord(
recordDeclaration,
call,
namePattern,
name,
ctx
)
} else {
recordDeclaration.methods.filter {
namePattern.matcher(it.name).matches() && it.hasSignature(call.signature)
}
val scope = this.scopeManager.lookupScope(recordDeclaration)
val list =
this.scopeManager.resolve<FunctionDeclaration>(scope) {
it.name.lastPartsMatch(name) && it.hasSignature(call.signature)
}
return list
}
}

protected fun getInvocationCandidatesFromParents(
name: String?,
name: String,
call: CallExpression,
possibleTypes: Set<RecordDeclaration>
): List<FunctionDeclaration> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import de.fraunhofer.aisec.cpg.graph.statements.expressions.CallExpression
import de.fraunhofer.aisec.cpg.graph.types.*
import de.fraunhofer.aisec.cpg.passes.SymbolResolver
import de.fraunhofer.aisec.cpg.passes.resolveWithImplicitCast
import java.util.regex.Pattern
import kotlin.reflect.KClass
import org.neo4j.ogm.annotation.Transient

Expand Down Expand Up @@ -136,7 +135,7 @@ open class CLanguage :
override fun refineInvocationCandidatesFromRecord(
recordDeclaration: RecordDeclaration,
call: CallExpression,
namePattern: Pattern,
name: String,
ctx: TranslationContext
): List<FunctionDeclaration> = emptyList()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import de.fraunhofer.aisec.cpg.graph.statements.expressions.MemberCallExpression
import de.fraunhofer.aisec.cpg.graph.types.*
import de.fraunhofer.aisec.cpg.passes.*
import de.fraunhofer.aisec.cpg.passes.inference.startInference
import java.util.regex.Pattern
import org.neo4j.ogm.annotation.Transient

/** The C++ language. */
Expand Down Expand Up @@ -157,15 +156,13 @@ class CPPLanguage :
override fun refineInvocationCandidatesFromRecord(
recordDeclaration: RecordDeclaration,
call: CallExpression,
namePattern: Pattern,
name: String,
ctx: TranslationContext
): List<FunctionDeclaration> {
val invocationCandidate =
mutableListOf<FunctionDeclaration>(
*recordDeclaration.methods
.filter { m ->
namePattern.matcher(m.name).matches() && m.hasSignature(call.signature)
}
.filter { m -> m.name.lastPartsMatch(name) && m.hasSignature(call.signature) }
.toTypedArray()
)
if (invocationCandidate.isEmpty()) {
Expand All @@ -174,8 +171,8 @@ class CPPLanguage :
resolveWithDefaultArgs(
call,
recordDeclaration.methods.filter { m ->
(namePattern.matcher(m.name).matches() /*&& !m.isImplicit()*/ &&
call.signature.size < m.signatureTypes.size)
m.name.lastPartsMatch(name) /*&& !m.isImplicit()*/ &&
call.signature.size < m.signatureTypes.size
}
)
)
Expand All @@ -186,7 +183,7 @@ class CPPLanguage :
resolveWithImplicitCast(
call,
recordDeclaration.methods.filter { m ->
namePattern.matcher(m.name).matches() /*&& !m.isImplicit()*/
m.name.lastPartsMatch(name) /*&& !m.isImplicit()*/
}
)
)
Expand Down

0 comments on commit e00167f

Please sign in to comment.