Class TypeParser

java.lang.Object
de.fraunhofer.aisec.cpg.graph.types.TypeParser

public class TypeParser
extends java.lang.Object
Class responsible for parsing the type definition and create the same Type as described by the type string, but complying to the CPG TypeSystem
  • Field Summary

    Fields
    Modifier and Type Field Description
    static java.util.List<java.lang.String> PRIMITIVES  
    static java.lang.String UNKNOWN_TYPE_STRING  
  • Method Summary

    Modifier and Type Method Description
    static Type.Qualifier calcQualifier​(java.util.List<java.lang.String> typeString, Type.Qualifier old)
    Infers corresponding qualifier information for the type depending of the keywords.
    static Type.Storage calcStorage​(java.util.List<java.lang.String> typeString)
    Infers the corresponding storage type depending on the present storage keyword.
    static @NonNull Type createFrom​(@NonNull java.lang.String type, boolean resolveAlias)
    Use this function for parsing new types and obtaining a new Type the TypeParser creates from * the typeString
    static Type createFrom​(@NonNull java.lang.String type, boolean resolveAlias, LanguageFrontend lang)  
    static @NonNull Type createIgnoringAlias​(@NonNull java.lang.String string)
    Does the same as createIgnoringAlias(String) but explicitly does not use type alias resolution.
    static TypeManager.Language getLanguage()  
    static boolean isElaboratedTypeSpecifier​(java.lang.String specifier)
    Returns whether the specifier is part of an elaborated type specifier.
    static boolean isKnownSpecifier​(java.lang.String specifier)  
    protected static boolean isQualifierSpecifier​(java.lang.String qualifier)  
    static boolean isStorageSpecifier​(java.lang.String specifier)  
    static void reset()  
    static @NonNull Type reWrapType​(@NonNull Type oldChain, @NonNull Type newRoot)
    Reconstructs the type chain when the root node is modified e.g.
    static @NonNull java.util.List<java.lang.String> separate​(@NonNull java.lang.String type)
    Separates typeString into the different Parts that make up the type information
    static void setLanguageSupplier​(java.util.function.Supplier<TypeManager.Language> languageSupplier)
    WARNING: This is only intended for Test Purposes of the TypeParser itself without parsing files.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • UNKNOWN_TYPE_STRING

      public static final java.lang.String UNKNOWN_TYPE_STRING
      See Also:
      Constant Field Values
    • PRIMITIVES

      public static final java.util.List<java.lang.String> PRIMITIVES
  • Method Details

    • reset

      public static void reset()
    • setLanguageSupplier

      public static void setLanguageSupplier​(java.util.function.Supplier<TypeManager.Language> languageSupplier)
      WARNING: This is only intended for Test Purposes of the TypeParser itself without parsing files. Do not use this.
      Parameters:
      languageSupplier - frontend language Java or CPP
    • getLanguage

      public static TypeManager.Language getLanguage()
    • calcQualifier

      public static Type.Qualifier calcQualifier​(java.util.List<java.lang.String> typeString, Type.Qualifier old)
      Infers corresponding qualifier information for the type depending of the keywords.
      Parameters:
      typeString - list of found keywords
      old - previous qualifier information which is completed with newer qualifier information
      Returns:
      Type.Qualifier
    • calcStorage

      public static Type.Storage calcStorage​(java.util.List<java.lang.String> typeString)
      Infers the corresponding storage type depending on the present storage keyword. Default AUTO
      Parameters:
      typeString - List of storage keywords
      Returns:
      Storage
    • isStorageSpecifier

      public static boolean isStorageSpecifier​(java.lang.String specifier)
    • isQualifierSpecifier

      protected static boolean isQualifierSpecifier​(java.lang.String qualifier)
    • isElaboratedTypeSpecifier

      public static boolean isElaboratedTypeSpecifier​(java.lang.String specifier)
      Returns whether the specifier is part of an elaborated type specifier. This only applies to C++ and can be used to declare that a type is a class / struct or union even though the type is not visible in the scope.
      Parameters:
      specifier - the specifier
      Returns:
      true, if it is part of an elaborated type. false, otherwise
    • isKnownSpecifier

      public static boolean isKnownSpecifier​(java.lang.String specifier)
    • separate

      public static @NonNull java.util.List<java.lang.String> separate​(@NonNull java.lang.String type)
      Separates typeString into the different Parts that make up the type information
      Parameters:
      type - string with the entire type definition
      Returns:
      list of strings in which every piece of type information is one element of the list
    • reWrapType

      public static @NonNull Type reWrapType​(@NonNull Type oldChain, @NonNull Type newRoot)
      Reconstructs the type chain when the root node is modified e.g. when swapping with alias (typedef)
      Parameters:
      oldChain - containing all types until the root
      newRoot - root the chain is swapped with
      Returns:
      oldchain but root replaced with newRoot
    • createIgnoringAlias

      public static @NonNull Type createIgnoringAlias​(@NonNull java.lang.String string)
      Does the same as createIgnoringAlias(String) but explicitly does not use type alias resolution. This is usually not what you want. Use with care!
      Parameters:
      string - the string representation of the type
      Returns:
      the type
    • createFrom

      public static Type createFrom​(@NonNull java.lang.String type, boolean resolveAlias, LanguageFrontend lang)
    • createFrom

      public static @NonNull Type createFrom​(@NonNull java.lang.String type, boolean resolveAlias)
      Use this function for parsing new types and obtaining a new Type the TypeParser creates from * the typeString
      Parameters:
      type - string with type information
      resolveAlias - should replace with original type in typedefs
      Returns:
      new type representing the type string. If an exception occurs during the parsing, UnknownType is returned