Represents the analysis result of DefUseAnalysis, i.e., both def-use chain and use-def chain.
| 37 | * both def-use chain and use-def chain. |
| 38 | */ |
| 39 | public class DefUse implements StmtResult<MultiMap<Var, Stmt>> { |
| 40 | |
| 41 | private static final String NULL_DEFS = "defs is null (not computed)" + |
| 42 | " as it is disabled in def-use analysis"; |
| 43 | |
| 44 | private static final String NULL_USES = "uses is null (not computed)" + |
| 45 | " as it is disabled in def-use analysis"; |
| 46 | |
| 47 | @Nullable |
| 48 | private final TwoKeyMultiMap<Stmt, Var, Stmt> defs; |
| 49 | |
| 50 | @Nullable |
| 51 | private final MultiMap<Stmt, Stmt> uses; |
| 52 | |
| 53 | DefUse(@Nullable TwoKeyMultiMap<Stmt, Var, Stmt> defs, |
| 54 | @Nullable MultiMap<Stmt, Stmt> uses) { |
| 55 | this.defs = defs; |
| 56 | this.uses = uses; |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @return definitions of {@code var} at {@code stmt}. |
| 61 | * If {@code var} is not used in {@code stmt} or it does not |
| 62 | * have any definitions, an empty set is returned. |
| 63 | */ |
| 64 | public Set<Stmt> getDefs(Stmt stmt, Var var) { |
| 65 | Objects.requireNonNull(defs, NULL_DEFS); |
| 66 | return defs.get(stmt, var); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * @return uses of the variable defined by {@code stmt}. |
| 71 | * If {@code stmt} does not define any variable or the defined variable |
| 72 | * does not have any uses, an empty Set is returned. |
| 73 | */ |
| 74 | public Set<Stmt> getUses(Stmt stmt) { |
| 75 | Objects.requireNonNull(uses, NULL_USES); |
| 76 | return uses.get(stmt); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public boolean isRelevant(Stmt stmt) { |
| 81 | return true; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * {@link StmtResult} for def-use analysis. Note that this result only |
| 86 | * contains use-def chain, and it is mainly for testing purpose. |
| 87 | */ |
| 88 | @Override |
| 89 | public MultiMap<Var, Stmt> getResult(Stmt stmt) { |
| 90 | Objects.requireNonNull(defs, NULL_DEFS); |
| 91 | return defs.get(stmt); |
| 92 | } |
| 93 | } |
nothing calls this directly
no outgoing calls
no test coverage detected