diff options
Diffstat (limited to 'plugins/org.eclipse.qvtd.codegen/src/org/eclipse')
6 files changed, 205 insertions, 122 deletions
diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiAnalysisVisitor.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiAnalysisVisitor.java index f6fd4cf0c..16e28d798 100644 --- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiAnalysisVisitor.java +++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiAnalysisVisitor.java @@ -11,15 +11,9 @@ package org.eclipse.qvtd.codegen.qvti.analyzer; import org.eclipse.jdt.annotation.NonNull; -import org.eclipse.ocl.examples.codegen.naming.GlobalNameManager; import org.eclipse.ocl.examples.codegen.naming.NestedNameManager; -import org.eclipse.ocl.pivot.OperationCallExp; -import org.eclipse.qvtd.codegen.qvticgmodel.CGFunction; -import org.eclipse.qvtd.codegen.qvticgmodel.CGFunctionCallExp; -import org.eclipse.qvtd.codegen.qvticgmodel.CGMappingCallBinding; import org.eclipse.qvtd.codegen.qvticgmodel.CGRealizedVariable; import org.eclipse.qvtd.codegen.qvticgmodel.util.AbstractQVTiAnalysisVisitor; -import org.eclipse.qvtd.pivot.qvtbase.Function; public class QVTiAnalysisVisitor extends AbstractQVTiAnalysisVisitor { @@ -31,7 +25,7 @@ public class QVTiAnalysisVisitor extends AbstractQVTiAnalysisVisitor return (QVTiAnalyzer) context; } - @Override + /* @Override public Object visitCGFunctionCallExp(@NonNull CGFunctionCallExp cgFunctionCallExp) { Function asFunction = (Function) ((OperationCallExp)cgFunctionCallExp.getAst()).getReferredOperation(); if (asFunction != null) { @@ -39,9 +33,9 @@ public class QVTiAnalysisVisitor extends AbstractQVTiAnalysisVisitor cgFunctionCallExp.setFunction(cgFunction); } return visitCGOperationCallExp(cgFunctionCallExp); - } + } */ - @Override + /* @Override public Object visitCGMappingCallBinding(@NonNull CGMappingCallBinding cgMappingCallBinding) { visitCGValuedElement(cgMappingCallBinding); GlobalNameManager globalNameManager = context.getGlobalNameManager(); @@ -49,7 +43,7 @@ public class QVTiAnalysisVisitor extends AbstractQVTiAnalysisVisitor // nameManager.queueValueName(cgMappingCallBinding, null, cgMappingCallBinding.getName()); // nameManager.declareStandardName(cgMappingCallBinding); return null; - } + } */ @Override public Object visitCGRealizedVariable(@NonNull CGRealizedVariable cgRealizedVariable) { diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiAnalyzer.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiAnalyzer.java index 8cd3d6896..3662d935a 100644 --- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiAnalyzer.java +++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiAnalyzer.java @@ -28,7 +28,6 @@ import org.eclipse.ocl.examples.codegen.analyzer.CodeGenAnalyzer; 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.CGEcoreContainerAssignment; import org.eclipse.ocl.examples.codegen.cgmodel.CGEcorePropertyAssignment; import org.eclipse.ocl.examples.codegen.cgmodel.CGEcorePropertyCallExp; import org.eclipse.ocl.examples.codegen.cgmodel.CGElement; @@ -89,7 +88,6 @@ import org.eclipse.qvtd.codegen.qvticgmodel.CGMapping; import org.eclipse.qvtd.codegen.qvticgmodel.CGMappingCallBinding; import org.eclipse.qvtd.codegen.qvticgmodel.CGMappingExp; import org.eclipse.qvtd.codegen.qvticgmodel.CGMappingLoop; -import org.eclipse.qvtd.codegen.qvticgmodel.CGMiddlePropertyAssignment; import org.eclipse.qvtd.codegen.qvticgmodel.CGRealizedVariable; import org.eclipse.qvtd.codegen.qvticgmodel.CGRealizedVariablePart; import org.eclipse.qvtd.codegen.qvticgmodel.CGSpeculateExp; @@ -410,8 +408,8 @@ public class QVTiAnalyzer extends CodeGenAnalyzer * Mapping from each AS TypedModel to its corresponding CGTypedModel. */ // private final @NonNull Map<@NonNull TypedModel, @NonNull CGTypedModel> asTypedModel2cgTypedModel = new HashMap<>(); - private final @Nullable TypeId originalThisTypeId; - private final @NonNull TypeId runtimeThisTypeId; + // private final @Nullable TypeId originalThisTypeId; + // private final @NonNull TypeId runtimeThisTypeId; private @Nullable PredicateTreeBuilder bodyBuilder; // private @NonNull Map<@NonNull Operation, org.eclipse.ocl.pivot.@NonNull Property> asOperation2asConstructorClass = new HashMap<>(); @@ -423,16 +421,16 @@ public class QVTiAnalyzer extends CodeGenAnalyzer public QVTiAnalyzer(@NonNull QVTiCodeGenerator codeGenerator) { super(codeGenerator); - ImperativeTransformation iTransformation = codeGenerator.getContextClass(); - Type contextClass = QVTimperativeUtil.getRuntimeContextClass(iTransformation); - if (contextClass != iTransformation) { - originalThisTypeId = iTransformation.getTypeId(); - runtimeThisTypeId = contextClass.getTypeId(); - } - else { - originalThisTypeId = null; - runtimeThisTypeId = iTransformation.getTypeId(); - } + // ImperativeTransformation iTransformation = codeGenerator.getContextClass(); + // Type contextClass = QVTimperativeUtil.getRuntimeContextClass(iTransformation); + // if (contextClass != iTransformation) { + // originalThisTypeId = iTransformation.getTypeId(); + // runtimeThisTypeId = contextClass.getTypeId(); + // } + // else { + // originalThisTypeId = null; + // runtimeThisTypeId = iTransformation.getTypeId(); + // } } // public void addCGFunction(@NonNull CGFunction cgFunction) { @@ -713,13 +711,14 @@ public class QVTiAnalyzer extends CodeGenAnalyzer return super.generatePropertyCallExp(cgSource, element); } - public CGNamedElement generateSetStatement(SetStatement asSetStatement) { + public @NonNull CGNamedElement generateSetStatement(@NonNull SetStatement asSetStatement) { ImperativeTransformation asTransformation = QVTimperativeUtil.getContainingTransformation(asSetStatement); EntryPointsAnalysis entryPointsAnalysis = getCodeGenerator().getEntryPointsAnalysis(asTransformation); Integer cacheIndex = entryPointsAnalysis.getCacheIndex(asSetStatement); if (cacheIndex != null) { // Property asProperty = ClassUtil.nonNullModel(asPropertyAssignment.getTargetProperty()); - CGMiddlePropertyAssignment cgPropertyAssignment = QVTiCGModelFactory.eINSTANCE.createCGMiddlePropertyAssignment(); + // CGMiddlePropertyAssignment cgPropertyAssignment = QVTiCGModelFactory.eINSTANCE.createCGMiddlePropertyAssignment(); + CGEcorePropertyAssignment cgPropertyAssignment = CGModelFactory.eINSTANCE.createCGEcorePropertyAssignment(); cgPropertyAssignment.setAst(asSetStatement); VariableDeclaration asVariable = asSetStatement.getTargetVariable(); assert asVariable != null; @@ -768,7 +767,8 @@ public class QVTiAnalyzer extends CodeGenAnalyzer assert ((EReference)eStructuralFeature).isContainment(); try { genModelHelper.getGetAccessor(eStructuralFeature); - CGEcoreContainerAssignment cgEcoreContainerAssignment = CGModelFactory.eINSTANCE.createCGEcoreContainerAssignment(); + // CGEcoreContainerAssignment cgEcoreContainerAssignment = CGModelFactory.eINSTANCE.createCGEcoreContainerAssignment(); + CGEcorePropertyAssignment cgEcoreContainerAssignment = CGModelFactory.eINSTANCE.createCGEcorePropertyAssignment(); cgEcoreContainerAssignment.setEStructuralFeature(eStructuralFeature); cgPropertyAssignment = cgEcoreContainerAssignment; } catch (GenModelException e) { diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiBoxingAnalyzer.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiBoxingAnalyzer.java index 821e68aee..41b89234d 100644 --- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiBoxingAnalyzer.java +++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/analyzer/QVTiBoxingAnalyzer.java @@ -28,7 +28,6 @@ import org.eclipse.ocl.pivot.TypedElement; import org.eclipse.ocl.pivot.utilities.PivotUtil; import org.eclipse.qvtd.codegen.qvticgmodel.CGEcoreRealizedVariable; import org.eclipse.qvtd.codegen.qvticgmodel.CGMappingCallBinding; -import org.eclipse.qvtd.codegen.qvticgmodel.CGMiddlePropertyAssignment; import org.eclipse.qvtd.codegen.qvticgmodel.CGRealizedVariablePart; import org.eclipse.qvtd.codegen.qvticgmodel.util.AbstractQVTiBoxingAnalysisVisitor; import org.eclipse.qvtd.pivot.qvtimperative.AppendParameterBinding; @@ -179,12 +178,28 @@ public class QVTiBoxingAnalyzer extends AbstractQVTiBoxingAnalysisVisitor } } - @Override + /* @Override public @Nullable Object visitCGMiddlePropertyAssignment(@NonNull CGMiddlePropertyAssignment cgMiddlePropertyAssignment) { + System.out.println(cgMiddlePropertyAssignment.getReferredProperty().getCallingConvention() + " <=m " + NameUtil.debugSimpleName(cgMiddlePropertyAssignment)); + + + SetStatement asSetStatement = QVTiCGUtil.getAST(cgMiddlePropertyAssignment); + ImperativeTransformation asTransformation = QVTimperativeUtil.getContainingTransformation(asSetStatement); + EntryPointsAnalysis entryPointsAnalysis = ((QVTiCodeGenerator)getCodeGenerator()).getEntryPointsAnalysis(asTransformation); + Integer cacheIndex = entryPointsAnalysis.getCacheIndex(asSetStatement); + assert (cacheIndex != null); + + + + + + EStructuralFeature eStructuralFeature = cgMiddlePropertyAssignment.getEStructuralFeature(); + assert eStructuralFeature instanceof EReference; + assert ((EReference)eStructuralFeature).getEOpposite() == null; rewriteAsUnboxed(cgMiddlePropertyAssignment.getOwnedSlotValue()); rewriteAsUnboxed(cgMiddlePropertyAssignment.getOwnedInitValue()); return super.visitCGMiddlePropertyAssignment(cgMiddlePropertyAssignment); - } + } */ /* @Override public @Nullable Object visitCGPropertyAssignment(@NonNull CGPropertyAssignment cgPropertyAssignment) { diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/calling/QVTiEcorePropertyCallingConvention.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/calling/QVTiEcorePropertyCallingConvention.java index cc4aea2c9..5117bd8e8 100644 --- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/calling/QVTiEcorePropertyCallingConvention.java +++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/calling/QVTiEcorePropertyCallingConvention.java @@ -10,23 +10,37 @@ *******************************************************************************/ package org.eclipse.qvtd.codegen.qvti.calling; +import java.util.Map; + +import org.eclipse.emf.ecore.EClassifier; +import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.EStructuralFeature; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; +import org.eclipse.ocl.examples.codegen.analyzer.BoxingAnalyzer; import org.eclipse.ocl.examples.codegen.calling.EcorePropertyCallingConvention; +import org.eclipse.ocl.examples.codegen.cgmodel.CGEcorePropertyAssignment; import org.eclipse.ocl.examples.codegen.cgmodel.CGEcorePropertyCallExp; import org.eclipse.ocl.examples.codegen.cgmodel.CGNavigationCallExp; +import org.eclipse.ocl.examples.codegen.cgmodel.CGPropertyAssignment; import org.eclipse.ocl.examples.codegen.cgmodel.CGValuedElement; +import org.eclipse.ocl.examples.codegen.generator.GenModelHelper; +import org.eclipse.ocl.examples.codegen.generator.TypeDescriptor; import org.eclipse.ocl.examples.codegen.java.CG2JavaVisitor; import org.eclipse.ocl.examples.codegen.java.JavaStream; import org.eclipse.ocl.pivot.Property; import org.eclipse.ocl.pivot.ids.ElementId; import org.eclipse.ocl.pivot.ids.TypeId; import org.eclipse.ocl.pivot.utilities.ClassUtil; +import org.eclipse.ocl.pivot.utilities.PivotUtil; import org.eclipse.ocl.pivot.utilities.ValueUtil; import org.eclipse.qvtd.codegen.qvti.java.QVTiCG2JavaVisitor; +import org.eclipse.qvtd.codegen.qvti.java.QVTiCodeGenerator; +import org.eclipse.qvtd.codegen.qvti.naming.QVTiGlobalNameManager; import org.eclipse.qvtd.codegen.utilities.QVTiCGUtil; import org.eclipse.qvtd.pivot.qvtimperative.ImperativeTransformation; +import org.eclipse.qvtd.pivot.qvtimperative.SetStatement; +import org.eclipse.qvtd.pivot.qvtimperative.evaluation.EntryPointsAnalysis; import org.eclipse.qvtd.pivot.qvtimperative.utilities.QVTimperativeUtil; /** @@ -44,7 +58,6 @@ public class QVTiEcorePropertyCallingConvention extends EcorePropertyCallingConv /** * Append the code for an EcorePropertyCall. If source is null, the code for the source will also be appended. * If source is non-null the caller has already appended it. - * @param qvticg2javaVisitor */ private @NonNull Boolean appendCGEcorePropertyCallExp(@NonNull QVTiCG2JavaVisitor cg2javaVisitor, @NonNull CGEcorePropertyCallExp cgPropertyCallExp, @Nullable CGValuedElement source) { JavaStream js = cg2javaVisitor.getJavaStream(); @@ -69,6 +82,112 @@ public class QVTiEcorePropertyCallingConvention extends EcorePropertyCallingConv return true; } + protected void appendEcoreSet(@NonNull CG2JavaVisitor cg2javaVisitor, @NonNull CGValuedElement cgSlot, @NonNull EStructuralFeature eStructuralFeature, @NonNull CGValuedElement cgInit, boolean isPartial) { + JavaStream js = cg2javaVisitor.getJavaStream(); + EClassifier eType = eStructuralFeature.getEType(); + String instanceClassName = eType.getInstanceClassName(); + GenModelHelper genModelHelper = cg2javaVisitor.getGenModelHelper(); + if (eStructuralFeature.isMany()) { + String getAccessor = genModelHelper.getGetAccessor(eStructuralFeature); + // + js.appendValueName(cgSlot); + js.append("."); + js.append(getAccessor); + js.append("()."); + if (isPartial) { + js.append("add("); + if (instanceClassName != null) { + js.appendEcoreValue(instanceClassName, cgInit); + } + else { + js.appendAtomicReferenceTo(cgInit); + } + } + else { + js.append( "addAll("); // FIXME may need to loop addAll manually + js.appendAtomicReferenceTo(cgInit); + } + js.append(");\n"); + } + else { + String setAccessor = genModelHelper.getSetAccessor(eStructuralFeature); + // + js.appendValueName(cgSlot); + js.append("."); + js.append(setAccessor); + js.append("("); + if (instanceClassName != null) { + js.appendEcoreValue(instanceClassName, cgInit); + } + else { + js.appendAtomicReferenceTo(cgInit); + } + js.append(");\n"); + } + } + + protected void doAssigned(@NonNull QVTiCG2JavaVisitor cg2javaVisitor, @NonNull CGEcorePropertyAssignment cgPropertyAssignment, boolean isPartial) { + JavaStream js = cg2javaVisitor.getJavaStream(); + boolean isIncremental = cg2javaVisitor.getCodeGenerator().getOptions().isIncremental(); + EStructuralFeature eStructuralFeature = QVTiCGUtil.getEStructuralFeature(cgPropertyAssignment); + CGValuedElement cgSlot = cg2javaVisitor.getExpression(QVTiCGUtil.getOwnedSlotValue(cgPropertyAssignment)); + CGValuedElement cgInit = cg2javaVisitor.getExpression(QVTiCGUtil.getOwnedInitValue(cgPropertyAssignment)); + if (isIncremental || ((SetStatement)cgPropertyAssignment.getAst()).isIsNotify()) { + QVTiGlobalNameManager globalNameManager = cg2javaVisitor.getGlobalNameManager(); + js.appendName(globalNameManager.getObjectManagerName()); + js.append(".assigned("); + if (isIncremental) { + cg2javaVisitor.appendThis(cgPropertyAssignment); + js.append(", "); + } + js.appendValueName(cgSlot); + js.append(", "); + cg2javaVisitor.appendQualifiedLiteralName(eStructuralFeature); + js.append(", "); + js.appendValueName(cgInit); + js.append(", "); + js.appendBooleanString(eStructuralFeature.isMany() && isPartial); + js.append(");\n"); + } + } + + @Override + public boolean generateJavaAssignment(@NonNull CG2JavaVisitor cg2javaVisitor, @NonNull CGPropertyAssignment cgPropertyAssignment) { + CGEcorePropertyAssignment cgEcorePropertyAssignment = (CGEcorePropertyAssignment)cgPropertyAssignment; + JavaStream js = cg2javaVisitor.getJavaStream(); + QVTiCG2JavaVisitor qvticg2javaVisitor = (QVTiCG2JavaVisitor)cg2javaVisitor; + QVTiCodeGenerator codeGenerator = qvticg2javaVisitor.getCodeGenerator(); + Property asProperty = QVTiCGUtil.getAsProperty(cgPropertyAssignment); + assert !asProperty.isIsImplicit(); + CGValuedElement slotValue = QVTiCGUtil.getOwnedSlotValue(cgPropertyAssignment); + CGValuedElement initValue = QVTiCGUtil.getOwnedInitValue(cgPropertyAssignment); + Map<@NonNull Property, @NonNull String> oppositeProperties = codeGenerator.getOppositeProperties(); + if (oppositeProperties != null) { + String cacheName = oppositeProperties.get(asProperty); + if (cacheName != null) { + TypeDescriptor outerTypeDescriptor = codeGenerator.getBoxedDescriptor(asProperty.getOwningClass().getTypeId()); + TypeDescriptor middleTypeDescriptor = codeGenerator.getBoxedDescriptor(PivotUtil.getElementalType(PivotUtil.getType(asProperty)).getTypeId()); + js.append(cacheName); + js.append(".put("); + js.appendReferenceTo(middleTypeDescriptor, initValue); + js.append(", "); + js.appendReferenceTo(outerTypeDescriptor, slotValue); + js.append(");\n"); + } + } + SetStatement asSetStatement = QVTiCGUtil.getAST(cgPropertyAssignment); + EStructuralFeature eStructuralFeature = QVTiCGUtil.getEStructuralFeature(cgEcorePropertyAssignment); + CGValuedElement cgSlot = cg2javaVisitor.getExpression(slotValue); + CGValuedElement cgInit = cg2javaVisitor.getExpression(initValue); + // Class<?> requiredJavaClass = requiredTypeDescriptor.getJavaClass(); + // Method leastDerivedMethod = requiredJavaClass != null ? getLeastDerivedMethod(requiredJavaClass, getAccessor) : null; + // Class<?> unboxedSourceClass = leastDerivedMethod != null ? leastDerivedMethod.getDeclaringClass() : requiredJavaClass; + boolean isPartial = asSetStatement.isIsPartial(); + appendEcoreSet(cg2javaVisitor, cgSlot, eStructuralFeature, cgInit, isPartial); + doAssigned(qvticg2javaVisitor, cgEcorePropertyAssignment, isPartial); + return true; + } + @Override public boolean generateJavaCall(@NonNull CG2JavaVisitor cg2javaVisitor, @NonNull CGNavigationCallExp cgPropertyCallExp) { CGEcorePropertyCallExp cgEcorePropertyCallExp = (CGEcorePropertyCallExp)cgPropertyCallExp; @@ -102,4 +221,22 @@ public class QVTiEcorePropertyCallingConvention extends EcorePropertyCallingConv qvticg2javaVisitor.doGot(cgPropertyCallExp, cgSource, eStructuralFeature); return status; } + + @Override + public void rewriteWithBoxingAndGuards(@NonNull BoxingAnalyzer boxingAnalyzer, @NonNull CGPropertyAssignment cgPropertyAssignment) { + CGEcorePropertyAssignment cgEcorePropertyAssignment = (CGEcorePropertyAssignment)cgPropertyAssignment; + SetStatement asSetStatement = QVTiCGUtil.getAST(cgPropertyAssignment); + ImperativeTransformation asTransformation = QVTimperativeUtil.getContainingTransformation(asSetStatement); + EntryPointsAnalysis entryPointsAnalysis = ((QVTiCodeGenerator)boxingAnalyzer.getCodeGenerator()).getEntryPointsAnalysis(asTransformation); + Integer cacheIndex = entryPointsAnalysis.getCacheIndex(asSetStatement); + if (cacheIndex != null) { // If a middle property assignment + EStructuralFeature eStructuralFeature = cgEcorePropertyAssignment.getEStructuralFeature(); + assert eStructuralFeature instanceof EReference; + assert ((EReference)eStructuralFeature).getEOpposite() == null; + boxingAnalyzer.rewriteAsUnboxed(cgEcorePropertyAssignment.getOwnedSlotValue()); + boxingAnalyzer.rewriteAsUnboxed(cgEcorePropertyAssignment.getOwnedInitValue()); + // XXX is it really appropriate to rewriteAsEcore in super ? + } + super.rewriteWithBoxingAndGuards(boxingAnalyzer, cgPropertyAssignment); + } } 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 ff260f760..1c0699df2 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 @@ -38,8 +38,6 @@ import org.eclipse.ocl.examples.codegen.cgmodel.CGAccumulator; import org.eclipse.ocl.examples.codegen.cgmodel.CGCachedOperation; import org.eclipse.ocl.examples.codegen.cgmodel.CGClass; import org.eclipse.ocl.examples.codegen.cgmodel.CGCollectionExp; -import org.eclipse.ocl.examples.codegen.cgmodel.CGEcoreContainerAssignment; -import org.eclipse.ocl.examples.codegen.cgmodel.CGEcorePropertyAssignment; import org.eclipse.ocl.examples.codegen.cgmodel.CGElement; import org.eclipse.ocl.examples.codegen.cgmodel.CGElementId; import org.eclipse.ocl.examples.codegen.cgmodel.CGExecutorType; @@ -102,7 +100,6 @@ import org.eclipse.qvtd.codegen.qvticgmodel.CGMappingCall; import org.eclipse.qvtd.codegen.qvticgmodel.CGMappingCallBinding; import org.eclipse.qvtd.codegen.qvticgmodel.CGMappingExp; import org.eclipse.qvtd.codegen.qvticgmodel.CGMappingLoop; -import org.eclipse.qvtd.codegen.qvticgmodel.CGMiddlePropertyAssignment; import org.eclipse.qvtd.codegen.qvticgmodel.CGRealizedVariable; import org.eclipse.qvtd.codegen.qvticgmodel.CGRealizedVariablePart; import org.eclipse.qvtd.codegen.qvticgmodel.CGSpeculateExp; @@ -126,7 +123,6 @@ import org.eclipse.qvtd.pivot.qvtimperative.MappingParameterBinding; import org.eclipse.qvtd.pivot.qvtimperative.NewStatement; import org.eclipse.qvtd.pivot.qvtimperative.NewStatementPart; import org.eclipse.qvtd.pivot.qvtimperative.ObservableStatement; -import org.eclipse.qvtd.pivot.qvtimperative.SetStatement; import org.eclipse.qvtd.pivot.qvtimperative.evaluation.QVTiModelsManager; import org.eclipse.qvtd.pivot.qvtimperative.evaluation.EntryPointAnalysis; import org.eclipse.qvtd.pivot.qvtimperative.evaluation.EntryPointsAnalysis; @@ -242,48 +238,6 @@ public class QVTiCG2JavaVisitor extends AbstractQVTiCG2JavaVisitor js.appendValueName(cgMappingCallBinding.getOwnedValue()); } - protected void appendEcoreSet(@NonNull CGValuedElement cgSlot, @NonNull EStructuralFeature eStructuralFeature, @NonNull CGValuedElement cgInit, boolean isPartial) { - EClassifier eType = eStructuralFeature.getEType(); - String instanceClassName = eType.getInstanceClassName(); - if (eStructuralFeature.isMany()) { - String getAccessor = genModelHelper.getGetAccessor(eStructuralFeature); - // - js.appendValueName(cgSlot); - js.append("."); - js.append(getAccessor); - js.append("()."); - if (isPartial) { - js.append("add("); - if (instanceClassName != null) { - js.appendEcoreValue(instanceClassName, cgInit); - } - else { - js.appendAtomicReferenceTo(cgInit); - } - } - else { - js.append( "addAll("); // FIXME may need to loop addAll manually - js.appendAtomicReferenceTo(cgInit); - } - js.append(");\n"); - } - else { - String setAccessor = genModelHelper.getSetAccessor(eStructuralFeature); - // - js.appendValueName(cgSlot); - js.append("."); - js.append(setAccessor); - js.append("("); - if (instanceClassName != null) { - js.appendEcoreValue(instanceClassName, cgInit); - } - else { - js.appendAtomicReferenceTo(cgInit); - } - js.append(");\n"); - } - } - @Override // FIXME promote to OCL protected void appendGuardFailure(@NonNull CGGuardExp cgGuardExp) { js.append("throw new "); @@ -306,16 +260,8 @@ public class QVTiCG2JavaVisitor extends AbstractQVTiCG2JavaVisitor js.append(cgTypedModel.getName()); } - protected void appendQualifiedLiteralName(@NonNull EStructuralFeature eStructuralFeature) { - EClass eContainingClass = ClassUtil.nonNullState(eStructuralFeature.getEContainingClass()); - EPackage ePackage = ClassUtil.nonNullState(eContainingClass.getEPackage()); - js.appendClassReference(null, genModelHelper.getQualifiedPackageInterfaceName(ePackage)); - js.append(".Literals."); - js.append(genModelHelper.getEcoreLiteralName(eStructuralFeature)); - } - - @Deprecated - protected void appendThis(@NonNull CGElement cgElement) { + @Deprecated // XXX rewrite to exploit 'rootThis' + public void appendThis(@NonNull CGElement cgElement) { for (EObject eObject = cgElement; eObject != null; eObject = eObject.eContainer()) { if (eObject instanceof CGMapping) { // js.appendThis(getMappingName((CGMapping)eObject)); // + ".this" @@ -498,7 +444,7 @@ public class QVTiCG2JavaVisitor extends AbstractQVTiCG2JavaVisitor return allInstancesAnalyses; } - protected void doAssigned(@NonNull CGEcoreContainerAssignment cgPropertyAssignment) { + /* protected void doAssigned(@NonNull CGEcoreContainerAssignment cgPropertyAssignment) { EStructuralFeature eStructuralFeature = QVTiCGUtil.getEStructuralFeature(cgPropertyAssignment); CGValuedElement cgSlot = getExpression(QVTiCGUtil.getOwnedSlotValue(cgPropertyAssignment)); CGValuedElement cgInit = getExpression(QVTiCGUtil.getOwnedInitValue(cgPropertyAssignment)); @@ -516,29 +462,7 @@ public class QVTiCG2JavaVisitor extends AbstractQVTiCG2JavaVisitor js.appendValueName(cgSlot); js.append(", false);\n"); } - } - - protected void doAssigned(@NonNull CGEcorePropertyAssignment cgPropertyAssignment, boolean isPartial) { - EStructuralFeature eStructuralFeature = QVTiCGUtil.getEStructuralFeature(cgPropertyAssignment); - CGValuedElement cgSlot = getExpression(QVTiCGUtil.getOwnedSlotValue(cgPropertyAssignment)); - CGValuedElement cgInit = getExpression(QVTiCGUtil.getOwnedInitValue(cgPropertyAssignment)); - if (isIncremental || ((SetStatement)cgPropertyAssignment.getAst()).isIsNotify()) { - js.appendName(getGlobalNameManager().getObjectManagerName()); - js.append(".assigned("); - if (isIncremental) { - appendThis(cgPropertyAssignment); - js.append(", "); - } - js.appendValueName(cgSlot); - js.append(", "); - appendQualifiedLiteralName(eStructuralFeature); - js.append(", "); - js.appendValueName(cgInit); - js.append(", "); - js.appendBooleanString(eStructuralFeature.isMany() && isPartial); - js.append(");\n"); - } - } + } */ private void doAssigned(@NonNull CGGuardVariable cgGuardVariable, @NonNull EStructuralFeature eStructuralFeature, CGValuedElement cgInit) { CGValuedElement cgSlot = cgGuardVariable; @@ -2333,7 +2257,7 @@ public class QVTiCG2JavaVisitor extends AbstractQVTiCG2JavaVisitor return Boolean.TRUE; } - @Override + /* @Override public @NonNull Boolean visitCGEcoreContainerAssignment(@NonNull CGEcoreContainerAssignment cgPropertyAssignment) { // Property referredProperty = cgPropertyAssignment.getReferredProperty(); // Property pivotProperty = cgPropertyCallExp.getReferredProperty(); @@ -2374,10 +2298,28 @@ public class QVTiCG2JavaVisitor extends AbstractQVTiCG2JavaVisitor } doAssigned(cgPropertyAssignment); return Boolean.TRUE; - } + } */ - @Override + /* @Override public @NonNull Boolean visitCGEcorePropertyAssignment(@NonNull CGEcorePropertyAssignment cgPropertyAssignment) { + Property pReferredProperty = QVTiCGUtil.getAsProperty(cgPropertyAssignment); + assert !pReferredProperty.isIsImplicit(); + CGValuedElement slotValue = QVTiCGUtil.getOwnedSlotValue(cgPropertyAssignment); + CGValuedElement initValue = QVTiCGUtil.getOwnedInitValue(cgPropertyAssignment); + Map<@NonNull Property, @NonNull String> oppositeProperties = getCodeGenerator().getOppositeProperties(); + if (oppositeProperties != null) { + String cacheName = oppositeProperties.get(pReferredProperty); + if (cacheName != null) { + TypeDescriptor outerTypeDescriptor = context.getBoxedDescriptor(pReferredProperty.getOwningClass().getTypeId()); + TypeDescriptor middleTypeDescriptor = context.getBoxedDescriptor(PivotUtil.getElementalType(PivotUtil.getType(pReferredProperty)).getTypeId()); + js.append(cacheName); + js.append(".put("); + js.appendReferenceTo(middleTypeDescriptor, initValue); + js.append(", "); + js.appendReferenceTo(outerTypeDescriptor, slotValue); + js.append(");\n"); + } + } // Property referredProperty = cgPropertyAssignment.getReferredProperty(); // Property pivotProperty = cgPropertyCallExp.getReferredProperty(); // CGTypeId cgTypeId = analyzer.getTypeId(pivotProperty.getOwningType().getTypeId()); @@ -2400,7 +2342,7 @@ public class QVTiCG2JavaVisitor extends AbstractQVTiCG2JavaVisitor appendEcoreSet(cgSlot, eStructuralFeature, cgInit, isPartial); doAssigned(cgPropertyAssignment, isPartial); return Boolean.TRUE; - } + } */ @Override public @NonNull Boolean visitCGEcoreRealizedVariable(@NonNull CGEcoreRealizedVariable cgRealizedVariable) { @@ -2688,7 +2630,7 @@ public class QVTiCG2JavaVisitor extends AbstractQVTiCG2JavaVisitor return Boolean.TRUE; } - @Override + /* @Override public @NonNull Boolean visitCGMiddlePropertyAssignment(@NonNull CGMiddlePropertyAssignment cgMiddlePropertyAssignment) { Property pReferredProperty = QVTiCGUtil.getAsProperty(cgMiddlePropertyAssignment); assert !pReferredProperty.isIsImplicit(); @@ -2709,7 +2651,7 @@ public class QVTiCG2JavaVisitor extends AbstractQVTiCG2JavaVisitor } } return visitCGEcorePropertyAssignment(cgMiddlePropertyAssignment); - } + } */ @Override public @NonNull Boolean visitCGRealizedVariable(@NonNull CGRealizedVariable cgRealizedVariable) { 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 64f624964..fef4d5aff 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 @@ -16,7 +16,6 @@ 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.CGEcoreContainerAssignment; import org.eclipse.ocl.examples.codegen.cgmodel.CGEcorePropertyAssignment; import org.eclipse.ocl.examples.codegen.cgmodel.CGEcorePropertyCallExp; import org.eclipse.ocl.examples.codegen.cgmodel.CGElement; @@ -165,10 +164,6 @@ public class QVTiCGUtil extends CGUtil return ClassUtil.nonNullState(basicGetContainingCGTransformation(cgElement)); } - public static @NonNull EStructuralFeature getEStructuralFeature(@NonNull CGEcoreContainerAssignment cgContainerAssignment) { - return ClassUtil.nonNullState(cgContainerAssignment.getEStructuralFeature()); - } - public static @NonNull EStructuralFeature getEStructuralFeature(@NonNull CGEcorePropertyAssignment cgPropertyAssignment) { return ClassUtil.nonNullState(cgPropertyAssignment.getEStructuralFeature()); } |