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 beb36b3661..dee23cc697 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 @@ -123,6 +123,15 @@ interface HasSuperClasses : LanguageTrait { ): Boolean } +/** + * A language trait, that specifies that this language has support for implicit receiver, e.g., that + * one can omit references to a base such as `this`. + */ +interface HasImplicitReceiver : LanguageTrait { + + val receiverName: String +} + /** * A language trait, that specifies that this language has certain qualifiers. If so, we should * consider them when parsing the types. 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 23d7b942fd..c5fc9815fd 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 @@ -56,7 +56,8 @@ open class CPPLanguage : HasUnknownType, HasFunctionStyleCasts, HasFunctionOverloading, - HasOperatorOverloading { + HasOperatorOverloading, + HasImplicitReceiver { override val fileExtensions = listOf("cpp", "cc", "cxx", "c++", "hpp", "hh") override val elaboratedTypeSpecifier = listOf("class", "struct", "union", "enum") override val unknownTypeString = listOf("auto") @@ -317,4 +318,7 @@ open class CPPLanguage : return Pair(false, listOf()) } + + override val receiverName: String + get() = "this" } diff --git a/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/JavaLanguage.kt b/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/JavaLanguage.kt index 4a3ed16ee2..f0f6497559 100644 --- a/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/JavaLanguage.kt +++ b/cpg-language-java/src/main/kotlin/de/fraunhofer/aisec/cpg/frontends/java/JavaLanguage.kt @@ -45,7 +45,8 @@ open class JavaLanguage : HasQualifier, HasUnknownType, HasShortCircuitOperators, - HasFunctionOverloading { + HasFunctionOverloading, + HasImplicitReceiver { override val fileExtensions = listOf("java") override val namespaceDelimiter = "." @Transient override val frontend: KClass = JavaLanguageFrontend::class @@ -116,4 +117,6 @@ open class JavaLanguage : override val startCharacter = '<' override val endCharacter = '>' + override val receiverName: String + get() = "this" }