From ed2bf996b31876613c146a63c6c3474f506a7c34 Mon Sep 17 00:00:00 2001 From: Hackerpilot Date: Sun, 15 Mar 2015 02:57:06 -0700 Subject: [PATCH] Fix #27 --- src/dfmt.d | 17 +++++++++++------ tests/allman/issue0027.d.ref | 21 +++++++++++++++++++++ tests/issue0027.d | 22 ++++++++++++++++++++++ tests/otbs/issue0027.d.ref | 19 +++++++++++++++++++ 4 files changed, 73 insertions(+), 6 deletions(-) create mode 100644 tests/allman/issue0027.d.ref create mode 100644 tests/issue0027.d create mode 100644 tests/otbs/issue0027.d.ref 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(); + } +}