use of org.graalvm.nativeimage.c.struct.CStruct in project graal by oracle.
the class InfoTreeBuilder method getStructName.
private static String getStructName(ResolvedJavaType type) {
CStruct structAnnotation = type.getAnnotation(CStruct.class);
if (structAnnotation == null) {
RawStructure rsanno = type.getAnnotation(RawStructure.class);
assert rsanno != null : "Unexpected struct type " + type;
return getSimpleJavaName(type);
}
String name = structAnnotation.value();
if (name.length() == 0) {
name = getSimpleJavaName(type);
}
if (structAnnotation.addStructKeyword()) {
name = "struct " + name;
}
return name;
}
use of org.graalvm.nativeimage.c.struct.CStruct 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;
}
}
Aggregations