Search in sources :

Example 1 with ElementKind

use of com.oracle.svm.hosted.c.info.SizableInfo.ElementKind in project graal by oracle.

the class InfoTreeBuilder method createEnumValueInfo.

private void createEnumValueInfo(EnumInfo enumInfo, ResolvedJavaMethod method) {
    if (!Modifier.isNative(method.getModifiers()) || Modifier.isStatic(method.getModifiers())) {
        nativeLibs.addError("Method annotated with @" + CEnumValue.class.getSimpleName() + " must be a non-static native method", method);
        return;
    }
    if (method.getSignature().getParameterCount(false) != 0) {
        nativeLibs.addError("Method annotated with @" + CEnumValue.class.getSimpleName() + " cannot have parameters", method);
        return;
    }
    ElementKind elementKind = elementKind((ResolvedJavaType) method.getSignature().getReturnType(method.getDeclaringClass()));
    if (elementKind != ElementKind.INTEGER) {
        nativeLibs.addError("Method annotated with @" + CEnumValue.class.getSimpleName() + " must have an integer return type", method);
        return;
    }
    EnumValueInfo valueInfo = new EnumValueInfo(method);
    enumInfo.adoptChild(valueInfo);
    nativeLibs.registerElementInfo(method, valueInfo);
}
Also used : ElementKind(com.oracle.svm.hosted.c.info.SizableInfo.ElementKind) CEnumValue(org.graalvm.nativeimage.c.constant.CEnumValue)

Example 2 with ElementKind

use of com.oracle.svm.hosted.c.info.SizableInfo.ElementKind in project graal by oracle.

the class InfoTreeBuilder method createConstantInfo.

protected void createConstantInfo(ResolvedJavaMethod method) {
    int actualParamCount = method.getSignature().getParameterCount(false);
    if (actualParamCount != 0) {
        nativeLibs.addError("Wrong number of parameters: expected 0; found " + actualParamCount, method);
        return;
    }
    ResolvedJavaType returnType = (ResolvedJavaType) method.getSignature().getReturnType(method.getDeclaringClass());
    if (returnType.getJavaKind() == JavaKind.Void || (returnType.getJavaKind() == JavaKind.Object && !nativeLibs.isString(returnType) && !nativeLibs.isByteArray(returnType) && !nativeLibs.isWordBase(returnType))) {
        nativeLibs.addError("Wrong return type: expected a primitive type, String, or a Word type; found " + returnType.toJavaName(true), method);
        return;
    }
    String constantName = getConstantName(method);
    ElementKind elementKind = elementKind(returnType);
    ConstantInfo constantInfo = new ConstantInfo(constantName, elementKind, method);
    nativeCodeInfo.adoptChild(constantInfo);
    nativeLibs.registerElementInfo(method, constantInfo);
}
Also used : ElementKind(com.oracle.svm.hosted.c.info.SizableInfo.ElementKind) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 3 with ElementKind

use of com.oracle.svm.hosted.c.info.SizableInfo.ElementKind in project graal by oracle.

the class InfoTreeBuilder method elementKind.

private ElementKind elementKind(Collection<AccessorInfo> accessorInfos) {
    ElementKind overallKind = ElementKind.UNKNOWN;
    AccessorInfo overallKindAccessor = null;
    for (AccessorInfo accessorInfo : accessorInfos) {
        ResolvedJavaMethod method = (ResolvedJavaMethod) accessorInfo.getAnnotatedElement();
        ElementKind newKind;
        switch(accessorInfo.getAccessorKind()) {
            case GETTER:
                newKind = elementKind((ResolvedJavaType) method.getSignature().getReturnType(method.getDeclaringClass()));
                break;
            case SETTER:
                newKind = elementKind((ResolvedJavaType) method.getSignature().getParameterType(accessorInfo.valueParameterNumber(false), method.getDeclaringClass()));
                break;
            default:
                continue;
        }
        if (overallKind == ElementKind.UNKNOWN) {
            overallKind = newKind;
            overallKindAccessor = accessorInfo;
        } else if (overallKind != newKind) {
            nativeLibs.addError("Accessor methods mix integer, floating point, and pointer kinds", overallKindAccessor.getAnnotatedElement(), method);
        }
    }
    return overallKind;
}
Also used : ElementKind(com.oracle.svm.hosted.c.info.SizableInfo.ElementKind) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Aggregations

ElementKind (com.oracle.svm.hosted.c.info.SizableInfo.ElementKind)3 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 CEnumValue (org.graalvm.nativeimage.c.constant.CEnumValue)1