detecting global variables used in functions

Hello everybody,
I want to be able to spot file-level variables(either with static or extern) used inside each function. I’ve already hooked an AST matcher(from for functions with definitions found during parsing.

Since I couldn’t find a matcher that would allow me to match top-level declarations, I thought I could similarly define another matcher for variable declarations along with a custom MatchCallback class to filter only on variables with file-scope declarations(using VarDecl::isFileVarDecl method). Is this the easy way to go or may there be a better way through AST matchers that would get me directly file-scope variable declarations(without having to check its cope myself), like with chaining/nesting some matchers together? The closest thing I could find was hasDeclContext but couldn’t find a matcher to match a translation unit scope.

Appreciating your advice.