Skip to content

Commit 440ea6a

Browse files
author
Dave Bartolomeo
committed
C++: QLDoc for PrintIR.qll
1 parent 2043d9c commit 440ea6a

File tree

5 files changed

+120
-20
lines changed

5 files changed

+120
-20
lines changed

cpp/ql/src/semmle/code/cpp/ir/implementation/aliased_ssa/PrintIR.qll

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* Outputs a representation of the IR as a control flow graph.
3+
*
4+
* This file contains the actual implementation of `PrintAST.ql`. For test cases and very small
5+
* databases, `PrintAST.ql` can be run directly to dump the IR for the entire database. For most
6+
* uses, however, it is better to write a query that imports `PrintAST.qll`, extends
7+
* `PrintIRConfiguration`, and overrides `shouldPrintFunction()` to select a subset of functions to
8+
* dump.
9+
*/
10+
111
private import internal.IRInternal
212
private import IR
313
private import internal.PrintIRImports as Imports
@@ -47,7 +57,7 @@ private newtype TPrintableIRNode =
4757
/**
4858
* A node to be emitted in the IR graph.
4959
*/
50-
abstract class PrintableIRNode extends TPrintableIRNode {
60+
abstract private class PrintableIRNode extends TPrintableIRNode {
5161
abstract string toString();
5262

5363
/**
@@ -98,7 +108,7 @@ abstract class PrintableIRNode extends TPrintableIRNode {
98108
/**
99109
* An IR graph node representing a `IRFunction` object.
100110
*/
101-
class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction {
111+
private class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction {
102112
IRFunction irFunc;
103113

104114
PrintableIRFunction() { this = TPrintableIRFunction(irFunc) }
@@ -129,7 +139,7 @@ class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction {
129139
/**
130140
* An IR graph node representing an `IRBlock` object.
131141
*/
132-
class PrintableIRBlock extends PrintableIRNode, TPrintableIRBlock {
142+
private class PrintableIRBlock extends PrintableIRNode, TPrintableIRBlock {
133143
IRBlock block;
134144

135145
PrintableIRBlock() { this = TPrintableIRBlock(block) }
@@ -161,7 +171,7 @@ class PrintableIRBlock extends PrintableIRNode, TPrintableIRBlock {
161171
/**
162172
* An IR graph node representing an `Instruction`.
163173
*/
164-
class PrintableInstruction extends PrintableIRNode, TPrintableInstruction {
174+
private class PrintableInstruction extends PrintableIRNode, TPrintableInstruction {
165175
Instruction instr;
166176

167177
PrintableInstruction() { this = TPrintableInstruction(instr) }
@@ -224,6 +234,9 @@ private string getPaddingString(int n) {
224234
n > 0 and n <= maxColumnWidth() and result = getPaddingString(n - 1) + " "
225235
}
226236

237+
/**
238+
* Holds if `node` belongs to the output graph, and its property `key` has the given `value`.
239+
*/
227240
query predicate nodes(PrintableIRNode node, string key, string value) {
228241
value = node.getProperty(key)
229242
}
@@ -237,6 +250,10 @@ private int getSuccessorIndex(IRBlock pred, IRBlock succ) {
237250
)
238251
}
239252

253+
/**
254+
* Holds if the output graph contains an edge from `pred` to `succ`, and that edge's property `key`
255+
* has the given `value`.
256+
*/
240257
query predicate edges(PrintableIRBlock pred, PrintableIRBlock succ, string key, string value) {
241258
exists(EdgeKind kind, IRBlock predBlock, IRBlock succBlock |
242259
predBlock = pred.getBlock() and
@@ -256,6 +273,9 @@ query predicate edges(PrintableIRBlock pred, PrintableIRBlock succ, string key,
256273
)
257274
}
258275

276+
/**
277+
* Holds if `parent` is the parent node of `child` in the output graph.
278+
*/
259279
query predicate parents(PrintableIRNode child, PrintableIRNode parent) {
260280
parent = child.getParent()
261281
}

cpp/ql/src/semmle/code/cpp/ir/implementation/raw/PrintIR.qll

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* Outputs a representation of the IR as a control flow graph.
3+
*
4+
* This file contains the actual implementation of `PrintAST.ql`. For test cases and very small
5+
* databases, `PrintAST.ql` can be run directly to dump the IR for the entire database. For most
6+
* uses, however, it is better to write a query that imports `PrintAST.qll`, extends
7+
* `PrintIRConfiguration`, and overrides `shouldPrintFunction()` to select a subset of functions to
8+
* dump.
9+
*/
10+
111
private import internal.IRInternal
212
private import IR
313
private import internal.PrintIRImports as Imports
@@ -47,7 +57,7 @@ private newtype TPrintableIRNode =
4757
/**
4858
* A node to be emitted in the IR graph.
4959
*/
50-
abstract class PrintableIRNode extends TPrintableIRNode {
60+
abstract private class PrintableIRNode extends TPrintableIRNode {
5161
abstract string toString();
5262

5363
/**
@@ -98,7 +108,7 @@ abstract class PrintableIRNode extends TPrintableIRNode {
98108
/**
99109
* An IR graph node representing a `IRFunction` object.
100110
*/
101-
class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction {
111+
private class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction {
102112
IRFunction irFunc;
103113

104114
PrintableIRFunction() { this = TPrintableIRFunction(irFunc) }
@@ -129,7 +139,7 @@ class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction {
129139
/**
130140
* An IR graph node representing an `IRBlock` object.
131141
*/
132-
class PrintableIRBlock extends PrintableIRNode, TPrintableIRBlock {
142+
private class PrintableIRBlock extends PrintableIRNode, TPrintableIRBlock {
133143
IRBlock block;
134144

135145
PrintableIRBlock() { this = TPrintableIRBlock(block) }
@@ -161,7 +171,7 @@ class PrintableIRBlock extends PrintableIRNode, TPrintableIRBlock {
161171
/**
162172
* An IR graph node representing an `Instruction`.
163173
*/
164-
class PrintableInstruction extends PrintableIRNode, TPrintableInstruction {
174+
private class PrintableInstruction extends PrintableIRNode, TPrintableInstruction {
165175
Instruction instr;
166176

167177
PrintableInstruction() { this = TPrintableInstruction(instr) }
@@ -224,6 +234,9 @@ private string getPaddingString(int n) {
224234
n > 0 and n <= maxColumnWidth() and result = getPaddingString(n - 1) + " "
225235
}
226236

237+
/**
238+
* Holds if `node` belongs to the output graph, and its property `key` has the given `value`.
239+
*/
227240
query predicate nodes(PrintableIRNode node, string key, string value) {
228241
value = node.getProperty(key)
229242
}
@@ -237,6 +250,10 @@ private int getSuccessorIndex(IRBlock pred, IRBlock succ) {
237250
)
238251
}
239252

253+
/**
254+
* Holds if the output graph contains an edge from `pred` to `succ`, and that edge's property `key`
255+
* has the given `value`.
256+
*/
240257
query predicate edges(PrintableIRBlock pred, PrintableIRBlock succ, string key, string value) {
241258
exists(EdgeKind kind, IRBlock predBlock, IRBlock succBlock |
242259
predBlock = pred.getBlock() and
@@ -256,6 +273,9 @@ query predicate edges(PrintableIRBlock pred, PrintableIRBlock succ, string key,
256273
)
257274
}
258275

276+
/**
277+
* Holds if `parent` is the parent node of `child` in the output graph.
278+
*/
259279
query predicate parents(PrintableIRNode child, PrintableIRNode parent) {
260280
parent = child.getParent()
261281
}

cpp/ql/src/semmle/code/cpp/ir/implementation/unaliased_ssa/PrintIR.qll

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* Outputs a representation of the IR as a control flow graph.
3+
*
4+
* This file contains the actual implementation of `PrintAST.ql`. For test cases and very small
5+
* databases, `PrintAST.ql` can be run directly to dump the IR for the entire database. For most
6+
* uses, however, it is better to write a query that imports `PrintAST.qll`, extends
7+
* `PrintIRConfiguration`, and overrides `shouldPrintFunction()` to select a subset of functions to
8+
* dump.
9+
*/
10+
111
private import internal.IRInternal
212
private import IR
313
private import internal.PrintIRImports as Imports
@@ -47,7 +57,7 @@ private newtype TPrintableIRNode =
4757
/**
4858
* A node to be emitted in the IR graph.
4959
*/
50-
abstract class PrintableIRNode extends TPrintableIRNode {
60+
abstract private class PrintableIRNode extends TPrintableIRNode {
5161
abstract string toString();
5262

5363
/**
@@ -98,7 +108,7 @@ abstract class PrintableIRNode extends TPrintableIRNode {
98108
/**
99109
* An IR graph node representing a `IRFunction` object.
100110
*/
101-
class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction {
111+
private class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction {
102112
IRFunction irFunc;
103113

104114
PrintableIRFunction() { this = TPrintableIRFunction(irFunc) }
@@ -129,7 +139,7 @@ class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction {
129139
/**
130140
* An IR graph node representing an `IRBlock` object.
131141
*/
132-
class PrintableIRBlock extends PrintableIRNode, TPrintableIRBlock {
142+
private class PrintableIRBlock extends PrintableIRNode, TPrintableIRBlock {
133143
IRBlock block;
134144

135145
PrintableIRBlock() { this = TPrintableIRBlock(block) }
@@ -161,7 +171,7 @@ class PrintableIRBlock extends PrintableIRNode, TPrintableIRBlock {
161171
/**
162172
* An IR graph node representing an `Instruction`.
163173
*/
164-
class PrintableInstruction extends PrintableIRNode, TPrintableInstruction {
174+
private class PrintableInstruction extends PrintableIRNode, TPrintableInstruction {
165175
Instruction instr;
166176

167177
PrintableInstruction() { this = TPrintableInstruction(instr) }
@@ -224,6 +234,9 @@ private string getPaddingString(int n) {
224234
n > 0 and n <= maxColumnWidth() and result = getPaddingString(n - 1) + " "
225235
}
226236

237+
/**
238+
* Holds if `node` belongs to the output graph, and its property `key` has the given `value`.
239+
*/
227240
query predicate nodes(PrintableIRNode node, string key, string value) {
228241
value = node.getProperty(key)
229242
}
@@ -237,6 +250,10 @@ private int getSuccessorIndex(IRBlock pred, IRBlock succ) {
237250
)
238251
}
239252

253+
/**
254+
* Holds if the output graph contains an edge from `pred` to `succ`, and that edge's property `key`
255+
* has the given `value`.
256+
*/
240257
query predicate edges(PrintableIRBlock pred, PrintableIRBlock succ, string key, string value) {
241258
exists(EdgeKind kind, IRBlock predBlock, IRBlock succBlock |
242259
predBlock = pred.getBlock() and
@@ -256,6 +273,9 @@ query predicate edges(PrintableIRBlock pred, PrintableIRBlock succ, string key,
256273
)
257274
}
258275

276+
/**
277+
* Holds if `parent` is the parent node of `child` in the output graph.
278+
*/
259279
query predicate parents(PrintableIRNode child, PrintableIRNode parent) {
260280
parent = child.getParent()
261281
}

csharp/ql/src/experimental/ir/implementation/raw/PrintIR.qll

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
/**
2+
* Outputs a representation of the IR as a control flow graph.
3+
*
4+
* This file contains the actual implementation of `PrintAST.ql`. For test cases and very small
5+
* databases, `PrintAST.ql` can be run directly to dump the IR for the entire database. For most
6+
* uses, however, it is better to write a query that imports `PrintAST.qll`, extends
7+
* `PrintIRConfiguration`, and overrides `shouldPrintFunction()` to select a subset of functions to
8+
* dump.
9+
*/
10+
111
private import internal.IRInternal
212
private import IR
313
private import internal.PrintIRImports as Imports
@@ -47,7 +57,7 @@ private newtype TPrintableIRNode =
4757
/**
4858
* A node to be emitted in the IR graph.
4959
*/
50-
abstract class PrintableIRNode extends TPrintableIRNode {
60+
abstract private class PrintableIRNode extends TPrintableIRNode {
5161
abstract string toString();
5262

5363
/**
@@ -98,7 +108,7 @@ abstract class PrintableIRNode extends TPrintableIRNode {
98108
/**
99109
* An IR graph node representing a `IRFunction` object.
100110
*/
101-
class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction {
111+
private class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction {
102112
IRFunction irFunc;
103113

104114
PrintableIRFunction() { this = TPrintableIRFunction(irFunc) }
@@ -129,7 +139,7 @@ class PrintableIRFunction extends PrintableIRNode, TPrintableIRFunction {
129139
/**
130140
* An IR graph node representing an `IRBlock` object.
131141
*/
132-
class PrintableIRBlock extends PrintableIRNode, TPrintableIRBlock {
142+
private class PrintableIRBlock extends PrintableIRNode, TPrintableIRBlock {
133143
IRBlock block;
134144

135145
PrintableIRBlock() { this = TPrintableIRBlock(block) }
@@ -161,7 +171,7 @@ class PrintableIRBlock extends PrintableIRNode, TPrintableIRBlock {
161171
/**
162172
* An IR graph node representing an `Instruction`.
163173
*/
164-
class PrintableInstruction extends PrintableIRNode, TPrintableInstruction {
174+
private class PrintableInstruction extends PrintableIRNode, TPrintableInstruction {
165175
Instruction instr;
166176

167177
PrintableInstruction() { this = TPrintableInstruction(instr) }
@@ -224,6 +234,9 @@ private string getPaddingString(int n) {
224234
n > 0 and n <= maxColumnWidth() and result = getPaddingString(n - 1) + " "
225235
}
226236

237+
/**
238+
* Holds if `node` belongs to the output graph, and its property `key` has the given `value`.
239+
*/
227240
query predicate nodes(PrintableIRNode node, string key, string value) {
228241
value = node.getProperty(key)
229242
}
@@ -237,6 +250,10 @@ private int getSuccessorIndex(IRBlock pred, IRBlock succ) {
237250
)
238251
}
239252

253+
/**
254+
* Holds if the output graph contains an edge from `pred` to `succ`, and that edge's property `key`
255+
* has the given `value`.
256+
*/
240257
query predicate edges(PrintableIRBlock pred, PrintableIRBlock succ, string key, string value) {
241258
exists(EdgeKind kind, IRBlock predBlock, IRBlock succBlock |
242259
predBlock = pred.getBlock() and
@@ -256,6 +273,9 @@ query predicate edges(PrintableIRBlock pred, PrintableIRBlock succ, string key,
256273
)
257274
}
258275

276+
/**
277+
* Holds if `parent` is the parent node of `child` in the output graph.
278+
*/
259279
query predicate parents(PrintableIRNode child, PrintableIRNode parent) {
260280
parent = child.getParent()
261281
}

0 commit comments

Comments
 (0)