From 08575b966cc288786be4739caab15a06e089a2d5 Mon Sep 17 00:00:00 2001 From: helly Date: Sat, 31 Dec 2005 01:31:43 +0000 Subject: [PATCH] - Fix -wb's switch/case --- code.cc | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/code.cc b/code.cc index 03b1c443..76f836e7 100644 --- a/code.cc +++ b/code.cc @@ -522,8 +522,10 @@ void Go::genLinear(std::ostream &o, uint ind, const State *from, const State *ne doLinear(o, ind, span, nSpans, from, next, readCh, mask); } -void genCases(std::ostream &o, uint ind, uint lb, Span *s, bool &newLine) +bool genCases(std::ostream &o, uint ind, uint lb, Span *s, bool &newLine, uint mask) { + bool used = false; + if (!newLine) { o << "\n"; @@ -533,20 +535,26 @@ void genCases(std::ostream &o, uint ind, uint lb, Span *s, bool &newLine) { for (;;) { - o << indent(ind) << "case "; - prtChOrHex(o, lb); - o << ":"; + if (!mask || lb > 0x00FF) + { + o << indent(ind) << "case "; + prtChOrHex(o, lb); + o << ":"; + newLine = false; + used = true; + } if (++lb == s->ub) { - newLine = false; break; } o << "\n"; ++oline; + newLine = true; } } + return used; } void Go::genSwitch(std::ostream &o, uint ind, const State *from, const State *next, bool &readCh, uint mask) const @@ -591,15 +599,17 @@ void Go::genSwitch(std::ostream &o, uint ind, const State *from, const State *ne while (t != &sP[0]) { + bool used = false; + r = s = &sP[0]; if (*s == &span[0]) { - genCases(o, ind, 0, *s, newLine); + used |= genCases(o, ind, 0, *s, newLine, mask); } else { - genCases(o, ind, (*s)[ -1].ub, *s, newLine); + used |= genCases(o, ind, (*s)[ -1].ub, *s, newLine, mask); } State *to = (*s)->to; @@ -608,7 +618,7 @@ void Go::genSwitch(std::ostream &o, uint ind, const State *from, const State *ne { if ((*s)->to == to) { - genCases(o, ind, (*s)[ -1].ub, *s, newLine); + used |= genCases(o, ind, (*s)[ -1].ub, *s, newLine, mask); } else { @@ -616,8 +626,11 @@ void Go::genSwitch(std::ostream &o, uint ind, const State *from, const State *ne } } - genGoTo(o, newLine ? ind+1 : 1, from, to, readCh); - newLine = true; + if (used) + { + genGoTo(o, newLine ? ind+1 : 1, from, to, readCh); + newLine = true; + } t = r; } -- 2.40.0