abstract class XTypeRecovery[CompilationUnitType <: AstNode] extends CpgPass
Based on a flow-insensitive 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.
In order to propagate types across compilation units, but avoid the poor scalability of a fixed-point algorithm, the number of iterations can be configured using the iterations parameter. Note that iterations < 2 will not provide any interprocedural type recovery capabilities.
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.
- CompilationUnitType
the AstNode type used to represent a compilation unit of the language.
- Alphabetic
- By Inheritance
- XTypeRecovery
- CpgPass
- ForkJoinParallelCpgPass
- NewStyleCpgPassBase
- CpgPassBase
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Instance Constructors
- new XTypeRecovery(cpg: Cpg, iterations: Int = 2)
- cpg
the CPG to recovery types for.
- iterations
the total number of iterations through which types are to be propagated. At least 2 are recommended in order to propagate interprocedural types. Think of this as similar to the dataflowengineoss' 'maxCallDepth'.
Type Members
- type DiffGraphBuilder = overflowdb.BatchedUpdate.DiffGraphBuilder
- Definition Classes
- NewStyleCpgPassBase
Abstract Value Members
- abstract def compilationUnit: Traversal[CompilationUnitType]
- returns
the compilation units as per how the language is compiled. e.g. file.
- abstract 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.
- unit
the compilation unit.
- builder
the graph builder.
- returns
a forkable RecoverForXCompilationUnit task.
Concrete Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- val addedNodes: HashSet[(Long, String)]
In the case of new nodes being added, will make sure these aren't duplicated because of future iterations.
In the case of new nodes being added, will make sure these aren't duplicated because of future iterations. This comes in pairs of parent ID -> string identifier.
- Attributes
- protected
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def baseLogger: Logger
- Attributes
- protected
- Definition Classes
- CpgPassBase
- def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
- def createAndApply(): Unit
- Definition Classes
- NewStyleCpgPassBase → CpgPassBase
- def createApplySerializeAndStore(serializedCpg: SerializedCpg, inverse: Boolean, prefix: String): Unit
- Definition Classes
- ForkJoinParallelCpgPass → CpgPassBase
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def finish(): Unit
- Definition Classes
- NewStyleCpgPassBase
- def generateOutFileName(prefix: String, outName: String, index: Int): String
- Attributes
- protected
- Definition Classes
- CpgPassBase
- final def generateParts(): Array[_ <: AnyRef]
- Definition Classes
- CpgPass → NewStyleCpgPassBase
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- val globalTable: SymbolTable[GlobalKey]
Stores type information for global structures that persist across compilation units, e.g.
Stores type information for global structures that persist across compilation units, e.g. field identifiers.
- Attributes
- protected
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
- def init(): Unit
- Definition Classes
- NewStyleCpgPassBase
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def name: String
- Definition Classes
- CpgPassBase
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
- def run(builder: DiffGraphBuilder): Unit
- Definition Classes
- XTypeRecovery → CpgPass
- final def runOnPart(builder: overflowdb.BatchedUpdate.DiffGraphBuilder, part: AnyRef): Unit
- Definition Classes
- CpgPass → NewStyleCpgPassBase
- def runWithBuilder(externalBuilder: overflowdb.BatchedUpdate.DiffGraphBuilder): Int
- Definition Classes
- NewStyleCpgPassBase → CpgPassBase
- def runWithBuilderLogged(builder: overflowdb.BatchedUpdate.DiffGraphBuilder): Int
- Definition Classes
- CpgPassBase
- def store(overlay: GeneratedMessageV3, name: String, serializedCpg: SerializedCpg): Unit
- Attributes
- protected
- Definition Classes
- CpgPassBase
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- def withStartEndTimesLogged[A](fun: => A): A
- Attributes
- protected
- Definition Classes
- CpgPassBase
Deprecated Value Members
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated
- Deprecated