Skip to content

Commit 362fbd1

Browse files
committed
C++: QLDoc for PrintAST.qll
1 parent 39aaccc commit 362fbd1

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

cpp/ql/src/semmle/code/cpp/PrintAST.qll

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
/**
2+
* Provides queries to pretty-print a C++ AST as a graph.
3+
*
4+
* By default, this will print the AST for all functions in the database. To change this behavior,
5+
* extend `PrintASTConfiguration` and override `shouldPrintFunction` to hold for only the functions
6+
* you wish to view the AST for.
7+
*/
8+
19
import cpp
210
private import semmle.code.cpp.Print
311

@@ -7,6 +15,9 @@ private newtype TPrintASTConfiguration = MkPrintASTConfiguration()
715
* The query can extend this class to control which functions are printed.
816
*/
917
class PrintASTConfiguration extends TPrintASTConfiguration {
18+
/**
19+
* Gets a textual representation of this `PrintASTConfiguration`.
20+
*/
1021
string toString() { result = "PrintASTConfiguration" }
1122

1223
/**
@@ -96,6 +107,9 @@ private newtype TPrintASTNode =
96107
* A node in the output tree.
97108
*/
98109
class PrintASTNode extends TPrintASTNode {
110+
/**
111+
* Gets a textual representation of this node in the PrintAST output tree.
112+
*/
99113
abstract string toString();
100114

101115
/**
@@ -208,6 +222,9 @@ class ExprNode extends ASTNode {
208222
result = expr.getValueCategoryString()
209223
}
210224

225+
/**
226+
* Gets the value of this expression, if it is a constant.
227+
*/
211228
string getValue() { result = expr.getValue() }
212229
}
213230

@@ -373,6 +390,9 @@ class ParametersNode extends PrintASTNode, TParametersNode {
373390

374391
override ASTNode getChild(int childIndex) { result.getAST() = func.getParameter(childIndex) }
375392

393+
/**
394+
* Gets the function for which this node represents the parameters.
395+
*/
376396
final Function getFunction() { result = func }
377397
}
378398

@@ -392,6 +412,9 @@ class ConstructorInitializersNode extends PrintASTNode, TConstructorInitializers
392412
result.getAST() = ctor.getInitializer(childIndex)
393413
}
394414

415+
/**
416+
* Gets the `Constructor` for which this node represents the initializer list.
417+
*/
395418
final Constructor getConstructor() { result = ctor }
396419
}
397420

@@ -411,6 +434,9 @@ class DestructorDestructionsNode extends PrintASTNode, TDestructorDestructionsNo
411434
result.getAST() = dtor.getDestruction(childIndex)
412435
}
413436

437+
/**
438+
* Gets the `Destructor` for which this node represents the destruction list.
439+
*/
414440
final Destructor getDestructor() { result = dtor }
415441
}
416442

@@ -464,6 +490,9 @@ class FunctionNode extends ASTNode {
464490
key = "semmle.order" and result = getOrder().toString()
465491
}
466492

493+
/**
494+
* Gets the `Function` this node represents.
495+
*/
467496
final Function getFunction() { result = func }
468497
}
469498

@@ -499,11 +528,16 @@ class ArrayAggregateLiteralNode extends ExprNode {
499528
}
500529
}
501530

531+
/**
532+
* Holds if `node` is printed in the PrintAST output tree and has the property `key` with the
533+
* value `value`.
534+
*/
502535
query predicate nodes(PrintASTNode node, string key, string value) {
503536
node.shouldPrint() and
504537
value = node.getProperty(key)
505538
}
506539

540+
/** Holds if `node` belongs to the output tree, and its property `key` has the given `value`. */
507541
query predicate edges(PrintASTNode source, PrintASTNode target, string key, string value) {
508542
exists(int childIndex |
509543
source.shouldPrint() and
@@ -517,6 +551,7 @@ query predicate edges(PrintASTNode source, PrintASTNode target, string key, stri
517551
)
518552
}
519553

554+
/** Holds if property `key` of the graph has the given `value`. */
520555
query predicate graphProperties(string key, string value) {
521556
key = "semmle.graphKind" and value = "tree"
522557
}

0 commit comments

Comments
 (0)