@@ -144,6 +144,20 @@ class AllocationInstruction extends CallInstruction {
144
144
AllocationInstruction ( ) { this .getStaticCallTarget ( ) instanceof Cpp:: AllocationFunction }
145
145
}
146
146
147
+ private predicate isIndirectionType ( Type t ) { t instanceof Indirection }
148
+
149
+ private predicate hasUnspecifiedBaseType ( Indirection t , Type base ) {
150
+ base = t .getBaseType ( ) .getUnspecifiedType ( )
151
+ }
152
+
153
+ /**
154
+ * Holds if `t2` is the same type as `t1`, but after stripping away `result` number
155
+ * of indirections.
156
+ * Furthermore, specifies in `t2` been deeply stripped and typedefs has been resolved.
157
+ */
158
+ private int getNumberOfIndirectionsImpl ( Type t1 , Type t2 ) =
159
+ shortestDistances( isIndirectionType / 1 , hasUnspecifiedBaseType / 2 ) ( t1 , t2 , result )
160
+
147
161
/**
148
162
* An abstract class for handling indirections.
149
163
*
@@ -162,7 +176,10 @@ abstract class Indirection extends Type {
162
176
* For example, the number of indirections of a variable `p` of type
163
177
* `int**` is `3` (i.e., `p`, `*p` and `**p`).
164
178
*/
165
- abstract int getNumberOfIndirections ( ) ;
179
+ final int getNumberOfIndirections ( ) {
180
+ result =
181
+ getNumberOfIndirectionsImpl ( this .getType ( ) , any ( Type end | not end instanceof Indirection ) )
182
+ }
166
183
167
184
/**
168
185
* Holds if `deref` is an instruction that behaves as a `LoadInstruction`
@@ -200,19 +217,11 @@ private class PointerOrArrayOrReferenceTypeIndirection extends Indirection insta
200
217
PointerOrArrayOrReferenceTypeIndirection ( ) {
201
218
baseType = PointerOrArrayOrReferenceType .super .getBaseType ( )
202
219
}
203
-
204
- override int getNumberOfIndirections ( ) {
205
- result = 1 + countIndirections ( this .getBaseType ( ) .getUnspecifiedType ( ) )
206
- }
207
220
}
208
221
209
222
private class PointerWrapperTypeIndirection extends Indirection instanceof PointerWrapper {
210
223
PointerWrapperTypeIndirection ( ) { baseType = PointerWrapper .super .getBaseType ( ) }
211
224
212
- override int getNumberOfIndirections ( ) {
213
- result = 1 + countIndirections ( this .getBaseType ( ) .getUnspecifiedType ( ) )
214
- }
215
-
216
225
override predicate isAdditionalDereference ( Instruction deref , Operand address ) {
217
226
exists ( CallInstruction call |
218
227
operandForFullyConvertedCall ( getAUse ( deref ) , call ) and
@@ -233,10 +242,6 @@ private module IteratorIndirections {
233
242
baseType = super .getValueType ( )
234
243
}
235
244
236
- override int getNumberOfIndirections ( ) {
237
- result = 1 + countIndirections ( this .getBaseType ( ) .getUnspecifiedType ( ) )
238
- }
239
-
240
245
override predicate isAdditionalDereference ( Instruction deref , Operand address ) {
241
246
exists ( CallInstruction call |
242
247
operandForFullyConvertedCall ( getAUse ( deref ) , call ) and
0 commit comments