Commit d147eb5f authored by Ahmed's avatar Ahmed

enable the argumentReturnCommand representation

parent 16decf01
......@@ -18,29 +18,19 @@ public abstract class MathCommandRegister {
public void registerMathCommand(MathCommand mathCommand) {
mathCommands.add(mathCommand);
}
public void registerMathCommand(ArgumentReturnMathCommand argumentReturnMathCommand){
mathCommands.add(argumentReturnMathCommand);
argumentReturnMathCommands.add(argumentReturnMathCommand);
if(mathCommand.isArgumentReturnMathCommand()){
argumentReturnMathCommands.add((ArgumentReturnMathCommand) mathCommand);
}
}
public MathCommand getMathCommand(String functionName) {
for (MathCommand mathCommand : mathCommands) {
if (mathCommand.getMathCommandName().equals(functionName))
if(mathCommand.isArgumentReturnMathCommand()){
return getArgumentReturnMathCommand(mathCommand);
} else {
return mathCommand;
}
}
return null;
}
public ArgumentReturnMathCommand getArgumentReturnMathCommand(MathCommand mathCommand){
return (ArgumentReturnMathCommand) mathCommand;
}
public boolean isMathCommand(String functionName) {
boolean isMathCommand = false;
if (getMathCommand(functionName) != null) {
......
......@@ -9,6 +9,7 @@ import de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol
import de.monticore.lang.monticar.generator.*;
import de.monticore.lang.monticar.generator.cpp.converter.ComponentConverter;
import de.monticore.lang.monticar.generator.cpp.converter.MathConverter;
import de.monticore.lang.monticar.generator.MathCommand;
import de.monticore.lang.monticar.generator.cpp.instruction.ConnectInstructionCPP;
import de.monticore.lang.monticar.generator.cpp.template.AllTemplates;
import de.monticore.lang.monticar.generator.cpp.viewmodel.LoggingViewModel;
......@@ -74,6 +75,7 @@ public class LanguageUnitCPP extends LanguageUnit {
}
public String getGeneratedHeader(TaggingResolver taggingResolver, BluePrintCPP bluePrint) {
MathCommand mathCommand = bluePrint.getMathCommandRegister().getMathCommand(ComponentConverter.nameOfFunction);
ExecutionOrderFixer.fixExecutionOrder(taggingResolver, bluePrint, (GeneratorCPP) bluePrint.getGenerator());
String nameOfFunction = ComponentConverter.nameOfFunction;
String resultString = "";
......
......@@ -9,6 +9,7 @@ import de.monticore.lang.embeddedmontiarcdynamic.embeddedmontiarcdynamic._symbol
import de.monticore.lang.math._symboltable.MathStatementsSymbol;
import de.monticore.lang.math._symboltable.expression.MathAssignmentExpressionSymbol;
import de.monticore.lang.math._symboltable.expression.MathExpressionSymbol;
import de.monticore.lang.math._symboltable.expression.MathValueSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixArithmeticValueSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol;
......@@ -31,6 +32,7 @@ public class ComponentConverter {
public static BluePrintCPP currentBluePrint = null;
public static String nameOfFunction = "";
public static MathCommand usedMathCommand = null;
public static BluePrint convertComponentSymbolToBluePrint(EMAComponentInstanceSymbol componentSymbol, MathStatementsSymbol mathStatementsSymbol, List<String> includeStrings, GeneratorCPP generatorCPP) {
BluePrintCPP bluePrint = new BluePrintCPP(GeneralHelperMethods.getTargetLanguageComponentName(componentSymbol.getFullName()));
......@@ -38,8 +40,9 @@ public class ComponentConverter {
bluePrint.setGenerator(generatorCPP);
bluePrint.setOriginalSymbol(componentSymbol);
bluePrint.addDefineGenerics(componentSymbol);
// Hint: the variables will be added here to the BluePrint
addVariables(componentSymbol, bluePrint);
// ToDo: you can fix the variables type here or later, so before it will be used
BluePrintFixer.fixBluePrintDynamicVariableConnectRequestQueues(bluePrint);
......@@ -65,12 +68,21 @@ public class ComponentConverter {
MathInformationFilter.filterStaticInformation(componentSymbol, bluePrint, mathStatementsSymbol, generatorCPP, includeStrings);
//save function name
if(mathStatementsSymbol != null) {
if (mathStatementsSymbol.getMathExpressionSymbols().get(0) instanceof MathAssignmentExpressionSymbol) {
if (mathStatementsSymbol.getMathExpressionSymbols().get(0).isAssignmentExpression()) {
if (((MathAssignmentExpressionSymbol) mathStatementsSymbol.getMathExpressionSymbols().get(0)).getExpressionSymbol() instanceof MathMatrixNameExpressionSymbol) {
nameOfFunction = ((MathMatrixNameExpressionSymbol) ((MathAssignmentExpressionSymbol) mathStatementsSymbol.getMathExpressionSymbols().get(0)).getExpressionSymbol()).getNameToAccess();
}
} else if(mathStatementsSymbol.getMathExpressionSymbols().get(0).isValueExpression()){
if(((MathValueSymbol) mathStatementsSymbol.getMathExpressionSymbols().get(0)).getValue() instanceof MathMatrixNameExpressionSymbol){
nameOfFunction = ((MathMatrixNameExpressionSymbol)((MathValueSymbol) mathStatementsSymbol.getMathExpressionSymbols().get(0)).getValue()).getNameToAccess();
}
}
}
if(nameOfFunction != "") {
usedMathCommand = bluePrint.getMathCommandRegister().getMathCommand(nameOfFunction);
}
//ToDo: add a BluePrintFixer.fixerBluePrintCVfuncitons(bluePrint, nameOfFunction);
generateInitMethod(componentSymbol, bluePrint, generatorCPP, includeStrings);
......@@ -286,7 +298,7 @@ public class ComponentConverter {
if(v.isParameterVariable()){
method.addInstruction(new TargetCodeInstruction("this->" + MathInformationRegister.getVariableInitName(v, bluePrint) + "=" + MathInformationRegister.getVariableInitName(v, bluePrint) + ";\n"));
method.addParameter(v);
}else {
}else {//ToDo: inside getInitLine you can add your configuration for another represetation
Optional<String> initLine = MathConverter.getInitLine(v, bluePrint);
initLine.ifPresent(s -> method.addInstruction(new TargetCodeInstruction(s)));
}
......
......@@ -138,6 +138,8 @@ public class ComponentConverterMethodGeneration {
}
generateInstruction(method, mathExpressionSymbol, bluePrint, includeStrings);
//lastIndex = currentGenerationIndex;
//fix argumentReturnFunctionsInstructions
}
handleInstructionReOrdering(method, beginIndex);
}
......@@ -192,6 +194,11 @@ public class ComponentConverterMethodGeneration {
mathExpressionSymbol, BluePrintCPP bluePrint, List<String> includeStrings/*, int lastIndex*/) {
MathFunctionFixer.fixMathFunctions(mathExpressionSymbol, bluePrint);
String result = ExecuteMethodGenerator.generateExecuteCode(mathExpressionSymbol, includeStrings);
if(ComponentConverter.usedMathCommand != null) {
if (ComponentConverter.usedMathCommand.isArgumentReturnMathCommand()) {
result = fixArgumentReturnInstruction(result, method, mathExpressionSymbol, bluePrint);
}
}
TargetCodeMathInstruction instruction = new TargetCodeMathInstruction(result, mathExpressionSymbol);
Log.info(mathExpressionSymbol.getClass().getName() + " " + mathExpressionSymbol.getTextualRepresentation(), "GenerateSymbol:");
if (mathExpressionSymbol instanceof MathValueSymbol) {
......@@ -334,4 +341,36 @@ public class ComponentConverterMethodGeneration {
}
if (beginIndex != currentGenerationIndex) swapNextInstructions = true;
}
private static String fixArgumentReturnInstruction(String instruction, Method method, MathExpressionSymbol mathExpressionSymbol, BluePrintCPP bluePrintCPP){
String newInstruction = "";
if(instruction.contains("=")){
int indexOfEqualOperator = instruction.indexOf("=");
String beforeEqualOperatorSubString = instruction.substring(0,indexOfEqualOperator-1);
String afterEqualOperatorSubString = instruction.substring(indexOfEqualOperator+2);
if(afterEqualOperatorSubString.contains(",")){
int indexOfCommaOperator = afterEqualOperatorSubString.indexOf(",");
newInstruction = afterEqualOperatorSubString.substring(0,indexOfCommaOperator) + ", " + beforeEqualOperatorSubString +
afterEqualOperatorSubString.substring(indexOfCommaOperator);
}else{
int indexOfBracket = afterEqualOperatorSubString.indexOf(")");
newInstruction = afterEqualOperatorSubString.substring(0,indexOfBracket) + ", " + beforeEqualOperatorSubString +
afterEqualOperatorSubString.substring(indexOfBracket);
}
newInstruction = removeBracket(newInstruction);
return newInstruction;
}
return instruction;
}
private static String removeBracket(String instruction){
String newInstruction = "";
if(instruction.indexOf("(") == 0){
int indexOfLastBracket = instruction.lastIndexOf(")");
newInstruction = instruction.substring(1,indexOfLastBracket) + instruction.substring(indexOfLastBracket+1);
return newInstruction;
}
return instruction;
}
}
......@@ -218,8 +218,6 @@ public class ArmadilloFunctionTest extends AbstractSymtabTest {
testMathCommand("min");
}
// Adding CV tests
@Test
......
......@@ -18,7 +18,7 @@ arrayOut=mat(n,m);
}
void execute()
{
arrayOut = (erode(arrayIn));
erode(arrayIn, arrayOut);
}
};
......
Markdown is supported
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