Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在构建一个clang libtool,我怎样才能获得预处理器信息,告诉我给定的Decl是否在#if #ifdef #ifndef的范围内?
不幸的是,对此没有简单的答案。Clang 并不完全了解任何预处理器指令的 AST 级别。
据我所知,您能做的最好的事情是实现一个 PPCallbacks 类,将其注册到编译器实例预处理器并实现 If、Elif、Endif 的函数。
然后,您可以使用 ASTVisitor 查找这些 Source 位置之间的所有内容。