Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Willink2016-10-29 08:20:06 +0000
committerEd Willink2016-10-29 17:59:16 +0000
commitfb1cd06c34020dbd83256655626d0555122f8e73 (patch)
treed6f8219995ab593a833fa08aa67570f9e70cfdf8
parent0df4b4de9c9f52098c2a5004004bf5f7f3642908 (diff)
downloadorg.eclipse.qvtd-fb1cd06c34020dbd83256655626d0555122f8e73.tar.gz
org.eclipse.qvtd-fb1cd06c34020dbd83256655626d0555122f8e73.tar.xz
org.eclipse.qvtd-fb1cd06c34020dbd83256655626d0555122f8e73.zip
[506716] Simplify orderActions
-rw-r--r--plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/AbstractRegion.java27
-rw-r--r--plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/QVTp2QVTg.java137
-rw-r--r--plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/SchedulerConstants.java14
3 files changed, 68 insertions, 110 deletions
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/AbstractRegion.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/AbstractRegion.java
index 5470a3cf2..9ba696717 100644
--- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/AbstractRegion.java
+++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/AbstractRegion.java
@@ -39,9 +39,6 @@ import org.eclipse.qvtd.pivot.qvtbase.TypedModel;
import org.eclipse.qvtd.pivot.qvtbase.graphs.GraphStringBuilder;
import org.eclipse.qvtd.pivot.qvtbase.graphs.GraphStringBuilder.GraphEdge;
import org.eclipse.qvtd.pivot.qvtbase.graphs.GraphStringBuilder.GraphNode;
-import org.eclipse.qvtd.pivot.schedule.AbstractAction;
-import org.eclipse.qvtd.pivot.schedule.MappingAction;
-
import com.google.common.base.Function;
import com.google.common.base.Predicate;
import com.google.common.collect.Iterables;
@@ -1773,36 +1770,12 @@ public abstract class AbstractRegion implements Region, ToDOT.ToDOTable
return loopingConnections;
}
- public @NonNull Iterable<@NonNull MappingAction> getMappingActions() {
- return Collections.emptyList();
- }
-
- public @NonNull MappingRegion getMappingRegion(@NonNull AbstractAction action) {
- return multiRegion.getMappingRegion(action);
- }
-
@Override
public @NonNull MultiRegion getMultiRegion() {
return multiRegion;
}
@Override
- public @NonNull String getName() {
- List<@NonNull String> names = new ArrayList<@NonNull String>();
- for (@NonNull MappingAction action : getMappingActions()) {
- names.add(ClassUtil.nonNullState(action.getMapping().getName()));
- }
- Collections.sort(names);;
- StringBuilder s = new StringBuilder();
- s.append(getClass().getSimpleName());
- for (@NonNull String name : names) {
- s.append("\n");
- s.append(name);
- }
- return s.toString();
- }
-
- @Override
public final @NonNull Iterable<@NonNull Node> getNavigableNodes() {
return Iterables.filter(nodes, IsNavigableNodePredicate.INSTANCE);
}
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/QVTp2QVTg.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/QVTp2QVTg.java
index 075211d47..527d11747 100644
--- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/QVTp2QVTg.java
+++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/QVTp2QVTg.java
@@ -56,6 +56,7 @@ import org.eclipse.qvtd.pivot.qvtcore.analysis.DomainUsage;
import org.eclipse.qvtd.pivot.qvtcore.analysis.DomainUsageAnalysis;
import org.eclipse.qvtd.pivot.qvtcore.analysis.RootDomainUsageAnalysis;
import org.eclipse.qvtd.pivot.qvtcore.utilities.QVTcoreUtil;
+import org.eclipse.qvtd.pivot.schedule.AbstractAction;
import org.eclipse.qvtd.pivot.schedule.AbstractDatum;
import org.eclipse.qvtd.pivot.schedule.ClassDatum;
import org.eclipse.qvtd.pivot.schedule.DataParameter;
@@ -63,6 +64,7 @@ import org.eclipse.qvtd.pivot.schedule.MappingAction;
import org.eclipse.qvtd.pivot.schedule.PropertyDatum;
import org.eclipse.qvtd.pivot.schedule.Schedule;
import org.eclipse.qvtd.pivot.schedule.ScheduleFactory;
+import org.eclipse.qvtd.pivot.schedule.utilities.DependencyUtil;
public class QVTp2QVTg {
@@ -81,19 +83,20 @@ public class QVTp2QVTg {
return propertyDatums;
}
+ private final @NonNull RootDomainUsageAnalysis domainUsageAnalysis;
+ private final @NonNull ClassRelationships classRelationships;
private final @NonNull Schedule dg= ScheduleFactory.eINSTANCE.createSchedule();
- ;
// Caches
- private Map<@NonNull TypedModel, @NonNull Map<org.eclipse.ocl.pivot.@NonNull Class, @NonNull ClassDatum>> typedModel2class2datum = new HashMap<>();
+ private @NonNull Map<@NonNull TypedModel, @NonNull Map<org.eclipse.ocl.pivot.@NonNull Class, @NonNull ClassDatum>> typedModel2class2classDatum = new HashMap<>();
+ private @NonNull Map<@NonNull ClassDatum, @NonNull Map<@NonNull Property, @NonNull PropertyDatum>> classDatum2property2propertyDatums = new HashMap<>();
- private Map<Mapping, List<@NonNull OperationCallExp>> mapping2opCallExps = new HashMap<>();
- private Map<Mapping, List<@NonNull NavigationAssignment>> mapping2propAssigns = new HashMap<>();
- private Map<Mapping, List<@NonNull NavigationCallExp>> mapping2navCallExps = new HashMap<>();
+ private @NonNull Map<@NonNull Mapping, @NonNull List<@NonNull OperationCallExp>> mapping2opCallExps = new HashMap<>();
+ private @NonNull Map<@NonNull Mapping, @NonNull List<@NonNull NavigationAssignment>> mapping2propAssigns = new HashMap<>();
+ private @NonNull Map<@NonNull Mapping, @NonNull List<@NonNull NavigationCallExp>> mapping2navCallExps = new HashMap<>();
- private final @NonNull RootDomainUsageAnalysis domainUsageAnalysis;
- private final @NonNull ClassRelationships classRelationships;
+ private /*@LazyNonNull*/ List<@NonNull AbstractAction> orderedActions; // FIXME ??is this ordering still needed??
public QVTp2QVTg(@NonNull RootDomainUsageAnalysis domainAnalysis, @NonNull ClassRelationships classRelationships) {
this.domainUsageAnalysis = domainAnalysis;
@@ -123,13 +126,6 @@ public class QVTp2QVTg {
return true;
}
- private void clearCaches() {
- typedModel2class2datum.clear();
- mapping2opCallExps.clear();
- mapping2propAssigns.clear();
- mapping2navCallExps.clear();
- }
-
private void computeInitialCaches(@NonNull Transformation tx) {
for (Rule rule : tx.getRule()) {
Mapping mapping = (Mapping) rule;
@@ -163,16 +159,26 @@ public class QVTp2QVTg {
}
- public @NonNull Schedule transformTransformation(@NonNull Transformation pTransformation) {
- clearCaches();
+ public void analyzeTransformation(@NonNull Transformation pTransformation) {
computeInitialCaches(pTransformation);
for (@NonNull Rule pRule : ClassUtil.nullFree(pTransformation.getRule())) {
createMappingAction((Mapping) pRule);
}
- return dg;
}
- protected MappingAction createMappingAction(@NonNull Mapping mapping) {
+ public @NonNull List<@NonNull AbstractAction> getOrderedActions() {
+ List<@NonNull AbstractAction> orderedActions2 = orderedActions;
+ if (orderedActions2 == null) {
+ DependencyUtil.NaturalOrderer orderer = new DependencyUtil.NaturalOrderer(dg);
+ orderedActions2 = orderedActions = orderer.computeOrdering(); // FIXME ??is this ordering still needed??
+ if (orderedActions2 == null) {
+ throw new IllegalArgumentException(orderer.diagnoseOrderingFailure());
+ }
+ }
+ return orderedActions2;
+ }
+
+ private MappingAction createMappingAction(@NonNull Mapping mapping) {
MappingAction ma = ScheduleFactory.eINSTANCE.createMappingAction();
@@ -209,7 +215,7 @@ public class QVTp2QVTg {
return ma;
}
- protected DataParameter createDataParameter(@NonNull Variable variable) {
+ private DataParameter createDataParameter(@NonNull Variable variable) {
TypedModel typedModel = getTypedModel(variable);
DataParameter dp = ScheduleFactory.eINSTANCE.createDataParameter();
dp.setVariable(variable);
@@ -217,32 +223,27 @@ public class QVTp2QVTg {
return dp;
}
- protected @NonNull ClassDatum createClassDatum(@NonNull TypedModel typedModel, org.eclipse.ocl.pivot.@NonNull Class aClass) {
- assert assertValidTypedModel(typedModel, aClass);
- ClassDatum cDatum = ScheduleFactory.eINSTANCE.createClassDatum();
- cDatum.setSchedule(dg);
- cDatum.setType(aClass);
- cDatum.setTypedModel(typedModel);
- if (!(aClass instanceof DataType)) {
- for (@SuppressWarnings("null") org.eclipse.ocl.pivot.@NonNull Class superClass : aClass.getSuperClasses()) {
- ClassDatum superCDatum = getClassDatum(typedModel, superClass);
- cDatum.getSuper().add(superCDatum);
- }
- }
- return cDatum;
- }
-
public @NonNull ClassDatum getClassDatum(@NonNull TypedModel typedModel, org.eclipse.ocl.pivot.@NonNull Class aClass) {
assert assertValidTypedModel(typedModel, aClass);
- Map<org.eclipse.ocl.pivot.@NonNull Class, @NonNull ClassDatum> class2datum = typedModel2class2datum.get(typedModel);
- if (class2datum == null) {
- class2datum = new HashMap<>();
- typedModel2class2datum.put(typedModel, class2datum);
- }
- ClassDatum cDatum = class2datum.get(aClass);
- if (cDatum == null) {
- cDatum = createClassDatum(typedModel, aClass);
- class2datum.put(aClass, cDatum);
+ Map<org.eclipse.ocl.pivot.@NonNull Class, @NonNull ClassDatum> class2classDatums = typedModel2class2classDatum.get(typedModel);
+ if (class2classDatums == null) {
+ class2classDatums = new HashMap<>();
+ typedModel2class2classDatum.put(typedModel, class2classDatums);
+ }
+ ClassDatum classDatum = class2classDatums.get(aClass);
+ if (classDatum == null) {
+ assert assertValidTypedModel(typedModel, aClass);
+ classDatum = ScheduleFactory.eINSTANCE.createClassDatum();
+ classDatum.setSchedule(dg);
+ classDatum.setType(aClass);
+ classDatum.setTypedModel(typedModel);
+ if (!(aClass instanceof DataType)) {
+ for (@SuppressWarnings("null") org.eclipse.ocl.pivot.@NonNull Class superClass : aClass.getSuperClasses()) {
+ ClassDatum superCDatum = getClassDatum(typedModel, superClass);
+ classDatum.getSuper().add(superCDatum);
+ }
+ }
+ class2classDatums.put(aClass, classDatum);
}
/**
* Following check is useful for heterogeneous checking. assertValidTypedModel should be better once BUG 485647 is fixed.
@@ -260,38 +261,32 @@ public class QVTp2QVTg {
}
}
} */
- return cDatum;
+ return classDatum;
}
- protected @NonNull PropertyDatum createPropertyDatum(@NonNull TypedModel typedModel, org.eclipse.ocl.pivot.@NonNull Class context, Property property) {
-
- PropertyDatum pDatum = ScheduleFactory.eINSTANCE.createPropertyDatum();
+ private @NonNull PropertyDatum getPropertyDatum(@NonNull TypedModel typedModel, org.eclipse.ocl.pivot.@NonNull Class context, @NonNull Property property) {
ClassDatum classDatum = getClassDatum(typedModel, context);
- pDatum.setTypedModel(classDatum.getTypedModel());
- pDatum.setProperty(property);
- pDatum.setClassDatum(classDatum);
+ for (PropertyDatum propertyDatum : getAllPropertyDatums(classDatum)) {
+ if (propertyDatum.getProperty().equals(property)) {
+ return propertyDatum;
+ }
+ }
+ // If not found we create it
+ PropertyDatum propertyDatum = ScheduleFactory.eINSTANCE.createPropertyDatum();
+ propertyDatum.setTypedModel(typedModel);
+ propertyDatum.setProperty(property);
+ propertyDatum.setClassDatum(classDatum);
if (context != property.getOwningClass()) {
for (@SuppressWarnings("null") org.eclipse.ocl.pivot.@NonNull Class superClass : context.getSuperClasses()) {
PropertyDatum superPropDatum = getPropertyDatum(typedModel, superClass, property);
- pDatum.getSuper().add(superPropDatum);
+ propertyDatum.getSuper().add(superPropDatum);
}
}
- return pDatum;
- }
-
- protected @NonNull PropertyDatum getPropertyDatum(@NonNull TypedModel typedModel, org.eclipse.ocl.pivot.@NonNull Class context, Property property) {
- ClassDatum cDatum = getClassDatum(typedModel, context);
- for (PropertyDatum pDatum : getAllPropertyDatums(cDatum)) {
- if (pDatum.getProperty().equals(property)) {
- return pDatum;
- }
- }
- // If not found we create it
- return createPropertyDatum(typedModel, context, property);
+ return propertyDatum;
}
- protected @NonNull List<@NonNull Variable> getInputVariables(@NonNull Mapping mapping) {
+ private @NonNull List<@NonNull Variable> getInputVariables(@NonNull Mapping mapping) {
List<@NonNull Variable> mInputVars = new ArrayList<>();
mInputVars.addAll(ClassUtil.nullFree(mapping.getGuardPattern().getVariable()));
@@ -305,7 +300,7 @@ public class QVTp2QVTg {
return mInputVars;
}
- protected @NonNull List<@NonNull RealizedVariable> getOutputVariables(@NonNull Mapping mapping) {
+ private @NonNull List<@NonNull RealizedVariable> getOutputVariables(@NonNull Mapping mapping) {
List<@NonNull RealizedVariable> mOutputVars = new ArrayList<>();
mOutputVars.addAll(ClassUtil.nullFree(mapping.getBottomPattern().getRealizedVariable()));
@@ -321,28 +316,28 @@ public class QVTp2QVTg {
// Property datum analysis
- protected @NonNull List<@NonNull NavigationCallExp> getPropertyNavigations(@NonNull Mapping mapping) {
+ private @NonNull List<@NonNull NavigationCallExp> getPropertyNavigations(@NonNull Mapping mapping) {
List<@NonNull NavigationCallExp> navCallExps = mapping2navCallExps.get(mapping);
return navCallExps == null ? Collections.<@NonNull NavigationCallExp>emptyList() : navCallExps;
}
- protected @NonNull List<@NonNull NavigationAssignment> getNavigationAssignments(@NonNull Mapping mapping) {
+ private @NonNull List<@NonNull NavigationAssignment> getNavigationAssignments(@NonNull Mapping mapping) {
List<@NonNull NavigationAssignment> propAssigns = mapping2propAssigns.get(mapping);
return propAssigns == null ? Collections.<@NonNull NavigationAssignment>emptyList() : propAssigns;
}
- protected @NonNull List<@NonNull OperationCallExp> getOperationCallExps(@NonNull Mapping mapping) {
+ private @NonNull List<@NonNull OperationCallExp> getOperationCallExps(@NonNull Mapping mapping) {
List<@NonNull OperationCallExp> opCallExps = mapping2opCallExps.get(mapping);
return opCallExps == null ? Collections.<@NonNull OperationCallExp>emptyList() : opCallExps;
}
- protected @NonNull PropertyDatum getPropertyDatum(@NonNull NavigationCallExp navCallExp) {
+ private @NonNull PropertyDatum getPropertyDatum(@NonNull NavigationCallExp navCallExp) {
org.eclipse.ocl.pivot.Class context = ClassUtil.nonNullState((org.eclipse.ocl.pivot.Class) navCallExp.getOwnedSource().getType());
return getPropertyDatum(navCallExp, context );
}
- protected @NonNull PropertyDatum getPropertyDatum(@NonNull NavigationCallExp navCallExp, org.eclipse.ocl.pivot.@NonNull Class context) {
+ private @NonNull PropertyDatum getPropertyDatum(@NonNull NavigationCallExp navCallExp, org.eclipse.ocl.pivot.@NonNull Class context) {
Property property = PivotUtil.getReferredProperty(navCallExp);
OCLExpression ownedSource = navCallExp.getOwnedSource();
assert ownedSource != null;
@@ -350,7 +345,7 @@ public class QVTp2QVTg {
return getPropertyDatum(typedModel, context, property);
}
- protected @NonNull Set<@NonNull PropertyDatum> getPropertyDatum(@NonNull NavigationAssignment propAssign) {
+ private @NonNull Set<@NonNull PropertyDatum> getPropertyDatum(@NonNull NavigationAssignment propAssign) {
Set<@NonNull PropertyDatum> result = new LinkedHashSet<>();
Property targetProp = QVTcoreUtil.getTargetProperty(propAssign);
OCLExpression slotExpression = ClassUtil.nonNullState(propAssign.getSlotExpression());
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/SchedulerConstants.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/SchedulerConstants.java
index 9383484c2..391fde112 100644
--- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/SchedulerConstants.java
+++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtp2qvts/SchedulerConstants.java
@@ -51,8 +51,6 @@ import org.eclipse.qvtd.pivot.qvtcore.analysis.RootDomainUsageAnalysis;
import org.eclipse.qvtd.pivot.qvtimperative.utilities.QVTimperativeUtil;
import org.eclipse.qvtd.pivot.schedule.AbstractAction;
import org.eclipse.qvtd.pivot.schedule.ClassDatum;
-import org.eclipse.qvtd.pivot.schedule.Schedule;
-import org.eclipse.qvtd.pivot.schedule.utilities.DependencyUtil;
public abstract class SchedulerConstants
{
@@ -131,8 +129,6 @@ public abstract class SchedulerConstants
private /*@LazyNonNull */ DependencyAnalyzer dependencyAnalyzer = null;
- private final @NonNull List<@NonNull AbstractAction> orderedActions;
-
protected SchedulerConstants(@NonNull EnvironmentFactory environmentFactory, @NonNull Transformation asTransformation) {
this.environmentFactory = environmentFactory;
this.transformation = asTransformation;
@@ -140,7 +136,7 @@ public abstract class SchedulerConstants
this.domainAnalysis = new QVTcoreDomainUsageAnalysis(environmentFactory);
domainAnalysis.analyzeTransformation(asTransformation);
this.qvtp2qvtg = new QVTp2QVTg(domainAnalysis, classRelationships);
- Schedule dependencyGraph = qvtp2qvtg.transformTransformation(asTransformation);
+ qvtp2qvtg.analyzeTransformation(asTransformation);
//
this.inputUsage = domainAnalysis.getInputUsage();
// int outputMask = ((DomainUsage.Internal)domainAnalysis.getOutputUsage()).getMask();
@@ -174,12 +170,6 @@ public abstract class SchedulerConstants
assert candidateOclContainerProperty != null : "OCL Standard Librarty has no OclElement::oclContainer property";
oclContainerProperty = candidateOclContainerProperty;
//
- DependencyUtil.NaturalOrderer orderer = new DependencyUtil.NaturalOrderer(dependencyGraph);
- List<@NonNull AbstractAction> orderedActions = orderer.computeOrdering(); // FIXME ??is this ordering still needed??
- if (orderedActions == null) {
- throw new IllegalArgumentException(orderer.diagnoseOrderingFailure());
- }
- this.orderedActions = orderedActions;
}
protected abstract @NonNull ClassDatumAnalysis createClassDatumAnalysis(@NonNull ClassDatum classDatum);
@@ -339,7 +329,7 @@ public abstract class SchedulerConstants
}
protected @NonNull List<@NonNull AbstractAction> getOrderedActions() {
- return orderedActions;
+ return qvtp2qvtg.getOrderedActions();
}
public @NonNull StandardLibrary getStandardLibrary() {

Back to the top