Skip to content

Commit 5016459

Browse files
committed
C++: Move private stuff from 'DataFlowUtil' to public stuff 'DataFlowPrivate'. Also make 'PostUpdateNodeImpl' public in 'DataFlowUtil'. Sadly, this means that it's visible at the query level (as DataFlow::PostUpdateNodeImpl), but I've added a big INTERNAL QLDoc on it to make sure people don't use it.
1 parent f50817e commit 5016459

File tree

2 files changed

+39
-42
lines changed

2 files changed

+39
-42
lines changed

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,41 @@ private module Cached {
5959
import Cached
6060
private import Nodes0
6161

62+
/**
63+
* A module for calculating the number of stars (i.e., `*`s) needed for various
64+
* dataflow node `toString` predicates.
65+
*/
66+
module NodeStars {
67+
private int getNumberOfIndirections(Node n) {
68+
result = n.(RawIndirectOperand).getIndirectionIndex()
69+
or
70+
result = n.(RawIndirectInstruction).getIndirectionIndex()
71+
or
72+
result = n.(VariableNode).getIndirectionIndex()
73+
or
74+
result = n.(PostUpdateNodeImpl).getIndirectionIndex()
75+
or
76+
result = n.(FinalParameterNode).getIndirectionIndex()
77+
}
78+
79+
private int maxNumberOfIndirections() { result = max(getNumberOfIndirections(_)) }
80+
81+
private string repeatStars(int n) {
82+
n = 0 and result = ""
83+
or
84+
n = [1 .. maxNumberOfIndirections()] and
85+
result = "*" + repeatStars(n - 1)
86+
}
87+
88+
/**
89+
* Gets the number of stars (i.e., `*`s) needed to produce the `toString`
90+
* output for `n`.
91+
*/
92+
string stars(Node n) { result = repeatStars(getNumberOfIndirections(n)) }
93+
}
94+
95+
import NodeStars
96+
6297
class Node0Impl extends TIRDataFlowNode0 {
6398
/**
6499
* INTERNAL: Do not use.

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

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -486,47 +486,6 @@ class Node extends TIRDataFlowNode {
486486
}
487487
}
488488

489-
private string toExprString(Node n) {
490-
not isDebugMode() and
491-
(
492-
result = n.asExpr(0).toString()
493-
or
494-
not exists(n.asExpr()) and
495-
result = stars(n) + n.asIndirectExpr(0, 1).toString()
496-
)
497-
}
498-
499-
private module NodeStars {
500-
private int getNumberOfIndirections(Node n) {
501-
result = n.(RawIndirectOperand).getIndirectionIndex()
502-
or
503-
result = n.(RawIndirectInstruction).getIndirectionIndex()
504-
or
505-
result = n.(VariableNode).getIndirectionIndex()
506-
or
507-
result = n.(PostUpdateNodeImpl).getIndirectionIndex()
508-
or
509-
result = n.(FinalParameterNode).getIndirectionIndex()
510-
}
511-
512-
private int maxNumberOfIndirections() { result = max(getNumberOfIndirections(_)) }
513-
514-
private string repeatStars(int n) {
515-
n = 0 and result = ""
516-
or
517-
n = [1 .. maxNumberOfIndirections()] and
518-
result = "*" + repeatStars(n - 1)
519-
}
520-
521-
/**
522-
* Gets the number of stars (i.e., `*`s) needed to produce the `toString`
523-
* output for `n`.
524-
*/
525-
string stars(Node n) { result = repeatStars(getNumberOfIndirections(n)) }
526-
}
527-
528-
private import NodeStars
529-
530489
/**
531490
* A class that lifts pre-SSA dataflow nodes to regular dataflow nodes.
532491
*/
@@ -589,7 +548,10 @@ Type stripPointer(Type t) {
589548
result = t.(FunctionPointerIshType).getBaseType()
590549
}
591550

592-
private class PostUpdateNodeImpl extends PartialDefinitionNode, TPostUpdateNodeImpl {
551+
/**
552+
* INTERNAL: Do not use.
553+
*/
554+
class PostUpdateNodeImpl extends PartialDefinitionNode, TPostUpdateNodeImpl {
593555
int indirectionIndex;
594556
Operand operand;
595557

0 commit comments

Comments
 (0)