Skip to content

Commit 4844c43

Browse files
committed
C++: Cleanup now that we're back to an abstract class.
1 parent 937e0ee commit 4844c43

File tree

4 files changed

+55
-44
lines changed

4 files changed

+55
-44
lines changed

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/DebugPrinting.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/**
2-
* This file contains a module that implements the _debug_ version of
2+
* This file contains the class that implements the _debug_ version of
33
* `toString` for `Instruction` and `Operand` dataflow nodes.
44
*/
55

66
private import semmle.code.cpp.ir.IR
77
private import codeql.util.Unit
8-
private import Node0ToStringSig
8+
private import Node0ToString
99
private import DataFlowUtil
1010

11-
class DebugNode0ToString extends Node0ToString {
11+
private class DebugNode0ToString extends Node0ToString {
1212
override string instructionToString(Instruction i) { result = i.getDumpString() }
1313

1414
override string operandToString(Operand op) {
Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,53 @@
11
/**
2-
* This file imports the module that is used to construct the strings used by `Node.ToString`.
2+
* This file imports the class that is used to construct the strings used by
3+
* `Node.ToString`.
34
*
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.
5+
* Normally, this file should just import `NormalNode0ToString` to compute the
6+
* efficient `toString`, but for debugging purposes one can import
7+
* `DebugPrinting.qll` to better correlate the dataflow nodes with their
8+
* underlying instructions and operands.
69
*/
710

8-
import Node0ToStringSig
9-
import NormalNode0ToString
11+
private import semmle.code.cpp.ir.IR
12+
private import codeql.util.Unit
13+
private import DataFlowUtil
14+
import NormalNode0ToString // Change this import to control which version should be used.
15+
16+
/** An abstract class to control the behavior of `Node.toString`. */
17+
abstract class Node0ToString extends Unit {
18+
/**
19+
* Gets the string that should be used by `OperandNode.toString` to print the
20+
* dataflow node whose underlying operand is `op.`
21+
*/
22+
abstract string operandToString(Operand op);
23+
24+
/**
25+
* Gets the string that should be used by `InstructionNode.toString` to print
26+
* the dataflow node whose underlying instruction is `instr`.
27+
*/
28+
abstract string instructionToString(Instruction i);
29+
30+
/**
31+
* Gets the string representation of the `Expr` associated with `n`, if any.
32+
*/
33+
abstract string toExprString(Node n);
34+
}
35+
36+
/**
37+
* Gets the string that should be used by `OperandNode.toString` to print the
38+
* dataflow node whose underlying operand is `op.`
39+
*/
40+
string operandToString(Operand op) { result = any(Node0ToString s).operandToString(op) }
41+
42+
/**
43+
* Gets the string that should be used by `InstructionNode.toString` to print
44+
* the dataflow node whose underlying instruction is `instr`.
45+
*/
46+
string instructionToString(Instruction instr) {
47+
result = any(Node0ToString s).instructionToString(instr)
48+
}
49+
50+
/**
51+
* Gets the string representation of the `Expr` associated with `n`, if any.
52+
*/
53+
string toExprString(Node n) { result = any(Node0ToString s).toExprString(n) }

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/Node0ToStringSig.qll

Lines changed: 0 additions & 33 deletions
This file was deleted.

cpp/ql/lib/semmle/code/cpp/ir/dataflow/internal/NormalNode0ToString.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/**
2-
* This file contains module that implements the non-debug version of
2+
* This file contains the class that implements the non-debug version of
33
* `toString` for `Instruction` and `Operand` dataflow nodes.
44
*/
55

66
private import semmle.code.cpp.ir.IR
77
private import codeql.util.Unit
8-
private import Node0ToStringSig
8+
private import Node0ToString
99
private import DataFlowUtil
1010
private import DataFlowPrivate
1111

12-
class NormalNode0ToStringImpl extends Node0ToString {
12+
private class NormalNode0ToString extends Node0ToString {
1313
override string instructionToString(Instruction i) {
1414
if i.(InitializeParameterInstruction).getIRVariable() instanceof IRThisVariable
1515
then result = "this"

0 commit comments

Comments
 (0)