@@ -7,7 +7,6 @@ import Location
7
7
import Namespace
8
8
import Property
9
9
private import Conversion
10
- private import dotnet
11
10
private import semmle.code.csharp.metrics.Coupling
12
11
private import TypeRef
13
12
private import semmle.code.csharp.frameworks.System
@@ -20,7 +19,10 @@ private import semmle.code.csharp.frameworks.system.runtime.CompilerServices
20
19
* a pointer type (`PointerType`), the arglist type (`ArglistType`), an unknown
21
20
* type (`UnknownType`), or a type parameter (`TypeParameter`).
22
21
*/
23
- class Type extends DotNet:: Type , Member , TypeContainer , @type {
22
+ class Type extends Member , TypeContainer , @type {
23
+ /** Gets the name of this type without additional syntax such as `[]` or `*`. */
24
+ override string getUndecoratedName ( ) { none ( ) }
25
+
24
26
override string getName ( ) { types ( this , _, result ) }
25
27
26
28
override Type getUnboundDeclaration ( ) { result = this }
@@ -56,15 +58,16 @@ private predicate isObjectClass(Class c) { c instanceof ObjectType }
56
58
*
57
59
* Either a value type (`ValueType`) or a reference type (`RefType`).
58
60
*/
59
- class ValueOrRefType extends DotNet :: ValueOrRefType , Type , Attributable , @value_or_ref_type {
61
+ class ValueOrRefType extends Type , Attributable , @value_or_ref_type {
60
62
/** Gets the namespace containing this type. */
61
63
Namespace getNamespace ( ) {
62
64
if exists ( this .getDeclaringType ( ) )
63
65
then result = this .getDeclaringType ( ) .getNamespace ( )
64
66
else result .getATypeDeclaration ( ) = this
65
67
}
66
68
67
- override Namespace getDeclaringNamespace ( ) { this = result .getATypeDeclaration ( ) }
69
+ /** Gets the namespace declaring this type, if any. */
70
+ Namespace getDeclaringNamespace ( ) { this = result .getATypeDeclaration ( ) }
68
71
69
72
override ValueOrRefType getDeclaringType ( ) { none ( ) }
70
73
@@ -73,6 +76,30 @@ class ValueOrRefType extends DotNet::ValueOrRefType, Type, Attributable, @value_
73
76
/** Gets a nested child type, if any. */
74
77
NestedType getAChildType ( ) { nested_types ( result , this , _) }
75
78
79
+ private string getPrefixWithTypes ( ) {
80
+ result = this .getDeclaringType ( ) .getLabel ( ) + "."
81
+ or
82
+ if this .getDeclaringNamespace ( ) .isGlobalNamespace ( )
83
+ then result = ""
84
+ else result = this .getDeclaringNamespace ( ) .getFullName ( ) + "."
85
+ }
86
+
87
+ pragma [ noinline]
88
+ private string getLabelNonGeneric ( ) {
89
+ not this instanceof Generic and
90
+ result = this .getPrefixWithTypes ( ) + this .getUndecoratedName ( )
91
+ }
92
+
93
+ pragma [ noinline]
94
+ private string getLabelGeneric ( ) {
95
+ result = this .getPrefixWithTypes ( ) + this .getUndecoratedName ( ) + getGenericsLabel ( this )
96
+ }
97
+
98
+ override string getLabel ( ) {
99
+ result = this .getLabelNonGeneric ( ) or
100
+ result = this .getLabelGeneric ( )
101
+ }
102
+
76
103
/**
77
104
* Gets the source namespace declaration in which this type is declared, if any.
78
105
* This only holds for non-nested types.
@@ -120,7 +147,7 @@ class ValueOrRefType extends DotNet::ValueOrRefType, Type, Attributable, @value_
120
147
}
121
148
122
149
/** Gets an immediate base type of this type, if any. */
123
- override ValueOrRefType getABaseType ( ) {
150
+ ValueOrRefType getABaseType ( ) {
124
151
result = this .getBaseClass ( ) or
125
152
result = this .getABaseInterface ( )
126
153
}
@@ -360,7 +387,8 @@ class ValueOrRefType extends DotNet::ValueOrRefType, Type, Attributable, @value_
360
387
nested_types ( this , _, result )
361
388
}
362
389
363
- override predicate isRecord ( ) { this .hasModifier ( "record" ) }
390
+ /** Holds if this type is a `record`. */
391
+ predicate isRecord ( ) { this .hasModifier ( "record" ) }
364
392
365
393
override string toString ( ) { result = Type .super .toString ( ) }
366
394
}
@@ -1064,7 +1092,7 @@ class InlineArrayType extends ValueType, @inline_array_type {
1064
1092
/**
1065
1093
* An array type, for example `int[]`.
1066
1094
*/
1067
- class ArrayType extends DotNet :: ArrayType , RefType , @array_type {
1095
+ class ArrayType extends RefType , @array_type {
1068
1096
/**
1069
1097
* Gets the dimension of this array type. For example `int[][]` is of
1070
1098
* dimension 2, while `int[]` is of dimension 1.
@@ -1081,13 +1109,15 @@ class ArrayType extends DotNet::ArrayType, RefType, @array_type {
1081
1109
predicate isMultiDimensional ( ) { this .getRank ( ) > 1 }
1082
1110
1083
1111
/** Gets the element type of this array, for example `int` in `int[]`. */
1084
- override Type getElementType ( ) {
1112
+ Type getElementType ( ) {
1085
1113
array_element_type ( this , _, _, result )
1086
1114
or
1087
1115
not array_element_type ( this , _, _, any ( Type t ) ) and
1088
1116
array_element_type ( this , _, _, getTypeRef ( result ) )
1089
1117
}
1090
1118
1119
+ final override string getLabel ( ) { result = this .getElementType ( ) .getLabel ( ) + "[]" }
1120
+
1091
1121
/** Holds if this array type has the same shape (dimension and rank) as `that` array type. */
1092
1122
predicate hasSameShapeAs ( ArrayType that ) {
1093
1123
this .getDimension ( ) = that .getDimension ( ) and
@@ -1128,33 +1158,36 @@ class ArrayType extends DotNet::ArrayType, RefType, @array_type {
1128
1158
not type_location ( this , _) and
1129
1159
result = this .getElementType ( ) .getALocation ( )
1130
1160
}
1161
+
1162
+ override string getAPrimaryQlClass ( ) { result = "ArrayType" }
1131
1163
}
1132
1164
1133
1165
/**
1134
1166
* A pointer type, for example `char*`.
1135
1167
*/
1136
- class PointerType extends DotNet:: PointerType , Type , @pointer_type {
1137
- override Type getReferentType ( ) {
1168
+ class PointerType extends Type , @pointer_type {
1169
+ /** Gets the type referred by this pointer type, for example `char` in `char*`. */
1170
+ Type getReferentType ( ) {
1138
1171
pointer_referent_type ( this , result )
1139
1172
or
1140
1173
not pointer_referent_type ( this , any ( Type t ) ) and
1141
1174
pointer_referent_type ( this , getTypeRef ( result ) )
1142
1175
}
1143
1176
1144
- override string toStringWithTypes ( ) { result = DotNet :: PointerType . super .toStringWithTypes ( ) }
1177
+ override string toStringWithTypes ( ) { result = this . getReferentType ( ) .toStringWithTypes ( ) + "*" }
1145
1178
1146
1179
override Type getChild ( int n ) { result = this .getReferentType ( ) and n = 0 }
1147
1180
1148
1181
final override string getName ( ) { types ( this , _, result ) }
1149
1182
1183
+ final override string getLabel ( ) { result = this .getReferentType ( ) .getLabel ( ) + "*" }
1184
+
1150
1185
final override string getUndecoratedName ( ) {
1151
1186
result = this .getReferentType ( ) .getUndecoratedName ( )
1152
1187
}
1153
1188
1154
1189
override Location getALocation ( ) { result = this .getReferentType ( ) .getALocation ( ) }
1155
1190
1156
- override string toString ( ) { result = DotNet:: PointerType .super .toString ( ) }
1157
-
1158
1191
override string getAPrimaryQlClass ( ) { result = "PointerType" }
1159
1192
}
1160
1193
0 commit comments