Commit 48a7167e authored by Alexander David Hellwig's avatar Alexander David Hellwig

Merge branch 'StructStreamTest' into 'master'

Math: struct variable definitions are now possible

See merge request !34
parents 1e13b60c 310fca2e
Pipeline #176339 passed with stages
in 35 minutes and 51 seconds
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
......@@ -10,13 +10,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>
......
......@@ -120,7 +120,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);
......
......@@ -6,16 +6,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
......@@ -152,11 +158,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) {
......
......@@ -58,7 +58,9 @@ public class AbstractSymtabTest extends AbstractSymtab {
return false;
}
lines1 = discardEmptyLines(lines1);
lines1 = discardCopyrightNotice(lines1);
lines2 = discardEmptyLines(lines2);
lines2 = discardCopyrightNotice(lines2);
if (lines1.size() != lines2.size()) {
Assert.fail(
"files have different number of lines: "
......@@ -83,6 +85,14 @@ public class AbstractSymtabTest extends AbstractSymtab {
return true;
}
private static List<String> discardCopyrightNotice(List<String> lines) {
return lines
.stream()
.filter(s -> !s.contains("(c) https://github.com/MontiCore/monticore"))
.collect(Collectors.toList());
}
private static List<String> discardEmptyLines(List<String> lines) {
return lines.stream()
.map(String::trim)
......
......@@ -715,4 +715,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