Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions dstep/translator/IncludeHandler.d
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,6 @@ class IncludeHandler

if (options.keepUntranslatable)
importsBlock(output, unhandled.keys);

output.finalize();
}

bool resolveDependency(in Cursor cursor)
Expand Down
2 changes: 1 addition & 1 deletion dstep/translator/Output.d
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,8 @@ D"[0 .. $ - 1]);
if (commentIndex && commentIndex.isHeaderCommentPresent)
{
auto location = commentIndex.queryHeaderCommentExtent.end;
headerEndOffset = location.offset + 2;
flushLocation(location, false);
headerEndOffset = cast(uint) buffer.data.length + 2;
return true;
}
else
Expand Down
31 changes: 18 additions & 13 deletions dstep/translator/Translator.d
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class Translator
Output translateCursors()
{
Output result = new Output(context.commentIndex);
Output content;
typedMacroDefinitions = inferMacroSignatures(context);

bool first = true;
Expand All @@ -91,36 +92,40 @@ class Translator
if (result.flushHeaderComment())
result.separator();

externDeclaration(result);
content = new Output(result);
externDeclaration(content);
first = false;
}

translateInGlobalScope(result, cursor, parent);
translateInGlobalScope(content, cursor, parent);
}
}

if (first)
{
if (result.flushHeaderComment())
result.separator();

content = new Output(result);
}

if (context.commentIndex)
result.flushLocation(context.commentIndex.queryLastLocation());
content.flushLocation(context.commentIndex.queryLastLocation());

foreach (value; deferredDeclarations.values)
result.singleLine(value);
content.singleLine(value);

moduleDeclaration(result);
context.includeHandler.toImports(result);
result.output(content);
result.finalize();

return result;
}

string translateToString()
{
import std.algorithm.mutation : strip;

Output main = translateCursors();
Output head = new Output();

moduleDeclaration(head);
context.includeHandler.toImports(head);

return main.header ~ head.data ~ main.content;
return translateCursors().data;
}

void translateInGlobalScope(
Expand Down
42 changes: 42 additions & 0 deletions tests/unit/CommentUnitTests.d
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,23 @@ q"D
D", true);
}

unittest
{
Options options;
options.packageName = "a";
options.outputFile = "b.h";

assertTranslates(
q"C
/* Header comment. */
C",
q"D
/* Header comment. */

module a.b;
D", options, true);
}

// Test disabled comments.
unittest
{
Expand All @@ -33,6 +50,31 @@ q"D
D", options, false);
}

unittest
{
Options options;
options.packageName = "a";
options.outputFile = "a.h";
options.globalImports = ["b"];

assertTranslates(
"/**\n * comment with trailing whitespace \n * \n**/\n\n#pragma once\n\n#define A 1\n",
q"D
/**
* comment with trailing whitespace
*
**/

module a.a;

import b;

extern (C):

enum A = 1;
D", options, true);
}

// Test single comment.
unittest
{
Expand Down