CPP: Extend the structs test.

This commit is contained in:
Geoffrey White
2019-08-06 15:52:25 +01:00
parent 5d4fba4446
commit cf20647765
4 changed files with 40 additions and 6 deletions

View File

@@ -10,3 +10,9 @@ void f(void) {
l = s.i;
}
void myFunction()
{
struct MyLocalStruct {
int x, y, z;
};
}

View File

@@ -0,0 +1,8 @@
class MyClass
{
public:
struct MyNestedStruct {
int x, y, z;
};
};

View File

@@ -1 +1,6 @@
structs
| structs.c:2:8:2:10 | foo | |
| structs.c:15:10:15:22 | MyLocalStruct | LocalStruct |
| structs.cpp:5:10:5:23 | MyNestedStruct | NestedStruct |
assignments
| structs.c:10:5:10:11 | ... = ... | structs.c:10:5:10:5 | l | int | structs.c:10:11:10:11 | i | int |

View File

@@ -1,9 +1,24 @@
import cpp
from Assignment a
select a,
a.getLValue() as l,
l.getType().explain(),
a.getRValue() as r,
r.getType().explain()
string describe(Struct s)
{
(
s instanceof LocalStruct and
result = "LocalStruct"
) or (
s instanceof NestedStruct and
result = "NestedStruct"
)
}
query predicate structs(Struct s, string descStr) {
s.fromSource() and
descStr = concat(describe(s), ", ")
}
query predicate assignments(Assignment a, Expr l, string explainL, Expr r, string explainR) {
l = a.getLValue() and
explainL = l.getType().explain() and
r = a.getRValue() and
explainR = r.getType().explain()
}