|
| 1 | +private import semmle.code.cpp.ir.IR |
| 2 | +private import cpp |
| 3 | + |
| 4 | +private newtype TNode = TInstructionNode(Instruction i) |
| 5 | + |
| 6 | +abstract private class NodeImpl extends TNode { |
| 7 | + /** Gets the `Instruction` associated with this node, if any. */ |
| 8 | + Instruction asInstruction() { result = this.(InstructionNode).getInstruction() } |
| 9 | + |
| 10 | + /** Gets the `Expr` associated with this node, if any. */ |
| 11 | + Expr asExpr() { result = this.(ExprNode).getExpr() } |
| 12 | + |
| 13 | + /** Gets the `Parameter` associated with this node, if any. */ |
| 14 | + Parameter asParameter() { result = this.(ParameterNode).getParameter() } |
| 15 | + |
| 16 | + /** Gets the location of this node. */ |
| 17 | + Location getLocation() { none() } |
| 18 | + |
| 19 | + /** |
| 20 | + * Holds if this element is at the specified location. |
| 21 | + * The location spans column `startcolumn` of line `startline` to |
| 22 | + * column `endcolumn` of line `endline` in file `filepath`. |
| 23 | + * For more information, see |
| 24 | + * [Locations](https://codeql.github.com/docs/writing-codeql-queries/providing-locations-in-codeql-queries/). |
| 25 | + */ |
| 26 | + final predicate hasLocationInfo( |
| 27 | + string filepath, int startline, int startcolumn, int endline, int endcolumn |
| 28 | + ) { |
| 29 | + this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) |
| 30 | + } |
| 31 | + |
| 32 | + /** Gets a textual representation of this node. */ |
| 33 | + abstract string toString(); |
| 34 | + |
| 35 | + /** Gets the enclosing callable of this node. */ |
| 36 | + abstract Callable getEnclosingFunction(); |
| 37 | +} |
| 38 | + |
| 39 | +final class Node = NodeImpl; |
| 40 | + |
| 41 | +private class InstructionNode extends NodeImpl { |
| 42 | + Instruction instr; |
| 43 | + |
| 44 | + InstructionNode() { this = TInstructionNode(instr) } |
| 45 | + |
| 46 | + /** Gets the `Instruction` associated with this node. */ |
| 47 | + Instruction getInstruction() { result = instr } |
| 48 | + |
| 49 | + final override Location getLocation() { result = instr.getLocation() } |
| 50 | + |
| 51 | + final override string toString() { result = instr.getAst().toString() } |
| 52 | + |
| 53 | + final override Callable getEnclosingFunction() { result = instr.getEnclosingFunction() } |
| 54 | +} |
| 55 | + |
| 56 | +private class ExprNode extends InstructionNode { |
| 57 | + Expr e; |
| 58 | + |
| 59 | + ExprNode() { e = this.getInstruction().getConvertedResultExpression() } |
| 60 | + |
| 61 | + /** Gets the `Expr` associated with this node. */ |
| 62 | + Expr getExpr() { result = e } |
| 63 | +} |
| 64 | + |
| 65 | +private class ParameterNode extends InstructionNode { |
| 66 | + override InitializeParameterInstruction instr; |
| 67 | + Parameter p; |
| 68 | + |
| 69 | + ParameterNode() { p = instr.getParameter() } |
| 70 | + |
| 71 | + /** Gets the `Parameter` associated with this node. */ |
| 72 | + Parameter getParameter() { result = p } |
| 73 | +} |
| 74 | + |
| 75 | +class CallNode extends InstructionNode { |
| 76 | + override CallInstruction instr; |
| 77 | +} |
| 78 | + |
| 79 | +class Callable = Function; |
0 commit comments