Commit 54203729 authored by vonWenckstern's avatar vonWenckstern
Browse files

modified grammar (and adpated AST classes to work with old features)

* added "connect this.* -> sub1.*;" as new name-based autoconnection
* added "connect unusedPort -> #;" to terminate the not used input port (this is needed for library components, e.g. FlipFlop, where only the Q port is needed and the notQ port is not needed to avoid errors)
parent 86758879
Pipeline #69029 passed with stage
in 2 minutes and 40 seconds
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
<groupId>de.monticore.lang.monticar</groupId> <groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc</artifactId> <artifactId>embedded-montiarc</artifactId>
<version>0.1.4-SNAPSHOT</version> <version>0.1.5-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= --> <!-- == PROJECT DEPENDENCIES ============================================= -->
......
...@@ -163,6 +163,17 @@ grammar EmbeddedMontiArc extends de.monticore.lang.monticar.Common2 { ...@@ -163,6 +163,17 @@ grammar EmbeddedMontiArc extends de.monticore.lang.monticar.Common2 {
Name Name
("[" UnitNumberResolution "]")? ; ("[" UnitNumberResolution "]")? ;
/**
* port1
* port1[2]
* port1[:]
* sub1.port1
* sub1[2].port1[3]
* sub1.*
* sub1[2].*
*/
QualifiedNameWithArrayAndStar = QualifiedNameWithArray DotStar?;
DotStar = "." {noSpace()}? "*";
/** /**
* A connector connects one source port with one or many * A connector connects one source port with one or many
* target ports. * target ports.
...@@ -173,10 +184,14 @@ grammar EmbeddedMontiArc extends de.monticore.lang.monticar.Common2 { ...@@ -173,10 +184,14 @@ grammar EmbeddedMontiArc extends de.monticore.lang.monticar.Common2 {
* instance names * instance names
*/ */
Connector implements Element= Connector implements Element=
"connect" (source:QualifiedNameWithArray | (boolLiteral:BooleanLiteral) | (stringLiteral:StringLiteral)| UnitNumberResolution) "->" "connect" (source:QualifiedNameWithArrayAndStar |
boolLiteral:BooleanLiteral |
stringLiteral:StringLiteral|
UnitNumberResolution) "->"
targets:ConnectorTargets ";" ; targets:ConnectorTargets ";" ;
ConnectorTargets = (QualifiedNameWithArray (",")? )+; ConnectorTargets = ["#"] | // route symbol terminates inputs
(QualifiedNameWithArrayAndStar || "," )+;
// autoconnect and autoinstantiate is removed // autoconnect and autoinstantiate is removed
// for autoconnect use "connect this.* -> sub1.*;" to connect all inports of the parent component to the inports of the sub1 subcomponent having the same name // for autoconnect use "connect this.* -> sub1.*;" to connect all inports of the parent component to the inports of the sub1 subcomponent having the same name
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
package de.monticore.lang.embeddedmontiarc.cocos; package de.monticore.lang.embeddedmontiarc.cocos;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTConnector; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTConnector;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTQualifiedNameWithArrayAndStar;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._cocos.EmbeddedMontiArcASTConnectorCoCo; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._cocos.EmbeddedMontiArcASTConnectorCoCo;
import de.monticore.lang.monticar.common2._ast.ASTQualifiedNameWithArray; import de.monticore.lang.monticar.common2._ast.ASTQualifiedNameWithArray;
import de.se_rwth.commons.logging.Log; import de.se_rwth.commons.logging.Log;
...@@ -62,14 +63,14 @@ public class ConnectorEndPointCorrectlyQualified ...@@ -62,14 +63,14 @@ public class ConnectorEndPointCorrectlyQualified
@Override @Override
public void check(ASTConnector node) { public void check(ASTConnector node) {
if (node.getSourceOpt().isPresent()) { if (node.getSourceOpt().isPresent()) {
checkEndPointMaximallyTwiceQualified(node.getSource()); checkEndPointMaximallyTwiceQualified(node.getSource().getQualifiedNameWithArray());
} else { } else {
if (!node.getUnitNumberResolutionOpt().isPresent() && !node.getBoolLiteralOpt().isPresent()) if (!node.getUnitNumberResolutionOpt().isPresent() && !node.getBoolLiteralOpt().isPresent())
Log.error("Error Connector has no valid source or constant " + node.toString()); Log.error("Error Connector has no valid source or constant " + node.toString());
} }
for (ASTQualifiedNameWithArray name : node.getTargets().getQualifiedNameWithArrayList()) { for (ASTQualifiedNameWithArrayAndStar name : node.getTargets().getQualifiedNameWithArrayAndStarList()) {
checkEndPointMaximallyTwiceQualified(name); checkEndPointMaximallyTwiceQualified(name.getQualifiedNameWithArray());
} }
} }
......
...@@ -73,8 +73,8 @@ public class InPortUniqueSender implements EmbeddedMontiArcASTComponentCoCo { ...@@ -73,8 +73,8 @@ public class InPortUniqueSender implements EmbeddedMontiArcASTComponentCoCo {
private void checkConnectors() { private void checkConnectors() {
for (ASTConnector connector : node.getConnectors()) { for (ASTConnector connector : node.getConnectors()) {
for (ASTQualifiedNameWithArray target : connector.getTargets().getQualifiedNameWithArrayList()) { for (ASTQualifiedNameWithArrayAndStar target : connector.getTargets().getQualifiedNameWithArrayAndStarList()) {
checkTarget(target); checkTarget(target.getQualifiedNameWithArray());
} }
} }
} }
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
package de.monticore.lang.embeddedmontiarc.cocos; package de.monticore.lang.embeddedmontiarc.cocos;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTConnector; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTConnector;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTQualifiedNameWithArrayAndStar;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._cocos.EmbeddedMontiArcASTConnectorCoCo; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._cocos.EmbeddedMontiArcASTConnectorCoCo;
import de.monticore.lang.monticar.common2._ast.ASTQualifiedNameWithArray; import de.monticore.lang.monticar.common2._ast.ASTQualifiedNameWithArray;
import de.se_rwth.commons.logging.Log; import de.se_rwth.commons.logging.Log;
...@@ -35,9 +36,9 @@ public class SourceTargetNumberMatch implements EmbeddedMontiArcASTConnectorCoCo ...@@ -35,9 +36,9 @@ public class SourceTargetNumberMatch implements EmbeddedMontiArcASTConnectorCoCo
sourceNum = getSourceNum(node); sourceNum = getSourceNum(node);
for (ASTQualifiedNameWithArray target : node.getTargets().getQualifiedNameWithArrayList()) { for (ASTQualifiedNameWithArrayAndStar target : node.getTargets().getQualifiedNameWithArrayAndStarList()) {
targetNum = getTargetNum(target); targetNum = getTargetNum(target.getQualifiedNameWithArray());
if (sourceNum != targetNum){ if (sourceNum != targetNum){
Log.error("0xJK901 source port number "+ sourceNum +" and target port number "+ targetNum + " don't match"); Log.error("0xJK901 source port number "+ sourceNum +" and target port number "+ targetNum + " don't match");
...@@ -48,13 +49,14 @@ public class SourceTargetNumberMatch implements EmbeddedMontiArcASTConnectorCoCo ...@@ -48,13 +49,14 @@ public class SourceTargetNumberMatch implements EmbeddedMontiArcASTConnectorCoCo
private int getSourceNum(ASTConnector node){ private int getSourceNum(ASTConnector node){
int sourceNum = 0, sourceComp = 0, sourcePort = 0; int sourceNum = 0, sourceComp = 0, sourcePort = 0;
if (node.getSourceOpt().isPresent()) { if (node.getSourceOpt().isPresent()) {
if (node.getSource().getCompArrayOpt().isPresent()){ ASTQualifiedNameWithArray source = node.getSource().getQualifiedNameWithArray();
if (node.getSource().getCompArray().getLowerboundOpt().isPresent()) if (source.getCompArrayOpt().isPresent()){
sourceComp = node.getSource().getCompArray().getUpperbound().getNumber().get().intValue() - node.getSource().getCompArray().getLowerbound().getNumber().get().intValue() + 1; if (source.getCompArray().getLowerboundOpt().isPresent())
sourceComp = source.getCompArray().getUpperbound().getNumber().get().intValue() - source.getCompArray().getLowerbound().getNumber().get().intValue() + 1;
}else sourceComp = 1; }else sourceComp = 1;
if (node.getSource().getPortArrayOpt().isPresent()){ if (source.getPortArrayOpt().isPresent()){
if (node.getSource().getPortArray().getLowerboundOpt().isPresent()) if (source.getPortArray().getLowerboundOpt().isPresent())
sourcePort = node.getSource().getPortArray().getUpperbound().getNumber().get().intValue() - node.getSource().getPortArray().getLowerbound().getNumber().get().intValue() + 1; sourcePort = source.getPortArray().getUpperbound().getNumber().get().intValue() - source.getPortArray().getLowerbound().getNumber().get().intValue() + 1;
}else sourcePort = 1; }else sourcePort = 1;
sourceNum = sourceComp * sourcePort; sourceNum = sourceComp * sourcePort;
} }
......
/**
*
* ******************************************************************************
* MontiCAR Modeling Family, www.se-rwth.de
* Copyright (c) 2017, Software Engineering Group at RWTH Aachen,
* All rights reserved.
*
* This project is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this project. If not, see <http://www.gnu.org/licenses/>.
* *******************************************************************************
*/
package de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast;
import de.monticore.lang.monticar.common2._ast.ASTQualifiedNameWithArray;
import java.util.List;
/**
* @author Sascha Schneiders
*/
public class ASTConnectorTargets extends ASTConnectorTargetsTOP {
public ASTConnectorTargets() {
super();
}
public ASTConnectorTargets(List<ASTQualifiedNameWithArray> qualifiedNameWithArrays) {
super(qualifiedNameWithArrays);
}
}
...@@ -314,7 +314,7 @@ public class EmbeddedMontiArcSymbolTableCreator extends EmbeddedMontiArcSymbolTa ...@@ -314,7 +314,7 @@ public class EmbeddedMontiArcSymbolTableCreator extends EmbeddedMontiArcSymbolTa
@Override @Override
public void visit(ASTConnector node) { public void visit(ASTConnector node) {
doConnectorResolution(node, this); doConnectorResolution(node, this);
ASTQualifiedNameWithArray portName; ASTQualifiedNameWithArrayAndStar portName;
List<String> sourceNames = null; List<String> sourceNames = null;
boolean isConstant = false; boolean isConstant = false;
if (node.getSourceOpt().isPresent()) { if (node.getSourceOpt().isPresent()) {
......
...@@ -22,6 +22,7 @@ package de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncMode ...@@ -22,6 +22,7 @@ package de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncMode
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTConnector; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTConnector;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTPort; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTPort;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTQualifiedNameWithArrayAndStar;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTSubComponent; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTSubComponent;
import de.monticore.lang.embeddedmontiarc.helper.ConstantPortHelper; import de.monticore.lang.embeddedmontiarc.helper.ConstantPortHelper;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.EmbeddedMontiArcSymbolTableCreator; import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.EmbeddedMontiArcSymbolTableCreator;
...@@ -121,21 +122,20 @@ public class EMAPortHelper { ...@@ -121,21 +122,20 @@ public class EMAPortHelper {
} }
public static List<String> getPortName(ASTQualifiedNameWithArray portName, public static List<String> getPortName(ASTQualifiedNameWithArrayAndStar portName,
EmbeddedMontiArcSymbolTableCreator symbolTableCreator) { EmbeddedMontiArcSymbolTableCreator symbolTableCreator) {
List<String> names = new ArrayList<String>(); List<String> names = new ArrayList<String>();
List<String> compNameParts = getComponentNameParts(portName, symbolTableCreator); List<String> compNameParts = getComponentNameParts(portName, symbolTableCreator);
List<String> portNameParts; List<String> portNameParts;
portNameParts = getPortNameParts(portName, symbolTableCreator); portNameParts = getPortNameParts(portName.getQualifiedNameWithArray(), symbolTableCreator);
Log.debug("portName: " + portName + " " + compNameParts.size(), "CompNameParts"); Log.debug("portName: " + portName.getQualifiedNameWithArray() + " " + compNameParts.size(), "CompNameParts");
Log.debug("" + portNameParts.size(), "PortNameParts"); Log.debug("" + portNameParts.size(), "PortNameParts");
for (String compNamePart : compNameParts) { for (String compNamePart : compNameParts) {
for (String portNamePart : portNameParts) { for (String portNamePart : portNameParts) {
String curName = compNamePart + portNamePart; String curName = compNamePart + portNamePart;
names.add(curName); names.add(curName);
} }
} }
...@@ -143,9 +143,10 @@ public class EMAPortHelper { ...@@ -143,9 +143,10 @@ public class EMAPortHelper {
return names; return names;
} }
public static List<String> getComponentNameParts(ASTQualifiedNameWithArray portName, public static List<String> getComponentNameParts(ASTQualifiedNameWithArrayAndStar portNameStar,
EmbeddedMontiArcSymbolTableCreator symbolTableCreator) { EmbeddedMontiArcSymbolTableCreator symbolTableCreator) {
List<String> names = new ArrayList<String>(); ASTQualifiedNameWithArray portName = portNameStar.getQualifiedNameWithArray();
List<String> names = new ArrayList<String>();
String name = ""; String name = "";
if (portName.getCompNameOpt().isPresent()) { if (portName.getCompNameOpt().isPresent()) {
name += portName.getCompName(); name += portName.getCompName();
...@@ -311,7 +312,7 @@ public class EMAPortHelper { ...@@ -311,7 +312,7 @@ public class EMAPortHelper {
Log.info("" + sourceNames.size(), "SourcePorts"); Log.info("" + sourceNames.size(), "SourcePorts");
int counter = 0, targetnum = 0; int counter = 0, targetnum = 0;
for (ASTQualifiedNameWithArray target : node.getTargets().getQualifiedNameWithArrayList()) { for (ASTQualifiedNameWithArrayAndStar target : node.getTargets().getQualifiedNameWithArrayAndStarList()) {
counter = 0; counter = 0;
targetnum = 0; targetnum = 0;
for (String sourceName : sourceNames) { for (String sourceName : sourceNames) {
...@@ -344,7 +345,7 @@ public class EMAPortHelper { ...@@ -344,7 +345,7 @@ public class EMAPortHelper {
EMAPortSymbol emaConstantPortSymbol = ConstantPortHelper.createConstantPortSymbol(node, EMAPortSymbol emaConstantPortSymbol = ConstantPortHelper.createConstantPortSymbol(node,
symbolTableCreator); symbolTableCreator);
symbolTableCreator.addToScope(emaConstantPortSymbol); symbolTableCreator.addToScope(emaConstantPortSymbol);
for (ASTQualifiedNameWithArray target : node.getTargets().getQualifiedNameWithArrayList()) { for (ASTQualifiedNameWithArrayAndStar target : node.getTargets().getQualifiedNameWithArrayAndStarList()) {
counter = 0; counter = 0;
targetnum = 0; targetnum = 0;
List<String> targetNames = getPortName(target, symbolTableCreator); List<String> targetNames = getPortName(target, symbolTableCreator);
......
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 a.* -> this.*;
// equivalent to:
// * 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 -> #;
}
\ No newline at end of file
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