如何识别在 clang 函数体中声明的变量

How to identify variables that are declared in a function body in clang

我已经用 clang 实现了一个 AST 递归访问者,我想区分变量声明。我想知道变量声明是全局的还是变量声明在函数体中。两者都会为我完成这项工作。 有什么想法吗?

谢谢。

您可以在 AST Visiter 中访问 VarDecl,然后您可能想使用像 isLocalVarDecl(), isLocalVarDeclOrParm(), isFunctionOrMethodVarDecl(), isStaticDataMember(), hasLocalStorage(), or hasGlobalStorage() from the VarDecl's Api here.

这样的函数