diff options
author | Olivier Goffart <ogoffart@woboq.com> | 2013-03-04 16:52:12 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-14 09:42:53 +0100 |
commit | 2b26f801b5b49e2f354da0b67070917d25d5917d (patch) | |
tree | c3542211d7827e2d05cbf18281af00c16d99e89b /src/tools/moc | |
parent | 8e261ac756132baeb857fb15013cde126ffa22cc (diff) |
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 <lars.knoll@digia.com>
Diffstat (limited to 'src/tools/moc')
-rw-r--r-- | src/tools/moc/moc.cpp | 38 |
1 files changed, 23 insertions, 15 deletions
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 |