diff options
author | Stephan Herrmann | 2014-04-18 19:18:19 +0000 |
---|---|---|
committer | Stephan Herrmann | 2014-04-18 21:32:45 +0000 |
commit | 794deee40327862be529603b140d568fee2b5009 (patch) | |
tree | 5f38e89d5c2e3b4b978fc4f480b7df02f1a7f91c | |
parent | f7adc5c3c5394eb83909d2d64c2590c5917f68fb (diff) | |
download | org.eclipse.objectteams-794deee40327862be529603b140d568fee2b5009.tar.gz org.eclipse.objectteams-794deee40327862be529603b140d568fee2b5009.tar.xz org.eclipse.objectteams-794deee40327862be529603b140d568fee2b5009.zip |
Bug 433077 - [otdre] select weaving scheme via a regular compiler option
52 files changed, 455 insertions, 300 deletions
diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java index becb746fb..83f5ac912 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AbstractMethodDeclaration.java @@ -740,8 +740,8 @@ public abstract class AbstractMethodDeclaration if (this.arguments != null) { //{ObjectTeams: retrench enhanced callin args: int firstArg = 0; - if (isCallin()) - firstArg = MethodSignatureEnhancer.ENHANCING_ARG_LEN; + if (isCallin() && this.scope != null) + firstArg = MethodSignatureEnhancer.getEnhancingArgLen(this.scope.compilerOptions().weavingScheme); for (int i = firstArg; i < this.arguments.length; i++) { /* orig: for (int i = 0; i < this.arguments.length; i++) { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java index 99bce3d70..6109d678a 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/AllocationExpression.java @@ -56,6 +56,7 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.*; import org.eclipse.jdt.internal.compiler.flow.*; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.impl.Constant; import org.eclipse.jdt.internal.compiler.lookup.*; import org.eclipse.jdt.internal.compiler.problem.ProblemSeverities; @@ -68,7 +69,6 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.AnchorMapping; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.DependentTypeBinding; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.ITeamAnchor; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel; import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.CopyInheritance; import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator; @@ -639,7 +639,7 @@ TypeBinding resolvePart3(ResolutionState state) { if (baseclassDecapsulationAllowed) { int accessId = state.scope.enclosingSourceType().roleModel.addInaccessibleBaseMethod(this.binding); state.scope.problemReporter().decapsulation(this, state.scope); - if (CallinImplementorDyn.DYNAMIC_WEAVING) { + if (state.scope.compilerOptions().weavingScheme == WeavingScheme.OTDRE) { this.resolvedType = allocationType; throw new ConstructorDecapsulationException(accessId); } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java index fae834c50..a1a7580d7 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/MessageSend.java @@ -72,6 +72,7 @@ import org.eclipse.jdt.internal.compiler.flow.UnconditionalFlowInfo; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; import org.eclipse.jdt.internal.compiler.impl.Constant; import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; @@ -110,7 +111,6 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.AnchorMapping; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.DependentTypeBinding; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.SyntheticRoleBridgeMethodBinding; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.WeakenedTypeBinding; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CalloutImplementor; import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CalloutImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel; @@ -1025,6 +1025,7 @@ public TypeBinding resolveType(BlockScope scope) { return this.resolvedType = null; } } + WeavingScheme weavingScheme = scope.compilerOptions().weavingScheme; // SH} if (!this.binding.isValidBinding()) { @@ -1047,7 +1048,7 @@ public TypeBinding resolveType(BlockScope scope) { this.accessId = scope.enclosingSourceType().roleModel.addInaccessibleBaseMethod(this.binding); // pretend that accessor method were already there: this.binding = new MethodBinding(this.binding, this.binding.declaringClass.getRealClass()); - if (CallinImplementorDyn.DYNAMIC_WEAVING) { + if (weavingScheme == WeavingScheme.OTDRE) { if (this.binding.isStatic()) this.binding.selector = CalloutImplementorDyn.OT_ACCESS_STATIC; else @@ -1115,7 +1116,7 @@ public TypeBinding resolveType(BlockScope scope) { //{ObjectTeams: new check (base.m() within m() ?) if (this.receiver instanceof BaseReference) { - if (!CallinImplementorDyn.DYNAMIC_WEAVING) { // FIXME(OTDYN): need a new strategy to check this for dyn weaving. + if (weavingScheme == WeavingScheme.OTRE) { // FIXME(OTDYN): need a new strategy to check this for dyn weaving. AbstractMethodDeclaration enclosingMethod = scope.methodScope().referenceMethod(); if (!enclosingMethod.isCallin()) enclosingMethod = BaseCallMessageSend.getOuterCallinMethod(scope.methodScope()); diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java index 53e9cd225..d037fb006 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/ast/QualifiedAllocationExpression.java @@ -48,6 +48,7 @@ import org.eclipse.jdt.internal.compiler.codegen.Opcodes; import org.eclipse.jdt.internal.compiler.flow.FlowContext; import org.eclipse.jdt.internal.compiler.flow.FlowInfo; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.impl.Constant; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; @@ -70,7 +71,6 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.ast.OTQualifiedAlloca import org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies; import org.eclipse.objectteams.otdt.internal.core.compiler.control.ITranslationStates; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.AnchorMapping; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator; @@ -606,7 +606,7 @@ public static abstract class AbstractQualifiedAllocationExpression extends Alloc this.binding = ((ProblemMethodBinding)this.binding).closestMatch; int accessId = scope.enclosingSourceType().roleModel.addInaccessibleBaseMethod(this.binding); scope.problemReporter().decapsulation(this, scope); - if (CallinImplementorDyn.DYNAMIC_WEAVING) { + if (scope.compilerOptions().weavingScheme == WeavingScheme.OTDRE) { this.resolvedType = allocationType; throw new ConstructorDecapsulationException(accessId); } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java index 162861ae2..39ba9802f 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/impl/CompilerOptions.java @@ -228,8 +228,20 @@ public class CompilerOptions { public static final String OPTION_PureJavaOnly = "org.eclipse.objectteams.otdt.compiler.option.pure_java"; //$NON-NLS-1$ // not for explicit configuration, set from project nature - - // multi value options + + // === multi value options ===: + + public static final String OPTION_WeavingScheme = + "org.eclipse.objectteams.otdt.compiler.option.weaving_scheme"; //$NON-NLS-1$ + /** Supported weaving schemes. */ + public static enum WeavingScheme { + /** Code generation for the traditional "Object Teams Runtime Environment" implementation based on BCEL. */ + OTRE, + /** Code generation for the newer "Object Teams Dynamic Runtime Environment" implementation based on ASM. */ + OTDRE + } + + public static final String OPTION_Decapsulation = "org.eclipse.objectteams.otdt.core.compiler.problem.decapsulation"; //$NON-NLS-1$ // values for the above: public static final String REPORT_CLASS = "report class"; //$NON-NLS-1$ @@ -533,6 +545,8 @@ public class CompilerOptions { public boolean allowScopedKeywords = true; // even stronger: forcing the scanner to pure Java? public boolean isPureJava = false; + // which scheme should be used for code generation (esp. callin bindings)? + public WeavingScheme weavingScheme = WeavingScheme.OTRE; // SH} // === Support for Null Annotations: === @@ -1330,9 +1344,6 @@ public class CompilerOptions { } -//{ObjectTeams: be nice: - @SuppressWarnings("unchecked") -// SH} public Map getMap() { Map optionsMap = new HashMap(30); optionsMap.put(OPTION_LocalVariableAttribute, (this.produceDebugAttributes & ClassFileConstants.ATTR_VARS) != 0 ? GENERATE : DO_NOT_GENERATE); @@ -1483,6 +1494,7 @@ public class CompilerOptions { optionsMap.put(OPTION_AllowScopedKeywords, this.allowScopedKeywords? ENABLED : DISABLED); optionsMap.put(OPTION_PureJavaOnly, this.isPureJava ? ENABLED : DISABLED); + optionsMap.put(OPTION_WeavingScheme, this.weavingScheme.toString()); // SH} optionsMap.put(OPTION_AnnotationBasedNullAnalysis, this.isAnnotationBasedNullAnalysisEnabled ? ENABLED : DISABLED); optionsMap.put(OPTION_ReportNullSpecViolation, getSeverityString(NullSpecViolation)); @@ -2025,6 +2037,9 @@ public class CompilerOptions { if ((optionValue = optionsMap.get(OPTION_Decapsulation)) != null) { this.decapsulation = (String)optionValue; } + if ((optionValue = optionsMap.get(OPTION_WeavingScheme)) != null) { + this.weavingScheme = WeavingScheme.valueOf((String)optionValue); + } // SH} if ((optionValue = optionsMap.get(OPTION_AnnotationBasedNullAnalysis)) != null) { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java index 7b51f108f..903c634e1 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/LookupEnvironment.java @@ -165,7 +165,7 @@ public class LookupEnvironment implements ProblemReasons, TypeConstants { private TeamMethodGenerator teamMethodGenerator; public TeamMethodGenerator getTeamMethodGenerator() { if (this.teamMethodGenerator == null) - this.teamMethodGenerator = new TeamMethodGenerator(); + this.teamMethodGenerator = new TeamMethodGenerator(this.globalOptions.weavingScheme); return this.teamMethodGenerator; } // SH} diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java index a47f86027..a571f004f 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodBinding.java @@ -39,6 +39,7 @@ import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.ConstantPool; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.util.Util; import org.eclipse.objectteams.otdt.core.compiler.IOTConstants; import org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.AnchorListAttribute; @@ -790,9 +791,9 @@ protected TypeBinding generalizedReturnType = null; // only set if return and pa public TypeBinding[] getSourceParameters() { TypeBinding[] allParameters = this.parameters; if ((this.switchCount == 0) && isCallin()) { - int numGeneratedArgs = MethodSignatureEnhancer.ENHANCING_ARG_LEN; + int numGeneratedArgs = getMethodSignatureEnhancer().ENHANCING_ARG_LEN; TypeBinding[] sourceParameters = new TypeBinding[allParameters.length - numGeneratedArgs]; - System.arraycopy(allParameters, MethodSignatureEnhancer.ENHANCING_ARG_LEN, + System.arraycopy(allParameters, numGeneratedArgs, sourceParameters, 0, sourceParameters.length); return sourceParameters; } else { @@ -802,10 +803,21 @@ public TypeBinding[] getSourceParameters() { /** How many source-level parameters does this method have? */ public int getSourceParamLength() { if ((this.switchCount == 0) && isCallin()) - return this.parameters.length - MethodSignatureEnhancer.ENHANCING_ARG_LEN; + return this.parameters.length - getMethodSignatureEnhancer().ENHANCING_ARG_LEN; return this.parameters.length; } +public MethodSignatureEnhancer getMethodSignatureEnhancer() { + WeavingScheme weavingScheme = WeavingScheme.OTRE; + if (this.declaringClass instanceof BinaryTypeBinding) + weavingScheme = ((BinaryTypeBinding)this.declaringClass).environment.globalOptions.weavingScheme; + else if (this.declaringClass instanceof SourceTypeBinding) { + Scope scope = ((SourceTypeBinding)this.declaringClass).scope; + if (scope != null) + weavingScheme = scope.compilerOptions().weavingScheme; + } + return MethodSignatureEnhancer.variants[weavingScheme.ordinal()]; +} /** * Temporarily set the source parameters as this method's parameters. * The same for the return type. @@ -1361,7 +1373,7 @@ public char[] readableName() /* foo(int, Thread) */ { buffer.insert(0, "tsuper."); //$NON-NLS-1$ } if (isCallin()) - firstParam = MethodSignatureEnhancer.ENHANCING_ARG_LEN; + firstParam = getMethodSignatureEnhancer().ENHANCING_ARG_LEN; /* orig: for (int i = 0, length = this.parameters.length; i < length; i++) { if (i > 0) @@ -1427,7 +1439,7 @@ public char[] shortReadableName() { buffer.insert(0, "tsuper."); //$NON-NLS-1$ } if (isCallin()) - firstParam = MethodSignatureEnhancer.ENHANCING_ARG_LEN; + firstParam = getMethodSignatureEnhancer().ENHANCING_ARG_LEN; /* orig: for (int i = 0, length = this.parameters.length; i < length; i++) { if (i > 0) diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java index e5d174e6b..d942a7f5f 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/MethodScope.java @@ -38,7 +38,6 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.ast.CallinMappingDecl import org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.WordValueAttribute; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.CallinCalloutScope; import org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel; -import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.MethodSignatureEnhancer; /** * OTDT changes: @@ -330,8 +329,7 @@ private void checkAndSetModifiersForMethod(final MethodBinding methodBinding) { // only allowed in direct role: if (!methodBinding.declaringClass.isDirectRole()) { problemReporter().callinInNonRole(methodBinding.declaringClass, referenceMethod); - // revert callin specifica: - referenceMethod.arguments = MethodSignatureEnhancer.maybeRetrenchArguments(referenceMethod); + // remove callin flag (note that method arguments will not be enhanced (during STB.resolveTypesFor())): referenceMethod.modifiers &= ~ExtraCompilerModifiers.AccCallin; modifiers &= ~ExtraCompilerModifiers.AccCallin; } else { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java index e2ca88a99..e1568d34c 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/lookup/SourceTypeBinding.java @@ -88,6 +88,7 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transfor import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.PredicateGenerator; import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.RoleMigrationImplementor; import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.RoleSplitter; +import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator; import org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator; import org.eclipse.objectteams.otdt.internal.core.compiler.util.TypeAnalyzer; @@ -2396,7 +2397,14 @@ public MethodBinding resolveTypesFor(MethodBinding method, boolean fromSynthetic AbstractMethodDeclaration methodDecl = method.sourceMethod(); if (methodDecl == null) return null; // method could not be resolved in previous iteration -//{ObjectTeams: pre-fetch (resolve) potential type anchors: +//{ObjectTeams: enhance callin signature (previously done in the parser): + if (methodDecl.isCallin() && !methodDecl.isCopied) { + AstGenerator gen = new AstGenerator(methodDecl.sourceEnd+1, methodDecl.sourceEnd+2); + methodDecl.arguments = MethodSignatureEnhancer.enhanceArguments( + methodDecl.arguments, new char[0], /*isWrapper*/false, gen, this.scope.compilerOptions().weavingScheme); + } + + // pre-fetch (resolve) potential type anchors: boolean[] anchorFlags = null; // keep track so we don't doubly resolve if (methodDecl.arguments != null) { anchorFlags = TypeAnchorReference.fetchAnchorFlags(methodDecl.arguments, methodDecl.typeParameters()); @@ -3512,7 +3520,7 @@ void verifyMethods(MethodVerifier verifier) { // (requires inherited callin bindings (from STATE_LATE_ATTRIBUTES_EVALUATED), but must happend // before resolve() so resolving BaseCallMessageSends will find inherited surrogates) if (this.isDirectRole() && !this.isInterface()) - SyntheticBaseCallSurrogate.addFakedBaseCallSurrogates(this); + SyntheticBaseCallSurrogate.addFakedBaseCallSurrogates(this, verifier.environment); // SH} } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java index 08df05019..938b40d6d 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/Parser.java @@ -71,7 +71,6 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel; import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.MethodSignatureEnhancer; import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstClone; import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstEdit; -import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator; import org.eclipse.objectteams.otdt.internal.core.compiler.util.TypeAnalyzer; /** @@ -6198,13 +6197,6 @@ protected void consumeMethodHeaderRightParen() { } } } -//{ObjectTeams: enhance callin method: - if (md.isCallin()) { - AstGenerator gen = new AstGenerator(md.sourceEnd+1, md.sourceEnd+2); - md.arguments = MethodSignatureEnhancer.enhanceArguments( - md.arguments, new char[0], /*isWrapper*/false, gen); - } -// SH} md.bodyStart = this.rParenPos+1; this.listLength = 0; // reset this.listLength after having read all parameters // recovery @@ -7102,7 +7094,7 @@ private void consumePredicate(boolean isBase) { arguments = new Argument[] {targetArg}; else arguments = makePredicateArguments( - null, MethodSignatureEnhancer.maybeRetrenchArguments(methodDecl), null, poss); + null, MethodSignatureEnhancer.maybeRetrenchArguments(methodDecl, this.options.weavingScheme), null, poss); } else if (this.astStack[this.astPtr] instanceof MethodSpec) { bmSpec = (MethodSpec)this.astStack[this.astPtr]; mappingDecl = (CallinMappingDeclaration)this.astStack[this.astPtr-this.astLengthStack[this.astLengthPtr]]; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java index 2a49a6b82..4e5d8a4c3 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/parser/RecoveredMethod.java @@ -38,8 +38,6 @@ import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; import org.eclipse.jdt.internal.compiler.util.Util; -import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.MethodSignatureEnhancer; -import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator; /** * Internal method structure for parsing recovery @@ -411,12 +409,6 @@ public AbstractMethodDeclaration updatedMethodDeclaration(int depth, Set knownTy } } } -//{ObjectTeams: ensure signature has taken place apropriately: - if (this.methodDeclaration.isCallin() && !MethodSignatureEnhancer.isEnhanced(this.methodDeclaration)) { - AstGenerator gen = new AstGenerator(this.methodDeclaration.sourceStart, this.methodDeclaration.sourceEnd); - this.methodDeclaration.arguments = MethodSignatureEnhancer.enhanceArguments(this.methodDeclaration.arguments, new char[0], /*isWrapper*/false, gen); - } -// SH} if (this.localTypeCount > 0) this.methodDeclaration.bits |= ASTNode.HasLocalType; return this.methodDeclaration; } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java index d951b1153..0917dfee1 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/problem/ProblemReporter.java @@ -8603,7 +8603,7 @@ private String typesAsString(MethodBinding methodBinding, TypeBinding[] paramete } } //{ObjectTeams: heuristically beautify: - MethodSignatureEnhancer.beautifyTypesString(buffer, makeShort); + MethodSignatureEnhancer.beautifyTypesString(buffer, makeShort, this.options.weavingScheme); // SH} return buffer.toString(); } @@ -8623,7 +8623,7 @@ private String typesAsString(TypeBinding[] types, boolean makeShort, boolean sho buffer.append(new String(makeShort ? type.shortReadableName() : type.readableName())); } //{ObjectTeams: heuristically beautify: - MethodSignatureEnhancer.beautifyTypesString(buffer, makeShort); + MethodSignatureEnhancer.beautifyTypesString(buffer, makeShort, this.options.weavingScheme); // SH} return buffer.toString(); } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/core/compiler/CompilerVersion.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/core/compiler/CompilerVersion.java index babd2226f..1120670ab 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/core/compiler/CompilerVersion.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/core/compiler/CompilerVersion.java @@ -1,7 +1,7 @@ /********************************************************************** * This file is part of the "Object Teams Development Tooling"-Software. * - * Copyright 2012 GK Software AG + * Copyright 2012, 2014 GK Software AG * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 @@ -15,16 +15,9 @@ **********************************************************************/ package org.eclipse.objectteams.otdt.core.compiler; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; - /** * @since 3.9 (OTDT 2.2) */ public class CompilerVersion { - /** - * Define whether the compiler should generate byte code suitable for dynamic weaving. - */ - public static void setDynamicWeaving(boolean useDynamicWeaving) { - CallinImplementorDyn.DYNAMIC_WEAVING = useDynamicWeaving; - } + // FIXME: can this class go? } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/BaseCallMessageSend.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/BaseCallMessageSend.java index 99260771a..87a9c0247 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/BaseCallMessageSend.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/BaseCallMessageSend.java @@ -30,6 +30,7 @@ import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; import org.eclipse.jdt.internal.compiler.flow.FlowContext; import org.eclipse.jdt.internal.compiler.flow.FlowInfo; import org.eclipse.jdt.internal.compiler.impl.Constant; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; @@ -84,6 +85,7 @@ public class BaseCallMessageSend extends AbstractExpressionWrapper protected MessageSend _sendOrig; BaseReference _receiver; // avoid casts like (BaseReference)wrappee.receiver public boolean isSuperAccess; // flag for base.super.m() calls + private WeavingScheme _weavingScheme = WeavingScheme.OTRE; // avoid null public BaseCallMessageSend(MessageSend wrappee, int baseEndPos) { @@ -99,6 +101,8 @@ public class BaseCallMessageSend extends AbstractExpressionWrapper this.isSuperAccess = isSuperAccess; if (isSuperAccess) problemReporter.baseSuperCallDecapsulation(this); + } + public void prepareSuperAccess(WeavingScheme weavingScheme) { // add a further boolean argument to pass this flag to the runtime. // insert it at front of regular arguments to it will end up between normal enhancement args and regular args. // (note that this arg may be removed again if current callin method is static, @@ -106,7 +110,7 @@ public class BaseCallMessageSend extends AbstractExpressionWrapper Expression[] args = this._sendOrig.arguments; this.sourceArgs = args; int len = 0; - int extra = CallinImplementorDyn.DYNAMIC_WEAVING ? 0 : 1; + int extra = weavingScheme == WeavingScheme.OTRE ? 1 : 0; if (args == null) { args = new Expression[extra]; } else { @@ -114,10 +118,11 @@ public class BaseCallMessageSend extends AbstractExpressionWrapper System.arraycopy(args, 0, args=new Expression[len+extra], extra, len); } // insert before regular args: - if (!CallinImplementorDyn.DYNAMIC_WEAVING) { // FIXME(OTDYN): base.super calls not supported by dynamic weaver. + if (weavingScheme == WeavingScheme.OTRE) { // FIXME(OTDYN): base.super calls not supported by dynamic weaver. args[0] = new AstGenerator(this).booleanLiteral(this.isSuperAccess); } this._sendOrig.arguments = args; + this._weavingScheme = weavingScheme; } public FlowInfo analyseCode(BlockScope currentScope, FlowContext flowContext, FlowInfo flowInfo) @@ -192,6 +197,7 @@ public class BaseCallMessageSend extends AbstractExpressionWrapper public TypeBinding resolveType(BlockScope scope) { + WeavingScheme weavingScheme = scope.compilerOptions().weavingScheme; AstGenerator gen = new AstGenerator(this._wrappee.sourceStart, this._wrappee.sourceEnd); MessageSend wrappedSend = this._sendOrig; AbstractMethodDeclaration referenceMethod = scope.methodScope().referenceMethod(); @@ -204,7 +210,7 @@ public class BaseCallMessageSend extends AbstractExpressionWrapper if (outerCallinMethod != null && outerCallinMethod.binding == null) return null; // no hope ReferenceBinding roleType = scope.enclosingSourceType(); - this._receiver.adjustReceiver(roleType, isStatic, outerCallinMethod, gen); + this._receiver.adjustReceiver(roleType, isStatic, outerCallinMethod, gen, weavingScheme); // empty base call surrogate is handled using a synthetic base call surrogate: boolean isCallinBound = false; @@ -213,16 +219,17 @@ public class BaseCallMessageSend extends AbstractExpressionWrapper } else { isCallinBound = roleType.roleModel.isBound(); } + // who should work, compiler or OTRE? - if (!isCallinBound && !CallinImplementorDyn.DYNAMIC_WEAVING) { - resolveSyntheticBaseCallSurrogate(outerCallinMethod, scope); + if (!isCallinBound && weavingScheme == WeavingScheme.OTRE) { + resolveSyntheticBaseCallSurrogate(outerCallinMethod, scope, weavingScheme); return this.resolvedType; } // selector: - if (CallinImplementorDyn.DYNAMIC_WEAVING) { + if (weavingScheme == WeavingScheme.OTDRE) { wrappedSend.selector = CallinImplementorDyn.OT_CALL_NEXT; } else { wrappedSend.selector = SyntheticBaseCallSurrogate.genSurrogateName(wrappedSend.selector, roleType.sourceName(), isStatic); @@ -257,7 +264,7 @@ public class BaseCallMessageSend extends AbstractExpressionWrapper BlockScopeWrapper baseCallScope = new BlockScopeWrapper(scope, this); super.resolveType(baseCallScope); - if (CallinImplementorDyn.DYNAMIC_WEAVING) { + if (weavingScheme == WeavingScheme.OTDRE) { // convert Object result from callNext if (returnType != null && !returnType.isBaseType()) { this.resolvedType = returnType; @@ -267,7 +274,7 @@ public class BaseCallMessageSend extends AbstractExpressionWrapper return this.resolvedType; } /* manual resolve for an empty base call surrogate, which is indeed generated by the compiler, not the OTRE. */ - private void resolveSyntheticBaseCallSurrogate(MethodDeclaration outerCallinMethod, BlockScope scope) + private void resolveSyntheticBaseCallSurrogate(MethodDeclaration outerCallinMethod, BlockScope scope, WeavingScheme weavingScheme) { // find the method: AbstractMethodDeclaration callinMethodDecl = outerCallinMethod; @@ -323,7 +330,7 @@ public class BaseCallMessageSend extends AbstractExpressionWrapper } if (!srcArgType.isCompatibleWith(methodParams[i])) { if (isBoxingCompatible(srcArgType, methodParams[i], this.sourceArgs[i], scope)) { - int enhancedArgIdx = i+MethodSignatureEnhancer.ENHANCING_ARG_LEN+1; // normal enhancement plus isSuperAccess flag + int enhancedArgIdx = i+MethodSignatureEnhancer.getEnhancingArgLen(weavingScheme)+1; // normal enhancement plus isSuperAccess flag this._sendOrig.arguments[enhancedArgIdx].computeConversion(scope, methodParams[i], srcArgType); } else { scope.problemReporter().baseCallDoesntMatchRoleMethodSignature(this); @@ -415,7 +422,7 @@ public class BaseCallMessageSend extends AbstractExpressionWrapper this._sendOrig.selector = this.sourceSelector; argsSave = this._sendOrig.arguments; boolean isEnhanced = (this._sendOrig.bits & ASTNode.HasBeenTransformed) != 0; - this._sendOrig.arguments = MethodSignatureEnhancer.retrenchBasecallArguments(argsSave, isEnhanced); + this._sendOrig.arguments = MethodSignatureEnhancer.retrenchBasecallArguments(argsSave, isEnhanced, this._weavingScheme); return this._sendOrig.printExpression(indent, output); } } finally { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/BaseReference.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/BaseReference.java index f0f85c198..bdefd056c 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/BaseReference.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/BaseReference.java @@ -26,12 +26,12 @@ import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.QualifiedThisReference; import org.eclipse.jdt.internal.compiler.ast.ThisReference; import org.eclipse.jdt.internal.compiler.codegen.CodeStream; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.impl.Constant; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator; import org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator; @@ -58,15 +58,17 @@ public class BaseReference extends ThisReference { * @param isStatic * @param outerCallinMethod * @param gen + * @param weavingScheme which weaver to compile for * @return the exact role class containing this base call (respecting local types). */ ReferenceBinding adjustReceiver( ReferenceBinding enclosingType, boolean isStatic, MethodDeclaration outerCallinMethod, - AstGenerator gen) + AstGenerator gen, + WeavingScheme weavingScheme) { - boolean redirectToTeam = isStatic || CallinImplementorDyn.DYNAMIC_WEAVING; // _OT$callNext is found via MyTeam.this + boolean redirectToTeam = isStatic || (weavingScheme == WeavingScheme.OTDRE); // _OT$callNext is found via MyTeam.this if (outerCallinMethod != null) { // use "R.this" in order to point to the correct class, direct enclosing is a local class. ReferenceBinding enclosingRole = outerCallinMethod.binding.declaringClass; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/FieldAccessSpec.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/FieldAccessSpec.java index e507f7e84..7a9468776 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/FieldAccessSpec.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/FieldAccessSpec.java @@ -25,6 +25,7 @@ import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ast.Argument; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; @@ -40,7 +41,6 @@ import org.eclipse.objectteams.otdt.core.compiler.IOTConstants; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.CallinCalloutScope; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.ITeamAnchor; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.model.FieldModel; import org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel; import org.eclipse.objectteams.otdt.internal.core.compiler.model.TeamModel; @@ -162,7 +162,7 @@ public class FieldAccessSpec extends MethodSpec { return null; } - this.implementationStrategy = CallinImplementorDyn.DYNAMIC_WEAVING + this.implementationStrategy = scope.compilerOptions().weavingScheme == WeavingScheme.OTDRE ? ImplementationStrategy.DYN_ACCESS : ImplementationStrategy.DECAPS_WRAPPER; // find accessor method which might have been generated already. diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/MethodSpec.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/MethodSpec.java index cb8cbb531..f2e0830d4 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/MethodSpec.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/ast/MethodSpec.java @@ -38,6 +38,7 @@ import org.eclipse.jdt.internal.compiler.ast.TypeParameter; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.ast.Expression.DecapsulationState; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; @@ -59,7 +60,6 @@ import org.eclipse.objectteams.otdt.core.compiler.IOTConstants; import org.eclipse.objectteams.otdt.core.exceptions.InternalCompilerError; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.AnchorMapping; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.CallinCalloutScope; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel; import org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel; import org.eclipse.objectteams.otdt.internal.core.compiler.model.TeamModel; @@ -502,7 +502,8 @@ public class MethodSpec extends ASTNode implements InvocationSite void checkDecapsulation(ReferenceBinding baseClass, Scope scope) { if (!this.resolvedMethod.canBeSeenBy(baseClass, this, scope)) { - this.implementationStrategy = CallinImplementorDyn.DYNAMIC_WEAVING + WeavingScheme weavingScheme = scope.compilerOptions().weavingScheme; + this.implementationStrategy = weavingScheme == WeavingScheme.OTDRE ? ImplementationStrategy.DYN_ACCESS : ImplementationStrategy.DECAPS_WRAPPER; this.accessId = createAccessAttribute(scope.enclosingSourceType().roleModel); scope.problemReporter().decapsulation(this, baseClass, scope); @@ -656,8 +657,8 @@ public class MethodSpec extends ASTNode implements InvocationSite return this.selector; } /** Like MethodBinding.signature() but use getSourceParamters() instead of enhanced parameters. */ - public char[] signature() { - return signature(this.resolvedMethod); + public char[] signature(WeavingScheme weavingScheme) { + return signature(this.resolvedMethod, weavingScheme); } /** * This method is used by @@ -666,19 +667,19 @@ public class MethodSpec extends ASTNode implements InvocationSite * @param method * @return the bytecode level signature of the given method (yet retrenched) */ - public static char[] signature(MethodBinding method) { + public static char[] signature(MethodBinding method, WeavingScheme weavingScheme) { StringBuffer buffer = new StringBuffer(); buffer.append('('); // synthetic args for static role method? MethodBinding orig = method.copyInheritanceSrc != null ? method.copyInheritanceSrc : method; // normalize to copyInhSrc so reading a callin-attr. from bytes can more easily find the method - if (CallinImplementorDyn.DYNAMIC_WEAVING && orig.declaringClass.isRole() && orig.isStatic()) { + if (weavingScheme == WeavingScheme.OTDRE && orig.declaringClass.isRole() && orig.isStatic()) { buffer.append('I'); buffer.append(String.valueOf(orig.declaringClass.enclosingType().signature())); } // manual retrenching? - boolean shouldRetrench = !CallinImplementorDyn.DYNAMIC_WEAVING && method.isCallin(); - int offset = shouldRetrench ? MethodSignatureEnhancer.ENHANCING_ARG_LEN : 0; + boolean shouldRetrench = weavingScheme == WeavingScheme.OTRE && method.isCallin(); + int offset = shouldRetrench ? MethodSignatureEnhancer.getEnhancingArgLen(weavingScheme) : 0; int paramLen = method.parameters.length; for (int i = offset; i < paramLen; i++) { // 'weaken' to that erasure that was used in the tsuper version: diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/CallinMethodMappingsAttribute.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/CallinMethodMappingsAttribute.java index fdfd9bf5b..29b666d4b 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/CallinMethodMappingsAttribute.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/CallinMethodMappingsAttribute.java @@ -28,6 +28,7 @@ import org.eclipse.jdt.internal.compiler.ClassFile; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileStruct; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; @@ -293,7 +294,7 @@ public class CallinMethodMappingsAttribute extends AbstractAttribute { this._mappings[idx++] = new Mapping( decl.name, decl.roleMethodSpec.selector, - decl.roleMethodSpec.signature(), + decl.roleMethodSpec.signature(WeavingScheme.OTRE), flags, decl.liftMethod != null ? decl.liftMethod.selector : new char[0], @@ -531,7 +532,7 @@ public class CallinMethodMappingsAttribute extends AbstractAttribute { while (currentType2 != null) { MethodBinding[] methods = currentType2.getMethods(mapping._roleSelector); for (int j = 0; j < methods.length; j++) { - if (CharOperation.prefixEquals(roleSignature, MethodSpec.signature(methods[j]))) + if (CharOperation.prefixEquals(roleSignature, MethodSpec.signature(methods[j], WeavingScheme.OTRE))) { result._roleMethodBinding = methods[j]; break roleMethod; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/OTDynCallinBindingsAttribute.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/OTDynCallinBindingsAttribute.java index d3b701891..74d56e3f7 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/OTDynCallinBindingsAttribute.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/OTDynCallinBindingsAttribute.java @@ -21,6 +21,7 @@ import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileStruct; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; @@ -234,7 +235,7 @@ public class OTDynCallinBindingsAttribute extends ListValueAttribute { MethodSpec roleSpec = callinDecl.roleMethodSpec; MethodSpec[] baseMethodSpecs = callinDecl.getBaseMethodSpecs(); Mapping mapping = new Mapping(callinDecl.scope.enclosingSourceType().sourceName(), // indeed: simple name - callinDecl.declaringRoleName(), callinDecl.name, roleSpec.selector, roleSpec.signature(), + callinDecl.declaringRoleName(), callinDecl.name, roleSpec.selector, roleSpec.signature(WeavingScheme.OTDRE), callinDecl.getCallinModifier(), flags, baseClassName, baseMethodSpecs.length); for (int i=0; i<baseMethodSpecs.length; i++) { @@ -244,7 +245,9 @@ public class OTDynCallinBindingsAttribute extends ListValueAttribute { baseFlags |= BaseMethod.CALLIN; if (baseSpec.isStatic()) baseFlags |= BaseMethod.STATIC; - mapping.addBaseMethod(i, baseSpec.codegenSeletor(), baseSpec.signature(), baseSpec.resolvedMethod.declaringClass.constantPoolName(), baseSpec.getCallinId(this.theTeam), baseFlags, baseSpec.getTranslationFlags()); + mapping.addBaseMethod(i, baseSpec.codegenSeletor(), baseSpec.signature(WeavingScheme.OTDRE), + baseSpec.resolvedMethod.declaringClass.constantPoolName(), + baseSpec.getCallinId(this.theTeam), baseFlags, baseSpec.getTranslationFlags()); } mapping.setSMAPinfo(callinDecl); this.mappings.add(mapping); @@ -407,7 +410,7 @@ public class OTDynCallinBindingsAttribute extends ListValueAttribute { while (currentType != null) { MethodBinding[] methods = currentType.getMethods(mapping.roleSelector); for (int j = 0; j < methods.length; j++) { - if (CharOperation.prefixEquals(roleSignature, MethodSpec.signature(methods[j]))) + if (CharOperation.prefixEquals(roleSignature, MethodSpec.signature(methods[j], WeavingScheme.OTDRE))) { result._roleMethodBinding = methods[j]; break roleMethod; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/OTSpecialAccessAttribute.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/OTSpecialAccessAttribute.java index 916f876c5..dce15593f 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/OTSpecialAccessAttribute.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/OTSpecialAccessAttribute.java @@ -25,6 +25,7 @@ import java.util.List; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.ClassFile; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileStruct; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; @@ -34,7 +35,6 @@ import org.eclipse.jdt.internal.compiler.parser.TerminalTokens; import org.eclipse.objectteams.otdt.core.compiler.IOTConstants; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.WeakenedTypeBinding; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel; import org.eclipse.objectteams.otdt.internal.core.compiler.model.TeamModel; import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.copyinheritance.CopyInheritance; @@ -59,8 +59,6 @@ public class OTSpecialAccessAttribute extends AbstractAttribute { private static final int DYN_DECAPSULATION_METHOD_ACCESS= 4; private static final int DYN_CALLOUT_FIELD_ACCESS = 5; private static final int DYN_SUPER_METHOD_ACCESS = 6; - private static final int M_SIZE = CallinImplementorDyn.DYNAMIC_WEAVING ? 8 : 6; - private static final int F_SIZE = CallinImplementorDyn.DYNAMIC_WEAVING ? 9 : 7; /* * For OTREDyn, each attribute of this type maintains a set of locally unique (per team) access IDs. @@ -91,7 +89,7 @@ public class OTSpecialAccessAttribute extends AbstractAttribute { if (CopyInheritance.isCreator(method)) // creator is declared in the enclosing team this.boundBaseclass = this.boundBaseclass.enclosingType(); - if (CallinImplementorDyn.DYNAMIC_WEAVING) { + if (OTSpecialAccessAttribute.this._weavingScheme == WeavingScheme.OTDRE) { for (DecapsulatedMethodDesc methodDesc : OTSpecialAccessAttribute.this._decapsulatedMethods) { if (methodDesc.method == method) { this.accessId = methodDesc.accessId; // share the accessId from another callout to the same method @@ -103,7 +101,7 @@ public class OTSpecialAccessAttribute extends AbstractAttribute { } void write() { - if (CallinImplementorDyn.DYNAMIC_WEAVING) + if (OTSpecialAccessAttribute.this._weavingScheme == WeavingScheme.OTDRE) writeByte((byte)DYN_DECAPSULATION_METHOD_ACCESS); else writeByte((byte)DECAPSULATION_METHOD_ACCESS); @@ -123,7 +121,7 @@ public class OTSpecialAccessAttribute extends AbstractAttribute { writeName(encodedName); writeName(this.method.signature()); } - if (CallinImplementorDyn.DYNAMIC_WEAVING) + if (OTSpecialAccessAttribute.this._weavingScheme == WeavingScheme.OTDRE) writeUnsignedShort(this.accessId); } @@ -152,7 +150,7 @@ public class OTSpecialAccessAttribute extends AbstractAttribute { CALLOUT_GET_FIELD : CALLOUT_SET_FIELD; if (field.isStatic()) this.flags |= CALLOUT_STATIC_FIELD; - if (CallinImplementorDyn.DYNAMIC_WEAVING) { + if (OTSpecialAccessAttribute.this._weavingScheme == WeavingScheme.OTDRE) { for (CalloutToFieldDesc ctf : OTSpecialAccessAttribute.this._calloutToFields) { if (ctf.field == field) { this.accessId = ctf.accessId; // share the accessId from another callout to the same field @@ -170,7 +168,7 @@ public class OTSpecialAccessAttribute extends AbstractAttribute { } void write() { - if (CallinImplementorDyn.DYNAMIC_WEAVING) { + if (OTSpecialAccessAttribute.this._weavingScheme == WeavingScheme.OTDRE) { writeByte((byte)DYN_CALLOUT_FIELD_ACCESS); writeUnsignedShort(this.accessId); } else { @@ -206,7 +204,7 @@ public class OTSpecialAccessAttribute extends AbstractAttribute { } void write() { - writeByte((byte)(CallinImplementorDyn.DYNAMIC_WEAVING ? DYN_SUPER_METHOD_ACCESS : SUPER_METHOD_ACCESS)); + writeByte((byte)(OTSpecialAccessAttribute.this._weavingScheme == WeavingScheme.OTDRE ? DYN_SUPER_METHOD_ACCESS : SUPER_METHOD_ACCESS)); writeName(this.method.declaringClass.attributeName()); writeName(this.method.declaringClass.superclass().attributeName()); writeName(this.method.selector); @@ -232,10 +230,12 @@ public class OTSpecialAccessAttribute extends AbstractAttribute { * FALSE means: use in a team referring to a super base class, which is indirectly adapted.*/ private List<Boolean> _baseclassDecapsulation = new ArrayList<Boolean>(); + WeavingScheme _weavingScheme; - public OTSpecialAccessAttribute (ReferenceBinding site) { + public OTSpecialAccessAttribute (ReferenceBinding site, WeavingScheme weavingScheme) { super(IOTConstants.OTSPECIAL_ACCESS); this._site = site; + this._weavingScheme = weavingScheme; } public int addDecapsulatedMethodAccess(ReferenceBinding boundBaseclass, MethodBinding method) { @@ -279,6 +279,8 @@ public class OTSpecialAccessAttribute extends AbstractAttribute { super.write(classFile); int attributeSize = 4; // initially empty, except for two counts + int M_SIZE = this._weavingScheme == WeavingScheme.OTDRE ? 8 : 6; + int F_SIZE = this._weavingScheme == WeavingScheme.OTDRE ? 9 : 7; attributeSize += this._decapsulatedMethods.size() * (1+M_SIZE); // 1 byte kind, 3 names (+1 short for otredyn) attributeSize += this._calloutToFields.size() * (1+F_SIZE); // 1 byte kind, 1 byte flags, 3 names (+1 byte for otredyn) attributeSize += this._superMethods.size() * 9; // 1 byte kind, 4 names diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/StaticReplaceBindingsAttribute.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/StaticReplaceBindingsAttribute.java index b6dd79be6..f79eca446 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/StaticReplaceBindingsAttribute.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/bytecode/StaticReplaceBindingsAttribute.java @@ -22,6 +22,7 @@ package org.eclipse.objectteams.otdt.internal.core.compiler.bytecode; import org.eclipse.jdt.internal.compiler.ClassFile; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileStruct; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; @@ -198,7 +199,7 @@ public class StaticReplaceBindingsAttribute extends AbstractAttribute { Mapping currentMapping = new Mapping( decl.roleMethodSpec.resolvedMethod.declaringClass.sourceName(), decl.roleMethodSpec.selector, - decl.roleMethodSpec.signature(), + decl.roleMethodSpec.signature(WeavingScheme.OTRE), decl.liftMethod != null ? decl.liftMethod.selector : new char[0], decl.liftMethod != null ? diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java index c91bdb844..d179c2542 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/control/Dependencies.java @@ -31,6 +31,7 @@ import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.env.AccessRestriction; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.ClassScope; @@ -1462,7 +1463,7 @@ public class Dependencies implements ITranslationStates { if ( teamDeclaration != null && teamDeclaration.memberTypes != null) { - model.liftingEnv.createLiftingInfrastructure(null, needMethodBodies(teamDeclaration)); + model.liftingEnv.createLiftingInfrastructure(null, needMethodBodies(teamDeclaration), model.getWeavingScheme()); model.setState(STATE_FULL_LIFTING); // shallow traversal only: for (RoleModel roleModel : model.getRoles(true)) @@ -1470,7 +1471,7 @@ public class Dependencies implements ITranslationStates { } else { // nothing to do for binary types and role-less teams. if (teamDeclaration != null && ReflectionGenerator.needToImplementITeamMethods(teamDeclaration)) - ReflectionGenerator.createRoleQueryMethods(teamDeclaration); // need to implement methods from ITeam + ReflectionGenerator.createRoleQueryMethods(teamDeclaration, model.getWeavingScheme()); // need to implement methods from ITeam model.setState(STATE_FULL_LIFTING); model.setMemberState(STATE_FULL_LIFTING); } @@ -1487,7 +1488,7 @@ public class Dependencies implements ITranslationStates { return true; } TeamModel teamModel = model.getTeamModel(); - teamModel.liftingEnv.createLiftingInfrastructure(model, needMethodBodies(roleDecl)); + teamModel.liftingEnv.createLiftingInfrastructure(model, needMethodBodies(roleDecl), model.getWeavingScheme()); model.setState(STATE_FULL_LIFTING); return success; } @@ -1939,7 +1940,7 @@ public class Dependencies implements ITranslationStates { TypeDeclaration type = clazz.getAst(); if (type != null) { if (needMethodBodies(type)) { - TransformStatementsVisitor transformer = new TransformStatementsVisitor(); + TransformStatementsVisitor transformer = new TransformStatementsVisitor(clazz.getWeavingScheme()); if ((type.bits & ASTNode.IsLocalType) != 0) { MethodScope methodScope = type.scope.methodScope(); if (methodScope != null) @@ -1977,7 +1978,7 @@ public class Dependencies implements ITranslationStates { { CopyInheritance.copyAttribute(aTeam); //{OTDyn: - if (CallinImplementorDyn.DYNAMIC_WEAVING) { + if (aTeam.getWeavingScheme() == WeavingScheme.OTDRE) { CallinImplementorDyn callinImplementor = new CallinImplementorDyn(); callinImplementor.transformTeam(aTeam); } @@ -2006,14 +2007,15 @@ public class Dependencies implements ITranslationStates { if (!roleDecl.binding.isSynthInterface()) { // synth interfaces have no callins anyway ;-) if (needMethodBodies) { // not translating callin bindings will cause no secondary errors -> skip if no body needed -//{OTDyn: - if (CallinImplementorDyn.DYNAMIC_WEAVING) { - CallinImplementorDyn callinImplementor = new CallinImplementorDyn(); - callinImplementor.transformRole(role); - } else { -// SH} + switch (roleDecl.scope.compilerOptions().weavingScheme) { + case OTDRE: + CallinImplementorDyn callinImplementorDyn = new CallinImplementorDyn(); + callinImplementorDyn.transformRole(role); + break; + case OTRE: CallinImplementor callinImplementor = new CallinImplementor(role); success &= callinImplementor.transform(); + break; } } } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lifting/Lifting.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lifting/Lifting.java index c0120c854..9d53bd7f7 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lifting/Lifting.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lifting/Lifting.java @@ -27,6 +27,7 @@ import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.BranchLabel; import org.eclipse.jdt.internal.compiler.codegen.CodeStream; import org.eclipse.jdt.internal.compiler.codegen.Opcodes; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.impl.Constant; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; @@ -47,7 +48,6 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.control.ITranslationS import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.ITeamAnchor; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.WeakenedTypeBinding; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel; import org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel; import org.eclipse.objectteams.otdt.internal.core.compiler.model.TeamModel; @@ -474,7 +474,7 @@ public class Lifting extends SwitchOnBaseTypeGenerator } statements[1] = // OTDYN: Slightly different methods depending on the weaving strategy: - CallinImplementorDyn.DYNAMIC_WEAVING + boundRootRoleModel.getWeavingScheme() == WeavingScheme.OTDRE ? gen.messageSend( gen.castExpression( gen.singleNameReference(_OT_BASE), diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lifting/LiftingEnvironment.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lifting/LiftingEnvironment.java index e13218990..53bce6b72 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lifting/LiftingEnvironment.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lifting/LiftingEnvironment.java @@ -44,6 +44,7 @@ import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.Constant; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding; @@ -150,11 +151,11 @@ public class LiftingEnvironment * @param lateRole * @param needMethodBodies */ - public void createLiftingInfrastructure(RoleModel lateRole, boolean needMethodBodies) { - TreeNode[] boundRoles = getBoundRoles(); + public void createLiftingInfrastructure(RoleModel lateRole, boolean needMethodBodies, WeavingScheme weavingScheme) { + TreeNode[] boundRoles = getBoundRoles(); if ((boundRoles == null) || (boundRoles.length == 0)) { if (lateRole == null && needMethodBodies) - ReflectionGenerator.createRoleQueryMethods(this._teamType); + ReflectionGenerator.createRoleQueryMethods(this._teamType, weavingScheme); return; } @@ -187,7 +188,7 @@ public class LiftingEnvironment generateRoleCaches(this._teamType); // TODO(SH): split into decl and statements (see fillGeneratedMethods()). if (needMethodBodies) - ReflectionGenerator.createRoleQueryMethods(this._teamType); + ReflectionGenerator.createRoleQueryMethods(this._teamType, weavingScheme); } else { // isTopBound? if (node != null && node.getTopmostBoundParent(true) == node) { diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/AnchorMapping.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/AnchorMapping.java index d3446770b..ca23363da 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/AnchorMapping.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/AnchorMapping.java @@ -140,7 +140,7 @@ public class AnchorMapping { scope = this._scope; // scope would be more specific but _scope is OK, too. TypeBinding[] newParams = null; boolean isMethodEnhanced = currentMethod != null && currentMethod.isCallin(); - int start = isMethodEnhanced ? MethodSignatureEnhancer.ENHANCING_ARG_LEN : 0; // don't map enhancement args, have no source expr. + int start = isMethodEnhanced ? this._methodSignatureEnhancer.ENHANCING_ARG_LEN : 0; // don't map enhancement args, have no source expr. for (int i=start; i<parameters.length; i++) { TypeBinding newParameter = instantiateParameter(scope, parameters[i], i, currentMethod, isMethodEnhanced); @@ -163,7 +163,7 @@ public class AnchorMapping { new IDependentTypeSubstitution() { @SuppressWarnings("synthetic-access") public TypeBinding substitute(DependentTypeBinding paramDependentType, TypeBinding[] typeArguments, int dimensions) { - int srcIdx = isMethodEnhanced ? i-MethodSignatureEnhancer.ENHANCING_ARG_LEN : i; + int srcIdx = isMethodEnhanced ? (i - AnchorMapping.this._methodSignatureEnhancer.ENHANCING_ARG_LEN) : i; ITeamAnchor anchor = null; if (AnchorMapping.this._arguments != null) anchor = translateAnchor(scope, AnchorMapping.this._arguments[srcIdx], paramDependentType, currentMethod); @@ -340,6 +340,7 @@ public class AnchorMapping { private Scope _scope = null; private HashMap<MethodBinding,TypeBinding[]> _instantiatedParameters = new HashMap<MethodBinding, TypeBinding[]>(); private boolean _allowInstantiation = true; + private MethodSignatureEnhancer _methodSignatureEnhancer; private AnchorMapping(Expression receiver, Statement[] arguments, Scope scope) { @@ -348,6 +349,7 @@ public class AnchorMapping { if (this._receiver instanceof ArrayReference) this._receiver = ((ArrayReference)this._receiver).receiver; this._scope = scope; + this._methodSignatureEnhancer = MethodSignatureEnhancer.variants[scope.compilerOptions().weavingScheme.ordinal()]; } /** diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/SyntheticBaseCallSurrogate.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/SyntheticBaseCallSurrogate.java index 4e5687edf..9d803ca0b 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/SyntheticBaseCallSurrogate.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/lookup/SyntheticBaseCallSurrogate.java @@ -20,6 +20,7 @@ import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.codegen.CodeStream; import org.eclipse.jdt.internal.compiler.codegen.Opcodes; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; @@ -33,7 +34,6 @@ import org.eclipse.objectteams.otdt.core.compiler.IOTConstants; import org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.WordValueAttribute; import org.eclipse.objectteams.otdt.internal.core.compiler.control.Config; import org.eclipse.objectteams.otdt.internal.core.compiler.control.Config.NotConfiguredException; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel; import org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel; import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.MethodSignatureEnhancer; @@ -66,7 +66,7 @@ public class SyntheticBaseCallSurrogate extends SyntheticOTMethodBinding this.selector = SyntheticBaseCallSurrogate.genSurrogateName(callinMethod.selector, callinMethod.declaringClass.sourceName(), callinMethod.isStatic()); if (!callinMethod.isStatic() && callinMethod.isCallin()) { // don't change paramaters if enhancement is absent // additional arg "boolean isSuperAccess": - this.parameters = addIsSuperAccessArg(this.parameters); + this.parameters = addIsSuperAccessArg(this.parameters, declaringClass.scope.compilerOptions().weavingScheme); } this.purpose = MethodAccess; this.targetMethod = callinMethod; @@ -125,14 +125,14 @@ public class SyntheticBaseCallSurrogate extends SyntheticOTMethodBinding * Add any required base-call surrogates to the given type. * @param type must be a role class. */ - public static void addFakedBaseCallSurrogates(SourceTypeBinding type) { + public static void addFakedBaseCallSurrogates(SourceTypeBinding type, LookupEnvironment environment) { if (type.methods() == null) return; - if (CallinImplementorDyn.DYNAMIC_WEAVING) // no surrogates for the dynamic weaver. + if (environment.globalOptions.weavingScheme == WeavingScheme.OTDRE) // no surrogates for the dynamic weaver. return; for (MethodBinding method : type.methods()) if (method.isCallin() && (method.returnType != null)) - SyntheticBaseCallSurrogate.getBaseCallSurrogate(method, type.roleModel, type.scope.environment()); + SyntheticBaseCallSurrogate.getBaseCallSurrogate(method, type.roleModel, environment); } /** @@ -165,7 +165,7 @@ public class SyntheticBaseCallSurrogate extends SyntheticOTMethodBinding TypeBinding returnType = MethodSignatureEnhancer.getGeneralizedReturnType(callinMethod.returnType, environment); TypeBinding[] baseCallParameters = callinMethod.parameters; if (!callinMethod.isStatic()) - baseCallParameters = addIsSuperAccessArg(baseCallParameters); + baseCallParameters = addIsSuperAccessArg(baseCallParameters, environment.globalOptions.weavingScheme); // search existing surrogate: candidates: @@ -228,15 +228,16 @@ public class SyntheticBaseCallSurrogate extends SyntheticOTMethodBinding return CharOperation.equals(one.sourceName(), two.sourceName()); } - static TypeBinding[] addIsSuperAccessArg(TypeBinding[] baseCallParameters) + static TypeBinding[] addIsSuperAccessArg(TypeBinding[] baseCallParameters, WeavingScheme weavingScheme) { int len = baseCallParameters.length; TypeBinding[] newParams = new TypeBinding[len+1]; - System.arraycopy(baseCallParameters, 0, newParams, 0, MethodSignatureEnhancer.ENHANCING_ARG_LEN); - newParams[MethodSignatureEnhancer.ENHANCING_ARG_LEN] = TypeBinding.BOOLEAN; - System.arraycopy(baseCallParameters, MethodSignatureEnhancer.ENHANCING_ARG_LEN, - newParams, MethodSignatureEnhancer.ENHANCING_ARG_LEN+1, - len-MethodSignatureEnhancer.ENHANCING_ARG_LEN); + int enhancingArgLen = MethodSignatureEnhancer.getEnhancingArgLen(weavingScheme); + System.arraycopy(baseCallParameters, 0, newParams, 0, enhancingArgLen); + newParams[enhancingArgLen] = TypeBinding.BOOLEAN; + System.arraycopy(baseCallParameters, enhancingArgLen, + newParams, enhancingArgLen+1, + len-enhancingArgLen); return newParams; } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/CallinImplementor.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/CallinImplementor.java index 3f91e0f21..40e04e631 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/CallinImplementor.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/CallinImplementor.java @@ -113,7 +113,6 @@ public class CallinImplementor extends MethodMappingImplementor //_OT$role static final char[] ROLE_VAR_NAME = CharOperation.concat(IOTConstants.OT_DOLLAR_NAME, IOTConstants.ROLE); private static final char[] OLD_IS_EXECUTING = "_OT$oldIsExecuting".toCharArray(); //$NON-NLS-1$ - private RoleModel _role; private ClassScope _roleScope; /** @@ -122,7 +121,7 @@ public class CallinImplementor extends MethodMappingImplementor */ public CallinImplementor(RoleModel role) { - this._role = role; + super(role); this._roleScope = role.getAst().scope; // we definitely have an AST here this.bindingDirection = TerminalTokens.TokenNameBINDIN; } @@ -356,7 +355,8 @@ public class CallinImplementor extends MethodMappingImplementor arguments, new char[0], true, // isWrapper - gen); + gen, + this._role.getWeavingScheme()); if (wrapperReturnType.isBaseType()) { TypeBinding baseReturn = baseReturnType; isReturnBoxed = (baseReturn.isBaseType() && baseReturn != TypeBinding.VOID); @@ -528,7 +528,7 @@ public class CallinImplementor extends MethodMappingImplementor // for role-side predicate Expression[] predicateArgs = null; int offset = callinBindingDeclaration.isReplaceCallin() ? - MethodSignatureEnhancer.ENHANCING_ARG_LEN : + getMethodSignatureEnhancer().ENHANCING_ARG_LEN : 0; int plainLen = messageSendArguments.length-offset; boolean needRoleVar = false; @@ -821,18 +821,18 @@ public class CallinImplementor extends MethodMappingImplementor int basePos = 1; // skip base object if (callinBindingDeclaration.isReplaceCallin()) { // we have enhanced arguments including _OT$unusedArgs - basePos += MethodSignatureEnhancer.ENHANCING_ARG_LEN; + basePos += getMethodSignatureEnhancer().ENHANCING_ARG_LEN; unusedIdx = 0; // check what is already in _OT$unusedArgs: if (baseMethodSpec.isCallin()) { - unusedIdx = MethodSignatureEnhancer.ENHANCING_ARG_LEN; + unusedIdx = getMethodSignatureEnhancer().ENHANCING_ARG_LEN; if (baseMethodSpec.isStatic()) // FIXME(SH): Static role methods other the callin? unusedIdx += 2; // a (dummyInt,MyTeam) pair of synthetics } } else { // no enhanced arguments, means also: no _OT$unusedArgs available yet. statements.add(gen.localVariable( - MethodSignatureEnhancer.UNUSED_ARGS, + getMethodSignatureEnhancer().UNUSED_ARGS, new ArrayQualifiedTypeReference( TypeConstants.JAVA_LANG_OBJECT, 1, // dims @@ -852,7 +852,7 @@ public class CallinImplementor extends MethodMappingImplementor statements.add( gen.assignment( new ArrayReference( - gen.singleNameReference(MethodSignatureEnhancer.UNUSED_ARGS), + gen.singleNameReference(getMethodSignatureEnhancer().UNUSED_ARGS), gen.intLiteral(unusedIdx++)), rhs)); } @@ -1018,7 +1018,7 @@ public class CallinImplementor extends MethodMappingImplementor char[] targetArgName = null; int generatedArgsLen = methodMapping.isReplaceCallin() ? - MethodSignatureEnhancer.ENHANCING_ARG_LEN: + 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 diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/CallinImplementorDyn.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/CallinImplementorDyn.java index c9f08dc37..f06f6f1ba 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/CallinImplementorDyn.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/CallinImplementorDyn.java @@ -40,6 +40,7 @@ import org.eclipse.jdt.internal.compiler.ast.TryStatement; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.ClassScope; @@ -85,10 +86,6 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator; * @since 1.3.0M3 */ public class CallinImplementorDyn extends MethodMappingImplementor { - - - public static boolean DYNAMIC_WEAVING = "dynamic".equals(System.getProperty("ot.weaving")); //$NON-NLS-1$ //$NON-NLS-2$ - //_OT$role static final char[] ROLE_VAR_NAME = CharOperation.concat(IOTConstants.OT_DOLLAR_NAME, IOTConstants.ROLE); @@ -125,7 +122,6 @@ public class CallinImplementorDyn extends MethodMappingImplementor { static final char[] CATCH_ARG = "_OT$caughtException".toCharArray(); //$NON-NLS-1$ - private RoleModel _role; private ClassScope _roleScope; /** @@ -197,7 +193,7 @@ public class CallinImplementorDyn extends MethodMappingImplementor { char[] targetArgName = null; int generatedArgsLen = methodMapping.isReplaceCallin() ? - MethodSignatureEnhancer.ENHANCING_ARG_LEN: + MethodSignatureEnhancer.getEnhancingArgLen(WeavingScheme.OTDRE): 0; final int srcIdx = idx-generatedArgsLen; // index into source-code signatures. @@ -457,7 +453,7 @@ public class CallinImplementorDyn extends MethodMappingImplementor { } int baseArgOffset = 0; - if (baseSpec.isCallin()) baseArgOffset+=MethodSignatureEnhancer.ENHANCING_ARG_LEN; + if (baseSpec.isCallin()) baseArgOffset+=MethodSignatureEnhancer.getEnhancingArgLen(WeavingScheme.OTDRE); if (baseSpec.isStatic() && baseSpec.getDeclaringClass().isRole()) baseArgOffset+=2; // unpack arguments to be used by parameter mappings and base predicate: // ArgTypeN argn = args[n] @@ -489,7 +485,7 @@ public class CallinImplementorDyn extends MethodMappingImplementor { // -- assemble arguments: TypeBinding[] roleParams = callinDecl.roleMethodSpec.resolvedParameters(); - Expression[] callArgs = new Expression [roleParams.length + (isReplace ? MethodSignatureEnhancer.ENHANCING_ARG_LEN : 0)]; + Expression[] callArgs = new Expression [roleParams.length + (isReplace ? MethodSignatureEnhancer.getEnhancingArgLen(WeavingScheme.OTDRE) : 0)]; int idx = 0; if (isReplace) for (char[] argName : REPLACE_ARG_NAMES) @@ -757,8 +753,10 @@ public class CallinImplementorDyn extends MethodMappingImplementor { methodDecl.hasParsedStatements = true; return true; } + }); } + /** * Assemble message send arguments plus perhaps a result reference to * yield argument expressions for a predicate call. diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/CalloutImplementor.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/CalloutImplementor.java index a2cb99d0b..2530885b6 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/CalloutImplementor.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/CalloutImplementor.java @@ -44,6 +44,7 @@ import org.eclipse.jdt.internal.compiler.ast.ThisReference; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.WrapperKind; import org.eclipse.jdt.internal.compiler.ast.Expression.DecapsulationState; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; @@ -122,7 +123,6 @@ public class CalloutImplementor extends MethodMappingImplementor private static final int INTERFACE = 0; private static final int CLASS = 1; - private RoleModel _role; /** * Generates a callout method for every callout mapping in the given RoleModel. @@ -142,7 +142,7 @@ public class CalloutImplementor extends MethodMappingImplementor public CalloutImplementor(RoleModel role) { - this._role = role; + super(role); this.bindingDirection = TerminalTokens.TokenNameBINDOUT; } @@ -591,7 +591,7 @@ public class CalloutImplementor extends MethodMappingImplementor else baseAccess = gen.qualifiedNameReference(new char[][] {IOTConstants._OT_BASE, baseField.name }); if (fieldSpec.isSetter()) { - int pos = (fieldSpec.isStatic() | CallinImplementorDyn.DYNAMIC_WEAVING) ? 0 : 1; + int pos = (fieldSpec.isStatic() | this._role.getWeavingScheme() == WeavingScheme.OTDRE) ? 0 : 1; baseAccess = gen.assignment((NameReference)baseAccess, arguments[pos]); returnType = TypeBinding.VOID; // signal that no result processing is necessary } @@ -678,7 +678,7 @@ public class CalloutImplementor extends MethodMappingImplementor minArguments = 1; else minArguments = 0; - if (!baseMethodSpec.isStatic() && !CallinImplementorDyn.DYNAMIC_WEAVING) { // OTREDyn uses non-static accessor for non-static fields + if (!baseMethodSpec.isStatic() && this._role.getWeavingScheme() == WeavingScheme.OTRE) { // OTREDyn uses non-static accessor for non-static fields arguments = new Expression[minArguments+1]; // cast needed against weakened _OT$base reference // and if base is a role, to go to the class type (FIXME) diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/MethodMappingImplementor.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/MethodMappingImplementor.java index 39791ac4b..5518e153e 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/MethodMappingImplementor.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/mappings/MethodMappingImplementor.java @@ -29,6 +29,7 @@ import org.eclipse.jdt.internal.compiler.ast.Statement; import org.eclipse.jdt.internal.compiler.ast.TypeParameter; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding; @@ -46,7 +47,9 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.ast.MethodSpec; import org.eclipse.objectteams.otdt.internal.core.compiler.ast.TypeAnchorReference; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.ITeamAnchor; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.RoleTypeBinding; +import org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel; import org.eclipse.objectteams.otdt.internal.core.compiler.model.TeamModel; +import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.MethodSignatureEnhancer; import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.ReplaceResultReferenceVisitor; import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstClone; import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator; @@ -67,6 +70,24 @@ public abstract class MethodMappingImplementor { // use this if source positions must be mapped between roleFile and enclosing team: protected AstGenerator synthGen; + protected RoleModel _role; + + private MethodSignatureEnhancer methodSignatureEnhancer; + + public MethodMappingImplementor(RoleModel role) { + this._role = role; + } + // for subclass CallinImplementorDyn, which uses one role per transform call. + protected MethodMappingImplementor() { + // empty + } + + MethodSignatureEnhancer getMethodSignatureEnhancer() { + if (this.methodSignatureEnhancer == null) + this.methodSignatureEnhancer = MethodSignatureEnhancer.variants[this._role.getWeavingScheme().ordinal()]; + return this.methodSignatureEnhancer; + } + /** * Make arguments for message send which implements a callout or a callin wrapper. * For a callout mapping this method is used only if signatures are given @@ -114,7 +135,7 @@ public abstract class MethodMappingImplementor { int implementationArgLen = implParameters.length; int expressionsOffset = 0; - if (isFieldAccess && !CallinImplementorDyn.DYNAMIC_WEAVING) { // OTREDyn uses non-static accessor for non-static fields + if (isFieldAccess && this._role.getWeavingScheme() == WeavingScheme.OTRE) { // OTREDyn uses non-static accessor for non-static fields // field access is mapped to static method with additional first parameter _OT$base (unless static): if (!((FieldAccessSpec)methodMapping.getBaseMethodSpecs()[0]).isStatic()) expressionsOffset = 1; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TypeModel.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TypeModel.java index 14b9799d0..c443172db 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TypeModel.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/model/TypeModel.java @@ -31,6 +31,7 @@ import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader; import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.BinaryTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.ClassScope; @@ -110,6 +111,9 @@ public class TypeModel extends ModelElement { * Version number of the compiler that created a (binary) type; */ public int _compilerVersion; + + WeavingScheme weavingScheme; + public void setBinding (ReferenceBinding binding) { this._binding = binding; @@ -510,7 +514,7 @@ public class TypeModel extends ModelElement { } protected OTSpecialAccessAttribute getSpecialAccessAttribute() { if (this._specialAccess == null) { - this._specialAccess = new OTSpecialAccessAttribute(this._binding); + this._specialAccess = new OTSpecialAccessAttribute(this._binding, getWeavingScheme()); addAttribute(this._specialAccess); } return this._specialAccess; @@ -559,4 +563,9 @@ public class TypeModel extends ModelElement { } return false; } + public WeavingScheme getWeavingScheme() { + if (this.weavingScheme == null && this._ast != null && this._ast.scope != null) + this.weavingScheme = this._ast.scope.compilerOptions().weavingScheme; + return this.weavingScheme; + } } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/MethodSignatureEnhancer.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/MethodSignatureEnhancer.java index 1cb78c0fa..be957c0e1 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/MethodSignatureEnhancer.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/MethodSignatureEnhancer.java @@ -28,12 +28,12 @@ import org.eclipse.jdt.internal.compiler.ast.Expression; import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.LookupEnvironment; import org.eclipse.jdt.internal.compiler.lookup.Scope; import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.objectteams.otdt.core.compiler.IOTConstants; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel; import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator; @@ -75,23 +75,34 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator; public class MethodSignatureEnhancer implements IOTConstants, TypeConstants, ClassFileConstants { - private static final char[] OBJECT_SIGNATURE = "Ljava/lang/Object;".toCharArray(); + private final static char[] OBJECT_SIGNATURE = "Ljava/lang/Object;".toCharArray(); /** * Names for arguments in enhanced signature used for passing runtime meta-information to the wrapper/role method. */ - private final static char[][] ENHANCING_ARG_NAMES; + private final char[][] ENHANCING_ARG_NAMES; + /** Length of the sublist of enhancing arguments. */ - public final static int ENHANCING_ARG_LEN; - public final static char[] UNUSED_ARGS; + public final int ENHANCING_ARG_LEN; + public final char[] UNUSED_ARGS; + + public static MethodSignatureEnhancer[] variants = new MethodSignatureEnhancer[WeavingScheme.values().length]; + + private WeavingScheme weavingScheme; + // {OT/JamVM support: private static final boolean JAMVM_ASPECTBI = System.getProperty("ot.jamvm.aspectBI") != null; // CH} //{OTDyn: make constants configurable: static { - if (CallinImplementorDyn.DYNAMIC_WEAVING) { - ENHANCING_ARG_NAMES = new char[][] { + for(WeavingScheme scheme : WeavingScheme.values()) + variants[scheme.ordinal()] = new MethodSignatureEnhancer(scheme); + } + private MethodSignatureEnhancer(WeavingScheme weavingScheme) { + this.weavingScheme = weavingScheme; + if (weavingScheme == WeavingScheme.OTDRE) { + this.ENHANCING_ARG_NAMES = new char[][] { "_OT$baseArg".toCharArray(), "_OT$teams".toCharArray(), "_OT$index".toCharArray(), @@ -100,14 +111,14 @@ public class MethodSignatureEnhancer implements IOTConstants, TypeConstants, Cla "_OT$args".toCharArray()}; // {OT/JamVM support: } else if (JAMVM_ASPECTBI) { - ENHANCING_ARG_NAMES = new char[][] { + this.ENHANCING_ARG_NAMES = new char[][] { "_OT$teamIterator".toCharArray(), "_OT$bindIdx".toCharArray(), "_OT$baseMethodTag".toCharArray(), "_OT$unusedArgs".toCharArray() }; // CH} } else { - ENHANCING_ARG_NAMES = new char[][] { + this.ENHANCING_ARG_NAMES = new char[][] { "_OT$teams".toCharArray(), "_OT$teamIDs".toCharArray(), "_OT$idx".toCharArray(), @@ -115,15 +126,15 @@ public class MethodSignatureEnhancer implements IOTConstants, TypeConstants, Cla "_OT$baseMethodTag".toCharArray(), "_OT$unusedArgs".toCharArray() }; } - ENHANCING_ARG_LEN = ENHANCING_ARG_NAMES.length; - UNUSED_ARGS = ENHANCING_ARG_NAMES[ENHANCING_ARG_LEN-1]; + this.ENHANCING_ARG_LEN = this.ENHANCING_ARG_NAMES.length; + this.UNUSED_ARGS = this.ENHANCING_ARG_NAMES[this.ENHANCING_ARG_LEN-1]; } // SH} /** Get Typebindings for all enhancing arguments. */ private static TypeBinding[] getEnhancingArgTypes (Scope scope) { //{OTDyn: configurable: - if (CallinImplementorDyn.DYNAMIC_WEAVING) + if (scope.compilerOptions().weavingScheme == WeavingScheme.OTDRE) return new TypeBinding[] { scope.getType(IOTConstants.ORG_OBJECTTEAMS_IBOUNDBASE, 3), // _OT$baseArg scope.createArrayType(scope.getOrgObjectteamsITeam(), 1), // _OT$teams @@ -164,14 +175,19 @@ public class MethodSignatureEnhancer implements IOTConstants, TypeConstants, Cla * @return a new array of args */ public static Argument[] enhanceArguments( + Argument[] arguments, char[] namePrefix, boolean isWrapper, AstGenerator gen, WeavingScheme weavingScheme) + { + return variants[weavingScheme.ordinal()].internalEnhanceArguments(arguments, namePrefix, isWrapper, gen); + } + private Argument[] internalEnhanceArguments( Argument[] arguments, char[] namePrefix, boolean isWrapper, AstGenerator gen) { - int fullLen = ENHANCING_ARG_LEN; + int fullLen = this.ENHANCING_ARG_LEN; if (arguments != null) fullLen += arguments.length; // source arguments? Argument[] newArgs = new Argument[fullLen]; TypeReference[] enhanceTypes = //{OTDyn: configurable: - CallinImplementorDyn.DYNAMIC_WEAVING + this.weavingScheme == WeavingScheme.OTDRE ? new TypeReference[] { gen.qualifiedTypeReference(ORG_OBJECTTEAMS_IBOUNDBASE), // _OT$baseArg gen.qualifiedArrayTypeReference(ORG_OBJECTTEAMS_ITEAM, 1), // _OT$teams @@ -203,33 +219,37 @@ public class MethodSignatureEnhancer implements IOTConstants, TypeConstants, Cla if (isWrapper && arguments != null) newArgs[prefixLen++] = arguments[0]; // enhancing args: - for (int i=0; i<ENHANCING_ARG_LEN; i++) + for (int i=0; i<this.ENHANCING_ARG_LEN; i++) newArgs[i+prefixLen] = gen.argument( - CharOperation.concat(namePrefix, ENHANCING_ARG_NAMES[i]), + CharOperation.concat(namePrefix, this.ENHANCING_ARG_NAMES[i]), enhanceTypes[i], AccFinal); // source args: if (arguments != null) System.arraycopy(arguments, prefixLen, - newArgs, ENHANCING_ARG_LEN+prefixLen, arguments.length-prefixLen); + newArgs, this.ENHANCING_ARG_LEN+prefixLen, arguments.length-prefixLen); return newArgs; } /** Enhance the arguments of a base call or self-call within callin. */ - public static Expression[] enhanceArguments(Expression[] arguments, int pos) + public static Expression[] enhanceArguments(Expression[] arguments, int pos, WeavingScheme weavingScheme) + { + return variants[weavingScheme.ordinal()].internalEnhanceArguments(arguments, pos); + } + private Expression[] internalEnhanceArguments(Expression[] arguments, int pos) { AstGenerator gen = new AstGenerator(pos, pos); - int fullLen = ENHANCING_ARG_LEN; // enhancing arguments + int fullLen = this.ENHANCING_ARG_LEN; // enhancing arguments if (arguments != null) fullLen += arguments.length; // source arguments? Expression[] enhancedArgs = new Expression[fullLen]; // enhancing arguments: - for (int i = 0; i < ENHANCING_ARG_LEN; i++) - enhancedArgs[i] = gen.singleNameReference(ENHANCING_ARG_NAMES[i]); + for (int i = 0; i < this.ENHANCING_ARG_LEN; i++) + enhancedArgs[i] = gen.singleNameReference(this.ENHANCING_ARG_NAMES[i]); // source arguments? if (arguments != null ) - System.arraycopy(arguments, 0, enhancedArgs, ENHANCING_ARG_LEN, arguments.length); + System.arraycopy(arguments, 0, enhancedArgs, this.ENHANCING_ARG_LEN, arguments.length); return enhancedArgs; } @@ -244,17 +264,21 @@ public class MethodSignatureEnhancer implements IOTConstants, TypeConstants, Cla */ public static TypeBinding[] enhanceParameters(Scope scope, TypeBinding[] parameters) { - int fullLen = parameters.length + ENHANCING_ARG_LEN; + return variants[scope.compilerOptions().weavingScheme.ordinal()].internalEnhanceParameters(scope, parameters); + } + private TypeBinding[] internalEnhanceParameters(Scope scope, TypeBinding[] parameters) + { + int fullLen = parameters.length + this.ENHANCING_ARG_LEN; TypeBinding[] newParameters = new TypeBinding[fullLen]; // enhancing parameters: System.arraycopy( getEnhancingArgTypes(scope), 0, - newParameters, 0, ENHANCING_ARG_LEN); + newParameters, 0, this.ENHANCING_ARG_LEN); // source parameters: System.arraycopy( parameters, 0, - newParameters, ENHANCING_ARG_LEN, parameters.length); + newParameters, this.ENHANCING_ARG_LEN, parameters.length); return newParameters; } @@ -331,42 +355,48 @@ public class MethodSignatureEnhancer implements IOTConstants, TypeConstants, Cla } /** If methodDecl is a callin method return just its source-level arguments. */ - public static Argument[] maybeRetrenchArguments(MethodDeclaration methodDecl) { + public static Argument[] maybeRetrenchArguments(MethodDeclaration methodDecl, WeavingScheme weavingScheme) { + return variants[weavingScheme.ordinal()].internalMaybeRetrenchArguments(methodDecl); + } + private Argument[] internalMaybeRetrenchArguments(MethodDeclaration methodDecl) { if (!methodDecl.isCallin()) return methodDecl.arguments; int len = methodDecl.arguments.length; - Argument[] result = new Argument[len-ENHANCING_ARG_LEN]; - System.arraycopy(methodDecl.arguments, ENHANCING_ARG_LEN, result, 0, result.length); + Argument[] result = new Argument[len-this.ENHANCING_ARG_LEN]; + System.arraycopy(methodDecl.arguments, this.ENHANCING_ARG_LEN, result, 0, result.length); return result; } - public static Expression[] retrenchBasecallArguments(Expression[] arguments, boolean isEnhanced) { + public static Expression[] retrenchBasecallArguments(Expression[] arguments, boolean isEnhanced, WeavingScheme weavingScheme) { + return variants[weavingScheme.ordinal()].internalRetrenchBasecallArguments(arguments, isEnhanced); + } + private Expression[] internalRetrenchBasecallArguments(Expression[] arguments, boolean isEnhanced) { if (arguments == null) return null; int len = arguments.length; - int discard = CallinImplementorDyn.DYNAMIC_WEAVING ? 0 : 1; // isSuperAccess (unconditionally) // FIXME(OTDYN) must handle super flag? + int discard = this.weavingScheme == WeavingScheme.OTDRE ? 0 : 1; // isSuperAccess (unconditionally) // FIXME(OTDYN) must handle super flag? if (isEnhanced) // if TransformStatementsVisitor has modified this node - discard += ENHANCING_ARG_LEN; + discard += this.ENHANCING_ARG_LEN; Expression[] result = new Expression[len-discard]; System.arraycopy(arguments, discard, result, 0, result.length); return result; } - public static TypeBinding[] retrenchParameterTypes(TypeBinding[] parameters) { + public TypeBinding[] retrenchParameterTypes(TypeBinding[] parameters) { if (parameters == null) return null; int len = parameters.length; - if (len >= ENHANCING_ARG_LEN) { - TypeBinding[] result = new TypeBinding[len-ENHANCING_ARG_LEN]; - System.arraycopy(parameters, ENHANCING_ARG_LEN, result, 0, result.length); + if (len >= this.ENHANCING_ARG_LEN) { + TypeBinding[] result = new TypeBinding[len-this.ENHANCING_ARG_LEN]; + System.arraycopy(parameters, this.ENHANCING_ARG_LEN, result, 0, result.length); return result; } return parameters; } - public static void beautifyTypesString(StringBuffer types, boolean makeShort) { + public static void beautifyTypesString(StringBuffer types, boolean makeShort, WeavingScheme weavingScheme) { String typeString = types.toString(); String prefix = //{OTDyn: configurable: - CallinImplementorDyn.DYNAMIC_WEAVING + weavingScheme == WeavingScheme.OTDRE ? (makeShort ? "IBoundBase, ITeam[], int, int[], int, Object[]" : "org.objectteams.IBoundBase, org.objectteams.ITeam[], int, int[] int, java.lang.Object[]))") @@ -387,17 +417,27 @@ public class MethodSignatureEnhancer implements IOTConstants, TypeConstants, Cla } } + public static Argument[] getSourceArguments(AbstractMethodDeclaration methodDeclaration, WeavingScheme weavingScheme) { + return variants[weavingScheme.ordinal()].internalGetSourceArguments(methodDeclaration); + } public static Argument[] getSourceArguments(AbstractMethodDeclaration methodDeclaration) { + WeavingScheme weavingScheme = WeavingScheme.OTRE; // "default" just to avoid null + if (methodDeclaration.scope != null) { + weavingScheme = methodDeclaration.scope.compilerOptions().weavingScheme; + } + return variants[weavingScheme.ordinal()].internalGetSourceArguments(methodDeclaration); + } + private Argument[] internalGetSourceArguments(AbstractMethodDeclaration methodDeclaration) { Argument[] arguments = methodDeclaration.arguments; if (methodDeclaration.isCallin()) { assert arguments != null; - int len = arguments.length - ENHANCING_ARG_LEN; + int len = arguments.length - this.ENHANCING_ARG_LEN; assert len >= 0; if (len == 0) arguments = null; else System.arraycopy( - arguments, ENHANCING_ARG_LEN, + arguments, this.ENHANCING_ARG_LEN, arguments = new Argument[len], 0, len); } else if (CharOperation.prefixEquals(IOTConstants.BASE_PREDICATE_PREFIX, methodDeclaration.selector)) { // hide base arg of base predicate (has dummy type after parsing): @@ -406,14 +446,21 @@ public class MethodSignatureEnhancer implements IOTConstants, TypeConstants, Cla return arguments; } - public static boolean isEnhanced(AbstractMethodDeclaration methodDeclaration) { + public static boolean isEnhanced(AbstractMethodDeclaration methodDeclaration, WeavingScheme weavingScheme) { + return variants[weavingScheme.ordinal()].internalIsEnhanced(methodDeclaration); + } + private boolean internalIsEnhanced(AbstractMethodDeclaration methodDeclaration) { Argument[] arguments = methodDeclaration.arguments; - if (arguments == null || arguments.length < ENHANCING_ARG_LEN) + if (arguments == null || arguments.length < this.ENHANCING_ARG_LEN) return false; - for (int i = 0; i < ENHANCING_ARG_LEN; i++) { - if (!CharOperation.endsWith(arguments[i].name, ENHANCING_ARG_NAMES[i])) + for (int i = 0; i < this.ENHANCING_ARG_LEN; i++) { + if (!CharOperation.endsWith(arguments[i].name, this.ENHANCING_ARG_NAMES[i])) return false; } return true; } + + public static int getEnhancingArgLen(WeavingScheme weavingScheme) { + return variants[weavingScheme.ordinal()].ENHANCING_ARG_LEN; + } } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/PredicateGenerator.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/PredicateGenerator.java index 5e72293fa..9861f6c7b 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/PredicateGenerator.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/PredicateGenerator.java @@ -39,6 +39,7 @@ import org.eclipse.jdt.internal.compiler.ast.ReturnStatement; import org.eclipse.jdt.internal.compiler.ast.Statement; import org.eclipse.jdt.internal.compiler.ast.ThisReference; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; @@ -50,7 +51,6 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.ast.GuardPredicateDec import org.eclipse.objectteams.otdt.internal.core.compiler.ast.MethodSpec; import org.eclipse.objectteams.otdt.internal.core.compiler.control.Config; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.CallinCalloutScope; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel; import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator; import org.eclipse.objectteams.otdt.internal.core.compiler.util.TSuperHelper; @@ -338,8 +338,11 @@ public class PredicateGenerator extends SwitchOnBaseTypeGenerator private Expression baseReference(char[] baseVarName, ReferenceBinding roleType, AstGenerator gen) { Expression result= gen.singleNameReference(baseVarName); if (roleType != null) { + WeavingScheme weavingScheme = WeavingScheme.OTRE; + if (roleType.roleModel != null) + weavingScheme = roleType.roleModel.getWeavingScheme(); if ( TypeBinding.notEquals(roleType.baseclass(), this._currentRole.baseclass()) - || CallinImplementorDyn.DYNAMIC_WEAVING) // under OTREDyn base is passed as IBoundBase => always need to cast. + || weavingScheme == WeavingScheme.OTDRE) // under OTREDyn base is passed as IBoundBase => always need to cast. { result= gen.castExpression(result, gen.baseTypeReference(roleType.baseclass()), CastExpression.RAW); } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/ReflectionGenerator.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/ReflectionGenerator.java index c7574eefb..9b2f5aeee 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/ReflectionGenerator.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/ReflectionGenerator.java @@ -40,6 +40,7 @@ import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.ast.Wildcard; import org.eclipse.jdt.internal.compiler.ast.Expression.DecapsulationState; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; @@ -48,7 +49,6 @@ import org.eclipse.objectteams.otdt.core.compiler.IOTConstants; import org.eclipse.objectteams.otdt.internal.core.compiler.control.Config; import org.eclipse.objectteams.otdt.internal.core.compiler.control.Config.NotConfiguredException; import org.eclipse.objectteams.otdt.internal.core.compiler.lifting.LiftingEnvironment; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel; import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstClone; import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstConverter; @@ -123,8 +123,9 @@ public class ReflectionGenerator implements IOTConstants, ClassFileConstants { * Due to the similarities, we create all six methods simultaneously. * * @param teamDecl + * @param weavingScheme TODO */ - public static void createRoleQueryMethods(TypeDeclaration teamDecl) + public static void createRoleQueryMethods(TypeDeclaration teamDecl, WeavingScheme weavingScheme) { if ( TypeAnalyzer.isOrgObjectteamsTeam(teamDecl.binding) || Protections.hasClassKindProblem(teamDecl.binding)) @@ -303,7 +304,7 @@ public class ReflectionGenerator implements IOTConstants, ClassFileConstants { hasStats2 [m2] = createIfTypeEqualAndContains(roleType, cacheName, gen, objectBinding); getStats2 [m2++] = createIfTypeEqualAndGet (roleType, cacheName, gen); getAStats2 [g2++] = createIfTypeEqualFetchValues(roleType, cacheName, gen); - unregStats2[u2++] = createRemove (roleType, cacheName, gen); + unregStats2[u2++] = createRemove (roleType, cacheName, gen, weavingScheme); } } if (g2 > 1) @@ -339,7 +340,7 @@ public class ReflectionGenerator implements IOTConstants, ClassFileConstants { null)); // no duplicate means: if found remove from first_cache; if (u1 > 3) - unregStats1[u1]=createRemoveIfFound(gen2); // if u1 <= 3 this would not be reachable due to definite null + unregStats1[u1]=createRemoveIfFound(gen2, weavingScheme); // if u1 <= 3 this would not be reachable due to definite null hasRole1.setStatements(hasStats1); getRole1.setStatements(getStats1); getARoles1.setStatements(getAStats1); @@ -568,7 +569,7 @@ public class ReflectionGenerator implements IOTConstants, ClassFileConstants { ); } - private static Statement createRemoveIfFound (AstGenerator gen) + private static Statement createRemoveIfFound (AstGenerator gen, WeavingScheme weavingScheme) { /* * For the end of unregisterRole(Object) create: @@ -591,7 +592,7 @@ public class ReflectionGenerator implements IOTConstants, ClassFileConstants { new Expression[] { gen.singleNameReference(FOUND_BASE) } ), // OTDYN: Slightly different methods depending on the weaving strategy: - CallinImplementorDyn.DYNAMIC_WEAVING + weavingScheme == WeavingScheme.OTDRE ? gen.messageSend( gen.castExpression( gen.singleNameReference(FOUND_BASE), @@ -822,7 +823,7 @@ public class ReflectionGenerator implements IOTConstants, ClassFileConstants { private static Statement createRemove( - ReferenceBinding roleType, char[] cacheName, AstGenerator gen) + ReferenceBinding roleType, char[] cacheName, AstGenerator gen, WeavingScheme weavingScheme) { /* * for each bound role create: @@ -860,7 +861,7 @@ public class ReflectionGenerator implements IOTConstants, ClassFileConstants { } ), // OTDYN: Slightly different methods depending on the weaving strategy: - CallinImplementorDyn.DYNAMIC_WEAVING + weavingScheme == WeavingScheme.OTDRE ? gen.messageSend( gen.castExpression( gen.singleNameReference(BASE_OBJ), diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/RoleMigrationImplementor.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/RoleMigrationImplementor.java index 496726a85..3d067df86 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/RoleMigrationImplementor.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/RoleMigrationImplementor.java @@ -54,7 +54,6 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.lifting.LiftingEnviro import org.eclipse.objectteams.otdt.internal.core.compiler.lifting.TreeNode; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.ITeamAnchor; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.TeamAnchor; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstEdit; import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator; import org.eclipse.objectteams.otdt.internal.core.compiler.util.RoleTypeCreator; @@ -370,22 +369,24 @@ public class RoleMigrationImplementor static void genAddOrRemoveRole(CodeStream codeStream, Scope scope, ReferenceBinding iboundBase, boolean isAdding) { codeStream.aload_0(); // this // OTDYN: Slightly different methods depending on the weaving strategy: - if (CallinImplementorDyn.DYNAMIC_WEAVING) { - // _OT$addOrRemoveRole(role, isAdding) - if (isAdding) - codeStream.iconst_1(); // isAdding=true - else - codeStream.iconst_0(); // isAdding=false - codeStream.invoke(Opcodes.OPC_invokeinterface, - iboundBase.getMethod(scope, IOTConstants.ADD_REMOVE_ROLE), - iboundBase); - } else { - // _OT$addRole(role) or _OT$removeRole(role): - codeStream.invoke(Opcodes.OPC_invokeinterface, - isAdding - ? iboundBase.getMethod(scope, IOTConstants.ADD_ROLE) - : iboundBase.getMethod(scope, IOTConstants.REMOVE_ROLE), + switch (scope.compilerOptions().weavingScheme) { + case OTDRE: + // _OT$addOrRemoveRole(role, isAdding) + if (isAdding) + codeStream.iconst_1(); // isAdding=true + else + codeStream.iconst_0(); // isAdding=false + codeStream.invoke(Opcodes.OPC_invokeinterface, + iboundBase.getMethod(scope, IOTConstants.ADD_REMOVE_ROLE), iboundBase); + break; + case OTRE: + // _OT$addRole(role) or _OT$removeRole(role): + codeStream.invoke(Opcodes.OPC_invokeinterface, + isAdding + ? iboundBase.getMethod(scope, IOTConstants.ADD_ROLE) + : iboundBase.getMethod(scope, IOTConstants.REMOVE_ROLE), + iboundBase); } } diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/SerializationGenerator.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/SerializationGenerator.java index eae12cb3e..fd7e3cce8 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/SerializationGenerator.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/SerializationGenerator.java @@ -29,6 +29,7 @@ import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; import org.eclipse.jdt.internal.compiler.ast.TypeReference; import org.eclipse.jdt.internal.compiler.ast.Wildcard; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.MethodBinding; import org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.ReferenceBinding; @@ -37,7 +38,6 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.objectteams.otdt.core.compiler.IOTConstants; import org.eclipse.objectteams.otdt.core.exceptions.InternalCompilerError; import org.eclipse.objectteams.otdt.internal.core.compiler.control.StateMemento; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstEdit; import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator; import org.eclipse.objectteams.otdt.internal.core.compiler.util.TypeAnalyzer; @@ -158,7 +158,7 @@ public class SerializationGenerator { }), // ((IBoundBase)base)._OT$addRole(castedRole); // OTDYN: Slightly different methods depending on the weaving strategy: - CallinImplementorDyn.DYNAMIC_WEAVING + teamType.scope.compilerOptions().weavingScheme == WeavingScheme.OTDRE ? gen.messageSend( gen.castExpression(gen.singleNameReference(IOTConstants.BASE), gen.qualifiedTypeReference(IOTConstants.ORG_OBJECTTEAMS_IBOUNDBASE), CastExpression.RAW), diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/TeamMethodGenerator.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/TeamMethodGenerator.java index ad6d687fb..aa36e2e87 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/TeamMethodGenerator.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/TeamMethodGenerator.java @@ -40,6 +40,7 @@ import org.eclipse.jdt.internal.compiler.classfmt.MethodInfo; import org.eclipse.jdt.internal.compiler.env.IBinaryMethod; import org.eclipse.jdt.internal.compiler.flow.FlowContext; import org.eclipse.jdt.internal.compiler.flow.FlowInfo; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.ClassScope; import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; @@ -59,7 +60,6 @@ import org.eclipse.objectteams.otdt.internal.core.compiler.bytecode.ConstantPool import org.eclipse.objectteams.otdt.internal.core.compiler.control.Dependencies; import org.eclipse.objectteams.otdt.internal.core.compiler.control.ITranslationStates; import org.eclipse.objectteams.otdt.internal.core.compiler.lookup.CallinCalloutBinding; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel; import org.eclipse.objectteams.otdt.internal.core.compiler.model.RoleModel; import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstEdit; @@ -234,8 +234,8 @@ public class TeamMethodGenerator { public SourceTypeBinding ooTeamBinding; // ==== ==== - public TeamMethodGenerator() { - if (CallinImplementorDyn.DYNAMIC_WEAVING) { + public TeamMethodGenerator(WeavingScheme weavingScheme) { + if (weavingScheme == WeavingScheme.OTDRE) { int l1 = this.methodDescriptors.length; int l2 = this.methodDescriptorsDyn.length; MethodDescriptor[] all = new MethodDescriptor[l1+l2]; diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/TransformStatementsVisitor.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/TransformStatementsVisitor.java index cff9a35d2..dc731c68b 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/TransformStatementsVisitor.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/statemachine/transformer/TransformStatementsVisitor.java @@ -34,6 +34,7 @@ import org.eclipse.jdt.internal.compiler.ast.ReturnStatement; import org.eclipse.jdt.internal.compiler.ast.Statement; import org.eclipse.jdt.internal.compiler.ast.ThisReference; import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.BaseTypeBinding; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.ClassScope; @@ -41,6 +42,7 @@ import org.eclipse.jdt.internal.compiler.lookup.TypeBinding; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; import org.eclipse.objectteams.otdt.core.compiler.IOTConstants; import org.eclipse.objectteams.otdt.core.exceptions.InternalCompilerError; +import org.eclipse.objectteams.otdt.internal.core.compiler.ast.BaseCallMessageSend; import org.eclipse.objectteams.otdt.internal.core.compiler.ast.BaseReference; import org.eclipse.objectteams.otdt.internal.core.compiler.control.ITranslationStates; import org.eclipse.objectteams.otdt.internal.core.compiler.control.StateHelper; @@ -76,6 +78,12 @@ public class TransformStatementsVisitor // -- fields and methods for scope management --- private Stack<MethodDeclaration> _methodDeclarationStack = new Stack<MethodDeclaration>(); + private WeavingScheme weavingScheme; + + public TransformStatementsVisitor(WeavingScheme weavingScheme) { + this.weavingScheme = weavingScheme; + } + /** * If methodDeclaration is a callin method remember it for translating base calls. * Only remember methodDeclarations with ignoreFurtherInvestigation==false to @@ -132,7 +140,12 @@ public class TransformStatementsVisitor } // === Adjustments following enhancement of callin method signatures: - + @Override + public boolean visit(BaseCallMessageSend messageSend, BlockScope scope) { + messageSend.prepareSuperAccess(this.weavingScheme); + return true; + } + /** May need to add arguments to a 'recursive' callin message send. */ @Override public boolean visit(MessageSend messageSend, BlockScope scope) { @@ -146,31 +159,35 @@ public class TransformStatementsVisitor { // argument enhancing within callin methods: Expression[] args = messageSend.arguments; - if (CallinImplementorDyn.DYNAMIC_WEAVING) { - if (isBaseCall) { - AstGenerator gen = new AstGenerator(messageSend); - if (args == null || args.length == 0) { - args = new Expression[] { gen.nullLiteral() }; - } else { - Expression[] boxedArgs = new Expression[args.length]; - for (int i = 0; i < args.length; i++) { - TypeBinding argType = methodDecl.arguments[i+MethodSignatureEnhancer.ENHANCING_ARG_LEN].binding.type; - if (argType.isBaseType()) - boxedArgs[i] = gen.createBoxing(args[i], (BaseTypeBinding) argType); - else - boxedArgs[i] = args[i]; - } - args = new Expression[] { - gen.arrayAllocation(gen.qualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT), 1, boxedArgs) - }; - } - } - } else if (args != null) { - int len = args.length; - if (isBaseCall && methodDecl.isStatic()) // chop of premature isSuperAccess flag: - System.arraycopy(args, 1, args=new Expression[len-1], 0, len-1); + if (isBaseCall) { + switch (this.weavingScheme) { + case OTDRE: + AstGenerator gen = new AstGenerator(messageSend); + if (args == null || args.length == 0) { + args = new Expression[] { gen.nullLiteral() }; + } else { + Expression[] boxedArgs = new Expression[args.length]; + for (int i = 0; i < args.length; i++) { + TypeBinding argType = methodDecl.arguments[i+MethodSignatureEnhancer.getEnhancingArgLen(this.weavingScheme)].binding.type; + if (argType.isBaseType()) + boxedArgs[i] = gen.createBoxing(args[i], (BaseTypeBinding) argType); + else + boxedArgs[i] = args[i]; + } + args = new Expression[] { + gen.arrayAllocation(gen.qualifiedTypeReference(TypeConstants.JAVA_LANG_OBJECT), 1, boxedArgs) + }; + } + break; + case OTRE: + if (args != null) { + int len = args.length; + if (methodDecl.isStatic()) // chop of premature isSuperAccess flag: + System.arraycopy(args, 1, args=new Expression[len-1], 0, len-1); + } + } } - messageSend.arguments = MethodSignatureEnhancer.enhanceArguments(args, messageSend.sourceEnd+1); + messageSend.arguments = MethodSignatureEnhancer.enhanceArguments(args, messageSend.sourceEnd+1, this.weavingScheme); messageSend.bits |= ASTNode.HasBeenTransformed; } return true; @@ -187,8 +204,8 @@ public class TransformStatementsVisitor if (callinMethod.arguments == null) return false; int sendArgs = messageSend.arguments == null ? 0 : messageSend.arguments.length; - sendArgs += MethodSignatureEnhancer.ENHANCING_ARG_LEN; - if (isBaseCall && !CallinImplementorDyn.DYNAMIC_WEAVING) + sendArgs += MethodSignatureEnhancer.getEnhancingArgLen(this.weavingScheme); + if (isBaseCall && this.weavingScheme == WeavingScheme.OTRE) sendArgs--; // don't count the isSuperAccess flag return sendArgs == callinMethod.arguments.length; } @@ -302,7 +319,7 @@ public class TransformStatementsVisitor { // but if class has errors the visitor bailed out. // need to transform before changing the selector - method.traverse(new TransformStatementsVisitor(), scope); + method.traverse(new TransformStatementsVisitor(scope.compilerOptions().weavingScheme), scope); } } }
\ No newline at end of file diff --git a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/RoleTypeCreator.java b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/RoleTypeCreator.java index d76511c96..8776b9048 100644 --- a/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/RoleTypeCreator.java +++ b/org.eclipse.jdt.core/compiler/org/eclipse/objectteams/otdt/internal/core/compiler/util/RoleTypeCreator.java @@ -29,6 +29,7 @@ import org.eclipse.jdt.internal.compiler.ast.*; import org.eclipse.jdt.internal.compiler.ast.Expression.DecapsulationState; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.*; import org.eclipse.jdt.internal.compiler.parser.TerminalTokens; import org.eclipse.jdt.internal.compiler.problem.ProblemReporter; @@ -335,7 +336,7 @@ public class RoleTypeCreator implements TagBits { else returnType = roleReturn; } - if (CallinImplementorDyn.DYNAMIC_WEAVING) { + if (scope.compilerOptions().weavingScheme == WeavingScheme.OTDRE) { if (CallinImplementorDyn.avoidWrapRoleType(scope, send.receiver)) // don't use synthetic local$role$n as additional anchor return returnType; @@ -488,7 +489,7 @@ public class RoleTypeCreator implements TagBits { && methodScope.referenceMethod() != null && methodScope.referenceMethod().isMappingWrapper._callin() //{OTDyn - && !CallinImplementorDyn.DYNAMIC_WEAVING) // this heuristic doesn't work for dyn weaving, FIXME(SH): check if still needed! + && scope.compilerOptions().weavingScheme == WeavingScheme.OTRE) // this heuristic doesn't work for dyn weaving, FIXME(SH): check if still needed! // SH} { // in a callin wrapper, for visibility reasons, pretend we are in the diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java index 8a31589c9..6d15a8578 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/ASTConverter.java @@ -62,6 +62,7 @@ import org.eclipse.jdt.internal.compiler.ast.Wildcard; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration.WrapperKind; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.ExtraCompilerModifiers; import org.eclipse.jdt.internal.compiler.lookup.TypeConstants; @@ -110,6 +111,7 @@ class ASTConverter { private DefaultCommentMapper commentMapper; //{ObjectTeams: one more configuration option: private boolean includeRoleFiles= false; + private WeavingScheme weavingScheme = WeavingScheme.OTRE; // avoid null // SH} public ASTConverter(Map options, boolean resolveBindings, IProgressMonitor monitor) { @@ -141,6 +143,9 @@ class ASTConverter { Object option = options.get(JavaCore.COMPILER_OPT_SCOPED_KEYWORDS); if (option != null) this.scanner.parseOTJonly = JavaCore.DISABLED.equals(option); + option = options.get(JavaCore.COMPILER_OPT_WEAVING_SCHEME); + if (option != null) + this.weavingScheme = WeavingScheme.valueOf((String) option); // SH} } @@ -682,7 +687,7 @@ class ASTConverter { /* orig: org.eclipse.jdt.internal.compiler.ast.Argument[] parameters = methodDeclaration.arguments; :giro */ - org.eclipse.jdt.internal.compiler.ast.Argument[] parameters = MethodSignatureEnhancer.getSourceArguments(methodDeclaration); + org.eclipse.jdt.internal.compiler.ast.Argument[] parameters = MethodSignatureEnhancer.getSourceArguments(methodDeclaration, this.weavingScheme); // SH} int parametersLength = parameters == null ? 0 : parameters.length; if (parametersLength > 0) { @@ -6533,7 +6538,8 @@ public BaseConstructorInvocation convert( if (arguments != null) { int argumentsLength = arguments.length; // FIXME(SH): static? - for (int idx = MethodSignatureEnhancer.ENHANCING_ARG_LEN+1; idx < argumentsLength; idx++) { // +1: skip 'isSuperAccess' + int startIdx = MethodSignatureEnhancer.getEnhancingArgLen(this.weavingScheme)+1; // +1: skip 'isSuperAccess' + for (int idx = startIdx; idx < argumentsLength; idx++) { Expression argExpr = convert(arguments[idx]); if (this.resolveBindings) { recordNodes(argExpr, arguments[idx]); diff --git a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodBinding.java b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodBinding.java index b29ef382c..b11221420 100644 --- a/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodBinding.java +++ b/org.eclipse.jdt.core/dom/org/eclipse/jdt/core/dom/MethodBinding.java @@ -27,7 +27,6 @@ import org.eclipse.jdt.internal.compiler.problem.AbortCompilation; import org.eclipse.jdt.internal.core.JavaElement; import org.eclipse.jdt.internal.core.util.Util; import org.eclipse.objectteams.otdt.internal.core.compiler.model.MethodModel; -import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.MethodSignatureEnhancer; /** * Internal implementation of method bindings. @@ -169,7 +168,7 @@ class MethodBinding implements IMethodBinding { org.eclipse.jdt.internal.compiler.lookup.TypeBinding[] parameters = this.binding.parameters; //{ObjectTeams: retrench callin method: if ((this.getModifiers() & ExtraCompilerModifiers.AccCallin) != 0) - parameters = MethodSignatureEnhancer.retrenchParameterTypes(parameters); + parameters = this.binding.getMethodSignatureEnhancer().retrenchParameterTypes(parameters); // SH} int length = parameters == null ? 0 : parameters.length; if (length == 0) { diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java index e03fa6ffc..fb4251212 100644 --- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java +++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java @@ -122,6 +122,7 @@ import org.eclipse.jdt.internal.compiler.ast.WhileStatement; import org.eclipse.jdt.internal.compiler.ast.Wildcard; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.lookup.BlockScope; import org.eclipse.jdt.internal.compiler.lookup.ClassScope; import org.eclipse.jdt.internal.compiler.lookup.CompilationUnitScope; @@ -211,6 +212,8 @@ public class CodeFormatterVisitor extends ASTVisitor { Arrays.sort(CLOSING_GENERICS_EXPECTEDTOKENS); Arrays.sort(SINGLETYPEREFERENCE_EXPECTEDTOKENS); } + // for access to MethodSignatureEnhancer: + private WeavingScheme weavingScheme = WeavingScheme.OTRE; // SH} public int lastLocalDeclarationSourceStart; int lastBinaryExpressionAlignmentBreakIndentation; @@ -243,6 +246,9 @@ public class CodeFormatterVisitor extends ASTVisitor { Object javaOption = settings.get(CompilerOptions.OPTION_PureJavaOnly); if (CompilerOptions.ENABLED.equals(javaOption)) this.preferences.isPureJava = true; + Object weavingOption = settings.get(JavaCore.COMPILER_OPT_WEAVING_SCHEME); + if (weavingOption != null) + this.weavingScheme = WeavingScheme.valueOf((String) weavingOption); // SH} this.scribe = new Scribe(this, sourceLevel, regions, codeSnippetParsingUtil, includeComments); } @@ -2168,7 +2174,7 @@ public class CodeFormatterVisitor extends ASTVisitor { /* orig: methodDeclaration.arguments, :giro */ - MethodSignatureEnhancer.getSourceArguments(methodDeclaration), + MethodSignatureEnhancer.getSourceArguments(methodDeclaration, this.weavingScheme), // SH} methodDeclaration.scope, spaceBeforeOpenParen, diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java index 3d59b59ce..b21ddd1ec 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/core/JavaCore.java @@ -1368,6 +1368,8 @@ public final class JavaCore extends Plugin { //{ObjectTeams: new option: scoped keywords (use stateful scanner?) public static final String COMPILER_OPT_SCOPED_KEYWORDS = OTDT_PLUGIN_ID + ".compiler.option.scoped_keywords"; //$NON-NLS-1$ + + public static final String COMPILER_OPT_WEAVING_SCHEME = OTDT_PLUGIN_ID + ".compiler.option.weaving_scheme"; //$NON-NLS-1$ // SH} /** diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java index 5eeef83ef..7468c60c2 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/compiler/parser/SourceTypeConverter.java @@ -57,8 +57,6 @@ import org.eclipse.objectteams.otdt.core.IOTType; import org.eclipse.objectteams.otdt.core.IRoleType; import org.eclipse.objectteams.otdt.core.OTModelManager; import org.eclipse.objectteams.otdt.internal.core.compiler.ast.AbstractMethodMappingDeclaration; -import org.eclipse.objectteams.otdt.internal.core.compiler.statemachine.transformer.MethodSignatureEnhancer; -import org.eclipse.objectteams.otdt.internal.core.compiler.util.AstGenerator; public class SourceTypeConverter extends TypeConverter { @@ -450,13 +448,6 @@ public class SourceTypeConverter extends TypeConverter { } } } -//{ObjectTeams: enhance signature for callin method: - if (method.isCallin()) { - AstGenerator gen = new AstGenerator(method.sourceEnd+1); - method.arguments = MethodSignatureEnhancer.enhanceArguments( - method.arguments, new char[0], /*isWrapper*/false, gen); - } -// SH} /* convert thrown exceptions */ char[][] exceptionTypeNames = methodInfo.getExceptionTypeNames(); diff --git a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java index 447a113f1..cc7ae59df 100644 --- a/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java +++ b/org.eclipse.jdt.core/model/org/eclipse/jdt/internal/core/util/Util.java @@ -55,6 +55,7 @@ import org.eclipse.jdt.internal.compiler.env.ClassSignature; import org.eclipse.jdt.internal.compiler.env.EnumConstantSignature; import org.eclipse.jdt.internal.compiler.env.IBinaryAnnotation; import org.eclipse.jdt.internal.compiler.env.IDependent; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.jdt.internal.compiler.impl.Constant; import org.eclipse.jdt.internal.compiler.lookup.Binding; import org.eclipse.jdt.internal.compiler.lookup.FieldBinding; @@ -1429,7 +1430,10 @@ public class Util { parameterSignatures = new String[arguments.length]; for (int i = 0; i < arguments.length; i++) { //{ObjectTeams: skip enhanced args of callin method: - if (methodDeclaration.isCallin() && i < MethodSignatureEnhancer.ENHANCING_ARG_LEN) + WeavingScheme weavingScheme = WeavingScheme.OTRE; // avoid null! + if (methodDeclaration.scope != null) + weavingScheme = methodDeclaration.scope.compilerOptions().weavingScheme; + if (methodDeclaration.isCallin() && i < MethodSignatureEnhancer.getEnhancingArgLen(weavingScheme)) continue; // SH} Argument argument = arguments[i]; diff --git a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java index 751f2791f..47f9b1d29 100644 --- a/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java +++ b/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/matching/MatchLocator.java @@ -534,7 +534,7 @@ protected IJavaElement createHandle(AbstractMethodDeclaration method, IJavaEleme /* orig: Argument[] arguments = method.arguments; :giro */ - Argument[] arguments = MethodSignatureEnhancer.getSourceArguments(method); + Argument[] arguments = MethodSignatureEnhancer.getSourceArguments(method, this.options.weavingScheme); // SH} int argCount = arguments == null ? 0 : arguments.length; if (type.isBinary()) { diff --git a/plugins/org.eclipse.objectteams.otdt/src/org/eclipse/objectteams/otdt/core/ext/OTDTPlugin.java b/plugins/org.eclipse.objectteams.otdt/src/org/eclipse/objectteams/otdt/core/ext/OTDTPlugin.java index bce0d77d1..8bb831121 100644 --- a/plugins/org.eclipse.objectteams.otdt/src/org/eclipse/objectteams/otdt/core/ext/OTDTPlugin.java +++ b/plugins/org.eclipse.objectteams.otdt/src/org/eclipse/objectteams/otdt/core/ext/OTDTPlugin.java @@ -1,7 +1,7 @@ /********************************************************************** * This file is part of "Object Teams Development Tooling"-Software * - * Copyright 2003, 2011 Fraunhofer Gesellschaft, Munich, Germany, + * Copyright 2003, 2014 Fraunhofer Gesellschaft, Munich, Germany, * for its Fraunhofer Institute for Computer Architecture and Software * Technology (FIRST), Berlin, Germany and Technical University Berlin, * Germany. @@ -28,7 +28,6 @@ import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; import org.eclipse.jdt.core.JavaCore; -import org.eclipse.objectteams.otdt.core.compiler.CompilerVersion; import org.eclipse.objectteams.otequinox.TransformerPlugin; import org.osgi.framework.BundleContext; @@ -251,13 +250,13 @@ public class OTDTPlugin extends Plugin public void start(BundleContext context) throws Exception { super.start(context); try { + // FIXME avoid global config but configure from CompilerOptions where needed String weavingProperty = System.getProperty("ot.weaving"); //$NON-NLS-1$ boolean useDynamicWeaving; if (weavingProperty != null) { useDynamicWeaving = "dynamic".equals(weavingProperty); } else useDynamicWeaving = TransformerPlugin.useDynamicWeaving(); - CompilerVersion.setDynamicWeaving(useDynamicWeaving); OTREContainer.findBytecodeLib(context, useDynamicWeaving); if (useDynamicWeaving) OTREContainer.OT_RUNTIME_PLUGIN = "org.eclipse.objectteams.otredyn"; //$NON-NLS-1$ diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/AbstractOTJLDTest.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/AbstractOTJLDTest.java index 4572e70c3..e974b0463 100644 --- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/AbstractOTJLDTest.java +++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/AbstractOTJLDTest.java @@ -22,8 +22,10 @@ import java.net.URL; import java.util.Map; import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; import org.eclipse.core.runtime.Platform; +import org.eclipse.jdt.core.JavaCore; import org.eclipse.jdt.core.tests.compiler.regression.AbstractComparableTest; import org.eclipse.jdt.core.tests.compiler.regression.InMemoryNameEnvironment; import org.eclipse.jdt.core.tests.compiler.regression.RegressionTestSetup; @@ -36,6 +38,10 @@ import org.eclipse.jdt.internal.compiler.batch.FileSystem; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.env.INameEnvironment; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; +import org.eclipse.objectteams.otdt.core.ext.OTDTPlugin; +import org.eclipse.objectteams.otdt.core.ext.OTREContainer; +import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.tests.ClasspathUtil; /** @@ -45,10 +51,10 @@ import org.eclipse.objectteams.otdt.tests.ClasspathUtil; public class AbstractOTJLDTest extends AbstractComparableTest { /** a test verifier that allows reusing a running vm even in the presence of (constant) vm arguments. */ - protected static class OTTestVerifier extends TestVerifier { + protected class OTTestVerifier extends TestVerifier { protected OTTestVerifier(boolean reuseVM) { super(reuseVM); - this.fVMArguments = OT_VM_ARGS; + this.fVMArguments = getOTVMArgs(); } @Override public boolean verifyClassFiles(String sourceFilePath, String className, String expectedOutputString, String expectedErrorStringStart, @@ -61,24 +67,44 @@ public class AbstractOTJLDTest extends AbstractComparableTest { return super.vmArgsEqual(mergeArgs(newArgs)); } protected String[] mergeArgs(String[] newArgs) { + String[] OTVMArgs = getOTVMArgs(); if (newArgs == null) - return OT_VM_ARGS; + return OTVMArgs; else { - int l1 = OT_VM_ARGS.length; + int l1 = OTVMArgs.length; int l2 = newArgs.length; String[] result = new String[l1+l2]; - System.arraycopy(OT_VM_ARGS, 0, result, 0, l1); + System.arraycopy(OTVMArgs, 0, result, 0, l1); System.arraycopy(newArgs, 0, result, l1, l2); return result; } } } - public static final String[] OT_VM_ARGS = new String[] { - "-javaagent:"+ClasspathUtil.OTAGENT_JAR_PATH, - "-Xbootclasspath/a:"+ClasspathUtil.OTRE_MIN_JAR_PATH, - "-Dot.dump=1" + private static String getOTDTJarPath(String jarName) { + return ClasspathUtil.OTDT_PATH + File.separator + "lib" + File.separator + jarName + ".jar"; + } + + public String[] getOTVMArgs() { + String OTRE_MIN_JAR_PATH, OTAGENT_JAR_PATH; + switch (this.weavingScheme) { + case OTDRE: + OTRE_MIN_JAR_PATH = getOTDTJarPath("otredyn_min"); + OTAGENT_JAR_PATH = getOTDTJarPath("otredyn_agent"); + break; + case OTRE: + OTRE_MIN_JAR_PATH = getOTDTJarPath("otre_min"); + OTAGENT_JAR_PATH = getOTDTJarPath("otre_agent"); + break; + default: + throw new IllegalStateException("Unsupported weavingScheme "+this.weavingScheme); + } + return new String[] { + "-javaagent:"+OTAGENT_JAR_PATH, + "-Xbootclasspath/a:"+OTRE_MIN_JAR_PATH, + "-Dot.dump=1" }; + } public static boolean IS_JRE_8; static { @@ -108,6 +134,8 @@ public class AbstractOTJLDTest extends AbstractComparableTest { // each subarray defines a set of classes to be compiled together: protected String[][] compileOrder; + protected WeavingScheme weavingScheme = WeavingScheme.OTRE; + public AbstractOTJLDTest(String name) { super(name); } @@ -128,6 +156,8 @@ public class AbstractOTJLDTest extends AbstractComparableTest { @Override public void initialize(CompilerTestSetup setUp) { super.initialize(setUp); + if ("dynamic".equals(System.getProperty("ot.weaving"))) + weavingScheme = WeavingScheme.OTDRE; if (setUp instanceof RegressionTestSetup) { RegressionTestSetup regressionSetTup = (RegressionTestSetup) setUp; if (!(regressionSetTup.verifier instanceof OTTestVerifier)) { @@ -155,6 +185,7 @@ public class AbstractOTJLDTest extends AbstractComparableTest { options.put(CompilerOptions.OPTION_ReportUnnecessaryElse, CompilerOptions.IGNORE); options.put(CompilerOptions.OPTION_ReportSyntheticAccessEmulation, CompilerOptions.IGNORE); options.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR); + options.put(CompilerOptions.OPTION_WeavingScheme, this.weavingScheme.toString()); return options; } diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/regression/DevelopmentExamples.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/regression/DevelopmentExamples.java index 21285d78d..6536889f6 100644 --- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/regression/DevelopmentExamples.java +++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/regression/DevelopmentExamples.java @@ -20,6 +20,7 @@ import java.util.Map; import org.eclipse.jdt.core.tests.util.Util; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.tests.otjld.AbstractOTJLDTest; @@ -4418,7 +4419,7 @@ public class DevelopmentExamples extends AbstractOTJLDTest { "}\n" + " \n" }, - (CallinImplementorDyn.DYNAMIC_WEAVING ? "OK" : "NO")); + (this.weavingScheme == WeavingScheme.OTDRE ? "OK" : "NO")); } // an after callin passes the base result to the team diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/roleplaying/BindingAmbiguities1.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/roleplaying/BindingAmbiguities1.java index 5f98cd2a0..09d323970 100644 --- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/roleplaying/BindingAmbiguities1.java +++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/roleplaying/BindingAmbiguities1.java @@ -20,6 +20,7 @@ package org.eclipse.objectteams.otdt.tests.otjld.roleplaying; import java.util.Map; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions.WeavingScheme; import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; import org.eclipse.objectteams.otdt.tests.otjld.AbstractOTJLDTest; @@ -1025,7 +1026,7 @@ public class BindingAmbiguities1 extends AbstractOTJLDTest { public void test731_ambiguousBinding8e() { Map options = getCompilerOptions(); options.put(CompilerOptions.OPTION_ReportMissingOverrideAnnotation, CompilerOptions.DISABLED); - boolean isOTdyn = CallinImplementorDyn.DYNAMIC_WEAVING; + boolean isOTdyn = this.weavingScheme == WeavingScheme.OTDRE; runNegativeTest( new String[] { "T731ab8e_3.java", diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/syntax/Syntax.java b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/syntax/Syntax.java index 13a524c7a..1af31f794 100644 --- a/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/syntax/Syntax.java +++ b/testplugins/org.eclipse.objectteams.otdt.tests/otjld/org/eclipse/objectteams/otdt/tests/otjld/syntax/Syntax.java @@ -31,7 +31,7 @@ public class Syntax extends AbstractOTJLDTest { // Static initializer to specify tests subset using TESTS_* static variables // All specified tests which does not belong to the class are skipped... static { - TESTS_NAMES = new String[] { "test8112_declaredLiftingSyntaxError4"}; +// TESTS_NAMES = new String[] { "test881_buggyRole3"}; // TESTS_NUMBERS = new int[] { 1459 }; // TESTS_RANGE = new int[] { 1097, -1 }; } diff --git a/testplugins/org.eclipse.objectteams.otdt.tests/src/org/eclipse/objectteams/otdt/tests/ClasspathUtil.java b/testplugins/org.eclipse.objectteams.otdt.tests/src/org/eclipse/objectteams/otdt/tests/ClasspathUtil.java index a929455b1..06e6203e6 100644 --- a/testplugins/org.eclipse.objectteams.otdt.tests/src/org/eclipse/objectteams/otdt/tests/ClasspathUtil.java +++ b/testplugins/org.eclipse.objectteams.otdt.tests/src/org/eclipse/objectteams/otdt/tests/ClasspathUtil.java @@ -16,36 +16,19 @@ **********************************************************************/ package org.eclipse.objectteams.otdt.tests; -import java.io.File; - import org.eclipse.core.runtime.IPath; import org.eclipse.jdt.core.JavaCore; import org.eclipse.objectteams.otdt.core.ext.OTDTPlugin; import org.eclipse.objectteams.otdt.core.ext.OTREContainer; -import org.eclipse.objectteams.otdt.internal.core.compiler.mappings.CallinImplementorDyn; /** Constants for the classpath of OT/J Projects.*/ public class ClasspathUtil { // === OT Paths: === - public static final String OTRE_PATH = new OTREContainer().getClasspathEntries()[0].getPath().toOSString(); public static final String OTDT_PATH = JavaCore.getClasspathVariable(OTDTPlugin.OTDT_INSTALLDIR).toOSString(); - public static final String OTRE_MIN_JAR_PATH; - public static final String OTAGENT_JAR_PATH; + public static final String OTRE_PATH = new OTREContainer().getClasspathEntries()[0].getPath().toOSString(); public static final IPath[] BYTECODE_LIB_JAR_PATH = OTREContainer.BYTECODE_LIBRARY_PATH; - - static { - if (CallinImplementorDyn.DYNAMIC_WEAVING) { - OTRE_MIN_JAR_PATH = getOTDTJarPath("otredyn_min"); - OTAGENT_JAR_PATH = getOTDTJarPath("otredyn_agent"); - } else { - OTRE_MIN_JAR_PATH = getOTDTJarPath("otre_min"); - OTAGENT_JAR_PATH = getOTDTJarPath("otre_agent"); - } - } - private static String getOTDTJarPath(String jarName) { - return OTDT_PATH + File.separator + "lib" + File.separator + jarName + ".jar"; - } + } |