List of usage examples for org.eclipse.jdt.internal.compiler.lookup LocalVariableBinding USED
int USED
To view the source code for org.eclipse.jdt.internal.compiler.lookup LocalVariableBinding USED.
Click Source Link
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.OTQualifiedAllocationExpression.java
License:Open Source License
/** * During resolve we make the decision which variant to use. *///from w w w.ja v a 2s. c om public TypeBinding resolveType(BlockScope scope) { if (this.anonymousType == null && this.creatorCall == null && this.enclosingInstance == null) // special case during code assist return super.resolveType(scope); CompilationResult compilationResult = scope.referenceContext().compilationResult(); CheckPoint cp = compilationResult.getCheckPoint(scope.referenceContext()); this.hasEnclosingInstanceProblem = false; if (this.anonymousType == null && this.creatorCall == null) { // no double processing if (this.enclosingInstance instanceof CastExpression) this.enclosingInstance.bits |= DisableUnnecessaryCastCheck; // will check later on (within super.resolveType()) TypeBinding enclosingInstanceType = this.enclosingInstance.resolveType(scope); this.hasEnclosingInstanceProblem = enclosingInstanceType == null; if (!scope.isGeneratedScope() && enclosingInstanceType != null && enclosingInstanceType.isTeam()) // non reference types will trigger error reporting via super.resolveType() { if (this.enclosingInstance instanceof NameReference) { final NameReference anchorRef = (NameReference) this.enclosingInstance; if (!((VariableBinding) anchorRef.binding).isFinal()) { // replace non-final anchor with fake-binding, // so that this type is not compatibly to anything else: char[] variableName = ((VariableBinding) anchorRef.binding).name; switch (anchorRef.bits & ASTNode.RestrictiveFlagMASK) { case Binding.LOCAL: final LocalVariableBinding localOrig = (LocalVariableBinding) anchorRef.binding; // mark the original as used before we procede with a fake copy: localOrig.useFlag = LocalVariableBinding.USED; anchorRef.binding = new LocalVariableBinding(variableName, enclosingInstanceType, ClassFileConstants.AccFinal, false) { @Override public int problemId() { return IProblem.AnchorNotFinal; } }; this.preGenerateTask = new Runnable() { public void run() { // need to transfer this info from the real local to the fake one (don't have that info yet): ((LocalVariableBinding) anchorRef.binding).resolvedPosition = localOrig.resolvedPosition; } }; break; case Binding.FIELD: anchorRef.binding = new FieldBinding(variableName, enclosingInstanceType, ClassFileConstants.AccFinal, scope.referenceType().binding, Constant.NotAConstant) { @Override public int problemId() { return IProblem.AnchorNotFinal; } }; break; default: throw new InternalCompilerError("Unexpected bits, neither local nor field " //$NON-NLS-1$ + anchorRef.bits + ": " + anchorRef); //$NON-NLS-1$ } } } if (this.type.getTypeName().length > 1) { scope.problemReporter().roleCreationNotRelativeToEnclosingTeam(this); return null; } // now it's finally time to create the alternate version: this.creatorCall = CopyInheritance.createConstructorMethodInvocationExpression(scope, this); if (this.creatorCall == null) return null; } } if (this.creatorCall == null) { TypeBinding typ = super.resolveType(scope); if (typ == null || typ instanceof PolyTypeBinding) return typ; if (!this.hasEnclosingInstanceProblem) { // more checks only if no error already // if enclosing is a role request a cast to the class part as required by the inner constructor if (this.enclosingInstance != null) { TypeBinding enclosingType = this.enclosingInstance.resolvedType; if (enclosingType instanceof ReferenceBinding && ((ReferenceBinding) enclosingType).isDirectRole()) this.enclosingInstanceCast = ((ReferenceBinding) enclosingType).getRealClass(); } ReferenceBinding superType = null; if (this.resolvedType instanceof ReferenceBinding) superType = ((ReferenceBinding) this.resolvedType).superclass(); if (superType != null && (superType instanceof RoleTypeBinding)) { RoleTypeBinding superRole = (RoleTypeBinding) superType; if (superRole.hasExplicitAnchor()) scope.problemReporter().extendingExternalizedRole(superRole, this.type); } } } else { // === with creatorCall === this.constant = Constant.NotAConstant; this.resolvedType = this.creatorCall.resolveType(scope); // when creating role nested instance, no cast of enclosing role needed in this branch, // because creator call is routed via the interface of the enclosing role. if (this.resolvedType != null) { if (((ReferenceBinding) this.resolvedType).isAbstract()) { if (!((ReferenceBinding) enclosingInstance().resolvedType).isAbstract()) scope.problemReporter().abstractRoleIsRelevant(this, (ReferenceBinding) this.creatorCall.resolvedType); } if (this.resolvedType.isValidBinding()) { // FIXME(SH): remove cast unwrapping Expression createExpr = this.creatorCall; while (createExpr instanceof CastExpression) // may have been wrapped using CollectedReplacementsTransformer createExpr = ((CastExpression) createExpr).expression; this.binding = ((MessageSend) createExpr).binding; // store the method binding // using lift-ctor in a qualified way? (OTJDL 2.4.1(a)) ReferenceBinding role = (ReferenceBinding) this.resolvedType; MethodBinding creator = this.binding; if (creator != null) { MethodBinding ctor = role.getExactConstructor(creator.parameters); if (Lifting.isLiftToConstructor(ctor, role)) scope.problemReporter().qualifiedUseOfLiftingConstructor(ctor, this.creatorCall); } } } } return this.resolvedType; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.BytecodeTransformer.java
License:Open Source License
/** * Add a byte code sequence that is a placeholder for chaining the * marker arg if the current method is copied lateron. * (See class comment in class ExplicitConstructorCall). * * @param scope//from ww w. j av a2 s . co m * @param codeStream * @param chainTSuperMarkArgPos position that a marker arg will get when added. */ public static void addChainingPlaceholder(BlockScope scope, CodeStream codeStream, int chainTSuperMarkArgPos) { // create local variable "Object _OT$chainArg" // at the very position that will be taken by an added // marker argument: LocalVariableBinding nullVar = new LocalVariableBinding("_OT$chainArg".toCharArray(), //$NON-NLS-1$ scope.getJavaLangObject(), 0, false); nullVar.resolvedPosition = chainTSuperMarkArgPos; nullVar.useFlag = LocalVariableBinding.USED; nullVar.declaringScope = scope.methodScope(); codeStream.record(nullVar); codeStream.addVisibleLocalVariable(nullVar); // add dummy code sequence "aconst_null; astore <i>" // which will be changed by BytecodeTransformer.replaceChainArg // to "nop; aload <i>" with the same <i>. codeStream.aconst_null(); codeStream.astore(chainTSuperMarkArgPos); // optimize small indices? // record positions for local varaible table. nullVar.recordInitializationStartPC(0); if (nullVar.initializationPCs != null) nullVar.recordInitializationEndPC(codeStream.position); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lifting.Lowering.java
License:Open Source License
@NonNull LocalVariableBinding makeNewLocal(BlockScope scope, TypeBinding variableType, int sourceStart, int sourceEnd, boolean deferredResolve) { char[] name = ("_OT$unlowered$" + sourceStart).toCharArray(); //$NON-NLS-1$ LocalVariableBinding varBinding = new LocalVariableBinding(name, variableType, 0, false); varBinding.declaration = new LocalDeclaration(name, sourceStart, sourceEnd); // needed for BlockScope.computeLocalVariablePositions() -> CodeStream.record() if (!deferredResolve) scope.addLocalVariable(varBinding); varBinding.setConstant(Constant.NotAConstant); varBinding.useFlag = LocalVariableBinding.USED; return varBinding; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.DependentTypeBinding.java
License:Open Source License
void initializeDependentType(ITeamAnchor anchor, int valueParamPosition) { // don't store baseclass, will be initialized by baseclass() this._valueParamPosition = valueParamPosition; SyntheticArgumentBinding[] valParams = this.type.valueParamSynthArgs(); if (valueParamPosition > -1) // subtypes don't set paramPosition/matchingField if (valueParamPosition < valParams.length) // defensive this._matchingVariable = valParams[valueParamPosition].matchingField; this._teamAnchor = anchor; if (anchor instanceof LocalVariableBinding) ((LocalVariableBinding) anchor).useFlag = LocalVariableBinding.USED; else if (anchor instanceof FieldBinding) ((FieldBinding) anchor).modifiers |= ExtraCompilerModifiers.AccLocallyUsed; // avoid unused-warning }
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 . ja v a 2 s. c om */ 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 }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.lookup.TeamAnchor.java
License:Open Source License
public TypeBinding getRoleTypeBinding(ReferenceBinding roleBinding, TypeBinding[] arguments, int dimensions) { if (kind() == Binding.LOCAL) ((LocalVariableBinding) this).useFlag = LocalVariableBinding.USED; if (RoleTypeBinding.isRoleWithExplicitAnchor(roleBinding)) { // ITeamAnchor combinedAnchor = combineAnchors(this, ((RoleTypeBinding)roleBinding)._teamAnchor); // if (combinedAnchor == null) { // ITeamAnchor anchor = ((RoleTypeBinding)roleBinding)._teamAnchor; // if (anchor.isPrefixLegal(roleBinding, this)) { // //combinedAnchor = anchor.setPathPrefix(this); // throw new InternalCompilerError("HERE!"); // } else { // FIXME(SH): who calls us with an RTB ?? is this strategy OK? // saw a call from FieldAccessSpec.resolveFeature() (improving anchor) return getRoleTypeBinding(roleBinding.getRealType(), arguments, dimensions); // } // } // return combinedAnchor.getRoleTypeBinding(roleBinding.getRealType(), dimensions); }//from w ww.java2 s . co m ReferenceBinding roleEnclosing = roleBinding.enclosingType(); if (roleEnclosing != null && TypeBinding.notEquals(roleEnclosing.erasure(), leafReferenceType().getRealClass())) // i.e.: teams differ { //assert TeamModel.areCompatibleEnclosings(this.leafType(), roleEnclosing); // team of roleBinding is less specific than this anchor => requesting a weakened type ReferenceBinding strengthenedRole = (ReferenceBinding) TeamModel.strengthenRoleType(leafReferenceType(), roleBinding); if (TypeBinding.notEquals(strengthenedRole, roleBinding)) {// avoid infinite recursion if strengthening made no difference DependentTypeBinding strongRoleType = (DependentTypeBinding) getRoleTypeBinding(strengthenedRole, arguments, 0); if (strongRoleType != null) return WeakenedTypeBinding.makeWeakenedTypeBinding(strongRoleType, roleBinding, dimensions); } if (dimensions == roleBinding.dimensions() && roleBinding instanceof DependentTypeBinding) return roleBinding; } int paramPosition = -1; if (roleBinding instanceof DependentTypeBinding) paramPosition = ((DependentTypeBinding) roleBinding)._valueParamPosition; if (roleBinding instanceof RoleTypeBinding) if (!this.isTeamContainingRole(roleBinding)) // need to switch to outer anchor? return this.asAnchorFor(roleBinding).getDependentTypeBinding(roleBinding, paramPosition, arguments, dimensions, ((RoleTypeBinding) roleBinding).environment); if (roleBinding instanceof WeakenedTypeBinding) { if (((WeakenedTypeBinding) roleBinding)._teamAnchor == this) return roleBinding; } if (roleBinding instanceof ParameterizedTypeBinding) return getDependentTypeBinding(roleBinding, paramPosition, arguments, dimensions, ((ParameterizedTypeBinding) roleBinding).environment); return getDependentTypeBinding(roleBinding, paramPosition, arguments, dimensions); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator.java
License:Open Source License
/** * Try to resolve an argument or return type as an anchored type. * * PRE: Regular type resolution has already failed. * * Currently only handles references of two components: anchor and Type. * (for parameters this is probably OK?) * NO: TODO(SH): arguments could also be anchored to arbitrary expressions/paths! * * @param type type reference to be analyzed (resolvedType is null or invalid) * @param arguments the arguments of the current method * @param index position of the argument to be analyzed * == arguments.length means: analyzing return type. * @param scope scope of the current method. * @return a RoleTypeBinding or null (after reporting error) *///from w w w .ja v a 2 s .c om public static TypeBinding getTypeAnchoredToParameter(TypeReference type, Argument[] arguments, int index, MethodScope scope, CheckPoint cp) { // we only handle QualifiedTypeReferences of length 2, or QualifiedArrayTypeReferences. if (!(type instanceof QualifiedTypeReference)) { return null; // not better than before } QualifiedTypeReference argType = (QualifiedTypeReference) type; // look for anchor in argument list: VariableBinding anchor = null; char[] anchorName = argType.tokens[0]; int argPos; for (argPos = 0; argPos < index; argPos++) { Argument argument = arguments[argPos]; // ensure arguments are bound, which must happen in correct order. argument.bind(scope, argument.type.resolvedType, /*used*/false); if (CharOperation.equals(argument.name, anchorName)) // compare possible anchor { argument.binding.useFlag = LocalVariableBinding.USED; // used as anchor anchor = argument.binding; if (scope.classScope().referenceContext.isConverted) anchor.modifiers |= ClassFileConstants.AccFinal; // lost during conversion. break; } } if (anchor == null) { argPos = -1; // mark as not found in argument list anchor = findAnchorInScope(scope, anchorName); } if (anchor == null) return null; // not better than before. if (!anchor.isFinal()) { char[][] typeName = type.getTypeName(); scope.problemReporter().anchorPathNotFinal(argType, anchor, typeName[typeName.length - 1]); return null; } // defensive programming: if (anchor.type == null) return null; // anchor must be a team: if (!anchor.type.isTeam()) { if (!anchor.type.isValidBinding()) return null; //can't decide whether this is a valid team or not. reportAnchorIsNotATeam(scope, argType); return null; } // delegate for role type lookup: TypeBinding anchoredType = resolveOtherPathElements(scope, type, anchor, argType.tokens, 1, argType.dimensions()); if (anchoredType != null) { if (!anchoredType.isValidBinding()) { scope.problemReporter().invalidType(type, anchoredType); return null; } if (anchoredType.leafComponentType().isRoleType()) { // prepare for creating an AnchorListAttribute RoleTypeBinding leafRoleType = (RoleTypeBinding) anchoredType.leafComponentType(); leafRoleType._argumentPosition = argPos; final AbstractMethodDeclaration methodDecl = scope.referenceMethod(); leafRoleType._declaringMethod = new DependentTypeBinding.IMethodProvider() { public MethodBinding getMethod() { return methodDecl.binding; } }; } scope.referenceContext.compilationResult().rollBack(cp); scope.problemReporter().deprecatedPathSyntax(type); } return anchoredType; }