12
12
*/
13
13
14
14
import csharp
15
+ private import semmle.code.csharp.frameworks.System
16
+ private import semmle.code.dotnet.DotNet as DotNet
15
17
16
18
/** An element that should be in the generated code. */
17
19
abstract class GeneratedElement extends Element { }
18
20
19
21
/** A member that should be in the generated code. */
20
22
abstract class GeneratedMember extends Member , GeneratedElement { }
21
23
24
+ /** Class representing all `struct`s, such as user defined ones and built-in ones, like `int`. */
25
+ private class StructEx extends Type {
26
+ StructEx ( ) {
27
+ this instanceof Struct or
28
+ this instanceof SimpleType or
29
+ this instanceof VoidType or
30
+ this instanceof SystemIntPtrType
31
+ }
32
+ }
33
+
22
34
/** A type that should be in the generated code. */
23
- abstract private class GeneratedType extends ValueOrRefType , GeneratedElement {
35
+ abstract private class GeneratedType extends Type , GeneratedElement {
24
36
GeneratedType ( ) {
25
37
(
26
38
this instanceof Interface
27
39
or
28
40
this instanceof Class
29
41
or
30
- this instanceof Struct
42
+ this instanceof StructEx
31
43
or
32
44
this instanceof Enum
33
45
or
@@ -53,7 +65,7 @@ abstract private class GeneratedType extends ValueOrRefType, GeneratedElement {
53
65
private string stubKeyword ( ) {
54
66
this instanceof Interface and result = "interface"
55
67
or
56
- this instanceof Struct and result = "struct"
68
+ this instanceof StructEx and result = "struct"
57
69
or
58
70
this instanceof Class and result = "class"
59
71
or
@@ -79,7 +91,7 @@ abstract private class GeneratedType extends ValueOrRefType, GeneratedElement {
79
91
}
80
92
81
93
private string stubAttributes ( ) {
82
- if this .getAnAttribute ( ) .getType ( ) .getQualifiedName ( ) = "System.FlagsAttribute"
94
+ if this .( ValueOrRefType ) . getAnAttribute ( ) .getType ( ) .getQualifiedName ( ) = "System.FlagsAttribute"
83
95
then result = "[System.Flags]\n"
84
96
else result = ""
85
97
}
@@ -112,7 +124,7 @@ abstract private class GeneratedType extends ValueOrRefType, GeneratedElement {
112
124
}
113
125
114
126
private ValueOrRefType getAnInterestingBaseType ( ) {
115
- result = this .getABaseType ( ) and
127
+ result = this .( ValueOrRefType ) . getABaseType ( ) and
116
128
not result instanceof ObjectType and
117
129
not result .getQualifiedName ( ) = "System.ValueType" and
118
130
( not result instanceof Interface or result .( Interface ) .isEffectivelyPublic ( ) )
@@ -171,9 +183,9 @@ abstract class GeneratedDeclaration extends Modifiable {
171
183
172
184
private class IndirectType extends GeneratedType {
173
185
IndirectType ( ) {
174
- this .getASubType ( ) instanceof GeneratedType
186
+ this .( ValueOrRefType ) . getASubType ( ) instanceof GeneratedType
175
187
or
176
- this .getAChildType ( ) instanceof GeneratedType
188
+ this .( ValueOrRefType ) . getAChildType ( ) instanceof GeneratedType
177
189
or
178
190
this .( UnboundGenericType ) .getAConstructedGeneric ( ) .getASubType ( ) instanceof GeneratedType
179
191
or
@@ -273,7 +285,8 @@ private class GeneratedNamespace extends Namespace, GeneratedElement {
273
285
}
274
286
275
287
private predicate isInAssembly ( Assembly assembly ) {
276
- any ( GeneratedType gt | gt .getDeclaringNamespace ( ) = this ) .isInAssembly ( assembly )
288
+ any ( GeneratedType gt | gt .( DotNet:: ValueOrRefType ) .getDeclaringNamespace ( ) = this )
289
+ .isInAssembly ( assembly )
277
290
or
278
291
this .getChildNamespace ( _) .isInAssembly ( assembly )
279
292
}
@@ -293,7 +306,7 @@ private class GeneratedNamespace extends Namespace, GeneratedElement {
293
306
this .isInAssembly ( assembly ) and
294
307
result =
295
308
concat ( GeneratedType gt |
296
- gt .getDeclaringNamespace ( ) = this and gt .isInAssembly ( assembly )
309
+ gt .( DotNet :: ValueOrRefType ) . getDeclaringNamespace ( ) = this and gt .isInAssembly ( assembly )
297
310
|
298
311
gt .getStub ( assembly ) order by gt .getName ( )
299
312
)
@@ -454,7 +467,7 @@ private string stubClassName(Type t) {
454
467
}
455
468
456
469
language [ monotonicAggregates]
457
- private string stubGenericArguments ( ValueOrRefType t ) {
470
+ private string stubGenericArguments ( Type t ) {
458
471
if t instanceof UnboundGenericType
459
472
then
460
473
result =
@@ -730,7 +743,7 @@ private string stubMember(Member m, Assembly assembly) {
730
743
if
731
744
not m .getDeclaringType ( ) instanceof Enum and
732
745
(
733
- not m .getDeclaringType ( ) instanceof Struct or
746
+ not m .getDeclaringType ( ) instanceof StructEx or
734
747
m .( Constructor ) .getNumberOfParameters ( ) > 0
735
748
)
736
749
then
0 commit comments