Search in sources :

Example 1 with MethodBinding

use of sharpen.xobotos.api.bindings.MethodBinding in project XobotOS by xamarin.

the class SharpenGenerator method processMethodDeclaration.

@Override
public CSMethodBase processMethodDeclaration(CSharpBuilder csharpBuilder, CSTypeDeclaration parent, MethodDeclaration node, IMethodBuilderDelegate delegate) {
    final ITypeBuilder type = _typeStack.peek();
    final AbstractMethodTemplate<?> template = type.findMethodTemplate(node);
    if (template == null)
        return null;
    try {
        _outputProviderStack.push(template);
        final OutputType output = getOutputType();
        final OutputMode mode = output.getModeForMember(node);
        if (mode == OutputMode.NOTHING)
            return null;
        MethodBinding binding = template.getBinding();
        if ((binding != null) && (binding.getNativeHandle() != null))
            return null;
        AbstractMethodBuilder<?, ?> builder;
        if (node.isConstructor())
            builder = new ConstructorBuilder((ConstructorTemplate) template, output, node);
        else if (template instanceof DestructorTemplate)
            builder = new DestructorBuilder((DestructorTemplate) template, output, node);
        else
            builder = new MethodBuilder(type, (MethodTemplate) template, output, node, _builder.getNativeBuilder());
        type.registerMember(node, builder);
        _currentMethod = builder;
        CSMethodBase method = builder.build(csharpBuilder, delegate);
        _currentMethod = null;
        if (method != null) {
            delegate.fixup(parent, method);
            parent.addMember(method);
            if (method instanceof CSMethod)
                registerMethod(node.resolveBinding(), (CSMethod) method);
        }
        return method;
    } finally {
        _outputProviderStack.pop();
    }
}
Also used : OutputMode(sharpen.xobotos.output.OutputMode) NativeMethodBuilder(sharpen.xobotos.api.interop.NativeMethodBuilder) MethodBinding(sharpen.xobotos.api.bindings.MethodBinding) OutputType(sharpen.xobotos.output.OutputType)

Example 2 with MethodBinding

use of sharpen.xobotos.api.bindings.MethodBinding in project XobotOS by xamarin.

the class SharpenGenerator method mappedMethodInvocation.

@Override
public CSExpression mappedMethodInvocation(CSharpBuilder builder, MethodInvocation node) {
    final IMethodBinding binding = node.resolveMethodBinding();
    final ITypeBinding declaringType = binding.getDeclaringClass();
    final AbstractTypeBinding typeBinding = my(BindingManager.class).resolveBinding(declaringType);
    final MethodBinding methodBinding = my(BindingManager.class).resolveBinding(binding);
    if (typeBinding instanceof EnumBinding) {
        EnumBinding enumBinding = (EnumBinding) typeBinding;
        String ctorMethod = enumBinding.getConstructorMethod();
        if ((ctorMethod != null) && node.getName().toString().equals(ctorMethod)) {
            return builder.mapExpression(declaringType, (Expression) node.arguments().get(0));
        }
    }
    if (methodBinding != null) {
        NativeHandle nh = methodBinding.getNativeHandle();
        if (nh != null) {
            CSExpression expr = builder.mapExpression(declaringType, node.getExpression());
            String member = nh.getProperty() != null ? nh.getProperty() : nh.getField();
            return new CSMemberReferenceExpression(expr, member);
        }
    }
    if (_currentMethod != null)
        _currentMethod.checkInvocationTarget(binding);
    return null;
}
Also used : NativeHandle(sharpen.xobotos.api.interop.NativeHandle) MethodBinding(sharpen.xobotos.api.bindings.MethodBinding)

Example 3 with MethodBinding

use of sharpen.xobotos.api.bindings.MethodBinding in project XobotOS by xamarin.

the class SharpenGenerator method mappedNullPointer.

@Override
public CSExpression mappedNullPointer(Expression expr) {
    VariableBinding variable = lookupVariableBinding(expr);
    if (variable != null) {
        if (variable.getNativeHandle() != null)
            return new CSNullLiteralExpression();
        if (variable.isPointer())
            return new CSReferenceExpression("System.IntPtr.Zero");
        return null;
    }
    if (expr instanceof MethodInvocation) {
        IMethodBinding method = ((MethodInvocation) expr).resolveMethodBinding();
        MethodBinding binding = my(BindingManager.class).resolveBinding(method);
        if (binding == null)
            return null;
        if (binding.getNativeHandle() != null)
            return new CSNullLiteralExpression();
    }
    return null;
}
Also used : MethodBinding(sharpen.xobotos.api.bindings.MethodBinding) VariableBinding(sharpen.xobotos.api.bindings.VariableBinding)

Aggregations

MethodBinding (sharpen.xobotos.api.bindings.MethodBinding)3 VariableBinding (sharpen.xobotos.api.bindings.VariableBinding)1 NativeHandle (sharpen.xobotos.api.interop.NativeHandle)1 NativeMethodBuilder (sharpen.xobotos.api.interop.NativeMethodBuilder)1 OutputMode (sharpen.xobotos.output.OutputMode)1 OutputType (sharpen.xobotos.output.OutputType)1