Commit 7c5fa253 authored by Malte Heithoff's avatar Malte Heithoff
Browse files

Fix Ports and Parameters

parent 2a40a6cb
Pipeline #352052 passed with stage
in 3 minutes and 19 seconds
/* (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,8 +255,7 @@ 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);
// instances
......
......@@ -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())
......
......@@ -27,6 +27,7 @@ import de.monticore.symboltable.MutableScope;
import de.monticore.symboltable.Symbol;
import de.monticore.symboltable.resolving.ResolvingFilter;
import de.monticore.symboltable.types.references.ActualTypeArgument;
import de.se_rwth.commons.Names;
import de.se_rwth.commons.logging.Log;
import java.util.*;
......@@ -359,12 +360,13 @@ public class EMAComponentInstanceBuilder {
final MutableScope scope = (MutableScope) sym.getSpannedScope();
resolvingFilters.stream().forEachOrdered(f -> scope.addResolver(f));
String componentFullName = Names.getQualifiedName(sym.getPackageName(), sym.getName());
ports.stream().forEachOrdered(p ->
instantiatePortSymbol(p, sym.getFullName(), scope)); // must be cloned since we change it if it has
handlePort(p, componentFullName, scope)); // must be cloned since we change it if it has
addPortArraySymbolsToInstance(sym);
// generics
connectors.stream().forEachOrdered(c -> instantiateConnectorSymbol(c, sym.getFullName(), scope));
connectors.stream().forEachOrdered(c -> instantiateConnectorSymbol(c, componentFullName, scope));
subComponents.stream().forEachOrdered(s -> scope.add(s));
sym.setActualTypeArguments(actualTypeArguments.values().stream().collect(Collectors.toList()));
......@@ -375,7 +377,7 @@ public class EMAComponentInstanceBuilder {
// set arguments
// there are either no arguments or the equal number to parameters
if (!arguments.isEmpty() && arguments.size() != parameters.size()) {
Log.error("TODO Wrong number of arguments: " + sym.getFullName());
Log.error("TODO Wrong number of arguments: " + componentFullName);
}
setDefaultValuesToArguments(sym);
sym.setArguments(arguments);
......@@ -420,9 +422,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) {
......
......@@ -79,7 +79,10 @@ 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());
for (EMAConnectorSymbol emaConnectorSymbol : cmp.getConnectors())
Log.info(emaConnectorSymbol.toString(), "Building Connector:");
// add sub components
......@@ -95,7 +98,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())
.build());
Log.debug(inst.getInstanceInformation().get().getInstanceNumberForArgumentIndex(0) + "", "InstanceInformation:");
Log.debug(inst.toString(), "ComponentInstance CreateInstance PostSub");
......
......@@ -228,10 +228,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());
}
......
/* (c) https://github.com/MontiCore/monticore */
package testing;
component ExpandedParameterInstance(N1 val = 2){
component ExpandedParameterInstance(N1 val = 3){
instance ExpandedParameter(val) basicParameter;
......
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