[cfe-dev] detecting global variables used in functions

Mohammed El-Afifi mohammed_elafifi at yahoo.com
Thu Apr 3 05:05:05 PDT 2014


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 definitionsfound 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140403/e7bdd03a/attachment.html>


More information about the cfe-dev mailing list