@@ -95,32 +95,55 @@ predicate usesMacro(HeaderFile hf, string macroName) {
9595 )
9696}
9797
98- /**
99- * File `f` both defines and un-defines a macro called `macroName`.
100- */
101- predicate defUndef ( File f , string macroName ) {
98+ /** File `f` defines a macro called `macroName`. */
99+ predicate definesMacro ( File f , string macroName ) {
102100 exists ( Macro m |
103101 m .getFile ( ) = f and
104102 m .getName ( ) = macroName
105- ) and exists ( PreprocessorUndef ud |
103+ )
104+ }
105+
106+ /** File `f` un-defines a macro called `macroName`. */
107+ predicate undefinesMacro ( File f , string macroName ) {
108+ exists ( PreprocessorUndef ud |
106109 ud .getFile ( ) = f and
107110 ud .getName ( ) = macroName
108111 )
109112}
110113
114+ /**
115+ * File `f` both defines and un-defines a macro called `macroName`.
116+ */
117+ predicate defUndef ( File f , string macroName ) {
118+ definesMacro ( f , macroName ) and
119+ undefinesMacro ( f , macroName )
120+ }
121+
111122/**
112123 * Header file `hf` looks like it contains an x-macro.
113124 * That is, a macro that is used to interpret the
114125 * data in `hf`, usually defined just before including that file
115126 * and undefined immediately afterwards.
116127 */
117128predicate hasXMacro ( HeaderFile hf ) {
129+ // Every header that includes `hf` both defines and undefines a macro that's
130+ // used in `hf`.
118131 exists ( string macroName |
119132 usesMacro ( hf , macroName ) and
120133 forex ( File f | f .getAnIncludedFile ( ) = hf |
121134 defUndef ( f , macroName )
122135 )
123136 )
137+ or
138+ // Every header that includes `hf` defines a macro that's used in `hf`, and
139+ // `hf` itself undefines it.
140+ exists ( string macroName |
141+ usesMacro ( hf , macroName ) and
142+ undefinesMacro ( hf , macroName ) and
143+ forex ( File f | f .getAnIncludedFile ( ) = hf |
144+ definesMacro ( f , macroName )
145+ )
146+ )
124147}
125148
126149from HeaderFile hf , string detail , MaybePreprocessorDirective detail1 , MaybePreprocessorDirective detail2
0 commit comments