Commit fc7ceba1 authored by Sergio Pérez's avatar Sergio Pérez
Browse files

New treatment for generators:

- Generators implicit and explicit restrictions are now more accurately treated
- Created +-[]S (List structure constraints)
- Created +-{}S (Tuple structure constraints)
- New kind of edges (ValueStructural Edges)
- Prevented the interference of the traversal of (Black) Structural Edges with other edges
parent aec5fda5
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import java.io.File;
import java.util.*;
import java.util.function.Predicate;

import edg.constraint.AccessConstraint;
import edg.constraint.EdgeConstraint;
import edg.graph.EDG;
import edg.graph.Edge;
@@ -124,6 +123,7 @@ public class DotFactory {
	private static final Attribute TURQUOISE  = DefaultAttribute.createAttribute("turquoise");
	private static final Attribute DEEPPINK = DefaultAttribute.createAttribute("deeppink");
	private static final Attribute SKYBLUE = DefaultAttribute.createAttribute("skyblue");
	private static final Attribute STEELBLUE = DefaultAttribute.createAttribute("steelblue1");
	// Numbers
	private static final Attribute ONE   = DefaultAttribute.createAttribute(1);
	private static final Attribute TWO   = DefaultAttribute.createAttribute(2);
@@ -231,6 +231,12 @@ public class DotFactory {
					attrs.put("constraint", FALSE);
					attrs.put("style", DASHED);
					break;
				case ValueStructure:
					attrs.put("color", STEELBLUE);
					attrs.put("penwidth", TWO);
					attrs.put("constraint", FALSE);
					attrs.put("style", DASHED);
					break;
				case CallReq:
					attrs.put("color", SKYBLUE);
					attrs.put("penwidth", TWO);
+23 −0
Original line number Diff line number Diff line
@@ -7,6 +7,7 @@ import java.util.function.Predicate;
import edg.constraint.AccessConstraint;
import edg.constraint.DataConstructorConstraint;
import edg.constraint.EdgeConstraint;
import edg.constraint.EmptyConstraint;
import edg.edge.*;
import edg.graph.Node;

@@ -61,6 +62,7 @@ public class EDGFactory {
					edg.removeEDGEdge(parent, node, Edge.Type.Structural);
					edg.setRemovableEdge(parent, node, Edge.Type.Structural);
				});
		moveGeneratorValueStructureArcs();
	}

	public static boolean isCallNode(Node node)
@@ -269,4 +271,25 @@ public class EDGFactory {
			edg.addEdge(result, to, e);
		}
	}

	private void moveGeneratorValueStructureArcs(){
		final List<Node> generatorNodes = this.last.getNodes(Node.Type.Generator);
		for (Node generator : generatorNodes){
			final Node expr = edg.getChild(generator, Node.Type.Iterator);
			final Set<Edge> outgoingEdges = edg.outgoingEdgesOf(expr);
			outgoingEdges.removeIf(e -> e.getType() != Edge.Type.ValueStructure);
			if (outgoingEdges.isEmpty())
				continue;

			for (Edge edge : outgoingEdges)
			{
				final Node from = edg.getEdgeSource(edge);
				final Node to = edg.getEdgeTarget(edge);
				final EdgeConstraint edgeConstraint = edge.getConstraint();
				edg.removeEdge(edge);
				final Edge e = new Edge(Edge.Type.ValueStructure,edgeConstraint);
				edg.addEdge(edg.getResFromNode(from), to, e);
			}
		}
	}
}
 No newline at end of file
+3 −1
Original line number Diff line number Diff line
@@ -9,7 +9,7 @@ import java.util.List;
public abstract class AccessConstraint extends EdgeConstraint {
	public enum Operation {Add, Remove}

	public enum CompositeType {DataConstructor, List, ListComprehension}
	public enum CompositeType {DataConstructor, List, ListComprehension}//, Literal}

	protected final Operation operation;
	protected final CompositeType compositeType;
@@ -79,6 +79,8 @@ public abstract class AccessConstraint extends EdgeConstraint {
				return super.wrap(super.push(phase, constraints));
			if (this.cancels(topConstraint))
				return super.wrap(super.pop(constraints));
			if (this instanceof ListConstraint && ((ListConstraint) this).letThrough(topConstraint))
				return super.wrap(constraints);
			return super.wrap();
		}

+2 −0
Original line number Diff line number Diff line
@@ -54,6 +54,8 @@ public class ListComprehensionConstraint extends AccessConstraint {
			if (listConstraint.operation != AccessConstraint.Operation.Add)
				break;

			if (listConstraint.position == ListConstraint.Position.S)
				return super.wrap(constraints);;
			if (listConstraint.position == ListConstraint.Position.H)
				correctlyTreated = true;
			constraintsClone.popEdgeConstraint();
+16 −2
Original line number Diff line number Diff line
@@ -2,7 +2,12 @@ package edg.constraint;

public class ListConstraint extends AccessConstraint
{
	public enum Position { H, T }
	public enum Position { H, T, S }
	// H -> Head
	// T -> Tail
	// S -> Structure: Interested in the list structure but not in its elements (Only positive constraints)
		// -[]T can be traversed but does not consume the +[]S
		// -[]H cannot be traversed

	protected final Position position;

@@ -38,7 +43,7 @@ public class ListConstraint extends AccessConstraint
	public String toString()
	{
		if (this.position != null)
			return super.toString() + this.position.toString();
			return super.toString() + this.position;
		return super.toString();
	}

@@ -48,4 +53,13 @@ public class ListConstraint extends AccessConstraint
			return new ListConstraint(Operation.Remove, this.position);
		return new ListConstraint(Operation.Add, this.position);
	}

	public boolean letThrough(AccessConstraint topConstraint){
		if (!(topConstraint instanceof ListConstraint))
			return false;
		ListConstraint top = (ListConstraint) topConstraint;
		if (this.position == Position.T && top.position == Position.S)
			return true;
		return false;
	}
}
 No newline at end of file
Loading