-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathStruct.qll
75 lines (63 loc) · 1.65 KB
/
Struct.qll
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* Provides classes for modeling `struct`s.
*/
import semmle.code.cpp.Type
import semmle.code.cpp.Class
/**
* A C/C++ structure or union. For example, the types `MyStruct` and `MyUnion`
* in:
* ```
* struct MyStruct {
* int x, y, z;
* };
*
* union MyUnion {
* int i;
* float f;
* };
* ```
*/
class Struct extends Class {
Struct() { usertypes(underlyingElement(this), _, [1, 3, 15, 17]) }
override string getAPrimaryQlClass() { result = "Struct" }
override string explain() { result = "struct " + this.getName() }
override predicate isDeeplyConstBelow() { any() } // No subparts
}
/**
* A C/C++ struct that is directly enclosed by a function. For example, the type
* `MyLocalStruct` in:
* ```
* void myFunction() {
* struct MyLocalStruct {
* int x, y, z;
* };
* }
* ```
*/
class LocalStruct extends Struct {
LocalStruct() { this.isLocal() }
override string getAPrimaryQlClass() { not this instanceof LocalUnion and result = "LocalStruct" }
}
/**
* A C/C++ nested struct. See 11.12. For example, the type `MyNestedStruct` in:
* ```
* class MyClass {
* public:
* struct MyNestedStruct {
* int x, y, z;
* };
* };
* ```
*/
class NestedStruct extends Struct {
NestedStruct() { this.isMember() }
override string getAPrimaryQlClass() {
not this instanceof NestedUnion and result = "NestedStruct"
}
/** Holds if this member is private. */
predicate isPrivate() { this.hasSpecifier("private") }
/** Holds if this member is protected. */
predicate isProtected() { this.hasSpecifier("protected") }
/** Holds if this member is public. */
predicate isPublic() { this.hasSpecifier("public") }
}