Skip to main content

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 Friend
Messages: 1
Registered: May 2010
Junior Member

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 DietrichFriend
Messages: 13314
Registered: July 2009
Senior Member

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="" xmlns:xsi=""
    xmlns:ecore="" name="metamodel"
    nsURI="" nsPrefix="metamodel">
  <eClassifiers xsi:type="ecore:EClass" name="Model">
    <eStructuralFeatures xsi:type="ecore:EReference" name="types" upperBound="-1"
        eType="#//Type" containment="true"/>
  <eClassifiers xsi:type="ecore:EClass" name="Type" abstract="true">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType"/>
  <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 xsi:type="ecore:EClass" name="Feature">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="type" eType="#//Type"/>
  <eClassifiers xsi:type="ecore:EClass" name="Operation">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="returnType" eType="#//Type"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="params" upperBound="-1"
        eType="#//Parameter" containment="true"/>
  <eClassifiers xsi:type="ecore:EClass" name="Parameter">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="name" eType="ecore:EDataType"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="type" eType="#//Type"/>

and a (very simple) java template like this

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

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


Need professional support for Xtext, Xpand, EMF?
Go to:
Twitter : @chrdietrich
Blog :
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 JockelFriend
Messages: 63
Registered: July 2009

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.

Previous Topic:[JET] How to Dynamically call JET transform api through a plugin?
Next Topic:[Xtend] Lists in JAVA extensions
Goto Forum:

Current Time: Wed Jan 22 23:06:05 GMT 2020

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

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

Back to the top