Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Willink2022-06-21 14:00:35 +0000
committerEd Willink2022-06-21 14:00:35 +0000
commit55a2084ee5671c021d8bc601ef4cafff94737650 (patch)
tree066819b5535d700461531a519d8fc1263825344c
parent5e62d3891360dd9f3e4f8a65901da2a721d5cce9 (diff)
downloadorg.eclipse.qvtd-ewillink/394658.tar.gz
org.eclipse.qvtd-ewillink/394658.tar.xz
org.eclipse.qvtd-ewillink/394658.zip
Tidying InternalFunctionOperationCallingConventionewillink/394658
-rw-r--r--plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiAS2CGVisitor.java15
-rw-r--r--plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/InternalFunctionOperationCallingConvention.java49
-rw-r--r--plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiCodeGenerator.java2
-rw-r--r--plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/utilities/QVTiCGUtil.java5
-rw-r--r--tests/org.eclipse.qvtd.xtext.qvtrelation.tests/models/callingConventions/CallingConventions.qvtr6
5 files changed, 65 insertions, 12 deletions
diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiAS2CGVisitor.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiAS2CGVisitor.java
index 3b380bf49..6d5fd323a 100644
--- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiAS2CGVisitor.java
+++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiAS2CGVisitor.java
@@ -29,6 +29,7 @@ import org.eclipse.ocl.examples.codegen.analyzer.NameResolution;
import org.eclipse.ocl.examples.codegen.analyzer.NestedNameManager;
import org.eclipse.ocl.examples.codegen.cgmodel.CGAccumulator;
import org.eclipse.ocl.examples.codegen.cgmodel.CGCastExp;
+import org.eclipse.ocl.examples.codegen.cgmodel.CGClass;
import org.eclipse.ocl.examples.codegen.cgmodel.CGConstantExp;
import org.eclipse.ocl.examples.codegen.cgmodel.CGEcorePropertyCallExp;
import org.eclipse.ocl.examples.codegen.cgmodel.CGExecutorPropertyCallExp;
@@ -71,6 +72,7 @@ import org.eclipse.ocl.pivot.internal.library.ImplicitNonCompositionProperty;
import org.eclipse.ocl.pivot.library.LibraryProperty;
import org.eclipse.ocl.pivot.utilities.ClassUtil;
import org.eclipse.ocl.pivot.utilities.NameUtil;
+import org.eclipse.ocl.pivot.utilities.PivotUtil;
import org.eclipse.qvtd.codegen.qvti.java.FunctionOperationCallingConvention;
import org.eclipse.qvtd.codegen.qvti.java.QVTiCodeGenerator;
import org.eclipse.qvtd.codegen.qvticgmodel.CGConnectionAssignment;
@@ -447,6 +449,8 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit
Function asFunction = (Function)asOperation;
CGFunction cgFunction = (CGFunction)analyzer.basicGetCGOperation(asFunction);
if (cgFunction == null) {
+ CGClass cgClass = analyzer.getCGClass(PivotUtil.getOwningClass(asOperation));
+ pushClassNameManager(cgClass);
FunctionOperationCallingConvention callingConvention = (FunctionOperationCallingConvention)context.getCallingConvention(asFunction, true);
cgFunction = callingConvention.createCGOperation(analyzer, asSourceType, asFunction);
// getNameManager().declarePreferredName(cgFunction);
@@ -454,10 +458,11 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit
assert cgFunction.getCallingConvention() == callingConvention;
// analyzer.addCGOperation(cgFunction);
// analyzer.installOperation(asOperation, cgFunction, callingConvention);
- pushNameManager(cgFunction);
+ pushNestedNameManager(cgFunction);
callingConvention.createCGParameters(this, cgFunction, (ExpressionInOCL)asFunction.getBodyExpression());
getAnalyzer().addFunction(asFunction, cgFunction);
popNameManager();
+ popNameManager();
}
return cgFunction;
}
@@ -943,7 +948,7 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit
public @Nullable CGNamedElement visitFunction(@NonNull Function asFunction) {
CGFunction cgFunction = (CGFunction)generateOperationDeclaration(null, asFunction, true);
FunctionOperationCallingConvention callingConvention = (FunctionOperationCallingConvention)cgFunction.getCallingConvention();
- pushNameManager(cgFunction);
+ pushNestedNameManager(cgFunction);
callingConvention.createCGBody(this, cgFunction);
// cgFunction.setRequired(asFunction.isIsRequired());
/* OCLExpression query = asFunction.getQueryExpression(); //getBodyExpression();
@@ -1122,7 +1127,7 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit
cgTransformation.setAst(asTransformation);
cgTransformation.setName(asTransformation.getName());
analyzer.setCGRootClass(cgTransformation);
- pushNameManager(cgTransformation);
+ pushClassNameManager(cgTransformation);
List<CGTypedModel> cgTypedModels = cgTransformation.getOwnedTypedModels();
for (@NonNull TypedModel asTypedModel : QVTimperativeUtil.getModelParameters(asTransformation)) {
CGTypedModel cgTypedModel = doVisit(CGTypedModel.class, asTypedModel);
@@ -1173,7 +1178,7 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit
@Override
public @Nullable CGNamedElement visitMapping(@NonNull Mapping asMapping) {
CGMapping cgMapping = generateMappingDeclaration(asMapping);
- pushNameManager(cgMapping);
+ pushNestedNameManager(cgMapping);
PredicateTreeBuilder bodyBuilder2 = bodyBuilder = new PredicateTreeBuilder(asMapping, cgMapping);
bodyBuilder2.doBottoms();
List<@NonNull CGGuardVariable> cgFreeVariables = ClassUtil.nullFree(cgMapping.getOwnedGuardVariables());
@@ -1209,7 +1214,7 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit
cgMappingLoop.setAst(asMappingLoop);
OCLExpression asSource = asMappingLoop.getOwnedExpression();
cgMappingLoop.setSource(doVisit(CGValuedElement.class, asSource));
- NestedNameManager nameManager = pushNameManager(cgMappingLoop);
+ NestedNameManager nameManager = pushNestedNameManager(cgMappingLoop);
List<LoopVariable> asIterators = asMappingLoop.getOwnedIterators();
if (asIterators.size() > 0) {
LoopVariable asIterator = asIterators.get(0);
diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/InternalFunctionOperationCallingConvention.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/InternalFunctionOperationCallingConvention.java
index b7f4177ae..2b0a6ab8e 100644
--- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/InternalFunctionOperationCallingConvention.java
+++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/InternalFunctionOperationCallingConvention.java
@@ -21,6 +21,9 @@ import org.eclipse.ocl.examples.codegen.cgmodel.CGOperation;
import org.eclipse.ocl.examples.codegen.cgmodel.CGOperationCallExp;
import org.eclipse.ocl.examples.codegen.cgmodel.CGParameter;
import org.eclipse.ocl.examples.codegen.cgmodel.CGValuedElement;
+import org.eclipse.ocl.examples.codegen.java.CG2JavaVisitor;
+import org.eclipse.ocl.examples.codegen.java.JavaStream;
+import org.eclipse.ocl.examples.codegen.utilities.CGUtil;
import org.eclipse.ocl.pivot.ExpressionInOCL;
import org.eclipse.ocl.pivot.OCLExpression;
import org.eclipse.ocl.pivot.Operation;
@@ -28,6 +31,7 @@ import org.eclipse.ocl.pivot.OperationCallExp;
import org.eclipse.ocl.pivot.Parameter;
import org.eclipse.ocl.pivot.Type;
import org.eclipse.ocl.pivot.library.LibraryOperation;
+import org.eclipse.ocl.pivot.utilities.PivotUtil;
import org.eclipse.qvtd.codegen.qvti.analyzer.QVTiAS2CGVisitor;
import org.eclipse.qvtd.codegen.qvticgmodel.CGFunction;
import org.eclipse.qvtd.codegen.qvticgmodel.CGFunctionCallExp;
@@ -37,6 +41,8 @@ import org.eclipse.qvtd.pivot.qvtbase.Function;
/**
* InternalFunctionOperationCallingConvention defines the support for the call of a QVTi function implemented by an OCL expression.
+ *
+ * The implementation uses a class whose instance caches a result to ensure unique shared execution.
*/
public class InternalFunctionOperationCallingConvention extends FunctionOperationCallingConvention // cg Cached/Constrained
{
@@ -70,6 +76,7 @@ public class InternalFunctionOperationCallingConvention extends FunctionOperatio
@Override
public @NonNull CGFunction createCGOperation(@NonNull CodeGenAnalyzer analyzer, @Nullable Type asSourceType, @NonNull Operation asOperation) {
+ // assert asOperation.getImplementation() == null; -- maybe ConstrainedOperation
assert asOperation.getImplementationClass() == null;
CGFunction cgFunction = QVTiCGModelFactory.eINSTANCE.createCGFunction();
analyzer.installOperation(asOperation, cgFunction, this);
@@ -77,6 +84,14 @@ public class InternalFunctionOperationCallingConvention extends FunctionOperatio
}
@Override
+ public @NonNull CGOperation createCGOperation(
+ @NonNull AS2CGVisitor as2cgVisitor, @Nullable Type asSourceType,
+ @NonNull Operation asOperation) {
+ // TODO Auto-generated method stub
+ return super.createCGOperation(as2cgVisitor, asSourceType, asOperation);
+ }
+
+ @Override
public @NonNull CGValuedElement createCGOperationCallExp(@NonNull AS2CGVisitor as2cgVisitor, @NonNull CGOperation cgOperation, @NonNull LibraryOperation libraryOperation,
@Nullable CGValuedElement cgSource, @NonNull OperationCallExp asOperationCallExp) {
QVTiAS2CGVisitor qvtias2cgVisitor = (QVTiAS2CGVisitor)as2cgVisitor;
@@ -99,17 +114,41 @@ public class InternalFunctionOperationCallingConvention extends FunctionOperatio
QVTiCodeGenerator codeGenerator = qvtias2cgVisitor.getCodeGenerator();
CGFunction cgFunction = (CGFunction)cgOperation;
Function asFunction = QVTiCGUtil.getAST(cgFunction);
- boolean useClassToCreateObject = codeGenerator.getShadowExp(asFunction) != null;
- assert !useClassToCreateObject;
- List<CGParameter> cgParameters = cgFunction.getParameters();
- cgParameters.add(((QVTiNestedNameManager)qvtias2cgVisitor.getNameManager()).getThisTransformerParameter());
- for (Parameter asParameter : asFunction.getOwnedParameters()) {
+ assert codeGenerator.getShadowExp(asFunction) == null;
+ QVTiNestedNameManager nameManager = (QVTiNestedNameManager)qvtias2cgVisitor.getNameManager();
+ List<@NonNull CGParameter> cgParameters = CGUtil.getParametersList(cgFunction);
+ cgParameters.add(nameManager.getThisTransformerParameter()); // Include "this" as part of the uniqueness Tuple.
+ for (@NonNull Parameter asParameter : PivotUtil.getOwnedParameters(asFunction)) {
CGParameter cgParameter = as2cgVisitor.doVisit(CGParameter.class, asParameter);
cgParameters.add(cgParameter);
}
}
@Override
+ public boolean generateJavaCall(@NonNull CG2JavaVisitor cg2javaVisitor,
+ @NonNull JavaStream js,
+ @NonNull CGOperationCallExp cgOperationCallExp) {
+ // TODO Auto-generated method stub
+ return super.generateJavaCall(cg2javaVisitor, js, cgOperationCallExp);
+ }
+
+ @Override
+ public boolean generateJavaDeclaration(
+ @NonNull CG2JavaVisitor cg2javaVisitor, @NonNull JavaStream js,
+ @NonNull CGOperation cgOperation) {
+ // TODO Auto-generated method stub
+ return super.generateJavaDeclaration(cg2javaVisitor, js, cgOperation);
+ }
+
+ @Override
+ public void rewriteWithBoxingAndGuards(
+ @NonNull BoxingAnalyzer boxingAnalyzer,
+ @NonNull CGOperation cgOperation) {
+ // TODO Auto-generated method stub
+ super.rewriteWithBoxingAndGuards(boxingAnalyzer, cgOperation);
+ }
+
+ @Override
public void rewriteWithBoxingAndGuards(@NonNull BoxingAnalyzer boxingAnalyzer,@NonNull CGOperationCallExp cgOperationCallExp) {
for (CGValuedElement cgArgument : cgOperationCallExp.getArguments()) {
boxingAnalyzer.rewriteAsBoxed(cgArgument);
diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiCodeGenerator.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiCodeGenerator.java
index fe548fe5e..74df9caa1 100644
--- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiCodeGenerator.java
+++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiCodeGenerator.java
@@ -184,7 +184,7 @@ public class QVTiCodeGenerator extends JavaCodeGenerator
}
}
assert cgPackage != null;
- as2cgVisitor.pushNameManager(cgTransformation);
+ as2cgVisitor.pushClassNameManager(cgTransformation);
cgAnalyzer.analyzeExternalFeatures(as2cgVisitor);
as2cgVisitor.popNameManager();
return cgPackage;
diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/utilities/QVTiCGUtil.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/utilities/QVTiCGUtil.java
index 091389698..6c6ba14dd 100644
--- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/utilities/QVTiCGUtil.java
+++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/utilities/QVTiCGUtil.java
@@ -15,6 +15,7 @@ import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.ocl.examples.codegen.cgmodel.CGAccumulator;
+import org.eclipse.ocl.examples.codegen.cgmodel.CGClass;
import org.eclipse.ocl.examples.codegen.cgmodel.CGEcorePropertyCallExp;
import org.eclipse.ocl.examples.codegen.cgmodel.CGElement;
import org.eclipse.ocl.examples.codegen.cgmodel.CGExecutorProperty;
@@ -127,6 +128,10 @@ public class QVTiCGUtil extends CGUtil
return ClassUtil.nonNullState(cgMappingLoop.getBody());
}
+ public static @NonNull CGClass getContainingCGClass(@NonNull CGFunction cgFunction) {
+ return ClassUtil.nonNullState(cgFunction.getContainingClass());
+ }
+
public static @NonNull CGMapping getContainingCGMapping(@NonNull CGElement cgElement) {
return ClassUtil.nonNullState(basicGetContainingCGMapping(cgElement));
}
diff --git a/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/models/callingConventions/CallingConventions.qvtr b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/models/callingConventions/CallingConventions.qvtr
index 13f001004..a3170719d 100644
--- a/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/models/callingConventions/CallingConventions.qvtr
+++ b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/models/callingConventions/CallingConventions.qvtr
@@ -13,10 +13,14 @@ import myMM : 'Called.ecore'::called;
package org::eclipse::qvtd::xtext::qvtrelation::tests::callingConventions {
transformation CallingConventions(from:myMM, to:myMM)
{
+ query internalSum(firstValue : ecore::EInt[1], secondValue : ecore::EInt[1]) : ecore::EInt[1] {
+ firstValue + secondValue
+ }
+
top relation Values2Values {
value : ecore::EInt[1];
domain from fromValues : Values{ integer = value };
- enforce domain to toValues : Values{ integer = value + 1 };
+ enforce domain to toValues : Values{ integer = internalSum(value, 1) };
}
}
} \ No newline at end of file

Back to the top