Loading EDG/src/main/java/edg/EDGFactory.java +3 −5 Original line number Diff line number Diff line Loading @@ -4,10 +4,7 @@ import java.util.List; import java.util.Set; import java.util.function.Predicate; import edg.constraint.AccessConstraint; import edg.constraint.DataConstructorConstraint; import edg.constraint.EdgeConstraint; import edg.constraint.EmptyConstraint; import edg.constraint.*; import edg.edge.*; import edg.graph.Node; Loading Loading @@ -224,6 +221,7 @@ public class EDGFactory { { final Node from = edg.getEdgeSource(valueEdge); final EdgeConstraint edgeConstraint = valueEdge.getConstraint(); if (node.getType() != Node.Type.Clause || !(edgeConstraint instanceof LiteralConstraint)) edg.removeEdge(valueEdge); final Edge e = new Edge(Edge.Type.Value, edgeConstraint); edg.addEdge(from, result, e); Loading EDG/src/main/java/edg/constraint/LiteralConstraint.java +2 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,8 @@ public class LiteralConstraint extends EdgeConstraint { return super.wrap(); } protected List<Constraints> resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, LiteralConstraint topConstraint, int productionDepth){ throw new IllegalStateException("There is no situation where 2 literal constraints are stacked consecutively."); return super.wrap(constraints); // throw new IllegalStateException("There is no situation where 2 literal constraints are stacked consecutively."); } protected List<Constraints> resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, GrammarConstraint topConstraint, int productionDepth) Loading e-Knife/src/main/java/eknife/erlang/ControlFlowGenerator.java +10 −9 Original line number Diff line number Diff line Loading @@ -162,8 +162,8 @@ public class ControlFlowGenerator extends VoidVisitor<Void> implements Generator { super.visitDataConstructor(n, arg); connectTo(n); if (graph.isPatternZone(n) && !this.isMatchExprPattern(n)) guardHangingStack.peek().addAll(hangingNodes); // if (graph.isPatternZone(n) && !this.isMatchExprPattern(n)) // guardHangingStack.peek().addAll(hangingNodes); } @Override Loading Loading @@ -240,6 +240,7 @@ public class ControlFlowGenerator extends VoidVisitor<Void> implements Generator else absorbentPattern = false; super.visitSelectable(n, arg); connectTo(n); } @Override Loading Loading @@ -279,8 +280,8 @@ public class ControlFlowGenerator extends VoidVisitor<Void> implements Generator public void visitLiteral(Node n, Void arg) { connectTo(n); if (graph.isPatternZone(n) && !this.isMatchExprPattern(n)) guardHangingStack.peek().addAll(hangingNodes); // if (graph.isPatternZone(n) && !this.isMatchExprPattern(n)) // guardHangingStack.peek().addAll(hangingNodes); } @Override Loading Loading @@ -372,11 +373,11 @@ public class ControlFlowGenerator extends VoidVisitor<Void> implements Generator super.visitList(n, arg); connectTo(n); if (graph.isPatternZone(n) && !this.isMatchExprPattern(n)) { if ((graph.getParent(n).getType() != Node.Type.List) && graph.getChildren(n).isEmpty()); guardHangingStack.peek().addAll(hangingNodes); } // if (graph.isPatternZone(n) && !this.isMatchExprPattern(n)) { // if ((graph.getParent(n).getType() == Node.Type.List) || // !graph.getChildren(n).isEmpty()) // guardHangingStack.peek().addAll(hangingNodes); // } } private boolean isAbsorbentPattern(Node n) { Loading e-Knife/src/main/java/eknife/erlang/ValueEdgeGenerator.java +34 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ public class ValueEdgeGenerator { this.generateRoutineCallEdges(); this.generateReturnEdges(); this.generateRoutineEdges(); this.generateImplicitRestrictionEdges(); } private void generateEqualityEdges() Loading Loading @@ -181,6 +182,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)); } } } Loading Loading @@ -339,4 +341,36 @@ public class ValueEdgeGenerator { this.last.addEdge(clause, routine, Edge.Type.Value, EmptyConstraint.getConstraint()); } } private void generateImplicitRestrictionEdges() { final List<Node> clauses = this.last.getNodes(Node.Type.Clause); for (Node clause : clauses) { final Node parametersNode = this.last.getChild(clause, Node.Type.Parameters); final List<Node> parameters = this.last.getChildren(parametersNode); for (Node parameter : parameters) generateImplicitRestrictions(parameter, List.of(clause)); } } private void generateImplicitRestrictions(Node restrictionNode, List<Node> expressionNode){ if (this.isImplicitRestrictionNode(restrictionNode)) { List<Node> children = this.last.getChildren(restrictionNode); if (children.stream().noneMatch(c -> isImplicitRestrictionNode(c))) for (Node node : expressionNode) this.last.addEdge(restrictionNode, node, Edge.Type.Value, LiteralConstraint.getConstraint()); for (Node child : children) this.generateImplicitRestrictions(child, expressionNode); } } private boolean isImplicitRestrictionNode(Node node){ switch(node.getType()){ case Literal: case DataConstructor: case List: return true; default: return false; } } } No newline at end of file Loading
EDG/src/main/java/edg/EDGFactory.java +3 −5 Original line number Diff line number Diff line Loading @@ -4,10 +4,7 @@ import java.util.List; import java.util.Set; import java.util.function.Predicate; import edg.constraint.AccessConstraint; import edg.constraint.DataConstructorConstraint; import edg.constraint.EdgeConstraint; import edg.constraint.EmptyConstraint; import edg.constraint.*; import edg.edge.*; import edg.graph.Node; Loading Loading @@ -224,6 +221,7 @@ public class EDGFactory { { final Node from = edg.getEdgeSource(valueEdge); final EdgeConstraint edgeConstraint = valueEdge.getConstraint(); if (node.getType() != Node.Type.Clause || !(edgeConstraint instanceof LiteralConstraint)) edg.removeEdge(valueEdge); final Edge e = new Edge(Edge.Type.Value, edgeConstraint); edg.addEdge(from, result, e); Loading
EDG/src/main/java/edg/constraint/LiteralConstraint.java +2 −1 Original line number Diff line number Diff line Loading @@ -40,7 +40,8 @@ public class LiteralConstraint extends EdgeConstraint { return super.wrap(); } protected List<Constraints> resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, LiteralConstraint topConstraint, int productionDepth){ throw new IllegalStateException("There is no situation where 2 literal constraints are stacked consecutively."); return super.wrap(constraints); // throw new IllegalStateException("There is no situation where 2 literal constraints are stacked consecutively."); } protected List<Constraints> resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, GrammarConstraint topConstraint, int productionDepth) Loading
e-Knife/src/main/java/eknife/erlang/ControlFlowGenerator.java +10 −9 Original line number Diff line number Diff line Loading @@ -162,8 +162,8 @@ public class ControlFlowGenerator extends VoidVisitor<Void> implements Generator { super.visitDataConstructor(n, arg); connectTo(n); if (graph.isPatternZone(n) && !this.isMatchExprPattern(n)) guardHangingStack.peek().addAll(hangingNodes); // if (graph.isPatternZone(n) && !this.isMatchExprPattern(n)) // guardHangingStack.peek().addAll(hangingNodes); } @Override Loading Loading @@ -240,6 +240,7 @@ public class ControlFlowGenerator extends VoidVisitor<Void> implements Generator else absorbentPattern = false; super.visitSelectable(n, arg); connectTo(n); } @Override Loading Loading @@ -279,8 +280,8 @@ public class ControlFlowGenerator extends VoidVisitor<Void> implements Generator public void visitLiteral(Node n, Void arg) { connectTo(n); if (graph.isPatternZone(n) && !this.isMatchExprPattern(n)) guardHangingStack.peek().addAll(hangingNodes); // if (graph.isPatternZone(n) && !this.isMatchExprPattern(n)) // guardHangingStack.peek().addAll(hangingNodes); } @Override Loading Loading @@ -372,11 +373,11 @@ public class ControlFlowGenerator extends VoidVisitor<Void> implements Generator super.visitList(n, arg); connectTo(n); if (graph.isPatternZone(n) && !this.isMatchExprPattern(n)) { if ((graph.getParent(n).getType() != Node.Type.List) && graph.getChildren(n).isEmpty()); guardHangingStack.peek().addAll(hangingNodes); } // if (graph.isPatternZone(n) && !this.isMatchExprPattern(n)) { // if ((graph.getParent(n).getType() == Node.Type.List) || // !graph.getChildren(n).isEmpty()) // guardHangingStack.peek().addAll(hangingNodes); // } } private boolean isAbsorbentPattern(Node n) { Loading
e-Knife/src/main/java/eknife/erlang/ValueEdgeGenerator.java +34 −0 Original line number Diff line number Diff line Loading @@ -47,6 +47,7 @@ public class ValueEdgeGenerator { this.generateRoutineCallEdges(); this.generateReturnEdges(); this.generateRoutineEdges(); this.generateImplicitRestrictionEdges(); } private void generateEqualityEdges() Loading Loading @@ -181,6 +182,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)); } } } Loading Loading @@ -339,4 +341,36 @@ public class ValueEdgeGenerator { this.last.addEdge(clause, routine, Edge.Type.Value, EmptyConstraint.getConstraint()); } } private void generateImplicitRestrictionEdges() { final List<Node> clauses = this.last.getNodes(Node.Type.Clause); for (Node clause : clauses) { final Node parametersNode = this.last.getChild(clause, Node.Type.Parameters); final List<Node> parameters = this.last.getChildren(parametersNode); for (Node parameter : parameters) generateImplicitRestrictions(parameter, List.of(clause)); } } private void generateImplicitRestrictions(Node restrictionNode, List<Node> expressionNode){ if (this.isImplicitRestrictionNode(restrictionNode)) { List<Node> children = this.last.getChildren(restrictionNode); if (children.stream().noneMatch(c -> isImplicitRestrictionNode(c))) for (Node node : expressionNode) this.last.addEdge(restrictionNode, node, Edge.Type.Value, LiteralConstraint.getConstraint()); for (Node child : children) this.generateImplicitRestrictions(child, expressionNode); } } private boolean isImplicitRestrictionNode(Node node){ switch(node.getType()){ case Literal: case DataConstructor: case List: return true; default: return false; } } } No newline at end of file