XTypeRecovery

io.joern.x2cpg.passes.frontend.XTypeRecovery
See theXTypeRecovery companion object
abstract class XTypeRecovery[CompilationUnitType <: AstNode](cpg: Cpg, state: XTypeRecoveryState) extends CpgPass

Based on a flow-insensitive static single-assignment symbol-table-style approach. This pass aims to be fast and deterministic and does not try to converge to some fixed point but rather iterates a fixed number of times. This will help recover:

  • Imported call signatures from external dependencies
  • Dynamic type hints for mutable variables in a compilation unit.

The algorithm flows roughly as follows:

  • Scan for method signatures of methods for each compilation unit, either by internally defined methods or by reading import signatures. This includes looking for aliases, e.g. import foo as bar.
  • (Optionally) Prune these method signatures by checking their validity against the CPG.
  • Visit assignments to populate where variables are assigned a value to extrapolate its type. Store these values in a local symbol table. If a field is assigned a value, store this in the global table
  • Find instances of where these fields and variables are used and update their type information.
  • If this variable is the receiver of a call, make sure to set the type of the call accordingly.

The symbol tables use the SymbolTable class to track possible type information.
Note: Local symbols are cleared once a compilation unit is complete. This is to keep memory usage down while maximizing concurrency.

Attributes

CompilationUnitType

the AstNode type used to represent a compilation unit of the language.

cpg

the CPG to recovery types for.

Companion:
object
Graph
Supertypes
class CpgPass
class ForkJoinParallelCpgPass[AnyRef]
class NewStyleCpgPassBase[AnyRef]
trait CpgPassBase
class Object
trait Matchable
class Any

Members list

Concise view

Type members

Inherited types

type DiffGraphBuilder = DiffGraphBuilder

Attributes

Inherited from:
NewStyleCpgPassBase

Value members

Abstract methods

def compilationUnit: Traversal[CompilationUnitType]

Attributes

Returns:

the compilation units as per how the language is compiled. e.g. file.

def generateRecoveryForCompilationUnitTask(unit: CompilationUnitType, builder: DiffGraphBuilder): RecoverForXCompilationUnit[CompilationUnitType]

A factory method to generate a RecoverForXCompilationUnit task with the given parameters.

A factory method to generate a RecoverForXCompilationUnit task with the given parameters.

Attributes

builder

the graph builder.

unit

the compilation unit.

Returns:

a forkable RecoverForXCompilationUnit task.

Concrete methods

override def run(builder: DiffGraphBuilder): Unit

Attributes

Definition Classes
CpgPass

Inherited methods

override def createAndApply(): Unit

Attributes

Definition Classes
NewStyleCpgPassBase -> CpgPassBase
Inherited from:
NewStyleCpgPassBase
override def createApplySerializeAndStore(serializedCpg: SerializedCpg, inverse: Boolean, prefix: String): Unit

Attributes

Definition Classes
ForkJoinParallelCpgPass -> CpgPassBase
Inherited from:
ForkJoinParallelCpgPass
def finish(): Unit

Attributes

Inherited from:
NewStyleCpgPassBase
final override def generateParts(): Array[_ <: AnyRef]

Attributes

Definition Classes
CpgPass -> NewStyleCpgPassBase
Inherited from:
CpgPass
def init(): Unit

Attributes

Inherited from:
NewStyleCpgPassBase
def name: String

Name of the pass. By default it is inferred from the name of the class, override if needed.

Name of the pass. By default it is inferred from the name of the class, override if needed.

Attributes

Inherited from:
CpgPassBase
final override def runOnPart(builder: DiffGraphBuilder, part: AnyRef): Unit

Attributes

Definition Classes
CpgPass -> NewStyleCpgPassBase
Inherited from:
CpgPass
override def runWithBuilder(externalBuilder: DiffGraphBuilder): Int

Runs the cpg pass, adding changes to the passed builder. Use with caution -- API is unstable. Returns max(nParts, 1), where nParts is either the number of parallel parts, or the number of iterarator elements in case of legacy passes. Includes init() and finish() logic.

Runs the cpg pass, adding changes to the passed builder. Use with caution -- API is unstable. Returns max(nParts, 1), where nParts is either the number of parallel parts, or the number of iterarator elements in case of legacy passes. Includes init() and finish() logic.

Attributes

Definition Classes
NewStyleCpgPassBase -> CpgPassBase
Inherited from:
NewStyleCpgPassBase
def runWithBuilderLogged(builder: DiffGraphBuilder): Int

Wraps runWithBuilder with logging, and swallows raised exceptions. Use with caution -- API is unstable. A return value of -1 indicates failure, otherwise the return value of runWithBuilder is passed through.

Wraps runWithBuilder with logging, and swallows raised exceptions. Use with caution -- API is unstable. A return value of -1 indicates failure, otherwise the return value of runWithBuilder is passed through.

Attributes

Inherited from:
CpgPassBase