Commit 7ac710ca authored by Nils Kaminski's avatar Nils Kaminski
Browse files

is_connected math command for dynamic

parent e8de8404
......@@ -55,6 +55,9 @@ public class MathCommandRegisterCPP extends MathCommandRegister {
//for fixing some errors
registerMathCommand(new MathRowCommand());
registerMathCommand(new MathColumnCommand());
//for dynamic
registerMathCommand(new DynamicMathPortIsConnectedCommand());
}
/**
......
package de.monticore.lang.monticar.generator.cpp.commands;
import de.monticore.lang.math._symboltable.expression.MathExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixAccessSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol;
import de.monticore.lang.monticar.generator.BluePrint;
import de.monticore.lang.monticar.generator.MathCommand;
import de.monticore.lang.monticar.generator.cpp.BluePrintCPP;
import de.monticore.lang.monticar.generator.cpp.MathFunctionFixer;
import de.monticore.lang.monticar.generator.cpp.converter.ExecuteMethodGenerator;
import de.monticore.lang.monticar.generator.cpp.symbols.MathStringExpression;
import de.se_rwth.commons.logging.Log;
import java.util.ArrayList;
import java.util.List;
public class DynamicMathPortIsConnectedCommand extends MathCommand {
public DynamicMathPortIsConnectedCommand() {
setMathCommandName("is_connected");
}
@Override
protected void convert(MathExpressionSymbol mathExpressionSymbol, BluePrint bluePrint) {
MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol = (MathMatrixNameExpressionSymbol) mathExpressionSymbol;
List<MathMatrixAccessSymbol> symbols = mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols();
if(symbols.size() != 2){
Log.error("Is connected wrong number of arguments! Usage for ports: isconnected(<PORT>, <INDEX>). Usage for component: isconnected(<INSTANCE>, <INDEX>)");
}
mathMatrixNameExpressionSymbol.setNameToAccess(" ");
String valueListString = "";
for (MathMatrixAccessSymbol accessSymbol : symbols)
MathFunctionFixer.fixMathFunctions(accessSymbol, (BluePrintCPP) bluePrint);
// valueListString += ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, new ArrayList<String>());
String portinstanceName = ExecuteMethodGenerator.generateExecuteCode(symbols.get(0), new ArrayList<>());
String indexCall = ExecuteMethodGenerator.generateExecuteCode(symbols.get(1), new ArrayList<>());
List<MathMatrixAccessSymbol> newMatrixAccessSymbols = new ArrayList<>();
MathStringExpression stringExpression = new MathStringExpression("__"+portinstanceName+"_connected["+indexCall+"-1]",
mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols());
newMatrixAccessSymbols.add(new MathMatrixAccessSymbol(stringExpression));
mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().setMathMatrixAccessSymbols(newMatrixAccessSymbols);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment