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 From 2b0f02aa5cc0f7d1b460d2d324d5d08c6f6d61b9 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 13 Feb 2014 11:13:30 +0100 Subject: moc: Fix parsing of operator< MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit moc would skip the 'operator' keyword as unknown and try to parse a type again but as it sees the '<' it looks for the corresponding '>' which does not exist types can't start with '<' anyway, so return an invalid type and continue parsing as usual Task-number: QTBUG-36834 Change-Id: If3d27076ef9947abf8c57c594713eece9334d0b0 Reviewed-by: Simon Hausmann Reviewed-by: Jędrzej Nowacki --- src/tools/moc/moc.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src/tools/moc') diff --git a/src/tools/moc/moc.cpp b/src/tools/moc/moc.cpp index 22cbb97364..b26fac5dcf 100644 --- a/src/tools/moc/moc.cpp +++ b/src/tools/moc/moc.cpp @@ -224,6 +224,10 @@ Type Moc::parseType() ; } if (test(LANGLE)) { + if (type.name.isEmpty()) { + // '<' cannot start a type + return type; + } type.name += lexemUntil(RANGLE); } if (test(SCOPE)) { -- cgit v1.2.3