ast-exporter: Export some macro arg expansions#1792
Conversation
29c07b0 to
e861f34
Compare
b13d905 to
465f6a7
Compare
2240b16 to
0481fbc
Compare
| SmallVector<MacroInfo*, 1> curMacroExpansionStack; | ||
| StringRef curMacroExpansionSource; | ||
| // TODO: Can this be made to use `unordered_set` for speed? | ||
| std::set<std::pair<unsigned, const StringRef>> macroCallSites; |
There was a problem hiding this comment.
What do these StringRefs point into? Is there a potential lifetime issue here?
There was a problem hiding this comment.
They point to the Clang AST in the same way that macros does, which also holds a StringRef. I assume that both live as long as the AST is kept alive?
| void encode_entry_raw(void *ast, ASTEntryTag tag, SourceRange loc, | ||
| const QualType ty, bool rvalue, | ||
| bool isVaList, bool encodeMacroExpansions, | ||
| bool isVaList, bool encodeMacroInvocations, |
There was a problem hiding this comment.
Could you explain why the rename from "expansions" to "invocations"? I'm guessing there's a subtle difference but I'm not sure what it is.
There was a problem hiding this comment.
In my understanding, an invocation is the place where the macro name is written, the "call". And the expansion is the act or result of replacing the macro name with its output tokens. Most of the logic for macros works "backwards": the fully expanded macro, in the form of a C expression, is the start point, and c2rust is working to find the original macro invocation(s)/call(s) that produced it. So I felt that naming that "expansion" was confusing and not very descriptive.
Maybe there are better things to name these though?
VisitExpr, handle when Begin and End start off in different macros #1795The "chain" of expansions is a little different for macros with args (that is, functional macros). This PR does two things:
Not all macro args are currently handled by this because of technical limitations. This code is only able to "see" macro args in the macro where they were expanded into tokens. They are not visible in macros that take an arg and then pass it on to another macro call in an arg. Maybe a solution will eventually be found for that. For now at least, the AST on the Rust side contains expressions that are macro arg expansions!