@@ -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,77 +82,86 @@ 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 reason = "used as a variable type"
86
86
or
87
87
// Used a function return type
88
88
exists ( Function f |
89
89
result = f and
90
90
not f .isCompilerGenerated ( ) and
91
91
not type = f .getDeclaringType ( )
92
92
|
93
- type = f .getType ( )
93
+ type = f .getType ( ) and reason = "used as a function return type"
94
94
or
95
- type = f .getATemplateArgument ( )
96
- )
97
- or
95
+ type = f .getATemplateArgument ( ) and reason = "used as a function template argument"
96
+ ) or
98
97
// Used either in a function call as a template argument, or as the declaring type
99
98
// of the function
100
99
exists ( FunctionCall fc | result = fc |
101
- type = fc .getTarget ( ) .getDeclaringType ( )
100
+ type = fc .getTarget ( ) .getDeclaringType ( ) and reason = "used in call to member function"
102
101
or
103
- type = fc .getATemplateArgument ( )
102
+ type = fc .getATemplateArgument ( ) and reason = "used in function call template argument"
104
103
)
105
104
or
106
105
// Aliased in a user typedef
107
- exists ( TypedefType t | result = t | type = t .getBaseType ( ) )
106
+ exists ( TypedefType t | result = t | type = t .getBaseType ( ) ) and
107
+ reason = "aliased in user typedef"
108
108
or
109
109
// A use in a `FunctionAccess`
110
- exists ( FunctionAccess fa | result = fa | type = fa .getTarget ( ) .getDeclaringType ( ) )
110
+ exists ( FunctionAccess fa | result = fa | type = fa .getTarget ( ) .getDeclaringType ( ) ) and
111
+ reason = "used in a function accesses"
111
112
or
112
113
// A use in a `sizeof` expr
113
- exists ( SizeofTypeOperator soto | result = soto | type = soto .getTypeOperand ( ) )
114
+ exists ( SizeofTypeOperator soto | result = soto | type = soto .getTypeOperand ( ) ) and
115
+ reason = "used in a sizeof expr"
114
116
or
115
117
// A use in a `Cast`
116
- exists ( Cast c | c = result | type = c .getType ( ) )
118
+ exists ( Cast c | c = result | type = c .getType ( ) ) and reason = "used in a cast"
117
119
or
118
120
// Use of the type name in source
119
- exists ( TypeName t | t = result | type = t .getType ( ) )
121
+ exists ( TypeName t | t = result | type = t .getType ( ) ) and reason = "used in a typename"
120
122
or
121
123
// Access of an enum constant
122
- exists ( EnumConstantAccess eca | result = eca | type = eca .getTarget ( ) .getDeclaringEnum ( ) )
124
+ exists ( EnumConstantAccess eca | result = eca | type = eca .getTarget ( ) .getDeclaringEnum ( ) ) and
125
+ reason = "used in an enum constant access"
123
126
or
124
127
// Accessing a field on the type
125
128
exists ( FieldAccess fa |
126
129
result = fa and
127
130
type = fa .getTarget ( ) .getDeclaringType ( )
128
- )
131
+ ) and reason = "used in a field access"
129
132
or
130
133
// Name qualifiers
131
134
exists ( NameQualifier nq |
132
135
result = nq and
133
136
type = nq .getQualifyingElement ( )
134
- )
137
+ ) and reason = "used in name qualifier"
135
138
// Temporary object creation of type `type`
136
139
or
137
- exists ( TemporaryObjectExpr toe | result = toe | type = toe .getType ( ) )
140
+ exists ( TemporaryObjectExpr toe | result = toe | type = toe .getType ( ) ) and
141
+ reason = "used in temporary object expr"
138
142
)
139
143
or
140
144
// Recursive case - used by a used type
141
- exists ( Type used | result = getATypeUse_i ( used ) |
145
+ exists ( Type used | result = getATypeUse_i ( used , _ ) |
142
146
// The `used` class has `type` as a base class
143
- type = used .( DerivedType ) .getBaseType ( )
147
+ type = used .( DerivedType ) .getBaseType ( ) and
148
+ reason = "used in derived type"
144
149
or
145
150
// The `used` class has `type` as a template argument
146
- type = used .( Class ) .getATemplateArgument ( )
151
+ type = used .( Class ) .getATemplateArgument ( ) and
152
+ reason = "used in class template argument"
147
153
or
148
154
// A used class is derived from the type class
149
- type = used .( Class ) .getABaseClass ( )
155
+ type = used .( Class ) .getABaseClass ( ) and
156
+ reason = "used in derived class"
150
157
or
151
158
// This is a TemplateClass where one of the instantiations is used
152
- type .( TemplateClass ) .getAnInstantiation ( ) = used
159
+ type .( TemplateClass ) .getAnInstantiation ( ) = used and
160
+ reason = "used in template class instantiation"
153
161
or
154
162
// This is a TemplateClass where one of the specializations is used
155
163
type = used .( ClassTemplateSpecialization ) .getPrimaryTemplate ( )
164
+ and reason = "used in template class specialization"
156
165
or
157
166
// Alias templates - alias templates and instantiations are not properly captured by the
158
167
// extractor (last verified in CodeQL CLI 2.7.6). The only distinguishing factor is that
@@ -167,6 +176,6 @@ private Locatable getATypeUse_i(Type type) {
167
176
not exists ( instantiation .getLocation ( ) ) and
168
177
// Template and instantiation both have the same qualified name
169
178
template .getQualifiedName ( ) = instantiation .getQualifiedName ( )
170
- )
179
+ ) and reason = "used in alias template instantiation"
171
180
)
172
181
}
0 commit comments