Skip to content

Support &=, ^=, |= for macros#307

Open
davispuh wants to merge 1 commit into
jacob-carlborg:masterfrom
davispuh:macro
Open

Support &=, ^=, |= for macros#307
davispuh wants to merge 1 commit into
jacob-carlborg:masterfrom
davispuh:macro

Conversation

@davispuh

Copy link
Copy Markdown

Consider macro like this:

#define FLAG_CLEAR(S, Flag) (S->Flags &= ~(Flag))

Currently such macros with &=, ^= and |= are dropped.
So this PR implements support for them and will produce D code like:

extern (D) auto FLAG_CLEAR(T0, T1)(auto ref T0 S, auto ref T1 Flag)
{
    return S.Flags &= ~Flag;
}

Copilot AI review requested due to automatic review settings March 19, 2026 22:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the macro expression parser so macros using compound bitwise-assignment operators (&=, ^=, |=) are no longer dropped and can be translated into equivalent D expressions.

Changes:

  • Added parsing support for &=, ^=, and |= in macro expressions.
  • Routed conditional-expression parsing through the new compound-assignment parse layer.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread dstep/translator/MacroParser.d Outdated

@jacob-carlborg jacob-carlborg left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

There's no test added.

@davispuh

Copy link
Copy Markdown
Author

I fixed operator precedence and added tests.

@davispuh davispuh mentioned this pull request Jul 4, 2026
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.

3 participants