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

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

Introduction

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

Prototype

public void swap() 

Source Link

Usage

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

License:Open Source License

/**
 * Generate the sequence for invoking this accessor.
 *
 * PRE: the role instance is on the stack, for write access also the new value
 * POST: values from PRE have been consumed, for read access the value is on the stack
 *
 * @param codeStream/*from w  w w. j  a v a 2  s  .c o  m*/
 */
public byte prepareOrGenerateInvocation(CodeStream codeStream, byte opcode) {
    ReferenceBinding roleType = (ReferenceBinding) this.parameters[0];
    if (roleType instanceof UnresolvedReferenceBinding) {
        try {
            roleType = ((UnresolvedReferenceBinding) roleType).resolve(Config.getLookupEnvironment(), false);
        } catch (NotConfiguredException e) {
            e.logWarning("Failed to generate accessor"); //$NON-NLS-1$
            return opcode;
        }
        this.parameters[0] = roleType;
    }
    if (this.purpose == FieldReadAccess || this.purpose == SuperFieldReadAccess) {
        insertOuterAccess(codeStream, roleType); // role -> role,team
        codeStream.swap(); // role,team -> team,role
        codeStream.invoke(Opcodes.OPC_invokevirtual, this, // team,role -> result
                this.declaringClass);
    } else {
        TypeBinding targetType = this.targetWriteField.type;
        LocalVariableBinding arg = new LocalVariableBinding("<tmp>".toCharArray(), //$NON-NLS-1$
                targetType, 0, false);
        arg.resolvedPosition = codeStream.maxLocals;
        arg.useFlag = LocalVariableBinding.USED;
        codeStream.record(arg);
        arg.recordInitializationStartPC(codeStream.position);
        codeStream.store(arg, false/*valueRequired*/); // role, arg -> role
        insertOuterAccess(codeStream, roleType); // role -> role,team
        codeStream.swap(); // role,team -> team,role
        codeStream.load(arg); //            -> team,role,arg
        codeStream.invoke(Opcodes.OPC_invokevirtual, this, //           -> <empty>
                this.declaringClass);
        if (arg.initializationPCs != null) // null checking is asymmetric in LocalVariableBinding.
            arg.recordInitializationEndPC(codeStream.position);
    }
    return 0; // done
}