| /** |
| * ******************************************************************************* |
| * Copyright (c) 2019-2020 Robert Bosch GmbH. |
| * |
| * This program and the accompanying materials are made |
| * available under the terms of the Eclipse Public License 2.0 |
| * which is available at https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Robert Bosch GmbH - initial API and implementation |
| * ******************************************************************************* |
| */ |
| |
| package org.eclipse.app4mc.amlt2systemc.m2t.transformers.sw |
| |
| import com.google.inject.Inject |
| import java.util.LinkedHashSet |
| import java.util.LinkedList |
| import org.eclipse.app4mc.amalthea.model.IActivityGraphItemContainer |
| import org.eclipse.app4mc.amlt2systemc.m2t.module.BaseTransformer |
| import org.eclipse.app4mc.amalthea.model.Group |
| import org.eclipse.app4mc.amalthea.model.ProbabilitySwitch |
| import org.eclipse.app4mc.amalthea.model.ModeSwitchEntry |
| import org.eclipse.app4mc.amalthea.model.ModeSwitchDefault |
| import org.eclipse.app4mc.amalthea.model.ActivityGraph |
| import org.eclipse.app4mc.amlt2systemc.m2t.transformers.common.ModeConditionTransformer.ModeConditionBuffer |
| |
| class IActivityGraphItemContainerTransformer extends BaseTransformer { |
| |
| @Inject ActivityGraphItemTransformer activityGraphItemTransformer |
| |
| static class ActivityGraphBuffer{ |
| val LinkedHashSet<String> activityItemIncludes |
| val LinkedList<String> activityItemCalls |
| public val String module |
| public val String instanceName |
| public val boolean parentIsPointer |
| |
| new(String _name, String _module, boolean _parentIsPointer){ |
| instanceName =_name |
| module= _module |
| parentIsPointer = _parentIsPointer |
| activityItemIncludes = new LinkedHashSet<String> |
| activityItemCalls = new LinkedList<String>() |
| } |
| |
| |
| new(ActivityGraphBuffer other){ |
| instanceName = other.instanceName |
| module = other.module |
| parentIsPointer = other.parentIsPointer |
| activityItemIncludes = other.activityItemIncludes |
| activityItemCalls = other.activityItemCalls |
| } |
| |
| def addAll(ActivityGraphBuffer other){ |
| activityItemIncludes.addAll(other.activityItemIncludes) |
| activityItemCalls.addAll(other.activityItemCalls) |
| } |
| |
| def addAll(ModeConditionBuffer other){ |
| if (other !== null){ |
| activityItemIncludes.addAll(other.includes) |
| activityItemCalls.addAll(0, other.conditions) //prepend conditions for readability |
| } |
| } |
| |
| def LinkedHashSet<String> getIncludes(){ |
| return activityItemIncludes |
| } |
| |
| def LinkedList<String> getSource(){ |
| return activityItemCalls |
| } |
| |
| def void addInclude(String includePath){ |
| activityItemIncludes.add("#include \"" + includePath + ".h\"") |
| } |
| |
| def void addAsActivityGraphItem(String itemConstructor){ |
| if (parentIsPointer) |
| activityItemCalls.add(instanceName + "->addActivityGraphItem" + itemConstructor + ";") |
| else |
| activityItemCalls.add(instanceName + ".addActivityGraphItem" + itemConstructor + ";") |
| } |
| |
| |
| def void addBody(String body){ |
| activityItemCalls.add(body) |
| } |
| |
| } |
| |
| protected def ActivityGraphBuffer transformItems(IActivityGraphItemContainer container, String parentInstanceName, String parentModule, boolean parentIsPointer){ |
| val containerContent = new ActivityGraphBuffer(parentInstanceName, parentModule, parentIsPointer) |
| if (container === null){ |
| return containerContent |
| } |
| //run through items |
| container.items.forEach [ item | { |
| if (item instanceof IActivityGraphItemContainer) { |
| //if the activity item is a activity item container contained in a activity item (e.g. Group within a Group) |
| //run recursively |
| containerContent.addBody(item.addCommentForNestedContainer()) |
| containerContent.addAll(transformItems(item, parentInstanceName, parentModule, containerContent.parentIsPointer)) |
| } else { |
| activityGraphItemTransformer.transform(item, containerContent) |
| } |
| }] |
| return containerContent |
| } |
| |
| private def addCommentForNestedContainer(IActivityGraphItemContainer item){ |
| if (item instanceof Group){ |
| return "/*---- Group: " + item.name + "----*/" |
| } |
| if (item instanceof ProbabilitySwitch){ |
| return "/*---- ProbabilitySwitch ----*/" |
| } |
| if (item instanceof ModeSwitchEntry){ |
| return "/*---- ModeSwitchEntry ----*/" |
| } |
| if (item instanceof ModeSwitchDefault){ |
| return "/*---- ModeSwitchDefault ----*/" |
| } |
| if (item instanceof ActivityGraph){ |
| return "/*---- ActivityGraph ----*/" |
| } |
| } |
| |
| } |