blob: bb358909797dcf641454d6b163fb9ccbfcee0898 [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.generators;
import java.util.Arrays;
import org.eclipse.app4mc.amalthea.model.LabelAccess;
import org.eclipse.app4mc.amalthea.model.LabelAccessEnum;
import org.eclipse.app4mc.amalthea.model.LabelAccessStatistic;
import org.eclipse.app4mc.amalthea.model.MinAvgMaxStatistic;
import org.eclipse.app4mc.amalthea.model.NumericStatistic;
import org.eclipse.app4mc.amalthea.model.SingleValueStatistic;
import org.eclipse.app4mc.transformation.util.OutputBuffer;
public class LabelAccessTranslationUnit extends TranslationUnit {
public String getBasePath() {
return this.tuLabel.getBasePath();
}
public String getModuleName() {
return this.tuLabel.getModuleName();
}
public String getIncFile() {
return this.tuLabel.getIncFile();
}
@Override
public String getCall() {
String _xblockexpression = null;
{
String statString = "1";
LabelAccessStatistic _statistic = null;
if (this.labelAccess != null) {
_statistic = this.labelAccess.getStatistic();
}
NumericStatistic _value = null;
if (_statistic != null) {
_value = _statistic.getValue();
}
final NumericStatistic stat = _value;
if ((stat != null)) {
LabelAccessStatistic _statistic_1 = null;
if (this.labelAccess != null) {
_statistic_1 = this.labelAccess.getStatistic();
}
NumericStatistic _value_1 = null;
if (_statistic_1 != null) {
_value_1 = _statistic_1.getValue();
}
statString = LabelAccessTranslationUnit.getNumericStatistic(_value_1);
}
String _switchResult = null;
LabelAccessEnum _access = this.labelAccess.getAccess();
if (_access != null) {
switch (_access) {
case READ:
_switchResult = this.tuLabel.readCall(statString);
break;
case WRITE:
_switchResult = this.tuLabel.writeCall(statString);
break;
default:
String _name = this.labelAccess.getData().getName();
String _plus = ("/*underspecified access to label" + _name);
_switchResult = (_plus + "*/");
break;
}
} else {
String _name = this.labelAccess.getData().getName();
String _plus = ("/*underspecified access to label" + _name);
_switchResult = (_plus + "*/");
}
_xblockexpression = _switchResult;
}
return _xblockexpression;
}
public String getModulePath() {
return getBasePath() + "/" + getModuleName();
}
private OutputBuffer outputBuffer;
@Override
public String getSrcFile() {
return getModuleName() + ".cpp";
}
public String getIncPath() {
return getModulePath() + "/_inc/" + getIncFile();
}
public String getSrcPath() {
return getModulePath() + "/_src/" + getSrcFile();
}
public boolean isIncFileEmpty() {
return !outputBuffer.bufferExists("INC", getModulePath() + "/_inc/" + getModuleName());
}
public boolean isSrcFileEmpty() {
return !outputBuffer.bufferExists("SRC", getModulePath() + "/_src/" + getModuleName());
}
public boolean incAppend(final String str) {
return outputBuffer.appendTo("INC", getModulePath() + "/_inc/" + getModuleName(), str);
}
public boolean srcAppend(final String str) {
return outputBuffer.appendTo("SRC", getModulePath() + "/_src/" + getModuleName(), str);
}
private final LabelTranslationUnit tuLabel;
private final LabelAccess labelAccess;
public LabelAccessTranslationUnit(final OutputBuffer outputBuffer, final LabelTranslationUnit tuLabel,
final LabelAccess labelAccess) {
super();
this.tuLabel = tuLabel;
this.labelAccess = labelAccess;
this.outputBuffer = outputBuffer;
}
protected static String _getNumericStatistic(final MinAvgMaxStatistic stat) {
String _string = Integer.valueOf(Double.valueOf(Math.ceil(stat.getAvg())).intValue()).toString();
return (_string + "/*MinAvgMaxStatistic not supported yet*/");
}
protected static String _getNumericStatistic(final SingleValueStatistic stat) {
return Integer.valueOf(Double.valueOf(Math.ceil(stat.getValue())).intValue()).toString();
}
public static String getNumericStatistic(final NumericStatistic stat) {
if (stat instanceof MinAvgMaxStatistic) {
return _getNumericStatistic((MinAvgMaxStatistic) stat);
} else if (stat instanceof SingleValueStatistic) {
return _getNumericStatistic((SingleValueStatistic) stat);
} else {
throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object>asList(stat).toString());
}
}
}