[FIR] Prepare ControlFlowAnalysisDiagnosticComponent
This commit is contained in:
+16
-2
@@ -7,10 +7,24 @@ package org.jetbrains.kotlin.fir.analysis.cfa
|
||||
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.declarations.FirClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirProperty
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.cfg.ControlFlowGraph
|
||||
|
||||
class FirControlFlowAnalyzer(private val reporter: DiagnosticReporter) {
|
||||
fun analyze(graph: ControlFlowGraph, context: CheckerContext) {
|
||||
class FirControlFlowAnalyzer {
|
||||
fun analyzeClassInitializer(klass: FirClass<*>, graph: ControlFlowGraph, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
if (graph.owner != null) return
|
||||
// TODO()
|
||||
}
|
||||
|
||||
fun analyzeFunction(function: FirFunction<*>, graph: ControlFlowGraph, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
if (graph.owner != null) return
|
||||
// TODO()
|
||||
}
|
||||
|
||||
fun analyzePropertyInitializer(property: FirProperty, graph: ControlFlowGraph, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
if (graph.owner != null) return
|
||||
// TODO()
|
||||
}
|
||||
}
|
||||
+48
-3
@@ -8,15 +8,60 @@ package org.jetbrains.kotlin.fir.analysis.collectors.components
|
||||
import org.jetbrains.kotlin.fir.analysis.cfa.FirControlFlowAnalyzer
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.collectors.AbstractDiagnosticCollector
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.references.FirControlFlowGraphReference
|
||||
import org.jetbrains.kotlin.fir.resolve.dfa.controlFlowGraph
|
||||
|
||||
class ControlFlowAnalysisDiagnosticComponent(collector: AbstractDiagnosticCollector) : AbstractDiagnosticCollectorComponent(collector) {
|
||||
override fun visitControlFlowGraphReference(controlFlowGraphReference: FirControlFlowGraphReference, data: CheckerContext) {
|
||||
private val controlFlowAnalyzer = FirControlFlowAnalyzer()
|
||||
|
||||
// ------------------------------- Class initializer -------------------------------
|
||||
|
||||
override fun visitRegularClass(regularClass: FirRegularClass, data: CheckerContext) {
|
||||
visitClass(regularClass, regularClass.controlFlowGraphReference, data)
|
||||
}
|
||||
|
||||
override fun visitAnonymousObject(anonymousObject: FirAnonymousObject, data: CheckerContext) {
|
||||
visitClass(anonymousObject, anonymousObject.controlFlowGraphReference, data)
|
||||
}
|
||||
|
||||
private fun <F : FirClass<F>> visitClass(
|
||||
klass: FirClass<F>,
|
||||
controlFlowGraphReference: FirControlFlowGraphReference,
|
||||
data: CheckerContext
|
||||
) {
|
||||
val graph = controlFlowGraphReference.controlFlowGraph ?: return
|
||||
runCheck {
|
||||
val controlFlowAnalyzer = FirControlFlowAnalyzer(it)
|
||||
controlFlowAnalyzer.analyze(graph, data)
|
||||
controlFlowAnalyzer.analyzeClassInitializer(klass, graph, data, it)
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------- Property initializer -------------------------------
|
||||
override fun visitProperty(property: FirProperty, data: CheckerContext) {
|
||||
val graph = property.controlFlowGraphReference.controlFlowGraph ?: return
|
||||
runCheck {
|
||||
controlFlowAnalyzer.analyzePropertyInitializer(property, graph, data, it)
|
||||
}
|
||||
}
|
||||
|
||||
// ------------------------------- Function -------------------------------
|
||||
|
||||
override fun <F : FirFunction<F>> visitFunction(function: FirFunction<F>, data: CheckerContext) {
|
||||
val graph = function.controlFlowGraphReference.controlFlowGraph ?: return
|
||||
runCheck {
|
||||
controlFlowAnalyzer.analyzeFunction(function, graph, data, it)
|
||||
}
|
||||
}
|
||||
|
||||
override fun visitSimpleFunction(simpleFunction: FirSimpleFunction, data: CheckerContext) {
|
||||
visitFunction(simpleFunction, data)
|
||||
}
|
||||
|
||||
override fun visitPropertyAccessor(propertyAccessor: FirPropertyAccessor, data: CheckerContext) {
|
||||
visitFunction(propertyAccessor, data)
|
||||
}
|
||||
|
||||
override fun visitConstructor(constructor: FirConstructor, data: CheckerContext) {
|
||||
visitFunction(constructor, data)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user