diff --git a/src/dfmt.d b/src/dfmt.d index 2385d40..8eba3fb 100644 --- a/src/dfmt.d +++ b/src/dfmt.d @@ -173,22 +173,26 @@ private: assert(index < tokens.length); if (currentIs(tok!"comment")) { + immutable bool currIsSlashSlash = tokens[index].text[0 .. 2] == "//"; if (index > 0) { immutable t = tokens[index - 1].type; - if (t != tok!";" && t != tok!"}" && tokens[index - 1].line + 1 < tokens[index] - .line) + immutable bool prevWasSlashSlash = t == tok!"comment" + && tokens[index - 1].text[0 .. 2] == "//"; + immutable bool shouldSkipNewline = prevWasSlashSlash && !currIsSlashSlash + && tokens[index - 1].line + 2 <= tokens[index].line; + if (!shouldSkipNewline && t != tok!";" && t != tok!"}" + && tokens[index - 1].line + 1 < tokens[index].line) { newline(); } - else if (tokens[index - 1].line == tokens[index].line) + else if (tokens[index - 1].line == tokens[index].line + || (t == tok!")" && tokens[index + 1].type == tok!"{")) write(" "); - else if (isWrapIndent(t)) - pushWrapIndent(t); } writeToken(); immutable j = justAddedExtraNewline; - if (tokens[index - 1].text[0 .. 2] == "//") + if (currIsSlashSlash) { newline(); justAddedExtraNewline = j; @@ -1019,6 +1023,7 @@ private: { output.put("\n"); } + justAddedExtraNewline = false; currentLineLength = 0; diff --git a/tests/allman/issue0027.d.ref b/tests/allman/issue0027.d.ref new file mode 100644 index 0000000..683f0d2 --- /dev/null +++ b/tests/allman/issue0027.d.ref @@ -0,0 +1,21 @@ +SignExtendedNumber opMul(const SignExtendedNumber a) const +{ + // like 0x10 * 0x10 == 0x100 == 0. + + /* Special handling for zeros: + */ +} + +unittest +{ + if (Port.isNan(r1) || Port.isNan(r2)) // if unordered + { + } + + while (cur && cur.ty == Tsarray) // sizes of dimensions + { + TypeSArray sa = cast(TypeSArray) cur; + mangleNumber(sa.dim ? sa.dim.toInteger() : 0); + cur = cur.nextOf(); + } +} diff --git a/tests/issue0027.d b/tests/issue0027.d new file mode 100644 index 0000000..442e856 --- /dev/null +++ b/tests/issue0027.d @@ -0,0 +1,22 @@ +SignExtendedNumber opMul(const SignExtendedNumber a) const +{ + // like 0x10 * 0x10 == 0x100 == 0. + + /* Special handling for zeros: + */ +} + +unittest +{ + if (Port.isNan(r1) || Port.isNan(r2)) // if unordered + { + } + + while (cur && cur.ty == Tsarray) + // sizes of dimensions + { + TypeSArray sa = cast(TypeSArray) cur; + mangleNumber(sa.dim ? sa.dim.toInteger() : 0); + cur = cur.nextOf(); + } +} diff --git a/tests/otbs/issue0027.d.ref b/tests/otbs/issue0027.d.ref new file mode 100644 index 0000000..922af48 --- /dev/null +++ b/tests/otbs/issue0027.d.ref @@ -0,0 +1,19 @@ +SignExtendedNumber opMul(const SignExtendedNumber a) const { + // like 0x10 * 0x10 == 0x100 == 0. + + /* Special handling for zeros: + */ +} + +unittest { + if (Port.isNan(r1) || Port.isNan(r2)) // if unordered + { + } + + while (cur && cur.ty == Tsarray) // sizes of dimensions + { + TypeSArray sa = cast(TypeSArray) cur; + mangleNumber(sa.dim ? sa.dim.toInteger() : 0); + cur = cur.nextOf(); + } +}