Commit e1101296 authored by vonWenckstern's avatar vonWenckstern
Browse files

Merge branch 'MvW-Grammar-Extension' into 'master'

Mv w grammar extension

See merge request !10
parents d64950d1 54203729
Pipeline #69030 passed with stage
in 5 minutes and 6 seconds
......@@ -30,7 +30,7 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc</artifactId>
<version>0.1.4-SNAPSHOT</version>
<version>0.1.5-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
......
/*
* ******************************************************************************
* MontiCore Language Workbench, www.monticore.de
* Copyright (c) 2017, MontiCore, 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;
/**
* Grammar for EmbeddedMontiArc.
*
* @author Michael von Wenckstern, Nina Pichler, Sascha Schneiders, Sining Wang, Yu Qiao
*/
grammar EmbeddedMontiArc extends de.monticore.lang.monticar.Common2 {
/** ASTEMACompilationUnit represents the complete component
* @attribute package The package declaration of this component
* @attribute importStatements List of imported elements
* @attribute Component the root component of the component
*/
EMACompilationUnit =
("package" package:(Name& || ".")+ ";")?
(ImportStatement )*
Component;
/* ======================================================*/
/* ===== Modified but based on old ARCD Grammar =========*/
/* ======================================================*/
/**
* A component may contain arbitrary many Elements.
* This interface may be used as an extension point to
* enrich components with further elements.
*/
interface Element;
/**
* A component is a unit of computation or a data store.
* The size of a component may scale from a single
* procedure to a whole application. A component may be
* either decomposed to subcomponents or is atomic.
*
* @attribute name type name of this component
* @attribute head is used to set generic types, a
* configuration and a parent component
* @attribute instanceName if this optional name is given,
* a subcomponent is automatically created that
* instantiates this inner component type. This is only
* allowed for inner component definitions.
* @attribute body contains the architectural elements
* inherited by this component
* A components head is used to define generic type
* parameters that may be used as port types in the
* component, to define configuration parameters that may
* be used to configure the component, and to set the
* parent component of this component.
*
* @attribute genericTypeParameters a list of type
* parameters that may be used as port types in the
* component
* @attribute parameters a list of Parameters that
* define a configurable component. If a configurable
* component is referenced, these parameters have to be
* set.
* @attribute superComponent the type of the super
* component
*/
symbol scope Component implements Element =
"component" Name
genericTypeParameters:TypeParameters2?
( "(" (Parameter || ",")+ ")" )?
("implements" superComponent:ReferenceType)?
body:ComponentBody;
/**
* The body contains architectural elements of
* this component.
*
* @attribute elements list of architectural elements
*/
ComponentBody =
("{"
Element*
"}" );
/**
* An Interface defines an interface of a component
* containing in- and outgoing ports.
* @attribute ports a list of ports that are contained in
* this interface
*/
Interface implements Element =
("port"|"ports")
ports:(Port || ",")+ ";" ;
/**a
* An incoming port is used to receive messages, an
* outgoing port is used to send messages of a specific
* type. Ports can now also be specified as an array.
*
* @attribute incoming true, if this is an incoming port
* @attribute outgoing true, if this is an outgoing port
* @attribute type the message type of this port
* @attribute name an optional name of this port
*/
/**might support auto type adding based on last previous type
* declaration later on
*/
Port =
AdaptableKeyword? (incoming:["in"] | outgoing:["out"])
Type (Name? | Name ( "[" UnitNumberResolution "]" )?) ;
/**
* A subcomponent is used to create one or more instances
* of another component. This way the hierarchical
* structure of a component is defined.
* @attribute type the type of the instantiated component
* @attribute arguments list of configuration parameters
* that are to be set, if the instantiated component is
* configurable.
* @attribute instances list of instances that should be
* created
*/
SubComponent implements Element =
"instance"
type:ReferenceType
("(" arguments:(Expression || ",")+ ")" )?
instances:(SubComponentInstance || ",")* ";" ;
/**
* A subcomponent instance binds the name of an instance
* with an optional list of simple connectors used to
* connect this instance with other subcomponents/ports.
* It does also support component arrays.
* Simple connectors directly connect outgoing ports of the
* corresponding subcomponent declaration with one or more target ports.
*
* @attribute name the name of this instance
* @attribute connectors list of simple connectors
*/
// TODO better/more intuitive name? e.g. "refConnector" (not really good...)
SubComponentInstance =
Name
("[" UnitNumberResolution "]")? ;
/**
* A connector connects one source port with one or many
* target ports.
*
* @attribute source source port or component instance
* name
* @attribute targets a list of target ports or component
* instance names
*/
Connector implements Element=
"connect" (source:QualifiedNameWithArray | (boolLiteral:BooleanLiteral) | (stringLiteral:StringLiteral)| UnitNumberResolution) "->"
targets:ConnectorTargets ";" ;
ConnectorTargets = (QualifiedNameWithArray (",")? )+;
/* ======================================================*/
/* ============ From OLD MARC Grammar ==================*/
/* ======================================================*/
/**
* MontiArc components may contain arbitrary many
* configurations. These configurations have to
* implement this interface.
*/
interface MontiArcConfig extends Element;
/**
* AutoConnect is used to connect ports automatically.
*
* @attribute type autoconnect unambigous ports with the
* same type
* @attribute port autoconnect unambigous ports with the
* same name and compatible type}
* @attribute off do not use autoconnection (default)
*/
MontiArcAutoConnect implements MontiArcConfig =
"autoconnect"
(["type"] | ["port"] | ["off"]) ";";
/**
* AutoInstantiate is used to automatically instantiate inner components.
*
* @attribute type autoinstantiate for inner components
* @attribute on to enable automatically instantiating inner components
* @attribute off do not use autoinstantiate (default)
*/
MontiArcAutoInstantiate implements MontiArcConfig =
"autoinstantiate"
(["on"] | ["off"]) ";";
}
/*
* ******************************************************************************
* MontiCore Language Workbench, www.monticore.de
* Copyright (c) 2017, MontiCore, 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;
/**
* Grammar for EmbeddedMontiArc.
*
* @author Michael von Wenckstern, Nina Pichler, Sascha Schneiders, Sining Wang, Yu Qiao
*/
grammar EmbeddedMontiArc extends de.monticore.lang.monticar.Common2 {
/** ASTEMACompilationUnit represents the complete component
* @attribute package The package declaration of this component
* @attribute importStatements List of imported elements
* @attribute Component the root component of the component
*/
EMACompilationUnit =
("package" package:(Name& || ".")+ ";")?
(ImportStatement )*
Component;
/* ======================================================*/
/* ===== Modified but based on old ARCD Grammar =========*/
/* ======================================================*/
/**
* A component may contain arbitrary many Elements.
* This interface may be used as an extension point to
* enrich components with further elements.
*/
interface Element;
/**
* A component is a unit of computation or a data store.
* The size of a component may scale from a single
* procedure to a whole application. A component may be
* either decomposed to subcomponents or is atomic.
*
* @attribute name type name of this component
* @attribute head is used to set generic types, a
* configuration and a parent component
* @attribute instanceName if this optional name is given,
* a subcomponent is automatically created that
* instantiates this inner component type. This is only
* allowed for inner component definitions.
* @attribute body contains the architectural elements
* inherited by this component
* A components head is used to define generic type
* parameters that may be used as port types in the
* component, to define configuration parameters that may
* be used to configure the component, and to set the
* parent component of this component.
*
* @attribute genericTypeParameters a list of type
* parameters that may be used as port types in the
* component
* @attribute parameters a list of Parameters that
* define a configurable component. If a configurable
* component is referenced, these parameters have to be
* set.
* @attribute superComponent the type of the super
* component
*/
symbol scope Component implements Element =
"component" (["interface"])? Name
//("component" | ["component_interface"]) Name
genericTypeParameters:TypeParameters2?
( "(" (Parameter || ",")+ ")" )?
("implements" superComponent:ReferenceType)?
body:ComponentBody;
/**
* The body contains architectural elements of
* this component.
*
* @attribute elements list of architectural elements
*/
ComponentBody =
("{"
Element*
"}" );
/**
* An Interface defines an interface of a component
* containing in- and outgoing ports.
* @attribute ports a list of ports that are contained in
* this interface
*/
Interface implements Element =
("port"|"ports")
ports:(Port || ",")+ ";" ;
/**a
* An incoming port is used to receive messages, an
* outgoing port is used to send messages of a specific
* type. Ports can now also be specified as an array.
*
* @attribute incoming true, if this is an incoming port
* @attribute outgoing true, if this is an outgoing port
* @attribute type the message type of this port
* @attribute name an optional name of this port
*/
/**might support auto type adding based on last previous type
* declaration later on
*/
Port =
AdaptableKeyword? (incoming:["in"] | outgoing:["out"])
Type (Name? | Name ( "[" UnitNumberResolution "]" )?) ;
/**
* A subcomponent is used to create one or more instances
* of another component. This way the hierarchical
* structure of a component is defined.
* @attribute type the type of the instantiated component
* @attribute arguments list of configuration parameters
* that are to be set, if the instantiated component is
* configurable.
* @attribute instances list of instances that should be
* created
*/
SubComponent implements Element =
"instance"
type:ReferenceType
("(" arguments:(Expression || ",")+ ")" )?
instances:(SubComponentInstance || ",")* ";" ;
/**
* A subcomponent instance binds the name of an instance
* with an optional list of simple connectors used to
* connect this instance with other subcomponents/ports.
* It does also support component arrays.
* Simple connectors directly connect outgoing ports of the
* corresponding subcomponent declaration with one or more target ports.
*
* @attribute name the name of this instance
* @attribute connectors list of simple connectors
*/
// TODO better/more intuitive name? e.g. "refConnector" (not really good...)
SubComponentInstance =
Name
("[" 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
* target ports.
*
* @attribute source source port or component instance
* name
* @attribute targets a list of target ports or component
* instance names
*/
Connector implements Element=
"connect" (source:QualifiedNameWithArrayAndStar |
boolLiteral:BooleanLiteral |
stringLiteral:StringLiteral|
UnitNumberResolution) "->"
targets:ConnectorTargets ";" ;
ConnectorTargets = ["#"] | // route symbol terminates inputs
(QualifiedNameWithArrayAndStar || "," )+;
// 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
}
......@@ -21,6 +21,7 @@
package de.monticore.lang.embeddedmontiarc.cocos;
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.monticar.common2._ast.ASTQualifiedNameWithArray;
import de.se_rwth.commons.logging.Log;
......@@ -62,14 +63,14 @@ public class ConnectorEndPointCorrectlyQualified
@Override
public void check(ASTConnector node) {
if (node.getSourceOpt().isPresent()) {
checkEndPointMaximallyTwiceQualified(node.getSource());
checkEndPointMaximallyTwiceQualified(node.getSource().getQualifiedNameWithArray());
} else {
if (!node.getUnitNumberResolutionOpt().isPresent() && !node.getBoolLiteralOpt().isPresent())
Log.error("Error Connector has no valid source or constant " + node.toString());
}
for (ASTQualifiedNameWithArray name : node.getTargets().getQualifiedNameWithArrayList()) {
checkEndPointMaximallyTwiceQualified(name);
for (ASTQualifiedNameWithArrayAndStar name : node.getTargets().getQualifiedNameWithArrayAndStarList()) {
checkEndPointMaximallyTwiceQualified(name.getQualifiedNameWithArray());
}
}
......
......@@ -73,8 +73,8 @@ public class InPortUniqueSender implements EmbeddedMontiArcASTComponentCoCo {
private void checkConnectors() {
for (ASTConnector connector : node.getConnectors()) {
for (ASTQualifiedNameWithArray target : connector.getTargets().getQualifiedNameWithArrayList()) {
checkTarget(target);
for (ASTQualifiedNameWithArrayAndStar target : connector.getTargets().getQualifiedNameWithArrayAndStarList()) {
checkTarget(target.getQualifiedNameWithArray());
}
}
}
......
......@@ -21,6 +21,7 @@
package de.monticore.lang.embeddedmontiarc.cocos;
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.monticar.common2._ast.ASTQualifiedNameWithArray;
import de.se_rwth.commons.logging.Log;
......@@ -35,9 +36,9 @@ public class SourceTargetNumberMatch implements EmbeddedMontiArcASTConnectorCoCo
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){
Log.error("0xJK901 source port number "+ sourceNum +" and target port number "+ targetNum + " don't match");
......@@ -48,13 +49,14 @@ public class SourceTargetNumberMatch implements EmbeddedMontiArcASTConnectorCoCo
private int getSourceNum(ASTConnector node){
int sourceNum = 0, sourceComp = 0, sourcePort = 0;
if (node.getSourceOpt().isPresent()) {
if (node.getSource().getCompArrayOpt().isPresent()){
if (node.getSource().getCompArray().getLowerboundOpt().isPresent())
sourceComp = node.getSource().getCompArray().getUpperbound().getNumber().get().intValue() - node.getSource().getCompArray().getLowerbound().getNumber().get().intValue() + 1;
ASTQualifiedNameWithArray source = node.getSource().getQualifiedNameWithArray();
if (source.getCompArrayOpt().isPresent()){
if (source.getCompArray().getLowerboundOpt().isPresent())
sourceComp = source.getCompArray().getUpperbound().getNumber().get().intValue() - source.getCompArray().getLowerbound().getNumber().get().intValue() + 1;
}else sourceComp = 1;
if (node.getSource().getPortArrayOpt().isPresent()){
if (node.getSource().getPortArray().getLowerboundOpt().isPresent())
sourcePort = node.getSource().getPortArray().getUpperbound().getNumber().get().intValue() - node.getSource().getPortArray().getLowerbound().getNumber().get().intValue() + 1;
if (source.getPortArrayOpt().isPresent()){
if (source.getPortArray().getLowerboundOpt().isPresent())
sourcePort = source.getPortArray().getUpperbound().getNumber().get().intValue() - source.getPortArray().getLowerbound().getNumber().get().intValue() + 1;
}else sourcePort = 1;
sourceNum = sourceComp * sourcePort;
}
......
......@@ -40,8 +40,8 @@ public class ASTComponent extends ASTComponentTOP {
super();
}
public ASTComponent(String name, Optional<ASTTypeParameters2> genericTypeParameters, List<ASTParameter> parameters, Optional<ASTReferenceType> superComponent, ASTComponentBody body) {
super(name, genericTypeParameters, parameters, superComponent, body);
public ASTComponent(String name, Optional<ASTTypeParameters2> genericTypeParameters, List<ASTParameter> parameters, Optional<ASTReferenceType> superComponent, ASTComponentBody body, boolean r__interface) {
super(name, genericTypeParameters, parameters, superComponent, body, r__interface);
}
// do not use symbol table, since symbol table must not be created
......
/**
*
* ******************************************************************************
* 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);
}
}
......@@ -29,7 +29,6 @@ import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instance