@@ -197,7 +197,35 @@ class DataFlowType = Type;
197197
198198class DataFlowLocation = Location ;
199199
200- class DataFlowCallable = Callable ;
200+ private newtype TDataFlowCallable =
201+ TCallable ( Callable c ) or
202+ TFileScope ( File f )
203+
204+ class DataFlowCallable extends TDataFlowCallable {
205+ Callable asCallable ( ) { this = TCallable ( result ) }
206+
207+ File asFileScope ( ) { this = TFileScope ( result ) }
208+
209+ FuncDef getFuncDef ( ) { result = this .asCallable ( ) .getFuncDef ( ) }
210+
211+ Function asFunction ( ) { result = this .asCallable ( ) .asFunction ( ) }
212+
213+ FuncLit asFuncLit ( ) { result = this .asCallable ( ) .asFuncLit ( ) }
214+
215+ SignatureType getType ( ) { result = this .asCallable ( ) .getType ( ) }
216+
217+ string toString ( ) {
218+ result = this .asCallable ( ) .toString ( ) or
219+ result = "File scope: " + this .asFileScope ( ) .toString ( )
220+ }
221+
222+ predicate hasLocationInfo (
223+ string filepath , int startline , int startcolumn , int endline , int endcolumn
224+ ) {
225+ this .asCallable ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn ) or
226+ this .asFileScope ( ) .hasLocationInfo ( filepath , startline , startcolumn , endline , endcolumn )
227+ }
228+ }
201229
202230/** A function call relevant for data flow. */
203231class DataFlowCall extends Expr {
@@ -214,7 +242,11 @@ class DataFlowCall extends Expr {
214242 ExprNode getNode ( ) { result = call }
215243
216244 /** Gets the enclosing callable of this call. */
217- DataFlowCallable getEnclosingCallable ( ) { result .getFuncDef ( ) = this .getEnclosingFunction ( ) }
245+ DataFlowCallable getEnclosingCallable ( ) {
246+ result .asCallable ( ) .getFuncDef ( ) = this .getEnclosingFunction ( )
247+ or
248+ not exists ( this .getEnclosingFunction ( ) ) and result .asFileScope ( ) = this .getFile ( )
249+ }
218250}
219251
220252/** Holds if `e` is an expression that always has the same Boolean value `val`. */
0 commit comments