Skip to content

Commit 81e10dc

Browse files
xerenhernanponcedeleon
authored andcommitted
Relation.checkIsRelation(Relation)
1 parent ffc1278 commit 81e10dc

33 files changed

+55
-128
lines changed

dartagnan/src/main/java/com/dat3m/dartagnan/solver/caat4wmm/ExecutionGraph.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ private Constraint getOrCreateConstraintFromAxiom(Axiom axiom) {
206206
}
207207

208208
private RelationGraph getOrCreateGraphFromRelation(Relation rel) {
209-
rel.checkRelation();
209+
Relation.checkIsRelation(rel);
210210
if (predicateToRelationMap.containsKey(rel)) {
211211
return (RelationGraph) predicateToRelationMap.get(rel);
212212
}
@@ -216,7 +216,7 @@ private RelationGraph getOrCreateGraphFromRelation(Relation rel) {
216216
}
217217

218218
private RelationGraph createGraphFromRelation(Relation rel) {
219-
rel.checkRelation();
219+
Relation.checkIsRelation(rel);
220220
final RelationGraph graph;
221221
final Class<?> relClass = rel.getDefinition().getClass();
222222
final List<Relation> dependencies = rel.getDependencies();
@@ -269,7 +269,7 @@ private RelationGraph createGraphFromRelation(Relation rel) {
269269
}
270270

271271
private SetPredicate getOrCreateSetFromRelation(Relation relation) {
272-
relation.checkSet();
272+
Relation.checkIsSet(relation);
273273
final CAATPredicate existing = predicateToRelationMap.get(relation);
274274
if (existing != null) {
275275
return (SetPredicate) existing;

dartagnan/src/main/java/com/dat3m/dartagnan/solver/caat4wmm/basePredicates/DynamicDefaultWMMGraph.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ public class DynamicDefaultWMMGraph extends MaterializedWMMGraph {
1212
private final Relation relation;
1313

1414
public DynamicDefaultWMMGraph(Relation rel) {
15-
rel.checkRelation();
16-
this.relation = rel;
15+
this.relation = Relation.checkIsRelation(rel);
1716
}
1817

1918
@Override

dartagnan/src/main/java/com/dat3m/dartagnan/solver/caat4wmm/basePredicates/DynamicDefaultWMMSet.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ public class DynamicDefaultWMMSet extends MaterializedWMMSet {
1212

1313
private final Relation relation;
1414

15-
public DynamicDefaultWMMSet(Relation rel) {
16-
rel.checkSet();
17-
this.relation = rel;
15+
public DynamicDefaultWMMSet(Relation predicate) {
16+
this.relation = Relation.checkIsSet(predicate);
1817
}
1918

2019
@Override

dartagnan/src/main/java/com/dat3m/dartagnan/verification/model/ExecutionModelManager.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ private CAATPredicate createPredicate(Relation r) {
246246
}
247247

248248
private SetPredicate createSet(Relation r) {
249-
r.checkSet();
249+
Relation.checkIsSet(r);
250250
SetPredicate set = r.getDependencies().isEmpty() ? new SimpleSet() : r.getDefinition().accept(setBuilder);
251251
set.setName(r.getNameOrTerm());
252252
if (!r.isRecursive()) {
@@ -256,7 +256,7 @@ private SetPredicate createSet(Relation r) {
256256
}
257257

258258
private RelationGraph createGraph(Relation r) {
259-
r.checkRelation();
259+
Relation.checkIsRelation(r);
260260
RelationGraph rg = r.getDependencies().isEmpty() ? new SimpleGraph() : r.getDefinition().accept(graphBuilder);
261261
rg.setName(r.getNameOrTerm());
262262
if (!r.isRecursive()) {
@@ -266,13 +266,11 @@ private RelationGraph createGraph(Relation r) {
266266
}
267267

268268
private SetPredicate getOrCreateSet(Relation r) {
269-
r.checkSet();
270-
return (SetPredicate) getOrCreatePredicate(r);
269+
return (SetPredicate) getOrCreatePredicate(Relation.checkIsSet(r));
271270
}
272271

273272
private RelationGraph getOrCreateGraph(Relation r) {
274-
r.checkRelation();
275-
return (RelationGraph) getOrCreatePredicate(r);
273+
return (RelationGraph) getOrCreatePredicate(Relation.checkIsRelation(r));
276274
}
277275

278276
private CAATPredicate getOrCreatePredicate(Relation r) {

dartagnan/src/main/java/com/dat3m/dartagnan/wmm/Relation.java

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,46 +32,28 @@ public enum Arity { UNARY, BINARY }
3232
this.arity = arity;
3333
}
3434

35-
/**
36-
* @return {@link Arity#UNARY UNARY} if this instance describes an event set in executions.
37-
* {@link Arity#BINARY BINARY} if this instance describes an event relation in executions.
38-
*/
3935
public Arity getArity() {
4036
return arity;
4137
}
4238

43-
/**
44-
* @return {@code true} if this instance describes an event set in executions. Otherwise {@code false}.
45-
*/
4639
public boolean isSet() {
4740
return arity == Arity.UNARY;
4841
}
4942

50-
/**
51-
* @return {@code true} if this instance describes an event relation in executions. Otherwise {@code false}.
52-
*/
5343
public boolean isRelation() {
5444
return arity == Arity.BINARY;
5545
}
5646

57-
/**
58-
* @throws IllegalArgumentException This instance does not describe an event set in executions.
59-
*/
60-
public void checkSet() {
61-
Preconditions.checkArgument(isSet(), "Non-unary relation %s.", this);
47+
public static Relation checkIsSet(Relation relation) {
48+
Preconditions.checkArgument(relation.isSet(), "Non-unary relation %s.", relation);
49+
return relation;
6250
}
6351

64-
/**
65-
* @throws IllegalArgumentException This instance does not describe an event relation in executions.
66-
*/
67-
public void checkRelation() {
68-
Preconditions.checkArgument(isRelation(), "Non-binary relation %s.", this);
52+
public static Relation checkIsRelation(Relation relation) {
53+
Preconditions.checkArgument(relation.isRelation(), "Non-binary relation %s.", relation);
54+
return relation;
6955
}
7056

71-
/**
72-
* @param others Instances of this class.
73-
* @throws IllegalArgumentException At least one instance in {@code others} has a different arity than this.
74-
*/
7557
public void checkEqualArityRelation(Collection<Relation> others) {
7658
Preconditions.checkArgument(!isSet() || others.stream().allMatch(Relation::isSet),
7759
"Non-unary relation in %s", others);

dartagnan/src/main/java/com/dat3m/dartagnan/wmm/axiom/Acyclicity.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,11 @@ public class Acyclicity extends Axiom {
2626
private static final Logger logger = LogManager.getLogger(Acyclicity.class);
2727

2828
public Acyclicity(Relation rel, boolean negated, boolean flag) {
29-
super(rel, negated, flag);
30-
rel.checkRelation();
29+
super(Relation.checkIsRelation(rel), negated, flag);
3130
}
3231

3332
public Acyclicity(Relation rel) {
34-
super(rel, false, false);
35-
rel.checkRelation();
33+
this(rel, false, false);
3634
}
3735

3836
// Under-approximates the must-set of (rel+ ; rel).

dartagnan/src/main/java/com/dat3m/dartagnan/wmm/axiom/Irreflexivity.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515
public class Irreflexivity extends Axiom {
1616

1717
public Irreflexivity(Relation rel, boolean negated, boolean flag) {
18-
super(rel, negated, flag);
19-
rel.checkRelation();
18+
super(Relation.checkIsRelation(rel), negated, flag);
2019
}
2120

2221
public Irreflexivity(Relation rel) {
23-
super(rel, false, false);
24-
rel.checkRelation();
22+
this(rel, false, false);
2523
}
2624

2725
@Override

dartagnan/src/main/java/com/dat3m/dartagnan/wmm/definition/AMOPairs.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
public class AMOPairs extends Definition {
88

99
public AMOPairs(Relation r0) {
10-
super(r0, RelationNameRepository.AMO);
11-
r0.checkRelation();
10+
super(Relation.checkIsRelation(r0), RelationNameRepository.AMO);
1211
}
1312

1413
@Override

dartagnan/src/main/java/com/dat3m/dartagnan/wmm/definition/CASDependency.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
public class CASDependency extends Definition {
99

1010
public CASDependency(Relation r0) {
11-
super(r0, CASDEP);
12-
r0.checkRelation();
11+
super(Relation.checkIsRelation(r0), CASDEP);
1312
}
1413

1514
@Override

dartagnan/src/main/java/com/dat3m/dartagnan/wmm/definition/CartesianProduct.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,9 @@ public class CartesianProduct extends Definition {
1111
private final Relation range;
1212

1313
public CartesianProduct(Relation r0, Relation r1, Relation r2) {
14-
super(r0, "%s*%s");
15-
domain = r1;
16-
range = r2;
17-
r0.checkRelation();
18-
r1.checkSet();
19-
r2.checkSet();
14+
super(Relation.checkIsRelation(r0), "%s*%s");
15+
domain = Relation.checkIsSet(r1);
16+
range = Relation.checkIsSet(r2);
2017
}
2118

2219
public Relation getDomain() { return domain; }

0 commit comments

Comments
 (0)