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
20 changes: 17 additions & 3 deletions dstep/translator/Output.d
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class Output

private uint lastestOffset = 0;
private uint lastestLine = 0;
private uint lastContentLine = 0;
private uint headerEndOffset = 0;

this(Output parent)
Expand All @@ -231,6 +232,7 @@ class Output
commentIndex = parent.commentIndex;
lastestOffset = parent.lastestOffset;
lastestLine = parent.lastestLine;
lastContentLine = parent.lastContentLine;
}

this(
Expand Down Expand Up @@ -268,6 +270,7 @@ class Output

lastestOffset = 0;
lastestLine = 0;
lastContentLine = 0;
headerEndOffset = 0;
}

Expand Down Expand Up @@ -325,6 +328,7 @@ class Output

lastestOffset = max(lastestOffset, output.lastestOffset);
lastestLine = max(lastestLine, output.lastestLine);
lastContentLine = max(lastContentLine, output.lastContentLine);
}
}

Expand All @@ -348,6 +352,7 @@ class Output
indent();
formattedWrite(buffer, fmt, args);
stack.back = Entity.singleLine;
lastContentLine = lastestLine;

if (first == Entity.bottom)
first = Entity.singleLine;
Expand Down Expand Up @@ -469,6 +474,8 @@ class Output
if (first == Entity.bottom)
first = Entity.adaptiveLine;

lastContentLine = lastestLine;

auto parts = adaptiveLineParts(fmt, args);

chunks.put(Chunk(ChunkType.opening, parts[0], parts[1]));
Expand Down Expand Up @@ -715,13 +722,17 @@ D"[0 .. $ - 1]);
}
}
}

lastContentLine = comment.extent.end.line;
}

private void comment(in CommentIndex.Comment comment)
{
if (lastestLine == comment.line)
auto wasInline = false;
if (lastContentLine == comment.line)
{
buffer.put(" ");
wasInline = true;
}
else if (stack.back != Entity.bottom)
{
Expand All @@ -736,11 +747,14 @@ D"[0 .. $ - 1]);

writeComment(comment);

stack.back = Entity.comment;

if (first == Entity.bottom)
first = Entity.comment;

if (!wasInline && lastestLine == comment.extent.end.line)
stack.back = Entity.separator;
else
stack.back = Entity.comment;

lastestLine = comment.extent.end.line;
lastestOffset = comment.extent.end.offset;
}
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/CommentUnitTests.d
Original file line number Diff line number Diff line change
Expand Up @@ -339,3 +339,35 @@ struct Foo
D");

}

// Comment inside taken #ifdef branch must not join extern (C): line.
unittest
{
assertTranslates(
q"C
#define G1

#ifdef G1 // Guard1
#define A 1
#else
#define A 2
#endif

#ifdef G2 // Guard2
#define B 3
#else
#define B 4
#endif
C",
q"D
extern (C):

// Guard1

enum A = 1;

// Guard2

enum B = 4;
D", true);
}