0
votes

I am facing a problem and I am kind of desesperate :

I am trying to transform a constraint OCL into a C# program. To do so, I define my ocl constraints in a CompleteOCL document, and I save it as Abstract Syntax : POC.ocl.oclas. Then I use Acceleo with the Pivot Meta-model ('http://www.eclipse.org/ocl/2015/Pivot').

However, common OCL operations (such as 'size') are defined in another model : the Library. So when I try to recover operations used on my OCL model, nothing happened, I can only recover the operation I defined in my ocl document.

When I opened POC.ocl.oclas, I have these 2 models : POC.ocl model + Library model.

I defined these generation :

[comment encoding = UTF-8 /]
[module generate('http://www.eclipse.org/ocl/2015/Pivot','http://www.eclipse.org/ocl/2015/Library')]

[template public generateElement(aModel : Model)]
[comment @main/]
[file (aModel.name + 'xx', false, 'UTF-8')]
yo
[/file]
[/template]

And it only generate one file : "POC.oclxx", not "Library.oclxx"

That lead us to this question : Is it possible in Acceleo to make a reference to another model (than the main one) ? And if it is, how to do that ?


ANNEXE :

The code I wrote :

[comment getCode() opération/]
[template public getCode(operationCallExp : pivot::OperationCallExp) post (trim())]
[operationCallExp.ownedSource.getCode()/] 
[operationCallExp.referredOperation.name/][operationCallExp.ownedArguments -> getArguments()/]
[/template]

In theory, [operationCallExp.referredOperation.name/] gives me the name of the operation. In reality, it gives me nothing, except when I defined the operation (and thus when the operation doesn't come from the OCL Library)

Thank you in advance !


The zipped projet : Archive_OCL_Acceleo

The POC folder contains POC metamodel (POC.ecore), OCL constraint on this metamodel (POC.ocl) and the Pivot model associate (POC.ocl.oclas). Files generated by Acceleo are in the files folder

The POC_Acceleo forlder contains the Acceleo transformation (generate.mtl)

2

2 Answers

0
votes

From the *.oclas file extension, I take it that you are using the/my Pivot-based Eclipse OCL Abstract Syntax.

My first attempt at Java code generation from OCL used Acceleo, but I abandoned this for various reasons, not least of which is that the step from OCL AS to Java code is far too big to perform in a single M2T step. While Java (and no doubt C#) is deceptively similar to OCL making a simple text template-driven translation attractive, that approach is doomed to support only a modest language subset. Real code generation needs real analyses such as Common Subexpression Elimination and these introduce a conflict between preserved source and rewritten source, if you rewrite the source.

The current Eclipse OCL to Java Generator (my third attempt) uses an intermediate CG model where rewrites happen. It is intended to be retargetable to C (or C# or ...). I have many plans for a higher level of auto-generation in my next (fourth) attempt with a further Java (or C or C# or ...) intermediate model to separate the 'trivial' textual language serialization from the non-trivial language concept synthesis.

If you are interested in a serious rather than simplified example tool for C# generation, I strongly recommend you look at the Eclipse OCL CG. If you want to work collaboratively to making it better and are happy to make you contributions available under the EPL, then perhaps we can arrange something.

0
votes

Are you using the latest code? I recall fixing a couple of bugs recently regarding missing 'cosmetic' AS model content.