@@ -35,7 +35,7 @@ private TypedefType getAnEquivalentTypeDef(TypedefType type) {
35
35
* is from within the function signature or field declaration of the type itself.
36
36
*/
37
37
Locatable getATypeUse ( Type type ) {
38
- result = getATypeUse_i ( type )
38
+ result = getATypeUse_i ( type , _ )
39
39
or
40
40
// Identify `TypeMention`s of typedef types, where the underlying type is used.
41
41
//
@@ -61,11 +61,11 @@ Locatable getATypeUse(Type type) {
61
61
tm .getMentionedType ( ) = typedefType
62
62
|
63
63
exists ( tm .getFile ( ) .getRelativePath ( ) ) and
64
- exists ( getATypeUse_i ( typedefType .getUnderlyingType ( ) ) )
64
+ exists ( getATypeUse_i ( typedefType .getUnderlyingType ( ) , _ ) )
65
65
)
66
66
}
67
67
68
- private Locatable getATypeUse_i ( Type type ) {
68
+ private Locatable getATypeUse_i ( Type type , string reason ) {
69
69
(
70
70
// Restrict to uses within the source checkout root
71
71
exists ( result .getFile ( ) .getRelativePath ( ) )
@@ -82,74 +82,92 @@ private Locatable getATypeUse_i(Type type) {
82
82
// Ignore self referential variables and parameters
83
83
not v .getDeclaringType ( ) .refersTo ( type ) and
84
84
not type = v .( Parameter ) .getFunction ( ) .getDeclaringType ( )
85
- )
85
+ ) and
86
+ reason = "used as a variable type"
86
87
or
87
88
// Used a function return type
88
89
exists ( Function f |
89
90
result = f and
90
91
not f .isCompilerGenerated ( ) and
91
92
not type = f .getDeclaringType ( )
92
93
|
93
- type = f .getType ( )
94
+ type = f .getType ( ) and reason = "used as a function return type"
94
95
or
95
- type = f .getATemplateArgument ( )
96
+ type = f .getATemplateArgument ( ) and reason = "used as a function template argument"
96
97
)
97
98
or
98
99
// Used either in a function call as a template argument, or as the declaring type
99
100
// of the function
100
101
exists ( FunctionCall fc | result = fc |
101
- type = fc .getTarget ( ) .getDeclaringType ( )
102
+ type = fc .getTarget ( ) .getDeclaringType ( ) and reason = "used in call to member function"
102
103
or
103
- type = fc .getATemplateArgument ( )
104
+ type = fc .getATemplateArgument ( ) and reason = "used in function call template argument"
104
105
)
105
106
or
106
107
// Aliased in a user typedef
107
- exists ( TypedefType t | result = t | type = t .getBaseType ( ) )
108
+ exists ( TypedefType t | result = t | type = t .getBaseType ( ) ) and
109
+ reason = "aliased in user typedef"
108
110
or
109
111
// A use in a `FunctionAccess`
110
- exists ( FunctionAccess fa | result = fa | type = fa .getTarget ( ) .getDeclaringType ( ) )
112
+ exists ( FunctionAccess fa | result = fa | type = fa .getTarget ( ) .getDeclaringType ( ) ) and
113
+ reason = "used in a function accesses"
111
114
or
112
115
// A use in a `sizeof` expr
113
- exists ( SizeofTypeOperator soto | result = soto | type = soto .getTypeOperand ( ) )
116
+ exists ( SizeofTypeOperator soto | result = soto | type = soto .getTypeOperand ( ) ) and
117
+ reason = "used in a sizeof expr"
114
118
or
115
119
// A use in a `Cast`
116
- exists ( Cast c | c = result | type = c .getType ( ) )
120
+ exists ( Cast c | c = result | type = c .getType ( ) ) and
121
+ reason = "used in a cast"
117
122
or
118
123
// Use of the type name in source
119
- exists ( TypeName t | t = result | type = t .getType ( ) )
124
+ exists ( TypeName t | t = result | type = t .getType ( ) ) and
125
+ reason = "used in a typename"
120
126
or
121
127
// Access of an enum constant
122
- exists ( EnumConstantAccess eca | result = eca | type = eca .getTarget ( ) .getDeclaringEnum ( ) )
128
+ exists ( EnumConstantAccess eca | result = eca | type = eca .getTarget ( ) .getDeclaringEnum ( ) ) and
129
+ reason = "used in an enum constant access"
123
130
or
124
131
// Accessing a field on the type
125
132
exists ( FieldAccess fa |
126
133
result = fa and
127
134
type = fa .getTarget ( ) .getDeclaringType ( )
128
- )
135
+ ) and
136
+ reason = "used in a field access"
129
137
or
130
138
// Name qualifiers
131
139
exists ( NameQualifier nq |
132
140
result = nq and
133
141
type = nq .getQualifyingElement ( )
134
- )
142
+ ) and
143
+ reason = "used in name qualifier"
144
+ or
145
+ // Temporary object creation of type `type`
146
+ exists ( TemporaryObjectExpr toe | result = toe | type = toe .getType ( ) ) and
147
+ reason = "used in temporary object expr"
135
148
)
136
149
or
137
150
// Recursive case - used by a used type
138
- exists ( Type used | result = getATypeUse_i ( used ) |
151
+ exists ( Type used | result = getATypeUse_i ( used , _ ) |
139
152
// The `used` class has `type` as a base class
140
- type = used .( DerivedType ) .getBaseType ( )
153
+ type = used .( DerivedType ) .getBaseType ( ) and
154
+ reason = "used in derived type"
141
155
or
142
156
// The `used` class has `type` as a template argument
143
- type = used .( Class ) .getATemplateArgument ( )
157
+ type = used .( Class ) .getATemplateArgument ( ) and
158
+ reason = "used in class template argument"
144
159
or
145
160
// A used class is derived from the type class
146
- type = used .( Class ) .getABaseClass ( )
161
+ type = used .( Class ) .getABaseClass ( ) and
162
+ reason = "used in derived class"
147
163
or
148
164
// This is a TemplateClass where one of the instantiations is used
149
- type .( TemplateClass ) .getAnInstantiation ( ) = used
165
+ type .( TemplateClass ) .getAnInstantiation ( ) = used and
166
+ reason = "used in template class instantiation"
150
167
or
151
168
// This is a TemplateClass where one of the specializations is used
152
- type = used .( ClassTemplateSpecialization ) .getPrimaryTemplate ( )
169
+ type = used .( ClassTemplateSpecialization ) .getPrimaryTemplate ( ) and
170
+ reason = "used in template class specialization"
153
171
or
154
172
// Alias templates - alias templates and instantiations are not properly captured by the
155
173
// extractor (last verified in CodeQL CLI 2.7.6). The only distinguishing factor is that
@@ -164,6 +182,7 @@ private Locatable getATypeUse_i(Type type) {
164
182
not exists ( instantiation .getLocation ( ) ) and
165
183
// Template and instantiation both have the same qualified name
166
184
template .getQualifiedName ( ) = instantiation .getQualifiedName ( )
167
- )
185
+ ) and
186
+ reason = "used in alias template instantiation"
168
187
)
169
188
}
0 commit comments