From 69a10263e51c2dbac51c02250bbe155a69c0654a Mon Sep 17 00:00:00 2001 From: serperu Date: Tue, 28 Sep 2021 12:47:11 +0200 Subject: [PATCH] Structural Constraint Removal --- .../java/edg/constraint/AccessConstraint.java | 3 - .../edg/constraint/AddNodeConstraint.java | 5 +- .../edg/constraint/AsteriskConstraint.java | 18 ---- .../java/edg/constraint/EdgeConstraint.java | 3 - .../java/edg/constraint/EmptyConstraint.java | 4 - .../edg/constraint/GrammarConstraint.java | 7 -- .../ListComprehensionConstraint.java | 6 -- .../java/edg/constraint/ListConstraint.java | 2 +- .../edg/constraint/LiteralConstraint.java | 5 - .../java/edg/constraint/PhaseConstraint.java | 7 +- .../edg/constraint/SeekingConstraint.java | 4 - .../edg/constraint/StructuralConstraint.java | 101 ------------------ EDG/src/main/java/edg/graph/Edge.java | 3 +- EDG/src/main/java/edg/graph/Grammar.java | 5 - 14 files changed, 4 insertions(+), 169 deletions(-) delete mode 100644 EDG/src/main/java/edg/constraint/StructuralConstraint.java diff --git a/EDG/src/main/java/edg/constraint/AccessConstraint.java b/EDG/src/main/java/edg/constraint/AccessConstraint.java index efbf319..55e9c64 100644 --- a/EDG/src/main/java/edg/constraint/AccessConstraint.java +++ b/EDG/src/main/java/edg/constraint/AccessConstraint.java @@ -89,9 +89,6 @@ public abstract class AccessConstraint extends EdgeConstraint { return super.wrap(super.push(phase, constraints)); } - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, StructuralConstraint topConstraint, int productionDepth) { - return super.wrap(); - } protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, LiteralConstraint topConstraint, int productionDepth){ if (this.operation == Operation.Add) return super.wrap(super.push(phase, constraints)); diff --git a/EDG/src/main/java/edg/constraint/AddNodeConstraint.java b/EDG/src/main/java/edg/constraint/AddNodeConstraint.java index fe68e84..8c5cc30 100644 --- a/EDG/src/main/java/edg/constraint/AddNodeConstraint.java +++ b/EDG/src/main/java/edg/constraint/AddNodeConstraint.java @@ -40,10 +40,7 @@ public class AddNodeConstraint extends EdgeConstraint { constraints.nodeConstraints.add(this.nodeConstraint); return super.wrap(constraints); } - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, StructuralConstraint topConstraint, int productionDepth) { - constraints.nodeConstraints.add(this.nodeConstraint); - return super.wrap(constraints); - } + protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, LiteralConstraint topConstraint, int productionDepth) { constraints.nodeConstraints.add(this.nodeConstraint); return super.wrap(constraints); diff --git a/EDG/src/main/java/edg/constraint/AsteriskConstraint.java b/EDG/src/main/java/edg/constraint/AsteriskConstraint.java index 76919ab..e65566d 100644 --- a/EDG/src/main/java/edg/constraint/AsteriskConstraint.java +++ b/EDG/src/main/java/edg/constraint/AsteriskConstraint.java @@ -56,25 +56,7 @@ public class AsteriskConstraint extends EdgeConstraint final EdgeConstraint peekConstraint = newConstraints.peekEdgeConstraint(); return super.resolve(phase, edg, edge, newConstraints, peekConstraint, productionDepth); } - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, StructuralConstraint topConstraint, int productionDepth) { - if (phase.isInstanceof(Phase.Slicing)) - return super.wrap(new Constraints()); - super.check(phase, Phase.SummaryGeneration); - - if (existsPreviousAsteriskConstraint(constraints)) - return super.wrap(this.popToAsteriskConstraint(constraints)); - - if (topConstraint.getConstraint().operation == AccessConstraint.Operation.Remove) - return super.wrap(super.push(phase, constraints)); - super.check(topConstraint.getConstraint().operation, AccessConstraint.Operation.Add); - final Constraints newConstraints = super.pop(constraints); - if (newConstraints.isEdgeConstraintsEmpty()) - return super.wrap(newConstraints); - - final EdgeConstraint peekConstraint = newConstraints.peekEdgeConstraint(); - return super.resolve(phase, edg, edge, newConstraints, peekConstraint, productionDepth); - } protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, LiteralConstraint topConstraint, int productionDepth) { if (phase.isInstanceof(Phase.Slicing)) return super.wrap(new Constraints()); diff --git a/EDG/src/main/java/edg/constraint/EdgeConstraint.java b/EDG/src/main/java/edg/constraint/EdgeConstraint.java index a515244..d31c79b 100644 --- a/EDG/src/main/java/edg/constraint/EdgeConstraint.java +++ b/EDG/src/main/java/edg/constraint/EdgeConstraint.java @@ -17,8 +17,6 @@ public abstract class EdgeConstraint extends Constraint return this.resolve(phase, edg, edge, constraints, (ListComprehensionConstraint) topConstraint, productionDepth); else if (topConstraint instanceof AccessConstraint) return this.resolve(phase, edg, edge, constraints, (AccessConstraint) topConstraint, productionDepth); - else if (topConstraint instanceof StructuralConstraint) - return this.resolve(phase, edg, edge, constraints, (StructuralConstraint) topConstraint, productionDepth); else if (topConstraint instanceof LiteralConstraint) return this.resolve(phase, edg, edge, constraints, (LiteralConstraint) topConstraint, productionDepth); else if (topConstraint instanceof EmptyConstraint) @@ -37,7 +35,6 @@ public abstract class EdgeConstraint extends Constraint protected abstract List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, int productionDepth); protected abstract List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, AccessConstraint topConstraint, int productionDepth); - protected abstract List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, StructuralConstraint topConstraint, int productionDepth); protected abstract List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, LiteralConstraint topConstraint, int productionDepth); protected final List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, AddNodeConstraint topConstraint, int productionDepth) diff --git a/EDG/src/main/java/edg/constraint/EmptyConstraint.java b/EDG/src/main/java/edg/constraint/EmptyConstraint.java index ddc0683..926b6fc 100644 --- a/EDG/src/main/java/edg/constraint/EmptyConstraint.java +++ b/EDG/src/main/java/edg/constraint/EmptyConstraint.java @@ -36,10 +36,6 @@ public class EmptyConstraint extends EdgeConstraint { return super.wrap(constraints); } - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, StructuralConstraint topConstraint, int productionDepth) - { - return super.wrap(constraints); - } protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, LiteralConstraint topConstraint, int productionDepth){ return super.wrap(constraints); } diff --git a/EDG/src/main/java/edg/constraint/GrammarConstraint.java b/EDG/src/main/java/edg/constraint/GrammarConstraint.java index 6adb497..e848852 100644 --- a/EDG/src/main/java/edg/constraint/GrammarConstraint.java +++ b/EDG/src/main/java/edg/constraint/GrammarConstraint.java @@ -76,13 +76,6 @@ public class GrammarConstraint extends EdgeConstraint { super.check(phase, Phase.SummaryGeneration); return super.wrap(super.push(phase, constraints)); } - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, StructuralConstraint topConstraint, int productionDepth) - { - if (phase.isInstanceof(Phase.Slicing)) - return this.resolveProductions(phase, edg, edge, constraints, productionDepth); - super.check(phase, Phase.SummaryGeneration); - return super.wrap(super.push(phase, constraints)); - } protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, LiteralConstraint topConstraint, int productionDepth){ if (phase.isInstanceof(Phase.Slicing)) return this.resolveProductions(phase, edg, edge, constraints, productionDepth); diff --git a/EDG/src/main/java/edg/constraint/ListComprehensionConstraint.java b/EDG/src/main/java/edg/constraint/ListComprehensionConstraint.java index ffaa91a..347cf38 100644 --- a/EDG/src/main/java/edg/constraint/ListComprehensionConstraint.java +++ b/EDG/src/main/java/edg/constraint/ListComprehensionConstraint.java @@ -69,12 +69,6 @@ public class ListComprehensionConstraint extends AccessConstraint { return super.wrap(super.push(phase, constraints)); } - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, StructuralConstraint topConstraint, int productionDepth) { - if (this.operation == Operation.Add) - return super.wrap(super.push(phase, constraints)); - return super.wrap(); - } - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, ListComprehensionConstraint topConstraint, int productionDepth) { if (topConstraint.operation == Operation.Add && this.cancels(topConstraint)) diff --git a/EDG/src/main/java/edg/constraint/ListConstraint.java b/EDG/src/main/java/edg/constraint/ListConstraint.java index a6f2ada..e28aa60 100644 --- a/EDG/src/main/java/edg/constraint/ListConstraint.java +++ b/EDG/src/main/java/edg/constraint/ListConstraint.java @@ -2,7 +2,7 @@ package edg.constraint; public class ListConstraint extends AccessConstraint { - public enum Position { H, T, S, HS } + 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) diff --git a/EDG/src/main/java/edg/constraint/LiteralConstraint.java b/EDG/src/main/java/edg/constraint/LiteralConstraint.java index a0938f0..a2ab32a 100644 --- a/EDG/src/main/java/edg/constraint/LiteralConstraint.java +++ b/EDG/src/main/java/edg/constraint/LiteralConstraint.java @@ -35,13 +35,8 @@ public class LiteralConstraint extends EdgeConstraint { { return super.wrap(super.push(phase, constraints)); } - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, StructuralConstraint topConstraint, int productionDepth) - { - return super.wrap(); - } protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, LiteralConstraint topConstraint, int productionDepth){ return super.wrap(constraints); - // throw new IllegalStateException("There is no situation where 2 literal constraints are stacked consecutively."); } protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, GrammarConstraint topConstraint, int productionDepth) diff --git a/EDG/src/main/java/edg/constraint/PhaseConstraint.java b/EDG/src/main/java/edg/constraint/PhaseConstraint.java index 3e4cfbb..b589580 100644 --- a/EDG/src/main/java/edg/constraint/PhaseConstraint.java +++ b/EDG/src/main/java/edg/constraint/PhaseConstraint.java @@ -53,12 +53,7 @@ public class PhaseConstraint extends EdgeConstraint { return super.wrap(constraints); return super.wrap(); } - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, StructuralConstraint topConstraint, int productionDepth) - { - if (this.allows(phase)) - return super.wrap(constraints); - return super.wrap(); - } + protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, LiteralConstraint topConstraint, int productionDepth) { if (this.allows(phase)) diff --git a/EDG/src/main/java/edg/constraint/SeekingConstraint.java b/EDG/src/main/java/edg/constraint/SeekingConstraint.java index 1f2beca..dc8cbcd 100644 --- a/EDG/src/main/java/edg/constraint/SeekingConstraint.java +++ b/EDG/src/main/java/edg/constraint/SeekingConstraint.java @@ -97,10 +97,6 @@ public abstract class SeekingConstraint extends EdgeConstraint { return super.wrap(super.push(phase, constraints)); return super.wrap(); } - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, StructuralConstraint topConstraint, int productionDepth) - { - throw new IllegalStateException("Scenario not evaluated"); - } protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, LiteralConstraint topConstraint, int productionDepth){ throw new IllegalStateException("Scenario not evaluated"); } diff --git a/EDG/src/main/java/edg/constraint/StructuralConstraint.java b/EDG/src/main/java/edg/constraint/StructuralConstraint.java deleted file mode 100644 index ae37b71..0000000 --- a/EDG/src/main/java/edg/constraint/StructuralConstraint.java +++ /dev/null @@ -1,101 +0,0 @@ -package edg.constraint; - -import edg.graph.EDG; -import edg.graph.Edge; -import edg.slicing.Phase; -import edg.constraint.AccessConstraint.Operation; - -import java.util.List; - -public class StructuralConstraint extends EdgeConstraint { - private AccessConstraint constraint; - - public StructuralConstraint(Operation operation, String index) { - constraint = new DataConstructorConstraint(operation, index + "S"); - } - - public StructuralConstraint(Operation operation, ListConstraint.Position position) { - constraint = new ListConstraint(operation, ListConstraint.Position.HS); - } - - private StructuralConstraint(AccessConstraint constraint) { - this.constraint = constraint; - } - - public AccessConstraint getConstraint() { - return this.constraint; - } - - public boolean equals(Object object) { - if (object == this) - return true; - if (!(object instanceof StructuralConstraint)) - return false; - - final StructuralConstraint sConstraint = (StructuralConstraint) object; - return this.constraint.equals(sConstraint.getConstraint()); - } - - public String toString() { - return this.constraint.toString(); - } - - public boolean cancels(StructuralConstraint constraint){ - return this.equals(constraint.opposite()); - } - - public StructuralConstraint opposite() { - final AccessConstraint opposite = this.constraint.opposite(); - return new StructuralConstraint(opposite); - } - - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, int productionDepth) { - if (this.constraint.operation == Operation.Add) - return super.wrap(super.push(phase, constraints)); - super.check(this.constraint.operation, Operation.Remove); - if (phase.isInstanceof(Phase.Slicing)) - return super.wrap(); - super.check(phase, Phase.SummaryGeneration); - return super.wrap(super.push(phase, constraints)); - } - - - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, AccessConstraint topConstraint, int productionDepth) { - throw new IllegalStateException("This combination of constraints is illegal"); - } - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, StructuralConstraint topConstraint, int productionDepth) { - if (topConstraint.constraint.operation == Operation.Add) - { - if (this.constraint.operation == Operation.Add) - return super.wrap(super.push(phase, constraints)); - if (!constraints.nodeConstraints.isEmpty()) - throw new IllegalStateException("NodeConstraints cannot be stacked in this implementation"); - Constraint bottomConstraint = constraints.edgeConstraints.firstElement(); - if (!(bottomConstraint instanceof StructuralConstraint)) - throw new IllegalStateException("The bottom constraint must be a Structural Constraint"); - StructuralConstraint headConstraint = (StructuralConstraint) bottomConstraint; - if (this.cancels(headConstraint)) { - constraints.edgeConstraints.remove(0); - return super.wrap(constraints); - } - return super.wrap(); - } - - super.check(topConstraint.constraint.operation, Operation.Remove); - super.check(phase, Phase.SummaryGeneration); - - return super.wrap(super.push(phase, constraints)); - } - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, LiteralConstraint topConstraint, int productionDepth) { - throw new IllegalStateException("This combination of constraints is illegal"); - } - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, SeekingConstraint topConstraint, int productionDepth) { - throw new IllegalStateException("This combination of constraints is illegal"); - } - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, AsteriskConstraint topConstraint, int productionDepth) { - throw new IllegalStateException("This combination of constraints is illegal"); - } - protected List resolve(Phase phase, EDG edg, Edge edge, Constraints constraints, GrammarConstraint topConstraint, int productionDepth) { - throw new IllegalStateException("This combination of constraints is illegal"); - } -} \ No newline at end of file diff --git a/EDG/src/main/java/edg/graph/Edge.java b/EDG/src/main/java/edg/graph/Edge.java index 83e8a1c..de5e6fc 100644 --- a/EDG/src/main/java/edg/graph/Edge.java +++ b/EDG/src/main/java/edg/graph/Edge.java @@ -16,8 +16,7 @@ public class Edge Call, Input, Output, Summary, Exception, TotalDefinition, ObjectFlow, - Class, CallReq, - ValueStructure + Class, CallReq } private boolean mark; diff --git a/EDG/src/main/java/edg/graph/Grammar.java b/EDG/src/main/java/edg/graph/Grammar.java index 3444c06..f1f06f7 100644 --- a/EDG/src/main/java/edg/graph/Grammar.java +++ b/EDG/src/main/java/edg/graph/Grammar.java @@ -1,6 +1,5 @@ package edg.graph; -import edg.constraint.Constraints; import edg.constraint.GrammarConstraint; import java.util.HashMap; @@ -57,10 +56,6 @@ public class Grammar return this.grammarConstraints.get(grammarConstraint.getRefNode()) == null; } - public Map getGrammarConstraints(){ - return grammarConstraints; - } - public boolean removeControlReachingProductions(GrammarConstraint grammarConstraint) { if (!grammarConstraint.isFlowReached()) return false; -- GitLab