CPP: Extend the unions test.

This commit is contained in:
Geoffrey White
2019-08-06 16:00:35 +01:00
parent cf20647765
commit 4ed559ee0b
3 changed files with 44 additions and 7 deletions

View File

@@ -1,3 +1,6 @@
| unions.cpp:4:8:4:12 | Entry | struct | |
| unions.cpp:13:7:13:11 | Value | struct | union |
| unions.cpp:19:8:19:22 | EntryWithMethod | struct | |
| unions.cpp:4:8:4:12 | Entry | Struct |
| unions.cpp:13:7:13:11 | Value | Struct, Union |
| unions.cpp:19:8:19:22 | EntryWithMethod | Struct |
| unions.cpp:27:9:27:20 | MyLocalUnion | LocalUnion, Struct, Union |
| unions.cpp:33:7:33:13 | MyClass | |
| unions.cpp:36:9:36:21 | MyNestedUnion | NestedUnion, Struct, Union |

View File

@@ -1,6 +1,23 @@
import cpp
from Class t, string struct, string union
where if t instanceof Struct then struct = "struct" else struct = ""
and if t instanceof Union then union = "union" else union = ""
select t, struct, union
string describe(Class c)
{
(
c instanceof Struct and
result = "Struct"
) or (
c instanceof Union and
result = "Union"
) or (
c instanceof LocalUnion and
result = "LocalUnion"
) or (
c instanceof NestedUnion and
result = "NestedUnion"
)
}
from Class c
select
c,
concat(describe(c), ", ")

View File

@@ -21,3 +21,20 @@ struct EntryWithMethod: Entry {
return i;
}
};
void myFunction()
{
union MyLocalUnion {
int i;
float f;
};
}
class MyClass
{
public:
union MyNestedUnion {
int i;
float f;
};
};