Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [xpand]How to generate C++ code?
[xpand]How to generate C++ code? [message #536024] Wed, 26 May 2010 16:46 Go to next message
takky  is currently offline takky
Messages: 1
Registered: May 2010
Junior Member
Hi,

I want to generate C++ code by xpand. I am a beginner.
How can I generate properly?

I executed workflow as the following procedure.
1.I created the sample project and modified the model.
2.I modified template(.xpt).
3.I ran as the workflow "MWE".

In the src-gen folder, there are C++ files after execution.
But these files only includes properties and getter, setter methods.

I defined "eoperation" in the model.
Can I implement the eoperation?
( and change the arguments or return?)
Re: [xpand]How to generate C++ code? [message #536056 is a reply to message #536024] Wed, 26 May 2010 19:50 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian Dietrich
Messages: 6327
Registered: July 2009
Senior Member
Hello,

i don't know what this question has to do with the target language (in your case c++) at all. the problem is the same generating java, c++, lisp or even a fairy tail book.

You wrote that you defined a "eoperation" in the model, but this does not make sense to me.

it might be that you defined it in the metamodel, but this is not what you need.

have a look what a operation (i guess you want to generate methods - signatures) is: A Operation is a "Thing" that has a name, a returntype and a list of Parameters.

So you have to extend your metamodel to allow you to define = model your operations in the model.

Based on the sample this could look like this

<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0"
    xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="metamodel"
    nsURI="http://www.example.org/metamodel" nsPrefix="metamodel">
  <eClassifiers xsi:type="ecore:EClass" name="Model">
    <eStructuralFeatures xsi:type="ecore:EReference" name="types" upperBound="-1"
        eType="#//Type" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Type" abstract="true">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Datatype" eSuperTypes="#//Type"/>
  <eClassifiers xsi:type="ecore:EClass" name="Entity" eSuperTypes="#//Type">
    <eStructuralFeatures xsi:type="ecore:EReference" name="features" upperBound="-1"
        eType="#//Feature" containment="true"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="operations" upperBound="-1"
        eType="#//Operation" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Feature">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="type" eType="#//Type"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Operation">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="returnType" eType="#//Type"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="params" upperBound="-1"
        eType="#//Parameter" containment="true"/>
  </eClassifiers>
  <eClassifiers xsi:type="ecore:EClass" name="Parameter">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="type" eType="#//Type"/>
  </eClassifiers>
</ecore:EPackage>



and a (very simple) java template like this

«DEFINE javaClass FOR Entity»
	«FILE name+".java"»
		public class «name» {
			
			«FOREACH operations AS o»
				public «o.returnType.name» «o.name» («FOREACH o.params AS p SEPARATOR ","»«p.type.name» «p.name»«ENDFOREACH») {
					return null;
				}
			«ENDFOREACH»
		}
	«ENDFILE»
«ENDDEFINE»


For the (manual) implementation of the method body there different possibilities (generation gap pattern / protected regions)

~Christian
Re: [xpand]How to generate C++ code? [message #536114 is a reply to message #536056] Thu, 27 May 2010 07:00 Go to previous message
Darius Jockel is currently offline Darius Jockel
Messages: 63
Registered: July 2009
Member
Hello,

in addition to Christian: Xpand is not a ready to use generator to generate Java or C++ code. It is a generator framework for building custom generators. So you have to define the templates you need by yourself or you can modify/customize other C++ generators build with Xpand.

Regards
Darius
Previous Topic:[Check] metatype function
Next Topic:[Acceleo] match/drop Special chars
Goto Forum:
  


Current Time: Thu Oct 02 00:35:47 GMT 2014

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

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