-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathUnion.qll
70 lines (58 loc) · 1.49 KB
/
Union.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
/**
* Provides classes for modeling `union`s.
*/
import semmle.code.cpp.Type
import semmle.code.cpp.Struct
/**
* A C/C++ union. See C.8.2. For example, the type `MyUnion` in:
* ```
* union MyUnion {
* int i;
* float f;
* };
* ```
*/
class Union extends Struct {
Union() { usertypes(underlyingElement(this), _, [3, 17]) }
override string getAPrimaryQlClass() { result = "Union" }
override string explain() { result = "union " + this.getName() }
override predicate isDeeplyConstBelow() { any() } // No subparts
}
/**
* A C/C++ union that is directly enclosed by a function. For example, the type
* `MyLocalUnion` in:
* ```
* void myFunction() {
* union MyLocalUnion {
* int i;
* float f;
* };
* }
* ```
*/
class LocalUnion extends Union {
LocalUnion() { this.isLocal() }
override string getAPrimaryQlClass() { result = "LocalUnion" }
}
/**
* A C/C++ nested union. For example, the type `MyNestedUnion` in:
* ```
* class MyClass {
* public:
* union MyNestedUnion {
* int i;
* float f;
* };
* };
* ```
*/
class NestedUnion extends Union {
NestedUnion() { this.isMember() }
override string getAPrimaryQlClass() { result = "NestedUnion" }
/** 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") }
}