1
1
import semmle.code.cpp.exprs.Expr
2
2
3
3
/**
4
- * A C/C++ arithmetic operation.
4
+ * A C/C++ unary arithmetic operation.
5
+ *
6
+ * This is an abstract base QL class.
5
7
*/
6
8
abstract class UnaryArithmeticOperation extends UnaryOperation {
7
9
}
8
10
9
11
/**
10
12
* A C/C++ unary minus expression.
13
+ * ```
14
+ * b = - a;
15
+ * ```
11
16
*/
12
17
class UnaryMinusExpr extends UnaryArithmeticOperation , @arithnegexpr {
13
18
override string getOperator ( ) { result = "-" }
14
19
15
20
override string getCanonicalQLClass ( ) { result = "UnaryMinusExpr" }
16
-
21
+
17
22
override int getPrecedence ( ) { result = 15 }
18
23
}
19
24
20
25
/**
21
26
* A C/C++ unary plus expression.
27
+ * ```
28
+ * b = + a;
29
+ * ```
22
30
*/
23
31
class UnaryPlusExpr extends UnaryArithmeticOperation , @unaryplusexpr {
24
32
override string getOperator ( ) { result = "+" }
25
33
26
34
override string getCanonicalQLClass ( ) { result = "UnaryPlusExpr" }
27
-
35
+
28
36
override int getPrecedence ( ) { result = 15 }
29
37
}
30
38
31
39
/**
32
- * A C/C++ GNU conjugation expression.
40
+ * A C/C++ GNU conjugation expression. It operates on `_Complex` or
41
+ * `__complex_`numbers, and is similar to the C99 `conj`, `conjf` and `conjl`
42
+ * functions.
43
+ * ```
44
+ * _Complex double a = ( 1.0, 2.0 );
45
+ * b = ~ a; // ( 1,0, - 2.0 )
46
+ * ```
33
47
*/
34
48
class ConjugationExpr extends UnaryArithmeticOperation , @conjugation {
35
49
override string getOperator ( ) { result = "~" }
50
+
51
+ override string getCanonicalQLClass ( ) { result = "ConjugationExpr" }
36
52
}
37
53
38
54
/**
39
55
* A C/C++ `++` or `--` expression (either prefix or postfix).
40
56
*
41
- * Note that this doesn't include calls to user-defined `operator++`
57
+ * This is the abstract base QL class for increment and decrement operations.
58
+ *
59
+ * Note that this doesn't include calls to _user-defined_ `operator++`
42
60
* or `operator--`.
43
61
*/
44
62
abstract class CrementOperation extends UnaryArithmeticOperation {
@@ -89,39 +107,48 @@ abstract class PostfixCrementOperation extends CrementOperation {
89
107
/**
90
108
* A C/C++ prefix increment expression, as in `++x`.
91
109
*
92
- * Note that this doesn't include calls to user-defined `operator++`.
110
+ * Note that this doesn't include calls to _user-defined_ `operator++`.
111
+ * ```
112
+ * b = ++a;
113
+ * ```
93
114
*/
94
115
class PrefixIncrExpr extends IncrementOperation , PrefixCrementOperation , @preincrexpr {
95
116
override string getOperator ( ) { result = "++" }
96
117
97
118
override string getCanonicalQLClass ( ) { result = "PrefixIncrExpr" }
98
-
119
+
99
120
override int getPrecedence ( ) { result = 15 }
100
121
}
101
122
102
123
/**
103
124
* A C/C++ prefix decrement expression, as in `--x`.
104
125
*
105
- * Note that this doesn't include calls to user-defined `operator--`.
126
+ * Note that this doesn't include calls to _user-defined_ `operator--`.
127
+ * ```
128
+ * b = --a;
129
+ * ```
106
130
*/
107
131
class PrefixDecrExpr extends DecrementOperation , PrefixCrementOperation , @predecrexpr {
108
132
override string getOperator ( ) { result = "--" }
109
133
110
134
override string getCanonicalQLClass ( ) { result = "PrefixDecrExpr" }
111
-
135
+
112
136
override int getPrecedence ( ) { result = 15 }
113
137
}
114
138
115
139
/**
116
140
* A C/C++ postfix increment expression, as in `x++`.
117
141
*
118
- * Note that this doesn't include calls to user-defined `operator++`.
142
+ * Note that this doesn't include calls to _user-defined_ `operator++`.
143
+ * ```
144
+ * b = a++;
145
+ * ```
119
146
*/
120
147
class PostfixIncrExpr extends IncrementOperation , PostfixCrementOperation , @postincrexpr {
121
148
override string getOperator ( ) { result = "++" }
122
149
123
150
override string getCanonicalQLClass ( ) { result = "PostfixIncrExpr" }
124
-
151
+
125
152
override int getPrecedence ( ) { result = 16 }
126
153
127
154
override string toString ( ) { result = "... " + getOperator ( ) }
@@ -130,90 +157,126 @@ class PostfixIncrExpr extends IncrementOperation, PostfixCrementOperation, @post
130
157
/**
131
158
* A C/C++ postfix decrement expression, as in `x--`.
132
159
*
133
- * Note that this doesn't include calls to user-defined `operator--`.
160
+ * Note that this doesn't include calls to _user-defined_ `operator--`.
161
+ * ```
162
+ * b = a--;
163
+ * ```
134
164
*/
135
165
class PostfixDecrExpr extends DecrementOperation , PostfixCrementOperation , @postdecrexpr {
136
166
override string getOperator ( ) { result = "--" }
137
167
138
168
override string getCanonicalQLClass ( ) { result = "PostfixDecrExpr" }
139
-
169
+
140
170
override int getPrecedence ( ) { result = 16 }
141
171
142
172
override string toString ( ) { result = "... " + getOperator ( ) }
143
173
}
144
174
145
175
/**
146
- * A C/C++ GNU real part expression.
176
+ * A C/C++ GNU real part expression. It operates on `_Complex` or
177
+ * `__complex__` numbers.
178
+ * ```
179
+ * #include <complex.h>
180
+ * _Complex double f = CMPLX( 2.0, 3.0 );
181
+ * double d = __real(f); // 2.0
182
+ * ```
147
183
*/
148
184
class RealPartExpr extends UnaryArithmeticOperation , @realpartexpr {
149
185
override string getOperator ( ) { result = "__real" }
186
+
187
+ override string getCanonicalQLClass ( ) { result = "RealPartExpr" }
150
188
}
151
189
152
190
/**
153
- * A C/C++ GNU imaginary part expression.
191
+ * A C/C++ GNU imaginary part expression. It operates on `_Complex` or
192
+ * `__complex__` numbers.
193
+ * ```
194
+ * #include <complex.h>
195
+ * _Complex double f = CMPLX( 2.0, 3.0 );
196
+ * double d = __imag(f); // 3.0
197
+ * ```
154
198
*/
155
199
class ImaginaryPartExpr extends UnaryArithmeticOperation , @imagpartexpr {
156
200
override string getOperator ( ) { result = "__imag" }
201
+
202
+ override string getCanonicalQLClass ( ) { result = "ImaginaryPartExpr" }
157
203
}
158
204
159
205
/**
160
206
* A C/C++ binary arithmetic operation.
207
+ *
208
+ * This is an abstract base QL class for all binary arithmetic operations.
161
209
*/
162
210
abstract class BinaryArithmeticOperation extends BinaryOperation {
163
211
}
164
212
165
213
/**
166
214
* A C/C++ add expression.
215
+ * ```
216
+ * c = a + b;
217
+ * ```
167
218
*/
168
219
class AddExpr extends BinaryArithmeticOperation , @addexpr {
169
220
override string getOperator ( ) { result = "+" }
170
221
171
222
override string getCanonicalQLClass ( ) { result = "AddExpr" }
172
-
223
+
173
224
override int getPrecedence ( ) { result = 12 }
174
225
}
175
226
176
227
/**
177
228
* A C/C++ subtract expression.
229
+ * ```
230
+ * c = a - b;
231
+ * ```
178
232
*/
179
233
class SubExpr extends BinaryArithmeticOperation , @subexpr {
180
234
override string getOperator ( ) { result = "-" }
181
235
182
236
override string getCanonicalQLClass ( ) { result = "SubExpr" }
183
-
237
+
184
238
override int getPrecedence ( ) { result = 12 }
185
239
}
186
240
187
241
/**
188
242
* A C/C++ multiply expression.
243
+ * ```
244
+ * c = a * b;
245
+ * ```
189
246
*/
190
247
class MulExpr extends BinaryArithmeticOperation , @mulexpr {
191
248
override string getOperator ( ) { result = "*" }
192
249
193
250
override string getCanonicalQLClass ( ) { result = "MulExpr" }
194
-
251
+
195
252
override int getPrecedence ( ) { result = 13 }
196
253
}
197
254
198
255
/**
199
256
* A C/C++ divide expression.
257
+ * ```
258
+ * c = a / b;
259
+ * ```
200
260
*/
201
261
class DivExpr extends BinaryArithmeticOperation , @divexpr {
202
262
override string getOperator ( ) { result = "/" }
203
263
204
264
override string getCanonicalQLClass ( ) { result = "DivExpr" }
205
-
265
+
206
266
override int getPrecedence ( ) { result = 13 }
207
267
}
208
268
209
269
/**
210
270
* A C/C++ remainder expression.
271
+ * ```
272
+ * c = a % b;
273
+ * ```
211
274
*/
212
275
class RemExpr extends BinaryArithmeticOperation , @remexpr {
213
276
override string getOperator ( ) { result = "%" }
214
277
215
278
override string getCanonicalQLClass ( ) { result = "RemExpr" }
216
-
279
+
217
280
override int getPrecedence ( ) { result = 13 }
218
281
}
219
282
@@ -224,6 +287,8 @@ class ImaginaryMulExpr extends BinaryArithmeticOperation, @jmulexpr {
224
287
override string getOperator ( ) { result = "*" }
225
288
226
289
override int getPrecedence ( ) { result = 13 }
290
+
291
+ override string getCanonicalQLClass ( ) { result = "ImaginaryMulExpr" }
227
292
}
228
293
229
294
/**
@@ -233,6 +298,8 @@ class ImaginaryDivExpr extends BinaryArithmeticOperation, @jdivexpr {
233
298
override string getOperator ( ) { result = "/" }
234
299
235
300
override int getPrecedence ( ) { result = 13 }
301
+
302
+ override string getCanonicalQLClass ( ) { result = "ImaginaryDivExpr" }
236
303
}
237
304
238
305
/**
@@ -242,6 +309,8 @@ class RealImaginaryAddExpr extends BinaryArithmeticOperation, @fjaddexpr {
242
309
override string getOperator ( ) { result = "+" }
243
310
244
311
override int getPrecedence ( ) { result = 12 }
312
+
313
+ override string getCanonicalQLClass ( ) { result = "RealImaginaryAddExpr" }
245
314
}
246
315
247
316
/**
@@ -251,6 +320,8 @@ class ImaginaryRealAddExpr extends BinaryArithmeticOperation, @jfaddexpr {
251
320
override string getOperator ( ) { result = "+" }
252
321
253
322
override int getPrecedence ( ) { result = 12 }
323
+
324
+ override string getCanonicalQLClass ( ) { result = "ImaginaryRealAddExpr" }
254
325
}
255
326
256
327
/**
@@ -260,6 +331,8 @@ class RealImaginarySubExpr extends BinaryArithmeticOperation, @fjsubexpr {
260
331
override string getOperator ( ) { result = "-" }
261
332
262
333
override int getPrecedence ( ) { result = 12 }
334
+
335
+ override string getCanonicalQLClass ( ) { result = "RealImaginarySubExpr" }
263
336
}
264
337
265
338
/**
@@ -269,20 +342,32 @@ class ImaginaryRealSubExpr extends BinaryArithmeticOperation, @jfsubexpr {
269
342
override string getOperator ( ) { result = "-" }
270
343
271
344
override int getPrecedence ( ) { result = 12 }
345
+
346
+ override string getCanonicalQLClass ( ) { result = "ImaginaryRealSubExpr" }
272
347
}
273
348
274
349
/**
275
350
* A C/C++ GNU min expression.
351
+ * ```
352
+ * c = a <? b;
353
+ * ```
276
354
*/
277
355
class MinExpr extends BinaryArithmeticOperation , @minexpr {
278
356
override string getOperator ( ) { result = "<?" }
357
+
358
+ override string getCanonicalQLClass ( ) { result = "MinExpr" }
279
359
}
280
360
281
361
/**
282
362
* A C/C++ GNU max expression.
363
+ * ```
364
+ * c = a >? b;
365
+ * ```
283
366
*/
284
367
class MaxExpr extends BinaryArithmeticOperation , @maxexpr {
285
368
override string getOperator ( ) { result = ">?" }
369
+
370
+ override string getCanonicalQLClass ( ) { result = "MaxExpr" }
286
371
}
287
372
288
373
/**
@@ -293,33 +378,45 @@ abstract class PointerArithmeticOperation extends BinaryArithmeticOperation {
293
378
294
379
/**
295
380
* A C/C++ pointer add expression.
381
+ * ```
382
+ * foo *ptr = &f[0];
383
+ * ptr = ptr + 2;
384
+ * ```
296
385
*/
297
386
class PointerAddExpr extends PointerArithmeticOperation , @paddexpr {
298
387
override string getOperator ( ) { result = "+" }
299
388
300
389
override string getCanonicalQLClass ( ) { result = "PointerAddExpr" }
301
-
390
+
302
391
override int getPrecedence ( ) { result = 12 }
303
392
}
304
393
305
394
/**
306
395
* A C/C++ pointer subtract expression.
396
+ * ```
397
+ * foo *ptr = &f[3];
398
+ * ptr = ptr - 2;
399
+ * ```
307
400
*/
308
401
class PointerSubExpr extends PointerArithmeticOperation , @psubexpr {
309
402
override string getOperator ( ) { result = "-" }
310
403
311
404
override string getCanonicalQLClass ( ) { result = "PointerSubExpr" }
312
-
405
+
313
406
override int getPrecedence ( ) { result = 12 }
314
407
}
315
408
316
409
/**
317
410
* A C/C++ pointer difference expression.
411
+ * ```
412
+ * foo *start = &f[0], *end = &f[4];
413
+ * int size = end - size;
414
+ * ```
318
415
*/
319
416
class PointerDiffExpr extends PointerArithmeticOperation , @pdiffexpr {
320
417
override string getOperator ( ) { result = "-" }
321
418
322
419
override string getCanonicalQLClass ( ) { result = "PointerDiffExpr" }
323
-
420
+
324
421
override int getPrecedence ( ) { result = 12 }
325
422
}
0 commit comments