Skip to content

Fix extern (C) header case#300

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

Fix extern (C) header case#300
davispuh wants to merge 2 commits into
jacob-carlborg:masterfrom
davispuh:extern

Conversation

@davispuh

Copy link
Copy Markdown

Currently if you have a.h like:

/**
 * comment
 *
**/

#pragma once

#define A 1

And you run dstep --package a --global-import b a.h
Then result will be broken code (note split extern):

/**
 * comment
 *
**/

extmodule a.a;

import b;

ern (C):

enum A = 1;

This PR fixes that so it will be correct code:

/**
 * comment
 *
**/

module a.a;

import b;



extern (C):

enum A = 1;

Copilot AI review requested due to automatic review settings March 18, 2026 23:07

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 fixes an output-ordering issue where module/imports could be inserted in the middle of the extern (C): line (e.g., producing extmodule / ern (C):) by restructuring how the translator builds the final Output.

Changes:

  • Split translation output into a separate content Output, then prepend module/imports/extern before merging.
  • Simplify translateToString() to return the Output’s header + content directly (removing the extra head output buffer).

💡 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/Translator.d
Comment thread dstep/translator/Translator.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 case.

davispuh added 2 commits June 21, 2026 22:50
Currently if you have `a.h` like:
```
/**
 * comment with trailing whitespace
 *
**/

 #pragma once

 #define A 1
```

And you run `dstep --package a --global-import b a.h`
You will get broken code (note split extern):
```
/**
 * comment with trailing whitespace
 *
**/

extmodule a.a;

import b;

ern (C):

enum A = 1;
```

This commit fixes this issue.
@davispuh

Copy link
Copy Markdown
Author

Rewrote this PR and added tests. First commit fixes original issue. 2nd is additional improvement.

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