diff options
author | Ed Willink | 2017-02-26 11:15:13 +0000 |
---|---|---|
committer | Ed Willink | 2017-02-28 17:41:31 +0000 |
commit | f35598e1ad9a51c9eaddb6974e4051cbcff56bc3 (patch) | |
tree | 591cf4e172589249f505a5ff8fad243a64c68d84 | |
parent | 0424bf1d865453e812616b943c6f01abb52b75c3 (diff) | |
download | org.eclipse.qvtd-f35598e1ad9a51c9eaddb6974e4051cbcff56bc3.tar.gz org.eclipse.qvtd-f35598e1ad9a51c9eaddb6974e4051cbcff56bc3.tar.xz org.eclipse.qvtd-f35598e1ad9a51c9eaddb6974e4051cbcff56bc3.zip |
[512532] Create QVTc Key functions lazily
6 files changed, 35 insertions, 40 deletions
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/AbstractQVTr2QVTcRelations.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/AbstractQVTr2QVTcRelations.java index 882313a62..b6a2c7c05 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/AbstractQVTr2QVTcRelations.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/AbstractQVTr2QVTcRelations.java @@ -438,7 +438,7 @@ import org.eclipse.qvtd.pivot.qvttemplate.TemplateExp; } for (@NonNull Variable rVariable : rEnforcedBoundVariables.keySet()) { Key rKey = qvtr2qvtc.getKeyForType(ClassUtil.nonNullState(rVariable.getType())); - variablesAnalysis.getVariableAnalysis(rVariable).setIsEnforcedBound(rEnforcedBoundVariables.get(rVariable), rKey); + variablesAnalysis.getVariableAnalysis(rVariable).setIsEnforcedBound(rEnforcedBoundVariables.get(rVariable), rEnforcedTypedModel, rKey); } for (@NonNull Variable rVariable : rEnforcedReferredVariables) { variablesAnalysis.getVariableAnalysis(rVariable).setIsEnforcedReferred(); diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/AbstractVariableAnalysis.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/AbstractVariableAnalysis.java index 935bc961f..d92d90899 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/AbstractVariableAnalysis.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/AbstractVariableAnalysis.java @@ -17,6 +17,7 @@ import org.eclipse.ocl.pivot.Property; import org.eclipse.ocl.pivot.Variable; import org.eclipse.ocl.pivot.utilities.ClassUtil; import org.eclipse.qvtd.compiler.CompilerChainException; +import org.eclipse.qvtd.pivot.qvtbase.TypedModel; import org.eclipse.qvtd.pivot.qvtcore.Area; import org.eclipse.qvtd.pivot.qvtcore.CoreDomain; import org.eclipse.qvtd.pivot.qvtrelation.Key; @@ -58,7 +59,7 @@ public abstract class AbstractVariableAnalysis implements VariableAnalysis } @Override - public void setIsEnforcedBound(@Nullable TemplateExp rTemplateExp, @Nullable Key rKey) { + public void setIsEnforcedBound(@Nullable TemplateExp rTemplateExp, @NonNull TypedModel rEnforcedTypedModel, @Nullable Key rKey) { System.out.println("Unexpected " + getClass().getSimpleName() + ".setIsEnforcedBound for " + this); } diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/QVTr2QVTc.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/QVTr2QVTc.java index c6e2cba43..f37f5b65d 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/QVTr2QVTc.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/QVTr2QVTc.java @@ -191,9 +191,9 @@ public class QVTr2QVTc extends AbstractQVTc2QVTc // private final @NonNull List<@NonNull Transformation> cTransformations = new ArrayList<@NonNull Transformation>(); /** - * Mapping from each key to its corresponding identification constructor function. + * Mapping from each key via the TYpedModel in which it is enforced to its corresponding identification constructor function. */ - private final @NonNull Map<@NonNull Key, @NonNull Function> key2function = new HashMap<>(); + private final @NonNull Map<@NonNull Key, @NonNull Map<@NonNull TypedModel, @NonNull Function>> key2typedModel2function = new HashMap<>(); /** * The Key that identifies each Class. @@ -536,8 +536,26 @@ public class QVTr2QVTc extends AbstractQVTc2QVTc return getKeyForCompleteClass(completeClass); } - /*public*/ @NonNull Function getKeyFunction(@NonNull Key key) { - return ClassUtil.nonNullState(key2function.get(key)); + /*public*/ @NonNull Function getKeyFunction(@NonNull TypedModel rTypedModel, @NonNull Key rKey) throws CompilerChainException { + Map<@NonNull TypedModel, @NonNull Function> typedModel2function = key2typedModel2function.get(rKey); + if (typedModel2function == null) { + typedModel2function = new HashMap<>(); + key2typedModel2function.put(rKey, typedModel2function); + } + Function cKeyFunction = typedModel2function.get(rTypedModel); + if (cKeyFunction == null) { + Iterable<org.eclipse.ocl.pivot.@NonNull Class> usedClasses = QVTrelationUtil.getUsedClasses(rTypedModel); + org.eclipse.ocl.pivot.@NonNull Class identifiedClass = QVTrelationUtil.getIdentifies(rKey); + assert (Iterables.contains(usedClasses, identifiedClass)); + QVTr2QVTc.SYNTHESIS.println("key " + rKey); + KeyToFunctionForIdentification keyToMapping = new KeyToFunctionForIdentification(this, rTypedModel, rKey); + cKeyFunction = keyToMapping.transform(); + getCoreTransformation(QVTrelationUtil.getContainingTransformation(rTypedModel)).getOwnedOperations().add(cKeyFunction); + // } + typedModel2function.put(rTypedModel, cKeyFunction); + // putTrace(traceClass, r); + } + return cKeyFunction; } public @NonNull Property getOclContainerProperty() { @@ -643,13 +661,6 @@ public class QVTr2QVTc extends AbstractQVTc2QVTc Variable rThis = QVTbaseUtil.getContextVariable(standardLibrary, rTransformation); // putGlobalTrace(cThis, rThis); addTrace(rThis, cThis); - List<@NonNull Key> rKeys = new ArrayList<>();//Lists.newArrayList(QVTrelationUtil.getOwnedKey(rTransformation)); - for (@Nullable Key rKey : new HashSet<>(completeClass2key.values())) { - if (rKey != null) { - rKeys.add(rKey); - } - } - Collections.sort(rKeys, QVTrelationUtil.KeyComparator.INSTANCE); UniqueArrayList<@NonNull TypedModel> rEnforceableTypedModels = new UniqueArrayList<>(); for (@NonNull Relation rRelation : rRelations) { for (@NonNull RelationDomain rDomain : QVTrelationUtil.getOwnedDomains(rRelation)) { @@ -658,19 +669,6 @@ public class QVTr2QVTc extends AbstractQVTc2QVTc } } } - for (@NonNull TypedModel rTypedModel : rEnforceableTypedModels) { - Iterable<org.eclipse.ocl.pivot.@NonNull Class> usedClasses = QVTrelationUtil.getUsedClasses(rTypedModel); - for (@NonNull Key rKey : rKeys) { - org.eclipse.ocl.pivot.@NonNull Class identifiedClass = QVTrelationUtil.getIdentifies(rKey); - if (Iterables.contains(usedClasses, identifiedClass)) { - QVTr2QVTc.SYNTHESIS.println("key " + rKey); - KeyToFunctionForIdentification keyToMapping = new KeyToFunctionForIdentification(this, rTypedModel, rKey); - Function cKeyFunction = keyToMapping.transform(); - putKeyFunction(rKey, cKeyFunction); - cTransformation.getOwnedOperations().add(cKeyFunction); - } - } - } mapQueries(rTransformation, cTransformation); for (@NonNull Relation rRelation : rRelations) { if (rRelation.isIsTopLevel()) { @@ -679,10 +677,6 @@ public class QVTr2QVTc extends AbstractQVTc2QVTc topLevelRelationToMappingForEnforcement.transform(); } } - // } - // for (@NonNull RelationalTransformation rTransformation : rTransformations) { - // List<@NonNull Rule> rules = new ArrayList<@NonNull Rule>(ClassUtil.nullFree(rTransformation.getRule())); - // Collections.sort(rules, NameUtil.NAMEABLE_COMPARATOR); for (@NonNull Relation rRelation : rRelations) { if (!rRelation.isIsTopLevel()) { InvokedRelationToMappingForEnforcement invokedRelationToMappingForEnforcement = new InvokedRelationToMappingForEnforcement(this, rRelation); @@ -731,12 +725,6 @@ public class QVTr2QVTc extends AbstractQVTc2QVTc // } } - /*public*/ void putKeyFunction(@NonNull Key rKey, @NonNull Function keyFunction) { - Function oldFunction = key2function.put(rKey, keyFunction); - assert oldFunction == null; - // putTrace(traceClass, r); - } - /*public*/ void putRelationTrace(@NonNull Relation rRelation, org.eclipse.ocl.pivot.@NonNull Class traceClass) { org.eclipse.ocl.pivot.Class oldTraceClass = relation2traceClass.put(rRelation, traceClass); assert oldTraceClass == null; diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/QVTrNameGenerator.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/QVTrNameGenerator.java index ac16c6305..bdf3dcae7 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/QVTrNameGenerator.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/QVTrNameGenerator.java @@ -34,7 +34,7 @@ public class QVTrNameGenerator public @NonNull String createKeyFunctionName(@NonNull TypedModel rTypedModel, @NonNull Key rKey) { org.eclipse.ocl.pivot.@NonNull Class identifiedClass = QVTrelationUtil.getIdentifies(rKey); - return "Key_" + QVTrelationUtil.getName(rTypedModel) + "2" + QVTrelationUtil.getName(identifiedClass); + return "Key_" + QVTrelationUtil.getName(rTypedModel) + "_" + QVTrelationUtil.getName(identifiedClass); } // public @NonNull String createKey2InstanceClassName(org.eclipse.ocl.pivot.@NonNull Class identifiedClass) { diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/RelationVariableAnalysis.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/RelationVariableAnalysis.java index 07cacca1c..8e6c6a690 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/RelationVariableAnalysis.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/RelationVariableAnalysis.java @@ -26,6 +26,7 @@ import org.eclipse.ocl.pivot.VariableExp; import org.eclipse.ocl.pivot.utilities.ClassUtil; import org.eclipse.qvtd.compiler.CompilerChainException; import org.eclipse.qvtd.pivot.qvtbase.Function; +import org.eclipse.qvtd.pivot.qvtbase.TypedModel; import org.eclipse.qvtd.pivot.qvtcore.Area; import org.eclipse.qvtd.pivot.qvtcore.Assignment; import org.eclipse.qvtd.pivot.qvtcore.BottomPattern; @@ -46,6 +47,7 @@ import org.eclipse.qvtd.pivot.qvttemplate.TemplateExp; public class RelationVariableAnalysis extends AbstractVariableAnalysis { protected final @NonNull Variable rVariable; + private @Nullable TypedModel rEnforcedTypedModel = null; private @Nullable Key rKey = null; private @Nullable TemplateExp rTemplateExp = null; private boolean isEnforcedBound = false; @@ -189,8 +191,9 @@ public class RelationVariableAnalysis extends AbstractVariableAnalysis } private void initializeKeyedVariable(@NonNull Variable cKeyedVariable) throws CompilerChainException { + TypedModel rEnforcedTypedModel2 = ClassUtil.nonNull(rEnforcedTypedModel); Key rKey2 = ClassUtil.nonNull(rKey); - Function function = variablesAnalysis.qvtr2qvtc.getKeyFunction(rKey2); + Function function = variablesAnalysis.qvtr2qvtc.getKeyFunction(rEnforcedTypedModel2, rKey2); List<@NonNull OCLExpression> asArguments = new ArrayList<@NonNull OCLExpression>(); if (rTemplateExp instanceof ObjectTemplateExp) { ObjectTemplateExp objectTemplateExp = (ObjectTemplateExp)rTemplateExp; @@ -248,13 +251,15 @@ public class RelationVariableAnalysis extends AbstractVariableAnalysis } @Override - public void setIsEnforcedBound(@Nullable TemplateExp rTemplateExp, @Nullable Key rKey) { + public void setIsEnforcedBound(@Nullable TemplateExp rTemplateExp, @NonNull TypedModel rEnforcedTypedModel, @Nullable Key rKey) { assert !isEnforcedBound; assert this.cOtherBound == null; + assert this.rEnforcedTypedModel == null; assert this.rKey == null; assert this.rTemplateExp == null; this.isEnforcedBound = true; this.rTemplateExp = rTemplateExp; + this.rEnforcedTypedModel = rEnforcedTypedModel; this.rKey = rKey; } diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/VariableAnalysis.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/VariableAnalysis.java index 05d6fb3ce..6618c0996 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/VariableAnalysis.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvtc/VariableAnalysis.java @@ -16,6 +16,7 @@ import org.eclipse.ocl.pivot.OCLExpression; import org.eclipse.ocl.pivot.Property; import org.eclipse.ocl.pivot.Variable; import org.eclipse.qvtd.compiler.CompilerChainException; +import org.eclipse.qvtd.pivot.qvtbase.TypedModel; import org.eclipse.qvtd.pivot.qvtcore.Area; import org.eclipse.qvtd.pivot.qvtcore.CoreDomain; import org.eclipse.qvtd.pivot.qvtcore.CorePattern; @@ -66,7 +67,7 @@ public interface VariableAnalysis * Accumulate the definition of this variable by rTemplateExp in an enforced domain. * If rKey is non-null the enforcement correlates with rKey. */ - void setIsEnforcedBound(@Nullable TemplateExp rTemplateExp, @Nullable Key rKey); + void setIsEnforcedBound(@Nullable TemplateExp rTemplateExp, @NonNull TypedModel rEnforcedTypedModel, @Nullable Key rKey); /** * Accumulate the references of this variable by an enforced domain. |