Example usage for org.eclipse.jdt.internal.compiler.codegen CodeStream load

List of usage examples for org.eclipse.jdt.internal.compiler.codegen CodeStream load

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.compiler.codegen CodeStream load.

Prototype

protected final void load(TypeBinding typeBinding, int resolvedPosition) 

Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.SyntheticRoleBridgeMethodBinding.java

License:Open Source License

@Override
public void generateInstructions(CodeStream codeStream) {
    TypeBinding[] arguments = this.parameters;
    int argLen = arguments.length;
    TypeBinding[] targetParameters = this.targetMethod.parameters;
    int resolvedPosition = 0;
    int argIdx = 0;
    int targetIdx = 0;
    switch (this.purpose) {
    case RoleMethodBridgeInner:
        codeStream.aload_0(); // synthetic first arg is the receiver role
        codeStream.checkcast(this.targetMethod.declaringClass);
        resolvedPosition = 1; // first arg is processed
        argIdx = 1;/*  www .j a va 2 s.  com*/
        if (this.targetMethod.isStatic()) {
            codeStream.iconst_0(); // dummy int
            codeStream.aload_2(); // pass synth. team arg
            argIdx += 2;
            resolvedPosition += 2;
        }
        break;
    case RoleMethodBridgeOuter:
        resolvedPosition = 1; // ignore team instance at 0
        argIdx = 0; // pass all args unchanged
        break;
    }
    while (argIdx < argLen) {
        TypeBinding parameter = targetParameters[targetIdx++];
        TypeBinding argument = arguments[argIdx++];
        codeStream.load(argument, resolvedPosition);
        if (TypeBinding.notEquals(argument, parameter))
            codeStream.checkcast(parameter);
        switch (parameter.id) {
        case TypeIds.T_long:
        case TypeIds.T_double:
            resolvedPosition += 2;
            break;
        default:
            resolvedPosition++;
            break;
        }
    }
    if (this.targetMethod.isStatic())
        codeStream.invoke(Opcodes.OPC_invokestatic, this.targetMethod, null);
    else
        codeStream.invoke(Opcodes.OPC_invokespecial, this.targetMethod, null); // non-static private role method
    switch (this.targetMethod.returnType.id) {
    case TypeIds.T_void:
        codeStream.return_();
        break;
    case TypeIds.T_boolean:
    case TypeIds.T_byte:
    case TypeIds.T_char:
    case TypeIds.T_short:
    case TypeIds.T_int:
        codeStream.ireturn();
        break;
    case TypeIds.T_long:
        codeStream.lreturn();
        break;
    case TypeIds.T_float:
        codeStream.freturn();
        break;
    case TypeIds.T_double:
        codeStream.dreturn();
        break;
    default:
        codeStream.areturn();
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.SyntheticRoleFieldAccess.java

License:Open Source License

public void generateBodyForWrite(FieldBinding fieldBinding, CodeStream codeStream) {
    if (fieldBinding.isStatic()) {
        fieldBinding = checkAdjustRoleFieldAccess(fieldBinding, codeStream);
        codeStream.load(fieldBinding.type, 1);
        codeStream.fieldAccess(Opcodes.OPC_putstatic, fieldBinding, fieldBinding.declaringClass);
    } else {/*from   w  w  w.ja va2s. co  m*/
        // prepare "this" and role args:
        LocalVariableBinding thisArg = createArgumentBinding(codeStream, "this".toCharArray(), //$NON-NLS-1$
                fieldBinding.declaringClass.enclosingType(), 0);
        char[] argName = typeNameToLower(this.parameters[0].sourceName());
        LocalVariableBinding arg1 = createArgumentBinding(codeStream, argName, this.parameters[0], 1);
        LocalVariableBinding arg2 = createArgumentBinding(codeStream, "value".toCharArray(), this.parameters[1], //$NON-NLS-1$
                2);

        codeStream.aload_1(); // not a static accessor, positions shifted by 1.
        fieldBinding = checkAdjustRoleFieldAccess(fieldBinding, codeStream);
        codeStream.load(fieldBinding.type, 2);
        codeStream.fieldAccess(Opcodes.OPC_putfield, fieldBinding, fieldBinding.declaringClass);

        // finish args:
        if ((codeStream.generateAttributes & (ClassFileConstants.ATTR_VARS
                | ClassFileConstants.ATTR_STACK_MAP_TABLE | ClassFileConstants.ATTR_STACK_MAP)) == 0)
            return; // avoid NPE below
        thisArg.recordInitializationEndPC(codeStream.position);
        arg1.recordInitializationEndPC(codeStream.position);
        arg2.recordInitializationEndPC(codeStream.position);
    }
}