| /** |
| * 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.generators; |
| |
| import org.eclipse.app4mc.slg.config.ConfigModel; |
| import org.eclipse.app4mc.transformation.util.OutputBuffer; |
| import org.eclipse.xtend2.lib.StringConcatenation; |
| import org.eclipse.xtext.xbase.lib.Conversions; |
| import org.eclipse.xtext.xbase.lib.IterableExtensions; |
| |
| public class TicksUtilsTranslationUnit extends TranslationUnit { |
| public static String getModulePathStatic() { |
| return "synthetic_gen" + "/" + getModuleNameStatic(); |
| } |
| |
| public static String getMakeFilePathStatic() { |
| return getModulePathStatic() + "/" + "CMakeLists.txt"; |
| } |
| |
| public static String getModuleNameStatic() { |
| return "ticksUtils"; |
| } |
| |
| public static String getLibName() { |
| return "TICKS_UTILS"; |
| } |
| |
| public String getModuleName() { |
| return TicksUtilsTranslationUnit.getModuleNameStatic(); |
| } |
| |
| public CharSequence getExecCall(final String params) { |
| StringConcatenation _builder = new StringConcatenation(); |
| _builder.append("executeTicks_"); |
| String _last = IterableExtensions |
| .<String>last(((Iterable<String>) Conversions.doWrapArray(this.valueClass.toString().split("\\.")))); |
| _builder.append(_last); |
| _builder.append("("); |
| _builder.append(params); |
| _builder.append(")"); |
| return _builder; |
| } |
| |
| public String getIncFile() { |
| return this.getModuleName() + ".h"; |
| } |
| |
| private final ConfigModel configModel; |
| |
| private final Object valueClass; |
| |
| private OutputBuffer outputBuffer; |
| |
| public TicksUtilsTranslationUnit(final OutputBuffer outputBuffer, final ConfigModel configModel, |
| final Object valueClass) { |
| super(); |
| this.configModel = configModel; |
| this.valueClass = valueClass; |
| this.outputBuffer = outputBuffer; |
| this.genFiles(); |
| } |
| |
| public void genFiles() { |
| |
| if (this.isIncFileEmpty()) { |
| this.toH(); |
| } |
| if (this.isSrcFileEmpty()) { |
| this.toCPP(); |
| } |
| srcAppend(TicksUtilsGenerator.generateTicks(valueClass)); |
| incAppend(TicksUtilsGenerator.generateTicksDeclaration(valueClass)); |
| } |
| |
| private void toCPP() { |
| srcAppend("#include \"" + getIncFile() + "\"\n"); |
| |
| final String ticksCodeSnippet = configModel.getCustomTickImpl().getValue(); |
| final boolean ticksCodeEnabled = configModel.getCustomTickImpl().isEnable(); |
| |
| final String burnTicksBody = ticksCodeEnabled ? ticksCodeSnippet : TicksUtilsGenerator.burnTicksDefault(); |
| |
| srcAppend(TicksUtilsGenerator.burnTicks(burnTicksBody)); |
| srcAppend(TicksUtilsGenerator.burnTicksStatistics(configModel)); |
| } |
| |
| private void toH() { |
| |
| incAppend(TicksUtilsGenerator.burnTicksDeclaration()); |
| incAppend(TicksUtilsGenerator.burnTicksStatisticsDeclaration()); |
| |
| } |
| |
| public String getBasePath() { |
| return "synthetic_gen"; |
| } |
| |
| public String getModulePath() { |
| return this.getBasePath() + "/" + this.getModuleName(); |
| } |
| |
| @Override |
| public String getSrcFile() { |
| return this.getModuleName() + ".cpp"; |
| } |
| |
| public String getIncPath() { |
| return this.getModulePath() + "/_inc/" + this.getIncFile(); |
| } |
| |
| public String getSrcPath() { |
| return this.getModulePath() + "/_src/" + this.getSrcFile(); |
| } |
| |
| public boolean isIncFileEmpty() { |
| return !this.outputBuffer.bufferExists("INC", this.getModulePath() + "/_inc/" + this.getModuleName()); |
| } |
| |
| public boolean isSrcFileEmpty() { |
| return !this.outputBuffer.bufferExists("SRC", this.getModulePath() + "/_src/" + this.getModuleName()); |
| } |
| |
| public boolean incAppend(final String str) { |
| return this.outputBuffer.appendTo("INC", ((this.getModulePath() + "/_inc/") + this.getModuleName()), str); |
| } |
| |
| public boolean srcAppend(final String str) { |
| return this.outputBuffer.appendTo("SRC", ((this.getModulePath() + "/_src/") + this.getModuleName()), str); |
| } |
| } |