Search in sources :

Example 1 with WrappedJavaType

use of com.oracle.graal.pointsto.infrastructure.WrappedJavaType in project graal by oracle.

the class InfoTreeBuilder method createEnumInfo.

private void createEnumInfo(ResolvedJavaType type) {
    if (!nativeLibs.isEnum(type)) {
        nativeLibs.addError("Annotation @" + CEnum.class.getSimpleName() + " can only be used on an Java enumeration", type);
        return;
    }
    CEnum annotation = type.getAnnotation(CEnum.class);
    String name = annotation.value();
    if (!name.isEmpty()) {
        if (annotation.addEnumKeyword()) {
            name = "enum " + name;
        }
    } else {
        name = "int";
    }
    EnumInfo enumInfo = new EnumInfo(name, type);
    /* Use the wrapped type to avoid registering all CEnum annotated classes as reachable. */
    ResolvedJavaType wrappedType = ((WrappedJavaType) type).getWrapped();
    for (ResolvedJavaField field : wrappedType.getStaticFields()) {
        assert Modifier.isStatic(field.getModifiers());
        if (Modifier.isFinal(field.getModifiers()) && field.getType().equals(wrappedType)) {
            createEnumConstantInfo(enumInfo, field);
        }
    }
    for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
        if (getMethodAnnotation(method, CEnumValue.class) != null) {
            createEnumValueInfo(enumInfo, method);
        }
        if (getMethodAnnotation(method, CEnumLookup.class) != null) {
            createEnumLookupInfo(enumInfo, method);
        }
    }
    nativeCodeInfo.adoptChild(enumInfo);
    nativeLibs.registerElementInfo(type, enumInfo);
}
Also used : CEnumLookup(org.graalvm.nativeimage.c.constant.CEnumLookup) CEnumValue(org.graalvm.nativeimage.c.constant.CEnumValue) CEnum(org.graalvm.nativeimage.c.constant.CEnum) WrappedJavaType(com.oracle.graal.pointsto.infrastructure.WrappedJavaType) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Aggregations

WrappedJavaType (com.oracle.graal.pointsto.infrastructure.WrappedJavaType)1 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 CEnum (org.graalvm.nativeimage.c.constant.CEnum)1 CEnumLookup (org.graalvm.nativeimage.c.constant.CEnumLookup)1 CEnumValue (org.graalvm.nativeimage.c.constant.CEnumValue)1