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

Finished another C code generator rework.

refs 857
parent 4c7c9139
......@@ -13,7 +13,7 @@ Require-Bundle: org.fortiss.af3.expression;bundle-version="2.1.0";visibility:=re
Export-Package: org.fortiss.af3.component,
org.fortiss.af3.component.constraint,
org.fortiss.af3.component.generator.c,
org.fortiss.af3.component.generator.imperative,
org.fortiss.af3.component.generator.component,
org.fortiss.af3.component.model,
org.fortiss.af3.component.model.behavior,
org.fortiss.af3.component.model.behavior.code,
......@@ -26,6 +26,9 @@ Export-Package: org.fortiss.af3.component,
org.fortiss.af3.component.model.behavior.util,
org.fortiss.af3.component.model.generator,
org.fortiss.af3.component.model.generator.impl,
org.fortiss.af3.component.model.generator.port,
org.fortiss.af3.component.model.generator.port.impl,
org.fortiss.af3.component.model.generator.port.util,
org.fortiss.af3.component.model.generator.util,
org.fortiss.af3.component.model.impl,
org.fortiss.af3.component.model.util,
......
......@@ -189,25 +189,48 @@
</eSubpackages>
<eSubpackages name="generator" nsURI="http://www.fortiss.org/af3/component/generator"
nsPrefix="org-fortiss-af3-component-generator">
<eClassifiers xsi:type="ecore:EClass" name="PortProgramFunction" eSuperTypes="platform:/plugin/org.fortiss.af3.expression/model/expression.ecore#//generator/ProgramFunction"/>
<eClassifiers xsi:type="ecore:EClass" name="PortProgramVariable" eSuperTypes="platform:/plugin/org.fortiss.af3.expression/model/expression.ecore#//generator/ProgramVariable"/>
<eClassifiers xsi:type="ecore:EClass" name="PortVariableOperation" abstract="true"
interface="true" eSuperTypes="platform:/plugin/org.fortiss.af3.project/model/project.ecore#//typesystem/ITerm">
<eStructuralFeatures xsi:type="ecore:EReference" name="variable" eType="#//generator/PortProgramVariable"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="argument" eType="#//generator/PortVariableOperationArgument"
containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="SetPortVariableStatement" eSuperTypes="#//generator/PortVariableOperation platform:/plugin/org.fortiss.af3.expression/model/expression.ecore#//terms/imperative/IStatementTerm"/>
<eClassifiers xsi:type="ecore:EClass" name="GetPortVariableExpression" eSuperTypes="#//generator/PortVariableOperation platform:/plugin/org.fortiss.af3.expression/model/expression.ecore#//terms/IExpressionTerm"/>
<eClassifiers xsi:type="ecore:EClass" name="TestPortVariableExpression" eSuperTypes="#//generator/PortVariableOperation platform:/plugin/org.fortiss.af3.expression/model/expression.ecore#//terms/IExpressionTerm"/>
<eClassifiers xsi:type="ecore:EClass" name="PortVariableOperationArgument" abstract="true"/>
<eClassifiers xsi:type="ecore:EClass" name="NoValArgument" eSuperTypes="#//generator/PortVariableOperationArgument"/>
<eClassifiers xsi:type="ecore:EClass" name="PortArgument" eSuperTypes="#//generator/PortVariableOperationArgument">
<eStructuralFeatures xsi:type="ecore:EReference" name="portVariable" eType="#//generator/PortProgramVariable"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ValueArgument" eSuperTypes="#//generator/PortVariableOperationArgument">
<eStructuralFeatures xsi:type="ecore:EReference" name="value" eType="ecore:EClass platform:/plugin/org.fortiss.af3.expression/model/expression.ecore#//terms/IExpressionTerm"
<eClassifiers xsi:type="ecore:EClass" name="ComponentProgram" eSuperTypes="platform:/plugin/org.fortiss.tooling.kernel/model/kernel.ecore#//INamedElement">
<eStructuralFeatures xsi:type="ecore:EReference" name="subPrograms" upperBound="-1"
eType="#//generator/ComponentProgram" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="portVariables" upperBound="-1"
eType="#//generator/PortVariable" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="initializeFunction" eType="#//generator/ComponentFunction"
containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="performStepFunction"
eType="#//generator/ComponentFunction" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="clearInputsFunction"
eType="#//generator/ComponentFunction" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="clearOutputsFunction"
eType="#//generator/ComponentFunction" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="localVariables" upperBound="-1"
eType="#//generator/LocalVariable" containment="true"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="localFunctions" upperBound="-1"
eType="#//generator/LocalFunction" containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ComponentFunction" eSuperTypes="platform:/plugin/org.fortiss.af3.expression/model/expression.ecore#//definitions/FunctionDefinition"/>
<eClassifiers xsi:type="ecore:EClass" name="LocalFunction" eSuperTypes="platform:/plugin/org.fortiss.af3.expression/model/expression.ecore#//definitions/FunctionDefinition"/>
<eClassifiers xsi:type="ecore:EClass" name="PortVariable" eSuperTypes="platform:/plugin/org.fortiss.af3.expression/model/expression.ecore#//definitions/FunctionParameter"/>
<eClassifiers xsi:type="ecore:EClass" name="LocalVariable" eSuperTypes="platform:/plugin/org.fortiss.af3.expression/model/expression.ecore#//definitions/FunctionParameter"/>
<eSubpackages name="port" nsURI="http://www.fortiss.org/af3/component/generator/port"
nsPrefix="org-fortiss-af3-component-generator-port">
<eClassifiers xsi:type="ecore:EClass" name="PortVariableOperation" abstract="true"
interface="true" eSuperTypes="platform:/plugin/org.fortiss.af3.project/model/project.ecore#//typesystem/ITerm">
<eStructuralFeatures xsi:type="ecore:EReference" name="variable" eType="#//generator/PortVariable"/>
<eStructuralFeatures xsi:type="ecore:EReference" name="argument" eType="#//generator/port/PortVariableOperationArgument"
containment="true"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="WritePortVariableStatement" eSuperTypes="#//generator/port/PortVariableOperation platform:/plugin/org.fortiss.af3.expression/model/expression.ecore#//terms/imperative/IStatementTerm"/>
<eClassifiers xsi:type="ecore:EClass" name="ReadPortVariableExpression" eSuperTypes="#//generator/port/PortVariableOperation platform:/plugin/org.fortiss.af3.expression/model/expression.ecore#//terms/IExpressionTerm"/>
<eClassifiers xsi:type="ecore:EClass" name="TestPortVariableExpression" eSuperTypes="#//generator/port/PortVariableOperation platform:/plugin/org.fortiss.af3.expression/model/expression.ecore#//terms/IExpressionTerm"/>
<eClassifiers xsi:type="ecore:EClass" name="PortVariableOperationArgument" abstract="true"/>
<eClassifiers xsi:type="ecore:EClass" name="NoValArgument" eSuperTypes="#//generator/port/PortVariableOperationArgument"/>
<eClassifiers xsi:type="ecore:EClass" name="PortArgument" eSuperTypes="#//generator/port/PortVariableOperationArgument">
<eStructuralFeatures xsi:type="ecore:EReference" name="portVariable" eType="#//generator/PortVariable"/>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="ValueArgument" eSuperTypes="#//generator/port/PortVariableOperationArgument">
<eStructuralFeatures xsi:type="ecore:EReference" name="value" eType="ecore:EClass platform:/plugin/org.fortiss.af3.expression/model/expression.ecore#//terms/IExpressionTerm"
containment="true"/>
</eClassifiers>
</eSubpackages>
</eSubpackages>
</ecore:EPackage>
......@@ -87,25 +87,40 @@
</nestedGenPackages>
<nestedGenPackages prefix="Generator" basePackage="org.fortiss.af3.component.model"
disposableProviderFactory="true" ecorePackage="component.ecore#//generator">
<genClasses ecoreClass="component.ecore#//generator/PortProgramFunction"/>
<genClasses ecoreClass="component.ecore#//generator/PortProgramVariable"/>
<genClasses image="false" ecoreClass="component.ecore#//generator/PortVariableOperation">
<genFeatures notify="false" createChild="false" propertySortChoices="true"
ecoreFeature="ecore:EReference component.ecore#//generator/PortVariableOperation/variable"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//generator/PortVariableOperation/argument"/>
</genClasses>
<genClasses image="false" ecoreClass="component.ecore#//generator/SetPortVariableStatement"/>
<genClasses image="false" ecoreClass="component.ecore#//generator/GetPortVariableExpression"/>
<genClasses image="false" ecoreClass="component.ecore#//generator/TestPortVariableExpression"/>
<genClasses image="false" ecoreClass="component.ecore#//generator/PortVariableOperationArgument"/>
<genClasses ecoreClass="component.ecore#//generator/NoValArgument"/>
<genClasses ecoreClass="component.ecore#//generator/PortArgument">
<genFeatures notify="false" createChild="false" propertySortChoices="true"
ecoreFeature="ecore:EReference component.ecore#//generator/PortArgument/portVariable"/>
</genClasses>
<genClasses ecoreClass="component.ecore#//generator/ValueArgument">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//generator/ValueArgument/value"/>
<genClasses ecoreClass="component.ecore#//generator/ComponentProgram">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//generator/ComponentProgram/subPrograms"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//generator/ComponentProgram/portVariables"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//generator/ComponentProgram/initializeFunction"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//generator/ComponentProgram/performStepFunction"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//generator/ComponentProgram/clearInputsFunction"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//generator/ComponentProgram/clearOutputsFunction"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//generator/ComponentProgram/localVariables"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//generator/ComponentProgram/localFunctions"/>
</genClasses>
<genClasses ecoreClass="component.ecore#//generator/ComponentFunction"/>
<genClasses ecoreClass="component.ecore#//generator/LocalFunction"/>
<genClasses ecoreClass="component.ecore#//generator/PortVariable"/>
<genClasses ecoreClass="component.ecore#//generator/LocalVariable"/>
<nestedGenPackages prefix="Port" basePackage="org.fortiss.af3.component.model.generator"
disposableProviderFactory="true" ecorePackage="component.ecore#//generator/port">
<genClasses image="false" ecoreClass="component.ecore#//generator/port/PortVariableOperation">
<genFeatures notify="false" createChild="false" propertySortChoices="true"
ecoreFeature="ecore:EReference component.ecore#//generator/port/PortVariableOperation/variable"/>
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//generator/port/PortVariableOperation/argument"/>
</genClasses>
<genClasses ecoreClass="component.ecore#//generator/port/WritePortVariableStatement"/>
<genClasses ecoreClass="component.ecore#//generator/port/ReadPortVariableExpression"/>
<genClasses ecoreClass="component.ecore#//generator/port/TestPortVariableExpression"/>
<genClasses image="false" ecoreClass="component.ecore#//generator/port/PortVariableOperationArgument"/>
<genClasses ecoreClass="component.ecore#//generator/port/NoValArgument"/>
<genClasses ecoreClass="component.ecore#//generator/port/PortArgument">
<genFeatures notify="false" createChild="false" propertySortChoices="true"
ecoreFeature="ecore:EReference component.ecore#//generator/port/PortArgument/portVariable"/>
</genClasses>
<genClasses ecoreClass="component.ecore#//generator/port/ValueArgument">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference component.ecore#//generator/port/ValueArgument/value"/>
</genClasses>
</nestedGenPackages>
</nestedGenPackages>
</genPackages>
</genmodel:GenModel>
......@@ -112,7 +112,7 @@
<extension
point="org.fortiss.tooling.kernel.transformationProvider">
<transformationProvider
transformationProvider="org.fortiss.af3.component.generator.c.ComponentArchitectureTransformation">
transformationProvider="org.fortiss.af3.component.generator.c.ComponentArchitectureToCSourcePackageTransformation">
<source>
<objectClass
objectClass="org.fortiss.af3.component.model.ComponentArchitecture">
......@@ -125,20 +125,20 @@
</target>
</transformationProvider>
<transformationProvider
transformationProvider="org.fortiss.af3.component.generator.imperative.CodeSpecificationTransformation">
transformationProvider="org.fortiss.af3.component.generator.c.ComponentProgramToCSourcePackageTransformation">
<source>
<objectClass
objectClass="org.fortiss.af3.component.model.Component">
objectClass="org.fortiss.af3.component.model.generator.ComponentProgram">
</objectClass>
</source>
<target>
<objectClass
objectClass="org.fortiss.af3.expression.model.generator.Program">
objectClass="org.fortiss.af3.generator.common.model.c.CSourcePackage">
</objectClass>
</target>
</transformationProvider>
<transformationProvider
transformationProvider="org.fortiss.af3.component.generator.imperative.CompositeComponentTransformation">
transformationProvider="org.fortiss.af3.component.generator.component.CodeSpecificationToComponentProgramTransformation">
<source>
<objectClass
objectClass="org.fortiss.af3.component.model.Component">
......@@ -146,27 +146,22 @@
</source>
<target>
<objectClass
objectClass="org.fortiss.af3.expression.model.generator.Program">
objectClass="org.fortiss.af3.component.model.generator.ComponentProgram">
</objectClass>
</target>
</transformationProvider>
<transformationProvider
transformationProvider="org.fortiss.af3.component.generator.c.CTransformer">
transformationProvider="org.fortiss.af3.component.generator.component.CompositeComponentToComponentProgramTransformation">
<source>
<objectClass
objectClass="org.fortiss.af3.component.model.generator.PortProgramVariable">
</objectClass>
<objectClass
objectClass="org.fortiss.af3.component.model.generator.PortProgramFunction">
objectClass="org.fortiss.af3.component.model.Component">
</objectClass>
</source>
<target>
<objectClass
objectClass="org.fortiss.af3.expression.generator.c.ICTransformer">
objectClass="org.fortiss.af3.component.model.generator.ComponentProgram">
</objectClass>
</target>
</transformationProvider>
</extension>
</plugin>
......@@ -17,7 +17,7 @@ $Id$
+--------------------------------------------------------------------------*/
package org.fortiss.af3.component.generator.c;
import static org.fortiss.af3.component.generator.c.CTransformer.getPortNoValIdentifier;
import static org.fortiss.af3.component.generator.c.ComponentProgramToCSourcePackageTransformation.getPortNoValIdentifier;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.and;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.assignment;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.boolConst;
......@@ -28,15 +28,15 @@ import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.or;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.sequence;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.var;
import org.fortiss.af3.component.model.generator.GetPortVariableExpression;
import org.fortiss.af3.component.model.generator.NoValArgument;
import org.fortiss.af3.component.model.generator.PortArgument;
import org.fortiss.af3.component.model.generator.PortVariableOperation;
import org.fortiss.af3.component.model.generator.PortVariableOperationArgument;
import org.fortiss.af3.component.model.generator.SetPortVariableStatement;
import org.fortiss.af3.component.model.generator.TestPortVariableExpression;
import org.fortiss.af3.component.model.generator.ValueArgument;
import org.fortiss.af3.expression.generator.imperative.TermReplacementVisitor;
import org.fortiss.af3.component.model.generator.port.NoValArgument;
import org.fortiss.af3.component.model.generator.port.PortArgument;
import org.fortiss.af3.component.model.generator.port.PortVariableOperation;
import org.fortiss.af3.component.model.generator.port.PortVariableOperationArgument;
import org.fortiss.af3.component.model.generator.port.ReadPortVariableExpression;
import org.fortiss.af3.component.model.generator.port.TestPortVariableExpression;
import org.fortiss.af3.component.model.generator.port.ValueArgument;
import org.fortiss.af3.component.model.generator.port.WritePortVariableStatement;
import org.fortiss.af3.expression.generator.TermReplacementVisitor;
import org.fortiss.af3.expression.model.terms.IExpressionTerm;
import org.fortiss.af3.expression.model.terms.imperative.Assignment;
import org.fortiss.af3.expression.model.terms.imperative.IfThenElse;
......@@ -49,9 +49,9 @@ import org.fortiss.af3.project.model.typesystem.ITerm;
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 7E652A47828864BAE61C858C423614B9
* @ConQAT.Rating YELLOW Hash: C8B5991B68C3C69513022526B95F0A2D
*/
public class CReplacement extends TermReplacementVisitor {
class CReplacement extends TermReplacementVisitor {
/** Constructor. */
public CReplacement(StatementSequence seq) {
super(seq);
......@@ -60,20 +60,20 @@ public class CReplacement extends TermReplacementVisitor {
/** {@inheritDoc} */
@Override
protected ITerm applyInternal(ITerm term) {
if(term instanceof SetPortVariableStatement) {
return setPortCode((SetPortVariableStatement)term);
if(term instanceof WritePortVariableStatement) {
return setPortCode((WritePortVariableStatement)term);
}
if(term instanceof TestPortVariableExpression) {
return testPortCode((TestPortVariableExpression)term);
}
if(term instanceof GetPortVariableExpression) {
return getPortCode((GetPortVariableExpression)term);
if(term instanceof ReadPortVariableExpression) {
return getPortCode((ReadPortVariableExpression)term);
}
return super.applyInternal(term);
}
/** Creates the port setter code. */
private ITerm setPortCode(SetPortVariableStatement term) {
private ITerm setPortCode(WritePortVariableStatement term) {
PortVariableOperationArgument arg = term.getArgument();
String targetPortName = term.getVariable().getVar().getIdentifier();
String targetNoValVar = getPortNoValIdentifier(targetPortName);
......@@ -127,7 +127,7 @@ public class CReplacement extends TermReplacementVisitor {
}
/** Returns the port getter code. */
private ITerm getPortCode(GetPortVariableExpression term) {
private ITerm getPortCode(ReadPortVariableExpression term) {
return var(term.getVariable().getVar().getIdentifier());
}
}
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2012 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.component.generator.c;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.boolType;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createCVariable;
import java.util.ArrayList;
import java.util.List;
import org.fortiss.af3.component.model.generator.PortProgramVariable;
import org.fortiss.af3.component.model.generator.impl.PortProgramFunctionImpl;
import org.fortiss.af3.component.model.generator.impl.PortProgramVariableImpl;
import org.fortiss.af3.expression.generator.c.DefaultCTransformer;
import org.fortiss.af3.expression.generator.c.ICTransformer;
import org.fortiss.af3.expression.model.generator.ProgramFunction;
import org.fortiss.af3.expression.model.generator.ProgramVariable;
import org.fortiss.af3.expression.model.terms.imperative.StatementSequence;
import org.fortiss.af3.generator.common.model.c.CFunctionDefinition;
import org.fortiss.af3.generator.common.model.c.CVariable;
import org.fortiss.tooling.kernel.extension.ITransformationProvider;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
/**
* Transforms {@link PortProgramVariable}s into two {@link CVariable}s.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 71CFE22AF678F4129DAE4C8BB2D4FC49
*/
public class CTransformer extends DefaultCTransformer implements ITransformationProvider {
/** The prefix of the NoVal port variables. */
private static final String NOVAL_PORT_VARIABLE_PREFIX = "noval_";
/** Returns the port NoVal variable identifier. */
public static String getPortNoValIdentifier(String pVar) {
return NOVAL_PORT_VARIABLE_PREFIX + pVar;
}
/** {@inheritDoc} */
@Override
public List<CVariable> createCVariablesFor(ProgramVariable progVar) {
List<CVariable> result = new ArrayList<CVariable>();
String progVarName = progVar.getVar().getIdentifier();
result.add(createCVariable(progVarName, progVar.getType()));
result.add(createCVariable(getPortNoValIdentifier(progVarName), boolType()));
return result;
}
/** {@inheritDoc} */
@Override
public List<CFunctionDefinition> createCFunctionsFor(ProgramFunction progFun) {
List<CFunctionDefinition> result = super.createCFunctionsFor(progFun);
StatementSequence replaced =
(StatementSequence)new CReplacement(progFun.getDefinition()).apply();
result.get(0).setBody(replaced);
return result;
}
/** {@inheritDoc} */
@Override
public Class<?> getTargetClass() {
return ICTransformer.class;
}
/** {@inheritDoc} */
@Override
public boolean
canHandleChainTransformation(Class<?> sourceClass, ITransformationContext context) {
return PortProgramVariableImpl.class.isAssignableFrom(sourceClass) ||
PortProgramFunctionImpl.class.isAssignableFrom(sourceClass);
}
/** {@inheritDoc} */
@Override
public boolean canTransform(Object source, ITransformationContext context) {
return source.getClass() == PortProgramVariableImpl.class ||
source.getClass() == PortProgramFunctionImpl.class;
}
/** {@inheritDoc} */
@Override
public Object transform(Object source, ITransformationContext context) {
return this;
}
}
......@@ -38,9 +38,9 @@ import org.fortiss.tooling.kernel.extension.exception.TransformationFailedExcept
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: 12730E4A705D109AD7C381412AF50A62
* @ConQAT.Rating YELLOW Hash: 8401983CD251DA509F01032FFE518959
*/
public class ComponentArchitectureTransformation implements ITransformationProvider {
public class ComponentArchitectureToCSourcePackageTransformation implements ITransformationProvider {
/** {@inheritDoc} */
@Override
......
......@@ -15,230 +15,162 @@ $Id$
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.expression.generator.c;
package org.fortiss.af3.component.generator.c;
import static org.fortiss.af3.expression.generator.c.DefaultCTransformer.DEFAULT_CVARIABLE_TRANSFORMER;
import static org.fortiss.af3.expression.generator.c.DataDictionaryToCSourcePackageTransformation.DATA_DICTIONARY_SOURCE_UNIT;
import static org.fortiss.af3.expression.utils.ExpressionModelElementFactory.boolType;
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 static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createCBooleanDeclaration;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createCDoubleDeclaration;
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.CLanguageModelElementFacade.addDeclaration;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFacade.addDefinition;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFacade.addExternVariableDeclaration;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFacade.addGeneratedHeader;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFacade.addGeneratedHeaderInclude;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFacade.addGeneratedSource;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFacade.addParameter;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFacade.addVariableDeclaration;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createCFunctionDeclaration;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createCIntDeclaration;
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.createCVariableDeclaration;
import static org.fortiss.af3.generator.common.utils.CLanguageModelElementFactory.createGeneratedHeaderInclude;
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.createUserHeaderInclude;
import static org.fortiss.af3.generator.common.utils.SourceUtils.mergeSourcePackageInto;
import static org.fortiss.tooling.kernel.utils.IdentifierUtils.getUniqueIdentifier;
import static org.fortiss.tooling.kernel.utils.TransformationUtils.createTransformedObjectFor;
import java.util.ArrayList;
import java.util.List;
import org.fortiss.af3.expression.model.definitions.BoolTypeDefinition;
import org.fortiss.af3.expression.model.definitions.DoubleTypeDefinition;
import org.fortiss.af3.expression.model.definitions.Enumeration;
import org.fortiss.af3.expression.model.definitions.EnumerationMember;
import org.fortiss.af3.expression.model.definitions.IntTypeDefinition;
import org.fortiss.af3.expression.model.generator.PlaceholderProgram;
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.generator.impl.ProgramFunctionImpl;
import org.fortiss.af3.expression.model.generator.impl.ProgramVariableImpl;
import org.fortiss.af3.component.model.generator.ComponentFunction;
import org.fortiss.af3.component.model.generator.ComponentProgram;
import org.fortiss.af3.component.model.generator.LocalFunction;
import org.fortiss.af3.component.model.generator.LocalVariable;
import org.fortiss.af3.component.model.generator.PortVariable;
import org.fortiss.af3.expression.model.definitions.FunctionDefinition;
import org.fortiss.af3.expression.model.definitions.FunctionParameter;
import org.fortiss.af3.expression.model.terms.imperative.StatementSequence;
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.source.SourcePackage;
import org.fortiss.af3.project.model.typesystem.ITypeDefinition;
import org.fortiss.tooling.kernel.extension.ITransformationProvider;
import org.fortiss.tooling.kernel.extension.base.TransformationProviderBase;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
import org.fortiss.tooling.kernel.extension.exception.TransformationFailedException;
/**
* An {@link ITransformationProvider} for the transformation of {@link Program} into a C
* An {@link ITransformationProvider} for the transformation of {@link ComponentProgram} into a C
* {@link SourcePackage}. The resulting package contains two sub-packages {@code inc-gen} and
* {@code src-gen}, which contain the header and implementation files respectively. It also creates
* the two sub-packages intended for hand-written code (named {@code inc} and {@code src},
* respectively).
* <P>
* If the transformation source program contains sub-programs these are also converted and placed in
* the respective packages. The only exception are instances of {@link PlaceholderProgram}, which
* are only referenced as {@link CInclude}s from their parent programs. Their header and
* implementation files are expected to be provided at compile time in the hand-written packages. At
* least the header file must be present in {@code inc} package since the include statement refers
* to that package. You may provide the implementation file in {@code src} package or use library
* during application linking.
* the respective packages.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: F881966EAA4F95A1D92F48DA1AB4FEE4
* @ConQAT.Rating YELLOW Hash: 48CD33BA4FFA05C414C30D9DB6A7A6EA
*/
public class ProgramTransformation implements ITransformationProvider {
public class ComponentProgramToCSourcePackageTransformation extends
TransformationProviderBase<ComponentProgram, CSourcePackage> {
/** {@inheritDoc} */
@Override
public Class<?> getTargetClass() {
return CSourcePackage.class;
protected Class<ComponentProgram> getSourceClass() {
return ComponentProgram.class;
}
/** {@inheritDoc} */
@Override
public boolean
canHandleChainTransformation(Class<?> sourceClass, ITransformationContext context) {
return Program.class.isAssignableFrom(sourceClass);
}
/** {@inheritDoc} */
@Override
public boolean canTransform(Object source, ITransformationContext context) {
return source instanceof Program;
public Class<CSourcePackage> getTargetClass() {
return CSourcePackage.class;
}
/** {@inheritDoc} */
@Override
public Object transform(Object source, ITransformationContext context)
public CSourcePackage transform(Object source, ITransformationContext context)
throws TransformationFailedException {
Program p = (Program)source;
ComponentProgram p = (ComponentProgram)source;
CSourcePackage pack = createCSourcePackage();
List<CFunctionDeclaration> cFunctions = prepareProgramFunctions(p, context);
pack.getIncGenPackage().getUnitsList().add(createHeader(p, cFunctions, context));
pack.getSrcGenPackage().getUnitsList().add(createImplementation(p, cFunctions, context));
for(Program subProg : p.getSubProgramsList()) {
if(subProg instanceof PlaceholderProgram) {
continue;
}
CSourcePackage subPack = (CSourcePackage)transform(subProg, context);
mergeSourcePackageInto(subPack, pack);