|
1 | 1 | /**
|
2 |
| - * This file contains the abstract class that serves as the base class for |
3 |
| - * dataflow node printing. |
| 2 | + * This file imports the module that is used to construct the strings used by `Node.ToString`. |
4 | 3 | *
|
5 |
| - * By default, a non-debug string is produced. However, a debug-friendly |
6 |
| - * string can be produced by importing `DebugPrinting.qll`. |
| 4 | + * Normally, this file should just import `NormalNode0ToString` to compute the efficient `toString`, but for debugging purposes |
| 5 | + * one can import `DebugPrinting.qll` to better correlate the dataflow nodes with their underlying instructions and operands. |
7 | 6 | */
|
8 | 7 |
|
9 |
| -private import semmle.code.cpp.ir.IR |
10 |
| -private import codeql.util.Unit |
11 |
| - |
12 |
| -/** |
13 |
| - * A class to control whether a debugging version of instructions and operands |
14 |
| - * should be printed as part of the `toString` output of dataflow nodes. |
15 |
| - * |
16 |
| - * To enable debug printing import the `DebugPrinting.ql` file. By default, |
17 |
| - * non-debug output will be used. |
18 |
| - */ |
19 |
| -class Node0ToString extends Unit { |
20 |
| - abstract predicate isDebugMode(); |
21 |
| - |
22 |
| - private string normalInstructionToString(Instruction i) { |
23 |
| - not this.isDebugMode() and |
24 |
| - if i.(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable |
25 |
| - then result = "this" |
26 |
| - else result = i.getAst().toString() |
27 |
| - } |
28 |
| - |
29 |
| - private string normalOperandToString(Operand op) { |
30 |
| - not this.isDebugMode() and |
31 |
| - if op.getDef().(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable |
32 |
| - then result = "this" |
33 |
| - else result = op.getDef().getAst().toString() |
34 |
| - } |
35 |
| - |
36 |
| - /** |
37 |
| - * Gets the string that should be used by `InstructionNode.toString` |
38 |
| - */ |
39 |
| - string instructionToString(Instruction i) { |
40 |
| - if this.isDebugMode() |
41 |
| - then result = i.getDumpString() |
42 |
| - else result = this.normalInstructionToString(i) |
43 |
| - } |
44 |
| - |
45 |
| - /** |
46 |
| - * Gets the string that should be used by `OperandNode.toString`. |
47 |
| - */ |
48 |
| - string operandToString(Operand op) { |
49 |
| - if this.isDebugMode() |
50 |
| - then result = op.getDumpString() + " @ " + op.getUse().getResultId() |
51 |
| - else result = this.normalOperandToString(op) |
52 |
| - } |
53 |
| -} |
54 |
| - |
55 |
| -private class NoDebugNode0ToString extends Node0ToString { |
56 |
| - final override predicate isDebugMode() { none() } |
57 |
| -} |
58 |
| - |
59 |
| -/** |
60 |
| - * Gets the string that should be used by `OperandNode.toString`. |
61 |
| - */ |
62 |
| -string operandToString(Operand op) { result = any(Node0ToString nts).operandToString(op) } |
63 |
| - |
64 |
| -/** |
65 |
| - * Gets the string that should be used by `InstructionNode.toString` |
66 |
| - */ |
67 |
| -string instructionToString(Instruction i) { result = any(Node0ToString nts).instructionToString(i) } |
68 |
| - |
69 |
| -/** |
70 |
| - * Holds if debugging mode is enabled. |
71 |
| - * |
72 |
| - * In debug mode the `toString` on dataflow nodes is more expensive to compute, |
73 |
| - * but gives more precise information about the different dataflow nodes. |
74 |
| - */ |
75 |
| -predicate isDebugMode() { any(Node0ToString nts).isDebugMode() } |
| 8 | +import NormalNode0ToString |
0 commit comments