Search in sources :

Example 1 with RawField

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

the class InfoTreeBuilder method createRawStructInfo.

private void createRawStructInfo(ResolvedJavaType type) {
    if (!validInterfaceDefinition(type, RawStructure.class)) {
        return;
    }
    Map<String, List<AccessorInfo>> fieldAccessorInfos = new TreeMap<>();
    List<AccessorInfo> structAccessorInfos = new ArrayList<>();
    for (ResolvedJavaMethod method : type.getDeclaredMethods()) {
        String fieldName;
        AccessorInfo accessorInfo;
        RawField fieldAnnotation = getMethodAnnotation(method, RawField.class);
        if (fieldAnnotation != null) {
            if (method.getSignature().getReturnKind() == JavaKind.Void) {
                accessorInfo = new AccessorInfo(method, AccessorKind.SETTER, false, hasLocationIdentityParameter(method), hasUniqueLocationIdentity(method));
            } else {
                accessorInfo = new AccessorInfo(method, AccessorKind.GETTER, false, hasLocationIdentityParameter(method), hasUniqueLocationIdentity(method));
            }
            fieldName = getStructFieldName(method, "", accessorInfo.getAccessorKind());
        } else if (method.getSignature().getReturnType(method.getDeclaringClass()).equals(method.getDeclaringClass())) {
            fieldName = null;
            accessorInfo = new AccessorInfo(method, AccessorKind.ADDRESS, method.getSignature().getParameterCount(false) > 0, false, false);
        } else {
            nativeLibs.addError("Unexpected method without annotation", method);
            continue;
        }
        if (accessorValid(accessorInfo)) {
            if (fieldName == null) {
                structAccessorInfos.add(accessorInfo);
            } else {
                Map<String, List<AccessorInfo>> map = fieldAccessorInfos;
                List<AccessorInfo> accessorInfos = map.get(fieldName);
                if (accessorInfos == null) {
                    accessorInfos = new ArrayList<>();
                    map.put(fieldName, accessorInfos);
                }
                accessorInfos.add(accessorInfo);
            }
            nativeLibs.registerElementInfo(method, accessorInfo);
        }
    }
    String typeName = getStructName(type);
    StructInfo structInfo = StructInfo.create(typeName, type);
    structInfo.adoptChildren(structAccessorInfos);
    for (Map.Entry<String, List<AccessorInfo>> entry : fieldAccessorInfos.entrySet()) {
        StructFieldInfo fieldInfo = new StructFieldInfo(entry.getKey(), elementKind(entry.getValue()));
        fieldInfo.adoptChildren(entry.getValue());
        structInfo.adoptChild(fieldInfo);
    }
    nativeCodeInfo.adoptChild(structInfo);
    nativeLibs.registerElementInfo(type, structInfo);
}
Also used : ArrayList(java.util.ArrayList) RawStructure(org.graalvm.nativeimage.c.struct.RawStructure) RawField(org.graalvm.nativeimage.c.struct.RawField) TreeMap(java.util.TreeMap) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) TreeMap(java.util.TreeMap) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 RawField (org.graalvm.nativeimage.c.struct.RawField)1 RawStructure (org.graalvm.nativeimage.c.struct.RawStructure)1