Commit 61681c90 authored by Malte Heithoff's avatar Malte Heithoff
Browse files

Add Loop Solver Code generation

parent dd91538e
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.monticar.generator.cpp;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarcmath._symboltable.math.symbols.EMAMSpecificationSymbol;
import de.monticore.lang.math._symboltable.expression.MathExpressionSymbol;
import de.monticore.lang.monticar.generator.*;
import de.monticore.lang.monticar.generator.cpp.loopSolver.CPPEquationSystemHelper;
import de.monticore.lang.monticar.generator.cpp.loopSolver.DummyRHSComponent;
import de.monticore.lang.monticar.generator.testing.StreamTestGenerator;
import de.monticore.lang.monticar.semantics.loops.symbols.EMAEquationSystemHelper;
import de.monticore.lang.monticar.semantics.loops.symbols.semiexplicit.SemiExplicitForm;
public class EMAMFunctionFixer extends BaseMathFunctionFixerHandler {
@Override
protected boolean canFixMathSymbol(MathExpressionSymbol symbol) {
if (symbol instanceof EMAMSpecificationSymbol)
return true;
// else if (symbol instanceof EMAMEquationSymbol)
// return true;
// else if (symbol instanceof EMAMInitialGuessSymbol)
// return true;
// else if (symbol instanceof EMAMInitialValueSymbol)
// return true;
else
return false;
}
@Override
protected void doFixMathFunction(MathExpressionSymbol symbol, EMAMBluePrintCPP bluePrintCPP) {
if (symbol instanceof EMAMSpecificationSymbol)
doFixMathFunction((EMAMSpecificationSymbol) symbol, bluePrintCPP);
}
protected void doFixMathFunction(EMAMSpecificationSymbol symbol, EMAMBluePrintCPP bluePrintCPP) {
EMAComponentInstanceSymbol originalSymbol = bluePrintCPP.getOriginalSymbol();
SemiExplicitForm semiExplicitForm = EMAEquationSystemHelper.buildSemiExplicitForm(originalSymbol, symbol);
GeneratorCPP generator = (GeneratorCPP) bluePrintCPP.getGenerator();
CPPEquationSystemHelper.handleEquationSystem(semiExplicitForm, bluePrintCPP,
generator, bluePrintCPP.getAdditionalUserIncludeStrings());
DummyRHSComponent rhsComponent = new DummyRHSComponent(originalSymbol);
StreamTestGenerator streamTestGenerator = new StreamTestGenerator();//only used when creating streamTestsForAComponent
LanguageUnitCPP languageUnitCPP = new LanguageUnitCPP();
languageUnitCPP.setGeneratorCPP(generator);
languageUnitCPP.addSymbolToConvert(rhsComponent);
languageUnitCPP.generateBluePrints();
EMAMBluePrintCPP currentBluePrint = null;
for (EMAMBluePrint bluePrint : languageUnitCPP.getBluePrints())
if (bluePrint.getOriginalSymbol().equals(rhsComponent))
bluePrintCPP = (EMAMBluePrintCPP) bluePrint;
CPPEquationSystemHelper.handleRHS(semiExplicitForm, bluePrintCPP, generator, bluePrintCPP.getAdditionalUserIncludeStrings());
String result = languageUnitCPP.getGeneratedHeader(null, bluePrintCPP);
generator.addFileContent(new FileContent(result, rhsComponent));
}
@Override
public String getRole() {
return "EMAMFunctionFixer";
}
}
......@@ -9,12 +9,18 @@ public class ExecutionStepperHelper {
public static String FILENAME = "ExecutionStepper";
public static String CURRENTTIME_METHOD_NAME = "getCurrentTime";
private static boolean TIME_USED = false;
public static void setUsed() {
TIME_USED = true;
}
public static void setUnused() {
TIME_USED = false;
}
public static boolean isUsed() {
return TIME_USED;
}
......
......@@ -14,31 +14,23 @@ import de.monticore.lang.monticar.generator.cmake.CMakeFindModule;
import de.monticore.lang.monticar.generator.cpp.Dynamics.DynamicHelper;
import de.monticore.lang.monticar.generator.cpp.Dynamics.EventPortValueCheck;
import de.monticore.lang.monticar.generator.cpp.converter.*;
import de.monticore.lang.monticar.generator.cpp.instruction.ConnectInstructionCPP;
import de.monticore.lang.monticar.generator.cpp.loopSolver.CPPEquationSystemHelper;
import de.monticore.lang.monticar.generator.cpp.loopSolver.EquationSystemComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.cpp.loopSolver.daecpp.DAECPPEquationSystemGenerator;
import de.monticore.lang.monticar.generator.cpp.loopSolver.daecpp.DAECPPOptions;
import de.monticore.lang.monticar.generator.cpp.loopSolver.odeint.OdeintEquationSystemGenerator;
import de.monticore.lang.monticar.generator.cpp.loopSolver.odeint.OdeintOptions;
import de.monticore.lang.monticar.generator.cpp.loopSolver.NumericSolverOptions;
import de.monticore.lang.monticar.generator.cpp.loopSolver.RHSComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.cpp.mathopt.MathOptSolverConfig;
import de.monticore.lang.monticar.generator.cpp.template.AllTemplates;
import de.monticore.lang.monticar.generator.cpp.viewmodel.AutopilotAdapterDataModel;
import de.monticore.lang.monticar.generator.cpp.viewmodel.ServerWrapperViewModel;
import de.monticore.lang.monticar.generator.order.ImplementExecutionOrder;
import de.monticore.lang.monticar.generator.testing.StreamTestGenerator;
import de.monticore.lang.monticar.semantics.ExecutionSemantics;
import de.monticore.lang.monticar.semantics.helper.Find;
import de.monticore.lang.monticar.semantics.helper.NameHelper;
import de.monticore.lang.monticar.semantics.loops.detection.ConnectionHelper;
import de.monticore.lang.monticar.semantics.loops.symbols.EMAEquationSystem;
import de.monticore.lang.monticar.semantics.loops.symbols.LoopComponentInstanceSymbol;
import de.monticore.lang.monticar.semantics.loops.symbols.LoopComponentInstanceSymbol;
import de.monticore.lang.monticar.semantics.resolve.SymbolTableHelper;
import de.monticore.lang.monticar.ts.MCTypeSymbol;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.Scope;
import de.se_rwth.commons.Joiners;
import de.se_rwth.commons.Names;
import de.se_rwth.commons.logging.Log;
import org.apache.commons.lang3.StringUtils;
......@@ -84,6 +76,10 @@ public class GeneratorCPP implements EMAMGenerator {
private MathOptFunctionFixer mathOptFunctionFixer = new MathOptFunctionFixer();
private EMAComponentInstanceSymbol rootModel = null;
// EMAM
private EMAMSymbolHandler specificationSymbolHandler = new EMAMSymbolHandler();
private EMAMFunctionFixer emamFunctionFixer = new EMAMFunctionFixer();
public GeneratorCPP() {
this.mathCommandRegister = new MathCommandRegisterCPP();
setGenerateCMake(true);
......@@ -93,6 +89,9 @@ public class GeneratorCPP implements EMAMGenerator {
mathOptExecuteMethodGenerator.setSuccessor(ExecuteMethodGenerator.getInstance());
mathOptFunctionFixer.setSuccessor(MathFunctionFixer.getInstance());
specificationSymbolHandler.setSuccessor(mathOptExecuteMethodGenerator);
emamFunctionFixer.setSuccessor(mathOptFunctionFixer);
}
......@@ -188,72 +187,10 @@ public class GeneratorCPP implements EMAMGenerator {
if (bluePrintCPP != null) {
bluePrints.add(bluePrintCPP);
if (componentSymbol.equals(this.rootModel) && ExecutionStepperHelper.isUsed()) {
Optional<Method> execute = bluePrintCPP.getMethod("execute");
execute.get().getInstructions().add(new Instruction() {
@Override
public String getTargetLanguageInstruction() {
return "advanceTime();\n";
}
@Override
public boolean isConnectInstruction() {
return false;
}
});
bluePrintCPP.addAdditionalIncludeString(ExecutionStepperHelper.FILENAME);
}
if (componentSymbol instanceof LoopComponentInstanceSymbol) {
// connect information to eqs
ExecutionStepperHelper.setUsed();
EMAEquationSystem equationSystem = ((LoopComponentInstanceSymbol) componentSymbol).getEquationSystem();
String eqsName = equationSystem.getName();
Variable eqs = new Variable("eqs", "");
eqs.setVariableType(new VariableType("", eqsName, eqsName));
bluePrintCPP.addVariable(eqs);
Optional<Method> execute = bluePrintCPP.getMethod("execute");
if (execute.isPresent()) {
for (EMAPortInstanceSymbol inport : equationSystem.getIncomingPorts()) {
Optional<EMAPortInstanceSymbol> originalSourcePort = equationSystem.getAtomicSourceOf(inport);
Optional<EMAPortInstanceSymbol> currentPort = componentSymbol.getIncomingPortInstances().stream()
.filter(i -> ConnectionHelper.sourceOf(i).equals(originalSourcePort))
.findFirst();
if (currentPort.isPresent()) {
String sourceName = currentPort.get().getName();
String targetName = String.join(".", "eqs",
CPPEquationSystemHelper.getNameOfPort(inport));
Variable v1 = PortConverter.convertPortSymbolToVariable(currentPort.get(), sourceName, bluePrintCPP);
Variable v2 = PortConverter.convertPortSymbolToVariable(inport, targetName, bluePrintCPP);
execute.get().addInstruction(new ConnectInstructionCPP(v2, v1));
} else Log.error("Missing information for equation system TODO");
}
execute.get().addInstruction(new Instruction() {
@Override
public String getTargetLanguageInstruction() {
return "eqs.execute();\n";
}
@Override
public boolean isConnectInstruction() {
return false;
}
});
for (EMAPortInstanceSymbol outport : componentSymbol.getOutgoingPortInstances()) {
Optional<EMAPortInstanceSymbol> eqsVar = equationSystem.getOutgoingPorts().stream()
.filter(p -> p.getFullName().equals(outport.getFullName()))
.findFirst();
if (eqsVar.isPresent()) {
String sourceName = String.join(".", "eqs",
CPPEquationSystemHelper.getNameOfPort(eqsVar.get()));
String targetName = outport.getName();
Variable v1 = PortConverter.convertPortSymbolToVariable(eqsVar.get(), sourceName, bluePrintCPP);
Variable v2 = PortConverter.convertPortSymbolToVariable(outport, targetName, bluePrintCPP);
execute.get().addInstruction(new ConnectInstructionCPP(v2, v1));
} else Log.error("Could not find corresponding port");
}
}
execute.get().getInstructions().add(new TargetCodeInstruction("advanceTime();\n"));
bluePrintCPP.addAdditionalUserIncludeStrings(ExecutionStepperHelper.FILENAME);
}
}
String result;
......@@ -264,7 +201,7 @@ public class GeneratorCPP implements EMAMGenerator {
return result;
}
public static List<FileContent> currentFileContentList = null;
public List<FileContent> currentFileContentList = new ArrayList<>();
private static Set<EMAMEquationSymbol> equationSystemsAlreadyBuild = new HashSet<>();
......@@ -279,15 +216,6 @@ public class GeneratorCPP implements EMAMGenerator {
// ImplementExecutionOrder.exOrder(taggingResolver, componentInstanceSymbol);
if (componentInstanceSymbol instanceof LoopComponentInstanceSymbol) {
((LoopComponentInstanceSymbol) componentInstanceSymbol).getEquationSystem()
.setName(Joiners.DOT.join(rootModel.getFullName(),
((LoopComponentInstanceSymbol) componentInstanceSymbol).getEquationSystem().getName()));
for (CMakeFindModule dependency : OdeintOptions.getDependencies())
cMakeConfig.addModuleDependency(dependency);
}
currentFileContentList = fileContents;
String lastNameWithoutArrayPart = "";
if (!streamTestGenerationMode) {
for (EMAComponentInstanceSymbol instanceSymbol : componentInstanceSymbol.getSubComponents()) {
......@@ -319,6 +247,20 @@ public class GeneratorCPP implements EMAMGenerator {
fileContents.addAll(SimulatorIntegrationHelper.getSimulatorIntegrationHelperFileContent());
}
}
if (componentInstanceSymbol instanceof LoopComponentInstanceSymbol) {
EMAEquationSystem equationSystem = ((LoopComponentInstanceSymbol) componentInstanceSymbol).getEquationSystem();
if (!equationSystemsAlreadyBuild.contains(equationSystem)) {
equationSystem.setName(Names.getQualifiedName(rootModel.getFullName(),
equationSystem.getName()));
CPPEquationSystemHelper.handleSubComponents(equationSystem);
fileContents.addAll(generateStrings(taggingResolver,
new EquationSystemComponentInstanceSymbol(equationSystem)));
fileContents.addAll(generateStrings(taggingResolver,
new RHSComponentInstanceSymbol(equationSystem)));
}
}
if (!streamTestGenerationMode)
fileContents.add(new FileContent(generateString(taggingResolver, componentInstanceSymbol), componentInstanceSymbol));
else
......@@ -346,17 +288,6 @@ public class GeneratorCPP implements EMAMGenerator {
fileContents.addAll(SimulatorIntegrationHelper.getSimulatorIntegrationHelperFileContent());
}
if (componentInstanceSymbol instanceof LoopComponentInstanceSymbol) {
EMAEquationSystem equationSystem = ((LoopComponentInstanceSymbol) componentInstanceSymbol).getEquationSystem();
if (!equationSystemsAlreadyBuild.contains(equationSystem)) {
// fileContents.addAll(OdeintEquationSystemGenerator.generateEquationSystem(
// ((LoopComponentInstanceSymbol) componentInstanceSymbol).getEquationSystem()));
fileContents.addAll(generateStrings(taggingResolver,
new EquationSystemComponentInstanceSymbol(equationSystem)));
}
}
return fileContents;
}
......@@ -375,6 +306,7 @@ public class GeneratorCPP implements EMAMGenerator {
EMAComponentInstanceSymbol componentInstanceSymbol = (EMAComponentInstanceSymbol) taggingResolver.resolve(componentFullName,
EMAComponentInstanceSymbol.KIND).get();
// TODO add properties
ExecutionSemantics semantics = new ExecutionSemantics(taggingResolver, componentInstanceSymbol);
semantics.addExecutionSemantics();
fileContents.addAll(generateStrings(taggingResolver, componentInstanceSymbol));
......@@ -403,6 +335,7 @@ public class GeneratorCPP implements EMAMGenerator {
if (ExecutionStepperHelper.isUsed()) {
fileContents.add(ExecutionStepperHelper.getTimeHelperFileContent());
}
fileContents.addAll(currentFileContentList);
List<File> files = saveFilesToDisk(fileContents);
//cmake
if (generateCMake)
......
......@@ -16,15 +16,20 @@ import de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol
import de.monticore.lang.monticar.generator.*;
import de.monticore.lang.monticar.generator.cpp.*;
import de.monticore.lang.monticar.generator.cpp.instruction.ConstantConnectInstructionCPP;
import de.monticore.lang.monticar.generator.cpp.loopSolver.CPPEquationSystemHelper;
import de.monticore.lang.monticar.generator.cpp.loopSolver.EquationSystemComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.cpp.loopSolver.RHSComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.optimization.MathInformationRegister;
import de.monticore.lang.monticar.semantics.executionOrder.ExecutionOrder;
import de.monticore.lang.monticar.semantics.loops.symbols.EMAEquationSystem;
import de.monticore.lang.monticar.semantics.loops.symbols.LoopComponentInstanceSymbol;
import de.se_rwth.commons.logging.Log;
import java.util.*;
import java.util.stream.Collectors;
/**
*
*/
public class ComponentConverter {
......@@ -59,29 +64,38 @@ public class ComponentConverter {
}
bluePrint.addVariable(ComponentInstanceConverter.convertComponentInstanceSymbolToVariable(instanceSymbol, componentSymbol));
}
if (componentSymbol instanceof LoopComponentInstanceSymbol) {
EMAEquationSystem equationSystem = ((LoopComponentInstanceSymbol) componentSymbol).getEquationSystem();
String eqsName = GeneralHelperMethods.getTargetLanguageComponentVariableInstanceName(equationSystem.getName());
Variable eqs = new Variable("eqs", "");
eqs.setVariableType(new VariableType("", eqsName, eqsName));
eqs.addAdditionalInformation(Variable.COMPONENT);
bluePrint.addVariable(eqs);
}
//create arrays from variables that only differ at the end by _number_
BluePrintFixer.fixBluePrintVariableArrays(bluePrint);
MathInformationFilter.filterStaticInformation(componentSymbol, bluePrint, mathStatementsSymbol, generatorCPP, includeStrings);
//save functions names
if(mathStatementsSymbol != null) {
if (mathStatementsSymbol != null) {
List<MathExpressionSymbol> mathExpressionSymbols = mathStatementsSymbol.getMathExpressionSymbols();
for(MathExpressionSymbol mathExpressionSymbol : mathExpressionSymbols){
for (MathExpressionSymbol mathExpressionSymbol : mathExpressionSymbols) {
String nameOfFunction = getNameOfMathCommand(mathExpressionSymbol);
namesOfFunctions.add(nameOfFunction);
fixFunctionTypes(nameOfFunction, mathExpressionSymbol, bluePrint);
}
if(mathExpressionSymbols.size() >= 1) {
if (mathExpressionSymbols.size() >= 1) {
for (MathExpressionSymbol mathExpressionSymbol : mathExpressionSymbols) {
MathExpressionProperties properties = new MathExpressionProperties();
MathConverter.setPropertiesForMathExpression(mathExpressionSymbols, mathExpressionSymbol, bluePrint, properties);
if(mathExpressionSymbol.isAssignmentExpression() && ((MathAssignmentExpressionSymbol)mathExpressionSymbol).getExpressionSymbol().isMatrixExpression()){
MathMatrixExpressionSymbol mathMatrixExpressionSymbol = (MathMatrixExpressionSymbol) ((MathAssignmentExpressionSymbol)mathExpressionSymbol).getExpressionSymbol();
if(mathMatrixExpressionSymbol.isMatrixNameExpression()) {
if (mathExpressionSymbol.isAssignmentExpression() && ((MathAssignmentExpressionSymbol) mathExpressionSymbol).getExpressionSymbol().isMatrixExpression()) {
MathMatrixExpressionSymbol mathMatrixExpressionSymbol = (MathMatrixExpressionSymbol) ((MathAssignmentExpressionSymbol) mathExpressionSymbol).getExpressionSymbol();
if (mathMatrixExpressionSymbol.isMatrixNameExpression()) {
MathMatrixNameExpressionSymbol mathMatrixNameExpressionSymbol = (MathMatrixNameExpressionSymbol) ((MathAssignmentExpressionSymbol) mathExpressionSymbol).getExpressionSymbol();
ComponentConverter.tuples.put(mathMatrixNameExpressionSymbol, properties);
}
} else{
} else {
ComponentConverter.tuples.put(mathExpressionSymbol, properties);
}
}
......@@ -89,8 +103,8 @@ public class ComponentConverter {
redefineVariables(mathExpressionSymbols, bluePrint);
}
if(namesOfFunctions != null) {
for(String nameOfFunction : namesOfFunctions){
if (namesOfFunctions != null) {
for (String nameOfFunction : namesOfFunctions) {
usedMathCommand.add(bluePrint.getMathCommandRegister().getMathCommand(nameOfFunction));
}
}
......@@ -111,17 +125,14 @@ public class ComponentConverter {
Method execute = ComponentConverterMethodGeneration.generateExecuteMethod(componentSymbol, bluePrint,
mathStatementsSymbol, generatorCPP, includeStrings);
EventConverter.generateEvents(execute, componentSymbol, bluePrint, mathStatementsSymbol,generatorCPP, includeStrings);
EventConverter.generateEvents(execute, componentSymbol, bluePrint, mathStatementsSymbol, generatorCPP, includeStrings);
extendInitMethod(componentSymbol, bluePrint, generatorCPP, includeStrings);
bluePrint.addMethod(execute);
EventConverter.generatePVCNextMethod(bluePrint);
if(componentSymbol instanceof EMADynamicComponentInstanceSymbol){
if(((EMADynamicComponentInstanceSymbol) componentSymbol).isDynamic()){
if (componentSymbol instanceof EMADynamicComponentInstanceSymbol) {
if (((EMADynamicComponentInstanceSymbol) componentSymbol).isDynamic()) {
// bluePrint.setHasSuperClass(Optional.of("__dynamicComponent"));
//TODO: ADD parent dynamic function pointer
addParentDynamicFunctionPointer(bluePrint);
......@@ -129,10 +140,14 @@ public class ComponentConverter {
bluePrint.addAdditionalUserIncludeStrings("DynamicHelper");
}
}
if(generatorCPP.isGenerateCV){
if (generatorCPP.isGenerateCV) {
MathCommand.redefineArmaMat(bluePrint);
MathCommand.redefineInit(bluePrint);
}
if (componentSymbol instanceof EquationSystemComponentInstanceSymbol) {
bluePrint.getMethod("init").get().addInstruction(
new TargetCodeInstruction("rhs.init();\n"));
}
// generate output and update
if (ExecutionOrder.needsOutputAndUpdateSplit(componentSymbol)) {
......@@ -141,6 +156,9 @@ public class ComponentConverter {
Method update = ComponentConverterMethodGeneration.generateUpdateMethod(componentSymbol, bluePrint,
mathStatementsSymbol, generatorCPP, includeStrings);
bluePrint.addMethod(output);
bluePrint.addMethod(update);
}
return bluePrint;
......@@ -161,13 +179,17 @@ public class ComponentConverter {
//add ports as variables to blueprint
for (EMAPortInstanceSymbol port : componentSymbol.getPortInstanceList()) {
//Config ports might already be added from adaptable Parameters
if(!port.isConfig()) {
bluePrint.addVariable(PortConverter.convertPortSymbolToVariable(port, port.getName(), bluePrint));
}else{
String name = (componentSymbol instanceof EquationSystemComponentInstanceSymbol ||
componentSymbol instanceof RHSComponentInstanceSymbol) ?
CPPEquationSystemHelper.getNameOfPort(port) :
port.getName();
if (!port.isConfig()) {
bluePrint.addVariable(PortConverter.convertPortSymbolToVariable(port, name, bluePrint));
} else {
Set<String> paramNames = componentSymbol.getParameters().stream().map(EMAVariable::getName).collect(Collectors.toSet());
if(!paramNames.contains(port.getName())){
if (!paramNames.contains(port.getName())) {
//The port was not created by an adaptable parameter with the same name -> add
bluePrint.addVariable(PortConverter.convertPortSymbolToVariable(port, port.getName(), bluePrint));
bluePrint.addVariable(PortConverter.convertPortSymbolToVariable(port, name, bluePrint));
}
}
......@@ -175,8 +197,8 @@ public class ComponentConverter {
}
}
public static void addParentDynamicFunctionPointer(EMAMBluePrint bluePrint){
if(!bluePrint.getVariable("(*__parent_dynamic)(void)").isPresent()) {
public static void addParentDynamicFunctionPointer(EMAMBluePrint bluePrint) {
if (!bluePrint.getVariable("(*__parent_dynamic)(void)").isPresent()) {
Variable pd = new Variable();
pd.setTypeNameTargetLanguage("void*");
pd.setName("__parent");
......@@ -194,7 +216,7 @@ public class ComponentConverter {
bluePrint.getMethod("init").get().addInstruction(new TargetCodeInstruction("__parent_dynamic = NULL;\n"));
}
if(!bluePrint.getMethod("set_Parent_Dynamic").isPresent()){
if (!bluePrint.getMethod("set_Parent_Dynamic").isPresent()) {
Method m = new Method();
m.setReturnTypeName("void");
m.setName("set_Parent_Dynamic");
......@@ -241,11 +263,11 @@ public class ComponentConverter {
for (Variable v : bluePrint.getVariables()) {
Log.info("Variable: " + v.getName(), "initBluePrintCreate:");
if(v instanceof VariablePortValueChecker) {
if (v instanceof VariablePortValueChecker) {
// ((VariablePortValueChecker) v).addInitInstructionsToMethod(method);
}else if(v instanceof VariableConstantArray){
} else if (v instanceof VariableConstantArray) {
// ((VariableConstantArray) v).generateInit(method);
}else {
} else {
if (v.isInputVariable() && !v.isConstantVariable()) {
//method.addParameter(v);
//Instruction instruction = new ConnectInstructionCPP(v, true, v, false);
......@@ -269,14 +291,14 @@ public class ComponentConverter {
}
String result = "";
if (componentSymbol instanceof EquationSystemComponentInstanceSymbol)
result += GeneralHelperMethods.getTargetLanguageVariableInstanceName(subComponent.getFullName()) + ".init(" + parameterString + ");\n";
else
result += GeneralHelperMethods.getTargetLanguageVariableInstanceName(subComponent.getName()) + ".init(" + parameterString + ");\n";
String subComponentName = subComponent.getName();
if (componentSymbol instanceof RHSComponentInstanceSymbol)
subComponentName = GeneralHelperMethods.getTargetLanguageComponentName(subComponent.getFullName());
result += GeneralHelperMethods.getTargetLanguageVariableInstanceName(subComponentName) + ".init(" + parameterString + ");\n";
if((componentSymbol instanceof EMADynamicComponentInstanceSymbol) && (subComponent instanceof EMADynamicComponentInstanceSymbol)){
if(((EMADynamicComponentInstanceSymbol) componentSymbol).isDynamic() && ((EMADynamicComponentInstanceSymbol) subComponent).isDynamic()){
result += GeneralHelperMethods.getTargetLanguageVariableInstanceName(subComponent.getName()) +".set_Parent_Dynamic(this, dynamicWrapper);\n";
if ((componentSymbol instanceof EMADynamicComponentInstanceSymbol) && (subComponent instanceof EMADynamicComponentInstanceSymbol)) {
if (((EMADynamicComponentInstanceSymbol) componentSymbol).isDynamic() && ((EMADynamicComponentInstanceSymbol) subComponent).isDynamic()) {
result += GeneralHelperMethods.getTargetLanguageVariableInstanceName(subComponent.getName()) + ".set_Parent_Dynamic(this, dynamicWrapper);\n";
}
}
......@@ -286,18 +308,18 @@ public class ComponentConverter {
return method;
}
public static void extendInitMethod(EMAComponentInstanceSymbol componentSymbol, EMAMBluePrintCPP bluePrint, GeneratorCPP generatorCPP, List<String> includeStrings){
public static void extendInitMethod(EMAComponentInstanceSymbol componentSymbol, EMAMBluePrintCPP bluePrint, GeneratorCPP generatorCPP, List<String> includeStrings) {
Optional<Method> init = bluePrint.getMethod("init");
if(!init.isPresent()){
if (!init.isPresent()) {
init = Optional.of(new Method("init", "void"));
bluePrint.addMethod(init.get());
}
for (Variable v : bluePrint.getVariables()) {
Log.info("Variable: " + v.getName(), "initBluePrintExtension:");
if(v instanceof VariablePortValueChecker) {
if (v instanceof VariablePortValueChecker) {
((VariablePortValueChecker) v).addInitInstructionsToMethod(init.get());
}else if(v instanceof VariableConstantArray){
} else if (v instanceof VariableConstantArray) {
((VariableConstantArray) v).generateInit(init.get());
}
}
......@@ -335,22 +357,22 @@ public class ComponentConverter {
public static void generateInitNonStaticVariable(Method method, Variable v, EMAMBluePrintCPP bluePrint) {
Log.info("v: " + v.getName(), "generateInitNonStaticVariable");
if(v.isParameterVariable()){
if (v.isParameterVariable()) {
method.addInstruction(new TargetCodeInstruction("this->" + MathInformationRegister.getVariableInitName(v, bluePrint) + "=" + MathInformationRegister.getVariableInitName(v, bluePrint) + ";\n"));
method.addParameter(v);
}else {
} else {
Optional<String> initLine = MathConverter.getInitLine(v, bluePrint);
initLine.ifPresent(s -> method.addInstruction(new TargetCodeInstruction(s)));
}
}
public static String getNameOfMathCommand(MathExpressionSymbol mathExpressionSymbol){
public static String getNameOfMathCommand(MathExpressionSymbol mathExpressionSymbol) {
String nameOfFunction = "";
if (mathExpressionSymbol.isAssignmentExpression()) {
if (((MathAssignmentExpressionSymbol) mathExpressionSymbol).getExpressionSymbol() instanceof MathMatrixNameExpressionSymbol) {
nameOfFunction = ((MathMatrixNameExpressionSymbol) ((MathAssignmentExpressionSymbol) mathExpressionSymbol).getExpressionSymbol()).getNameToAccess();
}
} else if(mathExpressionSymbol.isValueExpression()) {
} else if (mathExpressionSymbol.isValueExpression()) {
if (((MathValueSymbol) mathExpressionSymbol).getValue() instanceof MathMatrixNameExpressionSymbol) {
nameOfFunction = ((MathMatrixNameExpressionSymbol) ((MathValueSymbol) mathExpressionSymbol).getValue()).getNameToAccess();
}
......@@ -358,16 +380,16 @@ public class ComponentConverter {
return nameOfFunction;
}
public static String getNameOfOutput(MathExpressionSymbol mathExpressionSymbol){
public static String getNameOfOutput(MathExpressionSymbol mathExpressionSymbol) {
String outputName = "";
if (mathExpressionSymbol.isAssignmentExpression()) {
if (((MathAssignmentExpressionSymbol) mathExpressionSymbol).getExpressionSymbol() instanceof MathMatrixNameExpressionSymbol) {
outputName = ((MathAssignmentExpressionSymbol)mathExpressionSymbol).getNameOfMathValue();
outputName = ((MathAssignmentExpressionSymbol) mathExpressionSymbol).getNameOfMathValue();
}
}else if(mathExpressionSymbol.isValueExpression()) {
} else if (mathExpressionSymbol.isValueExpression()) {
if (((MathValueSymbol) mathExpressionSymbol).getValue() instanceof MathMatrixNameExpressionSymbol) {