1+ /**
2+ * Provides classes for identifying and reasoning about Microsoft source code
3+ * annoatation language (SAL) macros.
4+ */
5+
16import cpp
27
8+ /**
9+ * A SAL macro defined in `sal.h` or a similar header file.
10+ */
311class SALMacro extends Macro {
412 SALMacro ( ) {
513 exists ( string filename | filename = this .getFile ( ) .getBaseName ( ) |
@@ -22,25 +30,32 @@ class SALMacro extends Macro {
2230pragma [ noinline]
2331predicate isTopLevelMacroAccess ( MacroAccess ma ) { not exists ( ma .getParentInvocation ( ) ) }
2432
33+ /**
34+ * An invocation of a SAL macro (excluding invocations inside other macros).
35+ */
2536class SALAnnotation extends MacroInvocation {
2637 SALAnnotation ( ) {
2738 this .getMacro ( ) instanceof SALMacro and
2839 isTopLevelMacroAccess ( this )
2940 }
3041
31- /** Returns the `Declaration` annotated by `this`. */
42+ /** Gets the `Declaration` annotated by `this`. */
3243 Declaration getDeclaration ( ) {
3344 annotatesAt ( this , result .getADeclarationEntry ( ) , _, _) and
3445 not result instanceof Type // exclude typedefs
3546 }
3647
37- /** Returns the `DeclarationEntry` annotated by `this`. */
48+ /** Gets the `DeclarationEntry` annotated by `this`. */
3849 DeclarationEntry getDeclarationEntry ( ) {
3950 annotatesAt ( this , result , _, _) and
4051 not result instanceof TypeDeclarationEntry // exclude typedefs
4152 }
4253}
4354
55+ /**
56+ * A SAL macro indicating that the return value of a function should always be
57+ * checked.
58+ */
4459class SALCheckReturn extends SALAnnotation {
4560 SALCheckReturn ( ) {
4661 exists ( SALMacro m | m = this .getMacro ( ) |
@@ -50,6 +65,10 @@ class SALCheckReturn extends SALAnnotation {
5065 }
5166}
5267
68+ /**
69+ * A SAL macro indicating that a pointer variable or return value should not be
70+ * `NULL`.
71+ */
5372class SALNotNull extends SALAnnotation {
5473 SALNotNull ( ) {
5574 exists ( SALMacro m | m = this .getMacro ( ) |
@@ -69,6 +88,9 @@ class SALNotNull extends SALAnnotation {
6988 }
7089}
7190
91+ /**
92+ * A SAL macro indicating that a value may be `NULL`.
93+ */
7294class SALMaybeNull extends SALAnnotation {
7395 SALMaybeNull ( ) {
7496 exists ( SALMacro m | m = this .getMacro ( ) |
0 commit comments