Skip to content

Commit 6c26ad7

Browse files
committed
C++: Expand QLDoc.
1 parent 4033ed3 commit 6c26ad7

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

cpp/ql/lib/semmle/code/cpp/exprs/Literal.qll

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,15 @@ class ClassAggregateLiteral extends AggregateLiteral {
211211
* field `field`, if present. The expression is the `position`'th entry in the
212212
* aggregate literal.
213213
*
214-
* For example, if `aggr` represents the initialization literal `{.x = 1234, .x = 5678}` in
214+
* For example, if `aggr` represents the initialization literal `{.x = 123, .y = 456 .x = 789}` in
215215
* ```cpp
216-
* struct Foo { int x; };
217-
* struct Foo foo = {.x = 1234, .x = 5678};
216+
* struct Foo { int x; int y; };
217+
* struct Foo foo = {.x = 123, .y = 456 .x = 789};
218218
* ```
219-
* then `aggr.getFieldExpr(x, 0)` gives `1234`, and `aggr.getFieldExpr(x, 1)` gives `5678`.
219+
* then:
220+
* - `aggr.getFieldExpr(x, 0)` gives `123`.
221+
* - `aggr.getFieldExpr(y, 1)` gives `456`.
222+
* - `aggr.getFieldExpr(x, 2)` gives `789`.
220223
*/
221224
Expr getFieldExpr(Field field, int position) {
222225
field = classType.getAField() and
@@ -313,11 +316,14 @@ class ArrayOrVectorAggregateLiteral extends AggregateLiteral {
313316
* element `elementIndex`, if present. The expression is the `position`'th entry
314317
* in the aggregate literal.
315318
*
316-
* For example, if `a` represents the initialization literal `{[0] = 1234, [0] = 5678}` in
319+
* For example, if `a` represents the initialization literal `{[0] = 123, [1] = 456, [0] = 789 }` in
317320
* ```cpp
318-
* int x[1] = {[0] = 1234, [0] = 5678};
321+
* int x[2] = {[0] = 123, [1] = 456, [0] = 789 };
319322
* ```
320-
* then `a.getElementExpr(0, 0)` gives `1234`, and `a.getElementExpr(0, 1)` gives `5678`.
323+
* then:
324+
* - `a.getElementExpr(0, 0)` gives `123`.
325+
* - `a.getElementExpr(1, 1)` gives `456`.
326+
* - `a.getElementExpr(0, 2)` gives `789`.
321327
*/
322328
Expr getElementExpr(int elementIndex, int position) {
323329
aggregate_array_init(underlyingElement(this), unresolveElement(result), elementIndex, position)

0 commit comments

Comments
 (0)