Commit 295f5b83 authored by Alexander David Hellwig's avatar Alexander David Hellwig
Browse files

Added support for Generics iff Q,B,Z

parent fe50b6f2
......@@ -133,42 +133,38 @@ public class GeneratorRosMsg {
public static RosMsg getRosType(String packageName, MCTypeReference<? extends MCTypeSymbol> typeReference) {
MCTypeSymbol type = typeReference.getReferencedSymbol();
if (type.isKindOf(MCASTTypeSymbol.KIND)) {
MCASTTypeSymbol mcastTypeSymbol = (MCASTTypeSymbol) type;
if (mcastTypeSymbol.getName().equals("Q")) {
RosMsg tmpMsg = new RosMsg("std_msgs/Float64");
tmpMsg.addField(new RosField("data", new RosType("float64")));
return tmpMsg;
} else if (mcastTypeSymbol.getName().equals("Z")) {
RosMsg tmpMsg = new RosMsg("std_msgs/Int32");
tmpMsg.addField(new RosField("data", new RosType("int32")));
return tmpMsg;
} else if (mcastTypeSymbol.getName().equals("B")) {
RosMsg tmpMsg = new RosMsg("std_msgs/Bool");
tmpMsg.addField(new RosField("data", new RosType("bool")));
return tmpMsg;
} else if (mcastTypeSymbol.getName().equals("CommonMatrixType")) {
ASTCommonMatrixType matrixType = (ASTCommonMatrixType) mcastTypeSymbol.getAstType();
String tmpMsgName = "";
String tmpTypeName = "";
if (matrixType.getElementType().isIsRational()) {
tmpMsgName = "std_msgs/Float64MultiArray";
tmpTypeName = "float64";
} else if (matrixType.getElementType().isIsWholeNumberNumber()) {
tmpMsgName = "std_msgs/Int32MultiArray";
tmpTypeName = "int32";
} else if (matrixType.getElementType().isIsBoolean()) {
//TODO: BoolMultiArray?
tmpMsgName = "std_msgs/ByteMultiArray";
tmpTypeName = "byte";
} else {
Log.error("Matrix type not supported: " + matrixType);
}
//TODO: refactor
return getMultMatrixRosMsg(tmpMsgName, tmpTypeName);
String typeName = type.getName();
if (typeName.equals("Q")) {
RosMsg tmpMsg = new RosMsg("std_msgs/Float64");
tmpMsg.addField(new RosField("data", new RosType("float64")));
return tmpMsg;
} else if (typeName.equals("Z")) {
RosMsg tmpMsg = new RosMsg("std_msgs/Int32");
tmpMsg.addField(new RosField("data", new RosType("int32")));
return tmpMsg;
} else if (typeName.equals("B")) {
RosMsg tmpMsg = new RosMsg("std_msgs/Bool");
tmpMsg.addField(new RosField("data", new RosType("bool")));
return tmpMsg;
} else if (typeName.equals("CommonMatrixType") && type.isKindOf(MCASTTypeSymbol.KIND)) {
ASTCommonMatrixType matrixType = (ASTCommonMatrixType) ((MCASTTypeSymbol) type).getAstType();
String tmpMsgName = "";
String tmpTypeName = "";
if (matrixType.getElementType().isIsRational()) {
tmpMsgName = "std_msgs/Float64MultiArray";
tmpTypeName = "float64";
} else if (matrixType.getElementType().isIsWholeNumberNumber()) {
tmpMsgName = "std_msgs/Int32MultiArray";
tmpTypeName = "int32";
} else if (matrixType.getElementType().isIsBoolean()) {
tmpMsgName = "std_msgs/ByteMultiArray";
tmpTypeName = "byte";
} else {
Log.error("Case not handled! MCASTTypeSymbol " + mcastTypeSymbol.getName());
Log.error("Matrix type not supported: " + matrixType);
}
//TODO: refactor
return getMultMatrixRosMsg(tmpMsgName, tmpTypeName);
}
if (type instanceof StructSymbol) {
......
......@@ -144,6 +144,21 @@ public class BasicTypesTest extends AbstractSymtabTest {
testFilesAreEqual(files, "multinestedStruct/");
}
@Test
public void testGenericCompInstance() {
Scope symtab = createSymTab("src/test/resources/");
ExpandedComponentInstanceSymbol component = symtab.<ExpandedComponentInstanceSymbol>resolve("tests.genericCompInstance", ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(component);
RosMsg typeB = GeneratorRosMsg.getRosType("struct_msgs", component.getSubComponent("instB").get().getPort("in1").get().getTypeReference());
RosMsg typeQ = GeneratorRosMsg.getRosType("struct_msgs", component.getSubComponent("instQ").get().getPort("in1").get().getTypeReference());
RosMsg typeZ = GeneratorRosMsg.getRosType("struct_msgs", component.getSubComponent("instZ").get().getPort("in1").get().getTypeReference());
assertTrue(typeB.getName().equals("std_msgs/Bool"));
assertTrue(typeQ.getName().equals("std_msgs/Float64"));
assertTrue(typeZ.getName().equals("std_msgs/Int32"));
}
public RosMsg getBasicStruct(String packageName) {
RosMsg res = new RosMsg(packageName + "/structs_BasicStruct");
res.addField(new RosField("fieldQ1", new RosType("float64")));
......
package tests;
component GenericComp<T>{
port in T in1;
}
\ No newline at end of file
package tests;
component GenericCompInstance{
instance GenericComp<B> instB;
instance GenericComp<Q> instQ;
instance GenericComp<Z> instZ;
//Not supported: no way of getting the matrix type
//instance GenericComp<B^{3,1}> instBMat;
//instance GenericComp<Q^{3,1}> instQMat;
//instance GenericComp<Z^{3,1}> instZMat;
}
\ 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