global arrays for updating variables, bug fixes, varType in bip generator, fmi2SetXXX, fmi2GetXXX

parents
Pipeline #58 canceled with stages

Too many changes to show.

To preserve performance only 1000 of 1000+ files are displayed.

.metadata/
cli-lib/
cli-build/
This diff is collapsed.
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?project=acceleo.standalone.compiler&amp;ivyXmlPath=ivy.xml&amp;confs=*&amp;acceptedTypes=jar%2Cbundle%2Cejb%2Cmaven-plugin&amp;alphaOrder=false&amp;resolveInWorkspace=true&amp;retrievedClasspath=false&amp;sourceTypes=source&amp;javadocTypes=javadoc&amp;sourceSuffixes=-source%2C-sources%2C-src&amp;javadocSuffixes=-javadoc%2C-javadocs%2C-doc%2C-docs&amp;mapIfOnlyOneSource=false&amp;mapIfOnlyOneJavadoc=false&amp;resolveBeforeLaunch=false&amp;useExtendedResolveId=false"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>acceleo.standalone.compiler</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.apache.ivyde.eclipse.ivynature</nature>
</natures>
</projectDescription>
distribution.dir = ${basedir}/../../../distribution
\ No newline at end of file
<project name="acceleo.standalone.compiler" default="compile">
<property file="build.properties" />
<import file="${distribution.dir}/common.xml" />
</project>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info
organisation="ujf.verimag.bip"
module="acceleo.standalone.compiler">
</info>
<configurations>
<include file="../../../distribution/configurations.xml"/>
</configurations>
<dependencies>
<dependency name="ujf.verimag.bip.metamodel" rev="latest.integration"></dependency>
<dependency name="lpg.runtime.java" rev="2.0.17.v201004271640">
<artifact name="lpg.runtime.java" type="jar" url="file://${basedir}/externals/lpg.runtime.java_2.0.17.v201004271640.jar"/>
</dependency>
<dependency name="org.eclipse.acceleo.common" rev="3.6.6.201610060831">
<artifact name="org.eclipse.acceleo.common" type="jar" url="file://${basedir}/externals/org.eclipse.acceleo.common_3.6.6.201610060831.jar"/>
</dependency>
<dependency name="org.eclipse.acceleo.model" rev="3.6.6.201610060831">
<artifact name="org.eclipse.acceleo.model" type="jar" url="file://${basedir}/externals/org.eclipse.acceleo.model_3.6.6.201610060831.jar"/>
</dependency>
<dependency name="org.eclipse.acceleo.parser" rev="3.6.6.201610060831">
<artifact name="org.eclipse.acceleo.parser" type="jar" url="file://${basedir}/externals/org.eclipse.acceleo.parser_3.6.6.201610060831.jar"/>
</dependency>
<dependency name="org.eclipse.core.contenttype" rev="3.4.200.v20120523-2004">
<artifact name="org.eclipse.core.contenttype" type="jar" url="file://${basedir}/externals/org.eclipse.core.contenttype_3.4.200.v20120523-2004.jar"/>
</dependency>
<dependency name="org.eclipse.core.jobs" rev="3.5.200.v20120521-2346">
<artifact name="org.eclipse.core.jobs" type="jar" url="file://${basedir}/externals/org.eclipse.core.jobs_3.5.200.v20120521-2346.jar"/>
</dependency>
<dependency name="org.eclipse.core.runtime" rev="3.8.0.v20120521-2346">
<artifact name="org.eclipse.core.runtime" type="jar" url="file://${basedir}/externals/org.eclipse.core.runtime_3.8.0.v20120521-2346.jar"/>
</dependency>
<dependency name="org.eclipse.equinox.app" rev="1.3.100.v20120522-1841">
<artifact name="org.eclipse.equinox.app" type="jar" url="file://${basedir}/externals/org.eclipse.equinox.app_1.3.100.v20120522-1841.jar"/>
</dependency>
<dependency name="org.eclipse.equinox.common" rev="3.6.100.v20120522-1841">
<artifact name="org.eclipse.equinox.common" type="jar" url="file://${basedir}/externals/org.eclipse.equinox.common_3.6.100.v20120522-1841.jar"/>
</dependency>
<dependency name="org.eclipse.equinox.preferences" rev="3.5.0.v20120522-1841">
<artifact name="org.eclipse.equinox.preferences" type="jar" url="file://${basedir}/externals/org.eclipse.equinox.preferences_3.5.0.v20120522-1841.jar"/>
</dependency>
<dependency name="org.eclipse.ocl" rev="3.2.0.v20120611-1210">
<artifact name="org.eclipse.ocl" type="jar" url="file://${basedir}/externals/org.eclipse.ocl_3.2.0.v20120611-1210.jar"/>
</dependency>
<dependency name="org.eclipse.ocl.ecore" rev="3.2.0.v20120522-1637">
<artifact name="org.eclipse.ocl.ecore" type="jar" url="file://${basedir}/externals/org.eclipse.ocl.ecore_3.2.0.v20120522-1637.jar"/>
</dependency>
<dependency name="runtime" rev="registry_compatibility">
<artifact name="runtime" type="jar" url="file://${basedir}/externals/runtime_registry_compatibility.jar"/>
</dependency>
<dependency name="org.apache.ant" rev="1.8.0">
<artifact name="org.apache.ant" type="jar"
url="file://${basedir}/externals/ant-1.8.0.jar" />
</dependency>
</dependencies>
</ivy-module>
/**
* Copyright Verimag laboratory.
*
* contributors:
* Marc Pouhliès
*
* This software is a computer program whose purpose is to generate
* executable code from BIP models.
*
* This software is governed by the CeCILL-B license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-B
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-B license and that you accept its terms.
*/
package acceleo.standalone.compiler;
import java.security.CodeSource;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.resource.URIConverter;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.xmi.impl.EcoreResourceFactoryImpl;
import org.eclipse.acceleo.common.IAcceleoConstants;
import org.eclipse.acceleo.model.mtl.MtlPackage;
import org.eclipse.acceleo.model.mtl.resource.EMtlResourceFactoryImpl;
import org.eclipse.acceleo.parser.compiler.AcceleoCompiler;
import org.eclipse.emf.ecore.resource.Resource;
import org.apache.tools.ant.BuildException;
import bip2.Bip2Package;
/**
* This class is used to compile acceleo template without the need of
* running the full eclipse IDE. It is a custom Ant task, and thus needs
* to be executed from ant. It is a direct rip from Acceleo FAQ.
*
*/
public class AcceleoStandaloneCompiler extends AcceleoCompiler {
public void execute() throws BuildException {
registerResourceFactories();
registerPackages();
registerLibraries();
super.execute();
}
public void registerResourceFactories() {
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("ecore", new EcoreResourceFactoryImpl());
Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(IAcceleoConstants.EMTL_FILE_EXTENSION, new EMtlResourceFactoryImpl());
// Uncomment the following if you need to use UML models
// Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(UMLResource.FILE_EXTENSION, UMLResource.Factory.INSTANCE);
}
public void registerPackages() {
// Uncomment if you need to use UML models
EPackage.Registry.INSTANCE.put(Bip2Package.eNS_URI, Bip2Package.eINSTANCE);
// Uncomment if you need to use UML models saved with on old version of MDT/UML (you might need to change the URI's version number)
// EPackage.Registry.INSTANCE.put("http://www.eclipse.org/uml2/2.1.0/UML", UMLPackage.eINSTANCE);
}
public void registerLibraries() {
CodeSource acceleoModel = MtlPackage.class.getProtectionDomain().getCodeSource();
if (acceleoModel != null) {
String libraryLocation = acceleoModel.getLocation().toString();
if (libraryLocation.endsWith(".jar")) {
libraryLocation = "jar:" + libraryLocation + '!';
}
URIConverter.URI_MAP.put(URI.createURI("http://www.eclipse.org/acceleo/mtl/3.0/mtlstdlib.ecore"),
URI.createURI(libraryLocation + "/model/mtlstdlib.ecore"));
URIConverter.URI_MAP.put(URI.createURI("http://www.eclipse.org/acceleo/mtl/3.0/mtlnonstdlib.ecore"),
URI.createURI(libraryLocation + "/model/mtlnonstdlib.ecore"));
} else {
System.err.println("Coudln't retrieve location of plugin 'org.eclipse.acceleo.model'.");
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?project=ujf.verimag.bip.backend.aseba&amp;ivyXmlPath=ivy.xml&amp;confs=*&amp;acceptedTypes=jar%2Cbundle%2Cejb%2Cmaven-plugin&amp;alphaOrder=false&amp;resolveInWorkspace=true&amp;retrievedClasspath=false&amp;sourceTypes=source&amp;javadocTypes=javadoc&amp;sourceSuffixes=-source%2C-sources%2C-src&amp;javadocSuffixes=-javadoc%2C-javadocs%2C-doc%2C-docs&amp;mapIfOnlyOneSource=false&amp;mapIfOnlyOneJavadoc=false&amp;resolveBeforeLaunch=false&amp;useExtendedResolveId=false"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ujf.verimag.bip.backend.aseba</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.acceleo.ide.ui.acceleoBuilder</name>
<arguments>
<dictionary>
<key>compilation.kind</key>
<value>compilation.absolute.path</value>
</dictionary>
<dictionary>
<key>compliance</key>
<value>pragmatic</value>
</dictionary>
<dictionary>
<key>resource.kind</key>
<value>binary</value>
</dictionary>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.acceleo.ide.ui.acceleoNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.apache.ivyde.eclipse.ivynature</nature>
</natures>
</projectDescription>
#Wed Jul 13 11:45:17 CEST 2011
eclipse.preferences.version=1
formatter_profile=_custom
formatter_settings_version=12
<!-- ===================================================================== -->
<!-- Custom targets. -->
<!-- Set customBuildCallbacks = build.acceleo in your build.properties. -->
<!-- ===================================================================== -->
<project name="Build Acceleo Module" default="noDefault">
<!-- ================================================================= -->
<!-- Default target -->
<!-- ================================================================= -->
<target name="noDefault">
<echo message="This file must be called with explicit targets" />
</target>
<!-- ================================================================= -->
<!-- This will be called automatically after the compilation of each -->
<!-- Bundle... in dependency order. -->
<!-- ================================================================= -->
<target name="post.compile.@dot">
<acceleoCompiler
sourceFolder="${target.folder}"
outputFolder="${target.folder}"
dependencies="${target.folder}/../../ujf.verimag.bip.metamodel;${target.folder}/../../ujf.verimag.bip.error;${target.folder}/../../ujf.verimag.bip.backend;${target.folder}/../../ujf.verimag.bip;${target.folder}/../../acceleo.standalone.compiler;"
binaryResource="false">
</acceleoCompiler>
</target>
</project>
distribution.dir = ${basedir}/../../../distribution
\ No newline at end of file
<project name="ujf.verimag.bip.backend.aseba" default="compile">
<property file="build.properties" />
<target name="compile" depends="compile-java,compile-acceleo" />
<target name="compile-java" depends="resolve" description="--> compile the project">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="lib.path.id" debug="true" encoding="${compile.encoding}"/>
</target>
<target name="compile-acceleo" depends="resolve">
<taskdef name="acceleo" classname="acceleo.standalone.compiler.AcceleoStandaloneCompiler"
classpathref="lib.path.id"/>
<pathconvert pathsep=";" property="lib.path.strings" refid="lib.path.id"/>
<acceleo sourceFolder="${src.dir}"
outputFolder="${classes.dir}"
binaryResource="true"
dependencies="${lib.path.strings}"
packagesToRegister="" />
</target>
<import file="${distribution.dir}/common.xml" />
</project>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info
organisation="ujf.verimag.bip"
module="ujf.verimag.bip.backend.aseba">
</info>
<configurations>
<include file="../../../distribution/configurations.xml"/>
</configurations>
<dependencies>
<dependency name="ujf.verimag.bip.metamodel" rev="latest.integration"></dependency>
<dependency name="ujf.verimag.bip.backend" rev="latest.integration"></dependency>
</dependencies>
</ivy-module>
/**
* Copyright Verimag laboratory.
*
* contributors:
* Marc Pouhliès
*
* This software is a computer program whose purpose is to generate
* executable code from BIP models.
*
* This software is governed by the CeCILL-B license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-B
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-B license and that you accept its terms.
*/
package ujf.verimag.bip.backend.aseba;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.eclipse.emf.common.util.BasicMonitor;
import bip2.ujf.verimag.bip.instance.ComponentInstance;
import bip2.ujf.verimag.bip.packaging.BipPackage;
import ujf.verimag.bip.backend.BackendStatus;
import ujf.verimag.bip.backend.Backendable;
import ujf.verimag.bip.backend.BackendStatusEnum;
import ujf.verimag.bip.backend.aseba.templates.GenerateDeployed;
import ujf.verimag.bip.error.GenericError;
/**
* ASEBA backend for BIP compiler.
*
* This Backend makes strong asumptions on the input language (a subset of the
* BIP language). It also heavily relies on the Send/Receive BIP constructs.
*
* A set of annotations and naming conventions must be used in order for
* the backend to work:
* - variables with double '_' are mapped to dotted notation, '__' being replaced by a single dot.
* This is because aseba can use dotted notation but not BIP.
* - a variable with the 'system' aseba annotation denotes a variable that must
* not be declared in aseba as it's a builtin variable: '@aseba(system)'
* - a variable with the 'system' annotation and the 'map=FOO' will skip data
* declaration (system) and also rename reference to the variable to its corresponding
* value 'FOO' given in the annotation.
* - an exported port with the 'recv' annotation will be treated as a port by which
* something is received (data or simply an event).
* - an exported port with the 'send' annotation will be treated as a port by which
* something is sent (data or simply an event).
* - a component declaration must have a 'node="ASEBA NODE NAME"' annotation to guide the
* distribution of the generated code across available nodes.
* - a single component declaration may have the 'booter' annotation. It is used
* in case of delayed init, where all nodes are awaiting a 'start' event that the
* booter component will emit after a small delay (if --genaesl-start-delay is used).
*
* This backend is responsible for generating ASEBA code from a BIP model.
* It targets the Marxbot specifically by could be adapted to any platform
* supporting ASEBA.
*/
public class AsebaBackend implements Backendable {
@SuppressWarnings("unused")
private Logger logger = Logger.getLogger(this.getClass().getName());
/**
* Parameter for specifying where the files should be written
*/
private static final String GENAESL_OUTPUT_DIR = "genaesl-output-dir";
private String outputdir= null;
/**
* Parameter for specifying where the output file name
*/
private static final String GENAESL_OUTPUT_NAME = "genaesl-output-name";
private String outputname = null;
/**
* If used, then the generated code will include the glue necessary
* for a delayed start. The 'booter' annotation must be used on exactly
* one component declaration in the system (or nothing will happen).
*/
private static final String GENAESL_START_DELAY = "genaesl-start-delay";
private int delay = -1;
/**
* This variable is part of the interface convention between the compiler
* and the backend.
* DO NOT CHANGE ITS TYPE OR NAME
*/
public static String[][] backend_options_with_params={
{GENAESL_OUTPUT_DIR, "Output directory for Aseba scripts"},
{GENAESL_OUTPUT_NAME, "Output name for Aseba scripts"},
{GENAESL_START_DELAY, "Use a timer with the given delay to delay the start of the system."}
};
@Override
public boolean canGenerateFromPackage() {
return false;
}
@Override
public boolean canGenerateFromInstance() {
return true;
}
@Override
public BackendStatus generateFromPackage(BipPackage pack) {
return new BackendStatus(BackendStatusEnum.FAIL);
}
@Override
public BackendStatus generateFromInstance(ComponentInstance instance) {
GenerateDeployed generator;
List<String> tmpl_args = new ArrayList<String>();
File outputdirF = new File(this.outputdir);
tmpl_args.add(this.outputname);
tmpl_args.add("" + this.delay);
try {
generator = new GenerateDeployed(instance, outputdirF,
tmpl_args);
generator.doGenerate(new BasicMonitor());
} catch (IOException e) {
e.printStackTrace();
return new BackendStatus(BackendStatusEnum.FAIL);
}
return new BackendStatus(BackendStatusEnum.SUCCESS);
}
@Override
public boolean isEnabled() {
// enabled if the outputfile has been set.
return (this.outputdir != null);
}
@Override
public GenericError[] configure(OptionSet options,
Map<String, OptionSpec<String>> ospecs) {
if (options.has(ospecs.get(GENAESL_OUTPUT_DIR))){
this.outputdir= options.valueOf(ospecs.get(GENAESL_OUTPUT_DIR));
}
if (options.has(ospecs.get(GENAESL_OUTPUT_NAME))){
this.outputname = options.valueOf(ospecs.get(GENAESL_OUTPUT_NAME));
}
if (options.has(ospecs.get(GENAESL_START_DELAY))){
this.delay = Integer.parseInt(options.valueOf(ospecs.get(GENAESL_START_DELAY)));
}
return new GenericError[0];
}
}
[comment encoding = UTF-8 /]
[module connector('http://bip2/1.0')/]
[import ujf::verimag::bip::backend::acceleo::templates::expressions /]
[query public relatedConnectors(anAtomInstance: AtomInstance, aSetOfConnectors: OrderedSet(ConnectorInstance)) : Set(ConnectorInstance) =
aSetOfConnectors->select(e:ConnectorInstance | e.getConnectedAtomInstance()->includes(anAtomInstance))
/]
[query public eventSize(aConnectorInstance : ConnectorInstance) : Integer =
aConnectorInstance.portParamInstances->first().declaration.portType.dataParameterDeclarations->size()
/]
[query public getConnectedAtomInstance(aConnectorInstance : ConnectorInstance) : Set(AtomInstance) =
aConnectorInstance.portParamInstances->collect(e:PortInstance| e.oclAsType(ExportedPortInstance).eContainer().oclAsType(AtomInstance))->asSet()
/]
[query public getConnectedEPort(aConnectorInstance : ConnectorInstance, anAtomInstance : AtomInstance) : ExportedPortInstance =
aConnectorInstance.portParamInstances->select(p:PortInstance |
p.eContainer() = anAtomInstance)->first()
/]
[query public getUnderlyingIPort(aConnectorInstance : ConnectorInstance, anAtomInstance : AtomInstance) : AtomInternalPortInstance =
getConnectedEPort(aConnectorInstance, anAtomInstance).referencedPorts->first().oclAsType(AtomInternalPortInstance)
/]
[query public getConnectorFromEPort(aCompoundInstance: CompoundInstance, anEPortInstance: ExportedPortInstance) : ConnectorInstance =
aCompoundInstance.subConnectorInstances->select(ci : ConnectorInstance |
ci.portParamInstances->includes(anEPortInstance))->first()
/]
[template public eventNameFromConnector(aConnectorInstance : ConnectorInstance) post(trim())]
[aConnectorInstance.declaration.name /]Evt
[/template]
[template public dataNameFromConnector(aConnectorInstance : ConnectorInstance) post(trim())]
[aConnectorInstance.declaration.name /]Evt_data
[/template]
[comment encoding = UTF-8 /]
[module expressions('http://bip2/1.0') extends ujf::verimag::bip::backend::acceleo::templates::expressions/]
[import ujf::verimag::bip::backend::acceleo::templates::annotations /]
[comment
Overrides default one because aseba needs the 'call' keyword before the function name.
/]
[template public generateExpression(anExpression : FunctionCallExpression) post(trim())]
call [anExpression.functionName /]([for (ve : ValuedExpression | anExpression.parameters) separator(', ')][ve.generateExpression() /][/for])
[/template]
[template public downExpression(anExpression : AssignmentExpression) ? (anExpression.lhsIndirect <> null)]
[anExpression.lhsIndirect.generateExpression() /] = [anExpression.rhs.generateExpression() /]
[/template]
[query public getAsebaOp(anOperator : String) : String =
if anOperator = '&&' then 'and'
else if anOperator = '||' then 'or'
else anOperator
endif endif
/]
[template public generateExpression(anExpression : BinaryOpExpression) post(trim())]
([anExpression.left.generateExpression() /]) [' ' + anExpression.operator.toString().getAsebaOp() + ' '/] ([anExpression.right.generateExpression() /])
[/template]
[comment
for <portdecl>.<datadecl>
/]
[template public generateExpression(anExpression : SubDataDeclarationReferenceExpression) ? (anExpression.subDataDeclarationRef.portDeclaration <> null)]
[anExpression.subDataDeclarationRef.forwardDataDeclaration.name /]
[/template]
[query public buildSubstitutionMap(anAtomType : AtomType) : Sequence(Sequence(String)) =
anAtomType.internalDataDeclarations->select(
hasAnnotation('aseba', 'system') and hasAnnotation('aseba', 'map'))->collectNested(
Sequence{name, getAnnotation('aseba', 'map').substituteAll('"', '')})
/]
[query public unmangleDottedVarName(aMangledName : String) : String =
aMangledName.replaceAll('__', '.')
/]
[query public substituteVars(theStatements : String, theSubstitutions : Sequence(Sequence(String))) : String =
theStatements.unmangleDottedVarName().onlySubstituteVars(theSubstitutions)
/]
[query public onlySubstituteVars(theStatements : String, theSubstitutions : Sequence(Sequence(String))) : String =
if theSubstitutions->size() = 0 then
theStatements
else if theSubstitutions->size() = 1 then
theStatements.substituteVar(theSubstitutions->first())
else
theStatements.substituteVar(theSubstitutions->first()).substituteVars(theSubstitutions->subSequence(2,theSubstitutions->size()))
endif
endif
/]
[query public substituteVar(theStatements : String, theSubstitution : Sequence(String)) : String =
theStatements.replaceAll('\\b' + theSubstitution->at(1) + '\\b', theSubstitution->at(2))
/]
[comment encoding = UTF-8 /]
[module generateDeployed('http://bip2/1.0')/]
[import ujf::verimag::bip::backend::aseba::templates::atom /]
[import ujf::verimag::bip::backend::aseba::templates::connector /]
[import ujf::verimag::bip::backend::acceleo::templates::annotations /]
[query public toXMLentity(aString : String) : String =
aString.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;')
/]
[template public generateDeployed(aCompoundInstance : CompoundInstance, fileName : String, delay : String)]
[comment @main /]
[file (fileName, false, 'UTF-8')]
<!DOCTYPE aesl-source>
<network>
<!--list of global events-->
[for (connI : ConnectorInstance | aCompoundInstance.subConnectorInstances)]
<event size="[connI.eventSize()/]" name="[connI.eventNameFromConnector() /]" />
[/for]
[if (not delay.equalsIgnoreCase('-1'))]
<event size="0" name="start" />
[/if]
<!--list of constants-->
<!-- Empty, for the moment -->
[for (anAtomInstance : AtomInstance | aCompoundInstance.atomInstancesFromAnnot('aseba', 'node'))]
<!--source code of node [anAtomInstance.declaration.getAnnotation('aseba', 'node') /] -->
<node name=[anAtomInstance.declaration.getAnnotation('aseba', 'node') /]>
[anAtomInstance.generateBehavior(anAtomInstance.relatedConnectors(aCompoundInstance.subConnectorInstances), delay).toXMLentity() /]
</node>
[/for]
</network>
[/file]
[/template]
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.apache.ivyde.eclipse.cpcontainer.IVYDE_CONTAINER/?project=ujf.verimag.bip.backend.bip&amp;ivyXmlPath=ivy.xml&amp;confs=*&amp;acceptedTypes=jar%2Cbundle%2Cejb%2Cmaven-plugin&amp;alphaOrder=false&amp;resolveInWorkspace=true&amp;retrievedClasspath=false&amp;sourceTypes=source&amp;javadocTypes=javadoc&amp;sourceSuffixes=-source%2C-sources%2C-src&amp;javadocSuffixes=-javadoc%2C-javadocs%2C-doc%2C-docs&amp;mapIfOnlyOneSource=false&amp;mapIfOnlyOneJavadoc=false&amp;resolveBeforeLaunch=false&amp;useExtendedResolveId=false"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>ujf.verimag.bip.backend.bip</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.acceleo.ide.ui.acceleoBuilder</name>
<arguments>
<dictionary>
<key>compilation.kind</key>
<value>compilation.absolute.path</value>
</dictionary>
<dictionary>
<key>compliance</key>
<value>pragmatic</value>
</dictionary>
<dictionary>
<key>resource.kind</key>
<value>binary</value>
</dictionary>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.acceleo.ide.ui.acceleoNature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.apache.ivyde.eclipse.ivynature</nature>
</natures>
</projectDescription>
#Wed Jul 13 11:45:04 CEST 2011
eclipse.preferences.version=1
formatter_profile=_custom
formatter_settings_version=12
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Acceleo Bip Module Runtime Plug-in
Bundle-SymbolicName: ujf.verimag.bip.backend.bip
Bundle-Version: 1.0.0.qualifier
Bundle-Vendor: Eclipse Modeling Project
Require-Bundle: org.eclipse.core.runtime,
org.eclipse.emf.ecore,
org.eclipse.emf.ecore.xmi,
org.eclipse.ocl,
org.eclipse.ocl.ecore,
org.eclipse.acceleo.model,
org.eclipse.acceleo.engine
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ActivationPolicy: lazy
Eclipse-LazyStart: true
Export-Package: ujf.verimag.bip.backend.bip.templates
<!-- ===================================================================== -->
<!-- Custom targets. -->
<!-- Set customBuildCallbacks = build.acceleo in your build.properties. -->
<!-- ===================================================================== -->
<project name="Build Acceleo Module" default="noDefault">
<!-- ================================================================= -->
<!-- Default target -->
<!-- ================================================================= -->
<target name="noDefault">
<echo message="This file must be called with explicit targets" />
</target>
<!-- ================================================================= -->
<!-- This will be called automatically after the compilation of each -->
<!-- Bundle... in dependency order. -->
<!-- ================================================================= -->
<target name="post.compile.@dot">
<acceleoCompiler
sourceFolder="${target.folder}"
outputFolder="${target.folder}"
dependencies="${target.folder}/../../ujf.verimag.bip.metamodel;${target.folder}/../../ujf.verimag.bip.error;${target.folder}/../../ujf.verimag.bip.backend;${target.folder}/../../ujf.verimag.bip;${target.folder}/../../acceleo.standalone.compiler;"
binaryResource="false">
</acceleoCompiler>
</target>
</project>
source.. = src/
output.. = build/classes
bin.includes = META-INF/,\
.
customBuildCallbacks = build.acceleo
custom.dir = backends
src.dir = ${basedir}/src
distribution.dir = ${basedir}/../../../distribution
jre.compilation.profile = JavaSE-1.6
<project name="ujf.verimag.bip.backend.bip" default="compile">
<property file="build.properties" />
<target name="compile" depends="compile-java,compile-acceleo" />
<target name="compile-java" depends="resolve" description="--> compile the project">
<mkdir dir="${classes.dir}" />
<javac srcdir="${src.dir}" destdir="${classes.dir}" classpathref="lib.path.id" debug="${compile.debug}" target="${compile.target}" source="${compile.source}" encoding="${compile.encoding}"/>
</target>
<target name="compile-acceleo" depends="resolve">
<taskdef name="acceleo" classname="acceleo.standalone.compiler.AcceleoStandaloneCompiler"
classpathref="lib.path.id"/>
<pathconvert pathsep=";" property="lib.path.strings" refid="lib.path.id"/>
<acceleo sourceFolder="${src.dir}"
outputFolder="${classes.dir}"
binaryResource="true"
dependencies="${lib.path.strings}"
packagesToRegister="" />
</target>
<import file="${distribution.dir}/common.xml" />
</project>
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you 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.
-->
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info
organisation="ujf.verimag.bip"
module="ujf.verimag.bip.backend.bip">
</info>
<configurations>
<include file="../../../distribution/configurations.xml"/>
</configurations>
<dependencies>
<dependency name="ujf.verimag.bip.metamodel" rev="latest.integration"></dependency>
<dependency name="ujf.verimag.bip.backend" rev="latest.integration"></dependency>
</dependencies>
</ivy-module>
[comment encoding = UTF-8 /]
[module annotations('http://bip2/1.0')/]
[comment
See ticket #153 in BTS
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
This file is NOT used by the backends. There is a problem with acceleo
dependencies that prevent correct handling of module within jars.
Until a fix is released, this file must be copied in the concrete Backend.
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
/]
[comment
Returns the the BipAnnotation attached to the node for the name 'annotName' if any.
/]
[query public getAnnotation(anAnnotatedElement : AnnotatedElement, annotName : String) : BipAnnotation =
anAnnotatedElement.bipAnnotations->select(e: StringToAnnotationMapEntry| e.key.equalsIgnoreCase(annotName))->first().value
/]
[comment
Returns the parameter value (as String) for the given node/annotation name/parameter name.
/]
[query public getAnnotation(anAnnotatedElement : AnnotatedElement, annotName : String, keyName : String) : String =
anAnnotatedElement.getAnnotation(annotName).parameters->select(e: StringToStringMapEntry|
e.key.equalsIgnoreCase(keyName))->collect(e : StringToStringMapEntry|
e.value)->first()
/]
[comment
Tests if the given parameter for a given node/annotation name exists
/]
[query public hasAnnotation(anAnnotatedElement : AnnotatedElement, annotName : String, keyName : String) : Boolean =
anAnnotatedElement.hasAnnotation(annotName) and
anAnnotatedElement.getAnnotation(annotName).parameters->select(e: StringToStringMapEntry| e.key.equalsIgnoreCase(keyName))->notEmpty()
/]
[comment
Tests is the annotation name exists for the given node
/]
[query public hasAnnotation(anAnnotatedElement : AnnotatedElement, annotName : String) : Boolean =
anAnnotatedElement.bipAnnotations->select(e: StringToAnnotationMapEntry| e.key.equalsIgnoreCase(annotName))->notEmpty()
/]
[comment
Collect all Atom instances within a Compound for which the declaration has the given annotation name
/]
[query public atomInstancesFromAnnot(aCompoundInstance : CompoundInstance, annotName : String) : Set(AtomInstance) =
aCompoundInstance.subAtomInstances->select(e:AtomInstance| e.declaration.hasAnnotation(annotName))
/]
[comment
Collect all Atom instances within a Compound for which the declaration has the given annotation name + parameter name.
/]
[query public atomInstancesFromAnnot(aCompoundInstance : CompoundInstance, annotName : String, keyName : String) : Set(AtomInstance) =
aCompoundInstance.subAtomInstances->select(e:AtomInstance| e.declaration.hasAnnotation(annotName, keyName))
/]
[query public getSystemProperty(aPropertyName : String) : String =
invoke('java.lang.System', 'getProperty(java.lang.String,java.lang.String)', Sequence{aPropertyName, ''})
/]
[query public getSystemProperty(aPropertyName : String, aDefault : String) : String =
invoke('java.lang.System', 'getProperty(java.lang.String,java.lang.String)', Sequence{aPropertyName, aDefault})
/]
[comment encoding = UTF-8 /]
[module expressions('http://bip2/1.0')/]
[comment
See ticket #153 in BTS
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
This file is NOT used by the backends. There is a problem with acceleo
dependencies that prevent correct handling of module within jars.
Until a fix is released, this file must be copied in the concrete Backend.
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
/]
[comment
The following set of template simply generates back the input expression without
any modification.
/]
[template public generateExpression(anExpression : AssignmentExpression)
? (anExpression.lhs.oclIsKindOf(DirectDataDeclarationReferenceExpression) or
anExpression.lhs.oclIsKindOf(SubDataDeclarationReferenceExpression))]
[anExpression.lhs.generateExpression() /] = [anExpression.rhs.generateExpression() /]
[/template]
[template public generateExpression(anExpression : DirectDataDeclarationReferenceExpression)]
[anExpression.dataDeclaration.name /]
[/template]
[template public generateExpression(anExpression : BinaryOpExpression) post(trim())]
([anExpression.left.generateExpression() /] [' ' + anExpression.operator + ' '/] [anExpression.right.generateExpression() /])
[/template]
[template public generateExpression(anExpression : FunctionCallExpression) post(trim())]
[anExpression.functionName /]([for (ve : ValuedExpression | anExpression.parameters) separator(', ')][ve.generateExpression() /][/for])
[/template]
[template public generateExpression(anExpression : UnaryOpExpression) post(trim())]
[anExpression.operator /] [anExpression.operand.generateExpression() /]
[/template]
[template public generateExpression(anExpression : IfThenElseExpression) post(trim())]
if ([anExpression.condition.generateExpression()/]) then
[for (e : Expression | anExpression._then) ]
[e.generateExpression()/][if (not e.oclIsTypeOf(IfThenElseExpression))];[/if]
[/for]
[if (anExpression._else->notEmpty())]
else
[for (e : Expression | anExpression._else) ]
[e.generateExpression()/][if (not e.oclIsTypeOf(IfThenElseExpression))];[/if]
[/for]
[/if]
fi
[/template]
[comment
for <compdecl>.<datadecl>
/]
[template public generateExpression(anExpression : SubDataDeclarationReferenceExpression) ? (anExpression.subDataDeclarationRef.componentDeclaration <> null)]
[anExpression.subDataDeclarationRef.componentDeclaration.name /].[anExpression.subDataDeclarationRef.forwardDataDeclaration.name /]
[/template]
[comment
for <portdecl>.<datadecl>
/]
[template public generateExpression(anExpression : SubDataDeclarationReferenceExpression) ? (anExpression.subDataDeclarationRef.portDeclaration <> null)]
[anExpression.subDataDeclarationRef.portDeclaration.name /].[anExpression.subDataDeclarationRef.forwardDataDeclaration.name /]
[/template]
[template public generateExpression(anExpression : DirectBooleanExpression) post(trim())]
[if (anExpression.value)]true[else]false[/if]
[/template]
[template public generateExpression(anExpression : DirectIntegerExpression) post(trim())]
[anExpression.value.toString()/]
[/template]
[template public generateExpression(anExpression : DirectFloatExpression) post(trim())]
[anExpression.value.toString()/]
[/template]
[template public generateExpression(anExpression : DirectStringExpression) post(trim())]
[anExpression.value/]
[/template]
[comment THIS IS ANOTHER DEFAULT THAT SHOULD NEVER BE USED /]
[template public generateExpression(anExpression : ValuedExpression)]
INCOMPLETE, MISSING TEMPLATE FOR A SUBTYPE OF 'ValuedExpression'
[/template]
[comment THIS IS THE DEFAULT TEMPLATE THAT SHOULD NEVER BE USED. /]
[template public generateExpression(anExpression : Expression)]
INCOMPLETE, MISSING TEMPLATE FOR A SUBTYPE OF 'Expression'
[/template]
/**
* Copyright Verimag laboratory.
*
* contributors:
* Marc Pouhliès
* Jacques Combaz (jacques.combaz@univ-grenoble-alpes.fr)
*
* This software is a computer program whose purpose is to generate
* executable code from BIP models.
*
* This software is governed by the CeCILL-B license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-B
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-B license and that you accept its terms.
*/
package ujf.verimag.bip.backend.bip;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import org.eclipse.emf.common.util.BasicMonitor;
import org.eclipse.emf.ecore.EPackage;
import bip2.Bip2Package;
import bip2.ujf.verimag.bip.instance.ComponentInstance;
import bip2.ujf.verimag.bip.packaging.BipPackage;
import ujf.verimag.bip.backend.BackendStatus;
import ujf.verimag.bip.backend.Backendable;
import ujf.verimag.bip.backend.BackendStatusEnum;
import ujf.verimag.bip.backend.bip.templates.GeneratePackage;
import ujf.verimag.bip.error.GenericError;
/**
* BIP backend for BIP compiler.
*
* This backend is responsible for generating BIP code from a BIP model.
*/
public class BipBackend implements Backendable {
private Logger logger = Logger.getLogger(this.getClass().getName());
/**
* Parameter for specifying where the files should be written
*/
private static final String GENBIP_OUTPUT_DIR = "genbip-output-dir";
private String outputdir= null;
/**
* In case of used packages, should the backend also create code for them or assume
* everything is already done.
*/
private static final String GENBIP_FOLLOW_USED_PACKAGES = "genbip-follow-used-packages";
private boolean follow_used_package = false;
/**
* This variable is part of the interface convention between the compiler
* and the backend.
* DO NOT CHANGE ITS TYPE OR NAME
*/
public static String[][] backend_options_with_params={
{GENBIP_OUTPUT_DIR, "Output directory for BIP backend"},
};
/**
* This variable is part of the interface convention between the compiler
* and the backend.
* DO NOT CHANGE ITS TYPE OR NAME
*/
public static String[][] backend_options_with_no_params={
{GENBIP_FOLLOW_USED_PACKAGES, "Also generate code for used packages."},
};
@Override
public boolean canGenerateFromPackage() {
return true;
}
@Override
public boolean canGenerateFromInstance() {
// BIP language only describes types, nothing to do with instances.
return false;
}
@Override
public BackendStatus generateFromPackage(BipPackage pack) {
EPackage.Registry.INSTANCE.put(Bip2Package.eNS_URI,
Bip2Package.eINSTANCE);
// FIXME:
// /!\ introduced for running the compiler from Eclipse
// but in principle it should not be necessary
EPackage.Registry.INSTANCE.put("platform:/resource/ujf.verimag.bip.metamodel/model/bip2.ecore",
Bip2Package.eINSTANCE);
Stack<BipPackage> to_generate = new Stack<BipPackage>();
Set<BipPackage> already_generated = new HashSet<BipPackage>();
File outputdirF = new File(this.outputdir);
if (!outputdirF.exists() || !outputdirF.isDirectory()){
logger.log(Level.SEVERE, "Output directory does not exist (or not a directory) : " + outputdir);
return new BackendStatus(BackendStatusEnum.FAIL);
}
to_generate.add(pack);
try {
GeneratePackage generator;
logger.log(Level.FINEST, "Executing acceleo generator...");
while (!to_generate.isEmpty()){
BipPackage bp = to_generate.pop();
if (already_generated.contains(bp))
continue;
File this_pack_output_dir;
// check output path (create it if needed).
String pname = bp.getName();
int didx = pname.lastIndexOf('.'); // is it a nested package ?
if (didx != -1){
String ppath = pname.substring(0, didx).replace('.', File.separatorChar);
pname = pname.substring(didx + 1);
String fpath = this.outputdir + File.separatorChar + ppath;
this_pack_output_dir = new File(fpath);
if (!(this_pack_output_dir.exists() && this_pack_output_dir.isDirectory()) && !this_pack_output_dir.mkdirs()){
logger.log(Level.SEVERE, "Error with nested package directory (already exists with bad perms or error when creating it) : " + fpath);
return new BackendStatus(BackendStatusEnum.FAIL);
}
} else {
this_pack_output_dir = outputdirF;
}
List<String> tmpl_args = new ArrayList<String>();
tmpl_args.add(pname + ".bip");
generator = new GeneratePackage(bp, this_pack_output_dir,
tmpl_args);
generator.doGenerate(new BasicMonitor());
already_generated.add(bp);
if (this.follow_used_package){
to_generate.addAll(bp.getUsed_packages());
}
}
logger.log(Level.FINEST, "Executed acceleo generator.");
} catch (IOException e) {
e.printStackTrace();
return new BackendStatus(BackendStatusEnum.FAIL);
}
return new BackendStatus(BackendStatusEnum.SUCCESS);
}
@Override
public BackendStatus generateFromInstance(ComponentInstance instance) {
return new BackendStatus(BackendStatusEnum.FAIL);
}
@Override
public boolean isEnabled() {
// enabled if the outputfile has been set.
return (this.outputdir != null);
}
@Override
public GenericError[] configure(OptionSet options,
Map<String, OptionSpec<String>> ospecs) {
if (options.has(ospecs.get(GENBIP_OUTPUT_DIR))){
this.outputdir= options.valueOf(ospecs.get(GENBIP_OUTPUT_DIR));
}
if (options.has(GENBIP_FOLLOW_USED_PACKAGES)){
this.follow_used_package = true;
}
return new GenericError[0];
}
}
[comment encoding = UTF-8 /]
[module annotations('http://bip2/1.0')/]
[template public genAnnotations(anAnnotatedElt : AnnotatedElement) post(trim())]
[for (an : StringToAnnotationMapEntry | anAnnotatedElt.bipAnnotations)]
@[an.key/][for (it : StringToStringMapEntry | an.value.parameters) before('(') separator(', ') after(')')][it.key/]=[it.value/][/for]
[/for]
[/template]
\ No newline at end of file
[comment encoding = UTF-8 /]
[module commonBip('http://bip2/1.0')/]
[query public qualifiedName(fromPackage : BipPackage, usedType : BipType) : String =
if fromPackage = usedType.eContainer(BipPackage) then
usedType.name
else
usedType.eContainer(BipPackage).name + '.' + usedType.name
endif
/]
[query public qualifiedName(fromPackage : BipPackage, usedType : DataType) : String =
if fromPackage = usedType.eContainer(BipPackage) then
usedType.name
else
usedType.eContainer(BipPackage).name + '.' + usedType.name
endif
/]
[query public qualifiedName(fromType : BipType, usedType : BipType) : String =
qualifiedName(fromType.eContainer(BipPackage), usedType)
/]
[query public qualifiedName(fromType : BipType, usedType : DataType) : String =
qualifiedName(fromType.eContainer(BipPackage), usedType)
/]
[comment encoding = UTF-8 /]
[module connectorInteractionDefinition('http://bip2/1.0')]
[template public generateInteractionDefinition(intr : ConnectorInteractionPortReference)]
[intr.port.name/][if (intr.quoted)]'[/if]
[/template]
[template public generateInteractionDefinition(intr : ConnectorInteractionNestedDefinition)]
([for (ch : ConnectorInteractionDefinition | intr.subInteractions) separator(' ')]
[ch.generateInteractionDefinition()/]
[/for]
)[if (intr.quoted)]'[/if]
[/template]
[template public generateInteractionDefinition(intr : ConnectorInteractionDefinition)]
THIS TEMPLATE SHOULD NOT BE INVOKED. bip/connectorInteractionDefinition.mtl
[/template]
[comment encoding = UTF-8 /]
[module generateAtomType('http://bip2/1.0')/]
[import ujf::verimag::bip::backend::bip::templates::generatePortDeclaration /]
[import ujf::verimag::bip::backend::acceleo::templates::expressions /]
[import ujf::verimag::bip::backend::bip::templates::annotations /]
[import ujf::verimag::bip::backend::bip::templates::commonBip /]
[query private internalNotExported(iport : AtomInternalPortDeclaration, aAtomType: AtomType) : Boolean =
aAtomType.exportedPortDeclarations->select(e|e.oclAsType(AtomExportPortDeclaration).portDeclarationReferences->select(refs|refs.name = iport.name)->notEmpty())->isEmpty() /]
[template private generateAtomPriorityDeclaration(priod : AtomPriorityDeclaration)]
priority [priod.name/] [if (priod.low <> null)] [priod.low.name /][else] * [/if] < [if (priod.high <> null)] [priod.high.name /][else] * [/if]
[if (priod.guard->notEmpty())]
provided ([priod.guard.generateExpression() /])
[/if]
[/template]
[template private generateAtomInvariant(invariant : AtomInvariant)]
invariant [invariant.name/][if (invariant.exactState)] at[elseif (invariant.sources->notEmpty())] from[/if][for (state : State | invariant.sources) before(' ') separator(', ')][state.name/][/for][if (invariant.guard->notEmpty())] provided ([invariant.guard.generateExpression()/])[/if]
[/template]
[template public generateAtomType(aAtomType : AtomType) post(trim())]
atom type [aAtomType.name/] ([for (dd : DataDeclaration | aAtomType.dataParameterDeclarations) separator(', ')][if (dd.const)]const [/if][qualifiedName(aAtomType, dd.dataType) /] [dd.name /][/for])
[for (data : AtomInternalDataDeclaration | aAtomType.internalDataDeclarations)]
[data.genAnnotations()/]
[if (data.exported)]export [/if]data [if (data.const)]const [/if][qualifiedName(aAtomType, data.dataType)/] [data.name /][if (not data.value->isEmpty())] = [data.value.generateExpression()/][/if]
[/for]
[for (eport : AtomExportPortDeclaration | aAtomType.exportPortDeclarations)]
[if (eport.portDeclarationReferences->size() = 1)]
[eport.portDeclarationReferences->at(1).genAnnotations()/]
export port [eport.portDeclarationReferences->at(1).generatePortDeclaration(aAtomType) /]
[else]
export port [qualifiedName(aAtomType, eport.portDeclarationReferences->first().portType)/] [for (pd : AtomInternalPortDeclaration | eport.portDeclarationReferences) separator(', ')][pd.generatePortDeclaration(true, aAtomType)/][/for] as [eport.name /]
[/if]
[/for]
[for (iport : AtomInternalPortDeclaration | aAtomType.internalPortDeclarations)]
[if (internalNotExported(iport, aAtomType))]
[iport.genAnnotations()/]
port [iport.generatePortDeclaration(aAtomType) /]
[/if]
[/for]
[for (eport : AtomExternalPortDeclaration | aAtomType.externalPortDeclarations)]
extern port [eport.generatePortDeclaration(aAtomType)/][if (eport.backendName->notEmpty())] as "[eport.backendName/]"[/if] [generatePolicy(eport.policy)/]
[/for]
[comment][for (port : AtomInternalPortDeclaration | aAtomType.internalPortDeclarations)]
[if (port.exported)]export [/if]port [port.generatePortDeclaration() /]
[/for][/comment]
[aAtomType.behavior.generatePetriNet() /]
[for (priod : AtomPriorityDeclaration | aAtomType.priorities)]
[generateAtomPriorityDeclaration(priod) /]
[/for]
[for (invar : AtomInvariant | aAtomType.invariants)]
[generateAtomInvariant(invar) /]
[/for]
end
[/template]
[template private generatePolicy(p : EventConsumptionPolicy) post(trim())]
[if (p = EventConsumptionPolicy::remember)]remember[elseif (p = EventConsumptionPolicy::ignore)]ignore[elseif (p = EventConsumptionPolicy::error)]error[else]#ERROR: unsupported event consumption policy![/if]
[/template]
[template private generatePetriNet(pn : PetriNet) post(trim())]
place [for (s : State | pn.states) separator(', ')][s.name /][/for]
initial to [for (s : State | pn.initStates) separator(', ')][s.name /][/for]
[for (initaction : Expression | pn.initialActions) before (' do {\n') after(' }\n')]
[initaction.generateExpression() /][if (not initaction.oclIsTypeOf(IfThenElseExpression))];[/if]
[/for]
[for (t : Transition | pn.transitions)]
[t.generateTransition() /]
[/for]
[/template]
[template private generateTransition(t : Transition)]
[if (not t.triggerPort.oclIsUndefined())]
on [t.triggerPort.name/]
[else]
internal
[/if]
from [for (s : State | t.sources) separator(', ')][s.name/][/for]
to [for (s : State | t.destinations) separator(', ')][s.name/][/for]
[if (t.guard->notEmpty())]
provided ([t.guard.generateExpression() /])
[/if]
[for (e : Expression | t.actions) before (' do {\n') after(' }\n') ]
[e.generateExpression() /][if (not e.oclIsTypeOf(IfThenElseExpression))];[/if]
[/for]
[/template]
\ No newline at end of file
[comment encoding = UTF-8 /]
[module generateCompoundType('http://bip2/1.0')/]
[import ujf::verimag::bip::backend::acceleo::templates::expressions /]
[import ujf::verimag::bip::backend::bip::templates::commonBip /]
[template public generateCompoundType(aCompoundType : CompoundType) post(trim())]
compound type [aCompoundType.name/] ([for (dd : DataDeclaration | aCompoundType.dataParameterDeclarations) separator(', ')][if (dd.const)]const [/if][qualifiedName(aCompoundType, dd.dataType) /] [dd.name /][/for])
[for (cd : ComponentDeclaration | aCompoundType.componentDeclarations) after('\n')]
[cd.generateComponentDeclaration(aCompoundType) /]
[/for]
[for (cod : ConnectorDeclaration | aCompoundType.connectorDeclarations) after('\n')]
[cod.generateConnectorDeclaration(aCompoundType) /]
[/for]
[for (priod : CompoundPriorityDeclaration | aCompoundType.priorities) separator('\n')]
[priod.generatePriorityDeclaration() /]
[/for]
[for (epd : CompoundExportPortDeclaration | aCompoundType.exportPortDeclarations) after('\n')]
export port [for (spdr : SubPortDeclarationReference | epd.portDeclarationReferences) separator(', ')][spdr.generateSubPortDeclRef()/][/for] as [epd.name /]
[/for]
[for (edd : CompoundExportDataDeclaration | aCompoundType.exportDataDeclarations) after('\n')]
export data [edd.dataDeclarationReference.generateSubDataDeclRef() /] as [edd.name /]
[/for]
end
[/template]
[template private generateComponentDeclaration(aComponentDeclaration : ComponentDeclaration, aCompoundType : CompoundType) post(trim())]
component [qualifiedName(aCompoundType, aComponentDeclaration.type) /] [aComponentDeclaration.name /] ([for (param : ValuedExpression | aComponentDeclaration.parameters) separator(', ')][param.generateExpression()/][/for])
[/template]
[template private generateSubDataDeclRef(aDataDecl : SubDataDeclarationReference)]
[if (aDataDecl.componentDeclaration <> null)]
[aDataDecl.componentDeclaration.name /][else]
[aDataDecl.portDeclaration.name /][/if].[aDataDecl.forwardDataDeclaration.name /]
[/template]
[template private generateSubPortDeclRef(aPortDecl : SubPortDeclarationReference)]
[if (aPortDecl.componentDeclaration <> null)]
[aPortDecl.componentDeclaration.name /][else]
[aPortDecl.connectorDeclaration.name /][/if].[aPortDecl.forwardPortDeclaration.name /]
[/template]
[template public generateConnectorDeclaration(aConnectorDeclaration : ConnectorDeclaration, aCompoundType : CompoundType)]
connector [qualifiedName(aCompoundType, aConnectorDeclaration.type) /] [aConnectorDeclaration.name /] ([for (param : PortDeclarationReferenceParameter | aConnectorDeclaration.portParameters) separator(', ')][param.subPortDeclarationReference.generateSubPortDeclRef()/][/for])
[/template]
[template public generatePriorityDeclaration(aPriorityDeclaration : CompoundPriorityDeclaration)]
priority [aPriorityDeclaration.name /] [aPriorityDeclaration.low.generateConnectorInteraction() /] < [aPriorityDeclaration.high.generateConnectorInteraction() /]
[if (aPriorityDeclaration.guard <> null)]provided ([aPriorityDeclaration.guard.generateExpression()/])[/if]
[/template]
[template public generateConnectorInteraction(aConnectorInteraction : ConnectorInteraction)]
[if (aConnectorInteraction = null)]
*:*[else]
[aConnectorInteraction.connectorDeclaration.name /]:[for (pr : SubPortDeclarationReference | aConnectorInteraction.portDeclarationReferences) separator(', ')]
[pr.generateSubPortDeclRef() /][/for][if (aConnectorInteraction.portDeclarationReferences->isEmpty())]*[/if][/if]
[/template]
\ No newline at end of file
[comment encoding = UTF-8 /]
[module generateConnectorType('http://bip2/1.0')/]
[import ujf::verimag::bip::backend::bip::templates::generatePortDeclaration /]
[import ujf::verimag::bip::backend::bip::templates::connectorInteractionDefinition /]
[import ujf::verimag::bip::backend::acceleo::templates::expressions /]
[import ujf::verimag::bip::backend::bip::templates::commonBip /]
[query public getPortDecls(aConnectorType : ConnectorType) : Sequence(ConnectorPortParameterDeclaration) =
aConnectorType.ports /]
[template public generateConnectorType(aConnectorType : ConnectorType)]
connector type [aConnectorType.name /] ([for (param : PortDeclaration | aConnectorType.getPortDecls()) separator(', ')][qualifiedName(aConnectorType, param.portType)/] [param.name/][/for])
[for (dd : DataDeclaration | aConnectorType.dataDeclarations)]
data [if (dd.const)]const [/if][qualifiedName(aConnectorType, dd.dataType)/] [dd.name/][if (not dd.value->isEmpty())] = [dd.value.generateExpression()/][/if]
[/for]
[if (aConnectorType.exportedPortDeclaration <> null)]
export port [aConnectorType.exportedPortDeclaration.generatePortDeclaration(aConnectorType) /]
[/if]
define [aConnectorType.interactionDefinition.generateInteractionDefinition()/]
[for (cia : ConnectorInteractionAction | aConnectorType.interactions)]
on [for (onPort : ConnectorPortParameterDeclaration | cia.onPorts) separator(' ')][onPort.name/][/for]
[if (cia.guard->notEmpty())]
provided ([cia.guard.generateExpression()/])
[/if]
[for (e : Expression | cia.up) before (' up {\n') after(' }\n') ]
[e.generateExpression() /][if (not e.oclIsTypeOf(IfThenElseExpression))];[/if]
[/for]
[for (e : Expression | cia.down) before (' down {\n') after(' }\n') ]
[e.generateExpression() /][if (not e.oclIsTypeOf(IfThenElseExpression))];[/if]
[/for]
[/for]
end
[/template]
[comment encoding = UTF-8 /]
[module generatePackage('http://bip2/1.0')/]
[import ujf::verimag::bip::backend::bip::templates::commonBip /]
[import ujf::verimag::bip::backend::bip::templates::generateAtomType /]
[import ujf::verimag::bip::backend::bip::templates::generatePortType /]
[import ujf::verimag::bip::backend::bip::templates::generateConnectorType /]
[import ujf::verimag::bip::backend::bip::templates::generateCompoundType /]
[import ujf::verimag::bip::backend::bip::templates::annotations /]
[import ujf::verimag::bip::backend::acceleo::templates::expressions /]
[template public generatePackage(aPackage : BipPackage, fname : String)]
[comment @main /]
[file (fname, false, 'UTF-8')]
[aPackage.genAnnotations()/]
package [aPackage.name /]
[for (up : BipPackage | aPackage.used_packages)]
use [up.name /]
[/for]
[for (cdd : ConstDataDeclaration | aPackage.constData)]
const data [qualifiedName(aPackage, cdd.dataType)/] [cdd.name/] = [cdd.value.generateExpression()/]
[/for]
[for (edt : DataType | aPackage.dataTypes)]
[if (not edt.native)]
[edt.genAnnotations()/]
extern data type [edt.name /]
[/if]
[/for]
[for (ef : FunctionCallPrototype | aPackage.prototypes->select(oclIsKindOf(FunctionCallPrototype)))]
[if (not ef.native)]
[ef.genAnnotations()/]
extern function [if (not ef.returnType->isEmpty())][qualifiedName(aPackage, ef.returnType.oclAsType(DataType)) /] [/if][ef.functionName /]([generatePrototypeParameters(ef)/])
[/if]
[/for]
[for (ef : BinaryOpPrototype | aPackage.prototypes->select(oclIsKindOf(BinaryOpPrototype)))]
[if (not ef.native)]
[ef.genAnnotations()/]
extern operator [if (not ef.returnType->isEmpty())][qualifiedName(aPackage, ef.returnType.oclAsType(DataType)) /] [/if][ef.operator /]([generatePrototypeParameters(ef)/])
[/if]
[/for]
[for (ef : UnaryOpPrototype | aPackage.prototypes->select(oclIsKindOf(UnaryOpPrototype)))]
[if (not ef.native)]
[ef.genAnnotations()/]
extern operator [if (not ef.returnType->isEmpty())][qualifiedName(aPackage, ef.returnType.oclAsType(DataType)) /] [/if][ef.operator /]([generatePrototypeParameters(ef)/])
[/if]
[/for]
[for (pt : PortType | aPackage.portTypes)]
[pt.genAnnotations()/]
[pt.generatePortType() /]
[/for]
[for (ct : ConnectorType | aPackage.connectorTypes) separator('\n')]
[ct.genAnnotations()/]
[ct.generateConnectorType()/]
[/for]
[for (at : AtomType | aPackage.atomTypes) separator('\n')]
[at.genAnnotations()/]
[at.generateAtomType()/]
[/for]
[for (ct : CompoundType | aPackage.compoundTypes) separator('\n')]
[ct.genAnnotations()/]
[ct.generateCompoundType()/]
[/for]
end
[/file]
[/template]
[template private generatePrototypeParameters(proto : Prototype)]
[for (param : PrototypeParameterDeclaration | proto.parameterDeclarations) separator(', ')][generatePrototypeParameter(param)/][/for]
[/template]
[template private generatePrototypeParameter(param : PrototypeParameterDeclaration) {
aPackage : BipPackage = param.eContainer(Prototype).eContainer(BipPackage);
paramType : DataType = param.type.oclAsType(DataType);
}]
[if (param.const)]const [/if][qualifiedName(aPackage, paramType) /][if (param.name <> '')] [param.name/][/if]
[/template]
[comment encoding = UTF-8 /]
[module generatePortDeclaration('http://bip2/1.0')/]
[import ujf::verimag::bip::backend::bip::templates::commonBip /]
[template public generatePortDeclaration(aPortDeclaration : PortDeclaration, container : BipType)]
[aPortDeclaration.generatePortDeclaration(false, container)/]
[/template]
[template public generatePortDeclaration(aPortDeclaration : PortDeclaration, skipType: Boolean, container : BipType)]
[if (not skipType)][qualifiedName(container, aPortDeclaration.portType)/] [/if][aPortDeclaration.name /]([for (param : DataDeclarationReferenceDataParameter | aPortDeclaration.dataParameters) separator(', ')][param.dataDeclarationReference.name /][/for])
[/template]
\ No newline at end of file
[comment encoding = UTF-8 /]
[module generatePortType('http://bip2/1.0')/]
[import ujf::verimag::bip::backend::bip::templates::commonBip /]
[template public generatePortType(aPortType : PortType)]
port type [aPortType.name /] ([for (dd : DataDeclaration | aPortType.dataParameterDeclarations) separator(', ')][if (dd.const)]const [/if][qualifiedName(aPortType, dd.dataType)/] [dd.name /][/for])
[/template]
eclipse.preferences.version=1
formatter_profile=_custom
formatter_settings_version=12
/**
* Copyright Verimag laboratory.
*
* contributors:
* Jacques Combaz (jacques.combaz@univ-grenoble-alpes.fr)
*
* This software is a computer program whose purpose is to generate
* executable code from BIP models.
*
* This software is governed by the CeCILL-B license under French law and
* abiding by the rules of distribution of free software. You can use,
* modify and/ or redistribute the software under the terms of the CeCILL-B
* license as circulated by CEA, CNRS and INRIA at the following URL
* "http://www.cecill.info".
*
* As a counterpart to the access to the source code and rights to copy,
* modify and redistribute granted by the license, users are provided only
* with a limited warranty and the software's author, the holder of the
* economic rights, and the successive licensors have only limited
* liability.
*
* In this respect, the user's attention is drawn to the risks associated
* with loading, using, modifying and/or developing or reproducing the
* software by the user in light of its specific status of free software,
* that may mean that it is complicated to manipulate, and that also
* therefore means that it is reserved for developers and experienced
* professionals having in-depth computer knowledge. Users are therefore
* encouraged to load and test the software's suitability as regards their
* requirements in conditions enabling the security of their systems and/or
* data to be ensured and, more generally, to use and operate it in the
* same conditions as regards security.
*
* The fact that you are presently reading this means that you have had
* knowledge of the CeCILL-B license and that you accept its terms.
*/
package ujf.verimag.bip.backend.c;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.eclipse.emf.common.util.BasicMonitor;
import joptsimple.OptionSet;
import joptsimple.OptionSpec;
import bip2.ujf.verimag.bip.instance.ComponentInstance;
import bip2.ujf.verimag.bip.packaging.BipPackage;
import ujf.verimag.bip.backend.BackendStatus;
import ujf.verimag.bip.backend.Backendable;
import ujf.verimag.bip.backend.BackendStatusEnum;
import ujf.verimag.bip.backend.c.templates.GeneratePackage;
import ujf.verimag.bip.backend.error.BackendGenericError;
import ujf.verimag.bip.error.GenericError;
public class CBackend implements Backendable {
private Logger logger = Logger.getLogger(this.getClass().getName());
/**
* Parameter for specifying where the files should be written
*/
private static final String GENC_OUTPUT_DIR = "genc-output-dir";
private String outputdir= null;
/**
* In case of used packages, should the backend also create code for them or assume
* everything is already done.
*/
private static final String GENC_FOLLOW_USED_PACKAGES = "genc-follow-used-packages";
private boolean follow_used_package = false;
/**
* User can specify extra search paths for includes in the command line.
* These paths will be added to other paths when calling
* the C++ compiler
*/
private static final String GENC_CC_I = "genc-cc-I";
private final List<String> user_include_dirs = new ArrayList<String>();
/**
* User can specify extra search paths for libraries in the command line.
* These paths will be added to other paths at link time by the linker
*/
private static final String GENC_LD_L = "genc-ld-L";
private final List<String> user_lib_dirs = new ArrayList<String>();
/**
* User can specify extra library in the command line.
* These library will be used at link time by the linker
*/
private static final String GENC_LD_l = "genc-ld-l";
private final List<String> user_libs= new ArrayList<String>();
/**
* User can specify extra source files to compile along with the generated code
*/
private static final String GENC_CC_EXTRA_SRC = "genc-cc-extra-src";
private final List<String> user_extra_src= new ArrayList<String>();
/**
* User can specify extra objects files to link with the others parts
*/
private static final String GENC_LD_EXTRA_OBJ = "genc-ld-extra-obj";
private final List<String> user_extra_obj= new ArrayList<String>();
public static String[][] backend_options_with_no_params={
{GENC_FOLLOW_USED_PACKAGES, "Also generate code for used packages."}
};
public static String[][] backend_options_with_params={
{GENC_OUTPUT_DIR, "Output directory for C backend"},
{GENC_CC_I,"Add a path to the include search path (used when calling the C/C++ compiler)" },
{GENC_LD_l,"Link with this library (use several times to add many libraries)" },
{GENC_LD_L,"Add a path to the libraries search path (used when calling the linker)" },
{GENC_CC_EXTRA_SRC,"Add an extra source file to the compilation list" },
{GENC_LD_EXTRA_OBJ,"Add an extra object file to be linked with the other parts" }
};
@Override
public boolean isEnabled(){
// enabled if the outputfile has been set.
return (this.outputdir != null);
}
@Override
public BackendStatus generateFromPackage(BipPackage pack) {
System.out.println("Generate package for " + pack.getName());
File outputdirF = new File(this.outputdir, "c");
try {
List<String> tmpl_args = new ArrayList<String>();
tmpl_args.add("xxx.C");
outputdirF.mkdirs();
GeneratePackage generator = new GeneratePackage(pack, outputdirF,
tmpl_args);
generator.doGenerate(new BasicMonitor());
}
catch (IOException e) {
e.printStackTrace();
return new BackendStatus(BackendStatusEnum.FAIL);
}
return new BackendStatus(BackendStatusEnum.SUCCESS);
}
@Override
public boolean canGenerateFromPackage() {
return true;
}
@Override
public boolean canGenerateFromInstance() {
return true;
}
@Override
public BackendStatus generateFromInstance(ComponentInstance instance) {
System.out.println("Generate instance for " + instance.getDeclaration().getName());
return new BackendStatus(BackendStatusEnum.SUCCESS);
}
@Override
public GenericError[] configure(OptionSet options,
Map<String, OptionSpec<String>> ospecs) {
if (options.has(ospecs.get(GENC_OUTPUT_DIR))){
this.outputdir= options.valueOf(ospecs.get(GENC_OUTPUT_DIR));
}
if (options.has(GENC_FOLLOW_USED_PACKAGES)){
this.follow_used_package = true;
}
if (options.has(ospecs.get(GENC_CC_I))){
for (String dir : options.valuesOf(ospecs.get(GENC_CC_I))){
final File d = new File (dir);
if (!d.exists()){
logger.log(Level.WARNING, "Directory: " + dir + " does not exist.");
} else if (!d.isDirectory()){
logger.log(Level.WARNING, dir + " is not a directory.");
}
dir = d.getAbsolutePath();
this.user_include_dirs.add(dir);
}
}
if (options.has(ospecs.get(GENC_LD_l))){
this.user_libs.addAll(options.valuesOf(ospecs.get(GENC_LD_l)));
}
if (options.has(ospecs.get(GENC_LD_L))){
for (String dir : options.valuesOf(ospecs.get(GENC_LD_L))){
File d = new File (dir);
if (!d.exists()){
logger.log(Level.WARNING, "Directory: " + dir + " does not exist.");
} else if (!d.isDirectory()){
logger.log(Level.WARNING, dir + " is not a directory.");
}
dir = d.getAbsolutePath();
this.user_lib_dirs.add(dir);
}
}
if (options.has(ospecs.get(GENC_CC_EXTRA_SRC))){
for (String src : options.valuesOf(ospecs.get(GENC_CC_EXTRA_SRC))){
File d = new File (src);
if (!d.exists()){
logger.log(Level.WARNING, "File: " + src + " does not exist.");
} else if (!d.isFile()){
logger.log(Level.WARNING, src + " is not a file.");
}
src= d.getAbsolutePath();
this.user_extra_src.add(src);
}
}
if (options.has(ospecs.get(GENC_LD_EXTRA_OBJ))){
for (String obj : options.valuesOf(ospecs.get(GENC_LD_EXTRA_OBJ))){
File d = new File (obj);
if (!d.exists()){
logger.log(Level.WARNING, "File: " + obj + " does not exist.");
} else if (d.isFile()){
logger.log(Level.WARNING, obj+ " is not a file.");
}
obj = d.getAbsolutePath();
this.user_extra_obj.add(obj);
}
}
// C backend needs root declaration.
if (isEnabled() && ! options.has(ospecs.get("d"))){
return new GenericError[]{new BackendGenericError("C back-end requires a root component declaration.") };
} else {
return new GenericError[0];
}
}
}
\ No newline at end of file
[comment encoding = UTF-8 /]
[module bitset('http://bip2/1.0')/]
[query public numberOfBitsInt() : Integer = 32 /]
[query public numberOfInt(size : Integer) : Integer =
if (size.mod(numberOfBitsInt()) = 0) then
size.div(numberOfBitsInt())
else
size.div(numberOfBitsInt()) + 1
endif
/]
[query private signature(bits : Set(Integer), index : Integer) : Integer =
bits
->select(i : Integer | index * numberOfBitsInt() <= i and i < (index + 1) * numberOfBitsInt())
->collect(i : Integer | i - index * numberOfBitsInt())
->collect(i : Integer | signatureSingleBit(i))
->sum()
/]
[query private signatureSingleBit(bit : Integer) : Integer =
if (bit = 0) then
1
else
2 * signatureSingleBit(bit - 1)
endif
/]
[query private maximal(seq : Sequence(Integer)) : Integer =
if (seq->size() = 0) then
0
else if (seq->size() = 1) then
seq->first()
else
if (seq->first() >= maximal(seq->subSequence(2, seq->size()))) then
seq->first()
else
maximal(seq->subSequence(2, seq->size()))
endif
endif endif
/]
[template private toStringBinary(i : Integer)]
[/template]
[template public generateBitSetDeclaration(name : String, size : Integer)]unsigned int [name/]['['/][numberOfInt(size)/][']'/][/template]
[template public generateTestBitSet(name : String, bits : Set(Integer)) {
maximalIndex : Integer = numberOfInt(bits->asSequence()->maximal() + 1) - 1;
indexesToCheck : Sequence(Integer) = Sequence{0 .. maximalIndex }->select(i : Integer | signature(bits, i) <> 0);
}]
[if (indexesToCheck->isEmpty())]true[else][for (index : Integer | indexesToCheck) separator(' && ')](([name/]['['/][index/][']'/] & [signature(bits, index)/]) == [signature(bits, index)/])[/for][/if]
[/template]
[template public generateSetBitSet(name : String, bits : Set(Integer)) {
maximalIndex : Integer = numberOfInt(bits->asSequence()->maximal() + 1) - 1;
}
]
[for (index : Integer | Sequence{0 .. maximalIndex }
->select(i : Integer | signature(bits, i) <> 0))]
[name/]['['/][index/][']'/] |= [signature(bits, index)/];
[/for]
[/template]
[template public generateResetBitSet(name : String, bits : Set(Integer)) {
maximalIndex : Integer = numberOfInt(bits->asSequence()->maximal() + 1) - 1;
}
]
[for (index : Integer | Sequence{0 .. maximalIndex }
->select(i : Integer | signature(bits, i) <> 0))]
[name/]['['/][index/][']'/] &= ~[signature(bits, index)/];
[/for]
[/template]
[template public generateInitializeBitSet(name : String, size : Integer)]
[for (index : Integer | Sequence{0 .. numberOfInt(size) - 1})]
[name/]['['/][index/][']'/] = 0;
[/for]
[/template]
[comment encoding = UTF-8 /]
[module common('http://bip2/1.0')/]
[comment TODO: replace by actual code checking for options /]
[query public isOptimEnabled(name : String) : Boolean = true /]
[comment The following query provides static analysis expressions (data dependencies) /]
[query private usesCustomDataTypes(anAtomType : AtomType) : Boolean =
anAtomType.internalDataDeclarations->select(s:AtomInternalDataDeclaration| not s.dataType.native)->notEmpty()
/]
[query public includesFunctionCall(expression : Expression) : Boolean =
if expression.oclIsKindOf(BinaryOpExpression) then
expression.oclAsType(BinaryOpExpression).left.includesFunctionCall() or
expression.oclAsType(BinaryOpExpression).right.includesFunctionCall()
else if expression.oclIsKindOf(UnaryOpExpression) then
expression.oclAsType(UnaryOpExpression).operand.includesFunctionCall()
else if expression.oclIsKindOf(AssignmentExpression) then
expression.oclAsType(AssignmentExpression).rhs.includesFunctionCall()
else if expression.oclIsKindOf(FunctionCallExpression) then
true
else if expression.oclIsKindOf(ValuedReferenceExpression) then
expression.oclAsType(ValuedReferenceExpression).expressionReference.includesFunctionCall()
else if expression.oclIsKindOf(IfThenElseExpression) then
expression.oclAsType(IfThenElseExpression).condition.includesFunctionCall() or
expression.oclAsType(IfThenElseExpression)._then->exists(includesFunctionCall()) or
expression.oclAsType(IfThenElseExpression)._else->exists(includesFunctionCall())
else false
endif endif endif endif endif endif
/]
[query public readVariables(expression : Expression) : Set(DataDeclaration) =
if expression.oclIsKindOf(BinaryOpExpression) then
expression.oclAsType(BinaryOpExpression).left.readVariables()
->union(expression.oclAsType(BinaryOpExpression).right.readVariables())
else if expression.oclIsKindOf(UnaryOpExpression) then
expression.oclAsType(UnaryOpExpression).operand.readVariables()
else if expression.oclIsKindOf(SubDataDeclarationReference) then
Set { expression.oclAsType(SubDataDeclarationReference).forwardDataDeclaration }
else if expression.oclIsKindOf(DirectDataDeclarationReferenceExpression) then
Set { expression.oclAsType(DirectDataDeclarationReferenceExpression).dataDeclaration }
else if expression.oclIsKindOf(AssignmentExpression) then
Set { expression.oclAsType(AssignmentExpression).lhsDirect.dataDeclaration }
->union(expression.oclAsType(AssignmentExpression).rhs.readVariables())
else if expression.oclIsKindOf(FunctionCallExpression) then
expression.oclAsType(FunctionCallExpression).parameters->collect(readVariables())
->flatten()->asSet()
else if expression.oclIsKindOf(ValuedReferenceExpression) then
expression.oclAsType(ValuedReferenceExpression).expressionReference.readVariables()
else if expression.oclIsKindOf(IfThenElseExpression) then
expression.oclAsType(IfThenElseExpression).condition.readVariables()
->union(expression.oclAsType(IfThenElseExpression)._then->collect(readVariables())->flatten()->asSet())
->union(expression.oclAsType(IfThenElseExpression)._else->collect(readVariables())->flatten()->asSet())
else Set {}
endif endif endif endif endif endif endif endif
/]
[query public writtenVariables(expression : Expression) : Set(DataDeclaration) =
if expression.oclIsKindOf(BinaryOpExpression) then
expression.oclAsType(BinaryOpExpression).left.writtenVariables()
->union(expression.oclAsType(BinaryOpExpression).right.writtenVariables())
else if expression.oclIsKindOf(UnaryOpExpression) then
expression.oclAsType(UnaryOpExpression).operand.writtenVariables()
else if expression.oclIsKindOf(AssignmentExpression) then
Set { expression.oclAsType(AssignmentExpression).lhsDirect.dataDeclaration }
->union(expression.oclAsType(AssignmentExpression).rhs.writtenVariables())
else if expression.oclIsKindOf(FunctionCallExpression) then
expression.oclAsType(FunctionCallExpression).parameters->collect(readVariables())
->flatten()->asSet()
else if expression.oclIsKindOf(ValuedReferenceExpression) then
expression.oclAsType(ValuedReferenceExpression).expressionReference.writtenVariables()
else if expression.oclIsKindOf(IfThenElseExpression) then
expression.oclAsType(IfThenElseExpression).condition.writtenVariables()
->union(expression.oclAsType(IfThenElseExpression)._then->collect(writtenVariables())->flatten()->asSet())
->union(expression.oclAsType(IfThenElseExpression)._else->collect(writtenVariables())->flatten()->asSet())
else Set {}
endif endif endif endif endif endif
/]
[query public readVariables(actions : OrderedSet(Expression)) : Set(DataDeclaration) =
actions->collect(readVariables())->flatten()->asSet()
/]
[query public writtenVariables(actions : OrderedSet(Expression)) : Set(DataDeclaration) =
actions->collect(writtenVariables())->flatten()->asSet()
/]
[query public includesFunctionCall(actions : OrderedSet(Expression)) : Boolean =
actions->exists(a : Expression | includesFunctionCall(a))
/]
[query public mightBeModifiedBy(data : DataDeclaration, actions : OrderedSet(Expression)) : Boolean =
(not isOptimEnabled('no-side-effect') and (includesFunctionCall(actions) or writtenVariables(actions)->exists(not dataType.native))) or
writtenVariables(actions)->includes(data)
/]
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
#Wed Jul 13 11:45:11 CEST 2011
eclipse.preferences.version=1
formatter_profile=_custom
formatter_settings_version=12
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
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