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

creating data_dictionary.c

refs 118
parent 59d97022
......@@ -17,11 +17,12 @@ $Id: SimulatorEasyStartMenu.java 2798 2012-01-16 13:15:45Z becker $
+--------------------------------------------------------------------------*/
package org.fortiss.af3.component.ui.generator;
import static org.fortiss.af3.project.ui.AF3ProjectUIActivator.getImageDescriptor;
import org.eclipse.jface.resource.ImageDescriptor;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.project.extension.IExecutionTarget;
import org.fortiss.af3.project.services.IExecutionService;
import org.fortiss.af3.project.ui.AF3ProjectUIActivator;
import org.fortiss.af3.project.ui.execution.EasyStartMenuBase;
import org.fortiss.tooling.kernel.model.INamedElement;
import org.fortiss.tooling.kernel.ui.extension.data.ContextMenuContextProvider;
......@@ -59,8 +60,8 @@ public class CCodeGeneratorEasyStartMenu extends EasyStartMenuBase {
@Override
protected boolean acceptSelection(INamedElement selection,
ContextMenuContextProvider contextProvider) {
return (selection instanceof ComponentArchitecture)
&& INavigatorService.INSTANCE.isNavigatorView(contextProvider);
return (selection instanceof ComponentArchitecture) &&
INavigatorService.INSTANCE.isNavigatorView(contextProvider);
}
/** {@inheritDoc} */
......@@ -72,8 +73,7 @@ public class CCodeGeneratorEasyStartMenu extends EasyStartMenuBase {
/** {@inheritDoc} */
@Override
protected ImageDescriptor getActionIcon() {
return AF3ProjectUIActivator
.getImageDescriptor("icons/execution_configuration.gif");
return getImageDescriptor("icons/execution_configuration.gif");
}
/** {@inheritDoc} */
......
......@@ -26,11 +26,10 @@ import java.io.IOException;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.fortiss.af3.component.generator.c.CSourceComponent;
import org.fortiss.af3.component.ui.AF3ComponentUIActivator;
import org.fortiss.af3.generator.common.model.c.CSourcePackage;
import org.fortiss.af3.project.extension.base.ExecutionTargetBase;
import org.fortiss.af3.project.extension.data.Executable;
import org.fortiss.tooling.base.model.element.IModelElementSpecification;
/**
* Execution target implementation for the C code generator.
......@@ -45,37 +44,33 @@ public class CGeneratorExecutionTarget extends ExecutionTargetBase {
/** {@inheritDoc} */
@Override
public String getName() {
return "C Generator";
return "C Code Generator";
}
/** {@inheritDoc} */
@Override
public Class<?> getExecutableClass() {
return CSourceComponent.class;
return CSourcePackage.class;
}
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
protected void doExecute(Executable executable) {
CSourceComponent<IModelElementSpecification> sourceComponent = (CSourceComponent<IModelElementSpecification>) executable
.getExecutableObject();
CSourcePackage cSource = (CSourcePackage)executable.getExecutableObject();
IResource targetFolder = openFolderDialog();
if (targetFolder == null) {
if(targetFolder == null) {
return;
}
// write source
try {
// get the generated package and writes its content to the target
// folder location
sourceComponent.getSourcePackage().writeContentToLocation(
targetFolder.getLocation().toOSString());
} catch (IOException ioex) {
cSource.writeContentToLocation(targetFolder.getLocation().toOSString());
} catch(IOException ioex) {
error(AF3ComponentUIActivator.getDefault(), ioex.getMessage(), ioex);
}
// refresh workspace
try {
targetFolder.refreshLocal(IResource.DEPTH_INFINITE,
new NullProgressMonitor());
} catch (CoreException cex) {
targetFolder.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
} catch(CoreException cex) {
error(AF3ComponentUIActivator.getDefault(), cex.getMessage(), cex);
}
}
......
......@@ -133,6 +133,35 @@
</modelElementClass>
</modelElementConstraintChecker>
</extension>
<extension
point="org.fortiss.tooling.kernel.transformationProvider">
<transformationProvider
transformationProvider="org.fortiss.af3.component.generator.c.ComponentArchitectureTransformation">
<source>
<objectClass
objectClass="org.fortiss.af3.component.model.ComponentArchitecture">
</objectClass>
</source>
<target>
<objectClass
objectClass="org.fortiss.af3.generator.common.model.c.CSourcePackage">
</objectClass>
</target>
</transformationProvider>
<transformationProvider
transformationProvider="org.fortiss.af3.component.generator.c.ComponentTransformation">
<source>
<objectClass
objectClass="org.fortiss.af3.component.model.Component">
</objectClass>
</source>
<target>
<objectClass
objectClass="org.fortiss.af3.generator.common.model.c.CSourcePackage">
</objectClass>
</target>
</transformationProvider>
</extension>
</plugin>
......@@ -37,13 +37,13 @@ import org.fortiss.af3.generator.common.model.oldsource.SourcePackage;
/**
* {@link CSourceComponent} for {@link CodeSpecification}.
*
* @deprecated
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: FDBEB59C3DC3D222CC45EF30B61B2936
*/
public class CSourceCodeSpecification extends
CSourceComponent<CodeSpecification> {
public class CSourceCodeSpecification extends CSourceComponent<CodeSpecification> {
/** Constructor. */
public CSourceCodeSpecification(CodeSpecification specification) {
......@@ -57,16 +57,13 @@ public class CSourceCodeSpecification extends
protected Function createPerformStepFunction() {
StatementSequence seq = sequence(assignment(funcCall(CLEAR_OUTPUTS_FUNCTION_NAME)));
seq.getStatementsList().add(copy(specification.getBody()));
return createExternFunction(VOID_TYPE, getPerformStepFunctionName(),
EMPTY_LIST, EMPTY_LIST,
applyReplacement(seq, portVariableReplacement),
TYPE_STRING_GENERATOR);
return createExternFunction(VOID_TYPE, getPerformStepFunctionName(), EMPTY_LIST,
EMPTY_LIST, applyReplacement(seq, portVariableReplacement), TYPE_STRING_GENERATOR);
}
/** {@inheritDoc} */
@Override
protected void addSupplementaryFunction(
List<Function> supplementaryFunctions) {
protected void addSupplementaryFunction(List<Function> supplementaryFunctions) {
supplementaryFunctions.add(generateClearOutputsFunction());
}
......@@ -74,12 +71,11 @@ public class CSourceCodeSpecification extends
@Override
public SourcePackage getSourcePackage() {
SourcePackage sp;
if (parentExecutable == null) {
if(parentExecutable == null) {
sp = createRootSourcePackage();
// see createRootSourcePackage() for creation of sub-packages
sp.getSubPackages().get(0).addSourceUnit(getHeaderFile());
sp.getSubPackages().get(1)
.addSourceUnit(createImplementationFile());
sp.getSubPackages().get(1).addSourceUnit(createImplementationFile());
} else {
sp = new SourcePackage(getIdentifier());
sp.addSourceUnit(getHeaderFile());
......
......@@ -27,34 +27,32 @@ import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
* Transformation for a {@link Component} with a {@link CodeSpecification} into
* an {@link CSourceCodeSpecification};
*
* @deprecated
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 08B729F46F15E5A63F15CB4BC70A7673
*/
public class CSourceCodeSpecificationTransformation extends
CSourceComponentTransformationBase {
public class CSourceCodeSpecificationTransformation extends CSourceComponentTransformationBase {
/** {@inheritDoc} */
@Override
public boolean canHandleChainTransformation(Class<?> sourceClass,
ITransformationContext context) {
public boolean
canHandleChainTransformation(Class<?> sourceClass, ITransformationContext context) {
return Component.class.isAssignableFrom(sourceClass);
}
/** {@inheritDoc} */
@Override
public boolean canTransform(Object source, ITransformationContext context) {
return source instanceof Component
&& pickInstanceOf(CodeSpecification.class,
((Component) source).getSpecificationsList()) != null;
return source instanceof Component &&
pickInstanceOf(CodeSpecification.class, ((Component)source).getSpecificationsList()) != null;
}
/** {@inheritDoc} */
@Override
public Object transform(Object source, ITransformationContext context) {
return new CSourceCodeSpecification(pickInstanceOf(
CodeSpecification.class,
((Component) source).getSpecificationsList()));
return new CSourceCodeSpecification(pickInstanceOf(CodeSpecification.class,
((Component)source).getSpecificationsList()));
}
}
......@@ -67,6 +67,7 @@ import org.fortiss.tooling.kernel.model.INamedElement;
/**
* Transformation result and executable of the C code generator.
*
* @deprecated
* @author hoelzl
* @author $Author$
* @version $Rev$
......
......@@ -27,16 +27,15 @@ import org.fortiss.tooling.kernel.extension.exception.ChainTransformationFailedE
import org.fortiss.tooling.kernel.extension.exception.TransformationFailedException;
/**
* Base implementation for transformation of {@link Component}s into
* {@link CSourceComponent}s.
* Base implementation for transformation of {@link Component}s into {@link CSourceComponent}s.
*
* @deprecated
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: 92AF9E5F1BFB1CF994F337421F2749D0
*/
public abstract class CSourceComponentTransformationBase implements
ITransformationProvider {
public abstract class CSourceComponentTransformationBase implements ITransformationProvider {
/** {@inheritDoc} */
@SuppressWarnings("rawtypes")
......@@ -50,11 +49,11 @@ public abstract class CSourceComponentTransformationBase implements
* using the context.
*/
@SuppressWarnings("unchecked")
protected final CSourceComponent<? extends IModelElementSpecification> createExecutableForSpecification(
IModelElementSpecification specification, Class<?> targetClass,
ITransformationContext context)
throws ChainTransformationFailedException {
return (CSourceComponent<? extends IModelElementSpecification>) createTransformedObjectFor(
protected final CSourceComponent<? extends IModelElementSpecification>
createExecutableForSpecification(IModelElementSpecification specification,
Class<?> targetClass, ITransformationContext context)
throws ChainTransformationFailedException {
return (CSourceComponent<? extends IModelElementSpecification>)createTransformedObjectFor(
specification, targetClass, context);
}
......@@ -73,17 +72,17 @@ public abstract class CSourceComponentTransformationBase implements
TransformationFailedException lastException = null;
// Try component itself.
try {
CSourceComponent<? extends IModelElementSpecification> exec = createTransformedObjectFor(
component, getTargetClass(), context);
if (exec != null) {
CSourceComponent<? extends IModelElementSpecification> exec =
createTransformedObjectFor(component, getTargetClass(), context);
if(exec != null) {
// Found a transformation for the component, which succeeded.
return exec;
}
} catch (ChainTransformationFailedException cex) {
} catch(ChainTransformationFailedException cex) {
// Component transformation failed.
lastException = cex;
}
if (lastException != null) {
if(lastException != null) {
// There is a possible transformation, either of specification or
// component, which failed.
throw lastException;
......
......@@ -46,6 +46,7 @@ import org.fortiss.tooling.base.model.element.IModelElementSpecification;
/**
* {@link CSourceComponent} for composite components.
*
* @deprecated
* @author hoelzl
* @author $Author$
* @version $Rev$
......
......@@ -32,52 +32,48 @@ import org.fortiss.tooling.kernel.extension.exception.TransformationFailedExcept
/**
* {@link ITransformationProvider} for composite {@link Component}s.
*
* @deprecated
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating GREEN Hash: D5920BC59EA8DE764BD248D5AFE80C24
*/
public class CSourceCompositeComponentTransformation extends
CSourceComponentTransformationBase {
public class CSourceCompositeComponentTransformation extends CSourceComponentTransformationBase {
/** {@inheritDoc} */
@Override
public boolean canHandleChainTransformation(Class<?> sourceClass,
ITransformationContext context) {
return Component.class.isAssignableFrom(sourceClass)
|| ComponentArchitecture.class.isAssignableFrom(sourceClass);
public boolean
canHandleChainTransformation(Class<?> sourceClass, ITransformationContext context) {
return Component.class.isAssignableFrom(sourceClass) ||
ComponentArchitecture.class.isAssignableFrom(sourceClass);
}
/** {@inheritDoc} */
@Override
public boolean canTransform(Object source, ITransformationContext context) {
if (source instanceof ComponentArchitecture) {
source = ((ComponentArchitecture) source)
.getContainedElementsList().get(0);
if(source instanceof ComponentArchitecture) {
source = ((ComponentArchitecture)source).getContainedElementsList().get(0);
}
return source instanceof Component
&& ((Component) source).getContainedElementsLength() > 0;
return source instanceof Component && ((Component)source).getContainedElementsLength() > 0;
}
/** {@inheritDoc} */
@Override
public Object transform(Object source, ITransformationContext context)
throws TransformationFailedException {
if (source instanceof ComponentArchitecture) {
source = ((ComponentArchitecture) source)
.getContainedElementsList().get(0);
if(source instanceof ComponentArchitecture) {
source = ((ComponentArchitecture)source).getContainedElementsList().get(0);
}
Component sourceComponent = (Component) source;
List<CSourceComponent<? extends IModelElementSpecification>> subExecutables = new ArrayList<CSourceComponent<? extends IModelElementSpecification>>();
for (IHierarchicElement subComponent : sourceComponent
.getContainedElementsList()) {
CSourceComponent<? extends IModelElementSpecification> subExecutable = createExecutableForComponent(
(Component) subComponent, context);
if (subExecutable != null) {
Component sourceComponent = (Component)source;
List<CSourceComponent<? extends IModelElementSpecification>> subExecutables =
new ArrayList<CSourceComponent<? extends IModelElementSpecification>>();
for(IHierarchicElement subComponent : sourceComponent.getContainedElementsList()) {
CSourceComponent<? extends IModelElementSpecification> subExecutable =
createExecutableForComponent((Component)subComponent, context);
if(subExecutable != null) {
subExecutables.add(subExecutable);
} else {
throw new MissingComponentBehaviorTransformation(this,
subExecutables);
throw new MissingComponentBehaviorTransformation(this, subExecutables);
}
}
return new CSourceCompositeComponent(sourceComponent, subExecutables);
......
/*--------------------------------------------------------------------------+
$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.tooling.kernel.utils.TransformationUtils.createTransformedObjectFor;
import org.fortiss.af3.component.model.ComponentArchitecture;
import org.fortiss.af3.generator.common.model.c.CSourcePackage;
import org.fortiss.tooling.kernel.extension.ITransformationProvider;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
import org.fortiss.tooling.kernel.extension.exception.TransformationFailedException;
/**
* {@link ITransformationProvider} for the transformation from {@link ComponentArchitecture} to
* {@link CSourcePackage}.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class ComponentArchitectureTransformation implements ITransformationProvider {
/** {@inheritDoc} */
@Override
public Class<?> getTargetClass() {
return CSourcePackage.class;
}
/** {@inheritDoc} */
@Override
public boolean
canHandleChainTransformation(Class<?> sourceClass, ITransformationContext context) {
return ComponentArchitecture.class.isAssignableFrom(sourceClass);
}
/** {@inheritDoc} */
@Override
public boolean canTransform(Object source, ITransformationContext context) {
return source instanceof ComponentArchitecture;
}
/** {@inheritDoc} */
@Override
public Object transform(Object source, ITransformationContext context)
throws TransformationFailedException {
return createTransformedObjectFor(((ComponentArchitecture)source).getTopComponent(),
getTargetClass(), context);
}
}
/*--------------------------------------------------------------------------+
$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.generator.common.utils.CLanguageModelElementFactory.createCSourcePackage;
import static org.fortiss.af3.generator.common.utils.SourceUtils.mergeSourcePackageInto;
import static org.fortiss.tooling.kernel.utils.KernelModelElementUtils.getRootElement;
import static org.fortiss.tooling.kernel.utils.TransformationUtils.createTransformedObjectFor;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.expression.model.DataDictionary;
import org.fortiss.af3.generator.common.model.c.CSourcePackage;
import org.fortiss.tooling.kernel.extension.ITransformationProvider;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
import org.fortiss.tooling.kernel.extension.exception.TransformationFailedException;
/**
* {@link ITransformationProvider} for the transformation from {@link Component} to
* {@link CSourcePackage}.
*
* @author hoelzl
* @author $Author$
* @version $Rev$
* @ConQAT.Rating RED Hash:
*/
public class ComponentTransformation implements ITransformationProvider {
/** {@inheritDoc} */
@Override
public Class<?> getTargetClass() {
return CSourcePackage.class;
}
/** {@inheritDoc} */
@Override
public boolean
canHandleChainTransformation(Class<?> sourceClass, ITransformationContext context) {
return Component.class.isAssignableFrom(sourceClass);
}
/** {@inheritDoc} */
@Override
public boolean canTransform(Object source, ITransformationContext context) {
return source instanceof Component;
}
/** {@inheritDoc} */
@Override
public Object transform(Object source, ITransformationContext context)
throws TransformationFailedException {
Component sourceComponent = (Component)source;
CSourcePackage cPack = createCSourcePackage();
DataDictionary dict = getRootElement(sourceComponent, DataDictionary.class);
CSourcePackage dictSource = createTransformedObjectFor(dict, CSourcePackage.class, context);
mergeSourcePackageInto(dictSource, cPack);
return cPack;
}
}
......@@ -57,6 +57,7 @@ import org.fortiss.af3.project.model.typesystem.ITerm;
* <p>
* A flag variable is derived from a variable identifier by appending <code>"_NOVAL_FLAG"</code>.
*
* @deprecated
* @author hoelzl
* @author $Author$
* @version $Rev$
......
......@@ -364,6 +364,11 @@
<details key="body" value="return (DataDictionary) eContainer();"/>
</eAnnotations>
</eOperations>
<eOperations name="createIType" eType="ecore:EClass platform:/plugin/org.fortiss.af3.project/model/project.ecore#//typesystem/IType">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
<details key="body" value="return org.fortiss.af3.expression.utils.ExpressionModelElementFactory.definedType(getName());"/>
</eAnnotations>
</eOperations>
</eClassifiers>
<eClassifiers xsi:type="ecore:EClass" name="Enumeration" eSuperTypes="#//definitions/TypeDefinition">
<eAnnotations source="http://www.eclipse.org/emf/2002/GenModel">
......
......@@ -156,6 +156,7 @@
disposableProviderFactory="true" ecorePackage="expression.ecore#//definitions">
<genClasses image="false" ecoreClass="expression.ecore#//definitions/TypeDefinition">
<genOperations ecoreOperation="expression.ecore#//definitions/TypeDefinition/getDataDictionary"/>
<genOperations ecoreOperation="expression.ecore#//definitions/TypeDefinition/createIType"/>
</genClasses>
<genClasses ecoreClass="expression.ecore#//definitions/Enumeration">
<genFeatures property="None" children="true" createChild="true" ecoreFeature="ecore:EReference expression.ecore#//definitions/Enumeration/members"/>
......
......@@ -78,5 +78,18 @@
</objectClass>
</target>
</transformationProvider>
<transformationProvider
transformationProvider="org.fortiss.af3.expression.generator.c.ProgramTransformation">