Class CallResolver
- All Implemented Interfaces:
java.util.function.Consumer<TranslationResult>
public class CallResolver extends Pass
CallExpression and NewExpression targets.
A CallExpression specifies the method that wants to be called via Node.getName(). The call target is a method of the same class the caller belongs to,
so the name is resolved to the appropriate MethodDeclaration. This pass also takes into
consideration that a method might not be present in the current class, but rather has its
implementation in a superclass, and sets the pointer accordingly.
Constructor calls with ConstructExpression are resolved in such a way that their
ConstructExpression.getInstantiates() points to the correct RecordDeclaration.
Additionally, the ConstructExpression.getConstructor() is set to the according ConstructorDeclaration
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<FunctionDeclaration,Type>containingTypeprotected @Nullable TranslationUnitDeclarationcurrentTUprotected java.util.Map<java.lang.String,RecordDeclaration>recordMapprotected java.util.List<TemplateDeclaration>templateListprotected SubgraphWalker.ScopedWalkerwalker -
Constructor Summary
Constructors Constructor Description CallResolver() -
Method Summary
Modifier and Type Method Description voidaccept(@NonNull TranslationResult translationResult)static voidaddImplicitTemplateParametersToCall(java.util.List<de.fraunhofer.aisec.cpg.graph.Node> templateParams, de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression)Adds implicit duplicates of the TemplateParams to the implicit ConstructExpressionprotected voidaddRecursiveDefaultTemplateArgs(de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression, ClassTemplateDeclaration template)Adds the resolved default template arguments recursively to the templateParameter list of the ConstructExpression until a fixpoint is reached e.g.protected voidapplyImplicitCastToArguments(CallExpression call, java.util.List<CastExpression> implicitCasts)Changes the arguments of the CallExpression to use the implcit casts insteadprotected voidapplyImplicitCastToArguments(de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression, java.util.List<CastExpression> implicitCasts)Changes the arguments of the ConstructExpression to use the implcit casts insteadprotected voidapplyMissingParams(ClassTemplateDeclaration template, de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,de.fraunhofer.aisec.cpg.graph.Node> templateParametersExplicitInitialization, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,de.fraunhofer.aisec.cpg.graph.Node> templateParameterRealDefaultInitialization)Apply missingParameters (either explicit or defaults) to the ConstructExpression and its typeprotected voidapplyTemplateInstantiation(CallExpression templateCall, FunctionTemplateDeclaration functionTemplateDeclaration, FunctionDeclaration function, java.util.Map<Declaration,de.fraunhofer.aisec.cpg.graph.Node> initializationSignature, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,TemplateDeclaration.TemplateInitialization> initializationType, java.util.Map<Declaration,java.lang.Integer> orderedInitializationSignature)Performs all necessary steps to make a CallExpression instantiate a template: 1.protected booleancheckArgumentValidity(FunctionDeclaration functionDeclaration, java.util.List<Type> functionDeclarationSignature, CallExpression templateCallExpression, java.util.List<ParameterizedType> explicitInstantiation)protected voidcheckMostCommonImplicitCast(java.util.List<CastExpression> implicitCasts, java.util.List<CastExpression> implicitCastTargets)Checks if the current casts are compatible with the casts necessary to match with a new FunctionDeclaration.voidcleanup()protected booleancompatibleSignatures(java.util.List<Type> callSignature, java.util.List<Type> functionSignature)protected @Nullable java.util.Map<Declaration,de.fraunhofer.aisec.cpg.graph.Node>constructTemplateInitializationSignatureFromTemplateParameters(FunctionTemplateDeclaration functionTemplateDeclaration, CallExpression templateCall, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,TemplateDeclaration.TemplateInitialization> instantiationType, java.util.Map<Declaration,java.lang.Integer> orderedInitializationSignature, java.util.List<ParameterizedType> explicitInstantiated)Creates a Mapping between the Parameters of the TemplateDeclaration and the Values provided for the instantiation of the template (Only the ones that are in defined in the instantiation -> no defaults or implicit).protected ConstructorDeclarationcreateInferredConstructor(@NonNull RecordDeclaration containingRecord, java.util.List<Type> signature)protected voidcreateInferredFunction(java.util.List<FunctionDeclaration> invocationCandidates, CallExpression call)protected @NonNull FunctionDeclarationcreateInferredFunctionDeclaration(RecordDeclaration containingRecord, java.lang.String name, java.lang.String code, boolean isStatic, java.util.List<Type> signature)protected FunctionTemplateDeclarationcreateInferredFunctionTemplate(RecordDeclaration containingRecord, CallExpression call)Create an inferred FunctionTemplateDeclaration if a call to an FunctionTemplate could not be resolvedprotected voidcreateMethodDummies(java.util.List<FunctionDeclaration> invocationCandidates, java.util.Set<Type> possibleContainingTypes, CallExpression call)Creates an inferred element for each RecordDeclaration if the invocationCandidates are emptyprotected voidfindRecords(@NonNull de.fraunhofer.aisec.cpg.graph.Node node, RecordDeclaration curClass)protected voidfindTemplates(@NonNull de.fraunhofer.aisec.cpg.graph.Node node, RecordDeclaration curClass)Caches all TemplateDeclarations intemplateListprotected voidfixInitializers(@NonNull de.fraunhofer.aisec.cpg.graph.Node node, RecordDeclaration curClass)protected voidgenerateInferredStaticallyImportedMethods(@NonNull CallExpression call, @NonNull java.lang.String name, @NonNull java.util.List<FunctionDeclaration> invokes, RecordDeclaration curClass)protected java.util.List<Type>getCallSignature(FunctionDeclaration function, java.util.Map<ParameterizedType,TypeParamDeclaration> parameterizedTypeResolution, java.util.Map<Declaration,de.fraunhofer.aisec.cpg.graph.Node> initializationSignature)protected java.util.List<Type>getCallSignatureWithDefaults(CallExpression call, FunctionDeclaration functionDeclaration)protected @NonNull ConstructorDeclarationgetConstructorDeclaration(de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression, RecordDeclaration recordDeclaration)protected ConstructorDeclarationgetConstructorDeclarationDirectMatch(java.util.List<Type> signature, RecordDeclaration recordDeclaration)protected @NonNull ConstructorDeclarationgetConstructorDeclarationForExplicitInvocation(java.util.List<Type> signature, RecordDeclaration recordDeclaration)protected java.util.List<FunctionDeclaration>getInvocationCandidatesFromParents(java.lang.String name, CallExpression call, java.util.Set<RecordDeclaration> possibleTypes)protected java.util.List<FunctionDeclaration>getInvocationCandidatesFromRecord(RecordDeclaration recordDeclaration, java.lang.String name, CallExpression call)protected java.util.Set<FunctionDeclaration>getOverridingCandidates(java.util.Set<Type> possibleSubTypes, FunctionDeclaration declaration)protected java.util.Map<ParameterizedType,TypeParamDeclaration>getParameterizedSignaturesFromInitialization(java.util.Map<Declaration,de.fraunhofer.aisec.cpg.graph.Node> intialization)Gets all ParameterizedTypes from the initialization signatureprotected java.util.Set<Type>getPossibleContainingTypes(de.fraunhofer.aisec.cpg.graph.Node node, RecordDeclaration curClass)protected java.util.Map<Declaration,de.fraunhofer.aisec.cpg.graph.Node>getTemplateInitializationSignature(FunctionTemplateDeclaration functionTemplateDeclaration, CallExpression templateCall, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,TemplateDeclaration.TemplateInitialization> instantiationType, java.util.Map<Declaration,java.lang.Integer> orderedInitializationSignature, java.util.List<ParameterizedType> explicitInstantiated)Creates a Mapping between the Paramerters of the TemplateDeclaration and the Values provided * for the instantiation of the template.protected voidhandleCallExpression(RecordDeclaration curClass, CallExpression call)protected java.util.List<FunctionDeclaration>handleCXXMethodCall(RecordDeclaration curClass, CallExpression call)protected voidhandleDefaultTemplateParameters(ClassTemplateDeclaration template, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,de.fraunhofer.aisec.cpg.graph.Node> templateParameterRealDefaultInitialization)Matches declared template arguments to their defaults (without defaults of a previously defined template argument)protected voidhandleExplicitTemplateParameters(de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression, ClassTemplateDeclaration template, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,de.fraunhofer.aisec.cpg.graph.Node> templateParametersExplicitInitialization)Matches declared template arguments to the explicit instantiationprotected voidhandleFunctionPointerCall(CallExpression call, de.fraunhofer.aisec.cpg.graph.Node pointer)protected voidhandleImplicitTemplateParameter(FunctionTemplateDeclaration functionTemplateDeclaration, int index, java.util.Map<Declaration,de.fraunhofer.aisec.cpg.graph.Node> instantiationSignature, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,TemplateDeclaration.TemplateInitialization> instantiationType, java.util.Map<Declaration,java.lang.Integer> orderedInitializationSignature)Check if we are handling an implicit template parameter, if so set instantiationSignature, instantiationType and orderedInitializationSignature maps accordninglyprotected voidhandleMethodCall(RecordDeclaration curClass, CallExpression call)protected voidhandleNormalCallCXX(RecordDeclaration curClass, CallExpression call)protected voidhandleNormalCalls(RecordDeclaration curClass, CallExpression call)protected booleanhandlePossibleStaticImport(@Nullable CallExpression call, RecordDeclaration curClass)protected RecordDeclarationhandleSpecificSupertype(RecordDeclaration curClass, CallExpression call)protected voidhandleSuperCall(RecordDeclaration curClass, CallExpression call)Handle calls in the form ofsuper.call()orClassName.super.call(), conforming to JLS13 ยง15.12.1protected booleanhandleTemplateFunctionCalls(@Nullable RecordDeclaration curClass, @NonNull CallExpression templateCall, boolean applyInference)protected booleanisInstantiated(de.fraunhofer.aisec.cpg.graph.Node callParameter, Declaration templateParameter)Checks if the provided call parameter can instantiate the required template parameterprotected voidregisterMethods(RecordDeclaration currentClass, de.fraunhofer.aisec.cpg.graph.Node parent, @NonNull de.fraunhofer.aisec.cpg.graph.Node currentNode)protected voidresolve(@NonNull de.fraunhofer.aisec.cpg.graph.Node node, RecordDeclaration curClass)protected voidresolveArguments(CallExpression call, RecordDeclaration curClass)protected voidresolveConstructExpression(de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression)protected ConstructorDeclarationresolveConstructorWithDefaults(de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression, java.util.List<Type> signature, RecordDeclaration recordDeclaration)protected ConstructorDeclarationresolveConstructorWithImplicitCast(de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression, RecordDeclaration recordDeclaration)protected voidresolveExplicitConstructorInvocation(ExplicitConstructorInvocation eci)protected java.util.List<FunctionDeclaration>resolveWithDefaultArgs(CallExpression call, java.util.List<FunctionDeclaration> initialInvocationCandidates)Resolves a CallExpression to the potential target FunctionDeclarations by checking for ommitted arguments due to previously defined default argumentsprotected java.util.List<FunctionDeclaration>resolveWithDefaultArgsFunc(CallExpression call)protected java.util.List<FunctionDeclaration>resolveWithImplicitCast(CallExpression call, java.util.List<FunctionDeclaration> initialInvocationCandidates)modifies: call arguments by applying implicit castsprotected java.util.List<FunctionDeclaration>resolveWithImplicitCastFunc(CallExpression call)protected booleanshouldContinueSearchInParent(RecordDeclaration recordDeclaration, java.lang.String name)In C++ if there is a method that matches the name we are looking for, we have to stop searching in the parents even if the signature of the method does not matchprotected booleanshouldSearchForInvokesInParent(CallExpression call)In C++ search we don't search in the parent if there is a potential candidate with matching nameprotected java.util.List<CastExpression>signatureWithImplicitCastTransformation(java.util.List<Type> callSignature, java.util.List<Expression> arguments, java.util.List<Type> functionSignature)Computes the implicit casts that are necessary to reach theMethods inherited from class de.fraunhofer.aisec.cpg.passes.Pass
getLang, setLang, supportsLanguageFrontendMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface java.util.function.Consumer
andThen
-
Field Details
-
recordMap
-
templateList
-
containingType
-
currentTU
-
walker
-
-
Constructor Details
-
CallResolver
public CallResolver()
-
-
Method Details
-
cleanup
public void cleanup() -
accept
-
findRecords
protected void findRecords(@NonNull de.fraunhofer.aisec.cpg.graph.Node node, RecordDeclaration curClass) -
findTemplates
protected void findTemplates(@NonNull de.fraunhofer.aisec.cpg.graph.Node node, RecordDeclaration curClass)Caches all TemplateDeclarations intemplateList- Parameters:
node-curClass-
-
registerMethods
protected void registerMethods(RecordDeclaration currentClass, de.fraunhofer.aisec.cpg.graph.Node parent, @NonNull de.fraunhofer.aisec.cpg.graph.Node currentNode) -
fixInitializers
protected void fixInitializers(@NonNull de.fraunhofer.aisec.cpg.graph.Node node, RecordDeclaration curClass) -
addImplicitTemplateParametersToCall
public static void addImplicitTemplateParametersToCall(java.util.List<de.fraunhofer.aisec.cpg.graph.Node> templateParams, de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression)Adds implicit duplicates of the TemplateParams to the implicit ConstructExpression- Parameters:
templateParams- of the VariableDeclaration/NewExpressionconstructExpression- duplicate TemplateParameters (implicit) to preserve AST, as ConstructExpression uses AST as well as the VariableDeclaration/NewExpression
-
handleSuperCall
Handle calls in the form ofsuper.call()orClassName.super.call(), conforming to JLS13 ยง15.12.1- Parameters:
curClass- The class containing the callcall- The call to be resolved
-
handleSpecificSupertype
protected RecordDeclaration handleSpecificSupertype(RecordDeclaration curClass, CallExpression call) -
resolve
protected void resolve(@NonNull de.fraunhofer.aisec.cpg.graph.Node node, RecordDeclaration curClass) -
handleCallExpression
-
isInstantiated
protected boolean isInstantiated(de.fraunhofer.aisec.cpg.graph.Node callParameter, Declaration templateParameter)Checks if the provided call parameter can instantiate the required template parameter- Parameters:
callParameter-templateParameter-- Returns:
- If the TemplateParameter is an TypeParamDeclaration, the callParameter must be an ObjectType => returns true If the TemplateParameter is a ParamVariableDeclaration, the callParamerter must be an Expression and its type must match the type of the ParamVariableDeclaration (same type or subtype) => returns true Otherwise return false
-
getParameterizedSignaturesFromInitialization
protected java.util.Map<ParameterizedType,TypeParamDeclaration> getParameterizedSignaturesFromInitialization(java.util.Map<Declaration,de.fraunhofer.aisec.cpg.graph.Node> intialization)Gets all ParameterizedTypes from the initialization signature- Parameters:
intialization- mapping of the declaration of the template parameters to the explicit values the template is instantiated with- Returns:
- mapping of the parameterizedtypes to the corresponding TypeParamDeclaration in the template
-
handleImplicitTemplateParameter
protected void handleImplicitTemplateParameter(FunctionTemplateDeclaration functionTemplateDeclaration, int index, java.util.Map<Declaration,de.fraunhofer.aisec.cpg.graph.Node> instantiationSignature, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,TemplateDeclaration.TemplateInitialization> instantiationType, java.util.Map<Declaration,java.lang.Integer> orderedInitializationSignature)Check if we are handling an implicit template parameter, if so set instantiationSignature, instantiationType and orderedInitializationSignature maps accordningly- Parameters:
functionTemplateDeclaration- functionTemplate we have identifiedindex- position of the templateParameter we are currently handlinginstantiationSignature- mapping of the Declaration represeting a template parameter to the value that initializes that template parameterinstantiationType- mapping of the instantiation value to the instantiation type (depends on resolutionTemplateDeclaration.TemplateInitializationorderedInitializationSignature- mapping of the ordering of the template parameters
-
constructTemplateInitializationSignatureFromTemplateParameters
protected @Nullable java.util.Map<Declaration,de.fraunhofer.aisec.cpg.graph.Node> constructTemplateInitializationSignatureFromTemplateParameters(FunctionTemplateDeclaration functionTemplateDeclaration, CallExpression templateCall, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,TemplateDeclaration.TemplateInitialization> instantiationType, java.util.Map<Declaration,java.lang.Integer> orderedInitializationSignature, java.util.List<ParameterizedType> explicitInstantiated)Creates a Mapping between the Parameters of the TemplateDeclaration and the Values provided for the instantiation of the template (Only the ones that are in defined in the instantiation -> no defaults or implicit). Additionally, it fills the maps and lists mentioned below:- Parameters:
functionTemplateDeclaration- functionTemplate we have identified that should be instantiatedtemplateCall- callExpression that instantiates the templateinstantiationType- mapping of the instantiation value to the instantiation type (depends * on resolutionTemplateDeclaration.TemplateInitializationorderedInitializationSignature- mapping of the ordering of the template parametersexplicitInstantiated- list of all ParameterizedTypes which are explicitly instantiated- Returns:
- mapping containing the all elements of the signature of the TemplateDeclaration as key and the Type/Expression the Parameter is initialized with. This function returns null if the {ParamVariableDeclaration, TypeParamDeclaration} do not match the provided value for initialization -> initialization not possible
-
getTemplateInitializationSignature
protected java.util.Map<Declaration,de.fraunhofer.aisec.cpg.graph.Node> getTemplateInitializationSignature(FunctionTemplateDeclaration functionTemplateDeclaration, CallExpression templateCall, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,TemplateDeclaration.TemplateInitialization> instantiationType, java.util.Map<Declaration,java.lang.Integer> orderedInitializationSignature, java.util.List<ParameterizedType> explicitInstantiated)Creates a Mapping between the Paramerters of the TemplateDeclaration and the Values provided * for the instantiation of the template.The difference to
constructTemplateInitializationSignatureFromTemplateParameters(de.fraunhofer.aisec.cpg.graph.declarations.FunctionTemplateDeclaration, de.fraunhofer.aisec.cpg.graph.statements.expressions.CallExpression, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node, de.fraunhofer.aisec.cpg.graph.declarations.TemplateDeclaration.TemplateInitialization>, java.util.Map<de.fraunhofer.aisec.cpg.graph.declarations.Declaration, java.lang.Integer>, java.util.List<de.fraunhofer.aisec.cpg.graph.types.ParameterizedType>)is that this one also takes into account defaults and auto deductionsAdditionally, it fills the maps and lists mentioned below:
- Parameters:
functionTemplateDeclaration- functionTemplate we have identified that should be instantiatedtemplateCall- callExpression that instantiates the templateinstantiationType- mapping of the instantiation value to the instantiation type (depends on resolutionTemplateDeclaration.TemplateInitializationorderedInitializationSignature- mapping of the ordering of the template parametersexplicitInstantiated- list of all ParameterizedTypes which are explicitly instantiated- Returns:
- mapping containing the all elements of the signature of the TemplateDeclaration as key and the Type/Expression the Parameter is initialized with. This function returns null if the {ParamVariableDeclaration, TypeParamDeclaration} do not match the provided value for initialization -> initialization not possible
-
handleTemplateFunctionCalls
protected boolean handleTemplateFunctionCalls(@Nullable RecordDeclaration curClass, @NonNull CallExpression templateCall, boolean applyInference)- Parameters:
curClass- class the invoked method must be part of.templateCall- call to instantiate and invoke a function templateapplyInference- if the resolution was unsuccessful and applyInference is true the call will resolve to a instantiation/invocation of an inferred template- Returns:
- true if resolution was successful, false if not
-
applyTemplateInstantiation
protected void applyTemplateInstantiation(CallExpression templateCall, FunctionTemplateDeclaration functionTemplateDeclaration, FunctionDeclaration function, java.util.Map<Declaration,de.fraunhofer.aisec.cpg.graph.Node> initializationSignature, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,TemplateDeclaration.TemplateInitialization> initializationType, java.util.Map<Declaration,java.lang.Integer> orderedInitializationSignature)Performs all necessary steps to make a CallExpression instantiate a template: 1. Set TemplateInstantiation Edge from CallExpression to Template 2. Set Invokes Edge to all realizations of the Tempalte 3. Set return type of the CallExpression and checks if it uses a ParameterizedType and therefore has to be instantiated 4. Set Template Parameters Edge from the CallExpression to all Instantiation Values 5. Set DFG Edges from instantiation to ParamVariableDeclaration in TemplateDeclaration- Parameters:
templateCall- call to instantiate and invoke a function templatefunctionTemplateDeclaration- functionTemplate we have identified that should be instantiatedfunction- FunctionDeclaration representing the realization of the templateinitializationSignature- mapping containing the all elements of the signature of the TemplateDeclaration as key and the Type/Expression the Parameter is initialized with.initializationType- mapping of the instantiation value to the instantiation type (depends on resolutionTemplateDeclaration.TemplateInitializationorderedInitializationSignature- mapping of the ordering of the template parameters
-
checkArgumentValidity
protected boolean checkArgumentValidity(FunctionDeclaration functionDeclaration, java.util.List<Type> functionDeclarationSignature, CallExpression templateCallExpression, java.util.List<ParameterizedType> explicitInstantiation)- Parameters:
functionDeclaration- FunctionDeclaration realization of the templatefunctionDeclarationSignature- Signature of the realization FunctionDeclaration, but replacing the ParameterizedTypes with the ones provided in the instantiationtemplateCallExpression- CallExpression that instantiates the templateexplicitInstantiation- list of the explicitly instantiated type paramters- Returns:
- true if the instantiation of the template is compatible with the templatedeclaration, false otherwise
-
getCallSignature
protected java.util.List<Type> getCallSignature(FunctionDeclaration function, java.util.Map<ParameterizedType,TypeParamDeclaration> parameterizedTypeResolution, java.util.Map<Declaration,de.fraunhofer.aisec.cpg.graph.Node> initializationSignature)- Parameters:
function- FunctionDeclaration realization of the templateparameterizedTypeResolution- mapping of ParameterizedTypes to the TypeParamDeclarations that define them, used to backwards resolveinitializationSignature- mapping between the ParamDeclaration of the template and the corresponding instantiations- Returns:
- List of Types representing the Signature of the FunctionDeclaration, but ParameterizedTypes (which depend on the specific instantiation of the template) are resolved to the values the Template is instantiated with.
-
resolveArguments
-
compatibleSignatures
protected boolean compatibleSignatures(java.util.List<Type> callSignature, java.util.List<Type> functionSignature)- Parameters:
callSignature- Type signature of the CallExpressionfunctionSignature- Type signature of the FunctionDeclaration- Returns:
- true if the CallExpression signature can be transformed into the FunctionDeclaration signature by means of casting
-
signatureWithImplicitCastTransformation
protected java.util.List<CastExpression> signatureWithImplicitCastTransformation(java.util.List<Type> callSignature, java.util.List<Expression> arguments, java.util.List<Type> functionSignature)Computes the implicit casts that are necessary to reach the- Parameters:
callSignature- signature of the call we want to find invocation targets for by performing implicit castsarguments- arguments of the callfunctionSignature- Types of the signature of the possible invocation candidate- Returns:
- List containing either null on the i-th position (if the type of i-th argument of the call equals the type of the i-th argument of the FunctionDeclaration) or a CastExpression on the i-th position (if the argument of the call can be casted to match the type of the argument at the i-th position of the FunctionDeclaration). If the list is empty the signature of the FunctionDeclaration cannot be reached through implicit casts
-
getCallSignatureWithDefaults
protected java.util.List<Type> getCallSignatureWithDefaults(CallExpression call, FunctionDeclaration functionDeclaration)- Parameters:
call- CallExpressionfunctionDeclaration- FunctionDeclaration the CallExpression was resolved to- Returns:
- list containing the signature containing all argument types including the default arguments
-
resolveWithImplicitCast
protected java.util.List<FunctionDeclaration> resolveWithImplicitCast(CallExpression call, java.util.List<FunctionDeclaration> initialInvocationCandidates)modifies: call arguments by applying implicit casts- Parameters:
call- we want to find invocation targets for by performing implicit casts- Returns:
- list of invocation candidates by applying implicit casts
-
resolveWithImplicitCastFunc
- Parameters:
call- we want to find invocation targets for by performing implicit casts- Returns:
- list of invocation candidates by applying implicit casts
-
checkMostCommonImplicitCast
protected void checkMostCommonImplicitCast(java.util.List<CastExpression> implicitCasts, java.util.List<CastExpression> implicitCastTargets)Checks if the current casts are compatible with the casts necessary to match with a new FunctionDeclaration. If a one argument would need to be casted in two different types it would be modified to a cast to UnknownType- Parameters:
implicitCasts- current CastimplicitCastTargets- new Cast
-
applyImplicitCastToArguments
protected void applyImplicitCastToArguments(CallExpression call, java.util.List<CastExpression> implicitCasts)Changes the arguments of the CallExpression to use the implcit casts instead- Parameters:
call- CallExpressionimplicitCasts- Casts
-
applyImplicitCastToArguments
protected void applyImplicitCastToArguments(de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression, java.util.List<CastExpression> implicitCasts)Changes the arguments of the ConstructExpression to use the implcit casts instead- Parameters:
constructExpression- ConstructExpressionimplicitCasts- Casts
-
resolveWithDefaultArgs
protected java.util.List<FunctionDeclaration> resolveWithDefaultArgs(CallExpression call, java.util.List<FunctionDeclaration> initialInvocationCandidates)Resolves a CallExpression to the potential target FunctionDeclarations by checking for ommitted arguments due to previously defined default arguments- Parameters:
call- CallExpression- Returns:
- List of FunctionDeclarations that are the target of the CallExpression (will be connected with an invokes edge)
-
resolveWithDefaultArgsFunc
- Parameters:
call- we want to find invocation targets for by adding the default arguments to the signature- Returns:
- list of invocation candidates that have matching signature when considering default arguments
-
handleNormalCalls
-
handleNormalCallCXX
-
createInferredFunction
protected void createInferredFunction(java.util.List<FunctionDeclaration> invocationCandidates, CallExpression call) -
handleMethodCall
-
handleCXXMethodCall
protected java.util.List<FunctionDeclaration> handleCXXMethodCall(RecordDeclaration curClass, CallExpression call)- Parameters:
call-- Returns:
- FunctionDeclarations that are invocation candidates for the MethodCall call using C++ resolution techniques
-
createMethodDummies
protected void createMethodDummies(java.util.List<FunctionDeclaration> invocationCandidates, java.util.Set<Type> possibleContainingTypes, CallExpression call)Creates an inferred element for each RecordDeclaration if the invocationCandidates are empty- Parameters:
invocationCandidates-possibleContainingTypes-call-
-
shouldSearchForInvokesInParent
In C++ search we don't search in the parent if there is a potential candidate with matching name- Parameters:
call-- Returns:
- true if we should stop searching parent, false otherwise
-
resolveConstructExpression
protected void resolveConstructExpression(de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression) -
addRecursiveDefaultTemplateArgs
protected void addRecursiveDefaultTemplateArgs(de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression, ClassTemplateDeclaration template)Adds the resolved default template arguments recursively to the templateParameter list of the ConstructExpression until a fixpoint is reached e.g. template<class Type1, class Type2 = Type1>- Parameters:
constructExpression-template-
-
applyMissingParams
protected void applyMissingParams(ClassTemplateDeclaration template, de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,de.fraunhofer.aisec.cpg.graph.Node> templateParametersExplicitInitialization, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,de.fraunhofer.aisec.cpg.graph.Node> templateParameterRealDefaultInitialization)Apply missingParameters (either explicit or defaults) to the ConstructExpression and its type- Parameters:
template- Template which is instantiated by the ConstructExpressionconstructExpression-templateParametersExplicitInitialization- mapping of the template parameter to the explicit instantiationtemplateParameterRealDefaultInitialization- mapping of template parameter to its real default (no recursive)
-
handleExplicitTemplateParameters
protected void handleExplicitTemplateParameters(de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression, ClassTemplateDeclaration template, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,de.fraunhofer.aisec.cpg.graph.Node> templateParametersExplicitInitialization)Matches declared template arguments to the explicit instantiation- Parameters:
constructExpression- containing the explicit instantiationtemplate- containing declared template argumentstemplateParametersExplicitInitialization- mapping of the template parameter to the explicit instantiation
-
handleDefaultTemplateParameters
protected void handleDefaultTemplateParameters(ClassTemplateDeclaration template, java.util.Map<de.fraunhofer.aisec.cpg.graph.Node,de.fraunhofer.aisec.cpg.graph.Node> templateParameterRealDefaultInitialization)Matches declared template arguments to their defaults (without defaults of a previously defined template argument)- Parameters:
template- containing template argumetnstemplateParameterRealDefaultInitialization- mapping of template parameter to its real default (no recursive)
-
handleFunctionPointerCall
protected void handleFunctionPointerCall(CallExpression call, de.fraunhofer.aisec.cpg.graph.Node pointer) -
resolveExplicitConstructorInvocation
-
handlePossibleStaticImport
protected boolean handlePossibleStaticImport(@Nullable CallExpression call, RecordDeclaration curClass) -
generateInferredStaticallyImportedMethods
protected void generateInferredStaticallyImportedMethods(@NonNull CallExpression call, @NonNull java.lang.String name, @NonNull java.util.List<FunctionDeclaration> invokes, RecordDeclaration curClass) -
createInferredFunctionTemplate
protected FunctionTemplateDeclaration createInferredFunctionTemplate(RecordDeclaration containingRecord, CallExpression call)Create an inferred FunctionTemplateDeclaration if a call to an FunctionTemplate could not be resolved- Parameters:
containingRecord-call-- Returns:
- inferred FunctionTemplateDeclaration which can be invoked by the call
-
createInferredFunctionDeclaration
protected @NonNull FunctionDeclaration createInferredFunctionDeclaration(RecordDeclaration containingRecord, java.lang.String name, java.lang.String code, boolean isStatic, java.util.List<Type> signature) -
createInferredConstructor
protected ConstructorDeclaration createInferredConstructor(@NonNull RecordDeclaration containingRecord, java.util.List<Type> signature) -
getPossibleContainingTypes
protected java.util.Set<Type> getPossibleContainingTypes(de.fraunhofer.aisec.cpg.graph.Node node, RecordDeclaration curClass) -
getInvocationCandidatesFromRecord
protected java.util.List<FunctionDeclaration> getInvocationCandidatesFromRecord(RecordDeclaration recordDeclaration, java.lang.String name, CallExpression call) -
getInvocationCandidatesFromParents
protected java.util.List<FunctionDeclaration> getInvocationCandidatesFromParents(java.lang.String name, CallExpression call, java.util.Set<RecordDeclaration> possibleTypes) -
shouldContinueSearchInParent
protected boolean shouldContinueSearchInParent(RecordDeclaration recordDeclaration, java.lang.String name)In C++ if there is a method that matches the name we are looking for, we have to stop searching in the parents even if the signature of the method does not match- Parameters:
recordDeclaration-name-- Returns:
- true if there is no method in the recordDeclaration where the name of the method matches with the provided name. false otherwise
-
getOverridingCandidates
protected java.util.Set<FunctionDeclaration> getOverridingCandidates(java.util.Set<Type> possibleSubTypes, FunctionDeclaration declaration) -
getConstructorDeclarationDirectMatch
protected ConstructorDeclaration getConstructorDeclarationDirectMatch(java.util.List<Type> signature, RecordDeclaration recordDeclaration)- Parameters:
signature- of the ConstructExpressionrecordDeclaration- matching the class the ConstructExpression wants to construct- Returns:
- ConstructorDeclaration that matches the provided signature
-
resolveConstructorWithDefaults
protected ConstructorDeclaration resolveConstructorWithDefaults(de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression, java.util.List<Type> signature, RecordDeclaration recordDeclaration)- Parameters:
constructExpression- we want to find an invocation target forsignature- of the ConstructExpression (without defaults)recordDeclaration- associated with the Object the ConstructExpression constructs- Returns:
- a ConstructDeclaration that matches with the signature of the ConstructExpression with added default arguments. The default arguments are added to the arguments edge of the ConstructExpression
-
resolveConstructorWithImplicitCast
protected ConstructorDeclaration resolveConstructorWithImplicitCast(de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression, RecordDeclaration recordDeclaration)- Parameters:
constructExpression- we want to find an invocation target forrecordDeclaration- associated with the Object the ConstructExpression constructs- Returns:
- a ConstructDeclaration that matches the signature of the ConstructExpression by applying one or more implicit casts to the primitive type arguments of the ConstructExpressions. The arguments are proxied through a CastExpression to the type required by the ConstructDeclaration.
-
getConstructorDeclaration
protected @NonNull ConstructorDeclaration getConstructorDeclaration(de.fraunhofer.aisec.cpg.graph.statements.expressions.ConstructExpression constructExpression, RecordDeclaration recordDeclaration)- Parameters:
constructExpression- we want to find an invocation target forrecordDeclaration- associated with the Object the ConstructExpression constructs- Returns:
- a ConstructDeclaration that is an invocation of the given ConstructExpression. If there is no valid ConstructDeclaration we will create an implicit ConstructDeclaration that matches the ConstructExpression.
-
getConstructorDeclarationForExplicitInvocation
protected @NonNull ConstructorDeclaration getConstructorDeclarationForExplicitInvocation(java.util.List<Type> signature, RecordDeclaration recordDeclaration)
-