|
| 1 | +import cpp |
| 2 | +import TestUtilities.InlineExpectationsTest |
| 3 | +import semmle.code.cpp.dataflow.new.DataFlow::DataFlow |
| 4 | + |
| 5 | +bindingset[s] |
| 6 | +string quote(string s) { if s.matches("% %") then result = "\"" + s + "\"" else result = s } |
| 7 | + |
| 8 | +string formatNumberOfNodesForIndirectExpr(Expr e) { |
| 9 | + exists(int n | n = strictcount(Node node | node.asIndirectExpr() = e) | |
| 10 | + n > 1 and result = ": " + n |
| 11 | + ) |
| 12 | +} |
| 13 | + |
| 14 | +module AsIndirectExprTest implements TestSig { |
| 15 | + string getARelevantTag() { result = ["asIndirectExpr", "numberOfIndirectNodes"] } |
| 16 | + |
| 17 | + predicate hasActualResult(Location location, string element, string tag, string value) { |
| 18 | + exists(Node n, Expr e, string exprString | |
| 19 | + e = n.asIndirectExpr() and |
| 20 | + location = e.getLocation() and |
| 21 | + element = n.toString() and |
| 22 | + exprString = e.toString() |
| 23 | + | |
| 24 | + tag = "asIndirectExpr" and |
| 25 | + ( |
| 26 | + // The toString on an indirect is often formatted like `***myExpr`. |
| 27 | + // If the node's `toString` is of that form then we don't show it in |
| 28 | + // the expected output. |
| 29 | + if element.matches("%" + exprString) |
| 30 | + then value = quote(exprString) |
| 31 | + else value = quote(exprString + "(" + element + ")") |
| 32 | + ) |
| 33 | + or |
| 34 | + tag = "numberOfIndirectNodes" and |
| 35 | + value = quote(exprString + formatNumberOfNodesForIndirectExpr(e)) |
| 36 | + ) |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +import MakeTest<AsIndirectExprTest> |
0 commit comments