@Override
public MustDef apply(MustDef a, MustDef b) {
MustDef result = new MustDef();
Map<Var, Definition> resultMap = result.reachingDef;
// Take the join of all variables that are not TOP in this.
for (Var var : a.reachingDef.keySet()) {
Definition aDef = a.reachingDef.get(var);
if (aDef == null) {
// "a" is BOTTOM implies that the variable has more than one possible
// definition. We set the join of this to be BOTTOM regardless of what
// "b" might be.
resultMap.put(var, null);
continue;
}
Node aNode = aDef.node;
if (b.reachingDef.containsKey(var)) {
Definition bDef = b.reachingDef.get(var);
if (aDef.equals(bDef)) {
resultMap.put(var, aDef);
} else {
resultMap.put(var, null);
}
} else {
resultMap.put(var, aDef);
}
}
// Take the join of all variables that are not TOP in other but it is TOP
// in this.
for (Var var : b.reachingDef.keySet()) {
if (!a.reachingDef.containsKey(var)) {
resultMap.put(var, b.reachingDef.get(var));
}
}
return result;
}
}