Skip to content

Commit 918340d

Browse files
committed
temp
1 parent 4237e12 commit 918340d

File tree

5 files changed

+419
-62
lines changed

5 files changed

+419
-62
lines changed

csharp/ql/test/library-tests/call-graph/CallGraph.ql

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,51 @@
11
import csharp
22
import TestUtilities.InlineExpectationsTest
33

4+
string getQualifiedNameType(Type t) {
5+
exists(string prefix, string typeArgsSuffix |
6+
(
7+
typeArgsSuffix = "`" + t.(UnboundGeneric).getNumberOfTypeParameters()
8+
or
9+
not t instanceof Generic and
10+
typeArgsSuffix = ""
11+
) and
12+
result = prefix + typeArgsSuffix
13+
|
14+
prefix = getQualifiedNameType(t.(NestedType).getDeclaringType()) + "+" + t.getUndecoratedName()
15+
or
16+
prefix = getQualifiedNameType(t.(TypeParameter).getGeneric()) + "#" + t.getName()
17+
or
18+
prefix = getQualifiedNameCallable(t.(TypeParameter).getGeneric()) + "#" + t.getName()
19+
or
20+
not t instanceof NestedType and
21+
prefix =
22+
any(Namespace n | n.getATypeDeclaration() = t).getQualifiedName() + "." +
23+
t.getUndecoratedName()
24+
)
25+
}
26+
27+
string getUndecoratedName(Callable c) {
28+
result = c.(Constructor).getName()
29+
or
30+
not c instanceof Constructor and
31+
result = c.getUndecoratedName()
32+
}
33+
34+
string getQualifiedNameCallable(Callable c) {
35+
exists(string typeArgsSuffix |
36+
(
37+
typeArgsSuffix = "`" + c.(UnboundGeneric).getNumberOfTypeParameters()
38+
or
39+
not c instanceof Generic and
40+
typeArgsSuffix = ""
41+
)
42+
|
43+
result =
44+
getQualifiedNameType(c.getDeclaringType()) + "." + getUndecoratedName(c) + typeArgsSuffix
45+
)
46+
}
47+
48+
// string getParameterType(Parameter p) { result = p.getType().getQualifiedName() }
449
private predicate isOverloaded(Callable c) {
550
exists(Callable other |
651
c.getDeclaringType().hasCallable(other) and
@@ -24,9 +69,9 @@ class CallGraphTest extends InlineExpectationsTest {
2469
exists(Call c, string sig, Callable target |
2570
element = c.toString() and
2671
tag = "StaticTarget" and
27-
target = c.getTarget() and
72+
target = c.getTarget().getUnboundDeclaration() and
2873
(if isOverloaded(target) then sig = "(" + printSig(target) + ")" else sig = "") and
29-
value = target.getQualifiedName() + sig and
74+
value = getQualifiedNameCallable(target) + sig and
3075
c.getLocation() = location and
3176
not c.isImplicit()
3277
)
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
namespace G
2+
{
3+
namespace N1
4+
{
5+
class C1
6+
{
7+
public virtual void // $ TypeMention=System.Void
8+
M1<T1>(
9+
T1 x
10+
)
11+
{ }
12+
13+
public virtual void // $ TypeMention=System.Void
14+
M2<T1, T2>(
15+
T1 x1, T2 x2
16+
)
17+
{ }
18+
19+
void M() // $ TypeMention=System.Void
20+
{
21+
this.M1(0); // $ StaticTarget=G.N1.C1.M1`1
22+
this.M2(0, ""); // $ StaticTarget=G.N1.C1.M2`2
23+
}
24+
} // $ Class=G.N1.C1
25+
26+
class C2 : C1 // $ TypeMention=G.N1.C1
27+
{
28+
public override void // $ TypeMention=System.Void
29+
M1<S1>(
30+
S1 x
31+
)
32+
{ }
33+
34+
public override void // $ TypeMention=System.Void
35+
M2<S1, S2>(
36+
S1 x1, S2 x2
37+
)
38+
{ }
39+
40+
void M() // $ TypeMention=System.Void
41+
{
42+
this.M1(0); // $ StaticTarget=G.N1.C2.M1`1
43+
this.M2(0, ""); // $ StaticTarget=G.N1.C2.M2`2
44+
}
45+
} // $ Class=G.N1.C2
46+
}
47+
}

csharp/ql/test/library-tests/type-mentions/Mentions.cs

Lines changed: 188 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
unsafe class C : System.Exception
22
{
3-
void M1(
3+
void // $ TypeMention=System.Void
4+
M1(
45
C c1, // $ TypeMention=C
56
C[] c2
67
)
@@ -18,17 +19,51 @@ C[] c2
1819
}
1920
}
2021

21-
void M2(delegate*<int, void> f, int* x) { }
22+
void // $ TypeMention=System.Void
23+
M2(delegate*<int, void> f, int* x)
24+
{ }
2225
} // $ Class=C
2326

2427
class C2<T>
2528
{
26-
C2<
29+
C2< // $ TypeMention=C2`1
2730
C // $ TypeMention=C
28-
> // $ TypeMention=C2`1
31+
> // $ TypeMention=C2<C>
2932
M() => null;
3033

31-
void M2(int? i) { }
34+
void // $ TypeMention=System.Void
35+
M2(int? i)
36+
{ }
37+
38+
class C2Nested
39+
{
40+
} // $ Class=C2`1+C2Nested
41+
42+
C2< // $ TypeMention=C2`1
43+
C // $ TypeMention=C
44+
>. // $ TypeMention=C2<C>
45+
C2Nested // $ TypeMention=C2<C>+C2Nested
46+
M3() => null;
47+
48+
C2< // $ TypeMention=C2`1
49+
C2< // $ TypeMention=C2`1
50+
C // $ TypeMention=C
51+
> // $ TypeMention=C2<C>
52+
> // $ TypeMention=C2<C2<C>>
53+
M4() => null;
54+
55+
class C2Nested<T1, T2>
56+
{
57+
} // $ Class=C2`1+C2Nested`2
58+
59+
C2< // $ TypeMention=C2`1
60+
C // $ TypeMention=C
61+
>. // $ TypeMention=C2<C>
62+
C2Nested< // $ TypeMention=C2<C>+C2Nested`2
63+
int, // $ TypeMention=System.Int32
64+
string // $ TypeMention=System.String
65+
> // $ TypeMention=C2<C>+C2Nested<System.Int32,System.String>
66+
M5() => null;
3267
} // $ Class=C2`1
3368

3469
namespace N1
@@ -37,21 +72,39 @@ class C3
3772
{
3873
class C4 { } // $ Class=N1.C3+C4
3974

40-
void M(
75+
void // $ TypeMention=System.Void
76+
M(
4177
N1.C3 p1, // $ TypeMention=N1.C3
42-
N1.C3.C4 p2, // $ TypeMention=N1.C3+C4
43-
C3.C4 p3 // $ TypeMention=N1.C3+C4
78+
N1.C3. // $ TypeMention=N1.C3
79+
C4 p2, // $ TypeMention=N1.C3+C4
80+
C3. // $ TypeMention=N1.C3
81+
C4 p3 // $ TypeMention=N1.C3+C4
4482
)
4583
{ }
4684

47-
void M2(global::System.Int32 i) { }
85+
void // $ TypeMention=System.Void
86+
M2(global::System.Int32 i) // $ TypeMention=System.Int32
87+
{ }
4888

49-
void M3(ref int i) // not a ref type
89+
void // $ TypeMention=System.Void
90+
M3(ref // not a ref type
91+
int i) // $ TypeMention=System.Int32
5092
{
5193
ref int j = ref i;
5294
scoped ref int k = ref j;
53-
(int, string) tuple;
95+
(int, // $ TypeMention=System.Int32
96+
string) tuple; // $ TypeMention=System.String
5497
}
98+
99+
class C4Nested<T1>
100+
{
101+
} // $ Class=N1.C3+C4Nested`1
102+
103+
C3. // $ TypeMention=N1.C3
104+
C4Nested< // $ TypeMention=N1.C3+C4Nested`1
105+
int // $ TypeMention=System.Int32
106+
> // $ TypeMention=N1.C3+C4Nested<System.Int32>
107+
M4() => null;
55108
} // $ Class=N1.C3
56109
}
57110

@@ -63,10 +116,13 @@ public class C2
63116
{
64117
public class C3
65118
{
66-
void M(
119+
void // $ TypeMention=System.Void
120+
M(
67121
C3 p1, // $ TypeMention=N2.N3.C2+C3
68-
C2.C3 p2, // $ TypeMention=N2.N3.C2+C3
69-
N3.C2.C3 p3, // $ TypeMention=N2.N3.C2+C3
122+
C2. // $ TypeMention=N2.N3.C2
123+
C3 p2, // $ TypeMention=N2.N3.C2+C3
124+
N3.C2. // $ TypeMention=N2.N3.C2
125+
C3 p3, // $ TypeMention=N2.N3.C2+C3
70126
N2.N3.C3 p4, // $ TypeMention=N2.N3.C3
71127
C2 p5 // $ TypeMention=N2.N3.C2
72128
)
@@ -76,10 +132,13 @@ void M(
76132

77133
public class C3
78134
{
79-
void M(
135+
void // $ TypeMention=System.Void
136+
M(
80137
C3 p1, // $ TypeMention=N2.N3.C3
81-
C2.C3 p2, // $ TypeMention=N2.N3.C2+C3
82-
N3.C2.C3 p3, // $ TypeMention=N2.N3.C2+C3
138+
C2. // $ TypeMention=N2.N3.C2
139+
C3 p2, // $ TypeMention=N2.N3.C2+C3
140+
N3.C2. // $ TypeMention=N2.N3.C2
141+
C3 p3, // $ TypeMention=N2.N3.C2+C3
83142
N2.N3.C3 p4, // $ TypeMention=N2.N3.C3
84143
N3.C3 p5, // $ TypeMention=N2.N3.C3
85144
C2 p6 // $ TypeMention=N2.N3.C2
@@ -88,3 +147,115 @@ void M(
88147
} // $ Class=N2.N3.C3
89148
}
90149
}
150+
151+
namespace N4
152+
{
153+
// public class C
154+
// {
155+
// C.
156+
// C2 // $ TypeMention=N4.C.C2
157+
// field;
158+
159+
// void M() // $ TypeMention=System.Void
160+
// {
161+
// C.
162+
// C2. // $ TypeMention=N4.C.C2
163+
// M();
164+
// }
165+
// } // $ Class=N4.C
166+
167+
// namespace C
168+
// {
169+
// public class C2
170+
// {
171+
// public static void M() { } // $ TypeMention=System.Void
172+
// } // $ Class=N4.C.C2
173+
// }
174+
}
175+
176+
namespace N5
177+
{
178+
class MyAttribute : System.Attribute
179+
{
180+
public MyAttribute(
181+
int i // $ TypeMention=System.Int32
182+
)
183+
{ }
184+
} // $ Class=N5.MyAttribute
185+
186+
[MyAttribute(1)] // $ TypeMention=N5.MyAttribute
187+
class C1 { } // $ Class=N5.C1
188+
189+
[My(2)] // $ TypeMention=N5.MyAttribute
190+
class C2 { } // $ Class=N5.C2
191+
192+
class MyGenericAttribute<T> : System.Attribute { } // $ Class=N5.MyGenericAttribute`1
193+
class MyGeneric2Attribute<T, U> : System.Attribute { } // $ Class=N5.MyGeneric2Attribute`2
194+
195+
[
196+
MyGenericAttribute< // $ TypeMention=N5.MyGenericAttribute`1
197+
int // $ TypeMention=System.Int32
198+
>() // $ TypeMention=N5.MyGenericAttribute<System.Int32>
199+
]
200+
class C3 { } // $ Class=N5.C3
201+
202+
[
203+
MyGeneric< // $ TypeMention=N5.MyGenericAttribute`1
204+
string // $ TypeMention=System.String
205+
>() // $ TypeMention=N5.MyGenericAttribute<System.String>
206+
]
207+
class C4 { } // $ Class=N5.C4
208+
209+
[
210+
MyGeneric2< // $ TypeMention=N5.MyGeneric2Attribute`2
211+
int, // $ TypeMention=System.Int32
212+
string // $ TypeMention=System.String
213+
>() // $ TypeMention=N5.MyGeneric2Attribute<System.Int32,System.String>
214+
]
215+
class C5 { } // $ Class=N5.C5
216+
}
217+
218+
namespace N6
219+
{
220+
class C1<T>
221+
{
222+
T // $ TypeMention=N6.C1`1#T
223+
M1() => throw null;
224+
225+
void M2<T>( // $ TypeMention=System.Void
226+
T x // $ TypeMention=N6.C1`1.M2`1#T
227+
) => throw null;
228+
229+
class C2<T>
230+
{
231+
T // $ TypeMention=N6.C1`1+C2`1#T
232+
M() => throw null;
233+
} // $ Class=N6.C1`1+C2`1
234+
235+
class C3
236+
{
237+
class T
238+
{
239+
} // $ Class=N6.C1`1+C3+T
240+
241+
T // $ TypeMention=N6.C1`1+C3+T
242+
M() => throw null;
243+
} // $ Class=N6.C1`1+C3
244+
245+
void M3<T>( // $ TypeMention=System.Void
246+
T x // $ TypeMention=N6.C1`1.M3`1#T
247+
)
248+
{
249+
void LocalFunc<T>(
250+
T x // $ TypeMention=N6.C1`1.M3`1.LocalFunc`1#T
251+
)
252+
{
253+
void InnerLocalFunc<T>(
254+
T x // $ TypeMention=N6.C1`1.M3`1.LocalFunc`1.InnerLocalFunc`1#T
255+
)
256+
{
257+
}
258+
}
259+
}
260+
} // $ Class=N6.C1`1
261+
}

0 commit comments

Comments
 (0)