Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Papyrus for Real Time » Customizing code generator(How to beautify the tokens by the CodeGenerator)
Customizing code generator [message #1799026] Wed, 28 November 2018 22:51 Go to next message
Dimo Ditchev is currently offline Dimo DitchevFriend
Messages: 33
Registered: September 2018
Member
We have a Code Standard which differs from the output from the CodeGenerator in PapyrusRT.
For example, heather files have hpp extention instead of hh and source files are cpp and not cc. Also mthods are camel case and no underscores are allowed in the name.
Does anyone know (have) an example how to extend/alter the CodeGenerator so that the c++ tokens will comply to certain patterns.

Thanks,
Dimo
Re: Customizing code generator [message #1799068 is a reply to message #1799026] Thu, 29 November 2018 13:39 Go to previous messageGo to next message
Charles Rivet is currently offline Charles RivetFriend
Messages: 219
Registered: May 2014
Location: Canada
Senior Member

Have you checked the developer documentation? In this case, have a look at https://wiki.eclipse.org/Papyrus-RT/Developer/Design#Code_generation

/Charles Rivet
Re: Customizing code generator [message #1799105 is a reply to message #1799026] Thu, 29 November 2018 18:28 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
Unfortunately this problem is a bit of a can of worms. It can be done, but it is not as easy as one would like.

First of all, you should try to consider whether these formatting standards are truly necessary for you. The requirement that no underscores are allowed is particularly stringent, and as described bellow, if you want to change this, it will be quite difficult. If you have some automated quality testing tool that gives you warnings because it is not following the coding standards, then these would only be warnings, not show-stoppers. Furthermore, in most projects it is possible to disable such warnings or formatting standards tests for a subset of the code.

If you must apply those standards (perhaps because of mandated policy in your company) and there is no way around it, read on, but be warned that it is not trivial.

The first difficulty is that currently it is not possible to get the proper development environment for Papyrus-RT (including dependencies, target platform, build tools, etc.) so it is not possible to build a proper RCP, and at the moment all you can do is to clone the git repo (https://git.eclipse.org/r/papyrus-rt/org.eclipse.papyrus-rt.git), make the changes (outlined below) and then integrating them with one of two options:

1) compile the plugins you have changed, make them into jars with the same name and version number as the existing plugins, and add them to the "dropins" folder inside your Papyrus-RT Eclipse installation. There is a chance that Eclipse picks up the plugins under "plugins" instead of "dropins" if they have the exact same name/version/build number, in which case, delete the original ones from "plugins" and keep only the new ones under "dropins".

2) try to rebuild with Maven, but this will likely fail because of old dependencies, in which case, you are on your own to try to resolve them. (Unfortunately we are not currently maintaining it).

In either case it is not guaranteed that you will be able to compile because the proper target platform is not available anymore, so you will be on your own chasing missing/conflicting dependencies.

Ok, assuming that you still want to go ahead with the changes, here's what you need to modify:

1) To change the file extensions:

Search for ".hh" and ".cc" in the whole project, and make the changes where you find them. Currently these are the places that need to be updated:

org.eclipse.papyrusrt.codegen.lang.cpp.CppWriter.create
org.eclipse.papyrusrt.codegen.lang.cpp.name.FileName.getIncludePath

org.eclipse.papyrusrt.codegen.papyrus.handlers.EditSourceAction.getFile
org.eclipse.papyrusrt.xtumlrt.xtext.codegen.ui.handlers.EditSourceHandler.getFile

org.eclipse.papyrusrt.codegen.cpp.UMLChangeTracker.CPP_EXTENSION
org.eclipse.papyrusrt.codegen.cpp.CppMakefileGenerator


So that means that the following plugins have to be recompiled and added to "dropins" (assuming you go for option 1 above):

Do not change the extensions found in

org.eclipse.papyrusrt.codegen.cpp.rts.UMLRTRuntime


as these are the files of the C++ RTS (not generated), unless you change manually all those files in which case you will have to change the relevant Makefiles too.

org.eclipse.papyrusrt.codegen.lang.cpp
org.eclipse.papyrusrt.codegen.papyrus
org.eclipse.papyrusrt.xtumlrt.xtext.codegen.ui
org.eclipse.papyrusrt.codegen.cpp


These are in the git repo under

plugins/umlrt/codegen
plugins/xtumlrt/xtext


2) To update class/attribute/method names:

This is the really difficult one, because many of those names are built-in in the RTS, which means that if you change them, you would have to change not just the code generator, but the RTS itself (in C++), and that is a BIG task (including the fact that you have to rebuild the RTS). The RTS is in the git under

plugins/umlrt/runtime/rts


I would strongly recommend against modifying the names of the RTS, as it is a major task.

For other names, you can modify the following method:

org.eclipse.papyrusrt.codegen.cpp.CppCodePattern.getName


in the following plugin:

org.eclipse.papyrusrt.codegen.cpp


If you change the names in the RTS you will need to change them as well in

org.eclipse.papyrusrt.codegen.cpp.rts.UMLRTRuntime


But again, I strongly advice against making those changes, as the RTS expects certain structures with certain names in place.

So the change is not for the faint-hearted.

Re: Customizing code generator [message #1799106 is a reply to message #1799105] Thu, 29 November 2018 18:37 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
An addendum to my previous message. I previously answered a similar question about the file extensions, and my suggestion is to leave them as they are, and rather write a script that modifies the file's extensions after generation. See https://www.eclipse.org/forums/index.php?t=tree&th=1089604&goto=1775103&#msg_1775103
Re: Customizing code generator [message #1799171 is a reply to message #1799106] Fri, 30 November 2018 23:25 Go to previous messageGo to next message
Dimo Ditchev is currently offline Dimo DitchevFriend
Messages: 33
Registered: September 2018
Member
Ernesto and Charles,

Thank you very much for the information.

Dimo
Re: Customizing code generator [message #1799503 is a reply to message #1799171] Fri, 07 December 2018 19:08 Go to previous messageGo to next message
Dimo Ditchev is currently offline Dimo DitchevFriend
Messages: 33
Registered: September 2018
Member
Ernesto and Charles,

What is the best way to add include header files in PapyrusRT for classes defined in external libraries?

Thanks,
Dimo
Re: Customizing code generator [message #1799505 is a reply to message #1799503] Fri, 07 December 2018 19:30 Go to previous messageGo to next message
Ernesto Posse is currently offline Ernesto PosseFriend
Messages: 438
Registered: March 2011
Senior Member
Suppose you want to use some library "mylib" with header "mylib.h". Then, in the Model Explorer select the capsule of class where you want to use it, go to the Properties view, select the "Profile" tab, and under "Applied Stereotypes" click the green [+] button. In the dialog you'll see several possible stereotypes. Select "CapsuleProperties" (or "PassiveClassProperties") and click [OK]. In the Properties view you should now see the new stereotype. Unfold it and you'll see several properties that can be customized. Select the "headerPreface" field and in the text box that appears type

#include "mylib.h"

You can add any valid (header) C++ here as well.

You'll need to manually add this file (and the corresponding object file) to the generated Makefile.

There is a pattern that I like to use whenever I need to include many headers or add custom macros, which is to create a UML Artifact (right-click the Root element > New Child > Artifact), give it a name, and in the UML tab of the Properties view specify a file name for it (it will be a C++ compilation unit consisting of a header and source file). Then in the Profile tab add the "ArtifactProperties" stereotype. Once added, the stereotype has two fields "includeFile" and "sourceFile". They will be the contents of the generated header and source file respectively, so you can fill in there any C++. Once you have the Artifact, create a class diagram below the Root element (you may need to change to the "Advanced" viewpoint first by right-clicking the Root element > Switch Architecture Viewpoints > Advanced UML-RT Modeling Viewpoint). In the Advanced Viewpoint, the "New Diagram" menu will show standard UML diagrams, including the possibility of creating a Class diagram. This can be used to create inheritance relations, or in the case of Artifacts, Dependency relations: drag and drop the capsules or classes that you want to depend on the Artifact into the Class diagram, and create a Dependency edge from the relevant capsule/class to the Artifact. This will result in automatically adding the #include "Artifact.hh" in the capsule/class header.
Re: Customizing code generator [message #1799513 is a reply to message #1799505] Fri, 07 December 2018 22:30 Go to previous messageGo to next message
Dimo Ditchev is currently offline Dimo DitchevFriend
Messages: 33
Registered: September 2018
Member
Ernesto,

This is great!

Thanks you,
Dimo
Re: Customizing code generator [message #1800240 is a reply to message #1799505] Fri, 21 December 2018 17:18 Go to previous message
Dimo Ditchev is currently offline Dimo DitchevFriend
Messages: 33
Registered: September 2018
Member
Ernesto,

I tried this and it works really great for me.
Happy Holidays!
We are working on using Papyrus-RT in a business project.

Thanks,
Dimo
Previous Topic:Generating code for specific hardware
Next Topic:PapyrusRT example for SPP and SAP
Goto Forum:
  


Current Time: Thu Apr 25 17:38:38 GMT 2024

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

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

Back to the top