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

Symbols do not contain info about range

parent 9a5fedf7
Pipeline #61379 failed with stage
in 1 minute and 49 seconds
...@@ -12,6 +12,7 @@ import de.monticore.lang.monticar.generator.cpp.converter.TypeConverter; ...@@ -12,6 +12,7 @@ import de.monticore.lang.monticar.generator.cpp.converter.TypeConverter;
import de.monticore.lang.monticar.generator.cpp.template.AllTemplates; import de.monticore.lang.monticar.generator.cpp.template.AllTemplates;
import de.monticore.lang.monticar.generator.cpp.viewmodel.AutopilotAdapterViewModel; import de.monticore.lang.monticar.generator.cpp.viewmodel.AutopilotAdapterViewModel;
import de.monticore.lang.monticar.generator.cpp.viewmodel.ServerWrapperViewModel; import de.monticore.lang.monticar.generator.cpp.viewmodel.ServerWrapperViewModel;
import de.monticore.lang.monticar.generator.testing.StreamTestGenerator;
import de.monticore.lang.monticar.ts.MCTypeSymbol; import de.monticore.lang.monticar.ts.MCTypeSymbol;
import de.monticore.lang.tagging._symboltable.TaggingResolver; import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.monticore.symboltable.Scope; import de.monticore.symboltable.Scope;
...@@ -47,6 +48,7 @@ public class GeneratorCPP implements Generator { ...@@ -47,6 +48,7 @@ public class GeneratorCPP implements Generator {
protected boolean generateMainClass = false; protected boolean generateMainClass = false;
protected boolean generateSimulatorInterface = false; protected boolean generateSimulatorInterface = false;
protected boolean checkModelDir = false; protected boolean checkModelDir = false;
protected boolean streamTestGenerationMode = false;
public GeneratorCPP() { public GeneratorCPP() {
this.mathCommandRegister = new MathCommandRegisterCPP(); this.mathCommandRegister = new MathCommandRegisterCPP();
...@@ -55,11 +57,14 @@ public class GeneratorCPP implements Generator { ...@@ -55,11 +57,14 @@ public class GeneratorCPP implements Generator {
currentInstance = this; currentInstance = this;
} }
public void useArmadilloBackend() { public void useArmadilloBackend() {
MathConverter.curBackend = new ArmadilloBackend(); MathConverter.curBackend = new ArmadilloBackend();
} }
public void useStreamTestTestGeneration() {
streamTestGenerationMode = true;
}
public void useOctaveBackend() { public void useOctaveBackend() {
MathConverter.curBackend = new OctaveBackend(); MathConverter.curBackend = new OctaveBackend();
//Log.warn("This backend has been deprecated. Armadillo is the recommended backend now."); //Log.warn("This backend has been deprecated. Armadillo is the recommended backend now.");
...@@ -83,13 +88,16 @@ public class GeneratorCPP implements Generator { ...@@ -83,13 +88,16 @@ public class GeneratorCPP implements Generator {
@Override @Override
public String generateString(TaggingResolver taggingResolver, ExpandedComponentInstanceSymbol componentSymbol, MathStatementsSymbol mathStatementsSymbol) { public String generateString(TaggingResolver taggingResolver, ExpandedComponentInstanceSymbol componentSymbol, MathStatementsSymbol mathStatementsSymbol) {
StreamTestGenerator streamTestGenerator = new StreamTestGenerator();//only used when creating streamTestsForAComponent
LanguageUnitCPP languageUnitCPP = new LanguageUnitCPP(); LanguageUnitCPP languageUnitCPP = new LanguageUnitCPP();
languageUnitCPP.setGeneratorCPP(this); languageUnitCPP.setGeneratorCPP(this);
languageUnitCPP.addSymbolToConvert(componentSymbol); languageUnitCPP.addSymbolToConvert(componentSymbol);
if (mathStatementsSymbol != null) if (mathStatementsSymbol != null)
languageUnitCPP.addSymbolToConvert(mathStatementsSymbol); languageUnitCPP.addSymbolToConvert(mathStatementsSymbol);
languageUnitCPP.generateBluePrints(); if (!streamTestGenerationMode)
languageUnitCPP.generateBluePrints();
else
streamTestGenerator.createStreamTest(componentSymbol);
BluePrintCPP bluePrintCPP = null; BluePrintCPP bluePrintCPP = null;
for (BluePrint bluePrint : languageUnitCPP.getBluePrints()) { for (BluePrint bluePrint : languageUnitCPP.getBluePrints()) {
if (bluePrint.getOriginalSymbol().equals(componentSymbol)) { if (bluePrint.getOriginalSymbol().equals(componentSymbol)) {
...@@ -100,8 +108,11 @@ public class GeneratorCPP implements Generator { ...@@ -100,8 +108,11 @@ public class GeneratorCPP implements Generator {
if (bluePrintCPP != null) { if (bluePrintCPP != null) {
bluePrints.add(bluePrintCPP); bluePrints.add(bluePrintCPP);
} }
String result;
String result = languageUnitCPP.getGeneratedHeader(taggingResolver, bluePrintCPP); if (!streamTestGenerationMode)
result = languageUnitCPP.getGeneratedHeader(taggingResolver, bluePrintCPP);
else
result = streamTestGenerator.getCurrentGeneratedStreamTest().toString();
return result; return result;
} }
...@@ -365,8 +376,8 @@ public class GeneratorCPP implements Generator { ...@@ -365,8 +376,8 @@ public class GeneratorCPP implements Generator {
private static FileContent generateServerWrapper(ExpandedComponentInstanceSymbol componentSymbol) { private static FileContent generateServerWrapper(ExpandedComponentInstanceSymbol componentSymbol) {
return generateWrapper(componentSymbol, "server.cc"); return generateWrapper(componentSymbol, "server.cc");
} }
private static FileContent generateWrapper(ExpandedComponentInstanceSymbol componentSymbol, String name) { private static FileContent generateWrapper(ExpandedComponentInstanceSymbol componentSymbol, String name) {
ServerWrapperViewModel vm = new ServerWrapperViewModel(); ServerWrapperViewModel vm = new ServerWrapperViewModel();
vm.setMainModelName(GeneralHelperMethods.getTargetLanguageComponentName(componentSymbol.getFullName())); vm.setMainModelName(GeneralHelperMethods.getTargetLanguageComponentName(componentSymbol.getFullName()));
String fileContents = AllTemplates.generateServerWrapper(vm); String fileContents = AllTemplates.generateServerWrapper(vm);
......
package de.monticore.lang.monticar.generator.testing;
/**
* @author Sascha Schneiders
*/
public class StreamGenerator {
}
...@@ -7,7 +7,52 @@ import java.util.List; ...@@ -7,7 +7,52 @@ import java.util.List;
* @author Sascha Schneiders * @author Sascha Schneiders
*/ */
public class StreamTest { public class StreamTest {
List<StreamTestPort> ports = new ArrayList<>(); protected String name;
protected String packageName;
protected String componentName;
protected List<StreamTestPort> ports = new ArrayList<>();
public StreamTest() {
}
public List<StreamTestPort> getPorts() {
return ports;
}
public void setPorts(List<StreamTestPort> ports) {
this.ports = ports;
}
public void addPort(StreamTestPort port) {
this.ports.add(port);
}
@Override
public String toString() {
StringBuilder result = new StringBuilder();
result.append("package ");
result.append(packageName);
result.append(";\n");
result.append("stream ");
result.append(name);
result.append(" for ");
result.append(componentName);
result.append("{\n");
for (StreamTestPort port : ports) {
result.append(port.getName());
result.append(": ");
for (int i = 0; i < port.getValues().size(); ++i) {
StreamTestValue value = port.getValues().get(i);
result.append(value.getStringRepresentation());
result.append(" ");
if (i + 1 < port.getValues().size())
result.append("tick ");
}
result.append(";\n");
}
result.append("}");
return result.toString();
}
} }
package de.monticore.lang.monticar.generator.testing;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.monticar.ts.MontiCarTypeSymbol;
import de.monticore.lang.monticar.ts.references.CommonMCTypeReference;
import de.monticore.lang.monticar.ts.references.MCASTTypeSymbolReference;
import java.util.Collection;
/**
* @author Sascha Schneiders
*/
public class StreamTestGenerator {
protected StreamTest currentGeneratedStreamTest;
public void createStreamTest(ExpandedComponentInstanceSymbol expandedComponentInstanceSymbol) {
//TODO write stream test creation based on input ports with random values in input range
currentGeneratedStreamTest = new StreamTest();
Collection<PortSymbol> inPorts = expandedComponentInstanceSymbol.getIncomingPorts();
for (PortSymbol p : inPorts) {
System.out.println(p.getTypeReference().getClass().getName());
if (p.getTypeReference().getName().equals("CommonMatrixType")) {
//TODO handle commonMatrixType
MCASTTypeSymbolReference typeReference = (MCASTTypeSymbolReference) p.getTypeReference();
System.out.println(typeReference.getActualTypeArguments().size());
if (typeReference.getAstNode().isPresent())
System.out.println(p.getTypeReference().getAstNode().get().getClass().getName());
} else if (p.getTypeReference().getName().equals("Q")) {
CommonMCTypeReference typeReference = (CommonMCTypeReference) p.getTypeReference();
System.out.println(typeReference.getReferencedSymbol().getName());
MontiCarTypeSymbol typeSymbol = (MontiCarTypeSymbol) typeReference.getReferencedSymbol();
System.out.println(typeSymbol.getFormalTypeParameters().size());
System.out.println(typeSymbol.getInterfaces().size());
if (typeReference.getAstNode().isPresent())
System.out.println(p.getTypeReference().getAstNode().get().getClass().getName());
} else if (p.getTypeReference().getName().equals("Z")) {
CommonMCTypeReference typeReference = (CommonMCTypeReference) p.getTypeReference();
if (typeReference.getAstNode().isPresent())
System.out.println(p.getTypeReference().getAstNode().get().getClass().getName());
} else if (p.getTypeReference().getName().equals("N")) {
CommonMCTypeReference typeReference = (CommonMCTypeReference) p.getTypeReference();
if (typeReference.getAstNode().isPresent())
System.out.println(p.getTypeReference().getAstNode().get().getClass().getName());
}
System.out.println();
}
}
public StreamTest getCurrentGeneratedStreamTest() {
return currentGeneratedStreamTest;
}
}
package de.monticore.lang.monticar.generator.cpp;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.monticar.generator.AbstractSymtabTest;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
import de.se_rwth.commons.logging.Log;
import org.junit.BeforeClass;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import java.util.List;
import static org.junit.Assert.assertNotNull;
/**
* @author Sascha Schneiders
*/
public class StreamTestGenerationTest extends AbstractSymtabTest {
@BeforeClass
public static void setUp() {
// ensure an empty log
Log.getFindings().clear();
Log.enableFailQuick(false);
}
@Test
public void testStreamTestAutopilotTestGen() throws IOException {
TaggingResolver symtab = createSymTabAndTaggingResolver("src/test/resources");
ExpandedComponentInstanceSymbol componentSymbol = symtab.<ExpandedComponentInstanceSymbol>resolve("de.rwth.armin.modeling.autopilot.autopilot", ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentSymbol);
GeneratorCPP generatorCPP = new GeneratorCPP();
generatorCPP.useStreamTestTestGeneration();
generatorCPP.setGenerationTargetPath("./target/generated-sources-cpp/streamtest/autopilot/");
generatorCPP.useArmadilloBackend();
List<File> files = generatorCPP.generateFiles(symtab, componentSymbol, symtab);
String restPath = "streamtest/autopilot";
testFilesAreEqual(files, restPath);
}
}
package de.rwth.armin.modeling.autopilot;
component Tests {
port in B in1, out B out1;
instance de.rwth.armin.modeling.autopilot.common.Tests t1;
instance de.rwth.armin.modeling.autopilot.motion.Tests t2;
instance de.rwth.armin.modeling.autopilot.behavior.Tests t3;
}
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