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

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

Introduction

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

Prototype

public void checkcast(TypeBinding typeBinding) 

Source Link

Usage

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.TSuperMessageSend.java

License:Open Source License

@Override
public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
    // for code gen we need to add the marker arg... 
    int len = this.binding.parameters.length;
    TypeBinding[] extendedParameters = new TypeBinding[len + 1];
    System.arraycopy(this.binding.parameters, 0, extendedParameters, 0, len);
    char[] tSuperMarkName = TSuperHelper.getTSuperMarkName(this.tsuperReference.resolvedType.enclosingType());
    extendedParameters[len] = currentScope.getType(tSuperMarkName);

    // ... and find the copied method binding
    MethodBinding codegenBinding = currentScope.getMethod(this.actualReceiverType, this.selector,
            extendedParameters, this);

    if (codegenBinding.problemId() == ProblemReasons.NotFound) {
        // tsuper.m() may in fact refer to tsuper.super.m().
        // try to find the method as super.tsuper() instead:
        ReferenceBinding superRole = ((ReferenceBinding) this.receiver.resolvedType).superclass();
        codegenBinding = getAlternateMethod(currentScope, superRole, extendedParameters);
        if (codegenBinding == null)
            codegenBinding = getAlternateMethod(currentScope, superRole, this.binding.parameters);
        if (codegenBinding == null)
            throw new InternalCompilerError("cannot find real method binding for tsuper call!"); //$NON-NLS-1$

        this.receiver = new SuperReference(this.receiver.sourceStart, this.receiver.sourceEnd);
        this.receiver.resolvedType = superRole;
        this.receiver.constant = Constant.NotAConstant;
        this.actualReceiverType = superRole;
    }//  w w w.  j  a  v a2 s .  com

    MethodBinding tsuperMethod = this.binding;
    this.binding = codegenBinding;
    try {
        super.generateCode(currentScope, codeStream, valueRequired);
    } finally {
        this.binding = tsuperMethod;
    }

    if (valueRequired && this.binding.isCallin()) {
        if (this.resolvedType != null && this.resolvedType.isValidBinding()) {
            if (this.resolvedType.isBaseType()) {
                // something like: ((Integer)result).intValue()
                char[][] boxtypeName = AstGenerator.boxTypeName((BaseTypeBinding) this.resolvedType);
                codeStream.checkcast(currentScope.getType(boxtypeName, 3));
                codeStream.generateUnboxingConversion(this.resolvedType.id);
            } else {
                // (RefType)result
                codeStream.checkcast(this.resolvedType);
            }
        }
    }
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.TSuperMessageSend.java

License:Open Source License

@SuppressWarnings("hiding")
@Override/*from ww w .  ja  v a2s  . c o  m*/
public void generateArguments(MethodBinding binding, Expression[] arguments, BlockScope currentScope,
        CodeStream codeStream) {
    super.generateArguments(binding, arguments, currentScope, codeStream);
    // check if we need to pass the marker arg, too:
    TypeBinding[] parameters = this.binding.parameters;
    TypeBinding tsuperMarkerBinding = parameters.length == 0 ? null : parameters[parameters.length - 1];
    if (tsuperMarkerBinding == null || !TSuperHelper.isMarkerInterface(tsuperMarkerBinding))
        return;
    codeStream.aconst_null();
    codeStream.checkcast(tsuperMarkerBinding);
}

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;/* w w w.  j  av a2  s.c  o m*/
        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

private FieldBinding checkAdjustRoleFieldAccess(FieldBinding fieldBinding, CodeStream codeStream) {
    if (fieldBinding.declaringClass.isRole() && !fieldBinding.declaringClass.isInterface()) {
        ReferenceBinding roleType = fieldBinding.declaringClass;
        roleType = (ReferenceBinding) TeamModel.strengthenRoleType(this.declaringClass, roleType);
        roleType = roleType.getRealClass();
        if (!fieldBinding.isStatic())
            codeStream.checkcast(roleType); // receiver cast

        fieldBinding = new FieldBinding(fieldBinding, roleType);
    }//from  www  .  j av  a2 s.  co m
    return fieldBinding;
}

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

License:Open Source License

private void insertOuterAccess(CodeStream codeStream, ReferenceBinding roleType) {
    // external: use _OT$getTeam() method:
    codeStream.dup(); // role,role
    codeStream.invokeGetTeam(roleType); // role,team
    codeStream.checkcast(this.declaringClass); // role,team
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.RoleMigrationImplementor.java

License:Open Source License

static void genMigrateToTeamInstructions(CodeStream codeStream, SourceTypeBinding roleBinding) {
    // this.this$n = (MyTeam)otherTeam
    codeStream.aload_0(); // this
    codeStream.aload_1(); // otherTeam
    codeStream.checkcast(roleBinding.enclosingType());
    codeStream.fieldAccess(Opcodes.OPC_putfield, enclosingInstanceField(roleBinding), roleBinding);
    codeStream.aload_0();/* w w  w . j a v a  2  s . c  om*/
    codeStream.areturn();
    // not handling caches here, cf. IProblem.MigrateBoundRole
}

From source file:org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.RoleMigrationImplementor.java

License:Open Source License

static void genMigrateToBaseInstructions(CodeStream codeStream, SourceTypeBinding roleBinding, Scope scope,
        char[] cacheName) {
    FieldBinding baseField = roleBinding.getField(IOTConstants._OT_BASE, true);
    // accessing the cache (using remove() and put()):
    ReferenceBinding cacheTypeBinding = (ReferenceBinding) scope.getType(IOTConstants.WEAK_HASH_MAP, 3);
    MethodBinding remove = getMethod(cacheTypeBinding, "remove".toCharArray(), 1); //$NON-NLS-1$
    MethodBinding put = cacheTypeBinding.getMethod(scope, "put".toCharArray()); //$NON-NLS-1$
    // accessing the base object (using _OT$removeRole() and _OT$addRole()):
    WeavingScheme weavingScheme = scope.compilerOptions().weavingScheme;
    ReferenceBinding iboundBase = (ReferenceBinding) scope
            .getType(weavingScheme == WeavingScheme.OTDRE ? IOTConstants.ORG_OBJECTTEAMS_IBOUNDBASE2
                    : IOTConstants.ORG_OBJECTTEAMS_IBOUNDBASE, 3);

    // remove old from cache
    codeStream.aload_0(); // this
    codeStream.fieldAccess(Opcodes.OPC_getfield, enclosingInstanceField(roleBinding), // this.this$n
            roleBinding);/*  w  w  w  . java2  s  .c  om*/
    codeStream.fieldAccess(Opcodes.OPC_getfield, roleBinding.enclosingType().getField(cacheName, true), // this.this$n._OT$cache$R
            roleBinding.enclosingType());
    codeStream.dup(); // for use in put() below
    codeStream.aload_0(); // this
    codeStream.fieldAccess(Opcodes.OPC_getfield, baseField, // this._OT$base
            roleBinding);
    codeStream.dup(); // share for nested method call         // this._OT$base
    // remove role from this (old) base
    genAddOrRemoveRole(codeStream, scope, iboundBase, false);// -> void      // -> base._OT$removeRole(this)
    codeStream.invoke(Opcodes.OPC_invokevirtual, remove, // -> cache.remove(base)
            cacheTypeBinding);
    codeStream.pop(); // discard result

    // this._OT$base = (MyBase)otherBase
    codeStream.aload_0(); // this
    codeStream.aload_1(); // otherBase
    codeStream.checkcast(roleBinding.baseclass());
    codeStream.fieldAccess(Opcodes.OPC_putfield, baseField, roleBinding);

    // add new to cache (cache is still on the stack)
    codeStream.aload_1(); // otherBase
    codeStream.aload_0(); // this (role)
    codeStream.invoke(Opcodes.OPC_invokevirtual, put, cacheTypeBinding);

    // add to new base:
    codeStream.aload_1(); // otherBase
    genAddOrRemoveRole(codeStream, scope, iboundBase, true); // -> void      // -> base._OT$addRemoveRole(this, false)

    codeStream.return_();
}