diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/LanguageTraits.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/LanguageTraits.kt index a02976fd9d..e1c6e677cb 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/LanguageTraits.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/LanguageTraits.kt @@ -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 @@ -130,7 +129,7 @@ interface HasComplexCallResolution : LanguageTrait { fun refineInvocationCandidatesFromRecord( recordDeclaration: RecordDeclaration, call: CallExpression, - namePattern: Pattern, + name: String, ctx: TranslationContext ): List } diff --git a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt index 2d7512845c..7e41af3b62 100644 --- a/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt +++ b/cpg-core/src/main/kotlin/de/fraunhofer/aisec/cpg/passes/SymbolResolver.kt @@ -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 @@ -804,35 +803,30 @@ open class SymbolResolver(ctx: TranslationContext) : ComponentPass(ctx) { fun getInvocationCandidatesFromRecord( recordDeclaration: RecordDeclaration?, - name: String?, + name: String, call: CallExpression ): List { 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(scope) { + it.name.lastPartsMatch(name) && it.hasSignature(call.signature) + } + return list } } protected fun getInvocationCandidatesFromParents( - name: String?, + name: String, call: CallExpression, possibleTypes: Set ): List { diff --git a/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CLanguage.kt b/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CLanguage.kt index fc41a178dc..041f884d3e 100644 --- a/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CLanguage.kt +++ b/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CLanguage.kt @@ -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 @@ -136,7 +135,7 @@ open class CLanguage : override fun refineInvocationCandidatesFromRecord( recordDeclaration: RecordDeclaration, call: CallExpression, - namePattern: Pattern, + name: String, ctx: TranslationContext ): List = emptyList() diff --git a/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CPPLanguage.kt b/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CPPLanguage.kt index 218adb2749..6cd6312b0d 100644 --- a/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CPPLanguage.kt +++ b/cpg-language-cxx/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/cxx/CPPLanguage.kt @@ -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. */ @@ -157,15 +156,13 @@ class CPPLanguage : override fun refineInvocationCandidatesFromRecord( recordDeclaration: RecordDeclaration, call: CallExpression, - namePattern: Pattern, + name: String, ctx: TranslationContext ): List { val invocationCandidate = mutableListOf( *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()) { @@ -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 } ) ) @@ -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()*/ } ) )