diff options
author | Ed Willink | 2018-02-02 14:00:49 +0000 |
---|---|---|
committer | Ed Willink | 2018-04-13 11:25:37 +0000 |
commit | 7400fe1969c651fdd21275a0f2aa8be23973b583 (patch) | |
tree | b4357ba0a2bc8f6173a6040ecefd79822f7052a8 | |
parent | e71b1a6a53c44875ec6ed5d607add85473f7cd6c (diff) | |
download | org.eclipse.qvtd-7400fe1969c651fdd21275a0f2aa8be23973b583.tar.gz org.eclipse.qvtd-7400fe1969c651fdd21275a0f2aa8be23973b583.tar.xz org.eclipse.qvtd-7400fe1969c651fdd21275a0f2aa8be23973b583.zip |
[529130] Ongoing QVTr2QVTs development
16 files changed, 623 insertions, 192 deletions
diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/QVTrCompilerChain.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/QVTrCompilerChain.java index a7f53d86b..298c8344e 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/QVTrCompilerChain.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/QVTrCompilerChain.java @@ -11,19 +11,25 @@ package org.eclipse.qvtd.compiler; import java.io.IOException; +import java.util.Collection; import java.util.List; import java.util.Map; + +import org.eclipse.emf.codegen.ecore.genmodel.GenPackage; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.emf.ecore.xmi.XMLResource; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.ocl.pivot.OperationCallExp; import org.eclipse.ocl.pivot.internal.utilities.PivotUtilInternal; import org.eclipse.ocl.pivot.resource.ASResource; import org.eclipse.ocl.pivot.utilities.ClassUtil; +import org.eclipse.ocl.pivot.utilities.XMIUtil; import org.eclipse.qvtd.compiler.internal.qvtc2qvtu.QVTuConfiguration; import org.eclipse.qvtd.compiler.internal.qvtm2qvts.AbstractQVTb2QVTs; import org.eclipse.qvtd.compiler.internal.qvtm2qvts.ScheduleManager; +import org.eclipse.qvtd.compiler.internal.qvtr2qvtc.QVTr2QVTc; import org.eclipse.qvtd.compiler.internal.qvtr2qvts.QVTr2QVTs; import org.eclipse.qvtd.compiler.internal.qvts2qvts.QVTs2QVTs; import org.eclipse.qvtd.pivot.qvtbase.Transformation; @@ -55,6 +61,10 @@ public class QVTrCompilerChain extends AbstractCompilerChain if (missingOperationCallSources != null) { System.err.println("Missing OperationCallExp sources were fixed up for '" + txURI + "'"); } + boolean missingTraceArtefacts = QVTrelationUtil.rewriteMissingTraceArtefacts(environmentFactory, qvtrResource); + if (missingTraceArtefacts) { + System.err.println("Missing trace TypedModel.Class artefacts were fixed up for '" + txURI + "'"); + } checkForProxyURIs(qvtrResource); saveResource(qvtrResource); return qvtrResource; @@ -365,10 +375,71 @@ public class QVTrCompilerChain extends AbstractCompilerChain } } */ + protected static class TraceCompilerStep extends AbstractCompilerStep + { + public TraceCompilerStep(@NonNull CompilerChain compilerChain) { + super(compilerChain, TRACE_STEP); + } + + public @NonNull Resource execute(@NonNull QVTr2QVTc t) throws IOException { + CreateStrategy savedStrategy = environmentFactory.setCreateStrategy(QVTrEnvironmentFactory.CREATE_STRATEGY); + try { + URI traceURI = compilerChain.getURI(TRACE_STEP, URI_KEY); + Map<@NonNull String, @Nullable String> traceOptions = compilerChain.basicGetOption(TRACE_STEP, TRACE_OPTIONS_KEY); + String traceNsURI = traceOptions != null ? traceOptions.get(TRACE_NS_URI) : null; + Resource traceResource = createResource(PivotUtilInternal.getASURI(traceURI)); + if (traceNsURI != null) { + t.setTraceNsURI(traceNsURI); + } + // + t.transformToTracePackages(); + Map<Object, Object> saveOptions = compilerChain.basicGetOption(TRACE_STEP, SAVE_OPTIONS_KEY); + if (saveOptions == null) { + saveOptions = XMIUtil.createSaveOptions(); + } + t.saveTrace(traceResource, traceURI, traceOptions, saveOptions); + assertNoResourceSetErrors("Trace save", traceResource); + compiled(traceResource); + URI genModelURI = compilerChain.basicGetURI(GENMODEL_STEP, URI_KEY); + if (genModelURI != null) { // FIXME Move to GenModelCompilerStep once traceResource passable + saveOptions = compilerChain.basicGetOption(GENMODEL_STEP, SAVE_OPTIONS_KEY); + if (saveOptions == null) { + saveOptions = XMIUtil.createSaveOptions(); + } + saveOptions.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); + String modelDirectory = compilerChain.basicGetOption(GENMODEL_STEP, GENMODEL_MODEL_DIRECTORY_KEY); + Map<@NonNull String, @Nullable String> genmodelOptions = compilerChain.basicGetOption(GENMODEL_STEP, GENMODEL_OPTIONS_KEY); + Collection<@NonNull ? extends GenPackage> usedGenPackages = compilerChain.basicGetOption(GENMODEL_STEP, GENMODEL_USED_GENPACKAGES_KEY); + t.saveGenModel(this, traceResource, traceURI, genModelURI, modelDirectory, genmodelOptions, saveOptions, usedGenPackages); + } + return traceResource; + } + finally { + environmentFactory.setCreateStrategy(savedStrategy); + } + } + + /* protected @NonNull GenModel executeCreateGenModel(@NonNull QVTr2QVTc t, @NonNull Resource traceResource) throws IOException { + URI genModelURI = compilerChain.getURI(GENMODEL_STEP, URI_KEY); + URI traceURI = compilerChain.getURI(TRACE_STEP, URI_KEY); + Map<Object, Object> saveOptions = compilerChain.getOption(GENMODEL_STEP, SAVE_OPTIONS_KEY); + if (saveOptions == null) { + saveOptions = XMIUtil.createSaveOptions(); + } + saveOptions.put(XMLResource.OPTION_USE_ENCODED_ATTRIBUTE_STYLE, Boolean.TRUE); + String modelDirectory = compilerChain.getOption(GENMODEL_STEP, GENMODEL_MODEL_DIRECTORY_KEY); + Map<@NonNull String, @Nullable String> genmodelOptions = compilerChain.getOption(GENMODEL_STEP, GENMODEL_OPTIONS_KEY); + Collection<@NonNull ? extends GenPackage> usedGenPackages = compilerChain.getOption(GENMODEL_STEP, GENMODEL_USED_GENPACKAGES_KEY); + GenModel genModel = t.saveGenModel(this, traceResource, traceURI, genModelURI, modelDirectory, genmodelOptions, saveOptions, usedGenPackages); + return genModel; + } */ + } + protected final @NonNull Xtext2QVTrCompilerStep xtext2qvtrCompilerStep; protected final @NonNull QVTr2QVTsCompilerStep qvtr2qvtsCompilerStep; // protected final @NonNull CreateGenModelCompilerStep createGenModelCompilerStep; protected final @NonNull GenModelGenerateCompilerStep genmodelGenerateCompilerStep; + protected final @NonNull TraceCompilerStep traceCompilerStep; public QVTrCompilerChain(@NonNull QVTiEnvironmentFactory environmentFactory, @NonNull URI txURI, @NonNull URI intermediateFileNamePrefixURI, @NonNull CompilerOptions options) { super(environmentFactory, txURI, intermediateFileNamePrefixURI, options); @@ -376,6 +447,7 @@ public class QVTrCompilerChain extends AbstractCompilerChain this.qvtr2qvtsCompilerStep = createQVTr2QVTsCompilerStep(); // this.createGenModelCompilerStep = createCreateGenModelCompilerStepStep(); this.genmodelGenerateCompilerStep = createGenModelGenerateCompilerStep(); + this.traceCompilerStep = createTraceCompilerStep(); } @Override @@ -384,31 +456,32 @@ public class QVTrCompilerChain extends AbstractCompilerChain return qvtr2qvti(qvtrResource, enforcedOutputName); } - /* <<<<<<< Upstream, based on origin/ewillink/530599 - protected @NonNull ImperativeTransformation compileQVTrAS(@NonNull Resource rResource, @NonNull String enforcedOutputName) throws IOException { - // QVTr2QVTc t = new QVTr2QVTc(environmentFactory, rResource); - // t.analyze(); - // @SuppressWarnings("unused")Resource traceResource = traceCompilerStep.execute(t); - ScheduleManager scheduleManager = qvtr2qvtsCompilerStep.execute(rResource, enforcedOutputName); - // QVTuConfiguration qvtuConfiguration = createQVTuConfiguration(cResource, QVTuConfiguration.Mode.ENFORCE, enforcedOutputName); - // Resource pResource = qvtc2qvtm(cResource, qvtuConfiguration); - // ScheduledRegion rootRegion = qvtm2qvtsCompilerStep.execute(pResource); - ======= - >>>>>>> fd5dac8 [529130] Change to QVTr-to-QVTs+trace in CompilerChain - return qvts2qvtiCompilerStep.execute(scheduleManager); - } */ - - protected @NonNull ImperativeTransformation qvtr2qvti(@NonNull Resource qvtrResource, @NonNull String enforcedOutputName) throws IOException { + public @NonNull ImperativeTransformation qvtr2qvti(@NonNull Resource qvtrResource, @NonNull String enforcedOutputName) throws IOException { + QVTr2QVTc t = new QVTr2QVTc(environmentFactory, qvtrResource); + t.analyze(); + @SuppressWarnings("unused")Resource traceResource = traceCompilerStep.execute(t); URI ecoreTraceURI = getURI(TRACE_STEP, URI_KEY); URI traceURI = PivotUtilInternal.getASURI(ecoreTraceURI); - Resource traceResource = createResource(traceURI); + // Resource traceResource = createResource(traceURI); ScheduleManager scheduleManager = qvtr2qvtsCompilerStep.execute(qvtrResource, traceResource, enforcedOutputName); // createGenModelCompilerStep.execute(traceResource); return qvts2qvtiCompilerStep.execute(scheduleManager); + // ImperativeTransformation qvtr2qvti = qvtr2qvti(qvtrResource, enforcedOutputName); + // ScheduleManager scheduleManager = qvtr2qvti; + // QVTuConfiguration qvtuConfiguration = createQVTuConfiguration(cResource, QVTuConfiguration.Mode.ENFORCE, enforcedOutputName); + // Resource pResource = qvtc2qvtm(cResource, qvtuConfiguration); + // ScheduledRegion rootRegion = qvtm2qvtsCompilerStep.execute(pResource); + // ======= + // >>>>>>> fd5dac8 [529130] Change to QVTr-to-QVTs+trace in CompilerChain + // return qvts2qvtiCompilerStep.execute(scheduleManager); } - // protected @NonNull CreateGenModelCompilerStep createCreateGenModelCompilerStepStep() { - // return new CreateGenModelCompilerStep(this); + // protected @NonNull ImperativeTransformation qvtr2qvti(@NonNull Resource qvtrResource, @NonNull String enforcedOutputName) throws IOException { + // URI ecoreTraceURI = getURI(TRACE_STEP, URI_KEY); + // URI traceURI = PivotUtilInternal.getASURI(ecoreTraceURI); + // Resource traceResource = createResource(traceURI); + // // createGenModelCompilerStep.execute(traceResource); + // return qvts2qvtiCompilerStep.execute(scheduleManager); // } protected @NonNull GenModelGenerateCompilerStep createGenModelGenerateCompilerStep() { @@ -419,6 +492,10 @@ public class QVTrCompilerChain extends AbstractCompilerChain return new QVTr2QVTsCompilerStep(this); } + protected @NonNull TraceCompilerStep createTraceCompilerStep() { + return new TraceCompilerStep(this); + } + protected @NonNull Xtext2QVTrCompilerStep createXtext2QVTrCompilerStep() { return new Xtext2QVTrCompilerStep(this); } diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/AbstractScheduleManager.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/AbstractScheduleManager.java index 2b75f8961..f1b99e06b 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/AbstractScheduleManager.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/AbstractScheduleManager.java @@ -224,6 +224,12 @@ public abstract class AbstractScheduleManager implements ScheduleManager } } + public void analyzeRuleStructure() { + for (@NonNull TransformationAnalysis transformationAnalysis : transformation2transformationAnalysis.values()) { + transformationAnalysis.analyzeRuleStructure(); + } + } + @Override public void analyzeRules() { for (@NonNull TransformationAnalysis transformationAnalysis : transformation2transformationAnalysis.values()) { @@ -639,6 +645,11 @@ public abstract class AbstractScheduleManager implements ScheduleManager } @Override + public @NonNull TypedModel getTraceTypedModel() { + return domainUsageAnalysis.getTraceTypedModel(); + } + + @Override public @NonNull Iterable<@NonNull TransformationAnalysis> getTransformationAnalyses() { return transformation2transformationAnalysis.values(); } diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/ExpressionAnalyzer.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/ExpressionAnalyzer.java index 156abdb47..8f9cd6ee9 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/ExpressionAnalyzer.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/ExpressionAnalyzer.java @@ -62,11 +62,10 @@ import org.eclipse.qvtd.pivot.qvtbase.Predicate; import org.eclipse.qvtd.pivot.qvtbase.Transformation; import org.eclipse.qvtd.pivot.qvtbase.TypedModel; import org.eclipse.qvtd.pivot.qvtbase.util.AbstractExtendingQVTbaseVisitor; +import org.eclipse.qvtd.pivot.qvtbase.utilities.QVTbaseHelper; import org.eclipse.qvtd.pivot.qvtbase.utilities.QVTbaseUtil; import org.eclipse.qvtd.pivot.qvtbase.utilities.StandardLibraryHelper; import org.eclipse.qvtd.pivot.qvtcore.NavigationAssignment; -import org.eclipse.qvtd.pivot.qvtcore.utilities.QVTcoreHelper; -import org.eclipse.qvtd.pivot.qvtcore.utilities.QVTcoreUtil; import org.eclipse.qvtd.pivot.qvtschedule.RuleRegion; import org.eclipse.qvtd.pivot.qvtschedule.ClassDatum; import org.eclipse.qvtd.pivot.qvtschedule.Edge; @@ -91,7 +90,7 @@ public abstract class ExpressionAnalyzer extends AbstractExtendingQVTbaseVisitor protected final @NonNull ScheduleManager scheduleManager; protected final @NonNull EnvironmentFactory environmentFactory; - protected final @NonNull QVTcoreHelper helper; + protected final @NonNull QVTbaseHelper helper; protected final @NonNull StandardLibraryHelper standardLibraryHelper; private /*@LazyNonNull*/ ExpressionAnalyzer conditionalExpressionAnalyzer = null; // private /*@LazyNonNull*/ OperationDependencyAnalysis operationDependencyAnalysis; @@ -106,7 +105,7 @@ public abstract class ExpressionAnalyzer extends AbstractExtendingQVTbaseVisitor super(context); this.scheduleManager = context.getScheduleManager(); this.environmentFactory = scheduleManager.getEnvironmentFactory(); - this.helper = new QVTcoreHelper(environmentFactory); + this.helper = new QVTbaseHelper(environmentFactory); this.standardLibraryHelper = new StandardLibraryHelper(environmentFactory.getStandardLibrary()); // this.operationDependencyAnalysis = getOperationDependencyAnalysis(); } @@ -125,12 +124,12 @@ public abstract class ExpressionAnalyzer extends AbstractExtendingQVTbaseVisitor * For terminal operfations xxxx = yyyy.y() etc it cannot (yet). */ private @Nullable Node analyzeOperationCallExp_equals(@NonNull OperationCallExp operationCallExp) { - OCLExpression asSource = QVTcoreUtil.getOwnedSource(operationCallExp); - OCLExpression asTarget = QVTcoreUtil.getOwnedArgument(operationCallExp, 0); + OCLExpression asSource = QVTbaseUtil.getOwnedSource(operationCallExp); + OCLExpression asTarget = QVTbaseUtil.getOwnedArgument(operationCallExp, 0); Node sourceNode; Node targetNode; if (asSource instanceof VariableExp) { - VariableDeclaration referredVariable = QVTcoreUtil.getReferredVariable((VariableExp)asSource); + VariableDeclaration referredVariable = QVTbaseUtil.getReferredVariable((VariableExp)asSource); RuleRegion ruleRegion = context.getRegion(); sourceNode = ruleRegion.getNode(referredVariable); if (sourceNode != null) { @@ -150,7 +149,7 @@ public abstract class ExpressionAnalyzer extends AbstractExtendingQVTbaseVisitor } } else if (asTarget instanceof VariableExp) { - VariableDeclaration referredVariable = QVTcoreUtil.getReferredVariable((VariableExp)asTarget); + VariableDeclaration referredVariable = QVTbaseUtil.getReferredVariable((VariableExp)asTarget); RuleRegionImpl ruleRegion = (RuleRegionImpl)context.getRegion(); targetNode = ruleRegion.getNode(referredVariable); if (targetNode != null) { @@ -227,7 +226,7 @@ public abstract class ExpressionAnalyzer extends AbstractExtendingQVTbaseVisitor // if ((operationCallExp.getOwnedSource() instanceof CallExp) && sourceNode.refineClassDatumAnalysis(scheduler.getClassDatumAnalysis(operationCallExp))) { // return sourceNode; // } - Type castType = QVTcoreUtil.getType(operationCallExp); + Type castType = QVTbaseUtil.getType(operationCallExp); CompleteClass requiredClass = environmentFactory.getCompleteModel().getCompleteClass(castType); CompleteClass predicatedClass = sourceNode.getCompleteClass(); if (predicatedClass.conformsTo(requiredClass)) { @@ -291,7 +290,7 @@ public abstract class ExpressionAnalyzer extends AbstractExtendingQVTbaseVisitor } } else { - String name = QVTcoreUtil.getName(QVTcoreUtil.getReferredOperation(operationCallExp)); + String name = QVTbaseUtil.getName(QVTbaseUtil.getReferredOperation(operationCallExp)); Node argumentNode = analyze(argument); operationNode = findOperationNode(name, sourceNode, argumentNode); if (operationNode == null) { @@ -302,13 +301,13 @@ public abstract class ExpressionAnalyzer extends AbstractExtendingQVTbaseVisitor } private @NonNull Node analyzeOperationCallExp_oclContainer(@NonNull Node sourceNode, @NonNull OperationCallExp operationCallExp) { - // Type castType = QVTcoreUtil.getType(operationCallExp); + // Type castType = QVTbaseUtil.getType(operationCallExp); Property oclContainerProperty = standardLibraryHelper.getOclContainerProperty(); Edge oclContainerEdge = sourceNode.getPredicateEdge(oclContainerProperty); if (oclContainerEdge != null) { return oclContainerEdge.getEdgeTarget(); } - String name = QVTcoreUtil.getName(QVTcoreUtil.getReferredOperation(operationCallExp)); + String name = QVTbaseUtil.getName(QVTbaseUtil.getReferredOperation(operationCallExp)); Node oclContainerNode = createStepNode(name, operationCallExp, sourceNode); oclContainerEdge = createNavigationEdge(sourceNode, oclContainerProperty, oclContainerNode, false); return oclContainerNode; @@ -719,7 +718,7 @@ public abstract class ExpressionAnalyzer extends AbstractExtendingQVTbaseVisitor Variable ownedVariable = letExp.getOwnedVariable(); Node initNode = analyze(ownedVariable.getOwnedInit()); assert initNode != null; - Type type = QVTcoreUtil.getType(ownedVariable); + Type type = QVTbaseUtil.getType(ownedVariable); CompleteClass actualClass = initNode.getCompleteClass(); ClassDatum classDatum = scheduleManager.getClassDatum(ownedVariable); CompleteClass requiredClass = QVTscheduleUtil.getCompleteClass(classDatum); @@ -751,16 +750,16 @@ public abstract class ExpressionAnalyzer extends AbstractExtendingQVTbaseVisitor for (@NonNull Variable iterator : ownedIterators) { Node iteratorNode = createIteratorNode(iterator, sourceNode); @SuppressWarnings("unused") - Type iteratorType = QVTcoreUtil.getType(iterator); + Type iteratorType = QVTbaseUtil.getType(iterator); // Property iterateProperty = context.getScheduleModel().getIterateProperty(iteratorType); createIteratedEdge(sourceNode, QVTscheduleConstants.LOOP_ITERATOR_NAME, iteratorNode); argNodes[i++] = iteratorNode; } if (loopExp instanceof IterateExp) { - Variable accumulator = QVTcoreUtil.getOwnedResult((IterateExp)loopExp); + Variable accumulator = QVTbaseUtil.getOwnedResult((IterateExp)loopExp); Node iteratorNode = createIteratorNode(accumulator, sourceNode); @SuppressWarnings("unused") - Type iteratorType = QVTcoreUtil.getType(accumulator); + Type iteratorType = QVTbaseUtil.getType(accumulator); // Property iterateProperty = context.getScheduleModel().getIterateProperty(iteratorType); createIteratedEdge(sourceNode, QVTscheduleConstants.LOOP_ITERATOR_NAME, iteratorNode); argNodes[i++] = iteratorNode; @@ -793,7 +792,7 @@ public abstract class ExpressionAnalyzer extends AbstractExtendingQVTbaseVisitor @Override public @NonNull Node visitMapLiteralPart(@NonNull MapLiteralPart mapLiteralPart) { - OCLExpression ownedValue = QVTcoreUtil.getOwnedValue(mapLiteralPart); + OCLExpression ownedValue = QVTbaseUtil.getOwnedValue(mapLiteralPart); Node keyNode = analyze(mapLiteralPart.getOwnedKey()); Node valueNode = analyze(ownedValue); Node operationNode = createConnectedOperationNode("Part", mapArgNames, ownedValue, keyNode, valueNode); @@ -804,7 +803,7 @@ public abstract class ExpressionAnalyzer extends AbstractExtendingQVTbaseVisitor public @NonNull Node visitNavigationCallExp(@NonNull NavigationCallExp navigationCallExp) { assert !navigationCallExp.isIsSafe(); Property referredProperty = PivotUtil.getReferredProperty(navigationCallExp); - OCLExpression ownedSource = QVTcoreUtil.getOwnedSource(navigationCallExp); + OCLExpression ownedSource = QVTbaseUtil.getOwnedSource(navigationCallExp); Node sourceNode = analyze(ownedSource); if (sourceNode.isClass()) { if (!referredProperty.isIsMany()) { @@ -815,9 +814,9 @@ public abstract class ExpressionAnalyzer extends AbstractExtendingQVTbaseVisitor } String name = CompilerUtil.recoverVariableName(navigationCallExp); if (name == null) { - name = QVTcoreUtil.getName(referredProperty); + name = QVTbaseUtil.getName(referredProperty); } - Type type = QVTcoreUtil.getType(referredProperty); + Type type = QVTbaseUtil.getType(referredProperty); Node targetNode = expression2knownNode != null ? expression2knownNode.get(navigationCallExp) : null; if (targetNode == null) { if (type instanceof DataType) { @@ -1005,7 +1004,7 @@ public abstract class ExpressionAnalyzer extends AbstractExtendingQVTbaseVisitor @Override public @NonNull Node visitTypeExp(@NonNull TypeExp typeExp) { DomainUsage domainUsage = scheduleManager.getDomainUsage(typeExp); - Type referredType = QVTcoreUtil.getReferredType(typeExp); + Type referredType = QVTbaseUtil.getReferredType(typeExp); TypedModel typedModel = domainUsage.getTypedModel(typeExp); assert typedModel != null; ClassDatum classDatum = scheduleManager.getClassDatum(typedModel, (org.eclipse.ocl.pivot.Class)referredType); @@ -1016,7 +1015,7 @@ public abstract class ExpressionAnalyzer extends AbstractExtendingQVTbaseVisitor @Override public @NonNull Node visitVariableExp(@NonNull VariableExp variableExp) { - VariableDeclaration referredVariable = QVTcoreUtil.getReferredVariable(variableExp); + VariableDeclaration referredVariable = QVTbaseUtil.getReferredVariable(variableExp); return context.getReferenceNode(referredVariable); } }
\ No newline at end of file diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/QVTcoreScheduleManager.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/QVTcoreScheduleManager.java index 3b40d299a..84366717f 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/QVTcoreScheduleManager.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/QVTcoreScheduleManager.java @@ -79,6 +79,16 @@ public class QVTcoreScheduleManager extends AbstractScheduleManager } @Override + public boolean isInput(@NonNull Domain domain) { + return domain.isIsCheckable(); + } + + @Override + public boolean isOutput(@NonNull Domain domain) { + return domain.isIsEnforceable(); + } + + @Override public boolean isTopLevel(@NonNull Rule rule) { throw new UnsupportedOperationException(); } diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/RegionHelper.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/RegionHelper.java index fe932e341..dd4cef26b 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/RegionHelper.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/RegionHelper.java @@ -274,13 +274,19 @@ public class RegionHelper<R extends Region> extends QVTscheduleUtil implements N return edge; } - public @NonNull Node createPredicatedStepNode(@NonNull Node typedNode, boolean isMatched) { + public @NonNull Node createPredicatedNode(@NonNull String name, @NonNull ClassDatum classDatum, boolean isMatched) { PatternTypedNode node = QVTscheduleFactory.eINSTANCE.createPatternTypedNode(); - node.initialize(Role.PREDICATED, region, getName(typedNode), getClassDatum(typedNode)); + node.initialize(Role.PREDICATED, region, name, classDatum); node.setMatched(isMatched); return node; } + public @NonNull Node createPredicatedStepNode(@NonNull Node typedNode, boolean isMatched) { + String name = getName(typedNode); + ClassDatum classDatum = getClassDatum(typedNode); + return createPredicatedNode(name, classDatum, isMatched); + } + public @NonNull Node createRealizedDataTypeNode(@NonNull Node sourceNode, @NonNull Property source2targetProperty) { Role nodeRole = Role.REALIZED; return createPatternNode(nodeRole, sourceNode, source2targetProperty, sourceNode.isMatched()); @@ -301,12 +307,16 @@ public class RegionHelper<R extends Region> extends QVTscheduleUtil implements N return forwardEdge; } - public @NonNull VariableNode createRealizedStepNode(@NonNull VariableDeclaration stepVariable) { - Role nodeRole = Role.REALIZED; + public @NonNull VariableNode createRealizedNode(@NonNull String name, @NonNull ClassDatum classDatum, boolean isMatched) { PatternVariableNode node = QVTscheduleFactory.eINSTANCE.createPatternVariableNode(); - node.initialize(nodeRole, region, getName(stepVariable), scheduleManager.getClassDatum(stepVariable)); + node.initialize(Role.REALIZED, region, name, classDatum); + node.setMatched(isMatched); + return node; + } + + public @NonNull VariableNode createRealizedStepNode(@NonNull VariableDeclaration stepVariable) { + VariableNode node = createRealizedNode(getName(stepVariable), scheduleManager.getClassDatum(stepVariable), true); node.initializeVariable(region, stepVariable); - node.setMatched(true); return node; } diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/RuleAnalysis.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/RuleAnalysis.java index f557824ac..69e0942c8 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/RuleAnalysis.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/RuleAnalysis.java @@ -51,6 +51,8 @@ public abstract class RuleAnalysis extends RegionHelper<@NonNull RuleRegion> public abstract void analyze(); + public void analyzeStructure() {} + public @NonNull Node createDependencyHead(@NonNull ClassDatum classDatum) { if (dependencyHeadNodes == null) { dependencyHeadNodes = new ArrayList<>(); diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/ScheduleManager.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/ScheduleManager.java index 0e1cae542..49e945ea7 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/ScheduleManager.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/ScheduleManager.java @@ -100,6 +100,7 @@ public interface ScheduleManager @NonNull StandardLibraryHelper getStandardLibraryHelper(); @NonNull PropertyDatum getSuccessPropertyDatum(@NonNull Property successProperty); @NonNull Iterable<@NonNull ClassDatum> getSuperClassDatums(@NonNull ClassDatum classDatum); + @NonNull TypedModel getTraceTypedModel(); @NonNull Iterable<@NonNull TransformationAnalysis> getTransformationAnalyses(); @NonNull TransformationAnalysis getTransformationAnalysis(@NonNull Transformation transformation); @NonNull TransformationAnalysis2TracePackage getTransformationAnalysis2TracePackage(@NonNull TransformationAnalysis transformationAnalysis); @@ -115,12 +116,23 @@ public interface ScheduleManager boolean isElementallyConformantSource(@NonNull NavigableEdge thatEdge, @NonNull NavigableEdge thisEdge); /** + * Return true if domain is an input domain. + */ + boolean isInput(@NonNull Domain domain); + + /** * Return true if node is part of the middle (traced) domain. */ boolean isMiddle(@NonNull Node node); boolean isNoEarlyMerge(); boolean isNoLateConsumerMerge(); + + /** + * Return true if domain is an output domain. + */ + boolean isOutput(@NonNull Domain domain); + boolean isTopLevel(@NonNull Rule rule); void setScheduledRegion(@NonNull MappingRegion mappingRegion, @Nullable ScheduledRegion scheduledRegion); void writeDebugGraphs(@NonNull Region region, @Nullable String context); diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/TransformationAnalysis.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/TransformationAnalysis.java index cb7cba071..11b30042f 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/TransformationAnalysis.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtm2qvts/TransformationAnalysis.java @@ -69,6 +69,12 @@ public class TransformationAnalysis extends QVTbaseHelper implements Nameable } } + public void analyzeRuleStructure() { + for (@NonNull RuleAnalysis ruleAnalysis : rule2ruleAnalysis.values()) { + ruleAnalysis.analyzeStructure(); + } + } + public void analyzeRules() { // for (@NonNull RuleAnalysis ruleAnalysis : rule2ruleAnalysis.values()) { // FIXME testOCL2QVTi_Source2Target_Interpreted fails on 'random' order for (@NonNull Rule asRule : QVTbaseUtil.getOwnedRules(transformation)) { 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 f0c7cd580..c77652f62 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 @@ -12,6 +12,7 @@ package org.eclipse.qvtd.compiler.internal.qvtr2qvtc; import java.io.IOException; import java.util.ArrayList; +import java.util.Collection; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; @@ -20,28 +21,40 @@ import java.util.List; import java.util.Map; import java.util.Set; +import org.eclipse.emf.codegen.ecore.genmodel.GenJDKLevel; import org.eclipse.emf.codegen.ecore.genmodel.GenModel; +import org.eclipse.emf.codegen.ecore.genmodel.GenModelFactory; import org.eclipse.emf.codegen.ecore.genmodel.GenPackage; import org.eclipse.emf.common.util.TreeIterator; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.EPackage; +import org.eclipse.emf.ecore.impl.MinimalEObjectImpl; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.emf.ecore.xmi.XMLResource; +import org.eclipse.emf.importer.ecore.EcoreImporter; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.ocl.examples.codegen.dynamic.JavaFileUtil; +import org.eclipse.ocl.pivot.CollectionType; import org.eclipse.ocl.pivot.Element; import org.eclipse.ocl.pivot.Import; import org.eclipse.ocl.pivot.Model; +import org.eclipse.ocl.pivot.Namespace; import org.eclipse.ocl.pivot.PivotFactory; import org.eclipse.ocl.pivot.Property; import org.eclipse.ocl.pivot.StandardLibrary; +import org.eclipse.ocl.pivot.Type; import org.eclipse.ocl.pivot.internal.ecore.as2es.AS2Ecore; import org.eclipse.ocl.pivot.internal.utilities.EnvironmentFactoryInternal; +import org.eclipse.ocl.pivot.util.DerivedConstants; import org.eclipse.ocl.pivot.utilities.ClassUtil; import org.eclipse.ocl.pivot.utilities.EnvironmentFactory; import org.eclipse.ocl.pivot.utilities.NameUtil; import org.eclipse.ocl.pivot.utilities.TracingOption; +import org.eclipse.ocl.pivot.utilities.TreeIterable; +import org.eclipse.qvtd.compiler.CompilerChain; import org.eclipse.qvtd.compiler.CompilerChainException; import org.eclipse.qvtd.compiler.CompilerConstants; import org.eclipse.qvtd.compiler.ProblemHandler; @@ -361,7 +374,6 @@ public class QVTr2QVTc extends AbstractQVTc2QVTc asResource.save(options); } - /*<<<<<<< Upstream, based on origin/ewillink/530599 public @NonNull GenModel saveGenModel(@NonNull ProblemHandler problemHandler, @NonNull Resource asResource, @NonNull URI traceURI, @NonNull URI genModelURI, @Nullable String modelDirectory, @Nullable Map<@NonNull String, @Nullable String> genModelOptions, @NonNull Map<Object, Object> saveOptions2, @Nullable Collection<@NonNull ? extends GenPackage> usedGenPackages) throws IOException { URI trimFileExtension = traceURI.trimFileExtension(); String projectName = getProjectName(traceURI); @@ -478,7 +490,7 @@ public class QVTr2QVTc extends AbstractQVTc2QVTc saveOptions.put(Resource.OPTION_LINE_DELIMITER, Resource.OPTION_LINE_DELIMITER_UNSPECIFIED); genmodelResource.save(saveOptions); return genModel; - } */ + } public @NonNull Resource saveTrace(@NonNull Resource asResource, @NonNull URI traceURI, @Nullable Map<@NonNull String, @Nullable String> traceOptions, @NonNull Map<?, ?> saveOptions) throws IOException { // public @NonNull Resource saveTrace(@NonNull Resource asResource, @NonNull URI traceURI, @NonNull URI genModelURI, @Nullable Map<@NonNull String, @Nullable String> traceOptions, @NonNull Map<?, ?> saveOptions) throws IOException { diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/AbstractQVTrelationExpressionAnalyzer.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/AbstractQVTrelationExpressionAnalyzer.java new file mode 100644 index 000000000..5ff158a51 --- /dev/null +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/AbstractQVTrelationExpressionAnalyzer.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * Copyright (c) 2018 Willink Transformations and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * E.D.Willink - Initial API and implementation + */ +package org.eclipse.qvtd.compiler.internal.qvtr2qvts; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.qvtd.compiler.internal.qvtm2qvts.ExpressionAnalyzer; +import org.eclipse.qvtd.pivot.qvtrelation.util.QVTrelationVisitor; +import org.eclipse.qvtd.pivot.qvtschedule.Node; + +public abstract class AbstractQVTrelationExpressionAnalyzer extends ExpressionAnalyzer implements QVTrelationVisitor<@Nullable Node> +{ + protected AbstractQVTrelationExpressionAnalyzer(@NonNull RelationAnalysis context) { + super(context); + } + + @Override + public @Nullable Node visitCollectionTemplateExp(org.eclipse.qvtd.pivot.qvttemplate.@NonNull CollectionTemplateExp object) { + return visitTemplateExp(object); + } + + @Override + public @Nullable Node visitObjectTemplateExp(org.eclipse.qvtd.pivot.qvttemplate.@NonNull ObjectTemplateExp object) { + return visitTemplateExp(object); + } + + @Override + public @Nullable Node visitPropertyTemplateItem(org.eclipse.qvtd.pivot.qvttemplate.@NonNull PropertyTemplateItem object) { + return visitElement(object); + } + + @Override + public @Nullable Node visitTemplateExp(org.eclipse.qvtd.pivot.qvttemplate.@NonNull TemplateExp object) { + return visitLiteralExp(object); + } + + @Override + public @Nullable Node visitDomainPattern(org.eclipse.qvtd.pivot.qvtrelation.@NonNull DomainPattern object) { + return visitPattern(object); + } + + @Override + public @Nullable Node visitKey(org.eclipse.qvtd.pivot.qvtrelation.@NonNull Key object) { + return visitElement(object); + } + + @Override + public @Nullable Node visitRelation(org.eclipse.qvtd.pivot.qvtrelation.@NonNull Relation object) { + return visitRule(object); + } + + @Override + public @Nullable Node visitRelationCallExp(org.eclipse.qvtd.pivot.qvtrelation.@NonNull RelationCallExp object) { + return visitOCLExpression(object); + } + + @Override + public @Nullable Node visitRelationDomain(org.eclipse.qvtd.pivot.qvtrelation.@NonNull RelationDomain object) { + return visitDomain(object); + } + + @Override + public @Nullable Node visitRelationDomainAssignment(org.eclipse.qvtd.pivot.qvtrelation.@NonNull RelationDomainAssignment object) { + return visitElement(object); + } + + @Override + public @Nullable Node visitRelationImplementation(org.eclipse.qvtd.pivot.qvtrelation.@NonNull RelationImplementation object) { + return visitElement(object); + } + + @Override + public @Nullable Node visitRelationModel(org.eclipse.qvtd.pivot.qvtrelation.@NonNull RelationModel object) { + return visitBaseModel(object); + } + + @Override + public @Nullable Node visitRelationalTransformation(org.eclipse.qvtd.pivot.qvtrelation.@NonNull RelationalTransformation object) { + return visitTransformation(object); + } + + @Override + public @Nullable Node visitSharedVariable(org.eclipse.qvtd.pivot.qvtrelation.@NonNull SharedVariable object) { + return visitVariable(object); + } + + @Override + public @Nullable Node visitTemplateVariable(org.eclipse.qvtd.pivot.qvtrelation.@NonNull TemplateVariable object) { + return visitVariable(object); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/QVTr2QVTs.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/QVTr2QVTs.java index cc58f034c..f6d18685f 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/QVTr2QVTs.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/QVTr2QVTs.java @@ -217,9 +217,9 @@ public class QVTr2QVTs extends AbstractQVTb2QVTs context.pushScope(rOut); context.addTrace(rIn, rOut); for (@NonNull VariableDeclaration vIn : QVTrelationUtil.getOwnedVariables(rIn)) { - if (!QVTrelationUtil.isTraceClassVariable(vIn)) { - relationAnalysis.analyzeVariableDeclaration(vIn); - } + // if (!QVTrelationUtil.isTraceClassVariable(vIn)) { + relationAnalysis.analyzeVariableDeclaration(vIn); + // } } Pattern whenIn = rIn.getWhen(); if (whenIn != null) { @@ -467,9 +467,11 @@ public class QVTr2QVTs extends AbstractQVTb2QVTs // } public void transform(@NonNull Resource source, @NonNull Resource target, @Nullable String traceNsURI, @NonNull Resource traceResource) throws IOException { + QVTrelationScheduleManager scheduleManager2 = getScheduleManager(); debugSource = source; debugTarget = target; - scheduleManager.analyzeUsages(); + scheduleManager2.analyzeUsages(); + scheduleManager2.analyzeRuleStructure(); // // Do the transformation for each CoreModel. First a createVisitor descent of the input, then an updateVisitor descent of the output. // @@ -492,17 +494,17 @@ public class QVTr2QVTs extends AbstractQVTb2QVTs } } } - scheduleManager.analyzeRules(); + scheduleManager2.analyzeRules(); Model traceModel = PivotFactory.eINSTANCE.createModel(); traceModel.setExternalURI(traceResource.getURI().toString()); traceResource.getContents().add(traceModel); - for (@NonNull TransformationAnalysis transformationAnalysis : scheduleManager.getTransformationAnalyses()) { + for (@NonNull TransformationAnalysis transformationAnalysis : scheduleManager2.getTransformationAnalyses()) { if (AbstractQVTb2QVTs.DEBUG_GRAPHS.isActive()) { for (@NonNull RuleAnalysis ruleAnalysis : transformationAnalysis.getRuleAnalyses()) { - scheduleManager.writeDebugGraphs(ruleAnalysis.getRegion(), null); + scheduleManager2.writeDebugGraphs(ruleAnalysis.getRegion(), null); } } - QVTrelationDomainUsageAnalysis domainUsageAnalysis = getScheduleManager().getDomainUsageAnalysis(); + QVTrelationDomainUsageAnalysis domainUsageAnalysis = scheduleManager2.getDomainUsageAnalysis(); TypedModel traceTypedModel = domainUsageAnalysis.getTraceTypedModel(); transformationAnalysis.synthesizeTracePackage(traceTypedModel, traceModel); List<@NonNull RuleAnalysis> ruleAnalyses = Lists.newArrayList(transformationAnalysis.getRuleAnalyses()); @@ -512,12 +514,12 @@ public class QVTr2QVTs extends AbstractQVTb2QVTs } if (AbstractQVTb2QVTs.DEBUG_GRAPHS.isActive()) { for (@NonNull RuleAnalysis ruleAnalysis : ruleAnalyses) { - scheduleManager.writeDebugGraphs(ruleAnalysis.getRegion(), null); + scheduleManager2.writeDebugGraphs(ruleAnalysis.getRegion(), null); } } } if (QVTm2QVTs.DEBUG_GRAPHS.isActive()) { - scheduleManager.writeDebugGraphs("0-init", true, true, true); + scheduleManager2.writeDebugGraphs("0-init", true, true, true); } // // Debug code to confirm that every output object is traceable to some input object. @@ -540,6 +542,6 @@ public class QVTr2QVTs extends AbstractQVTb2QVTs if (missingTraceArtefacts) { System.err.println("Missing trace TypedModel.Class artefacts were fixed up for '" + target.getURI() + "'"); } - scheduleManager.analyzeTransformations(); + scheduleManager2.analyzeTransformations(); } } diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/QVTrelationExpressionAnalyzer.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/QVTrelationExpressionAnalyzer.java new file mode 100644 index 000000000..d5c437ced --- /dev/null +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/QVTrelationExpressionAnalyzer.java @@ -0,0 +1,115 @@ +/******************************************************************************* + * Copyright (c) 2015, 2018 Willink Transformations and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * E.D.Willink - Initial API and implementation + *******************************************************************************/ +package org.eclipse.qvtd.compiler.internal.qvtr2qvts; + +import java.util.List; + +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.ocl.pivot.CallExp; +import org.eclipse.ocl.pivot.OCLExpression; +import org.eclipse.ocl.pivot.Variable; +import org.eclipse.ocl.pivot.VariableDeclaration; +import org.eclipse.qvtd.compiler.internal.qvtm2qvts.ExpressionAnalyzer; +import org.eclipse.qvtd.compiler.internal.qvtr2qvts.RelationAnalysis.InvocationAnalysis; +import org.eclipse.qvtd.compiler.internal.qvts2trace.NameGenerator; +import org.eclipse.qvtd.compiler.internal.qvts2trace.RuleAnalysis2TraceClass; +import org.eclipse.qvtd.pivot.qvtbase.Pattern; +import org.eclipse.qvtd.pivot.qvtbase.TypedModel; +import org.eclipse.qvtd.pivot.qvtrelation.Relation; +import org.eclipse.qvtd.pivot.qvtrelation.RelationCallExp; +import org.eclipse.qvtd.pivot.qvtrelation.utilities.QVTrelationUtil; +import org.eclipse.qvtd.pivot.qvtschedule.ClassDatum; +import org.eclipse.qvtd.pivot.qvtschedule.Node; +import org.eclipse.qvtd.pivot.qvttemplate.TemplateExp; + +public class QVTrelationExpressionAnalyzer extends AbstractQVTrelationExpressionAnalyzer +{ + public static class ConditionalExpressionAnalyzer extends QVTrelationExpressionAnalyzer + { + protected ConditionalExpressionAnalyzer(@NonNull RelationAnalysis context) { + super(context); + } + + @Override + protected @NonNull Node createStepNode(@NonNull String name, @NonNull CallExp callExp, @NonNull Node sourceNode) { + return context.createStepNode(name, callExp, sourceNode, false); + } + + @Override + protected boolean isUnconditional() { + return false; + } + } + + protected QVTrelationExpressionAnalyzer(@NonNull RelationAnalysis context) { + super(context); + } + + @Override + protected @NonNull ExpressionAnalyzer createConditionalExpressionAnalyzer() { + return new ConditionalExpressionAnalyzer(getRelationAnalysis()); + } + + public @NonNull RelationAnalysis getRelationAnalysis() { + return (RelationAnalysis)context; + } + + @Override + public @Nullable Node visitRelationCallExp(@NonNull RelationCallExp relationCallExp) { + RelationAnalysis relationAnalysis = getRelationAnalysis(); + Relation relation = relationAnalysis.getRule(); + boolean isWhen = false; + Pattern containingPattern = QVTrelationUtil.basicGetContainingPattern(relationCallExp); + if (containingPattern !=null) { + if (relation.getWhen() == containingPattern) { + isWhen = true; + } + } + Relation referredRelation = QVTrelationUtil.getReferredRelation(relationCallExp); + RuleAnalysis2TraceClass referredRuleAnalysis2TraceClass = context.getTransformationAnalysis2TracePackage().getRuleAnalysis2TraceClass(referredRelation); + org.eclipse.ocl.pivot.Class invocationInterface = referredRuleAnalysis2TraceClass.getInvocationInterface(); + NameGenerator nameGenerator = context.getNameGenerator(); + String name = isWhen ? nameGenerator.createWhenInvocationPropertyName(referredRelation) + : nameGenerator.createWhereInvocationPropertyName(referredRelation); + TypedModel traceTypedModel = scheduleManager.getTraceTypedModel(); + ClassDatum classDatum = scheduleManager.getClassDatum(traceTypedModel, invocationInterface); + Node invokedNode; + if (isWhen) { + invokedNode = context.createPredicatedNode(name, classDatum, true); + } + else { + invokedNode = context.createRealizedNode(name, classDatum, true); + } + // + InvocationAnalysis invocationAnalysis = relationAnalysis.createInvocationAnalysis(referredRuleAnalysis2TraceClass, relationCallExp, invokedNode, isWhen); + List<@NonNull Variable> rootVariables = QVTrelationUtil.getRootVariables(referredRelation); + List<@NonNull OCLExpression> ownedArguments = QVTrelationUtil.Internal.getOwnedArgumentsList(relationCallExp); + int size = rootVariables.size(); + assert size == ownedArguments.size(); + for (int i = 0; i < size; i++) { + VariableDeclaration rootVariable = rootVariables.get(i); + OCLExpression ownedArgument = ownedArguments.get(i); + Node argumentNode = ownedArgument.accept(this); + assert argumentNode != null; + invocationAnalysis.add(rootVariable, argumentNode); + } + // for () + // if (referredRuleAnalysis2TraceClass.getStatusInterfaceProperty()) + return null; + } + + @Override + public @Nullable Node visitTemplateExp(@NonNull TemplateExp templateExp) { + VariableDeclaration referredVariable = QVTrelationUtil.getBindsTo(templateExp); + return context.getReferenceNode(referredVariable); + } +}
\ No newline at end of file diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/QVTrelationScheduleManager.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/QVTrelationScheduleManager.java index 576599ab4..cc57c6690 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/QVTrelationScheduleManager.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/QVTrelationScheduleManager.java @@ -26,7 +26,6 @@ import org.eclipse.qvtd.compiler.internal.qvtm2qvts.ExpressionAnalyzer; import org.eclipse.qvtd.compiler.internal.qvtm2qvts.RuleAnalysis; import org.eclipse.qvtd.compiler.internal.qvtm2qvts.TransformationAnalysis; import org.eclipse.qvtd.compiler.internal.qvtr2qvtc.analysis.QVTrelationDomainUsageAnalysis; -import org.eclipse.qvtd.compiler.internal.qvtr2qvts.RelationAnalysis.QVTrelationExpressionAnalyzer; import org.eclipse.qvtd.pivot.qvtbase.Domain; import org.eclipse.qvtd.pivot.qvtbase.Rule; import org.eclipse.qvtd.pivot.qvtbase.TypedModel; @@ -67,7 +66,7 @@ public class QVTrelationScheduleManager extends AbstractScheduleManager @Override public @NonNull ExpressionAnalyzer createExpressionAnalyzer(@NonNull RuleAnalysis ruleAnalysis) { - return new QVTrelationExpressionAnalyzer(ruleAnalysis); + return new QVTrelationExpressionAnalyzer((RelationAnalysis) ruleAnalysis); } @Override @@ -75,6 +74,7 @@ public class QVTrelationScheduleManager extends AbstractScheduleManager RuleRegion ruleRegion = QVTscheduleFactory.eINSTANCE.createRuleRegion(); ruleRegion.setOwningScheduleModel(scheduleModel); ruleRegion.setReferredRule(asRule); + ruleRegion.setName(nameGenerator.createMappingName((Relation) asRule, qvtuConfiguration)); return new RelationAnalysis(transformationAnalysis, qvtuConfiguration, ruleRegion); } @@ -104,6 +104,16 @@ public class QVTrelationScheduleManager extends AbstractScheduleManager } @Override + public boolean isInput(@NonNull Domain domain) { + return qvtuConfiguration.isInput(QVTrelationUtil.getTypedModel(domain)); + } + + @Override + public boolean isOutput(@NonNull Domain domain) { + return qvtuConfiguration.isOutput(QVTrelationUtil.getTypedModel(domain)); + } + + @Override public boolean isTopLevel(@NonNull Rule rule) { return ((Relation)rule).isIsTopLevel(); } diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/RelationAnalysis.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/RelationAnalysis.java index 3e33841e2..b184b9124 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/RelationAnalysis.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvtr2qvts/RelationAnalysis.java @@ -19,16 +19,15 @@ import java.util.Set; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; -import org.eclipse.ocl.pivot.CallExp; import org.eclipse.ocl.pivot.CompleteClass; import org.eclipse.ocl.pivot.OCLExpression; import org.eclipse.ocl.pivot.Property; import org.eclipse.ocl.pivot.Variable; import org.eclipse.ocl.pivot.VariableDeclaration; +import org.eclipse.ocl.pivot.VariableExp; import org.eclipse.ocl.pivot.utilities.NameUtil; import org.eclipse.ocl.pivot.utilities.PivotUtil; import org.eclipse.qvtd.compiler.internal.qvtc2qvtu.QVTuConfiguration; -import org.eclipse.qvtd.compiler.internal.qvtm2qvts.ExpressionAnalyzer; import org.eclipse.qvtd.compiler.internal.qvtm2qvts.MappingRegionAnalysis; import org.eclipse.qvtd.compiler.internal.qvtm2qvts.RuleAnalysis; import org.eclipse.qvtd.compiler.internal.qvtm2qvts.TransformationAnalysis; @@ -37,24 +36,64 @@ import org.eclipse.qvtd.compiler.internal.qvts2trace.VariableDeclaration2TracePr import org.eclipse.qvtd.pivot.qvtbase.Pattern; import org.eclipse.qvtd.pivot.qvtbase.Predicate; import org.eclipse.qvtd.pivot.qvtbase.TypedModel; +import org.eclipse.qvtd.pivot.qvtrelation.DomainPattern; import org.eclipse.qvtd.pivot.qvtrelation.Relation; import org.eclipse.qvtd.pivot.qvtrelation.RelationCallExp; -import org.eclipse.qvtd.pivot.qvtrelation.util.QVTrelationVisitor; +import org.eclipse.qvtd.pivot.qvtrelation.RelationDomain; import org.eclipse.qvtd.pivot.qvtrelation.utilities.QVTrelationUtil; import org.eclipse.qvtd.pivot.qvtschedule.RuleRegion; -import org.eclipse.qvtd.pivot.qvtschedule.VariableNode; import org.eclipse.qvtd.pivot.qvtschedule.ClassDatum; import org.eclipse.qvtd.pivot.qvtschedule.NavigableEdge; import org.eclipse.qvtd.pivot.qvtschedule.Node; +import org.eclipse.qvtd.pivot.qvtschedule.utilities.DomainUsage; import org.eclipse.qvtd.pivot.qvtschedule.utilities.QVTscheduleUtil; +import org.eclipse.qvtd.pivot.qvttemplate.CollectionTemplateExp; import org.eclipse.qvtd.pivot.qvttemplate.ObjectTemplateExp; import org.eclipse.qvtd.pivot.qvttemplate.PropertyTemplateItem; +import org.eclipse.qvtd.pivot.qvttemplate.TemplateExp; /** * A RelationAnalysis provides the analysis a QVTc mapping. */ public class RelationAnalysis extends RuleAnalysis { + public static class InvocationAnalysis + { + protected final @NonNull RelationAnalysis invokingRelationAnalysis; + protected final @NonNull RuleAnalysis2TraceClass invokedRuleAnalysis2TraceClass; + protected final @NonNull Node invokedNode; + protected final boolean isWhen; + private final @NonNull Map<@NonNull VariableDeclaration, @NonNull Node> rootVariable2argumentNode = new HashMap<>(); + + public InvocationAnalysis(@NonNull RelationAnalysis invokingRelationAnalysis, @NonNull RuleAnalysis2TraceClass invokedRuleAnalysis2TraceClass, + @NonNull RelationCallExp relationCallExp, @NonNull Node invokedNode, boolean isWhen) { + this.invokingRelationAnalysis = invokingRelationAnalysis; + this.invokedRuleAnalysis2TraceClass = invokedRuleAnalysis2TraceClass; + this.invokedNode = invokedNode; + this.isWhen = isWhen; + } + + public void add(@NonNull VariableDeclaration rootVariable, @NonNull Node argumentNode) { + Node oldNode = rootVariable2argumentNode.put(rootVariable, argumentNode); + assert oldNode == null; + } + + public void install() { + for (@NonNull VariableDeclaration rootVariable : rootVariable2argumentNode.keySet()) { + Node argumentNode = rootVariable2argumentNode.get(rootVariable); + assert argumentNode != null; + Property invocationProperty = invokedRuleAnalysis2TraceClass.getTraceProperty(rootVariable); + // if (isWhen) { + + // } + // else { + invokingRelationAnalysis.createNavigationEdge(invokedNode, invocationProperty, argumentNode, null); + // } + } + + } + } + /* public static @NonNull RelationAnalysis createMappingRegion(@NonNull ScheduleManager scheduleManager, @NonNull RuleRegion ruleRegion) { RelationAnalysis mappingAnalysis = new RelationAnalysis(scheduleManager, ruleRegion); @SuppressWarnings("unused")String name = mappingAnalysis.getRuleRegion().getName(); @@ -62,117 +101,6 @@ public class RelationAnalysis extends RuleAnalysis return mappingAnalysis; } */ - public static abstract class AbstractQVTrelationExpressionAnalyzer extends ExpressionAnalyzer implements QVTrelationVisitor<@Nullable Node> - { - protected AbstractQVTrelationExpressionAnalyzer(@NonNull RuleAnalysis context) { - super(context); - } - - @Override - public @Nullable Node visitCollectionTemplateExp(org.eclipse.qvtd.pivot.qvttemplate.@NonNull CollectionTemplateExp object) { - return visitTemplateExp(object); - } - - @Override - public @Nullable Node visitObjectTemplateExp(org.eclipse.qvtd.pivot.qvttemplate.@NonNull ObjectTemplateExp object) { - return visitTemplateExp(object); - } - - @Override - public @Nullable Node visitPropertyTemplateItem(org.eclipse.qvtd.pivot.qvttemplate.@NonNull PropertyTemplateItem object) { - return visitElement(object); - } - - @Override - public @Nullable Node visitTemplateExp(org.eclipse.qvtd.pivot.qvttemplate.@NonNull TemplateExp object) { - return visitLiteralExp(object); - } - - @Override - public @Nullable Node visitDomainPattern(org.eclipse.qvtd.pivot.qvtrelation.@NonNull DomainPattern object) { - return visitPattern(object); - } - - @Override - public @Nullable Node visitKey(org.eclipse.qvtd.pivot.qvtrelation.@NonNull Key object) { - return visitElement(object); - } - - @Override - public @Nullable Node visitRelation(org.eclipse.qvtd.pivot.qvtrelation.@NonNull Relation object) { - return visitRule(object); - } - - @Override - public @Nullable Node visitRelationCallExp(org.eclipse.qvtd.pivot.qvtrelation.@NonNull RelationCallExp object) { - return visitOCLExpression(object); - } - - @Override - public @Nullable Node visitRelationDomain(org.eclipse.qvtd.pivot.qvtrelation.@NonNull RelationDomain object) { - return visitDomain(object); - } - - @Override - public @Nullable Node visitRelationDomainAssignment(org.eclipse.qvtd.pivot.qvtrelation.@NonNull RelationDomainAssignment object) { - return visitElement(object); - } - - @Override - public @Nullable Node visitRelationImplementation(org.eclipse.qvtd.pivot.qvtrelation.@NonNull RelationImplementation object) { - return visitElement(object); - } - - @Override - public @Nullable Node visitRelationModel(org.eclipse.qvtd.pivot.qvtrelation.@NonNull RelationModel object) { - return visitBaseModel(object); - } - - @Override - public @Nullable Node visitRelationalTransformation(org.eclipse.qvtd.pivot.qvtrelation.@NonNull RelationalTransformation object) { - return visitTransformation(object); - } - - @Override - public @Nullable Node visitSharedVariable(org.eclipse.qvtd.pivot.qvtrelation.@NonNull SharedVariable object) { - return visitVariable(object); - } - - @Override - public @Nullable Node visitTemplateVariable(org.eclipse.qvtd.pivot.qvtrelation.@NonNull TemplateVariable object) { - return visitVariable(object); - } - } - - public static class QVTrelationExpressionAnalyzer extends AbstractQVTrelationExpressionAnalyzer - { - protected QVTrelationExpressionAnalyzer(@NonNull RuleAnalysis context) { - super(context); - } - - @Override - protected @NonNull ExpressionAnalyzer createConditionalExpressionAnalyzer() { - return new ConditionalExpressionAnalyzer(context); - } - } - - public static class ConditionalExpressionAnalyzer extends QVTrelationExpressionAnalyzer - { - protected ConditionalExpressionAnalyzer(@NonNull RuleAnalysis context) { - super(context); - } - - @Override - protected @NonNull Node createStepNode(@NonNull String name, @NonNull CallExp callExp, @NonNull Node sourceNode) { - return context.createStepNode(name, callExp, sourceNode, false); - } - - @Override - protected boolean isUnconditional() { - return false; - } - } - protected final @NonNull QVTuConfiguration qvtuConfiguration; /** @@ -182,6 +110,7 @@ public class RelationAnalysis extends RuleAnalysis private final @NonNull Set<@NonNull Predicate> complexPredicates = new HashSet<>(); private org.eclipse.ocl.pivot.@Nullable Class traceClass = null; + private Node traceNode = null; /** * The variable initializers, simple predicate reference expression and variable assignment values that define a value for each variable. @@ -198,11 +127,13 @@ public class RelationAnalysis extends RuleAnalysis * The expressions that call this relation from a when clause. */ private @Nullable List<@NonNull RelationCallExp> incomingWhenInvocations = null; + private @Nullable List<@NonNull InvocationAnalysis> incomingWhenInvocationAnalyses = null; /** * The expressions that call this relation from a where clause. */ private @Nullable List<@NonNull RelationCallExp> incomingWhereInvocations = null; + private @Nullable List<@NonNull InvocationAnalysis> incomingWhereInvocationAnalyses = null; /** * The expressions that call relations with this relation. @@ -213,17 +144,26 @@ public class RelationAnalysis extends RuleAnalysis * The expressions that call relations with this relation's when clause. */ private @Nullable List<@NonNull RelationCallExp> outgoingWhenInvocations = null; + private @Nullable List<@NonNull InvocationAnalysis> outgoingWhenInvocationAnalyses = null; /** * The expressions that call relations with this relation's where clause. */ private @Nullable List<@NonNull RelationCallExp> outgoingWhereInvocations = null; + private @Nullable List<@NonNull InvocationAnalysis> outgoingWhereInvocationAnalyses = null; /** * Closure of all overriding relations or null if not overridden. */ private @Nullable Set<@NonNull RelationAnalysis> overridingRelationAnalyses = null; + /** + * The output variables that can be reached by a trabsitive composition relationship + * from an output root variable. These variables are logically created as a single + * composite object. + */ + private final @NonNull Set<@NonNull VariableDeclaration> composedOutputVariables = new HashSet<>(); + public RelationAnalysis(@NonNull TransformationAnalysis transformationAnalysis, @NonNull QVTuConfiguration qvtuConfiguration, @NonNull RuleRegion ruleRegion) { super(transformationAnalysis, ruleRegion); this.qvtuConfiguration = qvtuConfiguration; @@ -485,6 +425,65 @@ public class RelationAnalysis extends RuleAnalysis return targetExpression; } + @Override + public void analyzeStructure() { + Relation relation = getRule(); + for (@NonNull RelationDomain relationDomain : QVTrelationUtil.getOwnedDomains(relation)) { + for (@NonNull DomainPattern domainPattern : QVTrelationUtil.getOwnedPatterns(relationDomain)) { + DomainUsage domainUsage = scheduleManager.getDomainUsage(domainPattern); + if (domainUsage.isOutput()) { + TemplateExp templateExpression = QVTrelationUtil.getOwnedTemplateExpression(domainPattern); + Variable rootVariable = QVTrelationUtil.getBindsTo(templateExpression); + // assert rootVariable != null; + composedOutputVariables.add(rootVariable); + analyzeTemplateExpression(templateExpression); + } + + } + } + } + + private void analyzeTemplateExpression(@NonNull TemplateExp templateExpression) { + if (templateExpression instanceof ObjectTemplateExp) { + for (@NonNull PropertyTemplateItem propertyTemplateItem : QVTrelationUtil.getOwnedParts((ObjectTemplateExp)templateExpression)) { + OCLExpression value = QVTrelationUtil.getOwnedValue(propertyTemplateItem); + Property property = QVTrelationUtil.getReferredProperty(propertyTemplateItem); + boolean isComposed = property.isIsComposite(); + // if (!isComposed) { + // Property oppositeProperty = property.getOpposite(); + // if ((oppositeProperty != null) && oppositeProperty.isIsComposite()) { + // isComposed = true; + // } + // } + if (isComposed) { + if (value instanceof VariableExp) { + composedOutputVariables.add(QVTrelationUtil.getReferredVariable((VariableExp)value)); + // FIXME composed CollectionLiterals + } + else if (value instanceof TemplateExp) { + composedOutputVariables.add(QVTrelationUtil.getBindsTo((TemplateExp)value)); + analyzeTemplateExpression((TemplateExp)value); + } + } + } + } + else if (templateExpression instanceof CollectionTemplateExp) { + for (@NonNull OCLExpression memberExpression : QVTrelationUtil.getOwnedMembers((CollectionTemplateExp)templateExpression)) { + if (memberExpression instanceof VariableExp) { + composedOutputVariables.add(QVTrelationUtil.getReferredVariable((VariableExp)memberExpression)); + } + else if (memberExpression instanceof TemplateExp) { + composedOutputVariables.add(QVTrelationUtil.getBindsTo((TemplateExp)memberExpression)); + analyzeTemplateExpression((TemplateExp)memberExpression); + } + } + VariableDeclaration restVariable = ((CollectionTemplateExp)templateExpression).getRest(); + if (restVariable != null) { + composedOutputVariables.add(restVariable); + } + } + } + /** * Create a GREEN node for each realized variable. * @@ -615,9 +614,14 @@ public class RelationAnalysis extends RuleAnalysis public void analyzeVariableDeclaration(@NonNull VariableDeclaration variableDeclaration) { ClassDatum classDatum = scheduleManager.getClassDatum(variableDeclaration); TypedModel typedModel = QVTscheduleUtil.getReferredTypedModel(classDatum); - if (qvtuConfiguration.isOutput(typedModel)) { + if (qvtuConfiguration.isOutput(typedModel) && composedOutputVariables.contains(variableDeclaration)) { createRealizedStepNode(variableDeclaration); } + else if (QVTrelationUtil.isTraceClassVariable(variableDeclaration)) { + // FIXME create traceClass earlier + // variableDeclaration.setType(traceClass); + // traceNode = createRealizedStepNode(variableDeclaration); + } else { createOldNode(variableDeclaration); } @@ -686,7 +690,38 @@ public class RelationAnalysis extends RuleAnalysis } } return null; - } */ + } + * @param invokedRuleAnalysis */ + + public @NonNull InvocationAnalysis createInvocationAnalysis(@NonNull RuleAnalysis2TraceClass invokedRuleAnalysis2TraceClass, @NonNull RelationCallExp relationCallExp, Node invokedNode, boolean isWhen) { + InvocationAnalysis invocationAnalysis = new InvocationAnalysis(this, invokedRuleAnalysis2TraceClass, relationCallExp, invokedNode, isWhen); + RelationAnalysis invokedRelationAnalysis = (RelationAnalysis) invokedRuleAnalysis2TraceClass.getRuleAnalysis(); + if (isWhen) { + List<@NonNull InvocationAnalysis> outgoingWhenInvocationAnalyses2 = outgoingWhenInvocationAnalyses; + if (outgoingWhenInvocationAnalyses2 == null) { + outgoingWhenInvocationAnalyses = outgoingWhenInvocationAnalyses2 = new ArrayList<>(); + } + outgoingWhenInvocationAnalyses2.add(invocationAnalysis); + List<@NonNull InvocationAnalysis> incomingWhenInvocationAnalyses2 = invokedRelationAnalysis.incomingWhenInvocationAnalyses; + if (incomingWhenInvocationAnalyses2 == null) { + invokedRelationAnalysis.incomingWhenInvocationAnalyses = incomingWhenInvocationAnalyses2 = new ArrayList<>(); + } + incomingWhenInvocationAnalyses2.add(invocationAnalysis); + } + else { + List<@NonNull InvocationAnalysis> outgoingWhereInvocationAnalyses2 = outgoingWhereInvocationAnalyses; + if (outgoingWhereInvocationAnalyses2 == null) { + outgoingWhereInvocationAnalyses = outgoingWhereInvocationAnalyses2 = new ArrayList<>(); + } + outgoingWhereInvocationAnalyses2.add(invocationAnalysis); + List<@NonNull InvocationAnalysis> incomingWhereInvocationAnalyses2 = invokedRelationAnalysis.incomingWhereInvocationAnalyses; + if (incomingWhereInvocationAnalyses2 == null) { + invokedRelationAnalysis.incomingWhereInvocationAnalyses = incomingWhereInvocationAnalyses2 = new ArrayList<>(); + } + incomingWhereInvocationAnalyses2.add(invocationAnalysis); + } + return invocationAnalysis; + } @Override public @Nullable Iterable<@NonNull ? extends OCLExpression> getIncomingInvocations() { @@ -787,6 +822,27 @@ public class RelationAnalysis extends RuleAnalysis return false; } + public void installInvocations() { + List<@NonNull InvocationAnalysis> outgoingWhenInvocationAnalyses2 = outgoingWhenInvocationAnalyses; + if (outgoingWhenInvocationAnalyses2 != null) { + for (@NonNull InvocationAnalysis invocationAnalysis : outgoingWhenInvocationAnalyses2) { + invocationAnalysis.install(); + } + } + List<@NonNull InvocationAnalysis> outgoingWhereInvocationAnalyses2 = outgoingWhereInvocationAnalyses; + if (outgoingWhereInvocationAnalyses2 != null) { + for (@NonNull InvocationAnalysis invocationAnalysis : outgoingWhereInvocationAnalyses2) { + invocationAnalysis.install(); + } + } + } + + @Override + public void registerConsumptionsAndProductions() { + installInvocations(); + super.registerConsumptionsAndProductions(); + } + @Override public void synthesizeTraceClass(@NonNull RuleAnalysis2TraceClass ruleAnalysis2traceClass) { // VariableDeclaration traceVariable = QVTrelationFactory.eINSTANCE.createSharedVariable(); @@ -794,17 +850,17 @@ public class RelationAnalysis extends RuleAnalysis // traceVariable.setType(ruleAnalysis2traceClass.getTraceClass()); // traceVariable.setIsRequired(true); // region.getAnnotatingComments() - Variable traceVariable = NameUtil.getNameable(QVTrelationUtil.getOwnedVariables(getRule()), QVTrelationUtil.TRACE_CLASS_NAME); + Variable traceVariable = NameUtil.getNameable(QVTrelationUtil.getOwnedVariables(getRule()), QVTrelationUtil.TRACE_CLASS_NAME); assert traceVariable != null; traceVariable.setType(ruleAnalysis2traceClass.getTraceClass()); - VariableNode traceNode = createRealizedStepNode(traceVariable); + traceNode = createRealizedStepNode(traceVariable); // Role nodeRole = Role.REALIZED; // PatternVariableNode traceNode = QVTscheduleFactory.eINSTANCE.createPatternVariableNode(); // ClassDatum classDatum = scheduleManager.getClassDatum(scheduleManager.getDomainUsageAnalysis().getTraceTypedModel(), ruleAnalysis2traceClass.getTraceClass()); // traceNode.initialize(nodeRole, region, getName(traceVariable), classDatum); // node.initializeVariable(region, stepVariable); // traceNode.setMatched(true); - // traceNode.setUtility(Node.Utility.STRONGLY_MATCHED); + traceNode.setUtility(Node.Utility.STRONGLY_MATCHED); // return node; for (@NonNull VariableDeclaration2TraceProperty variableDeclaration2traceProperty : ruleAnalysis2traceClass.getVariableDeclaration2TraceProperties()) { Property traceProperty = variableDeclaration2traceProperty.getTraceProperty(); diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvts2qvti/QVTs2QVTiVisitor.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvts2qvti/QVTs2QVTiVisitor.java index 170b5ee7d..188430a8a 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvts2qvti/QVTs2QVTiVisitor.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvts2qvti/QVTs2QVTiVisitor.java @@ -42,7 +42,6 @@ import org.eclipse.qvtd.pivot.qvtbase.Rule; import org.eclipse.qvtd.pivot.qvtbase.Transformation; import org.eclipse.qvtd.pivot.qvtbase.TypedModel; import org.eclipse.qvtd.pivot.qvtbase.utilities.QVTbaseUtil; -import org.eclipse.qvtd.pivot.qvtcore.utilities.QVTcoreUtil; import org.eclipse.qvtd.pivot.qvtimperative.ImperativeTypedModel; import org.eclipse.qvtd.pivot.qvtimperative.Mapping; import org.eclipse.qvtd.pivot.qvtimperative.utilities.QVTimperativeHelper; @@ -228,8 +227,9 @@ public class QVTs2QVTiVisitor extends AbstractExtendingQVTscheduleVisitor<@Nulla } for (Rule rule : qvtmTransformation.getRule()) { for (Domain domain : rule.getDomain()) { - if (domain.isIsCheckable()) { - ImperativeTypedModel checkableTypedModel = qvtmTypedModel2qvtiTypedModel.get(QVTcoreUtil.getTypedModel(domain)); + TypedModel typedModel = QVTbaseUtil.getTypedModel(domain); + if (scheduleManager.isInput(domain)) { + ImperativeTypedModel checkableTypedModel = qvtmTypedModel2qvtiTypedModel.get(typedModel); if ((checkableTypedModel != null) && !checkableAndEnforceableTypedModels.contains(checkableTypedModel)) { checkableTypedModel.setIsChecked(true); if (enforceableTypedModels.contains(checkableTypedModel)) { @@ -241,8 +241,8 @@ public class QVTs2QVTiVisitor extends AbstractExtendingQVTscheduleVisitor<@Nulla } } } - if (domain.isIsEnforceable()) { - ImperativeTypedModel enforceableTypedModel = qvtmTypedModel2qvtiTypedModel.get(QVTcoreUtil.getTypedModel(domain)); + if (scheduleManager.isOutput(domain)) { + ImperativeTypedModel enforceableTypedModel = qvtmTypedModel2qvtiTypedModel.get(typedModel); if ((enforceableTypedModel != null) && !checkableAndEnforceableTypedModels.contains(enforceableTypedModel)) { enforceableTypedModel.setIsEnforced(true); if (checkableTypedModels.contains(enforceableTypedModel)) { diff --git a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvts2trace/NameGenerator.java b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvts2trace/NameGenerator.java index 6f93ec80e..fefb2bc82 100644 --- a/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvts2trace/NameGenerator.java +++ b/plugins/org.eclipse.qvtd.compiler/src/org/eclipse/qvtd/compiler/internal/qvts2trace/NameGenerator.java @@ -9,9 +9,13 @@ import org.eclipse.ocl.pivot.VariableDeclaration; import org.eclipse.ocl.pivot.utilities.NameUtil; import org.eclipse.ocl.pivot.utilities.Nameable; import org.eclipse.ocl.pivot.utilities.PivotUtil; -import org.eclipse.qvtd.pivot.qvtbase.Domain; +import org.eclipse.qvtd.compiler.internal.qvtc2qvtu.QVTuConfiguration; import org.eclipse.qvtd.pivot.qvtbase.Rule; +import org.eclipse.qvtd.pivot.qvtbase.TypedModel; import org.eclipse.qvtd.pivot.qvtbase.utilities.QVTbaseUtil; +import org.eclipse.qvtd.pivot.qvtrelation.Relation; +import org.eclipse.qvtd.pivot.qvtrelation.RelationDomain; +import org.eclipse.qvtd.pivot.qvtrelation.utilities.QVTrelationUtil; /** * NameGenerator localizes the name generation functionality to facilitate a chnage / rewrite. @@ -99,11 +103,17 @@ public class NameGenerator return QVTbaseUtil.getName(identifiedVariable) + "_key"; } - public @NonNull String createMappingName(@NonNull Domain domain) { - Rule rule = QVTbaseUtil.getContainingRule(domain); - String ruleName = PivotUtil.getName(rule); - String enforcedDomainName = PivotUtil.getName(domain); - return ruleName + '_' + enforcedDomainName; + public @NonNull String createMappingName(@NonNull Relation rule, @NonNull QVTuConfiguration qvtuConfiguration) { + StringBuilder s = new StringBuilder(); + s.append(PivotUtil.getName(rule)); + for (@NonNull RelationDomain domain : QVTrelationUtil.getOwnedDomains(rule)) { + TypedModel typedModel = QVTrelationUtil.getTypedModel(domain); + if (qvtuConfiguration.isOutput(typedModel)) { + s.append("_"); + s.append(PivotUtil.getName(typedModel)); + } + } + return s.toString(); } public @NonNull String createTraceClassName(@NonNull Rule rule) { |