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,18 +314,15 @@ public class EmbeddedMontiArcSymbolTableCreator extends EmbeddedMontiArcSymbolTa ...@@ -314,18 +314,15 @@ public class EmbeddedMontiArcSymbolTableCreator extends EmbeddedMontiArcSymbolTa
@Override @Override
public void visit(ASTConnector node) { public void visit(ASTConnector node) {
doConnectorResolution(node, this); doConnectorResolution(node, this);
ASTQualifiedNameWithArrayAndStar portName;
List<String> sourceNames = null;
boolean isConstant = false;
if (node.getSourceOpt().isPresent()) { if (node.getSourceOpt().isPresent()) {
portName = node.getSource(); if(node.getSource().isPresentDotStar()) {
sourceNames = getPortName(portName, this); starConnectorSetup(node, this);
} else { } else {
isConstant = true; nonConstantPortSetup(node, this);
constantPortSetup(node, this);
} }
if (!isConstant) { } else {
nonConstantPortSetup(sourceNames, node, this); constantPortSetup(node, this);
} }
} }
......
...@@ -305,11 +305,56 @@ public class EMAPortHelper { ...@@ -305,11 +305,56 @@ public class EMAPortHelper {
return counter; return counter;
} }
public static void nonConstantPortSetup(List<String> sourceNames, public static void starConnectorSetup(de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.
de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.
ASTConnector node, EmbeddedMontiArcSymbolTableCreator ASTConnector node, EmbeddedMontiArcSymbolTableCreator
symbolTableCreator) { 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"); Log.info("" + sourceNames.size(), "SourcePorts");
int counter = 0, targetnum = 0; int counter = 0, targetnum = 0;
for (ASTQualifiedNameWithArrayAndStar target : node.getTargets().getQualifiedNameWithArrayAndStarList()) { for (ASTQualifiedNameWithArrayAndStar target : node.getTargets().getQualifiedNameWithArrayAndStarList()) {
...@@ -336,6 +381,13 @@ public class EMAPortHelper { ...@@ -336,6 +381,13 @@ public class EMAPortHelper {
/* if(counter!=targetnum) { Log.error("source port number "+ counter +" and target port num"+ /* if(counter!=targetnum) { Log.error("source port number "+ counter +" and target port num"+
* targetnum+" don't match"); } */ * 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( public static void constantPortSetup(
......
...@@ -37,6 +37,7 @@ import org.junit.BeforeClass; ...@@ -37,6 +37,7 @@ import org.junit.BeforeClass;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
...@@ -821,5 +822,47 @@ public class SymtabTest extends AbstractSymtabTest { ...@@ -821,5 +822,47 @@ public class SymtabTest extends AbstractSymtabTest {
assertNotNull(portInstanceSymbol3); 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; package testing;
component StarConnector { component StarConnector {
ports in B in1, ports in B in1,
in B in2, in B in2,
in B in3, in B in3,
out B out1, out B out1,
out B out2; out B out2;
component A{ component A{
ports in B in1, ports in B in1,
in B in2, in B in2,
out B out1, out B out1,
out B out2; out B out2;
} }
instance A a; instance A a;
connect this.* -> a.*; connect this.* -> a.*;
......
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