|
| 1 | +private import unified |
| 2 | +private import AllDataFlow |
| 3 | + |
| 4 | +predicate step(Node node1, Step step, Node node2) { |
| 5 | + any(DataFlowPlugin p).step(node1, step, node2) |
| 6 | + or |
| 7 | + exists(VariableDeclaration decl | |
| 8 | + node1.isResultValue(decl.getValue()) and |
| 9 | + step.value() and |
| 10 | + node2.isIncomingValue(decl.getPattern()) |
| 11 | + ) |
| 12 | + or |
| 13 | + exists(AssignExpr assign | |
| 14 | + node1.isResultValue(assign.getValue()) and |
| 15 | + step.value() and |
| 16 | + node2.isIncomingValue(assign.getTarget()) |
| 17 | + ) |
| 18 | + or |
| 19 | + exists(LocalVariableAccess access | |
| 20 | + node1.isLocalVariableRead(access, access.getLocalVariable()) and |
| 21 | + step.value() and |
| 22 | + node2.isResultValue(access) |
| 23 | + or |
| 24 | + node1.isIncomingValue(access) and |
| 25 | + step.value() and |
| 26 | + node2.isLocalVariableWrite(access, access.getLocalVariable()) |
| 27 | + or |
| 28 | + node1.isPostUpdate(access) and |
| 29 | + step.value() and |
| 30 | + node2.isLocalVariablePostUpdate(access, access.getLocalVariable()) |
| 31 | + ) |
| 32 | + or |
| 33 | + exists(UnqualifiedMemberAccess access | access.isInstanceAccess() | |
| 34 | + node1.isLocalVariableRead(access, access.getImplicitQualifierVariable()) and |
| 35 | + step.readName(access.getName()) and |
| 36 | + node2.isResultValue(access) |
| 37 | + or |
| 38 | + (node1.isIncomingValue(access) or node1.isPostUpdate(access)) and |
| 39 | + step.storeName(access.getName()) and |
| 40 | + node2.isLocalVariablePostUpdate(access, access.getImplicitQualifierVariable()) |
| 41 | + ) |
| 42 | + or |
| 43 | + exists(StringInterpolationExpr expr | |
| 44 | + node1.isResultValue(expr.getAnElement()) and |
| 45 | + step.taint() and |
| 46 | + node2.isResultValue(expr) |
| 47 | + ) |
| 48 | + or |
| 49 | + exists(TupleExpr expr, int i | |
| 50 | + node1.isResultValue(expr.getElement(i).getValue()) and |
| 51 | + step.storeName(i.toString()) and |
| 52 | + node2.isResultValue(expr) |
| 53 | + or |
| 54 | + node1.isIncomingValue(expr) and |
| 55 | + step.readName(i.toString()) and |
| 56 | + node2.isIncomingValue(expr.getElement(i).getValue()) |
| 57 | + ) |
| 58 | + or |
| 59 | + exists(MemberAccessExpr expr | |
| 60 | + node1.isResultValue(expr.getBase()) and |
| 61 | + step.readName(expr.getMemberName()) and |
| 62 | + node2.isResultValue(expr) |
| 63 | + or |
| 64 | + (node1.isIncomingValue(expr) or node1.isPostUpdate(expr)) and |
| 65 | + step.storeName(expr.getMemberName()) and |
| 66 | + node2.isPostUpdate(expr.getBase()) |
| 67 | + ) |
| 68 | + or |
| 69 | + none() // Temporarily disable compilation errors from unsatisfiable types |
| 70 | +} |
| 71 | + |
| 72 | +/** Holds if `node` should be included in the debug view. */ |
| 73 | +private signature predicate relevantNodeSig(AstNode node); |
| 74 | + |
| 75 | +module DebugGraph<relevantNodeSig/1 relevantNode> { |
| 76 | + private Node adjacent(Node n) { |
| 77 | + step(n, _, result) |
| 78 | + or |
| 79 | + step(result, _, n) |
| 80 | + or |
| 81 | + localSsaStep(n, result, _) |
| 82 | + or |
| 83 | + localSsaStep(result, n, _) |
| 84 | + } |
| 85 | + |
| 86 | + private predicate relevantDataFlowNode(Node node) { |
| 87 | + relevantNode(node.getWrappedAstNode()) |
| 88 | + or |
| 89 | + not exists(node.getWrappedAstNode()) and |
| 90 | + relevantDataFlowNode(adjacent(node)) |
| 91 | + } |
| 92 | + |
| 93 | + query predicate nodes(Node node, string key, string value) { |
| 94 | + relevantDataFlowNode(node) and |
| 95 | + key = "semmle.label" and |
| 96 | + value = node.toString() |
| 97 | + } |
| 98 | + |
| 99 | + query predicate edges(Node node1, Node node2, string key, string value) { |
| 100 | + key = "semmle.label" and |
| 101 | + relevantDataFlowNode(node1) and |
| 102 | + relevantDataFlowNode(node2) and |
| 103 | + ( |
| 104 | + exists(Step step | |
| 105 | + step(node1, step, node2) and |
| 106 | + value = step.toString() |
| 107 | + ) |
| 108 | + or |
| 109 | + exists(boolean isUseStep | |
| 110 | + localSsaStep(node1, node2, isUseStep) and |
| 111 | + if isUseStep = true then value = "use-use" else value = "def-use" |
| 112 | + ) |
| 113 | + or |
| 114 | + node2 = getPostUpdateNode(node1) and |
| 115 | + value = "post-update" |
| 116 | + ) |
| 117 | + } |
| 118 | +} |
0 commit comments