Search in sources :

Example 1 with ReferenceType

use of de.fraunhofer.aisec.cpg.graph.types.ReferenceType in project cpg by Fraunhofer-AISEC.

the class Util method generateParamName.

private static String generateParamName(int i, @NonNull Type targetType) {
    Deque<String> hierarchy = new ArrayDeque<>();
    Type currLevel = targetType;
    while (currLevel != null) {
        if (currLevel instanceof FunctionPointerType) {
            hierarchy.push("Fptr");
            currLevel = null;
        } else if (currLevel instanceof PointerType) {
            hierarchy.push("Ptr");
            currLevel = ((PointerType) currLevel).getElementType();
        } else if (currLevel instanceof ReferenceType) {
            hierarchy.push("Ref");
            currLevel = ((ReferenceType) currLevel).getElementType();
        } else {
            hierarchy.push(currLevel.getTypeName());
            currLevel = null;
        }
    }
    StringBuilder paramName = new StringBuilder();
    while (!hierarchy.isEmpty()) {
        String part = hierarchy.pop();
        if (part.isEmpty()) {
            continue;
        }
        if (paramName.length() > 0) {
            paramName.append(part.substring(0, 1).toUpperCase());
            if (part.length() >= 2) {
                paramName.append(part.substring(1));
            }
        } else {
            paramName.append(part.toLowerCase());
        }
    }
    paramName.append(i);
    return paramName.toString();
}
Also used : FunctionPointerType(de.fraunhofer.aisec.cpg.graph.types.FunctionPointerType) FunctionPointerType(de.fraunhofer.aisec.cpg.graph.types.FunctionPointerType) PointerType(de.fraunhofer.aisec.cpg.graph.types.PointerType) Type(de.fraunhofer.aisec.cpg.graph.types.Type) ReferenceType(de.fraunhofer.aisec.cpg.graph.types.ReferenceType) FunctionPointerType(de.fraunhofer.aisec.cpg.graph.types.FunctionPointerType) PointerType(de.fraunhofer.aisec.cpg.graph.types.PointerType) ArrayDeque(java.util.ArrayDeque) ReferenceType(de.fraunhofer.aisec.cpg.graph.types.ReferenceType)

Aggregations

FunctionPointerType (de.fraunhofer.aisec.cpg.graph.types.FunctionPointerType)1 PointerType (de.fraunhofer.aisec.cpg.graph.types.PointerType)1 ReferenceType (de.fraunhofer.aisec.cpg.graph.types.ReferenceType)1 Type (de.fraunhofer.aisec.cpg.graph.types.Type)1 ArrayDeque (java.util.ArrayDeque)1