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

moved non-EMF model and added EMF model for imperative and C generation

refs 118
parent 4bcbda17
......@@ -24,15 +24,15 @@ import static org.fortiss.af3.expression.generator.c.Types.TYPE_STRING_GENERATOR
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.assignment;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.sequence;
import static org.fortiss.af3.generator.common.model.c.Function.createExternFunction;
import static org.fortiss.af3.generator.common.model.c.VoidType.VOID_TYPE;
import static org.fortiss.af3.generator.common.model.oldc.Function.createExternFunction;
import static org.fortiss.af3.generator.common.model.oldc.VoidType.VOID_TYPE;
import java.util.List;
import org.fortiss.af3.component.model.behavior.code.CodeSpecification;
import org.fortiss.af3.expression.model.terms.imperative.StatementSequence;
import org.fortiss.af3.generator.common.model.c.Function;
import org.fortiss.af3.generator.common.model.source.SourcePackage;
import org.fortiss.af3.generator.common.model.oldc.Function;
import org.fortiss.af3.generator.common.model.oldsource.SourcePackage;
/**
* {@link CSourceComponent} for {@link CodeSpecification}.
......
......@@ -29,10 +29,10 @@ import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.boo
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.returns;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.sequence;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.var;
import static org.fortiss.af3.generator.common.model.c.Function.createExternFunction;
import static org.fortiss.af3.generator.common.model.c.Function.createInternFunction;
import static org.fortiss.af3.generator.common.model.c.Modifier.EXTERN;
import static org.fortiss.af3.generator.common.model.c.VoidType.VOID_TYPE;
import static org.fortiss.af3.generator.common.model.oldc.Function.createExternFunction;
import static org.fortiss.af3.generator.common.model.oldc.Function.createInternFunction;
import static org.fortiss.af3.generator.common.model.oldc.Modifier.EXTERN;
import static org.fortiss.af3.generator.common.model.oldc.VoidType.VOID_TYPE;
import static org.fortiss.tooling.kernel.utils.IdentifierUtils.getUniqueIdentifier;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getRootElement;
......@@ -53,13 +53,13 @@ import org.fortiss.af3.expression.model.DataDictionary;
import org.fortiss.af3.expression.model.terms.Var;
import org.fortiss.af3.expression.model.terms.imperative.IStatementTerm;
import org.fortiss.af3.expression.model.terms.imperative.StatementSequence;
import org.fortiss.af3.generator.common.model.c.Function;
import org.fortiss.af3.generator.common.model.c.HeaderFile;
import org.fortiss.af3.generator.common.model.c.ImplementationFile;
import org.fortiss.af3.generator.common.model.c.Include;
import org.fortiss.af3.generator.common.model.c.Variable;
import org.fortiss.af3.generator.common.model.source.SourcePackage;
import org.fortiss.af3.generator.common.model.source.SourceUnitBase;
import org.fortiss.af3.generator.common.model.oldc.Function;
import org.fortiss.af3.generator.common.model.oldc.HeaderFile;
import org.fortiss.af3.generator.common.model.oldc.ImplementationFile;
import org.fortiss.af3.generator.common.model.oldc.Include;
import org.fortiss.af3.generator.common.model.oldc.Variable;
import org.fortiss.af3.generator.common.model.oldsource.SourcePackage;
import org.fortiss.af3.generator.common.model.oldsource.SourceUnitBase;
import org.fortiss.tooling.base.model.element.IConnector;
import org.fortiss.tooling.base.model.element.IModelElementSpecification;
import org.fortiss.tooling.kernel.model.INamedElement;
......
......@@ -25,8 +25,8 @@ import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.ass
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.funcCall;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.sequence;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.var;
import static org.fortiss.af3.generator.common.model.c.Function.createExternFunction;
import static org.fortiss.af3.generator.common.model.c.VoidType.VOID_TYPE;
import static org.fortiss.af3.generator.common.model.oldc.Function.createExternFunction;
import static org.fortiss.af3.generator.common.model.oldc.VoidType.VOID_TYPE;
import static org.fortiss.af3.generator.common.utils.CSourcePackageUtils.flattenAndSortHierarchicSourcePackages;
import java.util.LinkedList;
......@@ -37,9 +37,9 @@ import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.expression.model.terms.Var;
import org.fortiss.af3.expression.model.terms.imperative.IStatementTerm;
import org.fortiss.af3.expression.model.terms.imperative.StatementSequence;
import org.fortiss.af3.generator.common.model.c.Function;
import org.fortiss.af3.generator.common.model.c.Include;
import org.fortiss.af3.generator.common.model.source.SourcePackage;
import org.fortiss.af3.generator.common.model.oldc.Function;
import org.fortiss.af3.generator.common.model.oldc.Include;
import org.fortiss.af3.generator.common.model.oldsource.SourcePackage;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.base.model.element.IModelElementSpecification;
......
......@@ -18,7 +18,7 @@ $Id$
package org.fortiss.af3.deployment.generator;
import org.antlr.stringtemplate.StringTemplate;
import org.fortiss.af3.generator.common.model.source.SourceUnitBase;
import org.fortiss.af3.generator.common.model.oldsource.SourceUnitBase;
import org.fortiss.af3.platform.model.ExecutionUnit;
import org.fortiss.af3.platform.templates.TemplateLoader;
......
......@@ -37,7 +37,7 @@ import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.model.Port;
import org.fortiss.af3.deployment.AF3DeploymentActivator;
import org.fortiss.af3.deployment.model.Deployment;
import org.fortiss.af3.generator.common.model.source.SourcePackage;
import org.fortiss.af3.generator.common.model.oldsource.SourcePackage;
import org.fortiss.af3.platform.language.executable.ExecutionUnitExecutableBase;
import org.fortiss.af3.platform.language.executable.PlatformArchitectureExecutable;
import org.fortiss.af3.platform.model.ExecutionUnit;
......
......@@ -18,8 +18,8 @@ $Id$
package org.fortiss.af3.expression.generator.c;
import static org.fortiss.af3.expression.generator.c.Types.TYPE_STRING_GENERATOR;
import static org.fortiss.af3.generator.common.model.c.Modifier.EXTERN;
import static org.fortiss.af3.generator.common.model.c.Modifier.NONE;
import static org.fortiss.af3.generator.common.model.oldc.Modifier.EXTERN;
import static org.fortiss.af3.generator.common.model.oldc.Modifier.NONE;
import java.util.ArrayList;
import java.util.Collections;
......@@ -30,12 +30,12 @@ import org.fortiss.af3.expression.model.DataDictionary;
import org.fortiss.af3.expression.model.definitions.Enumeration;
import org.fortiss.af3.expression.model.definitions.FunctionDefinition;
import org.fortiss.af3.expression.model.definitions.FunctionParameter;
import org.fortiss.af3.generator.common.model.c.Function;
import org.fortiss.af3.generator.common.model.c.HeaderFile;
import org.fortiss.af3.generator.common.model.c.ImplementationFile;
import org.fortiss.af3.generator.common.model.c.Include;
import org.fortiss.af3.generator.common.model.c.Variable;
import org.fortiss.af3.generator.common.model.source.DeclarationBase;
import org.fortiss.af3.generator.common.model.oldc.Function;
import org.fortiss.af3.generator.common.model.oldc.HeaderFile;
import org.fortiss.af3.generator.common.model.oldc.ImplementationFile;
import org.fortiss.af3.generator.common.model.oldc.Include;
import org.fortiss.af3.generator.common.model.oldc.Variable;
import org.fortiss.af3.generator.common.model.oldsource.DeclarationBase;
/**
* The generator for {@link DataDictionary}. It produces two files: <code>data_dictionary.h</code>
......
......@@ -23,15 +23,15 @@ import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.def
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.definedType;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.returns;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.sequence;
import static org.fortiss.af3.generator.common.model.c.Modifier.EXTERN;
import static org.fortiss.af3.generator.common.model.oldc.Modifier.EXTERN;
import java.util.ArrayList;
import java.util.List;
import org.fortiss.af3.expression.model.definitions.Enumeration;
import org.fortiss.af3.expression.model.definitions.EnumerationMember;
import org.fortiss.af3.generator.common.model.c.Function;
import org.fortiss.af3.generator.common.model.source.DeclarationBase;
import org.fortiss.af3.generator.common.model.oldc.Function;
import org.fortiss.af3.generator.common.model.oldsource.DeclarationBase;
import org.fortiss.af3.project.model.typesystem.IType;
/**
......
......@@ -21,11 +21,11 @@ import org.fortiss.af3.expression.model.types.TBool;
import org.fortiss.af3.expression.model.types.TDefinedType;
import org.fortiss.af3.expression.model.types.TDouble;
import org.fortiss.af3.expression.model.types.TInt;
import org.fortiss.af3.generator.common.model.c.BaseType;
import org.fortiss.af3.generator.common.model.c.Function;
import org.fortiss.af3.generator.common.model.c.ITypeStringGenerator;
import org.fortiss.af3.generator.common.model.c.Variable;
import org.fortiss.af3.generator.common.model.c.VoidType;
import org.fortiss.af3.generator.common.model.oldc.BaseType;
import org.fortiss.af3.generator.common.model.oldc.Function;
import org.fortiss.af3.generator.common.model.oldc.ITypeStringGenerator;
import org.fortiss.af3.generator.common.model.oldc.Variable;
import org.fortiss.af3.generator.common.model.oldc.VoidType;
import org.fortiss.af3.project.model.typesystem.IType;
/**
......
......@@ -10,7 +10,7 @@ Bundle-ActivationPolicy: lazy
Bundle-Activator: org.fortiss.af3.generator.common.AF3GeneratorCommonActivator
Require-Bundle: org.fortiss.af3.project;bundle-version="2.1.0";visibility:=reexport
Export-Package: org.fortiss.af3.generator.common,
org.fortiss.af3.generator.common.model.c,
org.fortiss.af3.generator.common.model.source,
org.fortiss.af3.generator.common.model.oldc,
org.fortiss.af3.generator.common.model.oldsource,
org.fortiss.af3.generator.common.model.vhdl,
org.fortiss.af3.generator.common.utils
......@@ -98,4 +98,27 @@
eOpposite="#//c/FunctionDeclaration/definition"/>
</eClassifiers>
</eSubpackages>
<eSubpackages name="imperative" nsURI="http://www.fortiss.org/af3/generator/common/languages/imperative"
nsPrefix="org-fortiss-af3-generator-common-languages-imperative">
<eClassifiers xsi:type="ecore:EClass" name="Program" eSuperTypes="../../org.fortiss.tooling.kernel/model/kernel.ecore#//INamedElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="variables" upperBound="-1"
eType="ecore:EClass ../../org.fortiss.af3.project/model/project.ecore#//typesystem/VarBase"
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="procedures" upperBound="-1"
eType="#//imperative/Procedure" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="subPrograms" upperBound="-1"
eType="#//imperative/Program" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Procedure" eSuperTypes="../../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"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="parameters" upperBound="-1"
eType="#//imperative/Variable" 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="Variable" eSuperTypes="../../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>
</ecore:EPackage>
<?xml version="1.0" encoding="UTF-8"?>
<genmodel:GenModel xmi:version="2.0"
xmlns:xmi="http://www.omg.org/XMI" xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" copyrightText="(c) 2011 ForTISS GmbH"
xmlns:xmi="http://www.omg.org/XMI" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore"
xmlns:genmodel="http://www.eclipse.org/emf/2002/GenModel" copyrightText="(c) 2011 ForTISS GmbH"
modelDirectory="/org.fortiss.af3.generator.common/generated-src" editDirectory="org.fortiss.af3.generator.common.edit/src"
editorDirectory="/org.fortiss.af3.generator.common.editor/src" modelPluginID="org.fortiss.af3.generator.common"
modelName="Model" modelPluginClass="" editPluginClass="org.fortiss.af3.generator.common.model.provider.ModelEditPlugin"
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="">
language="" usedGenPackages="../../org.fortiss.af3.project/model/project.genmodel#//model ../../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#/">
<nestedGenPackages prefix="AF3GeneratorCommonLanguagesSource" disposableProviderFactory="true"
ecorePackage="languages.ecore#//source">
<genClasses ecoreClass="languages.ecore#//source/Source"/>
<nestedGenPackages prefix="AF3GeneratorCommonLanguagesSource" basePackage="org.fortiss.af3.generator.common.model"
disposableProviderFactory="true" ecorePackage="languages.ecore#//source">
<genClasses ecoreClass="languages.ecore#//source/SourcePackage">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute languages.ecore#//source/SourcePackage/baseLocation"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//source/SourcePackage/subPackages"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//source/SourcePackage/units"/>
<genOperations ecoreOperation="languages.ecore#//source/SourcePackage/writeToLocation">
<genParameters ecoreParameter="languages.ecore#//source/SourcePackage/writeToLocation/rootLocation"/>
</genOperations>
<genOperations ecoreOperation="languages.ecore#//source/SourcePackage/writeContentToLocation">
<genParameters ecoreParameter="languages.ecore#//source/SourcePackage/writeContentToLocation/rootLocation"/>
</genOperations>
</genClasses>
<genClasses ecoreClass="languages.ecore#//source/SourceUnit">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute languages.ecore#//source/SourceUnit/name"/>
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute languages.ecore#//source/SourceUnit/executable"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//source/SourceUnit/imports"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//source/SourceUnit/declarations"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//source/SourceUnit/definitions"/>
<genOperations ecoreOperation="languages.ecore#//source/SourceUnit/toSource"/>
</genClasses>
<genClasses ecoreClass="languages.ecore#//source/Import">
<genFeatures createChild="false" ecoreFeature="ecore:EAttribute languages.ecore#//source/Import/sourceUnitReference"/>
</genClasses>
<genClasses ecoreClass="languages.ecore#//source/Declaration"/>
<genClasses ecoreClass="languages.ecore#//source/Definition"/>
<genClasses ecoreClass="languages.ecore#//source/FormattedSourceUnit">
<genOperations ecoreOperation="languages.ecore#//source/FormattedSourceUnit/toFormattedSource"/>
<genOperations ecoreOperation="languages.ecore#//source/FormattedSourceUnit/toSource"/>
</genClasses>
</nestedGenPackages>
<nestedGenPackages prefix="C" basePackage="org.fortiss.af3.generator.common.model"
disposableProviderFactory="true" ecorePackage="languages.ecore#//c">
<genEnums typeSafeEnumCompatible="false" ecoreEnum="languages.ecore#//c/Modifier">
<genEnumLiterals ecoreEnumLiteral="languages.ecore#//c/Modifier/EXTERN"/>
<genEnumLiterals ecoreEnumLiteral="languages.ecore#//c/Modifier/STATIC"/>
<genEnumLiterals ecoreEnumLiteral="languages.ecore#//c/Modifier/NONE"/>
</genEnums>
<genClasses ecoreClass="languages.ecore#//c/HeaderFile"/>
<genClasses ecoreClass="languages.ecore#//c/ImplementationFile"/>
<genClasses ecoreClass="languages.ecore#//c/PreProcessorDefine"/>
<genClasses ecoreClass="languages.ecore#//c/Include"/>
<genClasses ecoreClass="languages.ecore#//c/FunctionDeclaration">
<genFeatures notify="false" createChild="false" propertySortChoices="true"
ecoreFeature="ecore:EReference languages.ecore#//c/FunctionDeclaration/definition"/>
</genClasses>
<genClasses ecoreClass="languages.ecore#//c/FunctionDefinition">
<genFeatures notify="false" createChild="false" propertySortChoices="true"
ecoreFeature="ecore:EReference languages.ecore#//c/FunctionDefinition/declaration"/>
</genClasses>
</nestedGenPackages>
<nestedGenPackages prefix="Imperative" basePackage="org.fortiss.af3.generator.common.model"
disposableProviderFactory="true" ecorePackage="languages.ecore#//imperative">
<genClasses ecoreClass="languages.ecore#//imperative/Program">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//imperative/Program/variables"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//imperative/Program/procedures"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//imperative/Program/subPrograms"/>
</genClasses>
<genClasses ecoreClass="languages.ecore#//imperative/Procedure">
<genFeatures notify="false" createChild="false" propertySortChoices="true"
ecoreFeature="ecore:EReference languages.ecore#//imperative/Procedure/type"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//imperative/Procedure/parameters"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//imperative/Procedure/body"/>
</genClasses>
<genClasses ecoreClass="languages.ecore#//imperative/Variable">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference languages.ecore#//imperative/Variable/type"/>
</genClasses>
</nestedGenPackages>
<nestedGenPackages prefix="C" disposableProviderFactory="true" ecorePackage="languages.ecore#//c"/>
</genPackages>
</genmodel:GenModel>
......@@ -10,8 +10,15 @@
<extension point="org.eclipse.emf.ecore.generated_package">
<package
uri="http://www.fortiss.org/af3/generator/common/languages/source"
class="org.fortiss.af3.generator.common.model.source.AF3GeneratorCommonLanguagesSourcePackage"
class="org.fortiss.af3.generator.common.model.oldsource.AF3GeneratorCommonLanguagesSourcePackage"
genModel="model/languages.genmodel"/>
<package
uri="http://www.fortiss.org/af3/generator/common/languages/c"
class="org.fortiss.af3.generator.common.model.oldsource.AF3GeneratorCommonLanguagesCPackage"
genModel="model/languages.genmodel"/>
<package
uri="http://www.fortiss.org/af3/generator/common/languages/imperative"
class="org.fortiss.af3.generator.common.model.oldsource.AF3GeneratorCommonLanguagesImperativePackage"
genModel="model/languages.genmodel"/>
</extension>
</plugin>
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.generator.common.model.oldc;
import org.fortiss.af3.project.model.typesystem.IType;
import org.fortiss.af3.project.model.typesystem.impl.ITypeImpl;
/**
* C base type instance, e.g. for type defined in supplementary C libraries.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: BF2A2F7834FFD3DB4620E1226B0124B6
*/
public final class BaseType extends ITypeImpl {
/** Stores the name. */
private String name;
/** Returns name. */
public String getName() {
return name;
}
/** Sets name. */
public void setName(String name) {
this.name = name;
}
/** Creates BaseType instance with the given identifier. */
public static IType create(String identifier) {
BaseType result = new BaseType();
result.setName(identifier);
return result;
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.generator.common.model.oldc;
import static org.fortiss.af3.generator.common.model.oldc.Modifier.EXTERN;
import static org.fortiss.af3.generator.common.model.oldc.Modifier.STATIC;
import static org.fortiss.af3.generator.common.model.oldc.Modifier.modifierString;
import java.util.Iterator;
import java.util.List;
import org.fortiss.af3.generator.common.model.oldsource.DeclarationBase;
import org.fortiss.af3.generator.common.model.oldsource.DefinitionBase;
import org.fortiss.af3.project.model.typesystem.ITerm;
import org.fortiss.af3.project.model.typesystem.IType;
/**
* C function model.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 8D9C858FD8870B220E6C22D023E4D311
*/
public class Function {
/** Stores function modifier. */
private final Modifier modifier;
/** Stores result type. */
private final IType type;
/** Stores the name of the function. */
private final String name;
/** Stores the parameter list. */
private final List<Variable> parameters;
/** Stores the local variables list. */
private final List<Variable> variables;
/** Stores the body of the function. */
private final ITerm body;
/** Stores the type string generator. */
private final ITypeStringGenerator generator;
/** Constructor. */
public Function(Modifier modifier, IType type, String name,
List<Variable> parameters, List<Variable> variables, ITerm body,
ITypeStringGenerator generator) {
this.modifier = modifier;
this.type = type;
this.name = name;
this.parameters = parameters;
this.variables = variables;
this.body = body;
this.generator = generator;
}
/** Constructor. */
public Function(Modifier modifier, IType type, String name,
List<Variable> parameters, List<Variable> variables, ITerm body) {
this(modifier, type, name, parameters, variables, body,
new IdentityTypeStringGenerator());
}
/** Generates forward declaration. */
public DeclarationBase getDeclaration() {
return new DeclarationBase() {
@Override
public String toString() {
String sig = getSignature();
sig = modifierString(modifier) + sig;
return sig + ";\n";
}
};
}
/** Generates function implementation. */
public DefinitionBase getDefinition() {
return new DefinitionBase() {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
if (!EXTERN.equals(modifier)) {
buf.append(modifierString(modifier));
}
buf.append(getSignature()).append(" {\n");
for (Variable cv : variables) {
buf.append(cv.toString()).append(";\n");
}
buf.append(body.toString());
buf.append("}\n");
return buf.toString();
}
};
}
/** Returns function signature. */
public String getSignature() {
StringBuffer buf = new StringBuffer();
buf.append(generator.getTypeString(type)).append(' ');
buf.append(name).append('(');
if (!parameters.isEmpty()) {
for (Iterator<Variable> it = parameters.iterator(); it.hasNext();) {
Variable locvar = it.next();
buf.append(locvar.toString());
if (it.hasNext()) {
buf.append(", ");
}
}
} else {
buf.append("void");
}
buf.append(')');
return buf.toString();
}
/** Returns the function name. */
public String getName() {
return name;
}
/** Creates external function. */
public static Function createExternFunction(IType type, String name,
List<Variable> parameters, List<Variable> variables, ITerm body,
ITypeStringGenerator generator) {
return new Function(EXTERN, type, name, parameters, variables, body,
generator);
}
/** Creates internal function. */
public static Function createInternFunction(IType type, String name,
List<Variable> parameters, List<Variable> variables, ITerm body,
ITypeStringGenerator generator) {
return new Function(STATIC, type, name, parameters, variables, body,
generator);
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2011 ForTISS GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.generator.common.model.oldc;
import java.util.Date;
import org.fortiss.af3.generator.common.model.oldsource.DeclarationBase;
import org.fortiss.af3.generator.common.model.oldsource.ImportBase;
import org.fortiss.af3.generator.common.model.oldsource.SourceUnitBase;