RecoverForXCompilationUnit

io.joern.x2cpg.passes.frontend.RecoverForXCompilationUnit
abstract class RecoverForXCompilationUnit[CompilationUnitType <: AstNode](cpg: Cpg, cu: CompilationUnitType, builder: DiffGraphBuilder, state: XTypeRecoveryState) extends RecursiveTask[Boolean]

Performs type recovery from the root of a compilation unit level

Attributes

CompilationUnitType

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

builder

the graph builder

cpg

the graph.

cu

a compilation unit, e.g. file, procedure, type, etc.

Graph
Supertypes
class RecursiveTask[Boolean]
class ForkJoinTask[Boolean]
trait Serializable
trait Future[Boolean]
class Object
trait Matchable
class Any

Members list

Concise view

Type members

Classlikes

case class FieldPath(compUnitFullName: String, identifier: String)

Convenience class for transporting field names.

Convenience class for transporting field names.

Attributes

compUnitFullName

qualified path to base type holding the member.

identifier

the member name.

Graph
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any

Value members

Abstract methods

protected def isConstructor(c: Call): Boolean

A heuristic method to determine if a call is a constructor or not.

A heuristic method to determine if a call is a constructor or not.

Attributes

Concrete methods

protected def assignTypesToCall(x: Call, types: Set[String]): Set[String]

Given a LHS call, will retrieve its symbol to the given types.

Given a LHS call, will retrieve its symbol to the given types.

Attributes

protected def assignments: Traversal[Assignment]
protected def associateInterproceduralTypes(i: Identifier, base: Identifier, fi: FieldIdentifier, fieldName: String, baseTypes: Set[String]): Set[String]

Similar to associateTypes but used in the case where there is some kind of field load.

Similar to associateTypes but used in the case where there is some kind of field load.

Attributes

protected def associateInterproceduralTypes(i: Identifier, fieldFullName: String, fieldName: String, globalTypes: Set[String], baseTypes: Set[String]): Set[String]
protected def associateTypes(i: Identifier, types: Set[String]): Set[String]

Associates the types with the identifier. This may sometimes be an identifier that should be considered a field which this method uses isField to determine.

Associates the types with the identifier. This may sometimes be an identifier that should be considered a field which this method uses isField to determine.

Attributes

protected def associateTypes(symbol: LocalVar, fa: FieldAccess, types: Set[String]): Set[String]

Associates the types with the identifier. This may sometimes be an identifier that should be considered a field which this method uses isField to determine.

Associates the types with the identifier. This may sometimes be an identifier that should be considered a field which this method uses isField to determine.

Attributes

override def compute(): Boolean

Attributes

Definition Classes
RecursiveTask
protected def createCallFromIdentifierTypeFullName(typeFullName: String, callName: String): String
protected def getFieldBaseType(base: Identifier, fi: FieldIdentifier): Set[String]
protected def getFieldBaseType(baseName: String, fieldName: String): Set[String]
protected def getFieldName(fa: FieldAccess, prefix: String, suffix: String): String

Extracts a string representation of the name of the field within this field access.

Extracts a string representation of the name of the field within this field access.

Attributes

protected def getFieldParents(fa: FieldAccess): Set[String]

Returns the appropriate field parent scope.

Returns the appropriate field parent scope.

Attributes

protected def getIndexAccessTypes(ia: Call): Set[String]

Will attempt to retrieve index access types otherwise will return dummy value.

Will attempt to retrieve index access types otherwise will return dummy value.

Attributes

protected def getLiteralType(l: Literal): Set[String]

Not all frontends populate typeFullName for literals so we allow this to be overridden.

Not all frontends populate typeFullName for literals so we allow this to be overridden.

Attributes

protected def getLocalMember(i: Identifier): Option[Member]

Given an identifier that has been determined to be a field, an attempt is made to get the corresponding member. This implementation follows more the way dynamic languages define method/type relations.

Given an identifier that has been determined to be a field, an attempt is made to get the corresponding member. This implementation follows more the way dynamic languages define method/type relations.

Attributes

i

the identifier.

Returns:

the corresponding member, if found

protected def getSymbolFromCall(c: Call): (LocalKey, Set[FieldPath])

Tries to identify the underlying symbol from the call operation as it is used on the LHS of an assignment. The second element is a list of any associated global keys if applicable.

Tries to identify the underlying symbol from the call operation as it is used on the LHS of an assignment. The second element is a list of any associated global keys if applicable.

Attributes

protected def getTypesFromCall(c: Call): Set[String]

Given a call operation, will attempt to retrieve types from it.

Given a call operation, will attempt to retrieve types from it.

Attributes

protected def importNodes: Traversal[Import]
protected def indexAccessToCollectionVar(c: Call): Option[CollectionVar]

Generates an identifier for collection/index-access operations in the symbol table.

Generates an identifier for collection/index-access operations in the symbol table.

Attributes

protected def isField(i: Identifier): Boolean

A heuristic method to determine if an identifier may be a field or not. The result means that it would be stored in the global symbol table. By default this checks if the identifier name matches a member name.

A heuristic method to determine if an identifier may be a field or not. The result means that it would be stored in the global symbol table. By default this checks if the identifier name matches a member name.

This has found to be an expensive operation accessed often so we have memoized this step.

Attributes

protected def members: Traversal[Member]
protected def methodReturnValues(methodFullNames: Seq[String]): Set[String]

Will attempt to find the return values of a method if in the CPG, otherwise will give a dummy value.

Will attempt to find the return values of a method if in the CPG, otherwise will give a dummy value.

Attributes

protected def persistMemberWithTypeDecl(typeFullName: String, memberName: String, types: Set[String]): Unit

Given a type full name and member name, will persist the given types to the member.

Given a type full name and member name, will persist the given types to the member.

Attributes

memberName

the member name.

typeFullName

the type full name.

types

the types to associate.

protected def persistType(x: StoredNode, types: Set[String]): Unit
protected def postVisitImports(): Unit

The initial import setting is over-approximated, so this step checks the CPG for any matches and prunes against these findings. If there are no findings, it will leave the table as is. The latter is significant for external types or methods.

The initial import setting is over-approximated, so this step checks the CPG for any matches and prunes against these findings. If there are no findings, it will leave the table as is. The latter is significant for external types or methods.

Attributes

protected def prepopulateSymbolTable(): Unit

Provides an entrypoint to add known symbols and their possible types.

Provides an entrypoint to add known symbols and their possible types.

Attributes

protected def setCallMethodFullNameFromBase(c: Call): Set[String]

Will build a call full path using the call base node. This method assumes the base node is in the symbol table.

Will build a call full path using the call base node. This method assumes the base node is in the symbol table.

Attributes

protected def setTypeFromTypeHints(n: MethodParameterIn): Unit
protected def setTypeFromTypeHints(n: MethodReturn): Unit
protected def setTypeInformation(): Unit

Using an entry from the symbol table, will queue the CPG modification to persist the recovered type information.

Using an entry from the symbol table, will queue the CPG modification to persist the recovered type information.

Attributes

protected def setTypes(n: StoredNode, types: Seq[String]): Unit

If there is only 1 type hint then this is set to the typeFullName property and dynamicTypeHintFullName is cleared. If not then dynamicTypeHintFullName is set to the types.

If there is only 1 type hint then this is set to the typeFullName property and dynamicTypeHintFullName is cleared. If not then dynamicTypeHintFullName is set to the types.

Attributes

protected def storeDefaultTypeInfo(n: StoredNode, types: Seq[String]): Unit

Allows one to modify the types assigned to nodes otherwise.

Allows one to modify the types assigned to nodes otherwise.

Attributes

protected def storeIdentifierTypeInfo(i: Identifier, types: Seq[String]): Unit

Allows one to modify the types assigned to identifiers.

Allows one to modify the types assigned to identifiers.

Attributes

protected def storeLocalTypeInfo(l: Local, types: Seq[String]): Unit

Allows one to modify the types assigned to locals.

Allows one to modify the types assigned to locals.

Attributes

protected def storeMemberTypeInfo(m: Member, types: Seq[String]): Unit

Allows one to modify the types assigned to fields.

Allows one to modify the types assigned to fields.

Attributes

protected def typeDeclTraversal(typeFullName: String): Traversal[TypeDecl]

Type decls where member access are required need to point to the correct type decl that holds said members. This allows implementations to use the type names to find the correct type holding members.

Type decls where member access are required need to point to the correct type decl that holds said members. This allows implementations to use the type names to find the correct type holding members.

Attributes

typeFullName

the type full name.

Returns:

the type full name that has member children.

protected def visitAssignments(a: Assignment): Set[String]

Using assignment and import information (in the global symbol table), will propagate these types in the symbol table.

Using assignment and import information (in the global symbol table), will propagate these types in the symbol table.

Attributes

a

assignment call pointer.

protected def visitCallAssignedToBlock(c: Call, b: Block): Set[String]

Visits a call operation being assigned to the result of some operation.

Visits a call operation being assigned to the result of some operation.

Attributes

protected def visitCallAssignedToCall(x: Call, y: Call): Set[String]

Visits a call assigned to the return value of a call. This is often when there are operators involved.

Visits a call assigned to the return value of a call. This is often when there are operators involved.

Attributes

protected def visitCallAssignedToIdentifier(c: Call, i: Identifier): Set[String]

Visits a call assigned to an identifier. This is often when there are operators involved.

Visits a call assigned to an identifier. This is often when there are operators involved.

Attributes

protected def visitCallAssignedToLiteral(c: Call, l: Literal): Set[String]
protected def visitCallAssignedToMethodRef(c: Call, m: MethodRef): Set[String]

Handles a call operation assigned to a method/function pointer.

Handles a call operation assigned to a method/function pointer.

Attributes

protected def visitIdentifierAssignedToBlock(i: Identifier, b: Block): Set[String]

Visits an identifier being assigned to the result of some operation.

Visits an identifier being assigned to the result of some operation.

Attributes

protected def visitIdentifierAssignedToCall(i: Identifier, c: Call): Set[String]

Visits an identifier being assigned to a call. This call could be an operation, function invocation, or constructor invocation.

Visits an identifier being assigned to a call. This call could be an operation, function invocation, or constructor invocation.

Attributes

protected def visitIdentifierAssignedToCallRetVal(i: Identifier, c: Call): Set[String]

Visits an identifier being assigned to a call's return value.

Visits an identifier being assigned to a call's return value.

Attributes

protected def visitIdentifierAssignedToConstructor(i: Identifier, c: Call): Set[String]

Visits an identifier being assigned to a constructor and attempts to speculate the constructor path.

Visits an identifier being assigned to a constructor and attempts to speculate the constructor path.

Attributes

protected def visitIdentifierAssignedToFieldLoad(i: Identifier, fa: FieldAccess): Set[String]

Will handle an identifier being assigned to a field value.

Will handle an identifier being assigned to a field value.

Attributes

protected def visitIdentifierAssignedToIdentifier(x: Identifier, y: Identifier): Set[String]

Visits an identifier being assigned to the value held by another identifier. This is a weak copy.

Visits an identifier being assigned to the value held by another identifier. This is a weak copy.

Attributes

protected def visitIdentifierAssignedToIndexAcess(i: Identifier, c: Call): Set[String]

Visits an identifier being assigned to the result of an index access operation.

Visits an identifier being assigned to the result of an index access operation.

Attributes

protected def visitIdentifierAssignedToLiteral(i: Identifier, l: Literal): Set[String]

Will handle literal value assignments. Override if special handling is required.

Will handle literal value assignments. Override if special handling is required.

Attributes

protected def visitIdentifierAssignedToMethodRef(i: Identifier, m: MethodRef, rec: Option[String]): Set[String]

Will handle an identifier holding a function pointer.

Will handle an identifier holding a function pointer.

Attributes

protected def visitIdentifierAssignedToOperator(i: Identifier, c: Call, operation: String): Set[String]

Visits an identifier being assigned to an operator call.

Visits an identifier being assigned to an operator call.

Attributes

protected def visitIdentifierAssignedToTypeRef(i: Identifier, t: TypeRef, rec: Option[String]): Set[String]

Will handle an identifier holding a type pointer.

Will handle an identifier holding a type pointer.

Attributes

protected def visitImport(i: Import): Unit

Visits an import and stores references in the symbol table as both an identifier and call.

Visits an import and stores references in the symbol table as both an identifier and call.

Attributes

protected def visitStatementsInBlock(b: Block): Set[String]

Process each statement but only assign the type of the last statement to the identifier

Process each statement but only assign the type of the last statement to the identifier

Attributes

Inherited methods

def cancel(x$0: Boolean): Boolean

Attributes

Inherited from:
ForkJoinTask
final def compareAndSetForkJoinTaskTag(x$0: Short, x$1: Short): Boolean

Attributes

Inherited from:
ForkJoinTask
def complete(x$0: Boolean): Unit

Attributes

Inherited from:
ForkJoinTask
def completeExceptionally(x$0: Throwable): Unit

Attributes

Inherited from:
ForkJoinTask
final def fork(): ForkJoinTask[V]

Attributes

Inherited from:
ForkJoinTask
final def get(x$0: Long, x$1: TimeUnit): V

Attributes

Inherited from:
ForkJoinTask
final def get(): V

Attributes

Inherited from:
ForkJoinTask
final def getException(): Throwable

Attributes

Inherited from:
ForkJoinTask
final def getForkJoinTaskTag(): Short

Attributes

Inherited from:
ForkJoinTask
final def getRawResult(): V

Attributes

Inherited from:
RecursiveTask
final def invoke(): V

Attributes

Inherited from:
ForkJoinTask
final def isCancelled(): Boolean

Attributes

Inherited from:
ForkJoinTask
final def isCompletedAbnormally(): Boolean

Attributes

Inherited from:
ForkJoinTask
final def isCompletedNormally(): Boolean

Attributes

Inherited from:
ForkJoinTask
final def isDone(): Boolean

Attributes

Inherited from:
ForkJoinTask
final def join(): V

Attributes

Inherited from:
ForkJoinTask
final def quietlyComplete(): Unit

Attributes

Inherited from:
ForkJoinTask
final def quietlyInvoke(): Unit

Attributes

Inherited from:
ForkJoinTask
final def quietlyJoin(): Unit

Attributes

Inherited from:
ForkJoinTask
def reinitialize(): Unit

Attributes

Inherited from:
ForkJoinTask
final def setForkJoinTaskTag(x$0: Short): Short

Attributes

Inherited from:
ForkJoinTask
def tryUnfork(): Boolean

Attributes

Inherited from:
ForkJoinTask

Concrete fields

protected val addedNodes: HashSet[(Long, String)]

New node tracking set.

New node tracking set.

Attributes

protected val codeRoot: String

The root of the target codebase.

The root of the target codebase.

Attributes

protected val logger: Logger
protected val newTypesForMembers: HashMap[Member, Set[String]]

For tracking members and the type operations that need to be performed. Since these are mostly out of scope locally it helps to track these separately.

For tracking members and the type operations that need to be performed. Since these are mostly out of scope locally it helps to track these separately.

// TODO: Potentially a new use for a global table or modification to the symbol table?

Attributes

protected val pathSep: Char

The delimiter used to separate methods/functions in qualified names.

The delimiter used to separate methods/functions in qualified names.

Attributes

Stores type information for local structures that live within this compilation unit, e.g. local variables.

Stores type information for local structures that live within this compilation unit, e.g. local variables.

Attributes