blob: 85e5e2c5abd53adf8ab5b84065f3c58cfccbc927 [file] [log] [blame]
/**
* *******************************************************************************
* Copyright (c) 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.slg.commons.m2t.transformers
import com.google.inject.Inject
import com.google.inject.Singleton
import java.util.LinkedHashSet
import org.eclipse.app4mc.amalthea.model.Component
import org.eclipse.app4mc.amalthea.model.Group
import org.eclipse.app4mc.slg.commons.m2t.generators.TranslationUnit
import org.eclipse.app4mc.transformation.util.OutputBuffer
@Singleton
class GroupHeaderTransformer extends ActivityGraphItemTransformer {
@Inject OutputBuffer outputBuffer
@Inject ActivityGraphItemTransformer psCallGraphItemTransformer
static def getModuleName(Group group) {
return "groups"
}
static def getFunctionDef(Group group) {
return "group_" + group.name + "()"
}
def create new TranslationUnit()
transform(Group group, Component component) {
it.path = GroupHeaderTransformer.getModuleName(group)
it.call = GroupHeaderTransformer.getFunctionDef(group)
val groupItemIncludes = new LinkedHashSet<String>
val groupItemCalls = new LinkedHashSet<String>
group?.items.forEach [ item |
val tmp = psCallGraphItemTransformer.transform(item)
if (!tmp.extendedIncPath.isNullOrEmpty && !(it.extendedIncPath.equals(tmp.extendedIncPath)))
groupItemIncludes.add(tmp.extendedIncPath)
if (!tmp.call.isNullOrEmpty)
groupItemCalls.add(tmp.call)
]
// remove file extension
val index = it.extendedIncPath.lastIndexOf('.')
val trimmedIncPath = it.extendedIncPath.substring(0, index)
outputBuffer.appendTo("INC", trimmedIncPath, "\n//Group " + group.name + "----\n")
groupItemIncludes.forEach [ include |
outputBuffer.appendTo("INC", trimmedIncPath, "#include \"" + include + ".h\"\n")
]
outputBuffer.appendTo("INC", trimmedIncPath, "void " + it.call + ";\n")
}
}