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>PRIMITIVESstatic java.lang.StringUNKNOWN_TYPE_STRING -
Method Summary
Modifier and Type Method Description static Type.QualifiercalcQualifier(java.util.List<java.lang.String> typeString, Type.Qualifier old)Infers corresponding qualifier information for the type depending of the keywords.static Type.StoragecalcStorage(java.util.List<java.lang.String> typeString)Infers the corresponding storage type depending on the present storage keyword.static @NonNull TypecreateFrom(@NonNull java.lang.String type, boolean resolveAlias)Use this function for parsing new types and obtaining a new Type the TypeParser creates from * the typeStringstatic TypecreateFrom(@NonNull java.lang.String type, boolean resolveAlias, LanguageFrontend lang)static @NonNull TypecreateIgnoringAlias(@NonNull java.lang.String string)Does the same ascreateIgnoringAlias(String)but explicitly does not use type alias resolution.static TypeManager.LanguagegetLanguage()static booleanisElaboratedTypeSpecifier(java.lang.String specifier)Returns whether the specifier is part of an elaborated type specifier.static booleanisKnownSpecifier(java.lang.String specifier)protected static booleanisQualifierSpecifier(java.lang.String qualifier)static booleanisStorageSpecifier(java.lang.String specifier)static voidreset()static @NonNull TypereWrapType(@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 informationstatic voidsetLanguageSupplier(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
-
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 keywordsold- previous qualifier information which is completed with newer qualifier information- Returns:
- Type.Qualifier
-
calcStorage
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
Reconstructs the type chain when the root node is modified e.g. when swapping with alias (typedef)- Parameters:
oldChain- containing all types until the rootnewRoot- root the chain is swapped with- Returns:
- oldchain but root replaced with newRoot
-
createIgnoringAlias
Does the same ascreateIgnoringAlias(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
Use this function for parsing new types and obtaining a new Type the TypeParser creates from * the typeString- Parameters:
type- string with type informationresolveAlias- should replace with original type in typedefs- Returns:
- new type representing the type string. If an exception occurs during the parsing, UnknownType is returned
-