Commit d9f4c5a9 authored by Sascha Niklas Schneiders's avatar Sascha Niklas Schneiders
Browse files

updated to use newest language versions and added some fixes

parent 00cf147a
......@@ -8,7 +8,7 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-generator</artifactId>
<version>0.0.6-SNAPSHOT</version>
<version>0.0.7-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
......@@ -20,10 +20,10 @@
<mc.grammars.assembly.version>0.0.6-SNAPSHOT</mc.grammars.assembly.version>
<SIUnit.version>0.0.10-SNAPSHOT</SIUnit.version>
<Common-MontiCar.version>0.0.10-SNAPSHOT</Common-MontiCar.version>
<Embedded-MontiArc.version>0.0.10-SNAPSHOT</Embedded-MontiArc.version>
<Embedded-MontiArc-Behaviour.version>0.0.10-SNAPSHOT</Embedded-MontiArc-Behaviour.version>
<Math.version>0.0.10-SNAPSHOT</Math.version>
<Embedded-MontiArc-Math.version>0.0.10-SNAPSHOT</Embedded-MontiArc-Math.version>
<Embedded-MontiArc.version>0.0.11-SNAPSHOT</Embedded-MontiArc.version>
<Embedded-MontiArc-Behaviour.version>0.0.11-SNAPSHOT</Embedded-MontiArc-Behaviour.version>
<Math.version>0.0.11-SNAPSHOT</Math.version>
<Embedded-MontiArc-Math.version>0.0.11-SNAPSHOT</Embedded-MontiArc-Math.version>
<tagging.version>0.0.1</tagging.version>
<!-- .. Libraries .................................................. -->
<guava.version>18.0</guava.version>
......
......@@ -24,10 +24,11 @@ import java.util.List;
*/
public class ComponentConverterMethodGeneration {
public static int currentGenerationIndex = 0;
public static ExpandedComponentInstanceSymbol currentComponentSymbol = null;
public static void generateExecuteMethod(ExpandedComponentInstanceSymbol componentSymbol, BluePrintCPP bluePrint, MathStatementsSymbol mathStatementsSymbol, GeneratorCPP generatorCPP, List<String> includeStrings) {
Method method = new Method("execute", "void");
currentComponentSymbol = componentSymbol;
for (ConnectorSymbol connector : componentSymbol.getConnectors()) {
if (!connector.isConstant()) {
Log.info("source:" + connector.getSource() + " target:" + connector.getTarget(), "Port info:");
......
......@@ -62,6 +62,20 @@ public class ExecuteMethodGenerator {
return result;
}
/**
* Returns correct string for generation of matrix/array access
*
* @return
*/
public static String getCorrectAccessString(String nameOfMathValue, MathMatrixAccessOperatorSymbol mathMatrixAccessOperatorSymbol, List<String> includeStrings) {
String result = "";
if (ComponentConverterMethodGeneration.currentComponentSymbol.getPort(nameOfMathValue + "[1]").isPresent()) {
result += ExecuteMethodGeneratorMatrixExpressionHandler.generateExecuteCode(mathMatrixAccessOperatorSymbol, includeStrings, true).replaceAll("\\(", "\\[").replaceAll("\\)", "\\]") + " ";
} else {
result += ExecuteMethodGeneratorMatrixExpressionHandler.generateExecuteCode(mathMatrixAccessOperatorSymbol, includeStrings, true) + " ";
}
return result;
}
/*
public static String generateExecuteCodeFixForLoopAccess(MathMatrixAccessSymbol mathMatrixAccessSymbol, List<String> includeStrings) {
......
package de.monticore.lang.monticar.generator.cpp.converter;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.math.math._symboltable.MathForLoopHeadSymbol;
import de.monticore.lang.math.math._symboltable.expression.*;
import de.monticore.lang.math.math._symboltable.matrix.*;
import de.monticore.lang.monticar.generator.Variable;
import de.monticore.lang.monticar.generator.cpp.GeneratorCPP;
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;
......@@ -157,7 +159,7 @@ public class ExecuteMethodGeneratorHandler {
if (MathFunctionFixer.fixForLoopAccess(mathAssignmentExpressionSymbol.getNameOfMathValue(), ComponentConverter.currentBluePrint)) {
String result = mathAssignmentExpressionSymbol.getNameOfMathValue();
result += ExecuteMethodGeneratorMatrixExpressionHandler.generateExecuteCode(mathAssignmentExpressionSymbol.getMathMatrixAccessOperatorSymbol(), includeStrings, true) + " ";
result += ExecuteMethodGenerator.getCorrectAccessString(mathAssignmentExpressionSymbol.getNameOfMathValue(), mathAssignmentExpressionSymbol.getMathMatrixAccessOperatorSymbol(), includeStrings);
result += mathAssignmentExpressionSymbol.getAssignmentOperator().getOperator() + " ";
result += ExecuteMethodGenerator.generateExecuteCode(mathAssignmentExpressionSymbol.getExpressionSymbol(), includeStrings) + ";\n";
......@@ -170,7 +172,7 @@ public class ExecuteMethodGeneratorHandler {
}
}*/
String result = mathAssignmentExpressionSymbol.getNameOfMathValue();
result += ExecuteMethodGeneratorMatrixExpressionHandler.generateExecuteCode(mathAssignmentExpressionSymbol.getMathMatrixAccessOperatorSymbol(), includeStrings) + " ";
result += ExecuteMethodGenerator.getCorrectAccessString(mathAssignmentExpressionSymbol.getNameOfMathValue(), mathAssignmentExpressionSymbol.getMathMatrixAccessOperatorSymbol(), includeStrings);
result += mathAssignmentExpressionSymbol.getAssignmentOperator().getOperator() + " ";
result += ExecuteMethodGenerator.generateExecuteCode(mathAssignmentExpressionSymbol.getExpressionSymbol(), includeStrings) + ";\n";
......
......@@ -10,16 +10,10 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.Expanded
public class SimulatorTSTest extends AbstractSymtab{
private TaggingResolver symtab;
@Before
public void setUp() {
symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
}
@Test
public void resolveModelDoorStatus() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("doors.doorStatus",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
......@@ -28,7 +22,7 @@ public class SimulatorTSTest extends AbstractSymtab{
@Test
public void resolveModelGameOverTrigger() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("feature.gameOverTrigger",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
......@@ -37,7 +31,7 @@ public class SimulatorTSTest extends AbstractSymtab{
@Test
public void resolveModelBrakeLightsControl() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("lights.brakeLightsControl",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
......@@ -46,7 +40,7 @@ public class SimulatorTSTest extends AbstractSymtab{
@Test
public void resolveModelIndicatorStatus() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("lights.indicatorStatus",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
......@@ -55,16 +49,18 @@ public class SimulatorTSTest extends AbstractSymtab{
@Test
public void resolveModelsLightTimer() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("lights.lightTimer",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
Assert.assertNotNull(instanceSymbol);
}
//Does not work in maven for some reason
@Ignore
@Test
public void resolveModel() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("main.sDCS",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
......@@ -73,16 +69,18 @@ public class SimulatorTSTest extends AbstractSymtab{
@Test
public void resolveModelsConstantVelocity() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("movement.constantVelocity",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
Assert.assertNotNull(instanceSymbol);
}
//Does not work in maven for some reason
@Ignore
@Test
public void resolveModelsSteeringControl() {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources/simulator-ts/visualization");
ExpandedComponentInstanceSymbol instanceSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("movement.steeringControl",
ExpandedComponentInstanceSymbol.KIND).orElse(null);
......
......@@ -484,6 +484,21 @@ public class GenerationTest extends AbstractSymtabTest {
Assert.assertFalse(files.isEmpty());
}
@Test
public void testDemuxTest() throws IOException {
TaggingResolver symTab = createSymTabAndTaggingResolver("src/test/resources");
ExpandedComponentInstanceSymbol componentSymbol = symTab.<ExpandedComponentInstanceSymbol>resolve(
"testing.demuxTest",
ExpandedComponentInstanceSymbol.KIND
).orElse(null);
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/testing");
List<File> files = generatorCPP.generateFiles(componentSymbol, symTab);
String restPath = "testing/";
testFilesAreEqual(files, restPath);
}
@Test
@Ignore("https://github.com/EmbeddedMontiArc/EMAM2Cpp/issues/14")
public void cppCodeForMyComponent4v2CanBeGenerated() throws IOException {
......
......@@ -6,9 +6,9 @@ component Min<T,N1 n=2> {
out T out1;
implementation Math{
T minVal=in(1);
T minVal=in1(1);
for i=1:n
minVal=min(minVal,in(i));
minVal=min(minVal,in1(i));
end
out1=minVal;
}
......
......@@ -6,9 +6,9 @@ component Multiplication<T,N1 n=2> {
out T out1;
implementation Math{
T outVal=in(1);
T outVal=in1(1);
for i=2:n
outVal=outVal*in(i);
outVal=outVal*in1(i);
end
out1=outVal;
}
......
......@@ -8,7 +8,7 @@ component Or<T,N1 n=2> {
implementation Math{
T outVal=in1(1);
for i=1:n
outVal=or(outVal,in(i));
outVal=or(outVal,in1(i));
end
out1=outVal;
}
......
......@@ -10,6 +10,6 @@ component Sum<T,N1 n=2> {
for i=2:n
outVal=outVal+in1(i);
end
out=outVal;
out1=outVal;
}
}
......@@ -15,10 +15,10 @@ void init()
void execute()
{
for( auto i=1;i<=n;++i){
valOut(i) = val1[i-1]*2;
valOut[i-1] = val1[i-1]*2;
}
for( auto i=1;i<=n;++i){
valOut(i) = val1[i-1]*3;
valOut[i-1] = val1[i-1]*3;
}
}
......
......@@ -15,10 +15,10 @@ void init()
void execute()
{
for( auto i=1;i<=n;++i){
valOut(i) = val1[i-1]*2;
valOut[i-1] = val1[i-1]*2;
}
for( auto i=1;i<=n;++i){
valOut(i) = val1[i-1]*3;
valOut[i-1] = val1[i-1]*3;
}
}
......
#ifndef TESTING_DEMUXTEST
#define TESTING_DEMUXTEST
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#include "octave/oct.h"
class testing_demuxTest{
public:
bool address[3];
double demux_input;
double demux_output[3];
void init()
{
}
void execute()
{
for( auto i=1;i<=3;i+=1){
if((address[i-1] == 1)){
demux_output[i-1] = demux_input;
}
}
}
};
#endif
package testing;
component DemuxTest
{
ports in B address[3],
in Q demux_input,
out Q demux_output[3];
implementation Math
{
for i=1:1:3
if address(i) == 1
demux_output(i) = demux_input;
end
end
}
}
\ No newline at end of file
Supports Markdown
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