diff options
author | Kai Pastor <dg0yt@darc.de> | 2016-04-03 09:44:36 +0200 |
---|---|---|
committer | Kai Pastor <dg0yt@darc.de> | 2016-04-28 16:07:59 +0000 |
commit | 4ea581c95ae9704b250591c5d4d9b0517f5b62f2 (patch) | |
tree | 113919959a4296387d87b301ed93ceca1d494d46 /src | |
parent | e1520db966debc5ad2d5dd26ec297073367697c1 (diff) |
lupdate: Explicitly handle C++ member initializer lists
This change makes the cpp parser explicitly deal with parens and
braces in member initializer lists of constructors. It fixes
problems with C++11 syntax like list-initialization and lambdas.
It adds auto tests for tr() calls in initialization expressions.
The combination of parens in base class template parameters with
list initialization (braces) remains unsupported.
Task-number: QTBUG-34128
Task-number: QTBUG-42166
Change-Id: Id4ac0a011fcda8d2b72a15348a1b96fdd492ab32
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/linguist/lupdate/cpp.cpp | 53 |
1 files changed, 37 insertions, 16 deletions
diff --git a/src/linguist/lupdate/cpp.cpp b/src/linguist/lupdate/cpp.cpp index bf6d86de8..02a667320 100644 --- a/src/linguist/lupdate/cpp.cpp +++ b/src/linguist/lupdate/cpp.cpp @@ -1757,6 +1757,7 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac QString functionName; #endif bool yyTokColonSeen = false; // Start of c'tor's initializer list + bool yyTokIdentSeen = false; // Start of initializer (member or base class) metaExpected = true; prospectiveContext.clear(); @@ -1978,6 +1979,11 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac yyTok = getToken(); break; case Tok_Ident: + if (yyTokColonSeen && + yyBraceDepth == namespaceDepths.count() && yyParenDepth == 0) { + // member or base class identifier + yyTokIdentSeen = true; + } yyTok = getToken(); if (yyTok == Tok_LeftParen) { switch (trFunctionAliasManager.trFunctionByName(yyWord)) { @@ -2034,6 +2040,11 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac } break; case Tok_ColonColon: + if (yyTokIdentSeen) { + // member or base class identifier + yyTok = getToken(); + break; + } if (yyBraceDepth == namespaceDepths.count() && yyParenDepth == 0 && !yyTokColonSeen) prospectiveContext = prefix; prefix += strColons; @@ -2046,16 +2057,20 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac #endif break; case Tok_RightBrace: - if (yyBraceDepth + 1 == namespaceDepths.count()) // class or namespace - truncateNamespaces(&namespaces, namespaceDepths.pop()); - if (yyBraceDepth == namespaceDepths.count()) { - // function, class or namespace - if (!yyBraceDepth && !directInclude) - truncateNamespaces(&functionContext, 1); - else - functionContext = namespaces; - functionContextUnresolved.clear(); - pendingContext.clear(); + if (!yyTokColonSeen) { + if (yyBraceDepth + 1 == namespaceDepths.count()) { + // class or namespace + truncateNamespaces(&namespaces, namespaceDepths.pop()); + } + if (yyBraceDepth == namespaceDepths.count()) { + // function, class or namespace + if (!yyBraceDepth && !directInclude) + truncateNamespaces(&functionContext, 1); + else + functionContext = namespaces; + functionContextUnresolved.clear(); + pendingContext.clear(); + } } // fallthrough case Tok_Semicolon: @@ -2094,15 +2109,21 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac yyTok = getToken(); break; case Tok_LeftBrace: - if (!prospectiveContext.isEmpty() - && yyBraceDepth == namespaceDepths.count() + 1 && yyParenDepth == 0) { - pendingContext = prospectiveContext; - prospectiveContext.clear(); + if (yyBraceDepth == namespaceDepths.count() + 1 && yyParenDepth == 0) { + if (!prospectiveContext.isEmpty()) { + pendingContext = prospectiveContext; + prospectiveContext.clear(); + } + if (!yyTokIdentSeen) { + // Function body + yyTokColonSeen = false; + } } - yyTokColonSeen = false; // fallthrough - case Tok_Comma: case Tok_LeftParen: + yyTokIdentSeen = false; + // fallthrough + case Tok_Comma: case Tok_QuestionMark: metaExpected = true; yyTok = getToken(); |