@@ -18,7 +18,18 @@ abstract class Access extends Expr, NameQualifiableElement {
18
18
}
19
19
20
20
/**
21
- * A C/C++ enum constant access expression.
21
+ * A C/C++ `enum` constant access expression. For example the access to
22
+ * `MYENUMCONST1` in `myFunction` in the following code:
23
+ * ```
24
+ * enum MyEnum {
25
+ * MYENUMCONST1,
26
+ * MYENUMCONST2
27
+ * };
28
+ *
29
+ * void myFunction() {
30
+ * MyEnum v = MYENUMCONST1;
31
+ * };
32
+ * ```
22
33
*/
23
34
class EnumConstantAccess extends Access , @varaccess {
24
35
override string getCanonicalQLClass ( ) { result = "EnumConstantAccess" }
@@ -27,15 +38,23 @@ class EnumConstantAccess extends Access, @varaccess {
27
38
exists ( EnumConstant c | varbind ( underlyingElement ( this ) , unresolveElement ( c ) ) )
28
39
}
29
40
30
- /** Gets the accessed enum constant. */
41
+ /** Gets the accessed ` enum` constant. */
31
42
override EnumConstant getTarget ( ) { varbind ( underlyingElement ( this ) , unresolveElement ( result ) ) }
32
43
33
- /** Gets a textual representation of this enum constant access. */
44
+ /** Gets a textual representation of this ` enum` constant access. */
34
45
override string toString ( ) { result = this .getTarget ( ) .getName ( ) }
35
46
}
36
47
37
48
/**
38
- * A C/C++ variable access expression.
49
+ * A C/C++ variable access expression. For example the accesses to
50
+ * `x` and `y` in `myFunction` in the following code:
51
+ * ```
52
+ * int x;
53
+ *
54
+ * void myFunction(int y) {
55
+ * x = y;
56
+ * };
57
+ * ```
39
58
*/
40
59
class VariableAccess extends Access , @varaccess {
41
60
override string getCanonicalQLClass ( ) { result = "VariableAccess" }
@@ -129,7 +148,18 @@ class VariableAccess extends Access, @varaccess {
129
148
}
130
149
131
150
/**
132
- * A C/C++ field access expression.
151
+ * A C/C++ field access expression. For example the accesses to
152
+ * `x` and `y` in `myMethod` in the following code:
153
+ * ```
154
+ * class MyClass {
155
+ * public:
156
+ * void myMethod(MyClass &other) {
157
+ * x = other.y;
158
+ * }
159
+ *
160
+ * int x, y;
161
+ * };
162
+ * ```
133
163
*/
134
164
class FieldAccess extends VariableAccess {
135
165
override string getCanonicalQLClass ( ) { result = "FieldAccess" }
@@ -141,8 +171,23 @@ class FieldAccess extends VariableAccess {
141
171
}
142
172
143
173
/**
144
- * A field access of the form `obj->field`. The type of `obj` is a pointer,
145
- * so this is equivalent to `(*obj).field`.
174
+ * A field access whose qualifier is a pointer to a class, struct or union.
175
+ * These typically take the form `obj->field`. Another case is a field access
176
+ * with an implicit `this->` qualifier, which is often a `PointerFieldAccess`
177
+ * (but see also `ImplicitThisFieldAccess`).
178
+ *
179
+ * For example the accesses to `x` and `y` in `myMethod` in the following code
180
+ * are each a `PointerFieldAccess`:
181
+ * ```
182
+ * class MyClass {
183
+ * public:
184
+ * void myMethod(MyClass *other) {
185
+ * other->x = y;
186
+ * }
187
+ *
188
+ * int x, y;
189
+ * };
190
+ * ```
146
191
*/
147
192
class PointerFieldAccess extends FieldAccess {
148
193
override string getCanonicalQLClass ( ) { result = "PointerFieldAccess" }
@@ -169,7 +214,18 @@ class DotFieldAccess extends FieldAccess {
169
214
170
215
/**
171
216
* A field access of the form `obj.field`, where the type of `obj` is a
172
- * reference to a class/struct/union.
217
+ * reference to a class/struct/union. For example the accesses to `y` in
218
+ * `myMethod` in the following code:
219
+ * ```
220
+ * class MyClass {
221
+ * public:
222
+ * void myMethod(MyClass a, MyClass &b) {
223
+ * a.x = b.y;
224
+ * }
225
+ *
226
+ * int x, y;
227
+ * };
228
+ * ```
173
229
*/
174
230
class ReferenceFieldAccess extends DotFieldAccess {
175
231
override string getCanonicalQLClass ( ) { result = "ReferenceFieldAccess" }
@@ -179,7 +235,18 @@ class ReferenceFieldAccess extends DotFieldAccess {
179
235
180
236
/**
181
237
* A field access of the form `obj.field`, where the type of `obj` is a
182
- * class/struct/union (and not a reference).
238
+ * class/struct/union (and not a reference). For example the accesses to `x`
239
+ * in `myMethod` in the following code:
240
+ * ```
241
+ * class MyClass {
242
+ * public:
243
+ * void myMethod(MyClass a, MyClass &b) {
244
+ * a.x = b.y;
245
+ * }
246
+ *
247
+ * int x, y;
248
+ * };
249
+ * ```
183
250
*/
184
251
class ValueFieldAccess extends DotFieldAccess {
185
252
override string getCanonicalQLClass ( ) { result = "ValueFieldAccess" }
@@ -198,25 +265,40 @@ private predicate referenceConversion(Conversion c) {
198
265
/**
199
266
* Holds if `e` is a reference expression (that is, it has a type of the
200
267
* form `T&`), which is converted to a value. For example:
201
- *
202
268
* ```
203
269
* int myfcn(MyStruct &x) {
204
270
* return x.field;
205
271
* }
206
272
* ```
207
- *
208
273
* In this example, the type of `x` is `MyStruct&`, but it gets implicitly
209
274
* converted to `MyStruct` in the expression `x.field`.
210
275
*/
211
276
private predicate exprHasReferenceConversion ( Expr e ) { referenceConversion ( e .getConversion + ( ) ) }
212
277
213
278
/**
214
- * A field access of a field of `this`. The access has no qualifier because
215
- * the use of `this` is implicit. For example, `field` is equivalent to
216
- * `this->field` if `field` is a member of `this`.
279
+ * A field access of a field of `this` which has no qualifier because
280
+ * the use of `this` is implicit. For example, in the following code the
281
+ * implicit call to the destructor of `A` has no qualifier because the
282
+ * use of `this` is implicit:
283
+ * ```
284
+ * class A {
285
+ * public:
286
+ * ~A() {
287
+ * // ...
288
+ * }
289
+ * };
217
290
*
291
+ * class B {
292
+ * public:
293
+ * A a;
294
+ *
295
+ * ~B() {
296
+ * // Implicit call to the destructor of `A`.
297
+ * }
298
+ * };
299
+ * ```
218
300
* Note: the C++ front-end often automatically desugars `field` to
219
- * `this->field`, so most implicit accesses of `this->field` are instances
301
+ * `this->field`, so most accesses of `this->field` are instances
220
302
* of `PointerFieldAccess` (with `ThisExpr` as the qualifier), not
221
303
* `ImplicitThisFieldAccess`.
222
304
*/
@@ -250,7 +332,15 @@ class PointerToFieldLiteral extends ImplicitThisFieldAccess {
250
332
}
251
333
252
334
/**
253
- * A C/C++ function access expression.
335
+ * A C/C++ function access expression. For example the access to
336
+ * `myFunctionTarget` in `myFunction` in the following code:
337
+ * ```
338
+ * int myFunctionTarget(int);
339
+ *
340
+ * void myFunction() {
341
+ * int (*myFunctionPointer)(int) = &myTarget;
342
+ * }
343
+ * ```
254
344
*/
255
345
class FunctionAccess extends Access , @routineexpr {
256
346
FunctionAccess ( ) { not iscall ( underlyingElement ( this ) , _) }
@@ -269,7 +359,7 @@ class FunctionAccess extends Access, @routineexpr {
269
359
}
270
360
271
361
/**
272
- * An access to a parameter of a function signature for the purposes of a decltype.
362
+ * An access to a parameter of a function signature for the purposes of a ` decltype` .
273
363
*
274
364
* For example, given the following code:
275
365
* ```
@@ -279,15 +369,30 @@ class FunctionAccess extends Access, @routineexpr {
279
369
* }
280
370
* ```
281
371
* The return type of the function is a decltype, the expression of which contains
282
- * an add expression, which in turn has two ParamAccessForType children.
372
+ * an add expression, which in turn has two ` ParamAccessForType` children.
283
373
*/
284
374
class ParamAccessForType extends Expr , @param_ref {
285
375
override string toString ( ) { result = "param access" }
286
376
}
287
377
288
378
/**
289
379
* An access to a type. This occurs in certain contexts where a built-in
290
- * works on types directly rather than variables, expressions etc.
380
+ * works on types directly rather than variables, expressions etc. For
381
+ * example the reference to `MyClass` in `__is_pod` in the following code:
382
+ * ```
383
+ * class MyClass {
384
+ * ...
385
+ * };
386
+ *
387
+ * void myFunction() {
388
+ * if (__is_pod(MyClass))
389
+ * {
390
+ * ...
391
+ * } else {
392
+ * ...
393
+ * }
394
+ * }
395
+ * ```
291
396
*/
292
397
class TypeName extends Expr , @type_operand {
293
398
override string getCanonicalQLClass ( ) { result = "TypeName" }
@@ -296,24 +401,32 @@ class TypeName extends Expr, @type_operand {
296
401
}
297
402
298
403
/**
299
- * A C/C++ array access expression.
404
+ * A C/C++ array access expression. For example, the access to `as` in
405
+ * `myFunction` in the following code:
406
+ * ```
407
+ * int as[10];
300
408
*
301
- * For calls to operator[], which look syntactically identical, see OverloadedArrayExpr.
409
+ * void myFunction() {
410
+ * as[0]++;
411
+ * }
412
+ * ```
413
+ * For calls to `operator[]`, which look syntactically identical, see
414
+ * `OverloadedArrayExpr`.
302
415
*/
303
416
class ArrayExpr extends Expr , @subscriptexpr {
304
417
override string getCanonicalQLClass ( ) { result = "ArrayExpr" }
305
418
306
419
/**
307
420
* Gets the array or pointer expression being subscripted.
308
421
*
309
- * This is arr in both arr[0] and 0[arr].
422
+ * This is ` arr` in both ` arr[0]` and ` 0[arr]` .
310
423
*/
311
424
Expr getArrayBase ( ) { result = this .getChild ( 0 ) }
312
425
313
426
/**
314
427
* Gets the expression giving the index into the array.
315
428
*
316
- * This is 0 in both arr[0] and 0[arr].
429
+ * This is `0` in both ` arr[0]` and ` 0[arr]` .
317
430
*/
318
431
Expr getArrayOffset ( ) { result = this .getChild ( 1 ) }
319
432
0 commit comments