Commit a4b10e5b authored by Christoph Richter's avatar Christoph Richter
Browse files

ExecuteMethodGenerator: Implemented Chain-of-responsibility pattern

parent 7b56792f
package de.monticore.lang.monticar.generator.cpp.converter;
import de.monticore.lang.math._symboltable.expression.MathExpressionSymbol;
import de.se_rwth.commons.logging.Log;
import java.util.List;
public abstract class BaseExecuteMethodGeneratorHandler {
private BaseExecuteMethodGeneratorHandler successor = null;
public BaseExecuteMethodGeneratorHandler getSuccessor() {
return successor;
}
public void setSuccessor(BaseExecuteMethodGeneratorHandler successor) {
this.successor = successor;
}
protected abstract boolean canHandleSymbol(MathExpressionSymbol symbol);
protected abstract String doGenerateExecuteCode(MathExpressionSymbol symbol, List<String> includeStrings);
public abstract String getRole();
public String handleGenerateExecuteCode(MathExpressionSymbol symbol, List<String> includeStrings) {
String result = "";
if (canHandleSymbol(symbol)) {
result = doGenerateExecuteCode(symbol, includeStrings);
} else if (successor != null) {
result = successor.handleGenerateExecuteCode(symbol, includeStrings);
} else {
Log.info(symbol.getTextualRepresentation(), "Symbol:");
Log.debug(getRole(), "Case not handled!");
}
return result;
}
}
package de.monticore.lang.monticar.generator.cpp.converter;
import de.monticore.lang.math._symboltable.MathForLoopHeadSymbol;
import de.monticore.lang.math._symboltable.expression.*;
import de.monticore.lang.math._symboltable.matrix.*;
import de.monticore.lang.monticar.generator.Variable;
import de.monticore.lang.monticar.generator.cpp.MathFunctionFixer;
import de.monticore.lang.monticar.generator.cpp.OctaveHelper;
import de.monticore.lang.math._symboltable.matrix.MathMatrixAccessOperatorSymbol;
import de.monticore.lang.math._symboltable.matrix.MathMatrixExpressionSymbol;
import de.monticore.lang.monticar.generator.cpp.symbols.MathChainedExpression;
import de.monticore.lang.monticar.generator.cpp.symbols.MathStringExpression;
import de.se_rwth.commons.logging.Log;
import java.util.ArrayList;
import java.util.List;
/**
* @author Sascha Schneiders
*/
public class ExecuteMethodGenerator {
public static String generateExecuteCode(MathExpressionSymbol mathExpressionSymbol, List<String> includeStrings) {
public class ExecuteMethodGenerator extends BaseExecuteMethodGeneratorHandler {
private static ExecuteMethodGenerator ourInstance = new ExecuteMethodGenerator();
public static ExecuteMethodGenerator getInstance() {
return ourInstance;
}
private ExecuteMethodGenerator() {
}
@Override
public String getRole() {
return "ExecuteMethodGenerator";
}
@Override
protected boolean canHandleSymbol(MathExpressionSymbol mathExpressionSymbol) {
boolean canHandle = false;
if (mathExpressionSymbol == null
|| mathExpressionSymbol.isAssignmentExpression()
|| mathExpressionSymbol.isCompareExpression()
|| mathExpressionSymbol.isForLoopExpression()
|| mathExpressionSymbol.isMatrixExpression()
|| mathExpressionSymbol.isConditionalsExpression()
|| mathExpressionSymbol.isConditionalExpression()
|| mathExpressionSymbol.isArithmeticExpression()
|| mathExpressionSymbol.isValueExpression()
|| mathExpressionSymbol.isMathValueTypeExpression()
|| mathExpressionSymbol.isPreOperatorExpression()
|| (mathExpressionSymbol.getExpressionID() == MathStringExpression.ID)
|| (mathExpressionSymbol.getExpressionID() == MathChainedExpression.ID)
|| mathExpressionSymbol.isParenthesisExpression()) {
canHandle = true;
}
return canHandle;
}
protected String doGenerateExecuteCode(MathExpressionSymbol mathExpressionSymbol, List<String> includeStrings) {
String result = null;
//Not needed for execute method
/*if (mathExpressionSymbol.isAssignmentDeclarationExpression()) {
......@@ -63,6 +96,10 @@ public class ExecuteMethodGenerator {
return result;
}
public static String generateExecuteCode(MathExpressionSymbol mathExpressionSymbol, List<String> includeStrings) {
return getInstance().handleGenerateExecuteCode(mathExpressionSymbol, includeStrings);
}
/**
* Returns correct string for generation of matrix/array access
*
......
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