Skip to content

Commit ff546c1

Browse files
committed
C#: Add test cases for ref fields.
1 parent 2be090b commit ff546c1

File tree

7 files changed

+59
-0
lines changed

7 files changed

+59
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// TODO: Test needs to be enabled when .NET 7 is used as the runtime.
2+
namespace structassembly;
3+
4+
public class MyEmptyClass { }
5+
6+
public ref struct RefStruct
7+
{
8+
public int MyInt;
9+
public ref byte MyByte;
10+
public ref object MyObject;
11+
internal ref MyEmptyClass MyEmptyClass;
12+
public ref readonly byte MyReadonlyByte;
13+
public readonly ref object MyReadonlyObject;
14+
public readonly ref readonly string MyReadonlyString;
15+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
namespace structassembly;
2+
3+
public class MyEmptyClass { }
4+
5+
public ref struct RefStruct
6+
{
7+
public int MyInt;
8+
public ref byte MyByte;
9+
public ref object MyObject;
10+
internal ref MyEmptyClass MyEmptyClass;
11+
public ref readonly byte MyReadonlyByte;
12+
public readonly ref object MyReadonlyObject;
13+
public readonly ref readonly string MyReadonlyString;
14+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
| file://:0:0:0:0 | MyByte | Byte |
2+
| file://:0:0:0:0 | MyEmptyClass | MyEmptyClass |
3+
| file://:0:0:0:0 | MyObject | Object |
4+
| file://:0:0:0:0 | MyReadonlyByte | Byte |
5+
| file://:0:0:0:0 | MyReadonlyObject | Object |
6+
| file://:0:0:0:0 | MyReadonlyString | String |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import cil
2+
3+
query predicate cilfields(CIL::Field f, string type) {
4+
f.isRef() and type = f.getType().toString() and f.getDeclaringType().getName() = "RefStruct"
5+
}
Binary file not shown.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
reffields
2+
readonlyreffields
3+
readonlyfield
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import csharp
2+
3+
query predicate reffields(Field f) {
4+
f.getFile().getStem() = "Struct" and
5+
f.isRef()
6+
}
7+
8+
query predicate readonlyreffields(Field f) {
9+
f.getFile().getStem() = "Struct" and
10+
f.isReadonlyRef()
11+
}
12+
13+
query predicate readonlyfield(Field f) {
14+
f.getFile().getStem() = "Struct" and
15+
f.isReadOnly()
16+
}

0 commit comments

Comments
 (0)