blob: c32a9d04725840ed6982e75046f392362dc6e079 [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.sw
import com.google.inject.Inject
import com.google.inject.Singleton
import java.util.LinkedList
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 GroupSourceTransformer extends ActivityGraphItemTransformer {
@Inject OutputBuffer outputBuffer
@Inject ActivityGraphItemTransformer psCallGraphItemTransformer
def create new TranslationUnit()
transform(Group group, Component component) {
it.path = GroupHeaderTransformer.getModuleName(group)
it.call = GroupHeaderTransformer.getFunctionDef(group)
val groupItemIncludes = new LinkedList<String>
val groupItemCalls = new LinkedList<String>
group?.items.forEach [ item |
val tmp = psCallGraphItemTransformer.transform(item)
if (!tmp.path.isNullOrEmpty)
groupItemIncludes.add(tmp.path)
if (!tmp.call.isNullOrEmpty)
groupItemCalls.add(tmp.call)
]
// remove file extension
val index = it.extendedSrcPath.lastIndexOf('.')
val trimmedSrcPath = it.extendedSrcPath.substring(0, index)
outputBuffer.appendTo("SRC", trimmedSrcPath, "\n//Group " + group.name + "----\n")
groupItemIncludes.forEach [ include |
outputBuffer.appendTo("SRC", trimmedSrcPath, "#include \"" + include + ".h\"\n")
]
// write group body
outputBuffer.appendTo("SRC", trimmedSrcPath, "void " + it.call + "{\n")
groupItemCalls.forEach [ call |
outputBuffer.appendTo("SRC", trimmedSrcPath, call + ";\n")
]
outputBuffer.appendTo("SRC", trimmedSrcPath, "}")
}
}