|
1 | 1 | /** |
2 | | - * A library for identifying parameters which may be unused. |
3 | | - */ |
| 2 | +* A library for identifying parameters which may be unused. |
| 3 | +*/ |
4 | 4 |
|
5 | 5 | import cpp |
6 | 6 |
|
7 | 7 | /** |
8 | | - * A `Parameter` which is "usable" within the function. |
9 | | - * |
10 | | - * For this to be the case, the `Function` must have a definition, and that definition must include |
11 | | - * a body block, and the parameter must be a named parameter. |
12 | | - */ |
| 8 | +* A `Parameter` which is "usable" within the function. |
| 9 | +* |
| 10 | +* For this to be the case, the `Function` must have a definition, and that definition must include |
| 11 | +* a body block, and the parameter must be a named parameter. |
| 12 | +*/ |
13 | 13 | class UsableParameter extends Parameter { |
14 | 14 | UsableParameter() { |
15 | | - // Find the function associated with the parameter |
16 | | - exists(Function f | this = f.getAParameter() | |
17 | | - // Must have the definition of the function, not just the declaration |
18 | | - f.hasDefinition() and |
19 | | - // There must be a body block associated with the function, otherwise the parameter cannot |
20 | | - // possibly be used |
21 | | - exists(f.getBlock()) |
22 | | - ) and |
| 15 | + ( |
| 16 | + /* Regular Function */ |
| 17 | + // Find the function associated with the parameter |
| 18 | + exists(Function f | this = f.getAParameter() | |
| 19 | + // Must have the definition of the function, not just the declaration |
| 20 | + f.hasDefinition() and |
| 21 | + // There must be a body block associated with the function, otherwise the parameter cannot |
| 22 | + // possibly be used |
| 23 | + exists(f.getBlock()) |
| 24 | + ) |
| 25 | + or |
| 26 | + /* Lambda Expression */ |
| 27 | + // Find the function associated with the parameter |
| 28 | + exists(LambdaExpression lambda, Function f | |
| 29 | + this = lambda.getLambdaFunction().getParameter(_) |
| 30 | + | |
| 31 | + // Must have the definition of the function, not just the declaration |
| 32 | + lambda.getLambdaFunction() = f and |
| 33 | + f.hasDefinition() and |
| 34 | + // There must be a body block associated with the function, otherwise the parameter cannot |
| 35 | + // possibly be used |
| 36 | + exists(f.getBlock()) |
| 37 | + ) |
| 38 | + ) and |
23 | 39 | // Must be a named parameter, because unnamed parameters cannot be referenced |
24 | 40 | isNamed() |
25 | 41 | } |
26 | 42 | } |
27 | 43 |
|
28 | 44 | /** |
29 | | - * A `Parameter` which is usable but not directly used in the local context. |
30 | | - */ |
| 45 | +* A `Parameter` which is usable but not directly used in the local context. |
| 46 | +*/ |
31 | 47 | class UnusedParameter extends UsableParameter { |
32 | 48 | UnusedParameter() { not this instanceof UsedParameter } |
33 | 49 | } |
34 | 50 |
|
35 | 51 | /** |
36 | | - * A `Parameter` which is used in the local context. |
37 | | - */ |
| 52 | +* A `Parameter` which is used in the local context. |
| 53 | +*/ |
38 | 54 | class UsedParameter extends UsableParameter { |
39 | 55 | UsedParameter() { |
40 | 56 | // An access to the parameter exists in the function body |
|
0 commit comments