Fix: Struct Variable declaration in Math now possible

parent 9e854ab3
......@@ -30,13 +30,13 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-generator</artifactId>
<version>0.1.12-SNAPSHOT</version>
<version>0.1.13-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
<properties>
<Embedded-MontiArc-Math.version>0.1.9-SNAPSHOT</Embedded-MontiArc-Math.version>
<Embedded-MontiArc-Math.version>0.1.10-SNAPSHOT</Embedded-MontiArc-Math.version>
<!-- .. Libraries .................................................. -->
<guava.version>18.0</guava.version>
......
......@@ -139,7 +139,7 @@ public final class GeneratorCppCli {
}
public static void main(String[] args) {
Log.initDEBUG();
//Log.initDEBUG();
Options options = getOptions();
CommandLineParser parser = new DefaultParser();
CommandLine cliArgs = parseArgs(options, parser, args);
......
......@@ -25,16 +25,22 @@ import de.monticore.lang.math._symboltable.MathForLoopHeadSymbol;
import de.monticore.lang.math._symboltable.expression.*;
import de.monticore.lang.math._symboltable.matrix.MathMatrixNameExpressionSymbol;
import de.monticore.lang.monticar.generator.Variable;
import de.monticore.lang.monticar.generator.VariableType;
import de.monticore.lang.monticar.generator.cpp.MathCommandRegisterCPP;
import de.monticore.lang.monticar.generator.cpp.MathFunctionFixer;
import de.monticore.lang.monticar.generator.cpp.OctaveHelper;
import de.monticore.lang.monticar.generator.cpp.symbols.MathChainedExpression;
import de.monticore.lang.monticar.generator.cpp.symbols.MathStringExpression;
import de.monticore.lang.monticar.generator.cpp.viewmodel.Utils;
import de.monticore.lang.monticar.generator.optimization.MathInformationRegister;
import de.monticore.lang.monticar.struct._symboltable.StructSymbol;
import de.monticore.lang.monticar.types2._ast.ASTElementType;
import de.monticore.symboltable.Symbol;
import de.se_rwth.commons.logging.Log;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* @author Sascha Schneiders
......@@ -171,11 +177,31 @@ public class ExecuteMethodGeneratorHandler {
result = handleBooleanType(mathValueType);
} else {
Log.info(mathValueType.getTextualRepresentation(), "Representation:");
Log.error("MathValueType: Case not handled!");
result = handleStructType(mathValueType);
}
return result;
}
private static String handleStructType(MathValueType mathValueType) {
String res = "";
if (mathValueType.getDimensions().size() == 0){
if(mathValueType.getTypeRef().existsReferencedSymbol()){
Symbol tmpSym = mathValueType.getTypeRef().getReferencedSymbol();
if(tmpSym instanceof StructSymbol){
return tmpSym.getFullName().replace(".","_");
}else{
Log.error("Referenced Symbol is not a Struct!");
}
}else{
Log.error("Can not find Referenced type for " + mathValueType.getType().getName());
}
}else{
Log.error("StructType: Case not handled!");
}
return res;
}
private static String handleRationalType(MathValueType mathValueType) {
if (mathValueType.getDimensions().size() == 0) {
......
......@@ -734,4 +734,22 @@ public class GenerationTest extends AbstractSymtabTest {
testFilesAreEqual(files,"testing/WholeNumberMatrix/");
}
@Test
public void testStructDecl() throws IOException {
TaggingResolver taggingResolver = createSymTabAndTaggingResolver("src/test/resources");
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<EMAComponentInstanceSymbol>resolve("structs.structDeclarationComp",EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.useArmadilloBackend();
generatorCPP.setGenerateCMake(false);
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/structs/StructDeclarationComp/");
List<File> files = generatorCPP.generateFiles(componentInstanceSymbol, taggingResolver);
//testFilesAreEqual(files,"testing/WholeNumberMatrix/");
}
}
package structs;
struct NestedStruct{
SimpleStruct structField;
Q simpleField;
}
\ No newline at end of file
package structs;
struct SimpleStruct{
Q field;
}
\ No newline at end of file
package structs;
component StructDeclarationComp{
ports in SimpleStruct in1,
out SimpleStruct out1;
implementation Math{
Q tmpQ1;
Q tmpQ2 = 0;
SimpleStruct tmpSimpleStruct;
NestedStruct tmpNestedStruct;
}
}
\ No newline at end of file
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