Skip to content

Fix integers with LL suffix#299

Open
davispuh wants to merge 1 commit intojacob-carlborg:masterfrom
davispuh:ll
Open

Fix integers with LL suffix#299
davispuh wants to merge 1 commit intojacob-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
Copy link
Copy Markdown

Copilot AI left a comment

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 on lines 97 to +100
alias pred = (dchar x) => (x == 'u' || x == 'U' || x == 'L');
auto integer = literal.spelling.stripRight!pred;
auto uinteger = integer.stripLeft!(x => x == '+' || x == '-');
auto suffix = literal.spelling[integer.length .. $];
Comment on lines +107 to +116
if (suffix.length >= 2 && suffix[$-2..$] == "LL")
{
suffix = suffix.chop;
}
auto core = uinteger[0 .. $ - 1].stripLeft('0') ~ uinteger[$ - 1];
return "octal!" ~ core ~ suffix;
} else if (suffix.length >= 2 && suffix[$-2..$] == "LL")
{
suffix = suffix.chop;
return integer ~ suffix;
Comment on lines +113 to +116
} else if (suffix.length >= 2 && suffix[$-2..$] == "LL")
{
suffix = suffix.chop;
return integer ~ suffix;
Copy link
Copy Markdown
Owner

@jacob-carlborg jacob-carlborg left a comment

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.

{
(*context.imports).add("std.conv : octal");
auto suffix = literal.spelling[integer.length .. $];
if (suffix.length >= 2 && suffix[$-2..$] == "LL")
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 a function in the standard library that checks if a string ends with another string, can't that be used? https://dlang.org/phobos/std_algorithm_searching.html#.endsWith

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