Aufgrund von Umarbeiten des s3 Storage wird es in GitLab, in nächster Zeit, mögliche Performance-Einbußen geben. Näheres dazu unter: https://maintenance.itc.rwth-aachen.de/ticket/status/messages/43/show_ticket/6670

Commit f04930c9 authored by Malte Heithoff's avatar Malte Heithoff

Adding initialGuesses

parent 2a40a6cb
Pipeline #330837 failed with stage
in 1 minute and 59 seconds
/* (c) https://github.com/MontiCore/monticore */
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.embeddedmontiarc.cocos;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._cocos.EmbeddedMontiArcASTConnectorCoCo;
......@@ -29,6 +29,7 @@ public class EmbeddedMontiArcCoCos {
.addCoCo(new OnlyIncomingPortIsConfig())
.addCoCo(new InRosPortRosSender())
.addCoCo(new ConstantConnectorTargetRangeValid())
.addCoCo((new DistinctTargetPorts()));
.addCoCo((new DistinctTargetPorts()))
.addCoCo(new InitialGuessIsAssignment());
}
}
/* (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.ASTQualifiedNameWithArrayAndStar;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTSubComponent;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTSubComponentInstance;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._cocos.EmbeddedMontiArcASTSubComponentCoCo;
import de.monticore.mcexpressions._ast.ASTAssignmentExpression;
import de.se_rwth.commons.logging.Log;
import java.util.Optional;
public class InitialGuessIsAssignment implements EmbeddedMontiArcASTSubComponentCoCo {
@Override
public void check(ASTSubComponent node) {
for (ASTInitialGuess initialGuess : node.getInitialGuessList()) {
if (initialGuess.getExpression() instanceof ASTAssignmentExpression) {
Log.error(String.format("0x079B7 Initial guess of has to be an assignment"),
node.get_SourcePositionStart());
}
}
}
}
/* (c) https://github.com/MontiCore/monticore */
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable;
import de.monticore.expressionsbasis._ast.ASTExpression;
......@@ -255,9 +255,12 @@ public class EmbeddedMontiArcSymbolTableCreator extends EmbeddedMontiArcSymbolTa
/* for (ASTExpression arg : node.getArguments()) { String value = new JavaDSLPrettyPrinter(new
* IndentPrinter()).prettyprint(arg); value = value.replace("\"", "\\\"").replace("\n", "");
* configArgs.add(new ValueSymbol<>(value, Kind.Expression)); } */
for (ASTExpression astExpression : node.getArgumentsList())
componentTypeReference.addArgument(astExpression);
componentTypeReference.setArguments(node.getArgumentsList());
componentTypeReference.fixResolutions(this);
// InitialGuesses
componentTypeReference.setInitialGuesses(node.getInitialGuessList());
// instances
if (!node.getInstancesList().isEmpty()) {
......
......@@ -3,6 +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._symboltable.ComponentKind;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstantiationSymbol;
......@@ -19,10 +20,7 @@ import de.monticore.symboltable.modifiers.AccessModifier;
import de.monticore.symboltable.types.references.ActualTypeArgument;
import de.se_rwth.commons.logging.Log;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
import static com.google.common.base.Preconditions.checkArgument;
......@@ -57,6 +55,8 @@ public class EMAComponentSymbol extends CommonScopeSpanningSymbol implements EMA
private List<ASTExpression> arguments = new ArrayList<>();
private List<ASTInitialGuess> initalGuesses = new ArrayList<>();
public EMAComponentSymbol(String name) {
super(name, KIND);
}
......@@ -647,4 +647,21 @@ public class EMAComponentSymbol extends CommonScopeSpanningSymbol implements EMA
public Optional<EMAComponentSymbol> getParent() {
return (Optional<EMAComponentSymbol>) getEnclosingScope().getSpanningSymbol();
}
public List<ASTInitialGuess> getInitalGuesses() {
if (referencedComponent.isPresent())
return referencedComponent.get().getInitalGuesses();
return initalGuesses;
}
public void addInitialGuess(ASTInitialGuess initialGuess) {
if (referencedComponent.isPresent())
referencedComponent.get().addInitialGuess(initialGuess);
else
this.initalGuesses.add(initialGuess);
}
public void setInitialGuesses(List<ASTInitialGuess> initalGuesses) {
this.initalGuesses = initalGuesses;
}
}
......@@ -6,6 +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._symboltable.EmbeddedMontiArcSymbolTableCreator;
import de.monticore.lang.monticar.si._symboltable.ResolutionDeclarationSymbol;
import de.monticore.symboltable.MutableScope;
......@@ -31,6 +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<>();
public EMAComponentSymbolReference(final String name, final Scope definingScopeOfReference) {
super(name);
......@@ -161,7 +163,22 @@ public class EMAComponentSymbolReference extends EMAComponentSymbol implements
this.arguments = arguments;
}
/* Methods of Symbol interface */
@Override
public List<ASTInitialGuess> getInitalGuesses() {
return this.initalGuesses;
}
@Override
public void addInitialGuess(ASTInitialGuess initialGuess) {
this.initalGuesses.add(initialGuess);
}
@Override
public void setInitialGuesses(List<ASTInitialGuess> initalGuesses) {
this.initalGuesses = initalGuesses;
}
/* Methods of Symbol interface */
@Override
public String getName() {
......
......@@ -86,8 +86,8 @@ public class EMAPortBuilder {
throw new Error("not all parameters have been set before to build the port symbol");
}
public static EMAPortInstanceSymbol instantiate(EMAPortSymbol port, String packageName) {
EMAPortInstanceSymbol portInstance = new EMAPortInstanceSymbol(port.getName());
public static EMAPortInstanceSymbol instantiate(EMAPortSymbol port, String packageName, String name) {
EMAPortInstanceSymbol portInstance = new EMAPortInstanceSymbol(name);
portInstance.setDirection(port.isIncoming());
portInstance.setTypeReference(port.getTypeReference());
if (port.getAstNode().isPresent())
......
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure;
import com.google.common.hash.BloomFilter;
import com.sun.org.apache.xalan.internal.xsltc.compiler.sym;
import de.monticore.javaclassexpressions._ast.ASTLiteralExpression;
import de.monticore.javaclassexpressions._ast.ASTNameExpression;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTComponent;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTInitialGuess;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.EmbeddedMontiArcMill;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.EmbeddedMontiArcSymbolMill;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.UnitNumberExpressionSymbol;
......@@ -48,6 +51,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 static Map<MCTypeSymbol, ActualTypeArgument> createMap(List<MCTypeSymbol> keys,
List<ActualTypeArgument> values) {
......@@ -307,6 +311,20 @@ public class EMAComponentInstanceBuilder {
Log.error("TODO");
}
}
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();
ASTExpression argument = arguments.get(par);
if (argument != null)
port.setInitialGuess(argument);
}
}
}
}
}
protected ASTExpression calculateExchange(ASTExpression argument, Map<String, ASTExpression> arguments) {
......@@ -360,8 +378,10 @@ public class EMAComponentInstanceBuilder {
resolvingFilters.stream().forEachOrdered(f -> scope.addResolver(f));
ports.stream().forEachOrdered(p ->
instantiatePortSymbol(p, sym.getFullName(), scope)); // must be cloned since we change it if it has
handlePort(p, sym.getFullName(), scope)); // must be cloned since we change it if it has
addPortArraySymbolsToInstance(sym);
Collection<EMAPortInstanceSymbol> portInstances = scope.resolveLocally(EMAPortInstanceSymbol.KIND);
handleInitialGuesses(sym);
// generics
connectors.stream().forEachOrdered(c -> instantiateConnectorSymbol(c, sym.getFullName(), scope));
......@@ -392,6 +412,19 @@ public class EMAComponentInstanceBuilder {
throw new Error("not all parameters have been set before to build the expanded component instance symbol");
}
private void handleInitialGuesses(EMAComponentInstanceSymbol sym) {
Collection<EMAPortInstanceSymbol> portInstanceList = sym.getPortInstanceList();
for (ASTInitialGuess 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()));
}
}
private void setDefaultValuesToArguments(EMAComponentInstanceSymbol sym) {
if (arguments.isEmpty() && !parameters.isEmpty()) {
// set default values
......@@ -420,9 +453,24 @@ public class EMAComponentInstanceBuilder {
scope.add(EMAConnectorBuilder.instantiate(c, fullName));
}
protected void instantiatePortSymbol(EMAPortSymbol port, String packageName, MutableScope scope) {
EMAPortInstanceSymbol symbol = EMAPortBuilder.instantiate(port, packageName);
protected void handlePort(EMAPortSymbol port, String packageName, MutableScope scope) {
if (port instanceof EMAPortArraySymbol)
instantiatePortArraySymbol((EMAPortArraySymbol) port, packageName, scope);
else
instantiatePortSymbol(port, packageName, port.getName(), scope);
}
protected EMAPortInstanceSymbol instantiatePortSymbol(EMAPortSymbol port, String packageName, String name, MutableScope scope) {
EMAPortInstanceSymbol symbol = EMAPortBuilder.instantiate(port, packageName, name);
scope.add(symbol);
return symbol;
}
protected void instantiatePortArraySymbol(EMAPortArraySymbol port, String packageName, MutableScope scope) {
for (int i = 0; i < port.getDimension(); ++i) {
String portName = port.getName() + "[" + (i + 1) + "]";
instantiatePortSymbol(port, packageName, portName, scope);
}
}
protected void addOtherToComponentInstance(EMAComponentInstanceSymbol sym) {
......@@ -565,4 +613,16 @@ public class EMAComponentInstanceBuilder {
this.packageName = packageName;
return this;
}
public EMAComponentInstanceBuilder addInitialGuesses(List<ASTInitialGuess> initialGuesses) {
for (ASTInitialGuess initialGuess : initialGuesses) {
if (!this.initialGuesses.contains(initialGuess))
this.initialGuesses.add(initialGuess);
}
return this;
}
public List<ASTInitialGuess> getInitialGuesses() {
return initialGuesses;
}
}
......@@ -79,7 +79,11 @@ public class EMAComponentInstanceSymbolCreator {
.setSymbolReference(new EMAComponentSymbolReference(cmp.getName(),
cmp.getEnclosingScope()))
.addPorts(cmp.getPortsList())
.addConnectors(cmp.getConnectors()).addResolutionDeclarationSymbols(cmp.getResolutionDeclarationSymbols()).addParameters(cmp.getParameters()).addArguments(cmp.getArguments());
.addConnectors(cmp.getConnectors())
.addResolutionDeclarationSymbols(cmp.getResolutionDeclarationSymbols())
.addParameters(cmp.getParameters())
.addArguments(cmp.getArguments())
.addInitialGuesses(cmp.getInitalGuesses());
for (EMAConnectorSymbol emaConnectorSymbol : cmp.getConnectors())
Log.info(emaConnectorSymbol.toString(), "Building Connector:");
// add sub components
......@@ -95,7 +99,8 @@ public class EMAComponentInstanceSymbolCreator {
.addResolvingFilters(filters)
.addResolutionDeclarationSymbols(inst.getComponentType().getResolutionDeclarationSymbols())
.addParameters(inst.getComponentType().getReferencedSymbol().getParameters())
.addArguments(inst.getComponentType().getReferencedSymbol().getArguments()).build());
.addArguments(inst.getComponentType().getReferencedSymbol().getArguments())
.addInitialGuesses(inst.getComponentType().getReferencedSymbol().getInitalGuesses()).build());
Log.debug(inst.getInstanceInformation().get().getInstanceNumberForArgumentIndex(0) + "", "InstanceInformation:");
Log.debug(inst.toString(), "ComponentInstance CreateInstance PostSub");
......
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure;
import de.monticore.expressionsbasis._ast.ASTExpression;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAComponentSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAPortBuilder;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.EMAPortSymbol;
......@@ -52,6 +53,8 @@ public class EMAPortInstanceSymbol extends EMAPortSymbol implements EMAElementIn
private Optional<EMAConstantValue> constantValue = Optional.empty();
private Optional<ASTExpression> initialGuess = Optional.empty();
/**
* use {@link #builder()}
*/
......@@ -269,4 +272,19 @@ public class EMAPortInstanceSymbol extends EMAPortSymbol implements EMAElementIn
public boolean isSomeIPPort() {
return getMiddlewareSymbol().isPresent() && getMiddlewareSymbol().get().isKindOf(SomeIPConnectionSymbol.KIND);
}
public boolean isInitialGuessPresent() {
return this.initialGuess.isPresent();
}
public void setInitialGuess(ASTExpression initialGuess) {
this.initialGuess = Optional.ofNullable(initialGuess);
}
public ASTExpression getInitialGuess() {
if (isInitialGuessPresent())
return this.initialGuess.get();
else
return null;
}
}
......@@ -4,13 +4,12 @@ package de.monticore.lang.embeddedmontiarc;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.*;
import de.monticore.expressionsbasis._ast.ASTExpression;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.cncModel.*;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceBuilder;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAConnectorInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.InstanceInformation;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.*;
import de.monticore.lang.embeddedmontiarc.helper.ConstantPortHelper;
import de.monticore.lang.monticar.resolution._ast.ASTUnitNumberExpression;
import de.monticore.lang.monticar.si._symboltable.ResolutionDeclarationSymbol;
import de.monticore.symboltable.Scope;
import de.monticore.symboltable.Symbol;
import de.se_rwth.commons.logging.Log;
import org.junit.BeforeClass;
import org.junit.Ignore;
......@@ -228,10 +227,10 @@ public class ExpandedComponentInstanceTest extends AbstractSymtabTest {
(UnitNumberExpressionSymbol) sub21.getArguments().get(0).getSymbolOpt().get();
UnitNumberExpressionSymbol symbol22 =
(UnitNumberExpressionSymbol) sub22.getArguments().get(0).getSymbolOpt().get();
assertEquals("2", symbol1.getTextualRepresentation());
assertEquals("3", symbol1.getTextualRepresentation());
assertEquals("9", symbol2.getTextualRepresentation());
assertEquals("2", symbol11.getTextualRepresentation());
assertEquals("2", symbol12.getTextualRepresentation());
assertEquals("3", symbol11.getTextualRepresentation());
assertEquals("3", symbol12.getTextualRepresentation());
assertEquals("9", symbol21.getTextualRepresentation());
assertEquals("9", symbol22.getTextualRepresentation());
}
......@@ -538,4 +537,53 @@ public class ExpandedComponentInstanceTest extends AbstractSymtabTest {
assertNotNull(inst);
}
*/
@Test
public void testInitialGuesses() {
Scope symTab = createSymTab("src/test/resources");
EMAComponentInstanceSymbol inst = symTab.<EMAComponentInstanceSymbol>resolve(
"testing.initialGuessTest", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(inst);
EMAPortInstanceSymbol port = symTab.<EMAPortInstanceSymbol>resolve(
"testing.initialGuessTest.simple.out1",
EMAPortInstanceSymbol.KIND).orElse(null);
assertTrue(port.isInitialGuessPresent());
assertEquals(2.0, ((ASTUnitNumberExpression) port.getInitialGuess()).getNumberWithUnit().getNumber().get(), 0.001);
assertNotNull(port);
port = symTab.<EMAPortInstanceSymbol>resolve(
"testing.initialGuessTest.fromParameterDefault.simple.out1",
EMAPortInstanceSymbol.KIND).orElse(null);
assertTrue(port.isInitialGuessPresent());
assertEquals(3.0, ((ASTUnitNumberExpression) port.getInitialGuess()).getNumberWithUnit().getNumber().get(), 0.001);
assertNotNull(port);
port = symTab.<EMAPortInstanceSymbol>resolve(
"testing.initialGuessTest.fromParameterGiven.simple.out1",
EMAPortInstanceSymbol.KIND).orElse(null);
assertTrue(port.isInitialGuessPresent());
assertEquals(5.0, ((ASTUnitNumberExpression) port.getInitialGuess()).getNumberWithUnit().getNumber().get(), 0.001);
assertNotNull(port);
port = symTab.<EMAPortInstanceSymbol>resolve(
"testing.initialGuessTest.portArray.out1[1]",
EMAPortInstanceSymbol.KIND).orElse(null);
assertFalse(port.isInitialGuessPresent());
assertNotNull(port);
port = symTab.<EMAPortInstanceSymbol>resolve(
"testing.initialGuessTest.portArray.out1[2]",
EMAPortInstanceSymbol.KIND).orElse(null);
assertTrue(port.isInitialGuessPresent());
assertEquals(7.0, ((ASTUnitNumberExpression) port.getInitialGuess()).getNumberWithUnit().getNumber().get(), 0.001);
assertNotNull(port);
port = symTab.<EMAPortInstanceSymbol>resolve(
"testing.initialGuessTest.portArray.out1[3]",
EMAPortInstanceSymbol.KIND).orElse(null);
assertFalse(port.isInitialGuessPresent());
assertNotNull(port);
}
}
/* (c) https://github.com/MontiCore/monticore */
package de.monticore.lang.embeddedmontiarc.cocos;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._ast.ASTEmbeddedMontiArcNode;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._cocos.EmbeddedMontiArcCoCoChecker;
import org.junit.Test;
public class InitialValueCoCoTest extends AbstractCoCoTest {
private void checkModel(String model) {
ASTEmbeddedMontiArcNode astNode = getAstNode("", model);
EmbeddedMontiArcCoCoChecker checker = new EmbeddedMontiArcCoCoChecker();
checker.addCoCo(new InitialGuessIsAssignment());
checker.checkAll(astNode);
}
@Test
public void testValid() {
checkModel("testing.InitialGuessTest");
checkModel("testing.InitialGuessFromParameter");
}
}
/* (c) https://github.com/MontiCore/monticore */
package testing;
component ExpandedParameterInstance(N1 val = 2){
component ExpandedParameterInstance(N1 val = 3){
instance ExpandedParameter(val) basicParameter;
......
/* (c) https://github.com/MontiCore/monticore */
package testing;
component InitialGuessFromParameter(Q val = 3) {
instance InitialGuessSimple{out1 = val} simple;
}
\ No newline at end of file
/* (c) https://github.com/MontiCore/monticore */
package testing;
component InitialGuessPortArray {
port
out Q out1[3];
}
\ No newline at end of file
/* (c) https://github.com/MontiCore/monticore */
package testing;
import fas.basicLibrary.*;
component InitialGuessSimple {
ports
out Q out1;
}
\ No newline at end of file
/* (c) https://github.com/MontiCore/monticore */
package testing;
component InitialGuessTest {
instance InitialGuessSimple{out1 = 2} simple;
instance InitialGuessFromParameter fromParameterDefault;
instance InitialGuessFromParameter(5) fromParameterGiven;
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