Search in sources :

Example 1 with MemberInfo

use of sharpen.xobotos.api.interop.NativeStruct.MemberInfo in project XobotOS by xamarin.

the class StructHelperClass method buildMembers.

@Override
protected void buildMembers() {
    if (!_resolved)
        throw new IllegalStateException();
    if (_resolveFailed)
        return;
    final NamingStrategy ns = my(Configuration.class).getNamingStrategy();
    final List<MemberInfo> members = _template.getMembers();
    for (int i = 0; i < members.size(); i++) {
        final MemberInfo member = members.get(i);
        final String name = ns.identifier(member.getName());
        if (member.getValue() != null)
            addMember(new ValueMember(name, member.getValue()));
        else
            addMember(new StructMember(_fieldInfo[i], member.getNativeName(), name, member.getMode()));
    }
}
Also used : NamingStrategy(sharpen.core.NamingStrategy) Configuration(sharpen.core.Configuration) MemberInfo(sharpen.xobotos.api.interop.NativeStruct.MemberInfo)

Example 2 with MemberInfo

use of sharpen.xobotos.api.interop.NativeStruct.MemberInfo in project XobotOS by xamarin.

the class StructHelperClass method resolve.

@Override
public boolean resolve(IMarshalContext context) {
    if (BindingManager.DEBUG)
        Sharpen.Debug("RESOLVE STRUCT: %s", getName());
    if (_resolved)
        return !_resolveFailed;
    final List<MemberInfo> members = _template.getMembers();
    _fieldInfo = new ElementInfo[members.size()];
    for (int i = 0; i < members.size(); i++) {
        final MemberInfo member = members.get(i);
        IVariableBinding field = findField(getType(), member.getName());
        if (field == null) {
            Sharpen.Log(Level.SEVERE, "No such field '%s' in type '%s'", member.getName(), BindingUtils.qualifiedName(getType()));
            _resolveFailed = true;
            continue;
        }
        if (member.getValue() != null)
            continue;
        MarshalInfo marshal;
        if (member.getMarshalInfo() != null)
            marshal = member.getMarshalInfo().resolve(field.getType());
        else
            marshal = context.getMarshalInfo(field.getType());
        if (marshal == null) {
            Sharpen.Log(Level.SEVERE, "Missing marshal info for type '%s' of field '%s'", BindingUtils.qualifiedName(field.getType()), member.getName());
            _resolveFailed = true;
            continue;
        }
        _fieldInfo[i] = new ElementInfo(field.getType(), marshal, null, Flags.ELEMENT);
        if (BindingManager.DEBUG)
            Sharpen.Debug("STRUCT MEMBER: %s - %s", member.getName(), BindingUtils.qualifiedName(field.getType()));
        if (!marshal.resolve(context, field.getType())) {
            Sharpen.Log(Level.SEVERE, "Failed to resolve field '%s' in '%s'", member.getName(), BindingUtils.qualifiedName(getType()));
            _resolveFailed = true;
            continue;
        }
        if (!marshal.isPrimitiveType()) {
            Sharpen.Log(Level.SEVERE, "Field '%s' in '%s' is not a primitive type", member.getName(), BindingUtils.qualifiedName(getType()));
            _resolveFailed = true;
            continue;
        }
        if (BindingManager.DEBUG)
            Sharpen.Debug("STRUCT MEMBER DONE: %s - %s", member.getName(), BindingUtils.qualifiedName(field.getType()));
    }
    if (BindingManager.DEBUG)
        Sharpen.Debug("RESOLVE STRUCT DONE: %s%s", getName(), _resolveFailed ? " - ERROR" : "");
    _resolved = true;
    return true;
}
Also used : MemberInfo(sharpen.xobotos.api.interop.NativeStruct.MemberInfo) ElementInfo(sharpen.xobotos.api.interop.NativeMethodBuilder.ElementInfo) IVariableBinding(org.eclipse.jdt.core.dom.IVariableBinding) MarshalInfo(sharpen.xobotos.api.interop.marshal.MarshalInfo)

Aggregations

MemberInfo (sharpen.xobotos.api.interop.NativeStruct.MemberInfo)2 IVariableBinding (org.eclipse.jdt.core.dom.IVariableBinding)1 Configuration (sharpen.core.Configuration)1 NamingStrategy (sharpen.core.NamingStrategy)1 ElementInfo (sharpen.xobotos.api.interop.NativeMethodBuilder.ElementInfo)1 MarshalInfo (sharpen.xobotos.api.interop.marshal.MarshalInfo)1