private Network createNetwork(Element element) { Network network = IrFactory.eINSTANCE.createNetwork(); String id = element.getAttribute("id"); network.setId(id); doAnnotations(network, element); addIrObject(id, network); network.setType((TypeActor) createType(getChild(element, "Type"))); List<Element> declarations = getChildren(element, "Decl"); for (Element e : declarations) { Declaration decl = (Declaration) createDeclaration(e); network.getDeclarations().add(decl); if (decl instanceof Variable && ((Variable) decl).isParameter()) { network.getParameters().add((Variable) decl); } } List<Element> ports = getChildren(element, "Port"); for (Element e : ports) { Port port = createPort(e); if (e.getAttribute("direction").equals("in")) { network.getInputPorts().add(port); } else { network.getOutputPorts().add(port); } } List<Element> instances = getChildren(element, "Instance"); for (Element e : instances) { ActorInstance instance = createActorInstance(e); network.getActors().add(instance); } List<Element> connections = getChildren(element, "Connection"); for (Element e : connections) { Connection connection = createConnection(e, network); network.getConnections().add(connection); } return network; }
@Override public Stream caseNetwork(Network network) { s = new Stream( folder + File.separator + UtilIR.namespace2Path(network.getType().getNamespace()) + File.separator + network.getType().getName() + ".dot"); java.util.Date date = new java.util.Date(); s.println(); s.println("/* --- CAL Dotty Printer " + new Timestamp(date.getTime()) + " --- */"); s.println("digraph " + network.getType().getName() + "{"); s.inc(); s.println("node [shape=none];"); s.println("rankdir=LR;"); for (ActorInstance instance : network.getActors()) { caseActorInstance(instance); } for (Connection c : network.getConnections()) { doSwitch(c); } /* Network input ports */ List<Port> inputPorts = network.getInputPorts(); if (inputPorts.size() > 0) { s.println("__INs" + " [label=<"); s.println("<TABLE BORDER=\"1\" CELLBORDER=\"0\" CELLSPACING=\"0\">"); s.println("<TR><TD COLSPAN=\"2\">INs</TD></TR>"); s.inc(); for (int i = 0; i < inputPorts.size(); i++) { String in = inputPorts.get(i).getName(); s.println("<TR><TD></TD><TD ALIGN=\"RIGHT\" PORT=\"" + in + "\">" + in + "</TD></TR>"); } s.printlnDec("</TABLE>>];"); } /* Network output ports */ List<Port> outputPorts = network.getOutputPorts(); if (outputPorts.size() > 0) { s.println("__OUTs" + " [label=<"); s.println("<TABLE BORDER=\"1\" CELLBORDER=\"0\" CELLSPACING=\"0\">"); s.printlnInc("<TR><TD COLSPAN=\"2\">OUTs</TD></TR>"); for (int i = 0; i < outputPorts.size(); i++) { String out = outputPorts.get(i).getName(); s.println("<TR><TD ALIGN=\"LEFT\" PORT=\"" + out + "\">" + out + "</TD><TD></TD></TR>"); } s.printlnDec("</TABLE>>];"); } s.println(); s.println(); s.println("}"); return s; }