3
3
* `toString` for `Instruction` and `Operand` dataflow nodes.
4
4
*/
5
5
6
+ private import cpp
6
7
private import semmle.code.cpp.ir.IR
7
8
private import codeql.util.Unit
8
9
private import Node0ToString
9
10
private import DataFlowUtil
10
11
private import DataFlowPrivate
11
12
13
+ /**
14
+ * Gets the string representation of the unconverted expression `loc` if
15
+ * `loc` is an `Expression`.
16
+ *
17
+ * Otherwise, this gets the string representation of `loc`.
18
+ */
19
+ private string unconvertedAstToString ( Locatable loc ) {
20
+ result = loc .( Expr ) .getUnconverted ( ) .toString ( )
21
+ or
22
+ not loc instanceof Expr and
23
+ result = loc .toString ( )
24
+ }
25
+
12
26
private class NormalNode0ToString extends Node0ToString {
13
27
NormalNode0ToString ( ) {
14
28
// Silence warning about `this` not being bound.
@@ -18,14 +32,10 @@ private class NormalNode0ToString extends Node0ToString {
18
32
override string instructionToString ( Instruction i ) {
19
33
if i .( InitializeParameterInstruction ) .getIRVariable ( ) instanceof IRThisVariable
20
34
then result = "this"
21
- else result = i .getAst ( ) . toString ( )
35
+ else result = unconvertedAstToString ( i .getAst ( ) )
22
36
}
23
37
24
- override string operandToString ( Operand op ) {
25
- if op .getDef ( ) .( InitializeParameterInstruction ) .getIRVariable ( ) instanceof IRThisVariable
26
- then result = "this"
27
- else result = op .getDef ( ) .getAst ( ) .toString ( )
28
- }
38
+ override string operandToString ( Operand op ) { result = this .instructionToString ( op .getDef ( ) ) }
29
39
30
40
override string toExprString ( Node n ) {
31
41
result = n .asExpr ( 0 ) .toString ( )
0 commit comments