@@ -115,6 +115,12 @@ module QlBuiltinsMocks {
115
115
or
116
116
i = 2 and
117
117
result instanceof EquivalenceRelation:: EquivalenceRelationModule
118
+ or
119
+ i = 3 and
120
+ result instanceof NewEntity:: EntityKeySigClass
121
+ or
122
+ i = 4 and
123
+ result instanceof NewEntity:: NewEntityModule
118
124
}
119
125
}
120
126
@@ -123,15 +129,16 @@ module QlBuiltinsMocks {
123
129
* The equivalent to the following is implemented:
124
130
* ```CodeQL
125
131
* module QlBuiltins {
126
- * signature class T;
127
- * module EdgeSig<T MyT> { // This might not be needed.
128
- * signature predicate edgeSig(MyT a, MyT b);
129
- * }
130
- * module EquivalenceRelation<T MyT, EdgeSig<MyT>::edgeSig/2 edge> { // the `edge` parameter is not modeled
131
- * class EquivalenceClass;
132
- * EquivalenceClass getEquivalenceClass(MyT a);
133
- * }
134
- *}
132
+ * signature class T;
133
+ * module EdgeSig<T MyT> { // This might not be needed.
134
+ * signature predicate edgeSig(MyT a, MyT b);
135
+ * }
136
+ * module EquivalenceRelation<T MyT, EdgeSig<MyT>::edgeSig/2 edge> { // the `edge` parameter is not modeled
137
+ * class EquivalenceClass;
138
+ * EquivalenceClass getEquivalenceClass(MyT a);
139
+ * }
140
+ * }
141
+ * ```
135
142
*/
136
143
module EquivalenceRelation {
137
144
class SigClass extends MockClass:: Range {
@@ -259,4 +266,92 @@ module QlBuiltinsMocks {
259
266
override string getClassName ( ) { result = "EquivalenceClass" }
260
267
}
261
268
}
269
+
270
+ /**
271
+ * A mock that implements the `NewEntity` module.
272
+ * The equivalent to the following is implemented:
273
+ * ```CodeQL
274
+ * class EntityKeySig;
275
+ * module NewEntity<EntityKeySig EntityKey> {
276
+ * class EntityId;
277
+ *
278
+ * EntityId map(EntityKey key) { none() }
279
+ * }
280
+ * ```
281
+ */
282
+ module NewEntity {
283
+ class EntityKeySigClass extends MockClass:: Range {
284
+ EntityKeySigClass ( ) { this = "Mock: QlBuiltins::NewEntity::EntityKeySig" }
285
+
286
+ override string getName ( ) { result = "EntityKeySig" }
287
+ }
288
+
289
+ class NewEntityModule extends MockModule:: Range {
290
+ NewEntityModule ( ) { this = "Mock: QlBuiltins::NewEntity" }
291
+
292
+ override string getName ( ) { result = "NewEntity" }
293
+
294
+ override string getMember ( int i ) {
295
+ i = 0 and result instanceof EntityIdClass
296
+ or
297
+ i = 1 and result instanceof NewEntityMapPredicate
298
+ }
299
+
300
+ /// Holds if the `i`th type parameter has `type` (the ID of the mocked node) with `name`.
301
+ override predicate hasTypeParam ( int i , string type , string name ) {
302
+ i = 0 and
303
+ name = "EntityKey" and
304
+ type instanceof EntityKeySigTypeExpr
305
+ }
306
+ }
307
+
308
+ class EntityKeySigTypeExpr extends MockTypeExpr:: Range {
309
+ EntityKeySigTypeExpr ( ) { this = "Mock: QlBuiltins::NewEntity::EntityKey" }
310
+
311
+ override string getClassName ( ) { result = "EntityKeySig" }
312
+ }
313
+
314
+ class EntityIdClass extends MockClass:: Range {
315
+ EntityIdClass ( ) { this = "Mock: QlBuiltins::NewEntity::EntityId" }
316
+
317
+ override string getName ( ) { result = "EntityId" }
318
+ }
319
+
320
+ class NewEntityMapPredicate extends MockClasslessPredicate:: Range {
321
+ NewEntityMapPredicate ( ) { this = "Mock: QlBuiltins::NewEntity::map" }
322
+
323
+ override string getName ( ) { result = "map" }
324
+
325
+ override string getParameter ( int i ) {
326
+ i = 0 and
327
+ result instanceof NewEntityMapPredicateParam
328
+ }
329
+
330
+ override MockTypeExpr:: Range getReturnTypeExpr ( ) {
331
+ result .( NewEntityMapPredicateTypes ) .getClassName ( ) = "EntityId"
332
+ }
333
+ }
334
+
335
+ // both the TypeExprs used in the `map` predicate.
336
+ class NewEntityMapPredicateTypes extends MockTypeExpr:: Range {
337
+ string type ;
338
+
339
+ NewEntityMapPredicateTypes ( ) {
340
+ type = [ "EntityId" , "EntityKey" ] and
341
+ this = "Mock: QlBuiltins::NewEntity::map::T#" + type
342
+ }
343
+
344
+ override string getClassName ( ) { result = type }
345
+ }
346
+
347
+ class NewEntityMapPredicateParam extends MockVarDecl:: Range {
348
+ NewEntityMapPredicateParam ( ) { this = "Mock: QlBuiltins::NewEntity::map::#0" }
349
+
350
+ override string getName ( ) { result = "key" }
351
+
352
+ override MockTypeExpr:: Range getType ( ) {
353
+ result .( NewEntityMapPredicateTypes ) .getClassName ( ) = "EntityKey"
354
+ }
355
+ }
356
+ }
262
357
}
0 commit comments