Skip to content

Commit

Permalink
Overhaul of the pass system (#1169)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxisto authored May 28, 2023
1 parent b414a89 commit 99dfacf
Show file tree
Hide file tree
Showing 48 changed files with 734 additions and 384 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
*/
package de.fraunhofer.aisec.cpg.passes

import de.fraunhofer.aisec.cpg.TranslationResult
import de.fraunhofer.aisec.cpg.ScopeManager
import de.fraunhofer.aisec.cpg.TranslationConfiguration
import de.fraunhofer.aisec.cpg.analysis.ValueEvaluator
import de.fraunhofer.aisec.cpg.graph.Node
import de.fraunhofer.aisec.cpg.graph.declarations.TranslationUnitDeclaration
import de.fraunhofer.aisec.cpg.graph.edge.Properties
import de.fraunhofer.aisec.cpg.graph.statements.IfStatement
import de.fraunhofer.aisec.cpg.graph.statements.WhileStatement
Expand All @@ -40,23 +42,24 @@ import de.fraunhofer.aisec.cpg.processing.strategy.Strategy
* by setting the [Properties.UNREACHABLE] property of an eog-edge to true.
*/
@DependsOn(ControlFlowSensitiveDFGPass::class)
class UnreachableEOGPass : Pass() {
override fun accept(t: TranslationResult) {
for (tu in t.translationUnits) {
tu.accept(
Strategy::AST_FORWARD,
object : IVisitor<Node>() {
override fun visit(t: Node) {
when (t) {
is IfStatement -> handleIfStatement(t)
is WhileStatement -> handleWhileStatement(t)
}

super.visit(t)
class UnreachableEOGPass(
config: TranslationConfiguration,
scopeManager: ScopeManager,
) : TranslationUnitPass(config, scopeManager) {
override fun accept(tu: TranslationUnitDeclaration) {
tu.accept(
Strategy::AST_FORWARD,
object : IVisitor<Node>() {
override fun visit(t: Node) {
when (t) {
is IfStatement -> handleIfStatement(t)
is WhileStatement -> handleWhileStatement(t)
}

super.visit(t)
}
)
}
}
)
}

private fun handleIfStatement(n: IfStatement) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ class MultiValueEvaluatorTest {
topLevel,
true
) {
it.registerPass(EdgeCachePass())
it.registerPass<EdgeCachePass>()
}

assertNotNull(tu)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ class ComplexDFAOrderEvaluationTest {
true
) {
it.registerLanguage<JavaLanguage>()
.registerPass(UnreachableEOGPass())
.registerPass(EdgeCachePass())
.registerPass<UnreachableEOGPass>()
.registerPass<EdgeCachePass>()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ class SimpleDFAOrderEvaluationTest {
true
) {
it.registerLanguage<JavaLanguage>()
.registerPass(UnreachableEOGPass())
.registerPass(EdgeCachePass())
.registerPass<UnreachableEOGPass>()
.registerPass<EdgeCachePass>()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class UnreachableEOGPassTest {
topLevel,
true
) {
it.registerLanguage<JavaLanguage>().registerPass(UnreachableEOGPass())
it.registerLanguage<JavaLanguage>().registerPass<UnreachableEOGPass>()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class UnreachableEOGandDFGTest {
topLevel,
true
) {
it.registerLanguage<JavaLanguage>().registerPass(UnreachableEOGPass())
it.registerLanguage<JavaLanguage>().registerPass<UnreachableEOGPass>()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,7 @@ class QueryTest {
.sourceLocations(File("src/test/resources/query/array2.cpp"))
.defaultPasses()
.defaultLanguages()
.registerPass(EdgeCachePass())
.registerPass<EdgeCachePass>()
.build()

val analyzer = TranslationManager.builder().config(config).build()
Expand Down Expand Up @@ -585,7 +585,7 @@ class QueryTest {
.sourceLocations(File("src/test/resources/query/array3.cpp"))
.defaultPasses()
.defaultLanguages()
.registerPass(EdgeCachePass())
.registerPass<EdgeCachePass>()
.build()

val analyzer = TranslationManager.builder().config(config).build()
Expand Down Expand Up @@ -636,7 +636,7 @@ class QueryTest {
.sourceLocations(File("src/test/resources/query/array_correct.cpp"))
.defaultPasses()
.defaultLanguages()
.registerPass(EdgeCachePass())
.registerPass<EdgeCachePass>()
.build()

val analyzer = TranslationManager.builder().config(config).build()
Expand Down Expand Up @@ -817,7 +817,7 @@ class QueryTest {
.defaultPasses()
.defaultLanguages()
.registerLanguage(JavaLanguage())
.registerPass(EdgeCachePass())
.registerPass<EdgeCachePass>()
.build()

val analyzer = TranslationManager.builder().config(config).build()
Expand Down Expand Up @@ -871,7 +871,7 @@ class QueryTest {
.defaultPasses()
.defaultLanguages()
.registerLanguage(JavaLanguage())
.registerPass(EdgeCachePass())
.registerPass<EdgeCachePass>()
.build()

val analyzer = TranslationManager.builder().config(config).build()
Expand Down Expand Up @@ -925,7 +925,7 @@ class QueryTest {
.defaultPasses()
.defaultLanguages()
.registerLanguage(JavaLanguage())
.registerPass(EdgeCachePass())
.registerPass<EdgeCachePass>()
.build()

val analyzer = TranslationManager.builder().config(config).build()
Expand Down
14 changes: 14 additions & 0 deletions cpg-analysis/src/test/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Configuration status="WARN">
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss,SSS} %-5p %C{1} %m%n"/>
<ThresholdFilter level="DEBUG"/>
</Console>
</Appenders>
<Loggers>
<Logger level="DEBUG" name="de.fraunhofer.aisec.cpg"/>
<Root level="DEBUG">
<AppenderRef ref="STDOUT"/>
</Root>
</Loggers>
</Configuration>
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public ParameterizedType getTypeParameter(RecordDeclaration recordDeclaration, S
* @param typeParameters List containing all ParameterizedTypes used by the recordDeclaration and
* will be stored as value in the map
*/
@Deprecated
public void addTypeParameter(
RecordDeclaration recordDeclaration, List<ParameterizedType> typeParameters) {
this.recordToTypeParameters.put(recordDeclaration, typeParameters);
Expand All @@ -135,6 +136,7 @@ public void addTypeParameter(
* @return
*/
@Nullable
@Deprecated
public ParameterizedType getTypeParameter(TemplateDeclaration templateDeclaration, String name) {
if (this.templateToTypeParameters.containsKey(templateDeclaration)) {
for (ParameterizedType parameterizedType :
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,4 @@ import kotlin.reflect.KClass
* This annotation denotes that, this property is populates by a pass. Optionally, also specifying
* which Pass class is responsible.
*/
annotation class PopulatedByPass(vararg val value: KClass<out Pass>)
annotation class PopulatedByPass(vararg val value: KClass<out Pass<*>>)
Loading

0 comments on commit 99dfacf

Please sign in to comment.