Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some improvements to pass annotations #1674

Merged
merged 2 commits into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ private constructor(
log.info("Passes before enforcing order: {}", passes.map { it.simpleName })
val orderingHelper = PassOrderingHelper(passes)
log.info(
"The following mermaid graph represents the pass dependencies: \n ${buildMermaid(passes)}"
"The following mermaid graph represents the pass dependencies: \n${buildMermaid(passes)}"
)

return orderingHelper.order()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,15 +401,15 @@ val KClass<out Pass<*>>.hardDependencies: Set<KClass<out Pass<*>>>
val KClass<out Pass<*>>.softExecuteBefore: Set<KClass<out Pass<*>>>
get() {
return this.findAnnotations<ExecuteBefore>()
.filter { it.soft == true }
.filter { it.softDependency == true }
.map { it.other }
.toSet()
}

val KClass<out Pass<*>>.hardExecuteBefore: Set<KClass<out Pass<*>>>
get() {
return this.findAnnotations<ExecuteBefore>()
.filter { it.soft == false }
.filter { it.softDependency == false }
.map { it.other }
.toSet()
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import de.fraunhofer.aisec.cpg.processing.strategy.Strategy
@DependsOn(ControlDependenceGraphPass::class)
@DependsOn(DFGPass::class)
@DependsOn(ControlFlowSensitiveDFGPass::class, softDependency = true)
@DependsOn(DynamicInvokeResolver::class)
class ProgramDependenceGraphPass(ctx: TranslationContext) : TranslationUnitPass(ctx) {
private val visitor =
object : IVisitor<Node>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ class ReplaceCallCastPass(ctx: TranslationContext) : TranslationUnitPass(ctx) {
// cast expression. And this is only really necessary, if the function call has a single
// argument.
var callee = call.callee
if (parent != null && callee != null && call.arguments.size == 1) {
if (parent != null && call.arguments.size == 1) {
val language = parent.language

var pointer = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import kotlin.reflect.KClass

/**
* Register a dependency for the annotated pass. This ensures that the annotated pass is executed
* before [other] pass. The [soft] flag decides whether to treat this as a hard dependency
* before [other] pass. The [softDependency] flag decides whether to treat this as a hard dependency
* (resulting in the pass being registered if not present) or not.
*/
@Retention(AnnotationRetention.RUNTIME)
@Target(AnnotationTarget.CLASS)
@Repeatable
annotation class ExecuteBefore(val other: KClass<out Pass<*>>, val soft: Boolean = false)
annotation class ExecuteBefore(val other: KClass<out Pass<*>>, val softDependency: Boolean = true)
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ class PassOrderingHelper {

// take care of [ExecuteBefore] dependencies
for (dep in newElement.findAnnotations<ExecuteBefore>()) {
if (!dep.soft) {
if (!dep.softDependency) {
addToWorkingList(dep.other)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ import de.fraunhofer.aisec.cpg.passes.inference.startInference
*/
@ExecuteBefore(SymbolResolver::class)
@ExecuteBefore(EvaluationOrderGraphPass::class)
@ExecuteBefore(DFGPass::class)
@DependsOn(ImportResolver::class)
@DependsOn(TypeResolver::class)
class GoExtraPass(ctx: TranslationContext) : ComponentPass(ctx) {

private lateinit var walker: SubgraphWalker.ScopedWalker
Expand Down
Loading