Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Modeling (top-level project) » ANSI-C-model and dealing with redundant references
ANSI-C-model and dealing with redundant references [message #640801] Tue, 23 November 2010 09:05 Go to next message
Tom Brandenburg is currently offline Tom Brandenburg
Messages: 58
Registered: October 2010
Location: Abstatt, Germany
Member
Hello all,

In my current project I want to create some C code out of an UML model. For this I want to use the ANSI-C-Model from the ViPER project. But I think it's a more general topic apart from that.

Please look at the following extract from the ANSI-C-Model:
http://fcg.km23412-02.keymachine.de/ftp/upload/test/composition_example.jpg

Here you can see some type of hierarchy where TranslationElement and ASTElement are abstract and all children of TranslationElement inherit the composition association to itself. Now for complying with the ANSI-C-Standard and for better browsability there is also a composition between DeclSpecifier and FunctionDefinition. So somehow the composition is redundant.

During the model-2-model-transformation a DeclSpecifier is added to the FunctionDefinition explicitly as a DeclSpecifier and not as a nestedElement. The result is that the reference from a DeclSpecifier to a FunctionDefinition is set and not from the nestedElement to the nestingElement. The latter evolves to a problem when the model-2-text transformation want to browse through the model with the following code (found in the ViPER project):

ansic::TranslationUnit getTranslationUnit(ansic::ASTElement element) :
	element.translationUnit != null ? element.translationUnit : element.nestingElement.getTranslationUnit()
;


It returns null when translationUnit is null and the nestingElement reference is missing.

So my question is, how it might be possible to add a DeclSpecifier to a FunctionDefinition and the reference is also added automatically to the nestedElements relation (because it is a nested element but also a DeclSpecifier for the Function Definition). Otherwise I might have to change the code at many location because this problem is not the only one of that kind in the ANSI-C-model. On the other hand I wonder why it does not work with me, whereas the ViPER project is tested and released. Even without the complex m2m and m2t transformations I can simulate that behaviour (which is somehow understandable) with the small sample above and a dynamic instance of it. But I don't to change the implementation of the ViPER plugin.

Btw, the following code adds a DeclSpecifier to a FunctionDefinition:

create ansic::FunctionDefinition d createFunctionDefinition(ansic::DeclSpecifier declSpecifier, ansic::FunctionDeclarator declarator) :
	//let d = new ansic::FunctionDefinition :
		d.setDeclSpecifier(declSpecifier) ->
		d.setFunctionDeclarator(declarator) ->
		d


Where do the set-Functions come from? Is it a feature of EMF to have them automatically as soon as there are references with a 1-to-1-association?

Many thanks in advance and best regards,
Tom
Re: ANSI-C-model and dealing with redundant references [message #640990 is a reply to message #640801] Tue, 23 November 2010 19:00 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26137
Registered: July 2009
Senior Member
Tom,

comments below.


Tom Brandenburg wrote:
> Hello all,
>
> In my current project I want to create some C code out of an UML
> model. For this I want to use the ANSI-C-Model from the ViPER project.
> But I think it's a more general topic apart from that.
>
> Please look at the following extract from the ANSI-C-Model:
>
>
> Here you can see some type of hierarchy where TranslationElement and
> ASTElement are abstract and all children of TranslationElement inherit
> the composition association to itself. Now for complying with the
> ANSI-C-Standard and for better browsability there is also a
> composition between DeclSpecifier and FunctionDefinition. So somehow
> the composition is redundant.
Sounds like UML details best discussed on the UML2 newsgroup...
>
>
> During the model-2-model-transformation a DeclSpecifier is added to
> the FunctionDefinition explicitly as a DeclSpecifier and not as a
> nestedElement. The result is that the reference from a DeclSpecifier
> to a FunctionDefinition is set and not from the nestedElement to the
> nestingElement. The latter evolves to a problem when the model-2-text
> transformation want to browse through the model with the following
> code (found in the ViPER project):
>
> ansic::TranslationUnit getTranslationUnit(ansic::ASTElement element) :
> element.translationUnit != null ? element.translationUnit :
> element.nestingElement.getTranslationUnit()
> ;
>
> It returns null when translationUnit is null and the nestingElement
> reference is missing.
This model-2-model stuff is using what technology?
>
> So my question is, how it might be possible to add a DeclSpecifier to
> a FunctionDefinition and the reference is also added automatically to
> the nestedElements relation (because it is a nested element but also a
> DeclSpecifier for the Function Definition). Otherwise I might have to
> change the code at many location because this problem is not the only
> one of that kind in the ANSI-C-model. On the other hand I wonder why
> it does not work with me, whereas the ViPER project is tested and
> released. Even without the complex m2m and m2t transformations I can
> simulate that behaviour (which is somehow understandable) with the
> small sample above and a dynamic instance of it. But I don't to change
> the implementation of the ViPER plugin.
>
> Btw, the following code adds a DeclSpecifier to a FunctionDefinition:
>
> create ansic::FunctionDefinition d
> createFunctionDefinition(ansic::DeclSpecifier declSpecifier,
> ansic::FunctionDeclarator declarator) :
> //let d = new ansic::FunctionDefinition :
> d.setDeclSpecifier(declSpecifier) ->
> d.setFunctionDeclarator(declarator) ->
> d
>
> Where do the set-Functions come from? Is it a feature of EMF to have
> them automatically as soon as there are references with a
> 1-to-1-association?
Definitely best asked on the UML2 newsgroup. I've added it to the "to"
list of the reply, so no need to repost.
>
> Many thanks in advance and best regards,
> Tom
Re: ANSI-C-model and dealing with redundant references [message #641061 is a reply to message #640801] Wed, 24 November 2010 07:51 Go to previous messageGo to next message
Tom Brandenburg is currently offline Tom Brandenburg
Messages: 58
Registered: October 2010
Location: Abstatt, Germany
Member
Hi Ed,

sorry for maybe failing to assign the right category. I thought that it is a whole modeling project and I don't exactly know where the problem lays, so I inserted it here.

For the model-2-model transformation I have an Ecore-Metamodel of the ANSI-C-Standard and an UML file as an input. For execution I use an MWE workflow which invokes an XTend script. I hope that is what you want to hear Smile

Code for it:
    <!-- Model-2-Model transformation -->
    <component class="org.eclipse.xtend.XtendComponent">
        <metaModel class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
            <metaModelFile value="src/com/bosch/prj/codegen/metamodel/ansic.ecore"/>
        </metaModel>
        <metaModel class="org.eclipse.xtend.typesystem.uml2.UML2MetaModel"/>
        <invoke value="sc::viper::uml2::codegen::uml22ansic::transformation::generic::UMLModel::createModel(model)"/>
        <outputSlot value="model"/>
    </component>


Best regards
Tom
Re: ANSI-C-model and dealing with redundant references [message #641222 is a reply to message #641061] Wed, 24 November 2010 14:54 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26137
Registered: July 2009
Senior Member
Tom,

You've replied only to the modeling newsgroup. I guess you're using the
web UI; don't it let you reply to both group? You'd better start
monitoring the UML2 newsgroup...


Tom Brandenburg wrote:
> Hi Ed,
>
> sorry for maybe failing to assign the right category. I thought that
> it is a whole modeling project and I don't exactly know where the
> problem lays, so I inserted it here.
>
> For the model-2-model transformation I have an Ecore-Metamodel of the
> ANSI-C-Standard and an UML file as an input. For execution I use an
> MWE workflow which invokes an XTend script. I hope that is what you
> want to hear :)
>
> Code for it:
> <!-- Model-2-Model transformation -->
> <component class="org.eclipse.xtend.XtendComponent">
> <metaModel class="org.eclipse.xtend.typesystem.emf.EmfMetaModel">
> <metaModelFile
> value="src/com/bosch/prj/codegen/metamodel/ansic.ecore"/>
> </metaModel>
> <metaModel
> class="org.eclipse.xtend.typesystem.uml2.UML2MetaModel"/>
> <invoke
> value=" sc::viper::uml2::codegen::uml22ansic::transformation::generi c::UMLModel::createModel(model) "/>
>
> <outputSlot value="model"/>
> </component>
>
> Best regards
> Tom
Re: ANSI-C-model and dealing with redundant references [message #641406 is a reply to message #640801] Thu, 25 November 2010 11:11 Go to previous messageGo to next message
Erhard Weinell is currently offline Erhard Weinell
Messages: 39
Registered: January 2010
Location: Kassel, Germany
Member
Quote:
Where do the set-Functions come from? Is it a feature of EMF to have them automatically as soon as there are references with a 1-to-1-association?


These operations are contributed by the EMF typesystem implementation of Xtend, for both to-one and to-many references.

BTW, despite the diagram's slight similarity, your model has nothing to do with UML. It is a metamodel written in Ecore, not UML. Questions related to the model transformation language Xtend are best asked in the eclipse.modeling.m2m group, just to add another redirection Smile

Best regards,
Erhard Weinell
Re: ANSI-C-model and dealing with redundant references [message #641409 is a reply to message #640801] Thu, 25 November 2010 11:17 Go to previous messageGo to next message
Tom Brandenburg is currently offline Tom Brandenburg
Messages: 58
Registered: October 2010
Location: Abstatt, Germany
Member
Hello Erhard,

Thank you for your answer! It helps me in understanding!

Quote:
BTW, despite the diagram's slight similarity, your model has nothing to do with UML. It is a metamodel written in Ecore, not UML. Questions related to the model transformation language Xtend are best asked in the eclipse.modeling.m2m group, just to add another redirection Smile


I never said that it is an UML metamodel Smile But slowly I am getting confused where to add my threads - everyone has another suggestions than the other. I am awaiting the day where I might be right with my placement Smile

Bye Tom =)
Re: ANSI-C-model and dealing with redundant references [message #641415 is a reply to message #641409] Thu, 25 November 2010 11:34 Go to previous messageGo to next message
Erhard Weinell is currently offline Erhard Weinell
Messages: 39
Registered: January 2010
Location: Kassel, Germany
Member
Quote:
I never said that it is an UML metamodel


..well, but you called it a UML input file, which it is not. Plus, I don't think the UML metamodel entry is required in the workflow file.

Considering your original question, there are some more or less ugly ways to deal with your two references.

One is to extract modifications of the nestedElements reference into an own extension, and to maintain the declSpec relation as required there. Of course this implies refactoring all references.

Another one would be using Xtend's AOP features. Depends on your opinion of AOP Smile But you might be able to specify an "around" for the setter operations.

Best regards,
Erhard Weinell
Re: ANSI-C-model and dealing with redundant references [message #641421 is a reply to message #640801] Thu, 25 November 2010 12:12 Go to previous message
Tom Brandenburg is currently offline Tom Brandenburg
Messages: 58
Registered: October 2010
Location: Abstatt, Germany
Member
Ok, I didn't check whether defining "<metaModel class="org.eclipse.xtend.typesystem.uml2.UML2MetaModel"/>" is relevant. Again for understanding: I have a Ecore-metamodel (ANSIC) and I load an UML model (some model of a project which is not referenced here) which I want to transform according to the Ecore metamodel. So in general it is a transformation from UML to ANSIC. So the top function is:
create ansic::Model this createModel(uml::Model m) :

Therefor I thought to reference my EmfMetaModel (ANSIC) and the UML2MetaModel so that Xtend knows uml:: and ansic::.
But maybe I got something wrong? Smile

I am not so much into AOP. Nevertheless I already have some workarounds for my stated problem above. I just look for references equal to null and check whether there are some others. For this I had to change the code of the ViPER project, but this is the only way how it works with me by now.

[Updated on: Thu, 25 November 2010 12:15]

Report message to a moderator

Previous Topic:Reading multiple XML models of different XSD's
Next Topic:EMF : get Eclass from ClassifierID
Goto Forum:
  


Current Time: Thu Oct 23 11:50:23 GMT 2014

Powered by FUDForum. Page generated in 0.02018 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software