Class TypeManager

java.lang.Object
de.fraunhofer.aisec.cpg.graph.TypeManager

public class TypeManager
extends java.lang.Object
  • 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 parameterizedtypes
      name - 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 to recordToTypeParameters
      Parameters:
      recordDeclaration - will be stored as key for the map
      typeParameters - 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)
      Searches templateToTypeParameters for ParameterizedTypes that were defined in a template matching the provided name
      Parameters:
      templateDeclaration - that includes the ParameterizedType we are looking for
      name - 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 ParameterizedTypes
      name - 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 the templateToTypeParameters to be able to resolve this type when it is used
      Parameters:
      templateDeclaration - key for templateToTypeParameters
      typeParameter - 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 defined
      typeName - name of the ParameterizedType
      Returns:
    • getTypeState

      public @NonNull java.util.Map<Type,​java.util.List<Type>> getTypeState()
    • registerType

      public <T extends Type> T registerType​(T t)
    • getFirstOrderTypes

      public java.util.Set<Type> getFirstOrderTypes()
    • getSecondOrderTypes

      public java.util.Set<Type> getSecondOrderTypes()
    • typeExists

      public boolean typeExists​(java.lang.String name)
    • getInstance

      public static TypeManager getInstance()
    • isTypeSystemActive

      public static boolean isTypeSystemActive()
    • setTypeSystemActive

      public static void setTypeSystemActive​(boolean active)
    • getTypeCache

      @NotNull public java.util.Map<HasType,​java.util.Set<Type>> getTypeCache()
    • cacheType

      public void cacheType​(HasType node, Type type)
    • setLanguageFrontend

      public void setLanguageFrontend​(@NonNull LanguageFrontend frontend)
    • isPrimitive

      public boolean isPrimitive​(Type type)
    • isUnknown

      public boolean isUnknown​(Type type)
    • containsParameterizedType

      public boolean containsParameterizedType​(java.util.List<Type> generics)
      Parameters:
      generics -
      Returns:
      true if the generics contain parameterized Types
    • stopPropagation

      public boolean stopPropagation​(Type type, Type newType)
      Parameters:
      type - oldType that we want to replace
      newType - newType
      Returns:
      true if an objectType with instantiated generics is replaced by the same objectType with parameterizedTypes as generics false otherwise
    • getCommonType

      public @NonNull java.util.Optional<Type> getCommonType​(@NonNull java.util.Collection<Type> types)
    • getLanguage

      public @NonNull TypeManager.Language getLanguage()
    • getFrontend

      public @Nullable LanguageFrontend getFrontend()
    • isSupertypeOf

      public boolean isSupertypeOf​(Type superType, Type subType)
    • checkArrayAndPointer

      public boolean checkArrayAndPointer​(Type first, Type second)
    • cleanup

      public void cleanup()
    • handleTypedef

      public void handleTypedef​(LanguageFrontend frontend, java.lang.String rawCode)
      Handles type defs. It is necessary to specify which language frontend this belongs to, because in a parallel run, the TypeManager does 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

      public Type resolvePossibleTypedef​(Type alias)