Commit c01bc12a authored by Malte Heithoff's avatar Malte Heithoff

New Symbols

parent 715d4189
......@@ -10,35 +10,31 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc</artifactId>
<version>0.2.12-SNAPSHOT</version>
<version>0.4.4-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
<properties>
<wagon.provider.version>2.6</wagon.provider.version>
<!-- .. EMA-Libraries ................................................. -->
<struct.version>0.2.12-SNAPSHOT</struct.version>
<Common-MontiCar.version>0.2.12-SNAPSHOT</Common-MontiCar.version>
<tagging.version>0.2.12-SNAPSHOT</tagging.version>
<struct.version>0.4.4-SNAPSHOT</struct.version>
<Common-MontiCar.version>0.4.4-SNAPSHOT</Common-MontiCar.version>
<tagging.version>0.4.4-SNAPSHOT</tagging.version>
<!-- .. SE-Libraries .................................................. -->
<monticore.version>5.0.0</monticore.version>
<se-commons.version>1.7.7</se-commons.version>
<mc.grammars.assembly.version>0.0.6-SNAPSHOT</mc.grammars.assembly.version>
<languages.version>4.0.1-SNAPSHOT</languages.version>
<!-- .. Libraries .................................................. -->
<guava.version>25.1-jre</guava.version>
<junit.version>4.12</junit.version>
<logback.version>1.1.2</logback.version>
<jscience.version>4.3.1</jscience.version>
<jsr305.version>3.0.0</jsr305.version>
<!-- .. Plugins ....................................................... -->
<monticore.plugin>5.0.0</monticore.plugin>
<assembly.plugin>2.5.4</assembly.plugin>
<compiler.plugin>3.3</compiler.plugin>
<source.plugin>2.4</source.plugin>
<shade.plugin>2.4.3</shade.plugin>
<!-- Classifiers -->
<grammars.classifier>grammars</grammars.classifier>
......@@ -54,12 +50,6 @@
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.7.1</version>
</dependency>
<dependency>
<groupId>de.monticore.lang</groupId>
<artifactId>Tagging</artifactId>
......@@ -94,18 +84,6 @@
<!-- MontiCore Dependencies -->
<dependency>
<groupId>de.monticore</groupId>
<artifactId>monticore-runtime</artifactId>
<version>${monticore.version}</version>
</dependency>
<dependency>
<groupId>de.monticore</groupId>
<artifactId>monticore-grammar</artifactId>
<version>${monticore.version}</version>
</dependency>
<dependency>
<groupId>de.monticore</groupId>
<artifactId>monticore-grammar</artifactId>
......@@ -120,18 +98,6 @@
<version>${jsr305.version}</version>
</dependency>
<dependency>
<groupId>de.se_rwth.commons</groupId>
<artifactId>se-commons-groovy</artifactId>
<version>${se-commons.version}</version>
</dependency>
<dependency>
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>common-monticar</artifactId>
<version>${Common-MontiCar.version}</version>
</dependency>
<dependency>
<groupId>de.monticore.lang.monticar</groupId>
......@@ -149,26 +115,6 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>de.monticore</groupId>
<artifactId>monticore-runtime</artifactId>
<version>${monticore.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>org.jscience</groupId>
<artifactId>jscience</artifactId>
<version>${jscience.version}</version>
</dependency>
</dependencies>
<!-- == PROJECT BUILD SETTINGS =========================================== -->
......@@ -188,19 +134,6 @@
<skip>false</skip>
<script>de/monticore/monticore_noemf.groovy</script>
</configuration>
<dependencies>
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4</artifactId>
<version>4.7.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.antlr/antlr4-runtime -->
<dependency>
<groupId>org.antlr</groupId>
<artifactId>antlr4-runtime</artifactId>
<version>4.7.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
......
......@@ -126,7 +126,7 @@ grammar EmbeddedMontiArc extends de.monticore.lang.monticar.Common2 {
"instance"
type:ReferenceType
("(" arguments:(Expression || ",")+ ")" )?
("{" (InitialGuess || ",")+ "}")?
("{" (PortInitialValueOrGuess || ",")+ "}")?
instances:(SubComponentInstance || ",")+ ";" ;
......@@ -146,8 +146,8 @@ grammar EmbeddedMontiArc extends de.monticore.lang.monticar.Common2 {
Name
("[" UnitNumberResolution "]")?;
InitialGuess =
Name ( "[" UnitNumberResolution "]" )? "=" Expression;
PortInitialValueOrGuess =
Name ( "[" UnitNumberResolution "]" )? (guess:["~"])? "=" Expression;
/**
* port1
......
......@@ -30,6 +30,6 @@ public class EmbeddedMontiArcCoCos {
.addCoCo(new InRosPortRosSender())
.addCoCo(new ConstantConnectorTargetRangeValid())
.addCoCo((new DistinctTargetPorts()))
.addCoCo(new InitialGuessIsAssignment());
.addCoCo(new InitialGuessIsNotAssignmentCoCo());
}
}
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.embeddedmontiarc.cocos;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTInitialGuess;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTPortInitialValueOrGuess;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTSubComponent;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._cocos.EmbeddedMontiArcASTSubComponentCoCo;
import de.monticore.mcexpressions._ast.ASTAssignmentExpression;
import de.se_rwth.commons.logging.Log;
public class InitialGuessIsAssignment implements EmbeddedMontiArcASTSubComponentCoCo {
public class InitialGuessIsNotAssignmentCoCo implements EmbeddedMontiArcASTSubComponentCoCo {
@Override
public void check(ASTSubComponent node) {
for (ASTInitialGuess initialGuess : node.getInitialGuessList()) {
for (ASTPortInitialValueOrGuess initialGuess : node.getPortInitialValueOrGuessList()) {
if (initialGuess.getExpression() instanceof ASTAssignmentExpression) {
Log.error(String.format("0x079B7 Initial guess of has to be an assignment"),
node.get_SourcePositionStart());
......
......@@ -256,7 +256,7 @@ public class EmbeddedMontiArcSymbolTableCreator extends EmbeddedMontiArcSymbolTa
componentTypeReference.setArguments(node.getArgumentsList());
componentTypeReference.fixResolutions(this);
// InitialGuesses
componentTypeReference.setInitialGuesses(node.getInitialGuessList());
componentTypeReference.setInitialGuesses(node.getPortInitialValueOrGuessList());
// instances
......
......@@ -3,7 +3,7 @@ package de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncMode
import com.google.common.collect.ImmutableList;
import de.monticore.expressionsbasis._ast.ASTExpression;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTInitialGuess;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTPortInitialValueOrGuess;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ComponentKind;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstantiationSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc.types.EMAVariable;
......@@ -57,7 +57,7 @@ public class EMAComponentSymbol extends CommonScopeSpanningSymbol implements EMA
private List<ASTExpression> arguments = new ArrayList<>();
private List<ASTInitialGuess> initalGuesses = new ArrayList<>();
private List<ASTPortInitialValueOrGuess> initalGuesses = new ArrayList<>();
public EMAComponentSymbol(String name) {
super(name, KIND);
......@@ -650,20 +650,20 @@ public class EMAComponentSymbol extends CommonScopeSpanningSymbol implements EMA
return (Optional<EMAComponentSymbol>) getEnclosingScope().getSpanningSymbol();
}
public List<ASTInitialGuess> getInitalGuesses() {
public List<ASTPortInitialValueOrGuess> getInitalGuesses() {
if (referencedComponent.isPresent())
return referencedComponent.get().getInitalGuesses();
return initalGuesses;
}
public void addInitialGuess(ASTInitialGuess initialGuess) {
public void addInitialGuess(ASTPortInitialValueOrGuess initialGuess) {
if (referencedComponent.isPresent())
referencedComponent.get().addInitialGuess(initialGuess);
else
this.initalGuesses.add(initialGuess);
}
public void setInitialGuesses(List<ASTInitialGuess> initalGuesses) {
public void setInitialGuesses(List<ASTPortInitialValueOrGuess> initalGuesses) {
this.initalGuesses = initalGuesses;
}
}
......@@ -6,7 +6,7 @@ package de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncMode
import com.google.common.collect.ImmutableList;
import de.monticore.expressionsbasis._ast.ASTExpression;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTInitialGuess;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTPortInitialValueOrGuess;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.EmbeddedMontiArcSymbolTableCreator;
import de.monticore.lang.monticar.si._symboltable.ResolutionDeclarationSymbol;
import de.monticore.symboltable.MutableScope;
......@@ -32,7 +32,7 @@ public class EMAComponentSymbolReference extends EMAComponentSymbol implements
private List<ResolutionDeclarationSymbol> resSymbols = new ArrayList<>();
private List<ASTExpression> arguments = new ArrayList<>();
private List<ASTInitialGuess> initalGuesses = new ArrayList<>();
private List<ASTPortInitialValueOrGuess> initalGuesses = new ArrayList<>();
public EMAComponentSymbolReference(final String name, final Scope definingScopeOfReference) {
super(name);
......@@ -164,17 +164,17 @@ public class EMAComponentSymbolReference extends EMAComponentSymbol implements
}
@Override
public List<ASTInitialGuess> getInitalGuesses() {
public List<ASTPortInitialValueOrGuess> getInitalGuesses() {
return this.initalGuesses;
}
@Override
public void addInitialGuess(ASTInitialGuess initialGuess) {
public void addInitialGuess(ASTPortInitialValueOrGuess initialGuess) {
this.initalGuesses.add(initialGuess);
}
@Override
public void setInitialGuesses(List<ASTInitialGuess> initalGuesses) {
public void setInitialGuesses(List<ASTPortInitialValueOrGuess> initalGuesses) {
this.initalGuesses = initalGuesses;
}
......
......@@ -3,7 +3,7 @@ package de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanc
import de.monticore.expressionsbasis._ast.ASTExpression;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTComponent;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTInitialGuess;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTPortInitialValueOrGuess;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.EmbeddedMontiArcMill;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.UnitNumberExpressionSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.*;
......@@ -45,7 +45,7 @@ public class EMAComponentInstanceBuilder {
protected List<EMAVariable> parameters = new ArrayList<>();
protected List<ASTExpression> arguments = new ArrayList<>();
protected String packageName = "";
protected List<ASTInitialGuess> initialGuesses = new ArrayList<>();
protected List<ASTPortInitialValueOrGuess> initialGuesses = new ArrayList<>();
protected static Map<MCTypeSymbol, ActualTypeArgument> createMap(List<MCTypeSymbol> keys,
List<ActualTypeArgument> values) {
......@@ -307,14 +307,18 @@ public class EMAComponentInstanceBuilder {
}
for (EMAPortInstanceSymbol port : inst.getPortInstanceList()) {
if (port.isInitialGuessPresent()) {
ASTExpression initialGuess = port.getInitialGuess();
if (initialGuess instanceof ASTUnitNumberResolutionExpression) {
if (((ASTUnitNumberResolutionExpression) initialGuess).getUnitNumberResolution().getNameOpt().isPresent()) {
String par = ((ASTUnitNumberResolutionExpression) initialGuess).getUnitNumberResolution().getName();
if (port.isInitialGuessPresent() || port.isInitialValuePresent()) {
ASTExpression initial = port.isInitialGuessPresent() ? port.getInitialGuess() : port.getInitialValue();
if (initial instanceof ASTUnitNumberResolutionExpression) {
if (((ASTUnitNumberResolutionExpression) initial).getUnitNumberResolution().getNameOpt().isPresent()) {
String par = ((ASTUnitNumberResolutionExpression) initial).getUnitNumberResolution().getName();
ASTExpression argument = arguments.get(par);
if (argument != null)
if (argument != null) {
if (port.isInitialGuessPresent())
port.setInitialGuess(argument);
else
port.setInitialValue(argument);
}
}
}
}
......@@ -409,14 +413,19 @@ public class EMAComponentInstanceBuilder {
private void handleInitialGuesses(EMAComponentInstanceSymbol sym) {
Collection<EMAPortInstanceSymbol> portInstanceList = sym.getPortInstanceList();
for (ASTInitialGuess initialGuess : initialGuesses) {
for (ASTPortInitialValueOrGuess initialGuess : initialGuesses) {
String arrayAccess = "";
if (initialGuess.isPresentUnitNumberResolution())
arrayAccess += "[" + initialGuess.getUnitNumberResolution().getNumber().get().intValue() + "]";
final String portAccessName = initialGuess.getName() + arrayAccess;
portInstanceList.stream()
.filter(port -> port.getName().equals(portAccessName))
.forEachOrdered(port -> port.setInitialGuess(initialGuess.getExpression()));
.forEachOrdered(port -> {
if(initialGuess.isGuess())
port.setInitialGuess(initialGuess.getExpression());
else
port.setInitialValue(initialGuess.getExpression());
});
}
}
......@@ -609,15 +618,15 @@ public class EMAComponentInstanceBuilder {
return this;
}
public EMAComponentInstanceBuilder addInitialGuesses(List<ASTInitialGuess> initialGuesses) {
for (ASTInitialGuess initialGuess : initialGuesses) {
public EMAComponentInstanceBuilder addInitialGuesses(List<ASTPortInitialValueOrGuess> initialGuesses) {
for (ASTPortInitialValueOrGuess initialGuess : initialGuesses) {
if (!this.initialGuesses.contains(initialGuess))
this.initialGuesses.add(initialGuess);
}
return this;
}
public List<ASTInitialGuess> getInitialGuesses() {
public List<ASTPortInitialValueOrGuess> getInitialGuesses() {
return initialGuesses;
}
}
......@@ -55,6 +55,8 @@ public class EMAPortInstanceSymbol extends EMAPortSymbol implements EMAElementIn
private Optional<ASTExpression> initialGuess = Optional.empty();
private Optional<ASTExpression> initialValue = Optional.empty();
/**
* use {@link #builder()}
*/
......@@ -287,4 +289,19 @@ public class EMAPortInstanceSymbol extends EMAPortSymbol implements EMAElementIn
else
return null;
}
public boolean isInitialValuePresent() {
return this.initialValue.isPresent();
}
public void setInitialValue(ASTExpression initialGuess) {
this.initialValue = Optional.ofNullable(initialGuess);
}
public ASTExpression getInitialValue() {
if (isInitialValuePresent())
return this.initialValue.get();
else
return null;
}
}
......@@ -543,6 +543,7 @@ public class ExpandedComponentInstanceTest extends AbstractSymtabTest {
@Test
public void testInitialGuesses() {
Scope symTab = createSymTab("src/test/resources");
Log.enableFailQuick(true);
EMAComponentInstanceSymbol inst = symTab.<EMAComponentInstanceSymbol>resolve(
"testing.initialGuessTest", EMAComponentInstanceSymbol.KIND).orElse(null);
......
......@@ -11,7 +11,7 @@ public class InitialValueCoCoTest extends AbstractCoCoTest {
ASTEmbeddedMontiArcNode astNode = getAstNode("", model);
EmbeddedMontiArcCoCoChecker checker = new EmbeddedMontiArcCoCoChecker();
checker.addCoCo(new InitialGuessIsAssignment());
checker.addCoCo(new InitialGuessIsNotAssignmentCoCo());
checker.checkAll(astNode);
}
......
......@@ -3,6 +3,6 @@ package testing;
component InitialGuessFromParameter(Q val = 3) {
instance InitialGuessSimple{out1 = val} simple;
instance InitialGuessSimple{out1 ~= val} simple;
}
\ No newline at end of file
......@@ -3,9 +3,9 @@ package testing;
component InitialGuessTest {
instance InitialGuessSimple{out1 = 2} simple;
instance InitialGuessSimple{out1 ~= 2} simple;
instance InitialGuessFromParameter fromParameterDefault;
instance InitialGuessFromParameter(5) fromParameterGiven;
instance InitialGuessPortArray{out1[2] = 7} portArray;
instance InitialGuessPortArray{out1[2] ~= 7} portArray;
}
\ 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