@@ -1022,8 +1022,8 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1022
1022
}
1023
1023
}
1024
1024
1025
- /** Provides the input to `MatchingWithState `. */
1026
- signature module MatchingWithStateInputSig {
1025
+ /** Provides the input to `MatchingWithEnvironment `. */
1026
+ signature module MatchingWithEnvironmentInputSig {
1027
1027
/**
1028
1028
* A position inside a declaration. For example, the integer position of a
1029
1029
* parameter inside a method or the return type of a method.
@@ -1068,10 +1068,10 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1068
1068
string toString ( ) ;
1069
1069
}
1070
1070
1071
- /** A state to track during type matching. */
1071
+ /** An environment to track during type matching. */
1072
1072
bindingset [ this ]
1073
- class State {
1074
- /** Gets a textual representation of this state . */
1073
+ class Environment {
1074
+ /** Gets a textual representation of this environment . */
1075
1075
bindingset [ this ]
1076
1076
string toString ( ) ;
1077
1077
}
@@ -1094,17 +1094,17 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1094
1094
Type getTypeArgument ( TypeArgumentPosition tapos , TypePath path ) ;
1095
1095
1096
1096
/**
1097
- * Gets the inferred type at `path` for the position `apos` and state `state `
1097
+ * Gets the inferred type at `path` for the position `apos` and environment `e `
1098
1098
* of this access.
1099
1099
*
1100
1100
* For example, if this access is the method call `M(42)`, then the inferred
1101
1101
* type at argument position `0` is `int`.
1102
1102
*/
1103
- bindingset [ state ]
1104
- Type getInferredType ( State state , AccessPosition apos , TypePath path ) ;
1103
+ bindingset [ e ]
1104
+ Type getInferredType ( Environment e , AccessPosition apos , TypePath path ) ;
1105
1105
1106
- /** Gets the declaration that this access targets in `state `. */
1107
- Declaration getTarget ( State state ) ;
1106
+ /** Gets the declaration that this access targets in environment `e `. */
1107
+ Declaration getTarget ( Environment e ) ;
1108
1108
}
1109
1109
1110
1110
/** Holds if `apos` and `dpos` match. */
@@ -1142,20 +1142,20 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1142
1142
*
1143
1143
* Matching takes both base types and explicit type arguments into account.
1144
1144
*/
1145
- module MatchingWithState < MatchingWithStateInputSig Input> {
1145
+ module MatchingWithEnvironment < MatchingWithEnvironmentInputSig Input> {
1146
1146
private import Input
1147
1147
1148
1148
/**
1149
- * Holds if `a` targets `target` in `state ` and the type for `apos` at `path`
1149
+ * Holds if `a` targets `target` in environment `e ` and the type for `apos` at `path`
1150
1150
* in `a` is `t` after adjustment by `target`.
1151
1151
*/
1152
1152
pragma [ nomagic]
1153
1153
private predicate adjustedAccessType (
1154
- Access a , State state , AccessPosition apos , Declaration target , TypePath path , Type t
1154
+ Access a , Environment e , AccessPosition apos , Declaration target , TypePath path , Type t
1155
1155
) {
1156
- target = a .getTarget ( state ) and
1156
+ target = a .getTarget ( e ) and
1157
1157
exists ( TypePath path0 , Type t0 |
1158
- t0 = a .getInferredType ( state , apos , path0 ) and
1158
+ t0 = a .getInferredType ( e , apos , path0 ) and
1159
1159
adjustAccessType ( apos , target , path0 , t0 , path , t )
1160
1160
)
1161
1161
}
@@ -1179,50 +1179,51 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1179
1179
}
1180
1180
1181
1181
/**
1182
- * Holds if the type `t` at `path` of `a` in `state ` matches the type parameter `tp`
1183
- * of `target`.
1182
+ * Holds if the type `t` at `path` of `a` in environment `e ` matches the type
1183
+ * parameter `tp` of `target`.
1184
1184
*/
1185
1185
pragma [ nomagic]
1186
1186
private predicate directTypeMatch (
1187
- Access a , State state , Declaration target , TypePath path , Type t , TypeParameter tp
1187
+ Access a , Environment e , Declaration target , TypePath path , Type t , TypeParameter tp
1188
1188
) {
1189
1189
not exists ( getTypeArgument ( a , target , tp , _) ) and
1190
1190
exists ( AccessPosition apos , DeclarationPosition dpos , TypePath pathToTypeParam |
1191
1191
tp = target .getDeclaredType ( dpos , pathToTypeParam ) and
1192
1192
accessDeclarationPositionMatch ( apos , dpos ) and
1193
- adjustedAccessType ( a , state , apos , target , pathToTypeParam .appendInverse ( path ) , t )
1193
+ adjustedAccessType ( a , e , apos , target , pathToTypeParam .appendInverse ( path ) , t )
1194
1194
)
1195
1195
}
1196
1196
1197
1197
private module AccessBaseType {
1198
1198
/**
1199
- * Holds if inferring types at `a` in `state ` might depend on the type at
1199
+ * Holds if inferring types at `a` in environment `e ` might depend on the type at
1200
1200
* `path` of `apos` having `base` as a transitive base type.
1201
1201
*/
1202
- private predicate relevantAccess ( Access a , State state , AccessPosition apos , Type base ) {
1202
+ private predicate relevantAccess ( Access a , Environment e , AccessPosition apos , Type base ) {
1203
1203
exists ( Declaration target , DeclarationPosition dpos |
1204
- adjustedAccessType ( a , state , apos , target , _, _) and
1204
+ adjustedAccessType ( a , e , apos , target , _, _) and
1205
1205
accessDeclarationPositionMatch ( apos , dpos ) and
1206
1206
declarationBaseType ( target , dpos , base , _, _)
1207
1207
)
1208
1208
}
1209
1209
1210
1210
pragma [ nomagic]
1211
1211
private Type inferTypeAt (
1212
- Access a , State state , AccessPosition apos , TypeParameter tp , TypePath suffix
1212
+ Access a , Environment e , AccessPosition apos , TypeParameter tp , TypePath suffix
1213
1213
) {
1214
- relevantAccess ( a , state , apos , _) and
1214
+ relevantAccess ( a , e , apos , _) and
1215
1215
exists ( TypePath path0 |
1216
- result = a .getInferredType ( state , apos , path0 ) and
1216
+ result = a .getInferredType ( e , apos , path0 ) and
1217
1217
path0 .isCons ( tp , suffix )
1218
1218
)
1219
1219
}
1220
1220
1221
1221
/**
1222
1222
* Holds if `baseMention` is a (transitive) base type mention of the
1223
- * type of `a` at position `apos` at path `pathToSub` in `state`, and
1224
- * `t` is mentioned (implicitly) at `path` inside `base`. For example,
1225
- * in
1223
+ * type of `a` at position `apos` at path `pathToSub` in environment
1224
+ * `e`, and `t` is mentioned (implicitly) at `path` inside `base`.
1225
+ *
1226
+ * For example, in
1226
1227
*
1227
1228
* ```csharp
1228
1229
* class C<T1> { }
@@ -1251,15 +1252,16 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1251
1252
* `Base<C<T3>>` | `"T2.T1.T1"` | `int`
1252
1253
*/
1253
1254
predicate hasBaseTypeMention (
1254
- Access a , State state , AccessPosition apos , TypeMention baseMention , TypePath path , Type t
1255
+ Access a , Environment e , AccessPosition apos , TypeMention baseMention , TypePath path ,
1256
+ Type t
1255
1257
) {
1256
- relevantAccess ( a , state , apos , resolveTypeMentionRoot ( baseMention ) ) and
1257
- exists ( Type sub | sub = a .getInferredType ( state , apos , TypePath:: nil ( ) ) |
1258
+ relevantAccess ( a , e , apos , resolveTypeMentionRoot ( baseMention ) ) and
1259
+ exists ( Type sub | sub = a .getInferredType ( e , apos , TypePath:: nil ( ) ) |
1258
1260
baseTypeMentionHasNonTypeParameterAt ( sub , baseMention , path , t )
1259
1261
or
1260
1262
exists ( TypePath prefix , TypePath suffix , TypeParameter tp |
1261
1263
baseTypeMentionHasTypeParameterAt ( sub , baseMention , prefix , tp ) and
1262
- t = inferTypeAt ( a , state , apos , tp , suffix ) and
1264
+ t = inferTypeAt ( a , e , apos , tp , suffix ) and
1263
1265
path = prefix .append ( suffix )
1264
1266
)
1265
1267
)
@@ -1268,39 +1270,39 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1268
1270
1269
1271
private module AccessConstraint {
1270
1272
predicate relevantAccessConstraint (
1271
- Access a , State state , Declaration target , AccessPosition apos , TypePath path ,
1273
+ Access a , Environment e , Declaration target , AccessPosition apos , TypePath path ,
1272
1274
Type constraint
1273
1275
) {
1274
- target = a .getTarget ( state ) and
1276
+ target = a .getTarget ( e ) and
1275
1277
typeParameterConstraintHasTypeParameter ( target , apos , path , constraint , _, _)
1276
1278
}
1277
1279
1278
1280
private newtype TRelevantAccess =
1279
1281
MkRelevantAccess (
1280
- Access a , State state , Declaration target , AccessPosition apos , TypePath path
1282
+ Access a , Environment e , Declaration target , AccessPosition apos , TypePath path
1281
1283
) {
1282
- relevantAccessConstraint ( a , state , target , apos , path , _)
1284
+ relevantAccessConstraint ( a , e , target , apos , path , _)
1283
1285
}
1284
1286
1285
1287
/**
1286
- * If the access `a` for `apos`, `state `, and `path` has an inferred type
1288
+ * If the access `a` for `apos`, environment `e `, and `path` has an inferred type
1287
1289
* which type inference requires to satisfy some constraint.
1288
1290
*/
1289
1291
private class RelevantAccess extends MkRelevantAccess {
1290
1292
Access a ;
1291
- State state ;
1293
+ Environment e ;
1292
1294
Declaration target ;
1293
1295
AccessPosition apos ;
1294
1296
TypePath path ;
1295
1297
1296
- RelevantAccess ( ) { this = MkRelevantAccess ( a , state , target , apos , path ) }
1298
+ RelevantAccess ( ) { this = MkRelevantAccess ( a , e , target , apos , path ) }
1297
1299
1298
1300
Type getTypeAt ( TypePath suffix ) {
1299
- adjustedAccessType ( a , state , apos , target , path .appendInverse ( suffix ) , result )
1301
+ adjustedAccessType ( a , e , apos , target , path .appendInverse ( suffix ) , result )
1300
1302
}
1301
1303
1302
1304
/** Holds if this relevant access should satisfy `constraint`. */
1303
- Type getConstraint ( ) { relevantAccessConstraint ( a , state , target , apos , path , result ) }
1305
+ Type getConstraint ( ) { relevantAccessConstraint ( a , e , target , apos , path , result ) }
1304
1306
1305
1307
string toString ( ) {
1306
1308
result = a .toString ( ) + ", " + apos .toString ( ) + ", " + path .toString ( )
@@ -1318,24 +1320,24 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1318
1320
}
1319
1321
1320
1322
predicate satisfiesConstraintType (
1321
- Access a , State state , Declaration target , AccessPosition apos , TypePath prefix ,
1323
+ Access a , Environment e , Declaration target , AccessPosition apos , TypePath prefix ,
1322
1324
Type constraint , TypePath path , Type t
1323
1325
) {
1324
1326
SatisfiesConstraint< RelevantAccess , SatisfiesConstraintInput > :: satisfiesConstraintType ( MkRelevantAccess ( a ,
1325
- state , target , apos , prefix ) , constraint , path , t )
1327
+ e , target , apos , prefix ) , constraint , path , t )
1326
1328
}
1327
1329
}
1328
1330
1329
1331
/**
1330
- * Holds if the type of `a` at `apos` in `state ` has the base type `base`,
1332
+ * Holds if the type of `a` at `apos` in environment `e ` has the base type `base`,
1331
1333
* and when viewed as an element of that type has the type `t` at `path`.
1332
1334
*/
1333
1335
pragma [ nomagic]
1334
1336
private predicate accessBaseType (
1335
- Access a , State state , AccessPosition apos , Type base , TypePath path , Type t
1337
+ Access a , Environment e , AccessPosition apos , Type base , TypePath path , Type t
1336
1338
) {
1337
1339
exists ( TypeMention tm |
1338
- AccessBaseType:: hasBaseTypeMention ( a , state , apos , tm , path , t ) and
1340
+ AccessBaseType:: hasBaseTypeMention ( a , e , apos , tm , path , t ) and
1339
1341
base = resolveTypeMentionRoot ( tm )
1340
1342
)
1341
1343
}
@@ -1353,8 +1355,8 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1353
1355
}
1354
1356
1355
1357
/**
1356
- * Holds if the (transitive) base type `t` at `path` of `a` in `state` for
1357
- * some `AccessPosition` matches the type parameter `tp`, which is used in
1358
+ * Holds if the (transitive) base type `t` at `path` of `a` in environment `e`
1359
+ * for some `AccessPosition` matches the type parameter `tp`, which is used in
1358
1360
* the declared types of `target`.
1359
1361
*
1360
1362
* For example, in
@@ -1386,27 +1388,27 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1386
1388
*/
1387
1389
pragma [ nomagic]
1388
1390
private predicate baseTypeMatch (
1389
- Access a , State state , Declaration target , TypePath path , Type t , TypeParameter tp
1391
+ Access a , Environment e , Declaration target , TypePath path , Type t , TypeParameter tp
1390
1392
) {
1391
1393
not exists ( getTypeArgument ( a , target , tp , _) ) and
1392
- target = a .getTarget ( state ) and
1394
+ target = a .getTarget ( e ) and
1393
1395
exists ( AccessPosition apos , DeclarationPosition dpos , Type base , TypePath pathToTypeParam |
1394
- accessBaseType ( a , state , apos , base , pathToTypeParam .appendInverse ( path ) , t ) and
1396
+ accessBaseType ( a , e , apos , base , pathToTypeParam .appendInverse ( path ) , t ) and
1395
1397
declarationBaseType ( target , dpos , base , pathToTypeParam , tp ) and
1396
1398
accessDeclarationPositionMatch ( apos , dpos )
1397
1399
)
1398
1400
}
1399
1401
1400
1402
/**
1401
- * Holds if for `a` and corresponding `target` in `state `, the type parameter
1403
+ * Holds if for `a` and corresponding `target` in environment `e `, the type parameter
1402
1404
* `tp` is matched by a type argument at the access with type `t` and type path
1403
1405
* `path`.
1404
1406
*/
1405
1407
pragma [ nomagic]
1406
1408
private predicate explicitTypeMatch (
1407
- Access a , State state , Declaration target , TypePath path , Type t , TypeParameter tp
1409
+ Access a , Environment e , Declaration target , TypePath path , Type t , TypeParameter tp
1408
1410
) {
1409
- target = a .getTarget ( state ) and
1411
+ target = a .getTarget ( e ) and
1410
1412
t = getTypeArgument ( a , target , tp , path )
1411
1413
}
1412
1414
@@ -1448,36 +1450,36 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1448
1450
1449
1451
pragma [ nomagic]
1450
1452
private predicate typeConstraintBaseTypeMatch (
1451
- Access a , State state , Declaration target , TypePath path , Type t , TypeParameter tp
1453
+ Access a , Environment e , Declaration target , TypePath path , Type t , TypeParameter tp
1452
1454
) {
1453
1455
not exists ( getTypeArgument ( a , target , tp , _) ) and
1454
1456
exists ( Type constraint , AccessPosition apos , TypePath pathToTp , TypePath pathToTp2 |
1455
1457
typeParameterConstraintHasTypeParameter ( target , apos , pathToTp2 , constraint , pathToTp , tp ) and
1456
- AccessConstraint:: satisfiesConstraintType ( a , state , target , apos , pathToTp2 , constraint ,
1458
+ AccessConstraint:: satisfiesConstraintType ( a , e , target , apos , pathToTp2 , constraint ,
1457
1459
pathToTp .appendInverse ( path ) , t )
1458
1460
)
1459
1461
}
1460
1462
1461
1463
pragma [ inline]
1462
1464
private predicate typeMatch (
1463
- Access a , State state , Declaration target , TypePath path , Type t , TypeParameter tp
1465
+ Access a , Environment e , Declaration target , TypePath path , Type t , TypeParameter tp
1464
1466
) {
1465
1467
// A type given at the access corresponds directly to the type parameter
1466
1468
// at the target.
1467
- explicitTypeMatch ( a , state , target , path , t , tp )
1469
+ explicitTypeMatch ( a , e , target , path , t , tp )
1468
1470
or
1469
1471
// We can infer the type of `tp` from one of the access positions
1470
- directTypeMatch ( a , state , target , path , t , tp )
1472
+ directTypeMatch ( a , e , target , path , t , tp )
1471
1473
or
1472
1474
// We can infer the type of `tp` by going up the type hiearchy
1473
- baseTypeMatch ( a , state , target , path , t , tp )
1475
+ baseTypeMatch ( a , e , target , path , t , tp )
1474
1476
or
1475
1477
// We can infer the type of `tp` by a type constraint
1476
- typeConstraintBaseTypeMatch ( a , state , target , path , t , tp )
1478
+ typeConstraintBaseTypeMatch ( a , e , target , path , t , tp )
1477
1479
}
1478
1480
1479
1481
/**
1480
- * Gets the inferred type of `a` at `path` for position `apos` and state `state `.
1482
+ * Gets the inferred type of `a` at `path` for position `apos` and environment `e `.
1481
1483
*
1482
1484
* For example, in
1483
1485
*
@@ -1515,19 +1517,19 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1515
1517
* `"T2.T1.T1"` | `int`
1516
1518
*/
1517
1519
pragma [ nomagic]
1518
- Type inferAccessType ( Access a , State state , AccessPosition apos , TypePath path ) {
1520
+ Type inferAccessType ( Access a , Environment e , AccessPosition apos , TypePath path ) {
1519
1521
exists ( DeclarationPosition dpos | accessDeclarationPositionMatch ( apos , dpos ) |
1520
1522
// A suffix of `path` leads to a type parameter in the target
1521
1523
exists ( Declaration target , TypePath prefix , TypeParameter tp , TypePath suffix |
1522
1524
tp = target .getDeclaredType ( dpos , prefix ) and
1523
1525
path = prefix .append ( suffix ) and
1524
- typeMatch ( a , state , target , suffix , result , tp )
1526
+ typeMatch ( a , e , target , suffix , result , tp )
1525
1527
)
1526
1528
or
1527
1529
// `path` corresponds directly to a concrete type in the declaration
1528
1530
exists ( Declaration target |
1529
1531
result = target .getDeclaredType ( dpos , path ) and
1530
- target = a .getTarget ( state ) and
1532
+ target = a .getTarget ( e ) and
1531
1533
not result instanceof TypeParameter
1532
1534
)
1533
1535
)
@@ -1645,30 +1647,30 @@ module Make1<LocationSig Location, InputSig1<Location> Input1> {
1645
1647
* Matching takes both base types and explicit type arguments into account.
1646
1648
*/
1647
1649
module Matching< MatchingInputSig Input> {
1648
- private module Inp implements MatchingWithStateInputSig {
1650
+ private module Inp implements MatchingWithEnvironmentInputSig {
1649
1651
private import codeql.util.Unit
1650
1652
import Input
1651
1653
1652
1654
predicate adjustAccessType = Input:: adjustAccessType / 6 ;
1653
1655
1654
- class State = Unit ;
1656
+ class Environment = Unit ;
1655
1657
1656
1658
final private class AccessFinal = Input:: Access ;
1657
1659
1658
1660
class Access extends AccessFinal {
1659
- Type getInferredType ( State state , AccessPosition apos , TypePath path ) {
1660
- exists ( state ) and
1661
+ Type getInferredType ( Environment e , AccessPosition apos , TypePath path ) {
1662
+ exists ( e ) and
1661
1663
result = super .getInferredType ( apos , path )
1662
1664
}
1663
1665
1664
- Declaration getTarget ( State state ) {
1665
- exists ( state ) and
1666
+ Declaration getTarget ( Environment e ) {
1667
+ exists ( e ) and
1666
1668
result = super .getTarget ( )
1667
1669
}
1668
1670
}
1669
1671
}
1670
1672
1671
- private module M = MatchingWithState < Inp > ;
1673
+ private module M = MatchingWithEnvironment < Inp > ;
1672
1674
1673
1675
import M
1674
1676
0 commit comments