Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cf20647

Browse files
committed
CPP: Extend the structs test.
1 parent 5d4fba4 commit cf20647

4 files changed

Lines changed: 40 additions & 6 deletions

File tree

cpp/ql/test/library-tests/structs/structs/structs.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ void f(void) {
1010
l = s.i;
1111
}
1212

13+
void myFunction()
14+
{
15+
struct MyLocalStruct {
16+
int x, y, z;
17+
};
18+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
class MyClass
3+
{
4+
public:
5+
struct MyNestedStruct {
6+
int x, y, z;
7+
};
8+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1+
structs
2+
| structs.c:2:8:2:10 | foo | |
3+
| structs.c:15:10:15:22 | MyLocalStruct | LocalStruct |
4+
| structs.cpp:5:10:5:23 | MyNestedStruct | NestedStruct |
5+
assignments
16
| structs.c:10:5:10:11 | ... = ... | structs.c:10:5:10:5 | l | int | structs.c:10:11:10:11 | i | int |
Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
import cpp
22

3-
from Assignment a
4-
select a,
5-
a.getLValue() as l,
6-
l.getType().explain(),
7-
a.getRValue() as r,
8-
r.getType().explain()
3+
string describe(Struct s)
4+
{
5+
(
6+
s instanceof LocalStruct and
7+
result = "LocalStruct"
8+
) or (
9+
s instanceof NestedStruct and
10+
result = "NestedStruct"
11+
)
12+
}
913

14+
query predicate structs(Struct s, string descStr) {
15+
s.fromSource() and
16+
descStr = concat(describe(s), ", ")
17+
}
18+
19+
query predicate assignments(Assignment a, Expr l, string explainL, Expr r, string explainR) {
20+
l = a.getLValue() and
21+
explainL = l.getType().explain() and
22+
r = a.getRValue() and
23+
explainR = r.getType().explain()
24+
}

0 commit comments

Comments
 (0)