diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/IStatemachine.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/IStatemachine.class new file mode 100644 index 0000000000..3140396b18 Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/IStatemachine.class differ diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/ITimer.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/ITimer.class new file mode 100644 index 0000000000..2641153b0b Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/ITimer.class differ diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/ITimerCallback.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/ITimerCallback.class new file mode 100644 index 0000000000..6a5a92ab5e Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/ITimerCallback.class differ diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/RuntimeService$StatemachineTimerTask.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/RuntimeService$StatemachineTimerTask.class new file mode 100644 index 0000000000..9b50a8a09a Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/RuntimeService$StatemachineTimerTask.class differ diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/RuntimeService.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/RuntimeService.class new file mode 100644 index 0000000000..b025c3e28e Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/RuntimeService.class differ diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/TimerService$TimeEventTask.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/TimerService$TimeEventTask.class new file mode 100644 index 0000000000..a441179cd0 Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/TimerService$TimeEventTask.class differ diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/TimerService.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/TimerService.class new file mode 100644 index 0000000000..fe27639ce1 Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/TimerService.class differ diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/ITrafficLightWaitingStatemachine$SCIPedestrian.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/ITrafficLightWaitingStatemachine$SCIPedestrian.class new file mode 100644 index 0000000000..d09b437307 Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/ITrafficLightWaitingStatemachine$SCIPedestrian.class differ diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/ITrafficLightWaitingStatemachine$SCITrafficLight.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/ITrafficLightWaitingStatemachine$SCITrafficLight.class new file mode 100644 index 0000000000..10b7097ca2 Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/ITrafficLightWaitingStatemachine$SCITrafficLight.class differ diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/ITrafficLightWaitingStatemachine$SCInterface.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/ITrafficLightWaitingStatemachine$SCInterface.class new file mode 100644 index 0000000000..b988cfca9c Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/ITrafficLightWaitingStatemachine$SCInterface.class differ diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/ITrafficLightWaitingStatemachine.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/ITrafficLightWaitingStatemachine.class new file mode 100644 index 0000000000..b3c8a8836d Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/ITrafficLightWaitingStatemachine.class differ diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine$SCIPedestrianImpl.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine$SCIPedestrianImpl.class new file mode 100644 index 0000000000..3257aa75c9 Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine$SCIPedestrianImpl.class differ diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine$SCITrafficLightImpl.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine$SCITrafficLightImpl.class new file mode 100644 index 0000000000..7c36949c52 Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine$SCITrafficLightImpl.class differ diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine$SCInterfaceImpl.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine$SCInterfaceImpl.class new file mode 100644 index 0000000000..4a39a0898d Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine$SCInterfaceImpl.class differ diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine$State.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine$State.class new file mode 100644 index 0000000000..5fe3ee1ef3 Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine$State.class differ diff --git a/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine.class b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine.class new file mode 100644 index 0000000000..3a7c2d64e9 Binary files /dev/null and b/examples/org.yakindu.sct.examples.trafficlight/bin/org/yakindu/sct/examples/trafficlight/cyclebased/trafficlightwaiting/TrafficLightWaitingStatemachine.class differ diff --git a/examples/org.yakindu.sct.ui.examples/bin/org/yakindu/sct/ui/examples/Activator.class b/examples/org.yakindu.sct.ui.examples/bin/org/yakindu/sct/ui/examples/Activator.class new file mode 100644 index 0000000000..bb9fb7dadf Binary files /dev/null and b/examples/org.yakindu.sct.ui.examples/bin/org/yakindu/sct/ui/examples/Activator.class differ diff --git a/plugins/org.yakindu.sct.doc.user/help/05_reference/reference.textile b/plugins/org.yakindu.sct.doc.user/help/05_reference/reference.textile index 6791ff0909..0e32a28865 100644 --- a/plugins/org.yakindu.sct.doc.user/help/05_reference/reference.textile +++ b/plugins/org.yakindu.sct.doc.user/help/05_reference/reference.textile @@ -644,6 +644,24 @@ feature IdentifierSettings { } p. ==== +==== + +h4. Tracing + +The *Tracing* feature allows to enable generation of tracing callback functions: + +# __enterState__ (Boolean, optional): whether to generate a callback that is used to notify about 'state enter' events. +# __exitState__ (Boolean, optional): whether to generate a callback that is used to notify about 'state exit' events. + +Sample configuration: + +bc(prettyprint).. +feature Tracing { + enterState = true + exitState = true +} +p. ==== + ==== h4. GeneratorOptions diff --git a/plugins/org.yakindu.sct.domain.generic/src/org/yakindu/sct/domain/generic/extension/GenericDomainInjectorProvider.java b/plugins/org.yakindu.sct.domain.generic/src/org/yakindu/sct/domain/generic/extension/GenericDomainInjectorProvider.java index 0f48124e97..0a63db6c2a 100644 --- a/plugins/org.yakindu.sct.domain.generic/src/org/yakindu/sct/domain/generic/extension/GenericDomainInjectorProvider.java +++ b/plugins/org.yakindu.sct.domain.generic/src/org/yakindu/sct/domain/generic/extension/GenericDomainInjectorProvider.java @@ -82,7 +82,6 @@ public Module getSequencerModule() { return new GenericSequencerModule(); } - protected Module getResourceModule() { Module uiModule = Modules.override(getLanguageRuntimeModule()).with(getLanguageUIModule()); Module result = Modules.override(uiModule).with(getSharedStateModule()); @@ -117,14 +116,22 @@ public Injector getResourceInjector() { public Injector getSimulationInjector() { return Guice.createInjector(getSimulationModule()); } - + @Override public Injector getSequencerInjector() { return Guice.createInjector(getSequencerModule()); } + + @Override + public Injector getSequencerInjector(Module overrides) { + if(overrides != null) { + return Guice.createInjector(Modules.override(getSequencerModule()).with(overrides)); + } + return getSequencerInjector(); + } @Override public Injector getEditorInjector() { - return Guice.createInjector(new GenericEditorModule()); + return Guice.createInjector(new GenericEditorModule()); } } diff --git a/plugins/org.yakindu.sct.domain.generic/src/org/yakindu/sct/domain/generic/modules/GenericSequencerModule.java b/plugins/org.yakindu.sct.domain.generic/src/org/yakindu/sct/domain/generic/modules/GenericSequencerModule.java index ef9d0e111d..d58485cc8b 100644 --- a/plugins/org.yakindu.sct.domain.generic/src/org/yakindu/sct/domain/generic/modules/GenericSequencerModule.java +++ b/plugins/org.yakindu.sct.domain.generic/src/org/yakindu/sct/domain/generic/modules/GenericSequencerModule.java @@ -52,8 +52,8 @@ public Class bindIQualifiedNameProvider() { public Class bindITypeSystemInferrer() { return STextTypeInferrer.class; } - - public Class bindITypesystem(){ + + public Class bindITypesystem() { return GenericTypeSystem.class; } diff --git a/plugins/org.yakindu.sct.domain/src/org/yakindu/sct/domain/extension/IDomainInjectorProvider.java b/plugins/org.yakindu.sct.domain/src/org/yakindu/sct/domain/extension/IDomainInjectorProvider.java index dabddde58b..95c69ea1f8 100644 --- a/plugins/org.yakindu.sct.domain/src/org/yakindu/sct/domain/extension/IDomainInjectorProvider.java +++ b/plugins/org.yakindu.sct.domain/src/org/yakindu/sct/domain/extension/IDomainInjectorProvider.java @@ -13,6 +13,7 @@ import org.yakindu.sct.model.sgraph.resource.AbstractSCTResource; import com.google.inject.Injector; +import com.google.inject.Module; /** * @author andreas muelder - Initial contribution and API @@ -33,10 +34,17 @@ public interface IDomainInjectorProvider { public Injector getSimulationInjector(); /** - * Returns the Injector for the model sequencing + * Returns the Injector for the model sequencing without overriding existing + * bindings. */ public Injector getSequencerInjector(); + /** + * Returns the Injector for the model sequencing, giving precedence to those + * bindings in the overrides module. + */ + public Injector getSequencerInjector(Module overrides); + /** * Injector used to create the embedded in-diagram Xtext Editor * @@ -46,7 +54,6 @@ public interface IDomainInjectorProvider { */ public Injector getEmbeddedEditorInjector(String elementKey); - /** * Returns an injector for all editor and UI related stuff. */ diff --git a/plugins/org.yakindu.sct.generator.c/META-INF/MANIFEST.MF b/plugins/org.yakindu.sct.generator.c/META-INF/MANIFEST.MF index e10a0d8eda..4d223d37e6 100644 --- a/plugins/org.yakindu.sct.generator.c/META-INF/MANIFEST.MF +++ b/plugins/org.yakindu.sct.generator.c/META-INF/MANIFEST.MF @@ -20,7 +20,8 @@ Require-Bundle: org.yakindu.sct.model.sexec, org.yakindu.sct.generator.genmodel;bundle-version="1.0.0", org.yakindu.base.types;bundle-version="1.0.0", org.eclipse.xtext.xbase.lib;bundle-version="2.3.0", - org.eclipse.xtext.builder;bundle-version="2.3.0" + org.eclipse.xtext.builder;bundle-version="2.3.0", + org.yakindu.sct.domain.generic Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Export-Package: org.yakindu.sct.generator.c, org.yakindu.sct.generator.c.features, diff --git a/plugins/org.yakindu.sct.generator.c/library/FeatureTypeLibrary.xmi b/plugins/org.yakindu.sct.generator.c/library/FeatureTypeLibrary.xmi index e6e855cdbe..52e27b4abb 100644 --- a/plugins/org.yakindu.sct.generator.c/library/FeatureTypeLibrary.xmi +++ b/plugins/org.yakindu.sct.generator.c/library/FeatureTypeLibrary.xmi @@ -22,4 +22,17 @@ name="separator" optional="true"/> + + + + diff --git a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CCodeGenerator.java b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CCodeGenerator.java index cdefa49d24..65ee25f273 100644 --- a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CCodeGenerator.java +++ b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CCodeGenerator.java @@ -1,40 +1,47 @@ /** - * Copyright (c) 2012 committers of YAKINDU and others. + * Copyright (c) 2012, 2015 Committers of YAKINDU and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * Contributors: - * committers of YAKINDU - initial API and implementation + * + * Andreas Mülder - Initial API and implementation + * Alexander Nyßen - Support for 'Tracing' feature * */ package org.yakindu.sct.generator.c; import static org.yakindu.sct.generator.core.util.GeneratorUtils.isDumpSexec; +import org.yakindu.sct.domain.generic.modules.GenericSequencerModule; +import org.yakindu.sct.generator.c.features.ICFeatureConstants; import org.yakindu.sct.generator.c.types.CTypeSystemAccess; import org.yakindu.sct.generator.core.impl.GenericJavaBasedGenerator; import org.yakindu.sct.generator.core.types.ICodegenTypeSystemAccess; import org.yakindu.sct.model.sexec.ExecutionFlow; import org.yakindu.sct.model.sexec.naming.INamingService; +import org.yakindu.sct.model.sgen.FeatureConfiguration; import org.yakindu.sct.model.sgen.GeneratorEntry; import org.yakindu.sct.model.sgraph.Statechart; import com.google.inject.Binder; import com.google.inject.Module; +import com.google.inject.name.Names; import com.google.inject.util.Modules; /** + * Provides a C code generator implementation that is based on SExec. * - * @author andreas muelder + * @author Andreas Mülder + * @author Alexander Nyßen * */ public class CCodeGenerator extends GenericJavaBasedGenerator { @Override public void runGenerator(Statechart statechart, GeneratorEntry entry) { - CSCTGenerator delegate = getInjector(entry).getInstance( - CSCTGenerator.class); + CGenerator delegate = getInjector(entry).getInstance(CGenerator.class); ExecutionFlow flow = createExecutionFlow(statechart, entry); if (isDumpSexec(entry)) { dumpSexec(entry, flow); @@ -43,14 +50,34 @@ public void runGenerator(Statechart statechart, GeneratorEntry entry) { } @Override - protected Module getChildInjectorModule(final GeneratorEntry entry) { - Module module = super.getChildInjectorModule(entry); + protected Module getOverridesModule(final GeneratorEntry entry) { + Module module = super.getOverridesModule(entry); + return Modules.override(module).with(new Module() { public void configure(Binder binder) { - binder.bind(ICodegenTypeSystemAccess.class) - .to(CTypeSystemAccess.class); - binder.bind(INamingService.class).to(CNamingService.class); + binder.bind(GeneratorEntry.class).toInstance(entry); + binder.bind(INamingService.class).to(CNamingService.class); + binder.bind(ICodegenTypeSystemAccess.class).to(CTypeSystemAccess.class); + + // Enable generation of trace steps in case the Tracing feature + // is specified and at least one of enter/exit states is + // enabled. + FeatureConfiguration tracingFeatureConfiguration = entry + .getFeatureConfiguration(ICFeatureConstants.FEATURE_TRACING); + if (tracingFeatureConfiguration != null && ((tracingFeatureConfiguration + .getParameterValue(ICFeatureConstants.PARAMETER_TRACING_ENTER_STATE) != null + && tracingFeatureConfiguration + .getParameterValue(ICFeatureConstants.PARAMETER_TRACING_ENTER_STATE) + .getBooleanValue() == true) + || (tracingFeatureConfiguration + .getParameterValue(ICFeatureConstants.PARAMETER_TRACING_EXIT_STATE) != null + && tracingFeatureConfiguration + .getParameterValue(ICFeatureConstants.PARAMETER_TRACING_EXIT_STATE) + .getBooleanValue() == true))) { + binder.bind(Boolean.class).annotatedWith(Names.named(GenericSequencerModule.ADD_TRACES)) + .toInstance(Boolean.TRUE); + } } }); } diff --git a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CSCTGenerator.xtend b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CGenerator.xtend similarity index 71% rename from plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CSCTGenerator.xtend rename to plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CGenerator.xtend index a35ee61d34..189768227a 100644 --- a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CSCTGenerator.xtend +++ b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/CGenerator.xtend @@ -22,27 +22,20 @@ import org.yakindu.sct.model.sgraph.Statechart * * @author Axel Terfloth */ -class CSCTGenerator implements IExecutionFlowGenerator { +class CGenerator implements IExecutionFlowGenerator { @Inject extension Types - @Inject extension Statemachine - @Inject extension StatemachineC - @Inject extension StatemachineRequired + @Inject extension StatemachineHeader + @Inject extension StatemachineSource + @Inject extension StatemachineRequiredHeader @Inject extension Navigation override generate(ExecutionFlow flow, GeneratorEntry entry, IFileSystemAccess fsa) { - flow.generateTypesH(flow.sourceElement as Statechart, fsa, entry) - - flow.generateStatemachineH(flow.sourceElement as Statechart, fsa, entry) - + flow.generateStatemachineHeader(flow.sourceElement as Statechart, fsa, entry) if (flow.timed || !flow.operations.empty) { - flow.generateStatemachineClientH(flow.sourceElement as Statechart, fsa, entry) + flow.generateStatemachineRequiredHeader(flow.sourceElement as Statechart, fsa, entry) } - - flow.generateStatemachineC(flow.sourceElement as Statechart, fsa, entry) - + flow.generateStatemachineSource(flow.sourceElement as Statechart, fsa, entry) } - - } \ No newline at end of file diff --git a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/FlowCode.xtend b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/FlowCode.xtend index b346f67701..0a17b1d0e7 100644 --- a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/FlowCode.xtend +++ b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/FlowCode.xtend @@ -24,8 +24,12 @@ import org.yakindu.sct.model.sexec.ScheduleTimeEvent import org.yakindu.sct.model.sexec.Sequence import org.yakindu.sct.model.sexec.StateSwitch import org.yakindu.sct.model.sexec.Step +import org.yakindu.sct.model.sexec.Trace +import org.yakindu.sct.model.sexec.TraceStateEntered +import org.yakindu.sct.model.sexec.TraceStateExited import org.yakindu.sct.model.sexec.UnscheduleTimeEvent import org.yakindu.sct.model.sexec.naming.INamingService +import org.yakindu.sct.model.sgen.GeneratorEntry class FlowCode { @@ -33,6 +37,9 @@ class FlowCode { @Inject extension Navigation @Inject extension ExpressionCode @Inject extension INamingService + @Inject extension GenmodelEntries + + @Inject GeneratorEntry entry def stepComment(Step it) ''' «IF !comment.nullOrEmpty» @@ -43,6 +50,21 @@ class FlowCode { def dispatch CharSequence code(Step it) ''' #error ActionCode for Step '«getClass().name»' not defined ''' + +// ignore all trace steps not explicitly supported + def dispatch CharSequence code(Trace it)'''''' + + def dispatch CharSequence code(TraceStateEntered it) ''' + «IF entry.tracingEnterState» + stateEntered(«it.state.shortName»); + «ENDIF» + ''' + + def dispatch CharSequence code(TraceStateExited it) ''' + «IF entry.tracingExitState» + stateExited(«it.state.shortName»); + «ENDIF» + ''' def dispatch CharSequence code(SaveHistory it) ''' «stepComment» diff --git a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/GenmodelEntries.xtend b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/GenmodelEntries.xtend index 27625d68dd..f8b351c0ed 100644 --- a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/GenmodelEntries.xtend +++ b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/GenmodelEntries.xtend @@ -12,7 +12,7 @@ package org.yakindu.sct.generator.c import org.yakindu.sct.generator.core.features.ICoreFeatureConstants import org.yakindu.sct.model.sgen.FeatureParameterValue import org.yakindu.sct.model.sgen.GeneratorEntry -import org.yakindu.sct.generator.c.features.CFeatureConstants +import org.yakindu.sct.generator.c.features.ICFeatureConstants class GenmodelEntries { @@ -32,11 +32,11 @@ class GenmodelEntries { } def private getIdentifierSettingsFeature(GeneratorEntry it) { - getFeatureConfiguration(CFeatureConstants::FEATURE_IDENTIFIER_SETTINGS) + getFeatureConfiguration(ICFeatureConstants::FEATURE_NAMING) } def private FeatureParameterValue getMaxIdentifierLengthParameter(GeneratorEntry it) { - identifierSettingsFeature?.getParameterValue(CFeatureConstants::PARAMETER_MAX_IDENTIFIER_LENGTH) + identifierSettingsFeature?.getParameterValue(ICFeatureConstants::PARAMETER_NAMING_MAX_IDENTIFIER_LENGTH) } def getIdentifierLength(GeneratorEntry it) { @@ -52,7 +52,7 @@ class GenmodelEntries { } def private FeatureParameterValue getSeparatorParameter(GeneratorEntry it) { - identifierSettingsFeature?.getParameterValue(CFeatureConstants::PARAMETER_SEPARATOR) + identifierSettingsFeature?.getParameterValue(ICFeatureConstants::PARAMETER_NAMING_SEPARATOR) } def getSeparator(GeneratorEntry it) { @@ -60,7 +60,7 @@ class GenmodelEntries { } def private FeatureParameterValue getStatemachinePrefixParameter(GeneratorEntry it) { - identifierSettingsFeature?.getParameterValue(CFeatureConstants::PARAMETER_STATEMACHINE_PREFIX) + identifierSettingsFeature?.getParameterValue(ICFeatureConstants::PARAMETER_NAMING_STATEMACHINE_PREFIX) } def getStatemachinePrefix(GeneratorEntry it) { @@ -68,10 +68,31 @@ class GenmodelEntries { } def private FeatureParameterValue getModuleNameParameter(GeneratorEntry it) { - identifierSettingsFeature?.getParameterValue(CFeatureConstants::PARAMETER_MODULE_NAME) + identifierSettingsFeature?.getParameterValue(ICFeatureConstants::PARAMETER_NAMING_MODULE_NAME) } def getModuleName(GeneratorEntry it) { return moduleNameParameter?.stringValue } + + + def private getTracingFeature(GeneratorEntry it) { + getFeatureConfiguration(ICFeatureConstants::FEATURE_TRACING) + } + + def getTracingEnterState(GeneratorEntry it){ + val enterStateParameter = tracingFeature?.getParameterValue(ICFeatureConstants::PARAMETER_TRACING_ENTER_STATE) + if (enterStateParameter != null) { + return enterStateParameter.booleanValue + } + return false + } + + def getTracingExitState(GeneratorEntry it){ + val exitStateParameter = tracingFeature?.getParameterValue(ICFeatureConstants::PARAMETER_TRACING_EXIT_STATE) + if (exitStateParameter != null) { + return exitStateParameter.booleanValue + } + return false + } } \ No newline at end of file diff --git a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/Statemachine.xtend b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineHeader.xtend similarity index 96% rename from plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/Statemachine.xtend rename to plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineHeader.xtend index a1186985a8..937781c74c 100644 --- a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/Statemachine.xtend +++ b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineHeader.xtend @@ -29,7 +29,7 @@ import org.yakindu.sct.model.stext.stext.VariableDefinition import static org.eclipse.xtext.util.Strings.* -class Statemachine { +class StatemachineHeader { @Inject extension Naming cNaming @Inject extension Navigation @@ -37,12 +37,12 @@ class Statemachine { @Inject extension GenmodelEntries @Inject extension INamingService - def generateStatemachineH(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) { + def generateStatemachineHeader(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) { flow.initializeNamingService - fsa.generateFile(flow.module.h, flow.statemachineHContent(entry)) + fsa.generateFile(flow.module.h, flow.generateStatemachineHeaderContents(entry)) } - def statemachineHContent(ExecutionFlow it, GeneratorEntry entry) ''' + def generateStatemachineHeaderContents(ExecutionFlow it, GeneratorEntry entry) ''' «entry.licenseText» #ifndef «module.define»_H_ diff --git a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineRequired.xtend b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineRequiredHeader.xtend similarity index 84% rename from plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineRequired.xtend rename to plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineRequiredHeader.xtend index 05122f0fdd..bfaafe9d1f 100644 --- a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineRequired.xtend +++ b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineRequiredHeader.xtend @@ -21,7 +21,7 @@ import org.yakindu.sct.model.sgraph.Statechart import org.yakindu.sct.model.stext.stext.OperationDefinition import org.yakindu.sct.model.stext.stext.StatechartScope -class StatemachineRequired { +class StatemachineRequiredHeader { @Inject extension Naming cNaming @Inject extension Navigation @@ -29,11 +29,11 @@ class StatemachineRequired { @Inject extension GenmodelEntries @Inject extension INamingService - def generateStatemachineClientH(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) { - fsa.generateFile(flow.module.client.h, flow.statemachineClientHContent(entry) ) + def generateStatemachineRequiredHeader(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) { + fsa.generateFile(flow.module.client.h, flow.statemachineRequiredHeaderContents(entry) ) } - def statemachineClientHContent(ExecutionFlow it, GeneratorEntry entry) ''' + def statemachineRequiredHeaderContents(ExecutionFlow it, GeneratorEntry entry) ''' «entry.licenseText» #ifndef «module.client.define»_H_ @@ -95,6 +95,22 @@ class StatemachineRequired { extern void «type.toFirstLower»_unsetTimer(«scHandleDecl», const sc_eventid evid); «ENDIF» + + «IF entry.tracingEnterState || entry.tracingExitState» + /*! + * Tracing callback functions + */ + «IF entry.tracingEnterState» + /*! This function is called when a state is entered. */ + extern void stateEntered(const SCTStates state); + «ENDIF» + + «IF entry.tracingExitState» + /*! This function is called when a state is exited. */ + extern void stateExited(const SCTStates state); + «ENDIF» + «ENDIF» + #ifdef __cplusplus } #endif diff --git a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineC.xtend b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineSource.xtend similarity index 97% rename from plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineC.xtend rename to plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineSource.xtend index 6929856257..2dbcb4dda9 100644 --- a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineC.xtend +++ b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/StatemachineSource.xtend @@ -25,7 +25,7 @@ import org.yakindu.sct.model.stext.stext.VariableDefinition import org.yakindu.sct.model.stext.stext.StatechartScope import org.eclipse.xtext.util.Strings -class StatemachineC { +class StatemachineSource { @Inject extension Naming @Inject extension GenmodelEntries @@ -36,14 +36,14 @@ class StatemachineC { @Inject extension ConstantInitializationResolver @Inject protected extension StateVectorExtensions - def generateStatemachineC(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) { + def generateStatemachineSource(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) { flow.initializeNamingService - var content = flow.statemachineCContent(entry) + var content = flow.generateStatemachineSourceContents(entry) var target = flow.module.c fsa.generateFile(target , content) } - def statemachineCContent(ExecutionFlow it, GeneratorEntry entry) ''' + def generateStatemachineSourceContents(ExecutionFlow it, GeneratorEntry entry) ''' «entry.licenseText» #include diff --git a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/features/CDefaultFeatureValueProvider.java b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/features/CDefaultFeatureValueProvider.java index 54de2e9ccc..a59a8efbee 100644 --- a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/features/CDefaultFeatureValueProvider.java +++ b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/features/CDefaultFeatureValueProvider.java @@ -1,12 +1,14 @@ /** - * Copyright (c) 2011 committers of YAKINDU and others. + * Copyright (c) 2011, 2015 Committers of YAKINDU and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html - * Contributors: - * committers of YAKINDU - initial API and implementation * + * Contributors: + * Andreas Mülder - Initial contribution and API + * Markus Mühlbrandt - Added support for 'IdentifierSettings' feature + * Alexander Nyßen - Added support for 'Tracing' feature; general refactorings */ package org.yakindu.sct.generator.c.features; @@ -21,63 +23,65 @@ import org.yakindu.sct.model.sgraph.Statechart; /** - * Feature value provider for c code generator. - * - * @author andreas muelder - Initial contribution and API - * @author Markus Mühlbrandt - Added additional features + * Provides default values and support for validating parameter values of C code + * generator generator model. * + * @author Andreas Mülder + * @author Markus Mühlbrandt + * @author Alexander Nyßen */ -public class CDefaultFeatureValueProvider extends - AbstractDefaultFeatureValueProvider { +public class CDefaultFeatureValueProvider extends AbstractDefaultFeatureValueProvider { private static final String INVALID_IDENTIFIER_REGEX = "[^a-z&&[^A-Z&&[^0-9]]]"; private static final String VALID_IDENTIFIER_REGEX = "[_a-zA-Z][_a-zA-Z0-9]*"; + @Override public boolean isProviderFor(FeatureTypeLibrary library) { - return CFeatureConstants.LIBRARY_NAME.equals(library.getName()); + return ICFeatureConstants.LIBRARY_NAME.equals(library.getName()); } @Override - protected void setDefaultValue(FeatureParameterValue parameterValue, - EObject contextElement) { + protected void setDefaultValue(FeatureParameterValue parameterValue, EObject contextElement) { GeneratorEntry entry = (GeneratorEntry) contextElement; Statechart statechart = (Statechart) entry.getElementRef(); + String parameterName = parameterValue.getParameter().getName(); - if (parameterValue.getParameter().getName() - .equals(CFeatureConstants.PARAMETER_MODULE_NAME)) { + if (ICFeatureConstants.PARAMETER_NAMING_MODULE_NAME.equals(parameterName)) { parameterValue.setValue(asIdentifier(statechart.getName(), "_")); - } else if (parameterValue.getParameter().getName() - .equals(CFeatureConstants.PARAMETER_STATEMACHINE_PREFIX)) { - parameterValue.setValue(StringExtensions.toFirstLower(asIdentifier( - statechart.getName(), "_"))); - } else if (parameterValue.getParameter().getName() - .equals(CFeatureConstants.PARAMETER_MAX_IDENTIFIER_LENGTH)) { + } else if (ICFeatureConstants.PARAMETER_NAMING_STATEMACHINE_PREFIX.equals(parameterName)) { + parameterValue.setValue(StringExtensions.toFirstLower(asIdentifier(statechart.getName(), "_"))); + } else if (ICFeatureConstants.PARAMETER_NAMING_MAX_IDENTIFIER_LENGTH.equals(parameterName)) { parameterValue.setValue("31"); - } else if (parameterValue.getParameter().getName() - .equals(CFeatureConstants.PARAMETER_SEPARATOR)) { + } else if (ICFeatureConstants.PARAMETER_NAMING_SEPARATOR.equals(parameterName)) { parameterValue.setValue("_"); + } else if (ICFeatureConstants.PARAMETER_TRACING_ENTER_STATE.equals(parameterName)) { + parameterValue.setValue(true); + } else if (ICFeatureConstants.PARAMETER_TRACING_EXIT_STATE.equals(parameterName)) { + parameterValue.setValue(true); + } else { + throw new IllegalArgumentException("Unsupported parameter '" + parameterName + "'."); } } - /** - * Executes some validations on the given {@link FeatureParameterValue} - */ + @Override public IStatus validateParameterValue(FeatureParameterValue parameter) { String parameterName = parameter.getParameter().getName(); - if (CFeatureConstants.PARAMETER_MODULE_NAME.equals(parameterName)) { + if (ICFeatureConstants.PARAMETER_NAMING_MODULE_NAME.equals(parameterName)) { if (!parameter.getStringValue().matches(VALID_IDENTIFIER_REGEX)) { return error("Invalid module name"); } - } else if (CFeatureConstants.PARAMETER_STATEMACHINE_PREFIX.equals(parameterName)) { + } else if (ICFeatureConstants.PARAMETER_NAMING_STATEMACHINE_PREFIX.equals(parameterName)) { if (!parameter.getStringValue().matches(VALID_IDENTIFIER_REGEX)) { return error("Invalid function prefix name"); } - } else if (CFeatureConstants.PARAMETER_SEPARATOR.equals(parameterName)) { + } else if (ICFeatureConstants.PARAMETER_NAMING_SEPARATOR.equals(parameterName)) { if (!parameter.getStringValue().matches(VALID_IDENTIFIER_REGEX)) { return error("Invalid separator"); } } + // No specific validation is required for 'enterState' and 'exitState' + // parameters of 'Tracing' feature, as they are boolean. return Status.OK_STATUS; } diff --git a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/features/CFeatureConstants.java b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/features/CFeatureConstants.java deleted file mode 100644 index 803931cf18..0000000000 --- a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/features/CFeatureConstants.java +++ /dev/null @@ -1,31 +0,0 @@ -/** - * Copyright (c) 2011 committers of YAKINDU and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * Contributors: - * committers of YAKINDU - initial API and implementation - * - */ -package org.yakindu.sct.generator.c.features; - -/** - * - * @author holger willebrandt - Initial contribution and API - * @author Markus Mühlbrandt - Additional feature identifiers - * - */ -public interface CFeatureConstants { - public static final String LIBRARY_NAME = "C Generator"; - - public static final String FEATURE_IDENTIFIER_SETTINGS = "IdentifierSettings"; - - public static final String PARAMETER_MODULE_NAME = "moduleName"; - - public static final String PARAMETER_STATEMACHINE_PREFIX = "statemachinePrefix"; - - public static final String PARAMETER_MAX_IDENTIFIER_LENGTH = "maxIdentifierLength"; - - public static final String PARAMETER_SEPARATOR = "separator"; -} diff --git a/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/features/ICFeatureConstants.java b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/features/ICFeatureConstants.java new file mode 100644 index 0000000000..6005ba237c --- /dev/null +++ b/plugins/org.yakindu.sct.generator.c/src/org/yakindu/sct/generator/c/features/ICFeatureConstants.java @@ -0,0 +1,45 @@ +/** + * Copyright (c) 2011, 2015 Committers of YAKINDU and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Holger Willebrandt - Initial API and implementation + * Markus Mühlbrandt - Added 'IdentifierSettings' feature and related parameters + * Alexander Nyßen - Added 'Tracing' feature and renamed constants + * + */ +package org.yakindu.sct.generator.c.features; + +/** + * Defines constants to refer to features and parameters within C code generator + * generator model. + * + * @author Holger Willebrandt + * @author Markus Mühlbrandt + * @author Alexander Nyßen + */ +public interface ICFeatureConstants { + + public static final String LIBRARY_NAME = "C Generator"; + + // TODO: Change value of FEATURE_NAMING to 'Naming' and extract it to a + // general code generator feature (see issue #267). + public static final String FEATURE_NAMING = "IdentifierSettings"; + + public static final String PARAMETER_NAMING_MODULE_NAME = "moduleName"; + + public static final String PARAMETER_NAMING_STATEMACHINE_PREFIX = "statemachinePrefix"; + + public static final String PARAMETER_NAMING_MAX_IDENTIFIER_LENGTH = "maxIdentifierLength"; + + public static final String PARAMETER_NAMING_SEPARATOR = "separator"; + + public static final String FEATURE_TRACING = "Tracing"; + + public static final String PARAMETER_TRACING_ENTER_STATE = "enterState"; + + public static final String PARAMETER_TRACING_EXIT_STATE = "exitState"; +} diff --git a/plugins/org.yakindu.sct.generator.core/META-INF/MANIFEST.MF b/plugins/org.yakindu.sct.generator.core/META-INF/MANIFEST.MF index 8ef762b44e..b54206c454 100644 --- a/plugins/org.yakindu.sct.generator.core/META-INF/MANIFEST.MF +++ b/plugins/org.yakindu.sct.generator.core/META-INF/MANIFEST.MF @@ -22,7 +22,8 @@ Require-Bundle: org.eclipse.ui, org.yakindu.base.types;bundle-version="1.0.0", org.eclipse.xtext.builder;bundle-version="2.3.0", org.yakindu.sct.commons;bundle-version="1.0.0", - org.yakindu.sct.domain;bundle-version="2.4.1" + org.yakindu.sct.domain;bundle-version="2.4.1", + org.yakindu.sct.domain.generic;bundle-version="2.5.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-ActivationPolicy: lazy Export-Package: org.yakindu.sct.builder.nature, diff --git a/plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/AbstractSExecModelGenerator.java b/plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/AbstractSExecModelGenerator.java index 37dc32f76f..90ba531462 100644 --- a/plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/AbstractSExecModelGenerator.java +++ b/plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/AbstractSExecModelGenerator.java @@ -31,6 +31,7 @@ import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl; import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; +import org.yakindu.sct.domain.generic.modules.GenericSequencerModule; import org.yakindu.sct.model.sexec.ExecutionFlow; import org.yakindu.sct.model.sexec.transformation.FlowOptimizer; import org.yakindu.sct.model.sexec.transformation.IModelSequencer; @@ -38,7 +39,11 @@ import org.yakindu.sct.model.sgen.GeneratorEntry; import org.yakindu.sct.model.sgraph.Statechart; +import com.google.inject.Binder; import com.google.inject.Injector; +import com.google.inject.Module; +import com.google.inject.name.Names; +import com.google.inject.util.Modules; /** * abstract base class for all code generators that want to generate code based @@ -47,8 +52,7 @@ * @author andreas muelder - Initial contribution and API * */ -public abstract class AbstractSExecModelGenerator extends - AbstractSGraphModelGenerator { +public abstract class AbstractSExecModelGenerator extends AbstractSGraphModelGenerator { private static final String SEXEC_FILE_EXTENSION = "sexec"; @@ -60,45 +64,49 @@ public AbstractSExecModelGenerator() { protected void runGenerator(Statechart statechart, GeneratorEntry entry) { if (this instanceof IExecutionFlowGenerator) { IExecutionFlowGenerator flowGenerator = (IExecutionFlowGenerator) this; - flowGenerator.generate(createExecutionFlow(statechart, entry), - entry, null); + flowGenerator.generate(createExecutionFlow(statechart, entry), entry, null); } super.runGenerator(statechart, entry); } + @Override + protected Module getOverridesModule(GeneratorEntry entry) { + Module module = super.getOverridesModule(entry); + + return Modules.override(module).with(new Module() { + public void configure(Binder binder) { + // by default, traces should not be generated + binder.bind(Boolean.class).annotatedWith(Names.named(GenericSequencerModule.ADD_TRACES)) + .toInstance(Boolean.FALSE); + } + }); + } + /** * Transforms the {@link Statechart} model to a {@link ExecutionFlow} model */ - protected ExecutionFlow createExecutionFlow(Statechart statechart, - GeneratorEntry entry) { + protected ExecutionFlow createExecutionFlow(Statechart statechart, GeneratorEntry entry) { Injector injector = getInjector(entry); IModelSequencer sequencer = injector.getInstance(IModelSequencer.class); ExecutionFlow flow = sequencer.transform(statechart); Assert.isNotNull(flow, "Error creation ExecutionFlow"); - FeatureConfiguration optimizeConfig = entry - .getFeatureConfiguration(FUNCTION_INLINING_FEATURE); + FeatureConfiguration optimizeConfig = entry.getFeatureConfiguration(FUNCTION_INLINING_FEATURE); FlowOptimizer optimizer = injector.getInstance(FlowOptimizer.class); - optimizer.inlineReactions(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_REACTIONS, false)); - optimizer.inlineExitActions(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_EXIT_ACTIONS, false)); - optimizer.inlineEntryActions(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_ENTRY_ACTIONS, false)); - optimizer.inlineEnterSequences(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_ENTER_SEQUENCES, false)); - optimizer.inlineExitSequences(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_EXIT_SEQUENCES, false)); - optimizer.inlineChoices(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_CHOICES, false)); - optimizer.inlineEntries(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_ENTRIES, false)); - optimizer.inlineEnterRegion(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_ENTER_REGION, false)); - optimizer.inlineExitRegion(getBoolValue(optimizeConfig, - FUNCTION_INLINING_FEATURE_INLINE_EXIT_REGION, false)); + optimizer.inlineReactions(getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_REACTIONS, false)); + optimizer.inlineExitActions(getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_EXIT_ACTIONS, false)); + optimizer.inlineEntryActions( + getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_ENTRY_ACTIONS, false)); + optimizer.inlineEnterSequences( + getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_ENTER_SEQUENCES, false)); + optimizer.inlineExitSequences( + getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_EXIT_SEQUENCES, false)); + optimizer.inlineChoices(getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_CHOICES, false)); + optimizer.inlineEntries(getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_ENTRIES, false)); + optimizer.inlineEnterRegion(getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_ENTER_REGION, false)); + optimizer.inlineExitRegion(getBoolValue(optimizeConfig, FUNCTION_INLINING_FEATURE_INLINE_EXIT_REGION, false)); flow = optimizer.transform(flow); @@ -107,13 +115,10 @@ protected ExecutionFlow createExecutionFlow(Statechart statechart, protected void dumpSexec(GeneratorEntry entry, ExecutionFlow flow) { ResourceSet resourceSet = new ResourceSetImpl(); - resourceSet - .getResourceFactoryRegistry() - .getExtensionToFactoryMap() - .put(Resource.Factory.Registry.DEFAULT_EXTENSION, - new XMIResourceFactoryImpl()); - URI fileURI = entry.getElementRef().eResource().getURI() - .trimFileExtension().appendFileExtension(SEXEC_FILE_EXTENSION); + resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap() + .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl()); + URI fileURI = entry.getElementRef().eResource().getURI().trimFileExtension() + .appendFileExtension(SEXEC_FILE_EXTENSION); Resource resource = resourceSet.createResource(fileURI); resource.getContents().add(flow); try { diff --git a/plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/AbstractSGraphModelGenerator.java b/plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/AbstractSGraphModelGenerator.java index b59ec1bc87..44fe302f30 100644 --- a/plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/AbstractSGraphModelGenerator.java +++ b/plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/AbstractSGraphModelGenerator.java @@ -6,7 +6,8 @@ * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * committers of YAKINDU - initial API and implementation + * Andreas Mülder - Initial API and implementation + * Alexaner Nyßen - Refactored to use overriding module instead of child injector */ package org.yakindu.sct.generator.core.impl; @@ -38,7 +39,7 @@ * abstract base class for all code generators that want to generate code based * on the {@link ExecutionFlow} * - * @author andreas muelder - Initial contribution and API + * @author Andreas Mülder - Initial contribution and API * */ public abstract class AbstractSGraphModelGenerator implements ISCTGenerator { @@ -73,7 +74,7 @@ public File getTargetProject(GeneratorEntry entry) { public File getTargetFolder(GeneratorEntry entry) { return GeneratorUtils.getTargetFolder(entry); } - + public File getLibraryTargetFolder(GeneratorEntry entry) { return GeneratorUtils.getLibraryTargetFolder(entry); } @@ -137,11 +138,11 @@ protected void finishGenerator(GeneratorEntry entry) { private Injector injector; protected Injector createInjector(GeneratorEntry entry) { - Injector sequencerInjector = DomainRegistry.getDomainDescriptor(entry.getElementRef()).getDomainInjectorProvider().getSequencerInjector(); - return sequencerInjector.createChildInjector(getChildInjectorModule(entry)); + return DomainRegistry.getDomainDescriptor(entry.getElementRef()).getDomainInjectorProvider() + .getSequencerInjector(getOverridesModule(entry)); } - protected Module getChildInjectorModule(GeneratorEntry entry) { + protected Module getOverridesModule(GeneratorEntry entry) { Module bridgeModule = new Module() { public void configure(Binder binder) { binder.bind(IGeneratorBridge.class).toInstance(bridge); @@ -180,7 +181,7 @@ private MessageConsole getConsole() { } } MessageConsole myConsole = new MessageConsole(SCT_GENERATOR_CONSOLE, null); - conMan.addConsoles(new IConsole[] { myConsole }); + conMan.addConsoles(new IConsole[]{myConsole}); return myConsole; } diff --git a/plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/GenericJavaBasedGenerator.java b/plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/GenericJavaBasedGenerator.java index b09071d061..0af1619f82 100644 --- a/plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/GenericJavaBasedGenerator.java +++ b/plugins/org.yakindu.sct.generator.core/src/org/yakindu/sct/generator/core/impl/GenericJavaBasedGenerator.java @@ -10,8 +10,8 @@ */ package org.yakindu.sct.generator.core.impl; -import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.OUTLET_FEATURE_TARGET_FOLDER; import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.OUTLET_FEATURE_LIBRARY_TARGET_FOLDER; +import static org.yakindu.sct.generator.core.features.ICoreFeatureConstants.OUTLET_FEATURE_TARGET_FOLDER; import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.CONFIGURATION_MODULE; import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.GENERATOR_CLASS; import static org.yakindu.sct.generator.core.features.impl.IGenericJavaFeatureConstants.GENERATOR_PROJECT; @@ -45,8 +45,8 @@ public class GenericJavaBasedGenerator extends AbstractSExecModelGenerator { @Override - protected Module getChildInjectorModule(final GeneratorEntry entry) { - Module defaultModule = super.getChildInjectorModule(entry); + protected Module getOverridesModule(final GeneratorEntry entry) { + Module defaultModule = super.getOverridesModule(entry); String overridingModuleClass = null; FeatureConfiguration featureConfiguration = entry.getFeatureConfiguration(TEMPLATE_FEATURE); diff --git a/plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/CppCodeGenerator.java b/plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/CppCodeGenerator.java index 658a0a8d9d..cc7a90fd15 100644 --- a/plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/CppCodeGenerator.java +++ b/plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/CppCodeGenerator.java @@ -43,8 +43,8 @@ public void runGenerator(Statechart statechart, GeneratorEntry entry) { } @Override - protected Module getChildInjectorModule(final GeneratorEntry entry) { - Module module = super.getChildInjectorModule(entry); + protected Module getOverridesModule(final GeneratorEntry entry) { + Module module = super.getOverridesModule(entry); return Modules.override(module).with(new Module() { public void configure(Binder binder) { binder.bind(ICodegenTypeSystemAccess.class).to( diff --git a/plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/StatemachineHeader.xtend b/plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/StatemachineHeader.xtend index 754695e9e0..e8a78168a6 100644 --- a/plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/StatemachineHeader.xtend +++ b/plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/StatemachineHeader.xtend @@ -15,7 +15,6 @@ import java.util.List import org.eclipse.xtend2.lib.StringConcatenation import org.eclipse.xtext.generator.IFileSystemAccess import org.yakindu.base.types.Direction -import org.yakindu.sct.generator.c.Statemachine import org.yakindu.sct.generator.core.types.ICodegenTypeSystemAccess import org.yakindu.sct.generator.cpp.features.GenmodelEntriesExtension import org.yakindu.sct.model.sexec.Check @@ -31,7 +30,7 @@ import org.yakindu.sct.model.stext.stext.InternalScope import org.yakindu.sct.model.stext.stext.StatechartScope import org.yakindu.sct.model.stext.stext.VariableDefinition -class StatemachineHeader extends Statemachine { +class StatemachineHeader extends org.yakindu.sct.generator.c.StatemachineHeader { @Inject extension Naming @Inject extension Navigation @@ -41,12 +40,12 @@ class StatemachineHeader extends Statemachine { protected GeneratorEntry entry - def generateStatemachineHeader(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) { + override generateStatemachineHeader(ExecutionFlow flow, Statechart sc, IFileSystemAccess fsa, GeneratorEntry entry) { this.entry = entry - fsa.generateFile(flow.module().h, flow.statemachineHContent(entry)) + fsa.generateFile(flow.module().h, flow.generateStatemachineHeaderContents(entry)) } - override statemachineHContent(ExecutionFlow it, GeneratorEntry entry) ''' + override generateStatemachineHeaderContents(ExecutionFlow it, GeneratorEntry entry) ''' «entry.licenseText» #ifndef «module().define»_H_ diff --git a/plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/features/CPPDefaultFeatureValueProvider.java b/plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/features/CPPDefaultFeatureValueProvider.java index dc9675a7a5..b27a90ad6f 100644 --- a/plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/features/CPPDefaultFeatureValueProvider.java +++ b/plugins/org.yakindu.sct.generator.cpp/src/org/yakindu/sct/generator/cpp/features/CPPDefaultFeatureValueProvider.java @@ -16,7 +16,7 @@ import org.eclipse.core.runtime.Status; import org.eclipse.emf.ecore.EObject; import org.eclipse.xtext.xbase.lib.StringExtensions; -import org.yakindu.sct.generator.c.features.CFeatureConstants; +import org.yakindu.sct.generator.c.features.ICFeatureConstants; import org.yakindu.sct.generator.core.features.AbstractDefaultFeatureValueProvider; import org.yakindu.sct.generator.cpp.features.CPPFeatureConstants.Visibility; import org.yakindu.sct.model.sgen.FeatureParameterValue; @@ -46,17 +46,17 @@ protected void setDefaultValue(FeatureParameterValue parameterValue, Statechart statechart = (Statechart) entry.getElementRef(); if (parameterValue.getParameter().getName() - .equals(CFeatureConstants.PARAMETER_MODULE_NAME)) { + .equals(ICFeatureConstants.PARAMETER_NAMING_MODULE_NAME)) { parameterValue.setValue(asIdentifier(statechart.getName(), "_")); } else if (parameterValue.getParameter().getName() - .equals(CFeatureConstants.PARAMETER_STATEMACHINE_PREFIX)) { + .equals(ICFeatureConstants.PARAMETER_NAMING_STATEMACHINE_PREFIX)) { parameterValue.setValue(StringExtensions.toFirstLower(asIdentifier( statechart.getName(), "_"))); } else if (parameterValue.getParameter().getName() - .equals(CFeatureConstants.PARAMETER_MAX_IDENTIFIER_LENGTH)) { + .equals(ICFeatureConstants.PARAMETER_NAMING_MAX_IDENTIFIER_LENGTH)) { parameterValue.setValue("31"); } else if (parameterValue.getParameter().getName() - .equals(CFeatureConstants.PARAMETER_SEPARATOR)) { + .equals(ICFeatureConstants.PARAMETER_NAMING_SEPARATOR)) { parameterValue.setValue("_"); } else if (parameterValue .getParameter() @@ -71,16 +71,16 @@ protected void setDefaultValue(FeatureParameterValue parameterValue, public IStatus validateParameterValue(FeatureParameterValue parameter) { String parameterName = parameter.getParameter().getName(); - if (CFeatureConstants.PARAMETER_MODULE_NAME.equals(parameterName)) { + if (ICFeatureConstants.PARAMETER_NAMING_MODULE_NAME.equals(parameterName)) { if (!parameter.getStringValue().matches(VALID_IDENTIFIER_REGEX)) { return error("Invalid module name"); } - } else if (CFeatureConstants.PARAMETER_STATEMACHINE_PREFIX + } else if (ICFeatureConstants.PARAMETER_NAMING_STATEMACHINE_PREFIX .equals(parameterName)) { if (!parameter.getStringValue().matches(VALID_IDENTIFIER_REGEX)) { return error("Invalid function prefix name"); } - } else if (CFeatureConstants.PARAMETER_SEPARATOR.equals(parameterName)) { + } else if (ICFeatureConstants.PARAMETER_NAMING_SEPARATOR.equals(parameterName)) { if (!parameter.getStringValue().matches(VALID_IDENTIFIER_REGEX)) { return error("Invalid separator"); } diff --git a/plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/JavaCodeGenerator.java b/plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/JavaCodeGenerator.java index 438464b7f7..7362b35387 100644 --- a/plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/JavaCodeGenerator.java +++ b/plugins/org.yakindu.sct.generator.java/src/org/yakindu/sct/generator/java/JavaCodeGenerator.java @@ -41,8 +41,8 @@ public void generate(Statechart statechart, GeneratorEntry entry) { } @Override - protected Module getChildInjectorModule(final GeneratorEntry entry) { - Module module = super.getChildInjectorModule(entry); + protected Module getOverridesModule(final GeneratorEntry entry) { + Module module = super.getOverridesModule(entry); final GenmodelEntries entries = new GenmodelEntries(); return Modules.override(module).with(new Module() { public void configure(Binder binder) { diff --git a/plugins/org.yakindu.sct.model.sexec/META-INF/MANIFEST.MF b/plugins/org.yakindu.sct.model.sexec/META-INF/MANIFEST.MF index e86308eab8..f290c41c63 100644 --- a/plugins/org.yakindu.sct.model.sexec/META-INF/MANIFEST.MF +++ b/plugins/org.yakindu.sct.model.sexec/META-INF/MANIFEST.MF @@ -13,14 +13,14 @@ Export-Package: org.yakindu.sct.model.sexec, org.yakindu.sct.model.sexec.naming, org.yakindu.sct.model.sexec.transformation, org.yakindu.sct.model.sexec.util -Require-Bundle: org.eclipse.core.runtime, +Require-Bundle: com.google.inject, + org.eclipse.core.runtime, org.eclipse.emf.ecore;visibility:=reexport, - org.yakindu.sct.model.sgraph;visibility:=reexport, - org.yakindu.base.types;visibility:=reexport, - org.yakindu.base.expressions;visibility:=reexport, - com.google.inject, org.eclipse.xtext.xbase.lib, + org.eclipse.xtend.lib;bundle-version="2.3.0", org.eclipse.xtext, + org.yakindu.base.types;visibility:=reexport, + org.yakindu.base.expressions;visibility:=reexport, org.yakindu.sct.model.stext, - org.eclipse.xtend.lib;bundle-version="2.3.0" + org.yakindu.sct.model.sgraph;visibility:=reexport Bundle-ActivationPolicy: lazy diff --git a/plugins/org.yakindu.sct.model.sexec/src/org/yakindu/sct/model/sexec/transformation/SequenceBuilder.xtend b/plugins/org.yakindu.sct.model.sexec/src/org/yakindu/sct/model/sexec/transformation/SequenceBuilder.xtend index 8ebe71c3ca..4fff92d00d 100644 --- a/plugins/org.yakindu.sct.model.sexec/src/org/yakindu/sct/model/sexec/transformation/SequenceBuilder.xtend +++ b/plugins/org.yakindu.sct.model.sexec/src/org/yakindu/sct/model/sexec/transformation/SequenceBuilder.xtend @@ -18,6 +18,7 @@ import org.yakindu.base.expressions.expressions.BoolLiteral import org.yakindu.base.expressions.expressions.DoubleLiteral import org.yakindu.base.expressions.expressions.Expression import org.yakindu.base.expressions.expressions.ExpressionsFactory +import org.yakindu.base.expressions.expressions.FloatLiteral import org.yakindu.base.expressions.expressions.IntLiteral import org.yakindu.base.expressions.expressions.MultiplicativeOperator import org.yakindu.base.expressions.expressions.NumericalMultiplyDivideExpression @@ -41,7 +42,6 @@ import org.yakindu.sct.model.stext.stext.TimeUnit import org.yakindu.sct.model.stext.stext.VariableDefinition import static extension org.eclipse.emf.ecore.util.EcoreUtil.* -import org.yakindu.base.expressions.expressions.FloatLiteral class SequenceBuilder { @@ -53,7 +53,8 @@ class SequenceBuilder { @Inject extension ITypeValueProvider - @Inject @Named("ADD_TRACES") + @Inject + @Named("ADD_TRACES") boolean _addTraceSteps static String DEFAULT_SEQUENCE_NAME = "default"