Skip to content

Commit 4bf41d0

Browse files
committed
C#: Update model generator to exclude models for some collection like types.
1 parent 31dddef commit 4bf41d0

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

csharp/ql/src/utils/model-generator/internal/CaptureModelsSpecific.qll

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,31 @@ predicate asPartialModel = DataFlowPrivate::Csv::asPartialModel/1;
5858

5959
predicate asPartialNegativeModel = DataFlowPrivate::Csv::asPartialNegativeModel/1;
6060

61+
/**
62+
* Holds if `t` is a type that is generally used for bulk data in collection types.
63+
* Eg. char[] is roughly equivalent to string and thus a highly
64+
* relevant type for model generation.
65+
*/
66+
private predicate isPrimitiveTypeUsedForBulkData(CS::Type t) {
67+
t instanceof CS::ByteType or
68+
t instanceof CS::CharType
69+
}
70+
71+
/**
72+
* Holds if the collection type `ct` is irrelevant for model generation.
73+
* Collection types where the type of the elements are
74+
* (1) unknown - are considered relevant.
75+
* (2) known - at least one the child types should be relevant (a non-simple type
76+
* or a type used for bulk data)
77+
*/
78+
private predicate irrelevantCollectionType(CS::Type ct) {
79+
Collections::isCollectionType(ct) and
80+
forex(CS::Type child | child = ct.getAChild() |
81+
child instanceof CS::SimpleType and
82+
not isPrimitiveTypeUsedForBulkData(child)
83+
)
84+
}
85+
6186
/**
6287
* Holds for type `t` for fields that are relevant as an intermediate
6388
* read or write step in the data flow analysis.
@@ -66,7 +91,8 @@ predicate asPartialNegativeModel = DataFlowPrivate::Csv::asPartialNegativeModel/
6691
*/
6792
predicate isRelevantType(CS::Type t) {
6893
not t instanceof CS::SimpleType and
69-
not t instanceof CS::Enum
94+
not t instanceof CS::Enum and
95+
not irrelevantCollectionType(t)
7096
}
7197

7298
/**

0 commit comments

Comments
 (0)