Package de.fraunhofer.aisec.cpg.graph
Class TypeManager
java.lang.Object
de.fraunhofer.aisec.cpg.graph.TypeManager
public class TypeManager
extends java.lang.Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classTypeManager.Language -
Method Summary
Modifier and Type Method Description voidaddTypeParameter(RecordDeclaration recordDeclaration, java.util.List<ParameterizedType> typeParameters)Adds a List of ParameterizedType torecordToTypeParametersvoidaddTypeParameter(TemplateDeclaration templateDeclaration, ParameterizedType typeParameter)Adds ParameterizedType to thetemplateToTypeParametersto be able to resolve this type when it is usedvoidcacheType(HasType node, Type type)booleancheckArrayAndPointer(Type first, Type second)voidcleanup()booleancontainsParameterizedType(java.util.List<Type> generics)ParameterizedTypecreateOrGetTypeParameter(TemplateDeclaration templateDeclaration, java.lang.String typeName)Check if a ParameterizedType with name typeName is already registered.@NonNull java.util.List<ParameterizedType>getAllParameterizedType(TemplateDeclaration templateDeclaration)@NonNull java.util.Optional<Type>getCommonType(@NonNull java.util.Collection<Type> types)java.util.Set<Type>getFirstOrderTypes()@Nullable LanguageFrontendgetFrontend()static TypeManagergetInstance()@NonNull TypeManager.LanguagegetLanguage()java.util.Set<Type>getSecondOrderTypes()java.util.Map<HasType,java.util.Set<Type>>getTypeCache()@Nullable ParameterizedTypegetTypeParameter(RecordDeclaration recordDeclaration, java.lang.String name)@Nullable ParameterizedTypegetTypeParameter(TemplateDeclaration templateDeclaration, java.lang.String name)SearchestemplateToTypeParametersfor ParameterizedTypes that were defined in a template matching the provided name@NonNull java.util.Map<Type,java.util.List<Type>>getTypeState()voidhandleSingleAlias(LanguageFrontend frontend, java.lang.String rawCode, Type target, java.lang.String aliasString)voidhandleTypedef(LanguageFrontend frontend, java.lang.String rawCode)Handles type defs.booleanisPrimitive(Type type)booleanisSupertypeOf(Type superType, Type subType)static booleanisTypeSystemActive()booleanisUnknown(Type type)<T extends Type>
TregisterType(T t)static voidreset()TyperesolvePossibleTypedef(Type alias)ParameterizedTypesearchTemplateScopeForDefinedParameterizedTypes(Scope scope, java.lang.String name)Searches for ParameterizedType if the scope is a TemplateScope.voidsetLanguageFrontend(@NonNull LanguageFrontend frontend)static voidsetTypeSystemActive(boolean active)booleanstopPropagation(Type type, Type newType)booleantypeExists(java.lang.String name)Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Method Details
-
reset
public static void reset() -
getTypeParameter
public @Nullable ParameterizedType getTypeParameter(RecordDeclaration recordDeclaration, java.lang.String name)- Parameters:
recordDeclaration- that is instantiated by a template containing parameterizedtypesname- of the ParameterizedType we want to get- Returns:
- ParameterizedType if there is a parameterized type defined in the recordDeclaration with matching name, null instead
-
addTypeParameter
public void addTypeParameter(RecordDeclaration recordDeclaration, java.util.List<ParameterizedType> typeParameters)Adds a List of ParameterizedType torecordToTypeParameters- Parameters:
recordDeclaration- will be stored as key for the maptypeParameters- List containing all ParameterizedTypes used by the recordDeclaration and will be stored as value in the map
-
getTypeParameter
public @Nullable ParameterizedType getTypeParameter(TemplateDeclaration templateDeclaration, java.lang.String name)SearchestemplateToTypeParametersfor ParameterizedTypes that were defined in a template matching the provided name- Parameters:
templateDeclaration- that includes the ParameterizedType we are looking forname- name of the ParameterizedType we are looking for- Returns:
-
getAllParameterizedType
public @NonNull java.util.List<ParameterizedType> getAllParameterizedType(TemplateDeclaration templateDeclaration)- Parameters:
templateDeclaration-- Returns:
- List containing all ParameterizedTypes the templateDeclaration defines. If the templateDeclaration is not registered, an empty list is returned.
-
searchTemplateScopeForDefinedParameterizedTypes
public ParameterizedType searchTemplateScopeForDefinedParameterizedTypes(Scope scope, java.lang.String name)Searches for ParameterizedType if the scope is a TemplateScope. If not we search the parent scope until we reach the top.- Parameters:
scope- in which we are searching for the defined ParameterizedTypesname- of the ParameterizedType- Returns:
- ParameterizedType that is found within the scope (or any parent scope) and matches the provided name. Null if we reach the top of the scope without finding a matching ParameterizedType
-
addTypeParameter
public void addTypeParameter(TemplateDeclaration templateDeclaration, ParameterizedType typeParameter)Adds ParameterizedType to thetemplateToTypeParametersto be able to resolve this type when it is used- Parameters:
templateDeclaration- key fortemplateToTypeParameterstypeParameter- ParameterizedType we want to register
-
createOrGetTypeParameter
public ParameterizedType createOrGetTypeParameter(TemplateDeclaration templateDeclaration, java.lang.String typeName)Check if a ParameterizedType with name typeName is already registered. If so we return the already created ParameterizedType. If not, we create and return a new ParameterizedType- Parameters:
templateDeclaration- in which the ParameterizedType is definedtypeName- name of the ParameterizedType- Returns:
-
getTypeState
-
registerType
-
getFirstOrderTypes
-
getSecondOrderTypes
-
typeExists
public boolean typeExists(java.lang.String name) -
getInstance
-
isTypeSystemActive
public static boolean isTypeSystemActive() -
setTypeSystemActive
public static void setTypeSystemActive(boolean active) -
getTypeCache
-
cacheType
-
setLanguageFrontend
-
isPrimitive
-
isUnknown
-
containsParameterizedType
- Parameters:
generics-- Returns:
- true if the generics contain parameterized Types
-
stopPropagation
- Parameters:
type- oldType that we want to replacenewType- newType- Returns:
- true if an objectType with instantiated generics is replaced by the same objectType with parameterizedTypes as generics false otherwise
-
getCommonType
-
getLanguage
-
getFrontend
-
isSupertypeOf
-
checkArrayAndPointer
-
cleanup
public void cleanup() -
handleTypedef
Handles type defs. It is necessary to specify which language frontend this belongs to, because in a parallel run, theTypeManagerdoes not have access to the "current" one.- Parameters:
frontend-rawCode-
-
handleSingleAlias
public void handleSingleAlias(LanguageFrontend frontend, java.lang.String rawCode, Type target, java.lang.String aliasString) -
resolvePossibleTypedef
-