Commit 3e1d9ef2 authored by Florian Hölzl's avatar Florian Hölzl
Browse files

added c text generation

refs 121
parent 9be4c649
......@@ -473,11 +473,13 @@
<eStructuralFeatures xsi:type="ecore:EReference" name="variables" upperBound="-1"
eType="#//generator/ProgramVariable" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="functions" upperBound="-1"
eType="#//definitions/FunctionDefinition" containment="true"/>
eType="#//generator/ProgramFunction" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="subPrograms" upperBound="-1"
eType="#//generator/Program" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ProgramVariable" eSuperTypes="#//definitions/FunctionParameter">
<eClassifiers xsi:type="ecore:EClass" name="ProgramVariable" eSuperTypes="#//definitions/FunctionParameter #//generator/ExportedProgramElement"/>
<eClassifiers xsi:type="ecore:EClass" name="ProgramFunction" eSuperTypes="#//definitions/FunctionDefinition #//generator/ExportedProgramElement"/>
<eClassifiers xsi:type="ecore:EClass" name="ExportedProgramElement">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="exported" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EBoolean"/>
</eClassifiers>
</eSubpackages>
......
......@@ -199,8 +199,10 @@
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference expression.ecore#//generator/Program/functions"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference expression.ecore#//generator/Program/subPrograms"/>
</genClasses>
<genClasses ecoreClass="expression.ecore#//generator/ProgramVariable">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute expression.ecore#//generator/ProgramVariable/exported"/>
<genClasses ecoreClass="expression.ecore#//generator/ProgramVariable"/>
<genClasses ecoreClass="expression.ecore#//generator/ProgramFunction"/>
<genClasses ecoreClass="expression.ecore#//generator/ExportedProgramElement">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute expression.ecore#//generator/ExportedProgramElement/exported"/>
</genClasses>
</nestedGenPackages>
</genPackages>
......
......@@ -19,19 +19,30 @@ package org.fortiss.af3.expression.generator.c;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createCEnumerationDeclaration;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createCEnumerationMember;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createCFunctionDeclaration;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createCFunctionDefinition;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createCSourcePackage;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createCVariable;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createHeaderFile;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createImplementationFile;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createInclude;
import java.util.HashMap;
import java.util.Map;
import org.fortiss.af3.expression.model.definitions.Enumeration;
import org.fortiss.af3.expression.model.definitions.EnumerationMember;
import org.fortiss.af3.expression.model.definitions.FunctionDefinition;
import org.fortiss.af3.expression.model.definitions.FunctionParameter;
import org.fortiss.af3.expression.model.definitions.TypeDefinition;
import org.fortiss.af3.expression.model.generator.Program;
import org.fortiss.af3.expression.model.generator.ProgramFunction;
import org.fortiss.af3.generator.common.model.c.CFunctionDeclaration;
import org.fortiss.af3.generator.common.model.c.CFunctionDefinition;
import org.fortiss.af3.generator.common.model.c.CHeaderFile;
import org.fortiss.af3.generator.common.model.c.CImplementationFile;
import org.fortiss.af3.generator.common.model.c.CModifier;
import org.fortiss.af3.generator.common.model.c.CSourcePackage;
import org.fortiss.af3.generator.common.model.c.CVariable;
import org.fortiss.af3.generator.common.model.c.types.CEnumerationDeclaration;
import org.fortiss.af3.generator.common.model.c.types.CEnumerationMember;
import org.fortiss.af3.generator.common.model.source.SourcePackage;
......@@ -76,31 +87,57 @@ public class ProgramTransformation implements ITransformationProvider {
throws TransformationFailedException {
Program p = (Program)source;
CSourcePackage pack = createCSourcePackage();
pack.getIncGenPackage().getUnitsList().add(createHeader(p));
pack.getSrcGenPackage().getUnitsList().add(createImplementation(p));
Map<ProgramFunction, CFunctionDeclaration> functionMap = prepareProgramFunctions(p);
pack.getIncGenPackage().getUnitsList().add(createHeader(p, functionMap));
pack.getSrcGenPackage().getUnitsList().add(createImplementation(p, functionMap));
return pack;
}
/** Creates function definitions and declarations for all {@link ProgramFunction}s. */
private Map<ProgramFunction, CFunctionDeclaration> prepareProgramFunctions(Program p) {
Map<ProgramFunction, CFunctionDeclaration> functionMap =
new HashMap<ProgramFunction, CFunctionDeclaration>();
for(ProgramFunction fun : p.getFunctionsList()) {
CModifier mod = fun.isExported() ? CModifier.EXTERN : CModifier.STATIC;
CFunctionDefinition def =
createCFunctionDefinition(fun.getFunction().getName(), fun.getReturnType(),
fun.getDefinition());
for(FunctionParameter param : fun.getParametersList()) {
CVariable cVar = createCVariable(param.getVar().getIdentifier(), param.getType());
def.getParametersList().add(cVar);
}
CFunctionDeclaration decl = createCFunctionDeclaration(mod, def);
decl.setDefinition(def);
functionMap.put(fun, decl);
}
return functionMap;
}
/** Creates the implementation source code. */
private CImplementationFile createImplementation(Program p) {
private CImplementationFile createImplementation(Program p,
Map<ProgramFunction, CFunctionDeclaration> functionMap) {
CImplementationFile implFile = createImplementationFile(p.getName());
for(Program sub : p.getSubProgramsList()) {
implFile.getImportsList().add(createInclude(sub.getName(), false));
}
for(ProgramFunction fun : p.getFunctionsList()) {
implFile.getDefinitionsList().add(functionMap.get(fun).getDefinition());
}
implFile.getImportsList().add(createInclude(p.getName(), false));
return implFile;
}
/** Creates the header source code. */
private CHeaderFile createHeader(Program p) {
private CHeaderFile createHeader(Program p,
Map<ProgramFunction, CFunctionDeclaration> functionMap) {
CHeaderFile h = createHeaderFile(p.getName());
for(TypeDefinition td : p.getTypesList()) {
if(td instanceof Enumeration) {
addCEnumeration((Enumeration)td, h);
}
}
for(FunctionDefinition fd : p.getFunctionsList()) {
// TODO
for(ProgramFunction fun : p.getFunctionsList()) {
h.getDeclarationsList().add(functionMap.get(fun));
}
return h;
}
......
......@@ -20,7 +20,7 @@ package org.fortiss.af3.expression.generator.imperative;
import static org.eclipse.emf.ecore.util.EcoreUtil.copy;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.createEnumeration;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.createEnumerationMember;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.createUserDefinedFunctionDefinition;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.createFunctionParameter;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.definedConst;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.definedType;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.equal;
......@@ -29,6 +29,7 @@ import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.ret
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.sequence;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.var;
import static org.fortiss.af3.expression.utils.GeneratorModelElementFactory.createProgram;
import static org.fortiss.af3.expression.utils.GeneratorModelElementFactory.createProgramFunction;
import java.util.ArrayList;
import java.util.List;
......@@ -36,12 +37,11 @@ import java.util.List;
import org.fortiss.af3.expression.model.DataDictionary;
import org.fortiss.af3.expression.model.definitions.Enumeration;
import org.fortiss.af3.expression.model.definitions.EnumerationMember;
import org.fortiss.af3.expression.model.definitions.FunctionDefinition;
import org.fortiss.af3.expression.model.definitions.TypeDefinition;
import org.fortiss.af3.expression.model.generator.Program;
import org.fortiss.af3.expression.model.generator.ProgramFunction;
import org.fortiss.af3.expression.model.terms.imperative.IStatementTerm;
import org.fortiss.af3.expression.model.terms.imperative.IfThenElse;
import org.fortiss.af3.expression.utils.ExpressionModelElementFactory;
import org.fortiss.tooling.kernel.extension.ITransformationProvider;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
......@@ -104,8 +104,8 @@ public class DataDictionaryTransformation implements ITransformationProvider {
List<IStatementTerm> toStringBody = new ArrayList<IStatementTerm>();
for(EnumerationMember mem : enumeration.getMembersList()) {
// constructor function
FunctionDefinition fdef =
createUserDefinedFunctionDefinition(mem.getName(), enumeration.createIType());
ProgramFunction fdef =
createProgramFunction(true, mem.getName(), enumeration.createIType());
fdef.setDefinition(sequence(returns(definedConst(mem.getName()))));
p.getFunctionsList().add(fdef);
// toString body part
......@@ -117,12 +117,10 @@ public class DataDictionaryTransformation implements ITransformationProvider {
toStringBody.add(sequence(returns(definedConst("\"null\""))));
// toString function
FunctionDefinition fdef =
createUserDefinedFunctionDefinition(enumeration.getName() + "ToString",
ProgramFunction fdef =
createProgramFunction(true, enumeration.getName() + "ToString",
definedType("String"));
fdef.getParametersList().add(
ExpressionModelElementFactory.createFunctionParameter("value",
enumeration.createIType()));
fdef.getParametersList().add(createFunctionParameter("value", enumeration.createIType()));
fdef.setDefinition(sequence(toStringBody));
p.getFunctionsList().add(fdef);
}
......
......@@ -17,12 +17,16 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.expression.utils;
import static org.eclipse.emf.ecore.util.EcoreUtil.copy;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.var;
import org.fortiss.af3.expression.model.generator.GeneratorFactory;
import org.fortiss.af3.expression.model.generator.GeneratorPackage;
import org.fortiss.af3.expression.model.generator.Program;
import org.fortiss.af3.expression.model.generator.ProgramFunction;
import org.fortiss.af3.expression.model.generator.ProgramVariable;
import org.fortiss.af3.expression.model.terms.TermsFactory;
import org.fortiss.af3.expression.model.terms.UserdefinedFunction;
import org.fortiss.af3.project.model.typesystem.IType;
/**
......@@ -49,4 +53,16 @@ public class GeneratorModelElementFactory {
v.setType(type);
return v;
}
/** Creates a ProgramFunction for the given name, type and export value. */
public static ProgramFunction createProgramFunction(boolean export, String name,
IType returnType) {
ProgramFunction fun = GeneratorFactory.eINSTANCE.createProgramFunction();
UserdefinedFunction ufun = TermsFactory.eINSTANCE.createUserdefinedFunction();
ufun.setName(name);
fun.setFunction(ufun);
fun.setReturnType(copy(returnType));
fun.setExported(export);
return fun;
}
}
......@@ -121,12 +121,29 @@
</eOperations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="CFunctionDeclaration" eSuperTypes="#//source/Declaration">
<eOperations name="toString" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="return org.fortiss.af3.generator.common.textgen.c.CLanguageConstructTextGenerator.functionDeclarationToString(this);"/>
</eAnnotations>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="modifier" eType="#//c/CModifier"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="definition" eType="#//c/CFunctionDefinition"
eOpposite="#//c/CFunctionDefinition/declaration"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="CFunctionDefinition" eSuperTypes="#//source/Definition">
<eClassifiers xsi:type="ecore:EClass" name="CFunctionDefinition" eSuperTypes="#//source/Definition platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedElement">
<eOperations name="toString" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="return org.fortiss.af3.generator.common.textgen.c.CLanguageConstructTextGenerator.functionDefinitionToString(this);"/>
</eAnnotations>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EReference" name="declaration" eType="#//c/CFunctionDeclaration"
eOpposite="#//c/CFunctionDeclaration/definition"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="returnType" eType="ecore:EClass ../../org.fortiss.af3.project/model/project.ecore#//typesystem/IType"
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="parameters" upperBound="-1"
eType="#//c/CVariable" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="body" eType="ecore:EClass ../../org.fortiss.af3.project/model/project.ecore#//typesystem/ITerm"
containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="CSourcePackage" eSuperTypes="#//source/SourcePackage">
<eOperations name="getIncGenPackage" eType="#//source/SourcePackage">
......@@ -154,7 +171,22 @@
</eAnnotations>
</eOperations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="CTypeDeclaration" eSuperTypes="#//source/Declaration platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedElement"/>
<eClassifiers xsi:type="ecore:EClass" name="CTypeDeclaration" abstract="true"
eSuperTypes="#//source/Declaration platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedElement"/>
<eClassifiers xsi:type="ecore:EClass" name="CVariableDeclaration" eSuperTypes="#//source/Declaration">
<eOperations name="toString" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="return org.fortiss.af3.generator.common.textgen.c.CLanguageConstructTextGenerator.variableDeclarationToString(this);"/>
</eAnnotations>
</eOperations>
<eStructuralFeatures xsi:type="ecore:EAttribute" name="modifier" eType="#//c/CModifier"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="variable" eType="#//c/CVariable"
containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="CVariable" eSuperTypes="platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="type" eType="ecore:EClass ../../org.fortiss.af3.project/model/project.ecore#//typesystem/IType"
containment="true"/>
</eClassifiers>
<eSubpackages name="types" nsURI="http://www.fortiss.org/af3/generator/common/languages/c/types"
nsPrefix="org-fortiss-af3-generator-common-languages-c-types">
<eClassifiers xsi:type="ecore:EClass" name="CEnumerationDeclaration" eSuperTypes="#//c/CTypeDeclaration">
......
......@@ -8,7 +8,7 @@
editorPluginClass="org.fortiss.af3.generator.common.model.presentation.ModelEditorPlugin"
testsDirectory="/org.fortiss.af3.generator.common.tests/test-src" importerID="org.eclipse.emf.importer.ecore"
containmentProxies="true" arrayAccessors="true" complianceLevel="5.0" copyrightFields="false"
language="" usedGenPackages="platform:/plugin/org.fortiss.tooling.kernel/model/kernel.genmodel#//model">
language="" usedGenPackages="../../org.fortiss.af3.project/model/project.genmodel#//model platform:/plugin/org.fortiss.tooling.kernel/model/kernel.genmodel#//model">
<foreignModel>languages.ecore</foreignModel>
<genPackages prefix="AF3GeneratorCommonLanguages" basePackage="org.fortiss.af3.generator.common"
disposableProviderFactory="true" ecorePackage="languages.ecore#/">
......@@ -65,12 +65,18 @@
<genOperations ecoreOperation="languages.ecore#//c/CInclude/toString"/>
</genClasses>
<genClasses ecoreClass="languages.ecore#//c/CFunctionDeclaration">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute languages.ecore#//c/CFunctionDeclaration/modifier"/>
<genFeatures notify="false" createChild="false" propertySortChoices="true"
ecoreFeature="ecore:EReference languages.ecore#//c/CFunctionDeclaration/definition"/>
<genOperations ecoreOperation="languages.ecore#//c/CFunctionDeclaration/toString"/>
</genClasses>
<genClasses ecoreClass="languages.ecore#//c/CFunctionDefinition">
<genFeatures notify="false" createChild="false" propertySortChoices="true"
ecoreFeature="ecore:EReference languages.ecore#//c/CFunctionDefinition/declaration"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//c/CFunctionDefinition/returnType"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//c/CFunctionDefinition/parameters"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//c/CFunctionDefinition/body"/>
<genOperations ecoreOperation="languages.ecore#//c/CFunctionDefinition/toString"/>
</genClasses>
<genClasses ecoreClass="languages.ecore#//c/CSourcePackage">
<genOperations ecoreOperation="languages.ecore#//c/CSourcePackage/getIncGenPackage"/>
......@@ -79,6 +85,14 @@
<genOperations ecoreOperation="languages.ecore#//c/CSourcePackage/getSrcPackage"/>
</genClasses>
<genClasses ecoreClass="languages.ecore#//c/CTypeDeclaration"/>
<genClasses ecoreClass="languages.ecore#//c/CVariableDeclaration">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute languages.ecore#//c/CVariableDeclaration/modifier"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//c/CVariableDeclaration/variable"/>
<genOperations ecoreOperation="languages.ecore#//c/CVariableDeclaration/toString"/>
</genClasses>
<genClasses ecoreClass="languages.ecore#//c/CVariable">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//c/CVariable/type"/>
</genClasses>
<nestedGenPackages prefix="Types" basePackage="org.fortiss.af3.generator.common.model.c"
disposableProviderFactory="true" ecorePackage="languages.ecore#//c/types">
<genClasses ecoreClass="languages.ecore#//c/types/CEnumerationDeclaration">
......
......@@ -17,7 +17,17 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.generator.common.textgen.c;
import static org.fortiss.af3.generator.common.model.c.CModifier.EXTERN;
import static org.fortiss.af3.generator.common.model.c.CModifier.NONE;
import static org.fortiss.af3.generator.common.model.c.CModifier.STATIC;
import org.fortiss.af3.generator.common.model.c.CFunctionDeclaration;
import org.fortiss.af3.generator.common.model.c.CFunctionDefinition;
import org.fortiss.af3.generator.common.model.c.CInclude;
import org.fortiss.af3.generator.common.model.c.CModifier;
import org.fortiss.af3.generator.common.model.c.CVariable;
import org.fortiss.af3.generator.common.model.c.CVariableDeclaration;
import org.fortiss.af3.generator.common.model.c.impl.CFunctionDefinitionImpl;
/**
* Text generator for C language constructs.
......@@ -38,4 +48,94 @@ public class CLanguageConstructTextGenerator {
public static String includeToString(CInclude inc) {
return "#include " + inc.getSourceUnitReference() + '\n';
}
/**
* Creates the text for the given function declaration.
*
* @param decl
* the declaration
* @return the textual representation of the declaration
*/
public static String functionDeclarationToString(CFunctionDeclaration decl) {
StringBuffer buf = new StringBuffer();
buf.append(modifierToString(decl.getModifier())).append(' ');
CFunctionDefinition def = decl.getDefinition();
buf.append(def.getReturnType().toString()).append(' ');
buf.append(def.getName()).append(' ');
buf.append('(');
boolean first = true;
for(CVariable param : def.getParametersList()) {
if(!first) {
buf.append(',');
} else {
first = false;
}
buf.append(param.toString());
}
buf.append(");\n");
return null;
}
/**
* Creates the text for the given modifier.
*
* @param mod
* the modifier
* @return the textual representation of the modifier
*/
public static String modifierToString(CModifier mod) {
if(EXTERN.equals(mod)) {
return "extern ";
}
if(STATIC.equals(mod)) {
return "static ";
}
return ""; // CModifier.NONE
}
/**
* Creates the text for the given variable declaration.
*
* @param decl
* the declaration
* @return the textual representation
*/
public static String variableDeclarationToString(CVariableDeclaration decl) {
return modifierToString(decl.getModifier()) + ' ' +
decl.getVariable().getType().toString() + ' ' + decl.getVariable().getName() +
";\n";
}
/**
* Creates the text for the given function definition.
*
* @param def
* the definition
* @return the textual representation of the definition
*/
public static String functionDefinitionToString(CFunctionDefinitionImpl def) {
StringBuffer buf = new StringBuffer();
CModifier mod = def.getDeclaration().getModifier();
if(EXTERN.equals(mod)) {
mod = NONE;
}
buf.append(modifierToString(mod));
buf.append(def.getReturnType().toString()).append(' ');
buf.append(def.getName()).append(' ');
buf.append('(');
boolean first = true;
for(CVariable param : def.getParametersList()) {
if(!first) {
buf.append(',');
} else {
first = false;
}
buf.append(param.toString());
}
buf.append(") {\n");
buf.append(def.getBody().toString());
buf.append("}\n");
return null;
}
}
......@@ -17,15 +17,23 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.generator.common.utils;
import static org.eclipse.emf.ecore.util.EcoreUtil.copy;
import org.fortiss.af3.generator.common.model.c.AF3GeneratorCommonLanguagesCFactory;
import org.fortiss.af3.generator.common.model.c.AF3GeneratorCommonLanguagesCPackage;
import org.fortiss.af3.generator.common.model.c.CFunctionDeclaration;
import org.fortiss.af3.generator.common.model.c.CFunctionDefinition;
import org.fortiss.af3.generator.common.model.c.CHeaderFile;
import org.fortiss.af3.generator.common.model.c.CImplementationFile;
import org.fortiss.af3.generator.common.model.c.CInclude;
import org.fortiss.af3.generator.common.model.c.CModifier;
import org.fortiss.af3.generator.common.model.c.CSourcePackage;
import org.fortiss.af3.generator.common.model.c.CVariable;
import org.fortiss.af3.generator.common.model.c.types.CEnumerationDeclaration;
import org.fortiss.af3.generator.common.model.c.types.CEnumerationMember;
import org.fortiss.af3.generator.common.model.c.types.TypesFactory;
import org.fortiss.af3.project.model.typesystem.ITerm;
import org.fortiss.af3.project.model.typesystem.IType;
/**
* Model element factory for {@link AF3GeneratorCommonLanguagesCPackage} elements.
......@@ -105,6 +113,30 @@ public class CLanguageModelElementFactory {
return mem;
}
/** Creates a {@link CFunctionDefinition} with the given name and return type. */
public static CFunctionDefinition
createCFunctionDefinition(String name, IType type, ITerm body) {
CFunctionDefinition def =
AF3GeneratorCommonLanguagesCFactory.eINSTANCE.createCFunctionDefinition();
def.setName(name);
def.setReturnType(copy(type));
def.setBody(copy(body));
return def;
}
/**
* Creates a {@link CFunctionDeclaration} for the given {@link CFunctionDefinition} and
* {@link CModifier}.
*/
public static CFunctionDeclaration createCFunctionDeclaration(CModifier modifier,
CFunctionDefinition def) {
CFunctionDeclaration decl =
AF3GeneratorCommonLanguagesCFactory.eINSTANCE.createCFunctionDeclaration();
decl.setModifier(modifier);
decl.setDefinition(def);
return decl;
}
/**
* Creates an include statement (.h is appended).
*
......@@ -122,4 +154,12 @@ public class CLanguageModelElementFactory {
inc.setSourceUnitReference(headerRef);
return inc;
}
/** Creates a {@link CVariable} with the given name and type. */
public static CVariable createCVariable(String name, IType type) {
CVariable cvar = AF3GeneratorCommonLanguagesCFactory.eINSTANCE.createCVariable();
cvar.setName(name);
cvar.setType(copy(type));
return cvar;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment