Skip to content

Fix integers with LL suffix#299

Open
davispuh wants to merge 2 commits into
jacob-carlborg:masterfrom
davispuh:ll
Open

Fix integers with LL suffix#299
davispuh wants to merge 2 commits into
jacob-carlborg:masterfrom
davispuh:ll

Conversation

@davispuh

Copy link
Copy Markdown

Consider a.h with:

#define LARGE 3LL

Currently dstep would produce

extern (C):

enum LARGE = 3LL;

Which is not valid D code because D language doesn't have LL suffix.

$ ldc -c a.d
a.d(3): Error: repeated integer suffix `L`
enum LARGE = 3LL;
             ^

This PR fixes that so in such case result will be:

extern (C):

enum LARGE = 3L;

Copilot AI review requested due to automatic review settings March 18, 2026 22:47

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 dstep’s macro literal translation so C integer literals using the LL (long long) suffix are emitted as valid D integer literals (D doesn’t allow LL).

Changes:

  • Detects LL at the end of an integer literal suffix and collapses it to a single L.
  • Applies the same suffix normalization in both the octal-literal translation path and the non-octal path.

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

You can also share your feedback on Copilot code review. Take the survey.

Comment thread dstep/translator/MacroDefinition.d Outdated
Comment thread dstep/translator/MacroDefinition.d Outdated
Comment thread dstep/translator/MacroDefinition.d Outdated
Comment on lines +113 to +116
} else if (suffix.length >= 2 && suffix[$-2..$] == "LL")
{
suffix = suffix.chop;
return integer ~ suffix;

@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.

Comments by Copilot are reasonable, especially about missing tests.

Comment thread dstep/translator/MacroDefinition.d Outdated
davispuh added 2 commits June 22, 2026 21:16
Consider a.h with:
```c
 #define LARGE 3LL
```
Currently dstep would produce:
```d
extern (C):

enum LARGE = 3LL;
```

Which is not valid D code because D language doesn't have LL suffix.
This PR fixes this so such case will become:
```d
extern (C):

enum LARGE = 3L;
```
@davispuh

Copy link
Copy Markdown
Author

I rewrote this PR and added tests. I also implemented support for decimals (eg. 1.dd).
I looked into supporting complex numbers (eg. 1.0i, 2.0J) aswell but that would add additional complex code so dropped it.

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