Skip to content

transpile: Add MacroInvocationInfo - #1970

Open
Rua wants to merge 2 commits into
immunant:masterfrom
Rua:macro-invocation-info
Open

Rua wants to merge 2 commits into
immunant:masterfrom
Rua:macro-invocation-info

Conversation

@Rua

@Rua Rua commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Following up from #1792, this adds the necessary infrastructure to the AST to handle functional macro arguments. The MacroInvocationInfo::arguments value is currently unused.

@Rua
Rua force-pushed the macro-invocation-info branch 2 times, most recently from 2f8538e to 367c4d8 Compare August 8, 2026 16:14
@Rua
Rua force-pushed the macro-invocation-info branch 3 times, most recently from 9884df3 to 00e7abe Compare August 22, 2026 08:26
Comment thread c2rust-transpile/src/c_ast/conversion.rs
Comment thread c2rust-transpile/src/c_ast/conversion.rs
Comment thread c2rust-transpile/src/c_ast/conversion.rs Outdated
Comment thread c2rust-transpile/src/translator/macros.rs
@@ -1047,13 +1068,38 @@ impl ConversionContext {
};

if expected_ty & EXPR != 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about the callers of expr_possibly_as_stmt? I.e. expressions used as statements?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those get wrapped in a CStmtKind::Expr, in which the statement part and the expression part are handled separately.

@Rua
Rua force-pushed the macro-invocation-info branch 3 times, most recently from 2a6372a to 759cf38 Compare September 7, 2026 16:55
let info = macro_infos
.remove(&key)
.unwrap_or_else(|| panic!("No macro_infos entry for key {key}"));
let info = Rc::new(MacroInvocationInfo { expr_id, ..info });

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to also normalize info.arguments here (through unwrap_implicit_cast_expr or something else)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly, but I'm not sure. It kinda works "in reverse" when it comes to macro arguments, because they are placed within the macro definition. So if casts are left as-is, then they are considered to form part of the argument passed at the call site. If they are unwrapped, then they are considered part of the context surrounding the argument within the macro definition.

@Rua
Rua force-pushed the macro-invocation-info branch from 759cf38 to 094ecb8 Compare September 22, 2026 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants