Commit 7b6ee58a authored by Ahmed's avatar Ahmed

Storing pre- and suc-Properties for MathExpressionSymbols

parent 17554220
......@@ -19,13 +19,21 @@ import java.util.List;
*/
public class MathExpressionProperties {
public Level pre = Level.ARMA;
public Level succ = Level.ARMA;
public Level suc = Level.ARMA;
enum Level {
CV,
ARMA
}
public void setPreToCV(){
this.pre = Level.CV;
}
public void setSucToCV(){
this.suc = Level.CV;
}
/*public MathExpressionProperties(String name) {
(name);
}*/
......
......@@ -33,6 +33,7 @@ public class ComponentConverter {
public static BluePrintCPP currentBluePrint = null;
public static List<String> namesOfFunctions = new ArrayList<>();
public static List<MathCommand> usedMathCommand = new ArrayList<>();
public static HashMap<MathExpressionSymbol, MathExpressionProperties> tuples = new HashMap<MathExpressionSymbol, MathExpressionProperties>();
public static BluePrint convertComponentSymbolToBluePrint(EMAComponentInstanceSymbol componentSymbol, MathStatementsSymbol mathStatementsSymbol, List<String> includeStrings, GeneratorCPP generatorCPP) {
BluePrintCPP bluePrint = new BluePrintCPP(GeneralHelperMethods.getTargetLanguageComponentName(componentSymbol.getFullName()));
......@@ -66,18 +67,20 @@ public class ComponentConverter {
MathInformationFilter.filterStaticInformation(componentSymbol, bluePrint, mathStatementsSymbol, generatorCPP, includeStrings);
//save function name
if(mathStatementsSymbol != null) {
HashMap<MathExpressionSymbol, MathExpressionProperties> tuples = new HashMap<MathExpressionSymbol, MathExpressionProperties>();
List<MathExpressionSymbol> mathExpressionSymbols = mathStatementsSymbol.getMathExpressionSymbols();
for(MathExpressionSymbol mathExpressionSymbol : mathExpressionSymbols){
String nameOfFunction = getNameOfMathCommand(mathExpressionSymbol);
namesOfFunctions.add(nameOfFunction);
fixFunctionTypes(nameOfFunction, mathExpressionSymbol, bluePrint);
}
for(MathExpressionSymbol mathExpressionSymbol : mathExpressionSymbols){
//MathExpressionProperties properties = new MathExpressionProperties();
//setPropertiesForMathExpression(mathExpressionSymbol, properties);
//tuples.put(mathExpressionSymbol, );
if(mathExpressionSymbols.size() > 1) {
for (MathExpressionSymbol mathExpressionSymbol : mathExpressionSymbols) {
MathExpressionProperties properties = new MathExpressionProperties();
MathConverter.setPropertiesForMathExpression(mathExpressionSymbols, mathExpressionSymbol, bluePrint, properties);
ComponentConverter.tuples.put(mathExpressionSymbol, properties);
}
}
}
if(namesOfFunctions != null) {
......@@ -86,11 +89,6 @@ public class ComponentConverter {
}
}
if(mathStatementsSymbol != null){
//handleDependenceOfCVCommands(mathStatementsSymbol, BluePrintCPP bluePrint);
}
//ToDo: add a BluePrintFixer.fixerBluePrintCVfuncitons(bluePrint, nameOfFunction);
generateInitMethod(componentSymbol, bluePrint, generatorCPP, includeStrings);
//generate execute method
......@@ -320,27 +318,6 @@ public class ComponentConverter {
initLine.ifPresent(s -> method.addInstruction(new TargetCodeInstruction(s)));
}
}
//TODO: Try to modify this Method
public static void handleDependenceOfCVCommands(MathStatementsSymbol mathStatementsSymbol, BluePrintCPP bluePrint) {
List<MathExpressionSymbol> mathExpressionSymbols = mathStatementsSymbol.getMathExpressionSymbols();
int mathExpressionSymbolsSize = mathExpressionSymbols.size();
if (mathExpressionSymbolsSize > 1) {
for (int i = 0; i < mathExpressionSymbols.size(); i++) {
String nameOfMathCommand = getNameOfMathCommand(mathExpressionSymbols.get(i));
MathCommand mathCommand = bluePrint.getMathCommandRegister().getMathCommand(nameOfMathCommand);
if(mathCommand != null && mathCommand.isCVMathCommand()){
for (int j = i + 1; j < mathExpressionSymbols.size(); j++) {
String nameOfSucMathCommand = getNameOfMathCommand(mathExpressionSymbols.get(j));
MathCommand sucMathCommand = bluePrint.getMathCommandRegister().getMathCommand(nameOfSucMathCommand);
if(mathCommand != null && mathCommand.isCVMathCommand()){
}
}
}
}
}
}
public static String getNameOfMathCommand(MathExpressionSymbol mathExpressionSymbol){
String nameOfFunction = "";
......
......@@ -3,18 +3,19 @@ package de.monticore.lang.monticar.generator.cpp.converter;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAPortSymbol;
import de.monticore.lang.math._symboltable.expression.MathAssignmentExpressionSymbol;
import de.monticore.lang.math._symboltable.expression.MathExpressionSymbol;
import de.monticore.lang.math._symboltable.matrix.*;
import de.monticore.lang.monticar.generator.MathBackend;
import de.monticore.lang.monticar.generator.TargetCodeInstruction;
import de.monticore.lang.monticar.generator.Variable;
import de.monticore.lang.monticar.generator.*;
import de.monticore.lang.monticar.generator.cpp.BluePrintCPP;
import de.monticore.lang.monticar.generator.cpp.MathExpressionProperties;
import de.monticore.lang.monticar.generator.cpp.OctaveBackend;
import de.monticore.lang.monticar.generator.optimization.MathInformationRegister;
import de.monticore.numberunit._ast.ASTNumberWithUnit;
import de.se_rwth.commons.logging.Log;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
......@@ -180,4 +181,54 @@ public class MathConverter {
return Optional.ofNullable(initLine);
}
public static void setPropertiesForMathExpression(List<MathExpressionSymbol> mathExpressionSymbols, MathExpressionSymbol mathExpressionSymbol, BluePrintCPP bluePrint, MathExpressionProperties properties){
String nameOfFunction = ComponentConverter.getNameOfMathCommand(mathExpressionSymbol);
MathCommand currentCommand = bluePrint.getMathCommandRegister().getMathCommand(nameOfFunction);
int indexOfCurrentMathExpression = mathExpressionSymbols.indexOf(mathExpressionSymbol);
if(currentCommand != null && currentCommand.isCVMathCommand()) {
setPrePropertyForMathExpression(mathExpressionSymbols,mathExpressionSymbol, bluePrint, indexOfCurrentMathExpression, properties);
setSucPropertyForMathExpression(mathExpressionSymbols, mathExpressionSymbol, bluePrint, indexOfCurrentMathExpression, properties);
}
}
public static void setPrePropertyForMathExpression(List<MathExpressionSymbol> mathExpressionSymbols, MathExpressionSymbol currentMathExpressionSymbol, BluePrintCPP bluePrint, int currentMathExpressionIndex, MathExpressionProperties properties){
for (int i = 0; i < currentMathExpressionIndex; i++) {
MathExpressionSymbol preMathExpressionSymbol = mathExpressionSymbols.get(i);
String nameOfMathCommand = ComponentConverter.getNameOfMathCommand(preMathExpressionSymbol);
MathCommand mathCommand = bluePrint.getMathCommandRegister().getMathCommand(nameOfMathCommand);
if(mathCommand != null && mathCommand.isCVMathCommand()){
if(dependenceExists(preMathExpressionSymbol, currentMathExpressionSymbol)){
properties.setPreToCV();
}
}
}
}
public static void setSucPropertyForMathExpression(List<MathExpressionSymbol> mathExpressionSymbols, MathExpressionSymbol currentMathExpressionSymbol, BluePrintCPP bluePrint, int currentMathExpressionIndex, MathExpressionProperties properties){
int endIndex = mathExpressionSymbols.size();
for (int i = currentMathExpressionIndex + 1; i < endIndex; i++) {
MathExpressionSymbol sucMathExpressionSymbol = mathExpressionSymbols.get(i);
String nameOfMathCommand = ComponentConverter.getNameOfMathCommand(sucMathExpressionSymbol);
MathCommand mathCommand = bluePrint.getMathCommandRegister().getMathCommand(nameOfMathCommand);
if(mathCommand != null && mathCommand.isCVMathCommand()){
if(dependenceExists(currentMathExpressionSymbol, sucMathExpressionSymbol)){
properties.setSucToCV();
}
}
}
}
public static boolean dependenceExists(MathExpressionSymbol preMathExpressionSymbol, MathExpressionSymbol sucMathExpressionSymbol){
String outputOfPre = ComponentConverter.getNameOfOutput(preMathExpressionSymbol);
MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol = (MathMatrixNameExpressionSymbol) ((MathAssignmentExpressionSymbol) sucMathExpressionSymbol).getExpressionSymbol();
for (MathMatrixAccessSymbol accessSymbol : mathMatrixNameExpressionSymbol.getMathMatrixAccessOperatorSymbol().getMathMatrixAccessSymbols()){
String parameterName = accessSymbol.getTextualRepresentation();
if(outputOfPre.equals(parameterName)){
return true;
}
}
return false;
}
}
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