Commit 1826d29d authored by Sascha Niklas Schneiders's avatar Sascha Niklas Schneiders
Browse files

refactoring

parent bef0bcc4
......@@ -10,6 +10,8 @@ import de.monticore.lang.monticar.ts.references.MCASTTypeSymbolReference;
import de.monticore.lang.monticar.types2._ast.ASTType;
import de.se_rwth.commons.logging.Log;
import javax.sound.sampled.Port;
/**
* @author Sascha Schneiders
*/
......@@ -46,55 +48,59 @@ public class PortConverter {
if (variable != null&&variable.isArray())
return variable;
*/
Variable variable = new Variable();
String name = "";
String typeNameMontiCar = portSymbol.getTypeReference().getName();
if (portSymbol.getTypeReference().getReferencedSymbol() instanceof MCASTTypeSymbolReference) {
MCASTTypeSymbolReference typeSymbolReference = (MCASTTypeSymbolReference) portSymbol.getTypeReference().getReferencedSymbol();
ASTType astType = typeSymbolReference.getAstType();
if (astType instanceof ASTAssignmentType) {
ASTAssignmentType astAssignmentType = (ASTAssignmentType) astType;
//if (astAssignmentType.getMatrixProperty().size() > 0) Log.error(astType.toString());
variable.addProperties(astAssignmentType.getMatrixProperty());
}
}
if (portSymbol.isIncoming())
addVariableProperties(portSymbol, variable);
handlePortDirection(portSymbol, variable);
name += handlePortName(portSymbol, variable, connectName);
{
variable.setInputVariable(true);
} else
variable.setName(name);
variable.setVariableType(TypeConverter.getVariableTypeForMontiCarTypeName(typeNameMontiCar, variable, portSymbol).get());
variable.addAdditionalInformation(Variable.ORIGINPORT);
bluePrint.getMathInformationRegister().addVariable(variable);
{
return variable;
}
private static void handlePortDirection(PortSymbol portSymbol, Variable variable) {
if (portSymbol.isIncoming()) {
variable.setInputVariable(true);
} else {
variable.setInputVariable(false);
}
if (portSymbol.isConstant())
}
{
private static String handlePortName(PortSymbol portSymbol, Variable variable, String connectName) {
String name = "";
if (portSymbol.isConstant()) {
//name += "Constant" + ++counterConstantPorts;
name += connectName;
variable.setIsConstantVariable(true);
variable.setConstantValue(((ConstantPortSymbol) portSymbol).getConstantValue().getValueAsString());
// Log.error("0xCOPOSHNOBECRASAAVA Constant Port should not be created as a variable");
} else
{
} else {
//Log.info(portSymbol.getName(),"PORTNAME:");
name += connectName;
}
variable.setName(name);
variable.setVariableType(TypeConverter.getVariableTypeForMontiCarTypeName(typeNameMontiCar, variable, portSymbol).get());
variable.addAdditionalInformation(Variable.ORIGINPORT);
bluePrint.getMathInformationRegister().addVariable(variable);
return variable;
return name;
}
private static void addVariableProperties(PortSymbol portSymbol, Variable variable) {
if (portSymbol.getTypeReference().getReferencedSymbol() instanceof MCASTTypeSymbolReference) {
MCASTTypeSymbolReference typeSymbolReference = (MCASTTypeSymbolReference) portSymbol.getTypeReference().getReferencedSymbol();
ASTType astType = typeSymbolReference.getAstType();
if (astType instanceof ASTAssignmentType) {
ASTAssignmentType astAssignmentType = (ASTAssignmentType) astType;
//if (astAssignmentType.getMatrixProperty().size() > 0) Log.error(astType.toString());
variable.addProperties(astAssignmentType.getMatrixProperty());
}
}
}
public static String getPortNameWithoutArrayBracketPart(String name) {
String nameWithOutArrayBracketPart = name;
......
......@@ -21,7 +21,7 @@ public class MathDiagonalMatrixInversionOptimization implements MathOptimization
@Override
public void optimize(MathExpressionSymbol mathExpressionSymbol, List<MathExpressionSymbol> precedingExpressions) {
if (mathExpressionSymbol == null) {
//Do nothing
} else if (mathExpressionSymbol.isAssignmentExpression()) {
optimize((MathAssignmentExpressionSymbol) mathExpressionSymbol, precedingExpressions);
} else if (mathExpressionSymbol.isMatrixExpression()) {
......@@ -72,13 +72,7 @@ public class MathDiagonalMatrixInversionOptimization implements MathOptimization
public void optimize(MathMatrixNameExpressionSymbol mathExpressionSymbol, List<MathExpressionSymbol> precedingExpressions) {
if (mathExpressionSymbol.getNameToAccess().equals("inv")) {
//ComponentConverter.currentBluePrint.getMathInformationRegister().isDiagonalMatrix()
boolean invertsDiagonalMatrix = false;
if (mathExpressionSymbol.getAstMathMatrixNameExpression().getMathMatrixAccessExpression().isPresent()) {
//optimize(mathExpressionSymbol.getMathMatrixAccessOperatorSymbol(), precedingExpressions);
//Log.error(ComponentConverter.currentBluePrint.getMathInformationRegister().getVariable("degree").getProperties().toString());
String name = getMatrixName((MathMatrixAccessSymbol) mathExpressionSymbol.getAstMathMatrixNameExpression().getMathMatrixAccessExpression().get().getMathMatrixAccesss().get(0).getSymbol().get());//TODO handle all possible cases
invertsDiagonalMatrix = ComponentConverter.currentBluePrint.getMathInformationRegister().getVariable(name).getProperties().contains("diag");
}
boolean invertsDiagonalMatrix = invertsDiagonalMatrix();
if (invertsDiagonalMatrix) {
mathExpressionSymbol.setNameToAccess("invdiag");
}
......@@ -90,6 +84,17 @@ public class MathDiagonalMatrixInversionOptimization implements MathOptimization
Log.debug("Not handled: EndOperator", "optimizeMathMatrixNameExpr");
}
private boolean invertsDiagonalMatrix(MathMatrixNameExpressionSymbol mathExpressionSymbol) {
boolean invertsDiagonalMatrix = false;
if (mathExpressionSymbol.getAstMathMatrixNameExpression().getMathMatrixAccessExpression().isPresent()) {
//optimize(mathExpressionSymbol.getMathMatrixAccessOperatorSymbol(), precedingExpressions);
//Log.error(ComponentConverter.currentBluePrint.getMathInformationRegister().getVariable("degree").getProperties().toString());
String name = getMatrixName((MathMatrixAccessSymbol) mathExpressionSymbol.getAstMathMatrixNameExpression().getMathMatrixAccessExpression().get().getMathMatrixAccesss().get(0).getSymbol().get());//TODO handle all possible cases
invertsDiagonalMatrix = ComponentConverter.currentBluePrint.getMathInformationRegister().getVariable(name).getProperties().contains("diag");
}
return invertsDiagonalMatrix;
}
public void optimize(MathMatrixAccessOperatorSymbol mathExpressionSymbol, List<MathExpressionSymbol> precedingExpressions) {
for (MathExpressionSymbol subExpr : mathExpressionSymbol.getMathMatrixAccessSymbols()) {
optimize(subExpr, precedingExpressions);
......
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