package dataflow

import "github.com/godoctor/godoctor/analysis/dataflow"

Package dataflow provides data flow analyses that can be performed on a
previously constructed control flow graph, including a reaching definitions
analysis and a live variables analysis for local variables.

DefUse builds reaching definitions for a given control flow graph, returning
a map that maps each statement that defines a variable (i.e., declares or
assigns it) to the set of statements that use that variable.

Note: An assignment to a struct field or array element is treated as both a
use and a definition of that variable, since only part of its value is
assigned. For analysis purposes, it's treated as though the entire value
is read, then part of it is modified, then the entire value is assigned back
to the variable. (This is necessary for the analysis to produce correct
results.)

No nodes from the cfg.Defers list will be returned in the output of
this function as they are disjoint from a cfg's blocks.
For analyzing the statements in the cfg.Defers list, each defer
should be treated as though it has the same in and out sets as the cfg.Exit node.

DefsReaching builds reaching definitions for a given control flow graph,
returning the set of statements that define a variable (i.e., declare or
assign it) where that definition reaches the given statement.

LiveAt returns the in and out set of live variables for each block in
a given control flow graph (cfg) in the context of a loader.Program,
including the cfg.Entry and cfg.Exit nodes.

The traditional approach of holding the live variables at the exit node
to the empty set has been deviated from in order to handle defers.
The live variables in set of the cfg.Exit node will be set to the variables used
in all cfg.Defers. No liveness is analyzed for the cfg.Defers themselves.