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