[FIR] Create CFG for files to track top-level property initialization
In order to properly analyze top-level property initialization, a control-flow graph must be created for FirFiles. This change adds the foundation for the file CFG and updates body resolve to create the CFG. Checking the CFG for proper initialization is separated into a following change to ease code review. KT-56683
This commit is contained in:
@@ -291,6 +291,24 @@ class AnonymousFunctionExpressionNode(owner: ControlFlowGraph, override val fir:
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------- Files ------------------------------------------
|
||||
|
||||
class FileEnterNode(owner: ControlFlowGraph, override val fir: FirFile, level: Int) : CFGNodeWithSubgraphs<FirFile>(owner, level),
|
||||
GraphEnterNodeMarker {
|
||||
@set:CfgInternals
|
||||
override lateinit var subGraphs: List<ControlFlowGraph>
|
||||
|
||||
override fun <R, D> accept(visitor: ControlFlowGraphVisitor<R, D>, data: D): R {
|
||||
return visitor.visitFileEnterNode(this, data)
|
||||
}
|
||||
}
|
||||
|
||||
class FileExitNode(owner: ControlFlowGraph, override val fir: FirFile, level: Int) : CFGNode<FirFile>(owner, level), GraphExitNodeMarker {
|
||||
override fun <R, D> accept(visitor: ControlFlowGraphVisitor<R, D>, data: D): R {
|
||||
return visitor.visitFileExitNode(this, data)
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------- Classes -----------------------------------
|
||||
|
||||
class ClassEnterNode(owner: ControlFlowGraph, override val fir: FirClass, level: Int) : CFGNodeWithSubgraphs<FirClass>(owner, level),
|
||||
|
||||
@@ -98,6 +98,9 @@ fun CFGNode<*>.render(): String =
|
||||
is MergePostponedLambdaExitsNode -> "Merge postponed lambda exits"
|
||||
is AnonymousFunctionExpressionNode -> "Exit anonymous function expression"
|
||||
|
||||
is FileEnterNode -> "Enter file ${fir.name}"
|
||||
is FileExitNode -> "Exit file ${fir.name}"
|
||||
|
||||
is ClassEnterNode -> "Enter class ${owner.name}"
|
||||
is ClassExitNode -> "Exit class ${owner.name}"
|
||||
is LocalClassExitNode -> "Local class declaration"
|
||||
|
||||
+1
@@ -32,6 +32,7 @@ class ControlFlowGraph(val declaration: FirDeclaration?, val name: String, val k
|
||||
}
|
||||
|
||||
enum class Kind {
|
||||
File,
|
||||
Class,
|
||||
Function,
|
||||
LocalFunction,
|
||||
|
||||
+10
@@ -58,6 +58,16 @@ abstract class ControlFlowGraphVisitor<out R, in D> {
|
||||
return visitNode(node, data)
|
||||
}
|
||||
|
||||
// ----------------------------------- Files ------------------------------------------
|
||||
|
||||
open fun visitFileEnterNode(node: FileEnterNode, data: D): R {
|
||||
return visitNode(node, data)
|
||||
}
|
||||
|
||||
open fun visitFileExitNode(node: FileExitNode, data: D): R {
|
||||
return visitNode(node, data)
|
||||
}
|
||||
|
||||
// ----------------------------------- Classes -----------------------------------
|
||||
|
||||
open fun visitAnonymousObjectEnterNode(node: AnonymousObjectEnterNode, data: D): R {
|
||||
|
||||
Reference in New Issue
Block a user