Commit a97ea81b authored by Ferdinand Alexander Mehlan's avatar Ferdinand Alexander Mehlan
Browse files

Add starconnectors to stc

parent ad9ca53d
Pipeline #69320 passed with stage
in 3 minutes and 7 seconds
......@@ -314,19 +314,16 @@ public class EmbeddedMontiArcSymbolTableCreator extends EmbeddedMontiArcSymbolTa
@Override
public void visit(ASTConnector node) {
doConnectorResolution(node, this);
ASTQualifiedNameWithArrayAndStar portName;
List<String> sourceNames = null;
boolean isConstant = false;
if (node.getSourceOpt().isPresent()) {
portName = node.getSource();
sourceNames = getPortName(portName, this);
if(node.getSource().isPresentDotStar()) {
starConnectorSetup(node, this);
} else {
nonConstantPortSetup(node, this);
}
} else {
isConstant = true;
constantPortSetup(node, this);
}
if (!isConstant) {
nonConstantPortSetup(sourceNames, node, this);
}
}
......
......@@ -305,11 +305,56 @@ public class EMAPortHelper {
return counter;
}
public static void nonConstantPortSetup(List<String> sourceNames,
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.
public static void starConnectorSetup(de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.
ASTConnector node, EmbeddedMontiArcSymbolTableCreator
symbolTableCreator) {
String sourceCmpName = node.getSource().getQualifiedNameWithArray().isPresentCompName() ? node.getSource().getQualifiedNameWithArray().getCompName() + "." : "";
sourceCmpName += node.getSource().getQualifiedNameWithArray().getPortName();
String targetCmpName = node.getTargets().getQualifiedNameWithArrayAndStar(0).getQualifiedNameWithArray().isPresentCompName() ?
node.getTargets().getQualifiedNameWithArrayAndStar(0).getQualifiedNameWithArray().getCompName() + "." : "";
targetCmpName += node.getTargets().getQualifiedNameWithArrayAndStar(0).getQualifiedNameWithArray().getPortName();
EMAComponentSymbol sourceCmp, targetCmp;
if(sourceCmpName.equals("this")) {
sourceCmp = symbolTableCreator.componentStack.peek();
targetCmp = sourceCmp.getSubComponent(targetCmpName).get().getComponentType().getReferencedSymbol();
for(EMAPortSymbol from : sourceCmp.getIncomingPorts()) {
for (EMAPortSymbol to : targetCmp.getIncomingPorts()) {
if (from.getName().equals(to.getName())) {
EMAConnectorSymbol connector = new EMAConnectorSymbol(to.getName());
connector.setSource(from.getName());
connector.setTarget(targetCmpName + "." + to.getName());
symbolTableCreator.addToScopeAndLinkWithNode(connector, node);
}
}
}
} else if(targetCmpName.equals("this")) {
targetCmp = symbolTableCreator.componentStack.peek();
sourceCmp = targetCmp.getSubComponent(sourceCmpName).get().getComponentType().getReferencedSymbol();
for(EMAPortSymbol from : sourceCmp.getOutgoingPorts()) {
for (EMAPortSymbol to : targetCmp.getOutgoingPorts()) {
if (from.getName().equals(to.getName())) {
EMAConnectorSymbol connector = new EMAConnectorSymbol(to.getName());
connector.setSource(sourceCmpName + "." + from.getName());
connector.setTarget(to.getName());
symbolTableCreator.addToScopeAndLinkWithNode(connector, node);
}
}
}
} else {
}
}
public static void nonConstantPortSetup(de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.
ASTConnector node, EmbeddedMontiArcSymbolTableCreator
symbolTableCreator) {
List<String> sourceNames = getPortName(node.getSource(), symbolTableCreator);
Log.info("" + sourceNames.size(), "SourcePorts");
int counter = 0, targetnum = 0;
for (ASTQualifiedNameWithArrayAndStar target : node.getTargets().getQualifiedNameWithArrayAndStarList()) {
......@@ -336,6 +381,13 @@ public class EMAPortHelper {
/* if(counter!=targetnum) { Log.error("source port number "+ counter +" and target port num"+
* targetnum+" don't match"); } */
}
if (node.getTargets().isHASH()) {
String sourceName = getPortName(node.getSource(), symbolTableCreator).get(0);
EMAConnectorSymbol sym = new EMAConnectorSymbol("#");
sym.setSource(sourceName);
sym.setTarget("#");
symbolTableCreator.addToScopeAndLinkWithNode(sym, node);
}
}
public static void constantPortSetup(
......
......@@ -37,6 +37,7 @@ import org.junit.BeforeClass;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
......@@ -821,5 +822,47 @@ public class SymtabTest extends AbstractSymtabTest {
assertNotNull(portInstanceSymbol3);
}
@Test
public void starConnectorsTest() {
Scope symTab = createSymTab("src/test/resources");
EMAComponentSymbol component = symTab.<EMAComponentSymbol>resolve("testing.StarConnector", EMAComponentSymbol.KIND).orElse(null);
assertNotNull(component);
Collection<EMAConnectorSymbol> connectors = component.getConnectors();
assertEquals(5, connectors.size());
EMAConnectorSymbol connector = component.getConnector("a.in1").orElse(null);
assertNotNull(connector);
assertEquals("in1", connector.getSource());
assertEquals("a.in1", connector.getTarget());
assertTrue(connectors.contains(connector));
connector = component.getConnector("a.in1").orElse(null);
assertNotNull(connector);
assertEquals("in1", connector.getSource());
assertEquals("a.in1", connector.getTarget());
assertTrue(connectors.contains(connector));
connector = component.getConnector("out1").orElse(null);
assertNotNull(connector);
assertEquals("a.out1", connector.getSource());
assertEquals("out1", connector.getTarget());
assertTrue(connectors.contains(connector));
connector = component.getConnector("out1").orElse(null);
assertNotNull(connector);
assertEquals("a.out1", connector.getSource());
assertEquals("out1", connector.getTarget());
assertTrue(connectors.contains(connector));
connector = component.getConnector("#").orElse(null);
assertNotNull(connector);
assertEquals("in3", connector.getSource());
assertEquals("#", connector.getTarget());
assertTrue(connectors.contains(connector));
}
}
package testing;
component StarConnector {
ports in B in1,
in B in2,
in B in3,
out B out1,
out B out2;
component A{
ports in B in1,
in B in2,
out B out1,
out B out2;
}
instance A a;
connect this.* -> a.*;
// equivalent to:
// * connect in1 -> a.in1;
// * connect in2 -> a.in2;
// it will not connect in3
// * connect in1 -> a.in1;
// * connect in2 -> a.in2;
// it will not connect in3
connect a.* -> this.*;
// equivalent to:
// * connect a.out1 -> out1;
// * connect a.out2 -> out2;
// * connect a.out1 -> out1;
// * connect a.out2 -> out2;
// terminate unused input port in3 to avoid a warning that the port is not used
connect in3 -> #;
......
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