|
Re: [xpand]How to generate C++ code? [message #536056 is a reply to message #536024] |
Wed, 26 May 2010 19:50 |
|
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
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Powered by
FUDForum. Page generated in 0.04022 seconds