Skip to content

Commit

Permalink
Merge branch 'main' into renovate/rollup-4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
konradweiss authored Nov 7, 2023
2 parents 73f4856 + 61a7d2d commit ab1a523
Show file tree
Hide file tree
Showing 103 changed files with 2,851 additions and 1,378 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ jobs:
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- uses: actions/setup-node@v3
- uses: actions/setup-node@v4
with:
node-version: "18"
- name: Setup neo4j
Expand Down Expand Up @@ -137,7 +137,7 @@ jobs:
if: startsWith(github.ref, 'refs/tags/v') && !contains(github.ref, 'beta') && !contains(github.ref, 'alpha')
run: |
export ORG_GRADLE_PROJECT_signingKey=`echo ${{ secrets.GPG_PRIVATE_KEY }} | base64 -d`
./gradlew --no-daemon -Dorg.gradle.internal.publish.checksums.insecure=true --parallel -Pversion=$VERSION -PenableJavaFrontend=true -PenableCXXFrontend=true -PenableGoFrontend=true -PenablePythonFrontend=true -PenableLLVMFrontend=true -PenableTypeScriptFrontend=true publishToSonatype closeSonatypeStagingRepository
./gradlew --no-daemon -Dorg.gradle.internal.publish.checksums.insecure=true --parallel -Pversion=$VERSION -PenableJavaFrontend=true -PenableCXXFrontend=true -PenableGoFrontend=true -PenablePythonFrontend=true -PenableLLVMFrontend=true -PenableTypeScriptFrontend=true -PenableRubyFrontend=true publishToSonatype closeSonatypeStagingRepository
env:
VERSION: ${{ env.version }}
ORG_GRADLE_PROJECT_signingPassword: ${{ secrets.GPG_PASSWORD }}
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ In order to get familiar with the graph itself, you can use the subproject [cpg-
### As Library

The most recent version is being published to Maven central and can be used as a simple dependency, either using Maven or Gradle. Since Eclipse CDT is not published on maven central, it is necessary to add a repository with a custom layout to find the released CDT files. For example, using Gradle's Kotlin syntax:
```
```kotlin
repositories {
ivy {
setUrl("https://download.eclipse.org/tools/cdt/releases/11.0/cdt-11.0.0/plugins")
Expand Down Expand Up @@ -121,7 +121,7 @@ Instead of manually editing the `gradle.properties` file, you can also use the `

#### Golang

In the case of Golang, the necessary native code can be found in the `src/main/golang` folder of the `cpg-language-go` submodule. Gradle should automatically find JNI headers and stores the finished library in the `src/main/golang` folder. This currently only works for Linux and macOS. In order to use it in an external project, the resulting library needs to be placed somewhere in `java.library.path`.
In the case of Golang, the necessary native code can be found in the `src/main/golang` folder of the `cpg-language-go` submodule. Gradle should automatically store the finished library in the `src/main/golang` folder. This currently only works for Linux and macOS.

#### Python

Expand All @@ -145,7 +145,6 @@ Through the `JepSingleton`, the CPG library will look for well known paths on Li

For parsing TypeScript, the necessary NodeJS-based code can be found in the `src/main/nodejs` directory of the `cpg-language-typescript` submodule. Gradle should build the script automatically, provided NodeJS (>=16) is installed. The bundles script will be placed inside the jar's resources and should work out of the box.


### Code Style

We use [Google Java Style](https://github.com/google/google-java-format) as a formatting. Please install the appropriate plugin for your IDE, such as the [google-java-format IntelliJ plugin](https://plugins.jetbrains.com/plugin/8527-google-java-format) or [google-java-format Eclipse plugin](https://github.com/google/google-java-format/releases/download/google-java-format-1.6/google-java-format-eclipse-plugin_1.6.0.jar).
Expand Down Expand Up @@ -183,8 +182,7 @@ The following authors have contributed to this project (in alphabetical order):

## Contributing

We are currently discussing the implementation of a Contributor License Agreement (CLA). Unfortunately,
we cannot merge external pull requests until this issue is resolved.
Before accepting external contributions, you need to sign our [CLA](https://cla-assistant.io/Fraunhofer-AISEC/cpg). Our CLA assistent will check, whether you already signed the CLA when you open your first pull request.

## Further reading

Expand Down
12 changes: 7 additions & 5 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import org.jetbrains.dokka.gradle.DokkaMultiModuleTask
import java.io.BufferedOutputStream
import java.io.ByteArrayOutputStream

/*
* Copyright (c) 2019-2021, Fraunhofer AISEC. All rights reserved.
*
Expand Down Expand Up @@ -76,7 +72,7 @@ fun generateDokkaWithVersionTag(dokkaMultiModuleTask: org.jetbrains.dokka.gradle
val config = """{ "version": "$tag", "olderVersionsDir":"${oldOutputPath.path}" }"""
val mapOf = mapOf(id to config)

dokkaMultiModuleTask.outputDirectory.set(file(buildDir.resolve("dokkaCustomMultiModuleOutput").resolve(tag)))
dokkaMultiModuleTask.outputDirectory.set(file(layout.buildDirectory.asFile.get().resolve("dokkaCustomMultiModuleOutput").resolve(tag)))
dokkaMultiModuleTask.pluginsMapConfiguration.set(mapOf)
}

Expand Down Expand Up @@ -148,3 +144,9 @@ val enableTypeScriptFrontend: Boolean by extra {
enableTypeScriptFrontend.toBoolean()
}
project.logger.lifecycle("TypeScript frontend is ${if (enableTypeScriptFrontend) "enabled" else "disabled"}")

val enableRubyFrontend: Boolean by extra {
val enableRubyFrontend: String? by project
enableRubyFrontend.toBoolean()
}
project.logger.lifecycle("Ruby frontend is ${if (enableRubyFrontend) "enabled" else "disabled"}")
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ val enableGoFrontend: Boolean by rootProject.extra
val enablePythonFrontend: Boolean by rootProject.extra
val enableLLVMFrontend: Boolean by rootProject.extra
val enableTypeScriptFrontend: Boolean by rootProject.extra
val enableRubyFrontend: Boolean by rootProject.extra

dependencies {
if (enableJavaFrontend) api(project(":cpg-language-java"))
Expand All @@ -17,4 +18,5 @@ dependencies {
if (enablePythonFrontend) api(project(":cpg-language-python"))
if (enableLLVMFrontend) api(project(":cpg-language-llvm"))
if (enableTypeScriptFrontend) api(project(":cpg-language-typescript"))
if (enableRubyFrontend) api(project(":cpg-language-ruby"))
}
2 changes: 2 additions & 0 deletions configure_frontends.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ answerLLVM=$(ask "Do you want to enable the LLVM frontend? (currently $(getPrope
setProperty "enableLLVMFrontend" $answerLLVM
answerTypescript=$(ask "Do you want to enable the TypeScript frontend? (currently $(getProperty "enableTypeScriptFrontend"))")
setProperty "enableTypeScriptFrontend" $answerTypescript
answerRuby=$(ask "Do you want to enable the Ruby frontend? (currently $(getProperty "enableRubyFrontend"))")
setProperty "enableRubyFrontend" $answerRuby
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ open class ValueEvaluator(
"/=" -> handleDiv(lhsValue, rhsValue, expr)
"*",
"*=" -> handleTimes(lhsValue, rhsValue, expr)
"<<" -> handleShiftLeft(lhsValue, rhsValue, expr)
">>" -> handleShiftRight(lhsValue, rhsValue, expr)
"&" -> handleBitwiseAnd(lhsValue, rhsValue, expr)
"|" -> handleBitwiseOr(lhsValue, rhsValue, expr)
"^" -> handleBitwiseXor(lhsValue, rhsValue, expr)
">" -> handleGreater(lhsValue, rhsValue, expr)
">=" -> handleGEq(lhsValue, rhsValue, expr)
"<" -> handleLess(lhsValue, rhsValue, expr)
Expand Down Expand Up @@ -202,6 +207,51 @@ open class ValueEvaluator(
}
}

private fun handleShiftLeft(lhsValue: Any?, rhsValue: Any?, expr: Expression?): Any? {
return when {
// right side must always be an int
lhsValue is Int && rhsValue is Int -> lhsValue shl rhsValue
lhsValue is Long && rhsValue is Int -> lhsValue shl rhsValue
else -> cannotEvaluate(expr, this)
}
}

private fun handleShiftRight(lhsValue: Any?, rhsValue: Any?, expr: Expression?): Any? {
return when {
// right side must always be an int
lhsValue is Int && rhsValue is Int -> lhsValue shr rhsValue
lhsValue is Long && rhsValue is Int -> lhsValue shr rhsValue
else -> cannotEvaluate(expr, this)
}
}

private fun handleBitwiseAnd(lhsValue: Any?, rhsValue: Any?, expr: Expression?): Any? {
return when {
// left and right must be equal and only long and int are supported
lhsValue is Int && rhsValue is Int -> lhsValue and rhsValue
lhsValue is Long && rhsValue is Long -> lhsValue and rhsValue
else -> cannotEvaluate(expr, this)
}
}

private fun handleBitwiseOr(lhsValue: Any?, rhsValue: Any?, expr: Expression?): Any? {
return when {
// left and right must be equal and only long and int are supported
lhsValue is Int && rhsValue is Int -> lhsValue or rhsValue
lhsValue is Long && rhsValue is Long -> lhsValue or rhsValue
else -> cannotEvaluate(expr, this)
}
}

private fun handleBitwiseXor(lhsValue: Any?, rhsValue: Any?, expr: Expression?): Any? {
return when {
// left and right must be equal and only long and int are supported
lhsValue is Int && rhsValue is Int -> lhsValue xor rhsValue
lhsValue is Long && rhsValue is Long -> lhsValue xor rhsValue
else -> cannotEvaluate(expr, this)
}
}

private fun handleGreater(lhsValue: Any?, rhsValue: Any?, expr: Expression?): Any? {
return if (lhsValue is Number && rhsValue is Number) {
lhsValue.compareTo(rhsValue) > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
package de.fraunhofer.aisec.cpg.analysis.fsm

import de.fraunhofer.aisec.cpg.graph.Node
import de.fraunhofer.aisec.cpg.graph.declarations.Declaration
import de.fraunhofer.aisec.cpg.graph.declarations.ParameterDeclaration
import de.fraunhofer.aisec.cpg.graph.declarations.VariableDeclaration
import de.fraunhofer.aisec.cpg.graph.edge.Properties
Expand Down Expand Up @@ -291,7 +290,8 @@ open class DFAOrderEvaluator(
if (
node is MemberCallExpression &&
node.base is Reference &&
consideredBases.contains((node.base as Reference).refersTo as Declaration)
(node.base as Reference).refersTo != null &&
consideredBases.contains((node.base as Reference).refersTo!!)
) {
allUsedBases.add((node.base as Reference).refersTo)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,106 @@ class ValueEvaluatorTest {
}
}

@Test
fun testHandleShiftLeft() {
with(TestHandler(TestLanguageFrontend())) {
val binOp = newBinaryOperator("<<")
// Int.plus
binOp.lhs = newLiteral(3, primitiveType("int"))
binOp.rhs = newLiteral(2, primitiveType("int"))
assertEquals(12, ValueEvaluator().evaluate(binOp))

// Long.plus
binOp.lhs = newLiteral(3L, primitiveType("long"))
binOp.rhs = newLiteral(2, primitiveType("int"))
assertEquals(12L, ValueEvaluator().evaluate(binOp))

binOp.lhs = newLiteral("Hello", primitiveType("string"))
binOp.rhs = newLiteral(" world", primitiveType("string"))
assertEquals("{<<}", ValueEvaluator().evaluate(binOp))
}
}

@Test
fun testHandleShiftRight() {
with(TestHandler(TestLanguageFrontend())) {
val binOp = newBinaryOperator(">>")
// Int.plus
binOp.lhs = newLiteral(3, primitiveType("int"))
binOp.rhs = newLiteral(2, primitiveType("int"))
assertEquals(0, ValueEvaluator().evaluate(binOp))

// Long.plus
binOp.lhs = newLiteral(3L, primitiveType("long"))
binOp.rhs = newLiteral(2, primitiveType("int"))
assertEquals(0L, ValueEvaluator().evaluate(binOp))

binOp.lhs = newLiteral("Hello", primitiveType("string"))
binOp.rhs = newLiteral(" world", primitiveType("string"))
assertEquals("{>>}", ValueEvaluator().evaluate(binOp))
}
}

@Test
fun testHandleBitwiseAnd() {
with(TestHandler(TestLanguageFrontend())) {
val binOp = newBinaryOperator("&")
// Int.plus
binOp.lhs = newLiteral(3, primitiveType("int"))
binOp.rhs = newLiteral(2, primitiveType("int"))
assertEquals(2, ValueEvaluator().evaluate(binOp))

// Long.plus
binOp.lhs = newLiteral(3L, primitiveType("long"))
binOp.rhs = newLiteral(2L, primitiveType("long"))
assertEquals(2L, ValueEvaluator().evaluate(binOp))

binOp.lhs = newLiteral("Hello", primitiveType("string"))
binOp.rhs = newLiteral(" world", primitiveType("string"))
assertEquals("{&}", ValueEvaluator().evaluate(binOp))
}
}

@Test
fun testHandleBitwiseOr() {
with(TestHandler(TestLanguageFrontend())) {
val binOp = newBinaryOperator("|")
// Int.plus
binOp.lhs = newLiteral(3, primitiveType("int"))
binOp.rhs = newLiteral(2, primitiveType("int"))
assertEquals(3, ValueEvaluator().evaluate(binOp))

// Long.plus
binOp.lhs = newLiteral(3L, primitiveType("long"))
binOp.rhs = newLiteral(2L, primitiveType("long"))
assertEquals(3L, ValueEvaluator().evaluate(binOp))

binOp.lhs = newLiteral("Hello", primitiveType("string"))
binOp.rhs = newLiteral(" world", primitiveType("string"))
assertEquals("{|}", ValueEvaluator().evaluate(binOp))
}
}

@Test
fun testHandleBitwiseXor() {
with(TestHandler(TestLanguageFrontend())) {
val binOp = newBinaryOperator("^")
// Int.plus
binOp.lhs = newLiteral(3, primitiveType("int"))
binOp.rhs = newLiteral(2, primitiveType("int"))
assertEquals(1, ValueEvaluator().evaluate(binOp))

// Long.plus
binOp.lhs = newLiteral(3L, primitiveType("long"))
binOp.rhs = newLiteral(2L, primitiveType("long"))
assertEquals(1L, ValueEvaluator().evaluate(binOp))

binOp.lhs = newLiteral("Hello", primitiveType("string"))
binOp.rhs = newLiteral(" world", primitiveType("string"))
assertEquals("{^}", ValueEvaluator().evaluate(binOp))
}
}

@Test
fun testHandleUnary() {
with(TestHandler(TestLanguageFrontend())) {
Expand Down
Loading

0 comments on commit ab1a523

Please sign in to comment.