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

updated cocos

parent 8a829b1b
......@@ -42,83 +42,94 @@ import java.util.stream.Collectors;
*/
public class SubComponentsConnected implements EmbeddedMontiArcASTComponentCoCo {
private Collection<String> getNames(Collection<PortSymbol> ports) {
return ports.stream().map(p -> p.getName())
.collect(Collectors.toList());
}
private Collection<String> getNames(Collection<PortSymbol> ports) {
return ports.stream().map(p -> p.getName())
.collect(Collectors.toList());
}
private Collection<String> getSourceNames(Collection<ConnectorSymbol> connectors) {
return connectors.stream().map(c -> c.getSource()).collect(Collectors.toList());
}
private Collection<String> getSourceNames(Collection<ConnectorSymbol> connectors) {
return connectors.stream().map(c -> c.getSource()).collect(Collectors.toList());
}
private Collection<String> getTargetNames(Collection<ConnectorSymbol> connectors) {
return connectors.stream().map(c -> c.getTarget()).collect(Collectors.toList());
}
private Collection<String> getTargetNames(Collection<ConnectorSymbol> connectors) {
return connectors.stream().map(c -> c.getTarget()).collect(Collectors.toList());
}
@Override
public void check(ASTComponent node) {
ComponentSymbol entry = (ComponentSymbol) node.getSymbol().get();
// Implemented on the symTab as it takes auto-instantiation into account which is not reflected
// in the AST.
for (ComponentInstanceSymbol sub : entry.getSubComponents()) {
// ------- IN PORTS -------
// in ports must be connected
// outer.in->sub.in
// outer.AnySub.out->sub.in
// connectors with sub.in as target occur in outer.connectors or as
// outer.AnySub.simpleconnectors
@Override
public void check(ASTComponent node) {
ComponentSymbol entry = (ComponentSymbol) node.getSymbol().get();
// Implemented on the symTab as it takes auto-instantiation into account which is not reflected
// in the AST.
for (ComponentInstanceSymbol sub : entry.getSubComponents()) {
// ------- IN PORTS -------
// in ports must be connected
// outer.in->sub.in
// outer.AnySub.out->sub.in
// connectors with sub.in as target occur in outer.connectors or as
// outer.AnySub.simpleconnectors
Collection<String> remainingSubIn = getNames(sub.getComponentType().getIncomingPorts());
// Connectors in the outer context always refer to the ports in a relative-qualified way (e.g.
// sub.portX) and hence we must prefix the remaining ones with sub's name to compare sets of
// relative-qualified names
remainingSubIn = remainingSubIn.stream().map(s -> sub.getName() + "." + s)
.collect(Collectors.toList());
Collection<String> remainingSubIn = getNames(sub.getComponentType().getIncomingPorts());
// Connectors in the outer context always refer to the ports in a relative-qualified way (e.g.
// sub.portX) and hence we must prefix the remaining ones with sub's name to compare sets of
// relative-qualified names
remainingSubIn = remainingSubIn.stream().map(s -> sub.getName() + "." + s)
.collect(Collectors.toList());
Collection<String> outerConnectorTargets = getTargetNames(entry.getConnectors());
remainingSubIn.removeAll(outerConnectorTargets);
if (!remainingSubIn.isEmpty()) {
Collection<String> outerSubSimpleConnectorTargets = getTargetNames(
entry.getSubComponents().stream()
.flatMap(sc -> sc.getSimpleConnectors().stream()).collect(Collectors.toList()));
remainingSubIn.removeAll(outerSubSimpleConnectorTargets);
if (!remainingSubIn.isEmpty()) {
for (String p : remainingSubIn) {
if (PortSymbol.isConstantPortName(p)) {
Collection<String> outerConnectorTargets = getTargetNames(entry.getConnectors());
remainingSubIn.removeAll(outerConnectorTargets);
if (!remainingSubIn.isEmpty()) {
Collection<String> outerSubSimpleConnectorTargets = getTargetNames(
entry.getSubComponents().stream()
.flatMap(sc -> sc.getSimpleConnectors().stream()).collect(Collectors.toList()));
remainingSubIn.removeAll(outerSubSimpleConnectorTargets);
if (!remainingSubIn.isEmpty()) {
} else {
Log.error(
String.format("0xAC008 Port %s of subcomponent %s is not used!", p,
sub.getFullName()),
node.get_SourcePositionStart());
}
}
/*
remainingSubIn.forEach(p -> Log.error(
String.format("0xAC008 Port %s of subcomponent %s is not used!", p,
sub.getFullName()),
node.get_SourcePositionStart()));
}
}
// ------- OUT PORTS -------
// sub.out->outer.out
// sub.out->outer.AnySub.in
// connectors with sub.out as source occur as outer.connectors or
// outer.AnySub.simpleConnectors
Collection<String> remainingSubOut = getNames(sub.getComponentType().getOutgoingPorts());
// Connectors in the outer context always refer to the ports in a relative-qualified way (e.g.
// sub.portX) and hence we must prefix the remaining ones with sub's name to compare sets of
// relative-qualified names
remainingSubOut = remainingSubOut.stream().map(s -> sub.getName() + "." + s)
.collect(Collectors.toList());
node.get_SourcePositionStart()));*/
}
}
// ------- OUT PORTS -------
// sub.out->outer.out
// sub.out->outer.AnySub.in
// connectors with sub.out as source occur as outer.connectors or
// outer.AnySub.simpleConnectors
Collection<String> remainingSubOut = getNames(sub.getComponentType().getOutgoingPorts());
// Connectors in the outer context always refer to the ports in a relative-qualified way (e.g.
// sub.portX) and hence we must prefix the remaining ones with sub's name to compare sets of
// relative-qualified names
remainingSubOut = remainingSubOut.stream().map(s -> sub.getName() + "." + s)
.collect(Collectors.toList());
Collection<String> outerConnectorSources = getSourceNames(entry.getConnectors());
remainingSubOut.removeAll(outerConnectorSources);
Collection<String> outerConnectorSources = getSourceNames(entry.getConnectors());
remainingSubOut.removeAll(outerConnectorSources);
if (!remainingSubOut.isEmpty()) {
// qualified sources of simple connectors
List<Object> outerSubSimpleConnectorSources = entry.getSubComponents().stream()
.flatMap(sc -> sc.getSimpleConnectors().stream()
// map connector to qualified source name
.map(c -> sc.getName() + "." + c.getSource()))
.collect(Collectors.toList());
remainingSubOut.removeAll(outerSubSimpleConnectorSources);
if (!remainingSubOut.isEmpty()) {
remainingSubOut.forEach(p -> Log.error(
String.format("0xAC009 Port %s of subcomponent %s is not used!", p,
sub.getFullName()),
node.get_SourcePositionStart()));
if (!remainingSubOut.isEmpty()) {
// qualified sources of simple connectors
List<Object> outerSubSimpleConnectorSources = entry.getSubComponents().stream()
.flatMap(sc -> sc.getSimpleConnectors().stream()
// map connector to qualified source name
.map(c -> sc.getName() + "." + c.getSource()))
.collect(Collectors.toList());
remainingSubOut.removeAll(outerSubSimpleConnectorSources);
if (!remainingSubOut.isEmpty()) {
remainingSubOut.forEach(p -> Log.error(
String.format("0xAC009 Port %s of subcomponent %s is not used!", p,
sub.getFullName()),
node.get_SourcePositionStart()));
}
}
}
}
}
}
}
......@@ -306,4 +306,13 @@ public class PortSymbol extends TaggingSymbol implements ElementInstance {
//TODO: Find the way to get connections from the top element
}
public static boolean isConstantPortName(String name){
if(name.contains(".")){
String secondPart=name.split("\\.")[1];
return secondPart.startsWith("CONSTANTPORT");
}else{
return name.startsWith("CONSTANTPORT");
}
}
}
......@@ -102,6 +102,7 @@ public class ExpandedComponentInstanceTest extends AbstractSymtabTest {
@Test
public void testConnectorInstancing() {
ConstantPortSymbol.resetLastID();
Scope symTab = createSymTab("src/test/resources");
ExpandedComponentInstanceSymbol inst = symTab.<ExpandedComponentInstanceSymbol>resolve(
"testing.connectorInstancing", ExpandedComponentInstanceSymbol.KIND).orElse(null);
......@@ -156,23 +157,24 @@ public class ExpandedComponentInstanceTest extends AbstractSymtabTest {
assertEquals("RangeType", inst2.getSubComponent("sgc2").get().getPort("tOut").get().getTypeReference().getName());
*/
}
@Test
public void testBasicParameterInstance(){
public void testBasicParameterInstance() {
Scope symTab = createSymTab("src/test/resources");
ExpandedComponentInstanceSymbol inst = symTab.<ExpandedComponentInstanceSymbol>resolve(
"testing.basicParameterInstance", ExpandedComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(inst);
System.out.println(inst);
assertEquals(1,inst.getSubComponents().iterator().next().getParameters().size());
for(ASTExpression astExpression:inst.getSubComponents().iterator().next().getArguments()){
Log.info(astExpression.toString(),"info:");
assertEquals(1, inst.getSubComponents().iterator().next().getParameters().size());
for (ASTExpression astExpression : inst.getSubComponents().iterator().next().getArguments()) {
Log.info(astExpression.toString(), "info:");
}
assertEquals(1,inst.getSubComponents().iterator().next().getArguments().size());
assertEquals(1, inst.getSubComponents().iterator().next().getArguments().size());
}
@Test
public void testExtensionMechanism1(){
public void testExtensionMechanism1() {
Scope symTab = createSymTab("src/test/resources");
ExpandedComponentInstanceSymbol inst = symTab.<ExpandedComponentInstanceSymbol>resolve(
"a.superCompExtension", ExpandedComponentInstanceSymbol.KIND).orElse(null);
......@@ -183,7 +185,7 @@ public class ExpandedComponentInstanceTest extends AbstractSymtabTest {
}
@Test
public void testExtensionMechanism2(){
public void testExtensionMechanism2() {
Scope symTab = createSymTab("src/test/resources");
ExpandedComponentInstanceSymbol inst = symTab.<ExpandedComponentInstanceSymbol>resolve(
"a.superCompGenericExtension", ExpandedComponentInstanceSymbol.KIND).orElse(null);
......@@ -196,7 +198,7 @@ public class ExpandedComponentInstanceTest extends AbstractSymtabTest {
//Currently not working
@Ignore
@Test
public void testExtensionMechanism3(){
public void testExtensionMechanism3() {
Scope symTab = createSymTab("src/test/resources");
ExpandedComponentInstanceSymbol inst = symTab.<ExpandedComponentInstanceSymbol>resolve(
"a.superCompGenericGenericExtensionInstance", ExpandedComponentInstanceSymbol.KIND).orElse(null);
......
......@@ -34,13 +34,13 @@ public class ComponentInstanceNamesUniqueTest extends AbstractCoCoTest {
public static void setUp() {
Log.enableFailQuick(false);
}
@Ignore
//@Ignore
@Test
public void testValid() {
checkValid("", "testing.UniqueName");
}
@Ignore
//@Ignore
@Test
public void testInvalid() {
checkInvalid(new EmbeddedMontiArcCoCoChecker().addCoCo(new SourceTargetNumberMatch()),
......
......@@ -35,7 +35,7 @@ public class SourceTargetNumberMatchTest extends AbstractCoCoTest {
Log.enableFailQuick(false);
}
@Ignore
//@Ignore
@Test
public void testValid() {
checkValid("", "testing.CorrectPortNumber");
......
......@@ -34,13 +34,13 @@ public class UniquePortsTest extends AbstractCoCoTest {
public static void setUp() {
Log.enableFailQuick(false);
}
@Ignore
//@Ignore
@Test
public void testValid() {
checkValid("", "testing.UniqueName");
}
@Ignore
//@Ignore
@Test
public void testInvalid() {
checkInvalid(new EmbeddedMontiArcCoCoChecker().addCoCo(new SourceTargetNumberMatch()),
......
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