1
+ /**
2
+ * Provides classes for identifying and reasoning about Microsoft source code
3
+ * annoatation language (SAL) macros.
4
+ */
5
+
1
6
import cpp
2
7
8
+ /**
9
+ * A SAL macro defined in `sal.h` or a similar header file.
10
+ */
3
11
class SALMacro extends Macro {
4
12
SALMacro ( ) {
5
13
exists ( string filename | filename = this .getFile ( ) .getBaseName ( ) |
@@ -22,25 +30,32 @@ class SALMacro extends Macro {
22
30
pragma [ noinline]
23
31
predicate isTopLevelMacroAccess ( MacroAccess ma ) { not exists ( ma .getParentInvocation ( ) ) }
24
32
33
+ /**
34
+ * An invocation of a SAL macro (excluding invocations inside other macros).
35
+ */
25
36
class SALAnnotation extends MacroInvocation {
26
37
SALAnnotation ( ) {
27
38
this .getMacro ( ) instanceof SALMacro and
28
39
isTopLevelMacroAccess ( this )
29
40
}
30
41
31
- /** Returns the `Declaration` annotated by `this`. */
42
+ /** Gets the `Declaration` annotated by `this`. */
32
43
Declaration getDeclaration ( ) {
33
44
annotatesAt ( this , result .getADeclarationEntry ( ) , _, _) and
34
45
not result instanceof Type // exclude typedefs
35
46
}
36
47
37
- /** Returns the `DeclarationEntry` annotated by `this`. */
48
+ /** Gets the `DeclarationEntry` annotated by `this`. */
38
49
DeclarationEntry getDeclarationEntry ( ) {
39
50
annotatesAt ( this , result , _, _) and
40
51
not result instanceof TypeDeclarationEntry // exclude typedefs
41
52
}
42
53
}
43
54
55
+ /**
56
+ * A SAL macro indicating that the return value of a function should always be
57
+ * checked.
58
+ */
44
59
class SALCheckReturn extends SALAnnotation {
45
60
SALCheckReturn ( ) {
46
61
exists ( SALMacro m | m = this .getMacro ( ) |
@@ -50,6 +65,10 @@ class SALCheckReturn extends SALAnnotation {
50
65
}
51
66
}
52
67
68
+ /**
69
+ * A SAL macro indicating that a pointer variable or return value should not be
70
+ * `NULL`.
71
+ */
53
72
class SALNotNull extends SALAnnotation {
54
73
SALNotNull ( ) {
55
74
exists ( SALMacro m | m = this .getMacro ( ) |
@@ -69,6 +88,9 @@ class SALNotNull extends SALAnnotation {
69
88
}
70
89
}
71
90
91
+ /**
92
+ * A SAL macro indicating that a value may be `NULL`.
93
+ */
72
94
class SALMaybeNull extends SALAnnotation {
73
95
SALMaybeNull ( ) {
74
96
exists ( SALMacro m | m = this .getMacro ( ) |
0 commit comments