@@ -220,41 +220,44 @@ private signature class CallAllocationExprTarget extends Function;
220
220
* function using various heuristics.
221
221
*/
222
222
private module CallAllocationExprBase< CallAllocationExprTarget Target> {
223
- /**
224
- * A signature for a predicate that gets the index of the input pointer argument to
225
- * be reallocated, if this is a `realloc` function.
226
- */
227
- signature int getReallocPtrArgSig ( Target target ) ;
223
+ /** A module that contains the collection of member-predicates required on `Target`. */
224
+ signature module Param {
225
+ /**
226
+ * Gets the index of the input pointer argument to be reallocated, if
227
+ * this is a `realloc` function.
228
+ */
229
+ int getReallocPtrArg ( Target target ) ;
228
230
229
- /**
230
- * A signature for a predicate that gets the index of the argument for the allocation
231
- * size, if any. The actual allocation size is the value of this argument multiplied
232
- * by the result of `getSizeMult()`, in bytes.
233
- */
234
- signature int getSizeArgSig ( Target target ) ;
231
+ /**
232
+ * Gets the index of the argument for the allocation size, if any. The actual
233
+ * allocation size is the value of this argument multiplied by the result of
234
+ * `getSizeMult()`, in bytes.
235
+ */
236
+ int getSizeArg ( Target target ) ;
235
237
236
- /**
237
- * A signature for a predicate that gets the index of an argument that multiplies the
238
- * allocation size given by `getSizeArg`, if any.
239
- */
240
- signature int getSizeMultSig ( Target target ) ;
238
+ /**
239
+ * Gets the index of an argument that multiplies the allocation size given
240
+ * by `getSizeArg`, if any.
241
+ */
242
+ int getSizeMult ( Target target ) ;
241
243
242
- /**
243
- * A signature for a predicate that determines whether or not this allocation requires a
244
- * corresponding deallocation of some sort (most do, but `alloca` for example does not).
245
- * If it is unclear, we default to no (for example a placement `new` allocation may or
246
- * may not require a corresponding `delete`).
247
- */
248
- signature predicate requiresDeallocSig ( Target target ) ;
244
+ /**
245
+ * Holds if this allocation requires a
246
+ * corresponding deallocation of some sort (most do, but `alloca` for example
247
+ * does not). If it is unclear, we default to no (for example a placement `new`
248
+ * allocation may or may not require a corresponding `delete`).
249
+ */
250
+ predicate requiresDealloc ( Target target ) ;
251
+ }
249
252
250
253
/**
251
- * A module that abstracts over the various predicates in a that should really be
252
- * member-predicates of `CallAllocationExprTarget` (which which we cannot yet write in
253
- * QL) .
254
+ * A module that abstracts over a collection of predicates in
255
+ * the `Param` module). This should really be memeber-predicates
256
+ * on `CallAllocationExprTarget`, but we cannot yet write this in QL .
254
257
*/
255
- module With<
256
- getReallocPtrArgSig / 1 getReallocPtrArg , getSizeArgSig / 1 getSizeArg , getSizeMultSig / 1 getSizeMult ,
257
- requiresDeallocSig / 1 requiresDealloc > {
258
+ module With< Param P > {
259
+ private import P
260
+
258
261
/**
259
262
* An allocation expression that is a function call, such as call to `malloc`.
260
263
*/
@@ -313,20 +316,22 @@ private module CallAllocationExprBase<CallAllocationExprTarget Target> {
313
316
}
314
317
315
318
private module CallAllocationExpr {
316
- private int getReallocPtrArg ( AllocationFunction f ) { result = f .getReallocPtrArg ( ) }
319
+ private module Param implements CallAllocationExprBase< AllocationFunction > :: Param {
320
+ int getReallocPtrArg ( AllocationFunction f ) { result = f .getReallocPtrArg ( ) }
317
321
318
- private int getSizeArg ( AllocationFunction f ) { result = f .getSizeArg ( ) }
322
+ int getSizeArg ( AllocationFunction f ) { result = f .getSizeArg ( ) }
319
323
320
- private int getSizeMult ( AllocationFunction f ) { result = f .getSizeMult ( ) }
324
+ int getSizeMult ( AllocationFunction f ) { result = f .getSizeMult ( ) }
321
325
322
- private predicate requiresDealloc ( AllocationFunction f ) { f .requiresDealloc ( ) }
326
+ predicate requiresDealloc ( AllocationFunction f ) { f .requiresDealloc ( ) }
327
+ }
323
328
324
329
/**
325
330
* A class that provides the implementation of `AllocationExpr` for an allocation
326
331
* that calls an `AllocationFunction`.
327
332
*/
328
333
private class Base =
329
- CallAllocationExprBase< AllocationFunction > :: With< getReallocPtrArg / 1 , getSizeArg / 1 , getSizeMult / 1 , requiresDealloc / 1 > :: CallAllocationExprImpl ;
334
+ CallAllocationExprBase< AllocationFunction > :: With< Param > :: CallAllocationExprImpl ;
330
335
331
336
class CallAllocationExpr extends AllocationExpr , Base {
332
337
override Expr getSizeExpr ( ) { result = super .getSizeExprImpl ( ) }
@@ -444,20 +449,22 @@ private module HeuristicAllocation {
444
449
override predicate requiresDealloc ( ) { none ( ) }
445
450
}
446
451
447
- private int getReallocPtrArg ( HeuristicAllocationFunction f ) { result = f .getReallocPtrArg ( ) }
452
+ private module Param implements CallAllocationExprBase< HeuristicAllocationFunction > :: Param {
453
+ int getReallocPtrArg ( HeuristicAllocationFunction f ) { result = f .getReallocPtrArg ( ) }
448
454
449
- private int getSizeArg ( HeuristicAllocationFunction f ) { result = f .getSizeArg ( ) }
455
+ int getSizeArg ( HeuristicAllocationFunction f ) { result = f .getSizeArg ( ) }
450
456
451
- private int getSizeMult ( HeuristicAllocationFunction f ) { result = f .getSizeMult ( ) }
457
+ int getSizeMult ( HeuristicAllocationFunction f ) { result = f .getSizeMult ( ) }
452
458
453
- private predicate requiresDealloc ( HeuristicAllocationFunction f ) { f .requiresDealloc ( ) }
459
+ predicate requiresDealloc ( HeuristicAllocationFunction f ) { f .requiresDealloc ( ) }
460
+ }
454
461
455
462
/**
456
463
* A class that provides the implementation of `AllocationExpr` for an allocation
457
464
* that calls an `HeuristicAllocationFunction`.
458
465
*/
459
466
private class Base =
460
- CallAllocationExprBase< HeuristicAllocationFunction > :: With< getReallocPtrArg / 1 , getSizeArg / 1 , getSizeMult / 1 , requiresDealloc / 1 > :: CallAllocationExprImpl ;
467
+ CallAllocationExprBase< HeuristicAllocationFunction > :: With< Param > :: CallAllocationExprImpl ;
461
468
462
469
private class CallAllocationExpr extends HeuristicAllocationExpr , Base {
463
470
override Expr getSizeExpr ( ) { result = super .getSizeExprImpl ( ) }
0 commit comments