Skip to content

Commit

Permalink
Merge branch 'main' into eog-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto authored Nov 18, 2024
2 parents 8f0db0c + 3fe8edb commit 5f59e92
Show file tree
Hide file tree
Showing 10 changed files with 212 additions and 84 deletions.
7 changes: 7 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ cpg-language-cxx @peckto
cpg-language-llvm @KuechA
cpg-analysis @KuechA

*.java @konradweiss
cpg-language-java @konradweiss

cpg-language-jvm @oxisto

cpg-language-ruby @oxisto

cpg-neo4j @peckto

build.gradle.kts @oxisto
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
env:
VERSION: ${{ env.version }}
- name: Upload Code Coverage
uses: codecov/codecov-action@v4
uses: codecov/codecov-action@v5
with:
fail_ci_if_error: true
files: ./cpg-all/build/reports/kover/report.xml
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2023, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $$$$$$\ $$$$$$$\ $$$$$$\
* $$ __$$\ $$ __$$\ $$ __$$\
* $$ / \__|$$ | $$ |$$ / \__|
* $$ | $$$$$$$ |$$ |$$$$\
* $$ | $$ ____/ $$ |\_$$ |
* $$ | $$\ $$ | $$ | $$ |
* \$$$$$ |$$ | \$$$$$ |
* \______/ \__| \______/
*
*/
package de.fraunhofer.aisec.cpg.graph.types

import de.fraunhofer.aisec.cpg.frontends.Language

/** Represents a [List] type that contains multiple elements. */
class ListType(typeName: CharSequence, override var elementType: Type, language: Language<*>) :
ObjectType(typeName, listOf(elementType), false, language), SecondOrderType
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2023, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $$$$$$\ $$$$$$$\ $$$$$$\
* $$ __$$\ $$ __$$\ $$ __$$\
* $$ / \__|$$ | $$ |$$ / \__|
* $$ | $$$$$$$ |$$ |$$$$\
* $$ | $$ ____/ $$ |\_$$ |
* $$ | $$\ $$ | $$ | $$ |
* \$$$$$ |$$ | \$$$$$ |
* \______/ \__| \______/
*
*/
package de.fraunhofer.aisec.cpg.graph.types

import de.fraunhofer.aisec.cpg.frontends.Language

/** Represents a [Map] type with key-value pairs. */
class MapType(typeName: CharSequence, override var elementType: Type, language: Language<*>) :
ObjectType(typeName, listOf(elementType), false, language), SecondOrderType
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
*/
package de.fraunhofer.aisec.cpg.graph.types

/** Second-order types are generic container types (e.g., List, Set, Map) or pointer types. */
interface SecondOrderType {
var elementType: Type

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2023, Fraunhofer AISEC. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* $$$$$$\ $$$$$$$\ $$$$$$\
* $$ __$$\ $$ __$$\ $$ __$$\
* $$ / \__|$$ | $$ |$$ / \__|
* $$ | $$$$$$$ |$$ |$$$$\
* $$ | $$ ____/ $$ |\_$$ |
* $$ | $$\ $$ | $$ | $$ |
* \$$$$$ |$$ | \$$$$$ |
* \______/ \__| \______/
*
*/
package de.fraunhofer.aisec.cpg.graph.types

import de.fraunhofer.aisec.cpg.frontends.Language

/** Represents a [Set] type that contains unique elements. */
class SetType(typeName: CharSequence, override var elementType: Type, language: Language<*>) :
ObjectType(typeName, listOf(elementType), false, language), SecondOrderType
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import de.fraunhofer.aisec.cpg.graph.declarations.FunctionDeclaration
import de.fraunhofer.aisec.cpg.graph.declarations.MethodDeclaration
import de.fraunhofer.aisec.cpg.graph.statements.expressions.*
import de.fraunhofer.aisec.cpg.graph.types.FunctionType
import de.fraunhofer.aisec.cpg.graph.types.SecondOrderType
import de.fraunhofer.aisec.cpg.graph.types.Type
import de.fraunhofer.aisec.cpg.helpers.Util
import de.fraunhofer.aisec.cpg.passes.SymbolResolver.Companion.addImplicitTemplateParametersToCall
Expand Down Expand Up @@ -428,8 +427,6 @@ class ExpressionHandler(lang: CXXLanguageFrontend) :
val callExpression: CallExpression
when {
reference is MemberExpression -> {
val baseType = reference.base.type.root
assert(baseType !is SecondOrderType)
callExpression = newMemberCallExpression(reference, rawNode = ctx)
if (
(ctx.functionNameExpression as? IASTFieldReference)?.fieldName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,31 @@ class PythonLanguage :
this,
NumericType.Modifier.NOT_APPLICABLE
), // It's two floats
"str" to StringType("str", this, listOf())
"str" to StringType("str", this, listOf()),
"list" to
ListType(
typeName = "list",
elementType = ObjectType("object", listOf(), false, this),
language = this,
),
"tuple" to
ListType(
typeName = "tuple",
elementType = ObjectType("object", listOf(), false, this),
language = this
),
"dict" to
MapType(
typeName = "dict",
elementType = ObjectType("object", listOf(), false, this),
language = this
),
"set" to
SetType(
typeName = "set",
elementType = ObjectType("object", listOf(), false, this),
language = this
)
)

override fun propagateTypeOfBinaryOperation(operation: BinaryOperator): Type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ import de.fraunhofer.aisec.cpg.graph.Annotation
import de.fraunhofer.aisec.cpg.graph.declarations.*
import de.fraunhofer.aisec.cpg.graph.statements.*
import de.fraunhofer.aisec.cpg.graph.statements.expressions.*
import de.fraunhofer.aisec.cpg.graph.types.ListType
import de.fraunhofer.aisec.cpg.graph.types.MapType
import de.fraunhofer.aisec.cpg.graph.types.ObjectType
import de.fraunhofer.aisec.cpg.graph.types.SetType
import de.fraunhofer.aisec.cpg.helpers.SubgraphWalker
import de.fraunhofer.aisec.cpg.passes.ControlDependenceGraphPass
import de.fraunhofer.aisec.cpg.sarif.Region
Expand Down Expand Up @@ -1312,25 +1315,25 @@ class PythonFrontendTest : BaseTest() {
assertIs<AssignExpression>(aStmt)
val aStmtRhs = aStmt.rhs.singleOrNull()
assertIs<InitializerListExpression>(aStmtRhs)
assertEquals("list", aStmtRhs.type.name.localName)
assertIs<ListType>(aStmtRhs.type)

val bStmt = namespace.statements[1]
assertIs<AssignExpression>(bStmt)
val bStmtRhs = bStmt.rhs.singleOrNull()
assertIs<InitializerListExpression>(bStmtRhs)
assertEquals("set", bStmtRhs.type.name.localName)
assertIs<SetType>(bStmtRhs.type)

val cStmt = namespace.statements[2]
assertIs<AssignExpression>(cStmt)
val cStmtRhs = cStmt.rhs.singleOrNull()
assertIs<InitializerListExpression>(cStmtRhs)
assertEquals("tuple", cStmtRhs.type.name.localName)
assertIs<ListType>(cStmtRhs.type)

val dStmt = namespace.statements[3]
assertIs<AssignExpression>(dStmt)
val dStmtRhs = dStmt.rhs.singleOrNull()
assertIs<InitializerListExpression>(dStmtRhs)
assertEquals("dict", dStmtRhs.type.name.localName)
assertIs<MapType>(dStmtRhs.type)

val fourthStmt = namespace.statements[4]
assertIs<AssignExpression>(fourthStmt)
Expand Down
Loading

0 comments on commit 5f59e92

Please sign in to comment.