Verified Commit a6cd818f authored by Stefan Brunecker's avatar Stefan Brunecker
Browse files

Add type definition to Port data structure

parent 1b497621
package de.monticore.lang.monticar.generator.html;
import static de.monticore.lang.monticar.generator.GeneratorUtil.filterMultipleArrayPorts;
import static de.monticore.lang.monticar.generator.GeneratorUtil.getDimension;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.ExpandedComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.PortSymbol;
import de.monticore.lang.monticar.common2._ast.ASTCommonMatrixType;
import de.monticore.lang.monticar.freemarker.TemplateProcessor;
import de.monticore.lang.monticar.generator.GeneratorUtil;
import de.monticore.lang.monticar.ts.references.MCASTTypeSymbolReference;
import de.monticore.lang.monticar.types2._ast.ASTElementType;
import de.monticore.lang.monticar.types2._ast.ASTType;
import freemarker.template.TemplateException;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;
......@@ -51,8 +58,8 @@ public class HtmlGenerator {
*/
public void generate(ExpandedComponentInstanceSymbol model)
throws IOException, TemplateException {
List<Port> inports = produceInports(filterMultipleArrayPorts(model.getIncomingPorts()));
List<Port> outports = produceOutports(filterMultipleArrayPorts(model.getOutgoingPorts()));
List<Port> inports = produceInports(model.getIncomingPorts());
List<Port> outports = produceOutports(model.getOutgoingPorts());
Map<String, Object> dataModel = new HashMap<>();
dataModel.put("model", wasmNamingFunction.apply(model));
......@@ -73,14 +80,38 @@ public class HtmlGenerator {
private List<Port> producePorts(Collection<PortSymbol> ports,
Function<PortSymbol, String> methodNameFunction) {
return ports.stream().map(p -> port(p.getNameWithoutArrayBracketPart(),
methodNameFunction.apply(p))).collect(Collectors.toList());
return filterMultipleArrayPorts(ports).stream().map(
p -> port(p.getNameWithoutArrayBracketPart(), methodNameFunction.apply(p),
getType(ports, p))).collect(Collectors.toList());
}
private Port port(String name, String wrapperFunction) {
private String getType(Collection<PortSymbol> ports, PortSymbol port) {
MCASTTypeSymbolReference typeReference = (MCASTTypeSymbolReference) port.getTypeReference();
ASTType astType = typeReference.getAstType();
Optional<String> elementType;
if (astType instanceof ASTCommonMatrixType) {
ASTCommonMatrixType type = (ASTCommonMatrixType) astType;
elementType = type.getElementType().getTElementType();
} else if (astType instanceof ASTElementType) {
ASTElementType type = (ASTElementType) astType;
elementType = type.getTElementType();
} else {
throw new RuntimeException("Unexpected ASTType: " + astType);
}
String type = elementType.orElse("");
String[] dimension = getDimension(ports, port);
String dim = dimension.length > 0 ?
"[" + Arrays.stream(dimension).collect(Collectors.joining("][")) + "]" : "";
return type + dim;
}
private Port port(String name, String wrapperFunction, String type) {
Port port = new Port();
port.setName(name);
port.setWrapperFunction(wrapperFunction);
port.setType(type);
return port;
}
}
......@@ -4,6 +4,7 @@ public class Port {
private String name;
private String wrapperFunction;
private String type;
public String getName() {
return name;
......@@ -20,4 +21,8 @@ public class Port {
public void setWrapperFunction(String wrapperFunction) {
this.wrapperFunction = wrapperFunction;
}
public void setType(String type) {
this.type = type;
}
}
Supports Markdown
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