Search in sources :

Example 1 with CPointerTo

use of org.graalvm.nativeimage.c.struct.CPointerTo in project graal by oracle.

the class InfoTreeBuilder method getPointerToTypeName.

private String getPointerToTypeName(ResolvedJavaType type) {
    CPointerTo pointerToAnnotation = type.getAnnotation(CPointerTo.class);
    String nameOfCType = pointerToAnnotation.nameOfCType();
    Class<?> pointerToType = pointerToAnnotation.value();
    CStruct pointerToStructAnnotation;
    CPointerTo pointerToPointerAnnotation;
    do {
        pointerToStructAnnotation = pointerToType.getAnnotation(CStruct.class);
        pointerToPointerAnnotation = pointerToType.getAnnotation(CPointerTo.class);
        if (pointerToStructAnnotation != null || pointerToPointerAnnotation != null) {
            break;
        }
        pointerToType = pointerToType.getInterfaces().length == 1 ? pointerToType.getInterfaces()[0] : null;
    } while (pointerToType != null);
    int n = (nameOfCType.length() > 0 ? 1 : 0) + (pointerToStructAnnotation != null ? 1 : 0) + (pointerToPointerAnnotation != null ? 1 : 0);
    if (n != 1) {
        nativeLibs.addError(// 
        "Exactly one of " + // 
        "1) literal C type name, " + "2) class annotated with @" + CStruct.class.getSimpleName() + // 
        ", or " + "3) class annotated with @" + CPointerTo.class.getSimpleName() + " must be specified in @" + CPointerTo.class.getSimpleName() + " annotation", type);
        return "__error";
    }
    if (pointerToStructAnnotation != null) {
        return getStructName(getMetaAccess().lookupJavaType(pointerToType)) + "*";
    } else if (pointerToPointerAnnotation != null) {
        return getPointerToTypeName(getMetaAccess().lookupJavaType(pointerToType)) + "*";
    } else {
        return nameOfCType;
    }
}
Also used : CStruct(org.graalvm.nativeimage.c.struct.CStruct) CPointerTo(org.graalvm.nativeimage.c.struct.CPointerTo)

Aggregations

CPointerTo (org.graalvm.nativeimage.c.struct.CPointerTo)1 CStruct (org.graalvm.nativeimage.c.struct.CStruct)1