From 2b26f801b5b49e2f354da0b67070917d25d5917d Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 4 Mar 2013 16:52:12 +0100 Subject: Make parsing of template arguments more robust. At first, my goal was just to fix Moc::until() to parse properly template arguments containing expressions containing > or >> such as Foo<(8>>2)> But with the test, I realized that normalizeType also requires change not to split the > > too much. And QMetaObjectPrivate::decodeMethodSignature should not interpret the ) within the template parameter as the end of the function. Change-Id: Ia9d3a2a786368aeda1edcf66280d70f64cf05070 Reviewed-by: Lars Knoll --- src/tools/moc/moc.cpp | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) (limited to 'src/tools/moc') diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 8ff481d5b1..22cbb97364 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -224,14 +224,7 @@ Type Moc::parseType() ; } if (test(LANGLE)) { - QByteArray templ = lexemUntil(RANGLE); - for (int i = 0; i < templ.size(); ++i) { - type.name += templ.at(i); - if ((templ.at(i) == '<' && i+1 < templ.size() && templ.at(i+1) == ':') - || (templ.at(i) == '>' && i+1 < templ.size() && templ.at(i+1) == '>')) { - type.name += ' '; - } - } + type.name += lexemUntil(RANGLE); } if (test(SCOPE)) { type.name += lexem(); @@ -1395,10 +1388,14 @@ QByteArray Moc::lexemUntil(Token target) QByteArray s; while (from <= index) { QByteArray n = symbols.at(from++-1).lexem(); - if (s.size() && n.size() - && is_ident_char(s.at(s.size()-1)) - && is_ident_char(n.at(0))) - s += ' '; + if (s.size() && n.size()) { + char prev = s.at(s.size()-1); + char next = n.at(0); + if ((is_ident_char(prev) && is_ident_char(next)) + || (prev == '<' && next == ':') + || (prev == '>' && next == '>')) + s += ' '; + } s += n; } return s; @@ -1433,9 +1430,20 @@ bool Moc::until(Token target) { case RBRACK: --brackCount; break; case LPAREN: ++parenCount; break; case RPAREN: --parenCount; break; - case LANGLE: ++angleCount; break; - case RANGLE: --angleCount; break; - case GTGT: angleCount -= 2; t = RANGLE; break; + case LANGLE: + if (parenCount == 0 && braceCount == 0 && parenCount == 0) + ++angleCount; + break; + case RANGLE: + if (parenCount == 0 && braceCount == 0) + --angleCount; + break; + case GTGT: + if (parenCount == 0 && braceCount == 0) { + angleCount -= 2; + t = RANGLE; + } + break; default: break; } if (t == target -- cgit v1.2.3