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

New implicit restriction treatment

parent 3cc887ed
Loading
Loading
Loading
Loading
+0 −22
Original line number Diff line number Diff line
@@ -59,7 +59,6 @@ public class EDGFactory {
					edg.removeEDGEdge(parent, node, Edge.Type.Structural);
					edg.setRemovableEdge(parent, node, Edge.Type.Structural);
				});
		moveGeneratorValueStructureArcs();
	}

	public static boolean isCallNode(Node node)
@@ -267,25 +266,4 @@ 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
+2 −0
Original line number Diff line number Diff line
@@ -212,6 +212,8 @@ public class ControlFlowGenerator extends VoidVisitor<Void> implements Generator
			hangingNodes.addAll(guardHangingStack.peek());
			guardHangingStack.peek().clear();
			graph.getChild(n, Node.Type.Selectable).accept(this, arg);
			if (!absorbentPattern)
				guardHangingStack.peek().addAll(Set.copyOf(hangingNodes));
			graph.getChild(n, Node.Type.Guard).accept(this, arg);
			if (!absorbentPattern || !absorbentCondition)
				guardHangingStack.peek().addAll(Set.copyOf(hangingNodes));
+19 −120
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ public class ValueEdgeGenerator {
		this.generateGeneratorEdges();
		this.generateRoutineCallEdges();
		this.generateReturnEdges();
		this.generateGuardEdges();
		this.generateRoutineEdges();
		this.generateImplicitRestrictionEdges();
	}
@@ -80,26 +81,6 @@ public class ValueEdgeGenerator {
				final DataConstructorConstraint constraint = new DataConstructorConstraint(operation,
						childIndex + "/" + (dataConstructorChildren.size()-1));
				this.last.addEdge(from, to, Edge.Type.Value, constraint);

				if (!isPatternZone){
					// In case the parent is a List this structure is also necessary
					final Node parent = this.last.getParent(dataConstructor);
					if (parent.getType() == Node.Type.List) {
						StructuralConstraint sLc = new StructuralConstraint(AccessConstraint.Operation.Remove,
							ListConstraint.Position.HS);
						this.last.addEdge(dataConstructor, parent, Edge.Type.ValueStructure, sLc);
					}
					switch(dataConstructorChild.getType()){
						case DataConstructor:
						case List:
							StructuralConstraint sDc = new StructuralConstraint(AccessConstraint.Operation.Remove,
									childIndex + "/" + (dataConstructorChildren.size()-1));
							this.last.addEdge(dataConstructorChild, dataConstructor, Edge.Type.ValueStructure, sDc);
							break;
						default:
							break;
					}
				}
			}
		}
	}
@@ -127,33 +108,9 @@ public class ValueEdgeGenerator {
			} else {
				this.last.addEdge(head, list, Edge.Type.Value, headConstraint);
				this.last.addEdge(tail, list, Edge.Type.Value, tailConstraint);
				if (this.last.getParent(list).getType() == Node.Type.List){
					StructuralConstraint sLc = new StructuralConstraint(AccessConstraint.Operation.Remove,
							ListConstraint.Position.HS);
					this.last.addEdge(list, this.last.getParent(list), Edge.Type.ValueStructure, sLc);
				}
			}
		}
	}
//	private void generateDataConstructorAccessEdges()
//	{
//		final List<Node> dataConstructorAccesses = this.last.getNodes(Node.Type.DataConstructorAccess);
//
//		for (Node dataConstructorAccess : dataConstructorAccesses)
//		{
//			final Node dataConstructorAccessResult = this.last.getSibling(dataConstructorAccess, Node.Type.Result);
//			final Node dataConstructor = this.last.getChild(dataConstructorAccess, 0);
//			final Node dataConstructorResult = this.last.getSibling(dataConstructor, Node.Type.Result);
//			final Node indexExpression = this.last.getChild(dataConstructorAccess, 1);
//			final Node index = this.last.getChild(indexExpression, 0);
//			final Node indexResult = this.last.getSibling(index, Node.Type.Result);
//			final String indexValue = index.getType() == Node.Type.Literal ? index.getName() : "*";
//			final EdgeConstraint constraint = new DataConstructorConstraint(AccessConstraint.Operation.Add, indexValue);
//
//			this.last.addEdge(dataConstructorResult, dataConstructorAccessResult, Edge.Type.Value, constraint);
//			this.last.addEdge(indexResult, dataConstructorAccessResult, Edge.Type.Value, AsteriskConstraint.getConstraint());
//		}
//	}
			}
		}
	}
	private void generateOperationEdges()
	{
		final List<Node> operations = this.last.getNodes(Node.Type.Operation);
@@ -182,7 +139,7 @@ public class ValueEdgeGenerator {
				if (selector != null) {
					final Node selectable = this.last.getChild(selectableNode, Node.Type.Value);
					this.last.addEdge(selector, selectable, Edge.Type.Value, EmptyConstraint.getConstraint());
					this.generateImplicitRestrictions(selectable,List.of(_switch,selectableNode));
					this.generateImplicitRestrictions(selectable,List.of(selectableNode));
				}
			}
		}
@@ -216,75 +173,12 @@ public class ValueEdgeGenerator {
		{
			final Node pattern = this.last.getChild(generator, Node.Type.Variable);
			final Node expression = this.last.getChild(generator, Node.Type.Iterator);
			this.generateGeneratorPatternStructureEdges(generator, pattern);
			this.last.addEdge(expression, generator, Edge.Type.Value, listStructureConstraint);
			this.generateImplicitRestrictions(pattern, List.of(generator));
			this.last.addEdge(expression, generator, Edge.Type.Value, listStructureConstraint); // May be removed
			this.last.addEdge(expression, pattern, Edge.Type.Value, positiveConstraint);
		}
	}

	private void generateGeneratorPatternStructureEdges(Node parent, Node pattern){
		switch(pattern.getType()){
			case List:
			case DataConstructor:
				if (parent.getType() == Node.Type.Generator)
					this.last.addEdge(pattern, parent, Edge.Type.ValueStructure, EmptyConstraint.getConstraint());
				else {
					switch(parent.getType()){
						case List:
							StructuralConstraint sLc = new StructuralConstraint(AccessConstraint.Operation.Add, ListConstraint.Position.HS);
							this.last.addEdge(pattern, parent, Edge.Type.ValueStructure, sLc);
						case DataConstructor:
							StructuralConstraint sDc = new StructuralConstraint(AccessConstraint.Operation.Add,
									this.last.getChildIndex(pattern) + "/" + (this.last.getChildren(parent).size()-1));
							this.last.addEdge(pattern, parent, Edge.Type.ValueStructure, sDc);
					}
//					StructuralConstraint sLc = new StructuralConstraint(AccessConstraint.Operation.Add, ListConstraint.Position.HS);
//					this.last.addEdge(pattern, parent, Edge.Type.ValueStructure, sLc);
				}
				generateGeneratorPatternStructureEdges(pattern);
				break;
//			case DataConstructor:
//				if (parent.getType() == Node.Type.Generator)
//					this.last.addEdge(pattern, parent, Edge.Type.ValueStructure, EmptyConstraint.getConstraint());
//				else {
//					switch(parent.getType()){
//						case List:
//							StructuralConstraint sLc2 = new StructuralConstraint(AccessConstraint.Operation.Add, ListConstraint.Position.HS);
//							this.last.addEdge(pattern, parent, Edge.Type.ValueStructure, sLc2);
//						case DataConstructor:
//							StructuralConstraint sDc2 = new StructuralConstraint(AccessConstraint.Operation.Add,
//									this.last.getChildIndex(pattern) + "/" + (this.last.getChildren(parent).size()-1));
//							this.last.addEdge(pattern, parent, Edge.Type.ValueStructure, sDc2);
//					}
//				}
//				generateGeneratorPatternStructureEdges(pattern);
//				break;
			case Literal:
					final Node genNode = this.last.getAncestor(parent, Node.Type.Generator);
					this.last.addEdge(pattern, genNode, Edge.Type.Value, EmptyConstraint.getConstraint());
				// generateGeneratorPatternStructureEdges(pattern);
				break;
			default:
				break;
		}
	}

	private void generateGeneratorPatternStructureEdges(Node pattern) {
		List<Node> children = last.getChildrenNonResult(pattern);
		boolean allChildrenLeaves = true;
		for (Node child : children)
			if (child.getType() == Node.Type.DataConstructor || child.getType() == Node.Type.List) {
				allChildrenLeaves = false;
				this.generateGeneratorPatternStructureEdges(pattern, child);
			}
		if (allChildrenLeaves) {
			Node generator = this.last.getAncestor(pattern, Node.Type.Generator);
			Node  variableIt = this.last.getChild(generator, Node.Type.Iterator);
			final EdgeConstraint positiveConstraint = new ListComprehensionConstraint(ListComprehensionConstraint.Operation.Add);
			this.last.addEdge(variableIt, pattern, Edge.Type.ValueStructure, positiveConstraint);
		}
	}

	private void generateRoutineCallEdges()
	{
		final List<Node> calls = this.last.getNodes(Node.Type.Call);
@@ -332,10 +226,6 @@ public class ValueEdgeGenerator {

		for (Node routine : routines)
		{
//			final Node routineParent = this.last.getParent(routine);
//			final Node.Type routineParentType = routineParent.getType();
//			if (routineParentType == Node.Type.Module)
//				continue;
			final List<Node> clauses = this.last.getChildren(routine);
			for (Node clause : clauses)
				this.last.addEdge(clause, routine, Edge.Type.Value, EmptyConstraint.getConstraint());
@@ -352,14 +242,14 @@ public class ValueEdgeGenerator {
		}
	}

	private void generateImplicitRestrictions(Node restrictionNode, List<Node> expressionNode){
		if (this.isImplicitRestrictionNode(restrictionNode)) {
			List<Node> children = this.last.getChildren(restrictionNode);
	private void generateImplicitRestrictions(Node patternNode, List<Node> controlExpressionNode){
		if (this.isImplicitRestrictionNode(patternNode)) {
			List<Node> children = this.last.getChildren(patternNode);
			if (children.stream().noneMatch(c -> isImplicitRestrictionNode(c)))
				for (Node node : expressionNode)
					this.last.addEdge(restrictionNode, node, Edge.Type.Value, LiteralConstraint.getConstraint());
				for (Node node : controlExpressionNode)
					this.last.addEdge(patternNode, node, Edge.Type.Value, LiteralConstraint.getConstraint());
			for (Node child : children)
					this.generateImplicitRestrictions(child, expressionNode);
					this.generateImplicitRestrictions(child, controlExpressionNode);
		}
	}

@@ -373,4 +263,13 @@ public class ValueEdgeGenerator {
				return false;
		}
	}

	private void generateGuardEdges(){
		final List<Node> guards = this.last.getNodes(Node.Type.Guard);
		for (Node guard : guards) {
			List<Node> children = this.last.getChildren(guard);
			for (Node child : children)
				this.last.addEdge(child, guard, Edge.Type.Value, AsteriskConstraint.getConstraint());
		}
	}
}
 No newline at end of file