diff options
author | Ed Willink | 2022-06-23 15:46:32 +0000 |
---|---|---|
committer | Ed Willink | 2023-02-19 09:54:37 +0000 |
commit | 3dc799fa128f1bc5d3c8c579db172060e9ab7829 (patch) | |
tree | d08782cb332bff973bc7ff21cb2fd325b1e689c1 | |
parent | 14fcc5080f9194a3f3306c6dc97d34577909af2e (diff) | |
download | org.eclipse.qvtd-3dc799fa128f1bc5d3c8c579db172060e9ab7829.tar.gz org.eclipse.qvtd-3dc799fa128f1bc5d3c8c579db172060e9ab7829.tar.xz org.eclipse.qvtd-3dc799fa128f1bc5d3c8c579db172060e9ab7829.zip |
[580264] Add InternalFunctionOperationCallingConvention test
11 files changed, 193 insertions, 83 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 2b9933825..e216fcdd9 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 @@ -75,6 +75,7 @@ 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.qvti.java.QVTiNestedNameManager; import org.eclipse.qvtd.codegen.qvticgmodel.CGConnectionAssignment; import org.eclipse.qvtd.codegen.qvticgmodel.CGConnectionVariable; import org.eclipse.qvtd.codegen.qvticgmodel.CGEcoreContainerAssignment; @@ -438,7 +439,7 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit cgMapping = QVTiCGModelFactory.eINSTANCE.createCGMapping(); cgMapping.setAst(asMapping); globalNameManager.declareGlobalName(cgMapping, asMapping.getName()); - analyzer.addMapping(asMapping, cgMapping); + analyzer.addCGMapping(cgMapping); } return cgMapping; } @@ -447,7 +448,8 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit public @NonNull CGOperation generateOperationDeclaration(@Nullable Type asSourceType, @NonNull Operation asOperation, boolean requireFinal) { if (!requireFinal && (asOperation instanceof Function)) { // XXX ??? eliminate override Function asFunction = (Function)asOperation; - CGFunction cgFunction = (CGFunction)analyzer.basicGetCGOperation(asFunction); + QVTiAnalyzer analyzer = getAnalyzer(); + CGFunction cgFunction = analyzer.basicGetCGFunction(asFunction); if (cgFunction == null) { CGClass cgClass = analyzer.getCGClass(PivotUtil.getOwningClass(asOperation)); pushClassNameManager(cgClass); @@ -460,9 +462,9 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit // analyzer.installOperation(asOperation, cgFunction, callingConvention); pushNestedNameManager(cgFunction); callingConvention.createCGParameters(this, cgFunction, (ExpressionInOCL)asFunction.getBodyExpression()); - getAnalyzer().addFunction(asFunction, cgFunction); - popNameManager(); - popNameManager(); + analyzer.addCGFunction(cgFunction); + popNestedNameManager(); + popClassNameManager(); } return cgFunction; } @@ -573,7 +575,7 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit if (cgFunctionParameter == null) { cgFunctionParameter = QVTiCGModelFactory.eINSTANCE.createCGFunctionParameter(); cgFunctionParameter.setAst(asFunctionParameter); - cgFunctionParameter.setTypeId(analyzer.getCGTypeId(asFunctionParameter.getTypeId())); + // cgFunctionParameter.setTypeId(analyzer.getCGTypeId(asFunctionParameter.getTypeId())); // nameManager.declarePreferredName(cgFunctionParameter); cgFunctionParameter.setTypeId(analyzer.getCGTypeId(asFunctionParameter.getTypeId())); if (asFunctionParameter.isIsRequired()) { @@ -611,6 +613,11 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit // return (QVTiLocalContext)super.getLocalContext(); // } + @Override + public @NonNull QVTiNestedNameManager getNameManager() { + return (QVTiNestedNameManager)super.getNameManager(); + } + public @NonNull CGRealizedVariable getRealizedVariable(@NonNull NewStatement asNewStatement) { QVTiAnalyzer analyzer = getAnalyzer(); NestedNameManager nameManager = getNameManager(); @@ -1070,7 +1077,7 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit } // analyzer.addFunction(asFunction, cgFunction); */ - popNameManager(); + popNestedNameManager(); return cgFunction; } @@ -1142,7 +1149,7 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit CGOperation cgOperation = doVisit(CGOperation.class, asOperation); cgTransformation.getOperations().add(cgOperation); } - popNameManager(); + popClassNameManager(); return cgTransformation; } @@ -1183,7 +1190,7 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit cgFreeVariables.clear(); cgFreeVariables.addAll(sortedVariables); bodyBuilder = null; - popNameManager(); + popNestedNameManager(); return cgMapping; } @@ -1238,7 +1245,7 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit cgMappingStatements.add(cgMappingStatement); } cgMappingLoop.setBody(cgSequence); - popNameManager(); + popNestedNameManager(); return cgMappingLoop; } @@ -1487,7 +1494,7 @@ public class QVTiAS2CGVisitor extends AS2CGVisitor implements QVTimperativeVisit CGTypedModel cgTypedModel = QVTiCGModelFactory.eINSTANCE.createCGTypedModel(); cgTypedModel.setAst(asTypedModel); globalNameManager.declareGlobalName(cgTypedModel, asTypedModel.getName()); - getAnalyzer().addTypedModel(asTypedModel, cgTypedModel); + getAnalyzer().addCGTypedModel(cgTypedModel); return cgTypedModel; } 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 ee16a3e20..25aa368e9 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 @@ -16,13 +16,17 @@ import java.util.Map; import org.eclipse.jdt.annotation.NonNull; import org.eclipse.jdt.annotation.Nullable; import org.eclipse.ocl.examples.codegen.analyzer.CodeGenAnalyzer; +import org.eclipse.ocl.examples.codegen.cgmodel.CGCachedOperation; +import org.eclipse.ocl.examples.codegen.cgmodel.CGOperation; import org.eclipse.ocl.examples.codegen.cgmodel.CGTypeId; +import org.eclipse.ocl.pivot.Operation; import org.eclipse.ocl.pivot.Type; import org.eclipse.ocl.pivot.ids.TypeId; import org.eclipse.qvtd.codegen.qvti.java.QVTiCodeGenerator; import org.eclipse.qvtd.codegen.qvticgmodel.CGFunction; import org.eclipse.qvtd.codegen.qvticgmodel.CGMapping; import org.eclipse.qvtd.codegen.qvticgmodel.CGTypedModel; +import org.eclipse.qvtd.codegen.utilities.QVTiCGUtil; import org.eclipse.qvtd.pivot.qvtbase.Function; import org.eclipse.qvtd.pivot.qvtbase.TypedModel; import org.eclipse.qvtd.pivot.qvtimperative.ImperativeTransformation; @@ -31,9 +35,9 @@ import org.eclipse.qvtd.pivot.qvtimperative.utilities.QVTimperativeUtil; public class QVTiAnalyzer extends CodeGenAnalyzer { - private final @NonNull Map<@NonNull Function, @NonNull CGFunction> cgFunctions = new HashMap<>(); - private final @NonNull Map<@NonNull Mapping, @NonNull CGMapping> cgMappings = new HashMap<>(); - private final @NonNull Map<@NonNull TypedModel, @NonNull CGTypedModel> cgTypedModels = new HashMap<>(); + private final @NonNull Map<@NonNull Function, @NonNull CGFunction> asFunction2cgFunctions = new HashMap<>(); + private final @NonNull Map<@NonNull Mapping, @NonNull CGMapping> asMapping2cgMapping = new HashMap<>(); + private final @NonNull Map<@NonNull TypedModel, @NonNull CGTypedModel> asTypedModel2cgTypedModel = new HashMap<>(); private final @Nullable TypeId originalThisTypeId; private final @NonNull TypeId runtimeThisTypeId; @@ -51,20 +55,38 @@ public class QVTiAnalyzer extends CodeGenAnalyzer } } - public void addFunction(@NonNull Function pFunction, @NonNull CGFunction cgFunction) { - cgFunctions.put(pFunction, cgFunction); + public void addCGFunction(@NonNull CGFunction cgFunction) { + asFunction2cgFunctions.put(QVTiCGUtil.getAST(cgFunction), cgFunction); } - public void addMapping(@NonNull Mapping pMapping, @NonNull CGMapping cgMapping) { - cgMappings.put(pMapping, cgMapping); + public void addCGMapping(@NonNull CGMapping cgMapping) { + asMapping2cgMapping.put(QVTiCGUtil.getAST(cgMapping), cgMapping); } - public void addTypedModel(@NonNull TypedModel pTypedModel, @NonNull CGTypedModel cgTypedModel) { - cgTypedModels.put(pTypedModel, cgTypedModel); + @Override + public void addCGOperation(@NonNull CGOperation cgOperation) { + super.addCGOperation(cgOperation); + if (cgOperation instanceof CGFunction) { + addCGFunction((CGFunction)cgOperation); + } + } + + public void addCGTypedModel(@NonNull CGTypedModel cgTypedModel) { + asTypedModel2cgTypedModel.put(QVTiCGUtil.getAST(cgTypedModel), cgTypedModel); + } + + @Override + public void addVirtualCGOperation(@NonNull Operation asOperation, @NonNull CGCachedOperation cgOperation) { + super.addVirtualCGOperation(asOperation, cgOperation); + // XXX virtual functions + } + + public @Nullable CGFunction basicGetCGFunction(@NonNull Function asFunction) { + return asFunction2cgFunctions.get(asFunction); } - public @Nullable CGMapping basicGetCGMapping(@NonNull Mapping pMapping) { - return cgMappings.get(pMapping); + public @Nullable CGMapping basicGetCGMapping(@NonNull Mapping asMapping) { + return asMapping2cgMapping.get(asMapping); } @Override @@ -72,8 +94,8 @@ public class QVTiAnalyzer extends CodeGenAnalyzer return (QVTiCodeGenerator) super.getCodeGenerator(); } - public @Nullable CGFunction getFunction(@NonNull Function pFunction) { - return cgFunctions.get(pFunction); + public @Nullable CGFunction getCGFunction(@NonNull Function asFunction) { + return asFunction2cgFunctions.get(asFunction); } @Override @@ -86,7 +108,7 @@ public class QVTiAnalyzer extends CodeGenAnalyzer } } - public @Nullable CGTypedModel getTypedModel(@NonNull TypedModel pTypedModel) { - return cgTypedModels.get(pTypedModel); + public @Nullable CGTypedModel getTypedModel(@NonNull TypedModel asTypedModel) { + return asTypedModel2cgTypedModel.get(asTypedModel); } } diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/FunctionOperationCallingConvention.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/FunctionOperationCallingConvention.java index 0c92e6667..c370f8737 100644 --- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/FunctionOperationCallingConvention.java +++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvti/java/FunctionOperationCallingConvention.java @@ -36,6 +36,8 @@ 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.examples.codegen.java.JavaStream.SubStream; +import org.eclipse.ocl.examples.codegen.java.types.AbstractDescriptor; +import org.eclipse.ocl.examples.codegen.java.types.EObjectDescriptor; import org.eclipse.ocl.examples.codegen.utilities.CGUtil; import org.eclipse.ocl.pivot.Operation; import org.eclipse.ocl.pivot.Parameter; @@ -363,7 +365,7 @@ public abstract class FunctionOperationCallingConvention extends AbstractOperati } js.append("public "); js.append(functionName); - js.append("(/*Nullable*/ Object "); + js.append("(/*@Nullable*/ Object "); js.appendIsRequired(true); js.append(" [] boundValues) {\n"); js.pushIndentation(null); @@ -378,29 +380,68 @@ public abstract class FunctionOperationCallingConvention extends AbstractOperati // js.append(")boundValues[0];\n"); int i = 0; for (@NonNull CGParameter cgParameter : cgParameters) { - String valueName = qvticg2javaVisitor.getResolvedName(cgParameter); - js.appendThis(functionName); - js.append("."); - js.append(valueName); - js.append(" = "); int finalI = i++; - if (cgParameter.getNameResolution() == thisTransformerNameResolution) { + if (cgParameter.getNameResolution() == thisTransformerNameResolution) { // XXX Is this irregularity really necessary + String valueName = qvticg2javaVisitor.getResolvedName(cgParameter); + js.appendThis(functionName); + js.append("."); + js.append(valueName); + js.append(" = "); js.append("("); js.appendIsRequired(true); js.append(" "); js.append(cgClass.getName()); js.append(")boundValues[" + finalI + "]"); + js.append(";\n"); } else { - SubStream castBody = new SubStream() { + SubStream castBody1 = new SubStream() { @Override public void append() { js.append("boundValues[" + finalI + "]"); } }; - js.appendClassCast(cgParameter, castBody); + String valueName = qvticg2javaVisitor.getResolvedName(cgParameter); + /// js.appendTypeDeclaration(cgParameter); + // TypeRepresentation boxedTypeRepresentation = js.getBoxedTypeRepresentation(); + // boxedTypeRepresentation.appendTypeDeclaration(cgParameter); // FIXME this doesn't enforce boxed if cgElement is primitive + Boolean isRequired = codeGenerator.isRequired(cgParameter); + js.appendIsCaught(cgParameter.isNonInvalid(), cgParameter.isCaught()); + js.append(" "); + // boxedTypeRepresentation.appendClassReference(isRequired, cgParameter); + assert cgParameter != null; + assert !cgParameter.getNamedValue().isCaught(); + ElementId elementId = cgParameter.getTypeId().getElementId(); + TypeDescriptor boxedTypeDescriptor = codeGenerator.getBoxedDescriptor(elementId); + if ((cgParameter instanceof CGParameter) && (cgParameter.eContainer() instanceof CGOperation) && (boxedTypeDescriptor instanceof EObjectDescriptor)) { // FIXME eliminate reclassing + Class<?> originalJavaClass = ((EObjectDescriptor)boxedTypeDescriptor).getOriginalJavaClass(); + js.appendClassReference(isRequired, originalJavaClass); + } + else { + boxedTypeDescriptor.append(js, isRequired); + } + js.append(" "); + js.append(valueName); + js.append(" = "); + // js.appendClassCast(cgParameter, castBody1); + boxedTypeDescriptor.appendCast(js, isRequired, null, castBody1); + js.append(";\n"); + SubStream castBody2 = new SubStream() { + @Override + public void append() { + js.append(valueName); + } + }; + js.appendThis(functionName); // XXX Not needed. This is precisely "this" + js.append("."); + js.append(valueName); + js.append(" = "); + // js.appendClassCast(cgParameter, castBody2); + assert cgParameter != null; + AbstractDescriptor declaredTypeDescriptor = (AbstractDescriptor) codeGenerator.getTypeDescriptor(cgParameter); + declaredTypeDescriptor.appendCast(js, isRequired, declaredTypeDescriptor.getNonPrimitiveJavaClass(), castBody2); + js.append(";\n"); } - js.append(";\n"); } doFunctionBody3(qvticg2javaVisitor, js, cgFunction); js.popIndentation(); @@ -607,7 +648,7 @@ public abstract class FunctionOperationCallingConvention extends AbstractOperati assert asShadowExp == null; // ShadowFunctionOperationCallingConvention overload if (!asFunction.isIsTransient()) { NameResolution thisTransformerNameResolution = codeGenerator.getGlobalNameManager().getThisTransformerNameResolution(); - String thisTransformerName = thisTransformerNameResolution.getResolvedName(); + // String thisTransformerName = thisTransformerNameResolution.getResolvedName(); CGClass cgClass = ClassUtil.nonNullState(CGUtil.getContainingClass(cgFunction)); js.append("protected class "); js.append(functionName); 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 2b0a6ab8e..01aa9e08a 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 @@ -84,25 +84,21 @@ public class InternalFunctionOperationCallingConvention extends FunctionOperatio } @Override - public @NonNull CGOperation createCGOperation( - @NonNull AS2CGVisitor as2cgVisitor, @Nullable Type asSourceType, - @NonNull Operation asOperation) { - // TODO Auto-generated method stub + public @NonNull CGOperation createCGOperation(@NonNull AS2CGVisitor as2cgVisitor, @Nullable Type asSourceType, @NonNull Operation asOperation) { 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) { + assert cgSource != null; QVTiAS2CGVisitor qvtias2cgVisitor = (QVTiAS2CGVisitor)as2cgVisitor; - QVTiCodeGenerator codeGenerator = qvtias2cgVisitor.getCodeGenerator(); CGFunction cgFunction = (CGFunction)cgOperation; + QVTiCodeGenerator codeGenerator = qvtias2cgVisitor.getCodeGenerator(); Function asFunction = QVTiCGUtil.getAST(cgFunction); - boolean useClassToCreateObject = codeGenerator.getShadowExp(asFunction) != null; + assert codeGenerator.getShadowExp(asFunction) == null; CGFunctionCallExp cgFunctionCallExp = QVTiCGModelFactory.eINSTANCE.createCGFunctionCallExp(); initCallExp(as2cgVisitor, cgFunctionCallExp, asOperationCallExp, cgOperation, asFunction.isIsRequired()); - assert !useClassToCreateObject; - assert cgSource != null; cgFunctionCallExp.getArguments().add(cgSource); initCallArguments(as2cgVisitor, cgFunctionCallExp); return cgFunctionCallExp; @@ -115,7 +111,7 @@ public class InternalFunctionOperationCallingConvention extends FunctionOperatio CGFunction cgFunction = (CGFunction)cgOperation; Function asFunction = QVTiCGUtil.getAST(cgFunction); assert codeGenerator.getShadowExp(asFunction) == null; - QVTiNestedNameManager nameManager = (QVTiNestedNameManager)qvtias2cgVisitor.getNameManager(); + QVTiNestedNameManager nameManager = 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)) { @@ -125,32 +121,25 @@ public class InternalFunctionOperationCallingConvention extends FunctionOperatio } @Override - public boolean generateJavaCall(@NonNull CG2JavaVisitor cg2javaVisitor, - @NonNull JavaStream js, - @NonNull CGOperationCallExp cgOperationCallExp) { - // TODO Auto-generated method stub + public boolean generateJavaCall(@NonNull CG2JavaVisitor cg2javaVisitor, @NonNull JavaStream js, @NonNull CGOperationCallExp cgOperationCallExp) { return super.generateJavaCall(cg2javaVisitor, js, cgOperationCallExp); } @Override - public boolean generateJavaDeclaration( - @NonNull CG2JavaVisitor cg2javaVisitor, @NonNull JavaStream js, - @NonNull CGOperation cgOperation) { - // TODO Auto-generated method stub + public boolean generateJavaDeclaration(@NonNull CG2JavaVisitor cg2javaVisitor, @NonNull JavaStream js, @NonNull CGOperation cgOperation) { return super.generateJavaDeclaration(cg2javaVisitor, js, cgOperation); } @Override - public void rewriteWithBoxingAndGuards( - @NonNull BoxingAnalyzer boxingAnalyzer, - @NonNull CGOperation cgOperation) { - // TODO Auto-generated method stub + public void rewriteWithBoxingAndGuards(@NonNull BoxingAnalyzer boxingAnalyzer, @NonNull CGOperation cgOperation) { super.rewriteWithBoxingAndGuards(boxingAnalyzer, cgOperation); + CGValuedElement cgBody = CGUtil.getBody(cgOperation); + boxingAnalyzer.rewriteAsBoxed(cgBody); } @Override public void rewriteWithBoxingAndGuards(@NonNull BoxingAnalyzer boxingAnalyzer,@NonNull CGOperationCallExp cgOperationCallExp) { - for (CGValuedElement cgArgument : cgOperationCallExp.getArguments()) { + for (@NonNull CGValuedElement cgArgument : CGUtil.getArguments(cgOperationCallExp)) { 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 6be0a4ea5..e4f304626 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 @@ -186,7 +186,7 @@ public class QVTiCodeGenerator extends JavaCodeGenerator assert cgPackage != null; as2cgVisitor.pushClassNameManager(cgTransformation); cgAnalyzer.analyzeExternalFeatures(as2cgVisitor); - as2cgVisitor.popNameManager(); + as2cgVisitor.popClassNameManager(); return cgPackage; } diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvticgmodel/utilities/QVTiCGModelAnalysisVisitor.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvticgmodel/utilities/QVTiCGModelAnalysisVisitor.java index c2ccdf289..c6b816c2a 100644 --- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvticgmodel/utilities/QVTiCGModelAnalysisVisitor.java +++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvticgmodel/utilities/QVTiCGModelAnalysisVisitor.java @@ -31,9 +31,9 @@ public class QVTiCGModelAnalysisVisitor extends AbstractQVTiCGModelAnalysisVisit @Override public Object visitCGFunctionCallExp(@NonNull CGFunctionCallExp cgFunctionCallExp) { - Function pFunction = (Function) ((OperationCallExp)cgFunctionCallExp.getAst()).getReferredOperation(); - if (pFunction != null) { - CGFunction cgFunction = ((QVTiAnalyzer)context).getFunction(pFunction); + Function asFunction = (Function) ((OperationCallExp)cgFunctionCallExp.getAst()).getReferredOperation(); + if (asFunction != null) { + CGFunction cgFunction = ((QVTiAnalyzer)context).getCGFunction(asFunction); cgFunctionCallExp.setFunction(cgFunction); } return visitCGOperationCallExp(cgFunctionCallExp); diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvticgmodel/utilities/QVTiCGModelBoxingAnalysisVisitor.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvticgmodel/utilities/QVTiCGModelBoxingAnalysisVisitor.java index 8dc4663bf..8a14337de 100644 --- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvticgmodel/utilities/QVTiCGModelBoxingAnalysisVisitor.java +++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvticgmodel/utilities/QVTiCGModelBoxingAnalysisVisitor.java @@ -22,7 +22,6 @@ import org.eclipse.ocl.pivot.TypedElement; import org.eclipse.qvtd.codegen.qvticgmodel.CGEcoreContainerAssignment; import org.eclipse.qvtd.codegen.qvticgmodel.CGEcorePropertyAssignment; import org.eclipse.qvtd.codegen.qvticgmodel.CGEcoreRealizedVariable; -import org.eclipse.qvtd.codegen.qvticgmodel.CGFunction; import org.eclipse.qvtd.codegen.qvticgmodel.CGMappingCallBinding; import org.eclipse.qvtd.codegen.qvticgmodel.CGMiddlePropertyAssignment; import org.eclipse.qvtd.codegen.qvticgmodel.CGRealizedVariablePart; @@ -82,13 +81,13 @@ public class QVTiCGModelBoxingAnalysisVisitor extends AbstractQVTiCGModelBoxingA return super.visitCGEcoreRealizedVariable(cgEcoreRealizedVariable); } - @Override + /* @Override public @Nullable Object visitCGFunction(@NonNull CGFunction cgFunction) { visitCGOperation(cgFunction); // rewriteAsUnboxed(cgFunction.getBody()); rewriteAsBoxed(cgFunction.getBody()); return null; - } + } */ /* @Override public @Nullable Object visitCGFunctionCallExp(@NonNull CGFunctionCallExp cgFunctionCallExp) { diff --git a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvticgmodel/utilities/QVTiCGModelCG2JavaVisitor.java b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvticgmodel/utilities/QVTiCGModelCG2JavaVisitor.java index 187c38f22..47d0590c4 100644 --- a/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvticgmodel/utilities/QVTiCGModelCG2JavaVisitor.java +++ b/plugins/org.eclipse.qvtd.codegen/src/org/eclipse/qvtd/codegen/qvticgmodel/utilities/QVTiCGModelCG2JavaVisitor.java @@ -2427,7 +2427,7 @@ public class QVTiCGModelCG2JavaVisitor extends AbstractQVTiCGModelCG2JavaVisitor if (asContainer instanceof TypedModel) { Transformation asTransformation = ((TypedModel)asContainer).getTransformation(); if (asTransformation != null) { - int index = asTransformation.getModelParameter().indexOf(asContainer); + int index = asTransformation.getModelParameter().indexOf(asContainer); // XXX is this irregularity still necessary here ? String name = getGlobalNameManager().getModelsName() + "[" + index + "/*" + ((TypedModel)asContainer).getName() + "*/]"; return name; } diff --git a/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/models/callingConventions/CallingConventions.qvtr b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/models/callingConventions/InternalFunctionCallingConvention.qvtr index a3170719d..6692a35fd 100644 --- a/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/models/callingConventions/CallingConventions.qvtr +++ b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/models/callingConventions/InternalFunctionCallingConvention.qvtr @@ -1,17 +1,17 @@ /******************************************************************************* - * Copyright (c) 2017 Willink Transformations and others. + * Copyright (c) 2022 Willink Transformations and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v20.html * * Contributors: - * E.D.Willink - initial implementation for ModelMorf + * E.D.Willink - initial implementation *******************************************************************************/ import myMM : 'Called.ecore'::called; package org::eclipse::qvtd::xtext::qvtrelation::tests::callingConventions { - transformation CallingConventions(from:myMM, to:myMM) + transformation InternalFunctionCallingConvention(from:myMM, to:myMM) { query internalSum(firstValue : ecore::EInt[1], secondValue : ecore::EInt[1]) : ecore::EInt[1] { firstValue + secondValue diff --git a/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/models/callingConventions/LibraryOperationCallingConvention.qvtr b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/models/callingConventions/LibraryOperationCallingConvention.qvtr new file mode 100644 index 000000000..1332cd824 --- /dev/null +++ b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/models/callingConventions/LibraryOperationCallingConvention.qvtr @@ -0,0 +1,26 @@ +/******************************************************************************* + * Copyright (c) 2022 Willink Transformations and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v20.html + * + * Contributors: + * E.D.Willink - initial implementation + *******************************************************************************/ +import myMM : 'Called.ecore'::called; + +package org::eclipse::qvtd::xtext::qvtrelation::tests::callingConventions { + transformation LibraryOperationCallingConvention(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 }; + } + } +}
\ No newline at end of file diff --git a/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java index 29f619dd0..41165f082 100644 --- a/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java +++ b/tests/org.eclipse.qvtd.xtext.qvtrelation.tests/src/org/eclipse/qvtd/xtext/qvtrelation/tests/QVTrCompilerTests.java @@ -651,18 +651,44 @@ public class QVTrCompilerTests extends LoadTestCase } @Test - public void testQVTrCompiler_CallingConventions_CG() throws Exception { - // StandaloneProjectMap.addTrace(EcorePackage.eNS_URI, ~0); - // StandaloneProjectMap.addTrace("http://www.eclipse.org/ocl/2015/Library", ~0); - // Splitter.GROUPS.setState(true); - // Splitter.RESULT.setState(true); - // Splitter.STAGES.setState(true); - // AbstractTransformer.EXCEPTIONS.setState(true); - // AbstractTransformer.INVOCATIONS.setState(true); - // QVTm2QVTp.PARTITIONING.setState(true); - // QVTp2QVTs.REGION_ORDER.setState(true); + public void testQVTrCompiler_InternalFunctionCallingConvention_CG() throws Exception { + Class<? extends Transformer> txClass; + MyQVT myQVT1 = createQVT("InternalFunctionCallingConvention", getModelsURI("callingConventions/InternalFunctionCallingConvention.qvtr")); + myQVT1.addUsedGenPackage("org.eclipse.emf.ecore/model/Ecore.genmodel", "//ecore"); + try { + ProjectManager projectMap = myQVT1.getProjectManager(); + projectMap.configure(myQVT1.getResourceSet(), StandaloneProjectMap.LoadFirstStrategy.INSTANCE, StandaloneProjectMap.MapToFirstConflictHandler.INSTANCE); + TypedModelsConfigurations typedModelsConfigurations = new TypedModelsConfigurations(); + typedModelsConfigurations.add(new TypedModelsConfiguration("to")); + txClass = myQVT1.buildTransformation(typedModelsConfigurations, false); + } + finally { + myQVT1.dispose(); + myQVT1 = null; + } + ThreadLocalExecutor.resetEnvironmentFactory(); + MyQVT myQVT2 = createQVT("InternalFunctionCallingConvention", getModelsURI("InternalFunctionCallingConvention/InternalFunctionCallingConvention.qvtr")); + try { + myQVT2.loadEPackage(txClass, "called.calledPackage"); + myQVT2.loadEPackage(txClass, "trace_InternalFunctionCallingConvention.trace_InternalFunctionCallingConventionPackage"); + // + myQVT2.createGeneratedExecutor(txClass); + myQVT2.addInputURI("from", getModelsURI("callingConventions/samples/testcase1-in.xmi")); + myQVT2.executeTransformation(); + myQVT2.addOutputURI("to", getTestURI("testcase1-out_CG.called")); + myQVT2.saveModels(null); + myQVT2.checkOutput(getTestURI("testcase1-out_CG.called"), getModelsURI("callingConventions/samples/testcase1-out.xmi"), null); + } + finally { + myQVT2.dispose(); + myQVT2 = null; + } + } + + @Test + public void testQVTrCompiler_LibraryOperationCallingConvention_CG() throws Exception { Class<? extends Transformer> txClass; - MyQVT myQVT1 = createQVT("CallingConventions", getModelsURI("callingConventions/CallingConventions.qvtr")); + MyQVT myQVT1 = createQVT("LibraryOperationCallingConvention", getModelsURI("callingConventions/LibraryOperationCallingConvention.qvtr")); myQVT1.addUsedGenPackage("org.eclipse.emf.ecore/model/Ecore.genmodel", "//ecore"); try { ProjectManager projectMap = myQVT1.getProjectManager(); @@ -676,10 +702,10 @@ public class QVTrCompilerTests extends LoadTestCase myQVT1 = null; } ThreadLocalExecutor.resetEnvironmentFactory(); - MyQVT myQVT2 = createQVT("CallingConventions", getModelsURI("CallingConventions/CallingConventions.qvtr")); + MyQVT myQVT2 = createQVT("LibraryOperationCallingConvention", getModelsURI("LibraryOperationCallingConvention/LibraryOperationCallingConvention.qvtr")); try { myQVT2.loadEPackage(txClass, "called.calledPackage"); - myQVT2.loadEPackage(txClass, "trace_CallingConventions.trace_CallingConventionsPackage"); + myQVT2.loadEPackage(txClass, "trace_LibraryOperationCallingConvention.trace_LibraryOperationCallingConventionPackage"); // myQVT2.createGeneratedExecutor(txClass); myQVT2.addInputURI("from", getModelsURI("callingConventions/samples/testcase1-in.xmi")); |