Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEd Willink2022-01-31 05:52:19 +0000
committerEd Willink2022-01-31 15:38:03 +0000
commitc3fc70bdac6f1a364a3eeb3d6ed2e15c1dc3545b (patch)
treedf8663df2504c5ca4b46b58d6a9ca91586cbedd3
parent4b2d9ad8c41f416e7f2dcdeb32ae1ac08772c18a (diff)
downloadorg.eclipse.qvtd-ewillink/578443.tar.gz
org.eclipse.qvtd-ewillink/578443.tar.xz
org.eclipse.qvtd-ewillink/578443.zip
[578443] Support qualifiedThisVariableewillink/578443
-rw-r--r--plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiAS2CGVisitor.java41
-rw-r--r--plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiCG2JavaVisitor.java7
-rw-r--r--plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiGlobalContext.java14
-rw-r--r--plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiLocalContext.java32
4 files changed, 62 insertions, 32 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 3268ad7db..753a90753 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
@@ -114,6 +114,7 @@ import org.eclipse.qvtd.pivot.qvtbase.FunctionBody;
import org.eclipse.qvtd.pivot.qvtbase.FunctionParameter;
import org.eclipse.qvtd.pivot.qvtbase.Pattern;
import org.eclipse.qvtd.pivot.qvtbase.Predicate;
+import org.eclipse.qvtd.pivot.qvtbase.QVTbasePackage;
import org.eclipse.qvtd.pivot.qvtbase.Rule;
import org.eclipse.qvtd.pivot.qvtbase.SimpleTargetElement;
import org.eclipse.qvtd.pivot.qvtbase.Transformation;
@@ -435,23 +436,6 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit
return castCopy;
}
- /* protected @NonNull CGValuedElement generateMiddlePropertyCallExp(@NonNull CGValuedElement cgSource, @NonNull MiddlePropertyCallExp asMiddlePropertyCallExp) {
- Property asOppositeProperty = ClassUtil.nonNullModel(asMiddlePropertyCallExp.getReferredProperty());
- Property asProperty = ClassUtil.nonNullModel(asOppositeProperty.getOpposite());
- globalContext.addToMiddleProperty(asOppositeProperty);
-// LibraryProperty libraryProperty = metamodelManager.getImplementation(asProperty);
- CGMiddlePropertyCallExp cgPropertyCallExp = QVTiCGModelFactory.eINSTANCE.createCGMiddlePropertyCallExp();
-// CGExecutorProperty cgExecutorProperty = analyzer.getExecutorProperty(asProperty);
-// cgExecutorPropertyCallExp.setExecutorProperty(cgExecutorProperty);
-// cgPropertyCallExp = cgExecutorPropertyCallExp;
-// cgPropertyCallExp.getDependsOn().add(cgExecutorProperty);
- cgPropertyCallExp.setReferredProperty(asOppositeProperty);
- setAst(cgPropertyCallExp, asMiddlePropertyCallExp);
- cgPropertyCallExp.setRequired(asProperty.isIsRequired());
- cgPropertyCallExp.setSource(cgSource);
- return cgPropertyCallExp;
- } */
-
@Override
protected @NonNull CGValuedElement generateOperationCallExp(@Nullable CGValuedElement cgSource, @NonNull OperationCallExp asOperationCallExp) {
Operation pOperation = asOperationCallExp.getReferredOperation();
@@ -674,6 +658,29 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit
}
@Override
+ protected boolean isQualifiedThis(@NonNull VariableExp asVariableExp, @NonNull Parameter asParameter) {
+ assert asParameter == PivotUtil.getReferredVariable(asVariableExp);
+ assert isThis(asParameter);
+ Type currentType = PivotUtil.getContainingType(asVariableExp);
+ Mapping currentMapping = QVTimperativeUtil.basicGetContainingMapping(asVariableExp);
+ Operation currentOperation = QVTimperativeUtil.basicGetContainingOperation(asVariableExp);
+ Type referencedType = PivotUtil.getContainingType(asParameter); // FIXME Mappings
+ return (currentType != referencedType) || (currentMapping != null) || (currentOperation != null);
+ }
+
+ /**
+ * Return true if asParameter is a 'this' parameter.
+ */
+ @Override
+ protected boolean isThis(@NonNull Parameter asParameter) {
+ EStructuralFeature eContainingFeature = asParameter.eContainingFeature();
+ if (eContainingFeature == QVTbasePackage.Literals.TRANSFORMATION__OWNED_CONTEXT) {
+ return true;
+ }
+ return super.isThis(asParameter);
+ }
+
+ @Override
public @Nullable CGNamedElement visitAddStatement(@NonNull AddStatement asAddStatement) {
ConnectionVariable asVariable = asAddStatement.getTargetVariable();
if (asVariable == null) {
diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiCG2JavaVisitor.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiCG2JavaVisitor.java
index e6da44159..b73dcb0f6 100644
--- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiCG2JavaVisitor.java
+++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiCG2JavaVisitor.java
@@ -779,8 +779,14 @@ public class QVTiCG2JavaVisitor extends CG2JavaVisitor<@NonNull QVTiCodeGenerato
// String evaluatorName = ((QVTiGlobalContext)globalContext).getEvaluatorParameter().getName();
String evaluatorName = globalContext.getExecutorName();
String className = cgTransformation.getName();
+ String transformationName = ((QVTiGlobalContext)globalContext).getTransformationName();
Iterable<@NonNull CGTypedModel> cgTypedModels = QVTiCGUtil.getOwnedTypedModels(cgTransformation);
//
+ js.append("protected final ");
+ js.appendIsRequired(true);
+ js.append(" " + className + " " + transformationName + " = this;\n");
+ js.append("\n");
+ //
js.append("public " + className + "(final ");
js.appendClassReference(true, TransformationExecutor.class);
js.append(" " + evaluatorName + ") {\n");
@@ -2756,7 +2762,6 @@ public class QVTiCG2JavaVisitor extends CG2JavaVisitor<@NonNull QVTiCodeGenerato
}
@Deprecated
- @Override
protected @NonNull String getThisName(@NonNull CGElement cgElement) {
for (EObject eObject = cgElement; eObject != null; eObject = eObject.eContainer()) {
if (eObject instanceof CGMapping) {
diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiGlobalContext.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiGlobalContext.java
index f4a473ad6..746d98ee3 100644
--- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiGlobalContext.java
+++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiGlobalContext.java
@@ -16,6 +16,7 @@ import java.util.Map;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.ocl.examples.codegen.cgmodel.CGElement;
+import org.eclipse.ocl.examples.codegen.cgmodel.CGNamedElement;
import org.eclipse.ocl.examples.codegen.java.JavaConstants;
import org.eclipse.ocl.examples.codegen.java.JavaGlobalContext;
import org.eclipse.ocl.pivot.Property;
@@ -40,12 +41,15 @@ public class QVTiGlobalContext extends JavaGlobalContext<@NonNull QVTiCodeGenera
public static final @NonNull String OUTPUT_SPECULATION_SLOT_STATE_NAME = "outputSpeculatingSlotState";
public static final @NonNull String OUTPUT_SPECULATION_SLOT_STATUS_NAME = "outputSpeculatingSlotStatus";
public static final @NonNull String TRANSFORMATION_EXECUTION_NAME = "transformationExecution";
+ public static final @NonNull String TRANSFORMATION_NAME = "transformation";
/**
* Map from an oppositeProperty that requites a cache to the global name of that cache.
*/
private /*@LazyNonNull*/ Map<@NonNull Property, @NonNull String> oppositeProperty2oppositeCacheName = null;
+ protected final @NonNull String transformationName ;
+
public QVTiGlobalContext(@NonNull QVTiCodeGenerator codeGenerator) {
super(codeGenerator);
nameManager.reserveName(JavaConstants.EVALUATION_CACHE_NAME, null);
@@ -64,6 +68,7 @@ public class QVTiGlobalContext extends JavaGlobalContext<@NonNull QVTiCodeGenera
nameManager.reserveName(OUTPUT_SPECULATION_SLOT_STATE_NAME, null);
nameManager.reserveName(OUTPUT_SPECULATION_SLOT_STATUS_NAME, null);
nameManager.reserveName(TRANSFORMATION_EXECUTION_NAME, null);
+ this.transformationName = nameManager.reserveName(TRANSFORMATION_NAME, null);
}
public @NonNull String addOppositeProperty(@NonNull Property pivotProperty) {
@@ -84,7 +89,16 @@ public class QVTiGlobalContext extends JavaGlobalContext<@NonNull QVTiCodeGenera
return new QVTiLocalContext(this, cgScope);
}
+ @Override
+ public @Nullable QVTiLocalContext getLocalContext( @NonNull CGNamedElement cgElement) {
+ return (QVTiLocalContext)super.getLocalContext(cgElement);
+ }
+
public @Nullable Map<@NonNull Property, @NonNull String> getOppositeProperties() {
return oppositeProperty2oppositeCacheName;
}
+
+ public @NonNull String getTransformationName() {
+ return transformationName;
+ }
}
diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiLocalContext.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiLocalContext.java
index e50dd6949..bd689d5d7 100644
--- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiLocalContext.java
+++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/QVTiLocalContext.java
@@ -14,7 +14,6 @@ import org.eclipse.emf.ecore.EObject;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.ocl.examples.codegen.cgmodel.CGElement;
-import org.eclipse.ocl.examples.codegen.cgmodel.CGTypeId;
import org.eclipse.ocl.examples.codegen.cgmodel.CGValuedElement;
import org.eclipse.ocl.examples.codegen.cgmodel.CGVariable;
import org.eclipse.ocl.examples.codegen.cgmodel.CGVariableExp;
@@ -35,6 +34,24 @@ public class QVTiLocalContext extends JavaLocalContext<@NonNull QVTiCodeGenerato
}
@Override
+ public @NonNull CGVariable createExecutorVariable() {
+ assert executorIsParameter;
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public @NonNull CGVariable createQualifiedThisVariable() {
+ assert executorIsParameter;
+ assert asType instanceof Transformation;
+ String transformationName = getGlobalContext().getTransformationName();
+ CGVariable transformationVariable = analyzer.createCGParameter(transformationName, analyzer.getTypeId(asType.getTypeId()), true);
+ transformationVariable.setValueName(transformationName);
+ transformationVariable.setNonInvalid();
+ transformationVariable.setNonNull();
+ return transformationVariable;
+ }
+
+ @Override
public @Nullable CGValuedElement getBody() {
if (cgScope instanceof CGMapping) {
return ((CGMapping)cgScope).getOwnedBody();
@@ -43,24 +60,11 @@ public class QVTiLocalContext extends JavaLocalContext<@NonNull QVTiCodeGenerato
}
@Override
- public @NonNull CGVariable createExecutorVariable() {
- throw new UnsupportedOperationException();
- }
-
- @Override
public @NonNull QVTiGlobalContext getGlobalContext() {
return (QVTiGlobalContext) globalContext;
}
@Override
- protected @NonNull CGTypeId getScopeTypeId() {
- // if (cgScope instanceof CGMapping) {
- // return analyzer.getTypeId(QVTiCGUtil.getAST((CGMapping)cgScope).eContainer()).getTypeId());
- // }
- return super.getScopeTypeId();
- }
-
- @Override
public @NonNull String getValueName(@NonNull CGValuedElement cgElement) {
String valueName = cgElement.getValueName();
if (valueName != null) {

Back to the top