List of usage examples for org.eclipse.jdt.internal.compiler.ast Expression resolve
@Override public void resolve(BlockScope scope)
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.BaseAllocationExpression.java
License:Open Source License
public static Expression convertToDynAccess(BlockScope scope, AllocationExpression expression, int accessId) { TypeBinding baseclass = expression.resolvedType; AstGenerator gen = new AstGenerator(expression); Expression receiver = gen.typeReference(baseclass); char[] selector = CalloutImplementorDyn.OT_ACCESS_STATIC; int modifiers = ClassFileConstants.AccPublic | ClassFileConstants.AccStatic; Expression[] arguments = expression.arguments; Expression enclosingInstance = null; if (expression instanceof QualifiedAllocationExpression) { enclosingInstance = ((QualifiedAllocationExpression) expression).enclosingInstance; } else if (baseclass.isMemberType()) { // extract the enclosing base instance from an outer playedBy: ReferenceBinding enclosingTeam = scope.enclosingReceiverType().enclosingType(); if (enclosingTeam != null && TypeBinding.equalsEquals(baseclass.enclosingType(), enclosingTeam.baseclass)) { enclosingInstance = gen.fieldReference(gen.qualifiedThisReference(gen.typeReference(enclosingTeam)), IOTConstants._OT_BASE); enclosingInstance.resolve(scope); }/*from www . jav a2 s .c o m*/ } if (enclosingInstance != null) { if (arguments == null) { arguments = new Expression[] { enclosingInstance }; } else { int len = arguments.length; System.arraycopy(arguments, 0, arguments = new Expression[len + 1], 1, len); arguments[0] = enclosingInstance; } } MessageSend allocSend = new MessageSend() { @Override public boolean isDecapsulationAllowed(Scope scope2) { // this message send can decapsulate independent of scope return true; } @Override public DecapsulationState getBaseclassDecapsulation() { return DecapsulationState.ALLOWED; } }; gen.setPositions(allocSend); allocSend.receiver = receiver; allocSend.selector = selector; allocSend.constant = Constant.NotAConstant; allocSend.actualReceiverType = baseclass; allocSend.accessId = accessId; allocSend.arguments = createResolvedAccessArguments(gen, accessId, arguments, scope); allocSend.binding = new MethodBinding(modifiers, new TypeBinding[] { TypeBinding.INT, TypeBinding.INT, scope.createArrayType(scope.getJavaLangObject(), 1), scope.getOrgObjectteamsITeam() }, Binding.NO_EXCEPTIONS, (ReferenceBinding) baseclass); allocSend.binding.returnType = scope.getJavaLangObject(); allocSend.binding.selector = selector; return gen.resolvedCastExpression(allocSend, baseclass, CastExpression.RAW); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.PrivateRoleMethodCall.java
License:Open Source License
@Override public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) { // manually redirect to synth bridge: Expression receiverReference; boolean isCallinAccess = false; if (RoleTypeBinding.isRoleWithExplicitAnchor(this.actualReceiverType)) { // new receiver is the anchor denoting the base role's enclosing team instance: ITeamAnchor teamAnchor = ((RoleTypeBinding) this.actualReceiverType)._teamAnchor; TypeAnchorReference syntheticReceiver = this.gen.typeAnchorReference(teamAnchor); syntheticReceiver.isExpression = true; receiverReference = syntheticReceiver; } else {/*w ww .ja v a2s . co m*/ isCallinAccess = true; // call from inside a otre-dyn callin wrapper: receiver is the current team: receiverReference = this.gen.thisReference(); } receiverReference.resolve(currentScope); if (this.isCalloutToField) // for c-t-f this receiver *replaces* the original receiver, // role instance additionally exists as a visible method argument this.receiver = receiverReference; else // for method callout or callin to private *add* the team instance to the front of pushes // original role instance receiver will become the first implicit argument receiverReference.generateCode(currentScope, codeStream, true/*valueRequired*/); if (isCallinAccess) { // might need more synthetic args: if (this.binding.isStatic()) { codeStream.aconst_null(); // first arg in role bridge: (null) role codeStream.iconst_0(); // enclosingTeamInstance: dummy value codeStream.aload_0(); // enclosingTeamInstance: team instance } } // directly use the accessor and its declaring class for the invoke instruction: this.binding = this.syntheticAccessor; this.actualReceiverType = this.syntheticAccessor.declaringClass; this.syntheticAccessor = null; super.generateCode(currentScope, codeStream, valueRequired); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.ast.WithinStatement.java
License:Open Source License
public void resolve(BlockScope upperScope) { this.scope = new BlockScope(upperScope, this.explicitDeclarations); // special treatment of type errors for teamExpr: Expression teamExpr = this.teamVarDecl.initialization; teamExpr.resolve(this.scope); TypeBinding tb = teamExpr.resolvedType; if ((tb instanceof ReferenceBinding) && ((ReferenceBinding) tb).isTeam()) { this.teamVarDecl.initialization = null; // don't resolve again... this.teamVarDecl.resolve(this.scope); // no type error possible any more. this.teamVarDecl.initialization = teamExpr; // ... restore. } else {/* w ww.j a v a 2 s . com*/ this.scope.problemReporter().withinStatementNeedsTeamInstance(teamExpr); // don't procede because we don't want to see errors related // to the generated variable... return; } for (int i = 1; i < this.statements.length; i++) // skip [0]: it's the teamVarDecl. this.statements[i].resolve(this.scope); }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementor.java
License:Open Source License
/** * Implements inherited abstract method. * * Note that as a side effect, this method modifies methodMapping.mappings! * * @param methodMapping lookup method spec and parameter mapping here * @param wrapperDeclaration use args of this method if no mapping is involved * @param implParameters parameters of the implemented method to invoke (possibly enhanced) * @param idx argument position on the target side * @param hasResultArgument as a 'result' argument been prepended to the wrapper args? * @param sourceMethodSpec this signature defines the provided args * @return the expression to pass to the implemented method. */// w w w. ja v a2 s . c o m Expression getArgument(AbstractMethodMappingDeclaration methodMapping, MethodDeclaration wrapperDeclaration, TypeBinding[] implParameters, int idx, boolean hasResultArgument, final MethodSpec sourceMethodSpec) { final MethodSpec implementationMethodSpec = methodMapping.getImplementationMethodSpec(); Expression mappedArgExpr = null; int pos = -1; char[] targetArgName = null; int generatedArgsLen = methodMapping.isReplaceCallin() ? getMethodSignatureEnhancer().ENHANCING_ARG_LEN : 0; final int srcIdx = idx - generatedArgsLen; // index into source-code signatures. int wrapperPrefixLen = hasResultArgument ? 2 : 1; // skip prepended base_arg, and possibly result arg if (methodMapping.mappings == null // have no parameter mapping || methodMapping.mappings.length == 0 || idx < generatedArgsLen) // don't map generated args. { targetArgName = idx + wrapperPrefixLen < wrapperDeclaration.arguments.length ? wrapperDeclaration.arguments[idx + wrapperPrefixLen].name : CharOperation.concat(IOTConstants.OT_DOLLAR_NAME, "missingArg".toCharArray()); //$NON-NLS-1$ MethodSpec rmSpec = methodMapping.roleMethodSpec; mappedArgExpr = genSimpleArgExpr(targetArgName, rmSpec); if (idx >= generatedArgsLen) mappedArgExpr.resolve(wrapperDeclaration.scope); // resolved type needed in liftCall(). } else { targetArgName = implementationMethodSpec.arguments[srcIdx].name; // retrieve info collected during analyzeParameterMappings: Pair<Expression, Integer> mapper = methodMapping.mappingExpressions[srcIdx]; mappedArgExpr = mapper.first; if (mapper.second != null) pos = mapper.second.intValue(); } if (mappedArgExpr != null) { SourceTypeBinding roleType = methodMapping.scope.enclosingSourceType(); if (idx >= implParameters.length) // CLOVER: never true in jacks suite return mappedArgExpr; // arg is invisible to receiver, don't lift TypeBinding expectedType = implParameters[idx]; // arg might have been weakened: if (expectedType.isRole() && TypeBinding.notEquals(expectedType.enclosingType(), roleType.enclosingType())) expectedType = TeamModel.strengthenRoleType(roleType, expectedType); AstGenerator gen = new AstGenerator(mappedArgExpr.sourceStart, mappedArgExpr.sourceEnd); Expression receiver = null; TypeBinding expectedLeaf = expectedType.leafComponentType(); if (RoleTypeBinding.isRoleWithoutExplicitAnchor(expectedLeaf) && TypeBinding .equalsEquals(roleType.getRealClass(), ((ReferenceBinding) expectedLeaf).enclosingType())) { // expectedType is a role of the current role(=team), // use the role as the receiver for the lift call: receiver = gen.singleNameReference(ROLE_VAR_NAME); } if (sourceMethodSpec.hasSignature) { if (sourceMethodSpec.argNeedsTranslation(srcIdx)) { mappedArgExpr.tagReportedBaseclassDecapsulation(); return Lifting.liftCall(methodMapping.scope, receiver != null ? receiver : gen.qualifiedThisReference(expectedLeaf.enclosingType()), mappedArgExpr, sourceMethodSpec.resolvedParameters()[srcIdx], expectedType, methodMapping.isReplaceCallin()/*needLowering*/); } if (methodMapping.mappings == null) // we have signatures and no parameter mapping. // if no need for translation has been recorded, it IS not needed. return mappedArgExpr; } // don't know yet whether lifting is actually needed (=>potentially) Expression liftExpr = gen.potentialLift(receiver, mappedArgExpr, expectedType, methodMapping.isReplaceCallin()); // reversible? // if param mappings are present, connect the PLE to the method spec for propagating translation flag // (CallinMethodMappingsAttribute needs to know whether lifting is actually needed.) if (methodMapping.mappings != null && liftExpr instanceof PotentialLiftExpression) { final int srcPos = pos; ((PotentialLiftExpression) liftExpr).onLiftingRequired(new Runnable() { public void run() { if (srcPos != -1) sourceMethodSpec.argNeedsTranslation[srcPos] = true; implementationMethodSpec.argNeedsTranslation[srcIdx] = true; } }); } return liftExpr; } wrapperDeclaration.scope.problemReporter().unmappedParameter(targetArgName, implementationMethodSpec, methodMapping.isCallout()); return null; }
From source file:org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator.java
License:Open Source License
/** * Version to use by MessageSend.//from w ww.j a v a 2 s .co m * May specialize role type to revert signature weakening. * * @param send retrieve all relevant information from this message send. * @param scope * @return wrapped type or original or null */ public static TypeBinding maybeWrapQualifiedRoleType(MessageSend send, BlockScope scope) { Expression receiver = send.receiver; TypeBinding returnType = send.binding.returnType; if (returnType == null || !(returnType.leafComponentType() instanceof ReferenceBinding) || returnType.leafComponentType().isEnum()) return returnType; int dimensions = returnType.dimensions(); ReferenceBinding refReturn = (ReferenceBinding) returnType.leafComponentType(); // don't try externalized non-public role if compatibility can be established with plain types: if (send.expectedType != null && !(send.expectedType instanceof DependentTypeBinding)) if (refReturn.isRole() && !refReturn.isPublic() && returnType.isCompatibleWith(send.expectedType)) return returnType; boolean isCalloutGet = CharOperation.prefixEquals(IOTConstants.OT_GETFIELD, send.selector); // // FIXME(SH): test with field of role type { AbstractMethodDeclaration referenceMethod = scope.methodScope().referenceMethod(); if (referenceMethod != null) isCalloutGet &= (referenceMethod.isMappingWrapper.callout()); } if (!isCalloutGet) { if (refReturn instanceof WeakenedTypeBinding) { WeakenedTypeBinding weakenedReturn = (WeakenedTypeBinding) refReturn; if (dimensions > 0) throw new InternalCompilerError("array not yet supported in this position"); //$NON-NLS-1$ ReferenceBinding strongType = weakenedReturn.getStrongType(); if (TypeBinding.notEquals(strongType.getRealType(), weakenedReturn.weakenedType)) { if (send.expectedType == null || !weakenedReturn.weakenedType.isCompatibleWith(send.expectedType)) send.valueCast = strongType; } TypeBinding instantiated = maybeWrapQualifiedRoleType(scope, send.receiver, strongType, send); return instantiated; } if (refReturn instanceof RoleTypeBinding) { RoleTypeBinding roleReturn = (RoleTypeBinding) refReturn; if (roleReturn._argumentPosition > -1 && send.binding.original() == roleReturn._declaringMethod.getMethod()) { ReferenceBinding roleEnclosing = roleReturn.enclosingType(); // anchored to argument, instantiate directly: Expression anchorExpr = send.arguments[roleReturn._argumentPosition]; TypeBinding anchorType = anchorExpr.resolvedType; ITeamAnchor anchor = null; if (anchorType.isRole() && ((ReferenceBinding) anchorType).isCompatibleViaLowering(roleEnclosing)) { // see 1.1.31-otjld-stacked-teams-1 f. if (anchorExpr.isThis()) anchor = ((ReferenceBinding) anchorType).getField(IOTConstants._OT_BASE, true); else return returnType; // cannot improve, error will be reported upstream } else { if (anchorType.isRole()) anchorType = ((ReferenceBinding) anchorType).getRealClass(); // ignore role-ness of team anchor if (!anchorType.isCompatibleWith(roleEnclosing)) return returnType; // cannot improve, anchor doesn't match expected team. anchor = (ITeamAnchor) ((NameReference) anchorExpr).binding; } return anchor.getRoleTypeBinding(roleReturn, returnType.dimensions()); } // retrieve existing information: ITeamAnchor anchor = roleReturn._teamAnchor; ReferenceBinding receiverType = (ReferenceBinding) send.actualReceiverType; if (anchor instanceof TThisBinding // not yet instantiated && (receiverType.isTeam() || receiverType.isRole())) { roleReturn = (RoleTypeBinding) TeamModel.strengthenRoleType(receiverType, roleReturn); if (dimensions > 0) returnType = roleReturn.getArrayType(dimensions); else returnType = roleReturn; } if (avoidWrapRoleType(scope, receiver)) // don't use synthetic _OT$role as additional anchor return returnType; } } else { if (send.arguments != null && send.arguments.length > 0) { // no arguments if accessed field is static // for wrapping types of a field access method, fake a _OT$base receiver // (although method is actually static) // see also comment in FieldAccessSpec.createMethod(). receiver = new SingleNameReference(IOTConstants._OT_BASE, 0); receiver.resolve(scope); } } return maybeWrapQualifiedRoleType(scope, receiver, returnType, send); }