From: Oswald Buddenhagen Date: Fri, 26 Jul 2013 17:46:15 +0000 (+0200) Subject: fix handling of c'tors with namespaced parent classes X-Git-Tag: accepted/tizen/20131212.181521~89^2~18 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=51ceecc96159e5d096b1cfa320db5d41c009387f;p=platform%2Fupstream%2Fqttools.git fix handling of c'tors with namespaced parent classes this is achieved by setting yyTokColonSeen under much narrower conditions (when we are pretty sure that we are seeing the start of a c'tor's initializer list), which allows us to unset it under much narrower conditions (when we are pretty sure we are seeing the start of the c'tor's body), so we now actually *do* skip over qualifications which would confuse us. Change-Id: Ic04bad57a08cc66d41094775570d25e7288e6324 Reviewed-by: hjk Reviewed-by: Oswald Buddenhagen --- diff --git a/src/linguist/lupdate/cpp.cpp b/src/linguist/lupdate/cpp.cpp index 7cd3db0..37547bd 100644 --- a/src/linguist/lupdate/cpp.cpp +++ b/src/linguist/lupdate/cpp.cpp @@ -293,7 +293,7 @@ private: enum { Tok_Eof, Tok_class, Tok_friend, Tok_namespace, Tok_using, Tok_return, Tok_tr, Tok_trUtf8, Tok_translate, Tok_translateUtf8, Tok_trid, - Tok_Q_OBJECT, Tok_Q_DECLARE_TR_FUNCTIONS, + Tok_Q_OBJECT, Tok_Q_DECLARE_TR_FUNCTIONS, Tok_Access, Tok_Ident, Tok_Comment, Tok_String, Tok_Arrow, Tok_Colon, Tok_ColonColon, Tok_Equals, Tok_LeftBracket, Tok_RightBracket, Tok_LeftBrace, Tok_RightBrace, Tok_LeftParen, Tok_RightParen, Tok_Comma, Tok_Semicolon, @@ -499,6 +499,13 @@ STRING(tr); STRING(trUtf8); STRING(translate); STRING(using); +STRING(private); +STRING(protected); +STRING(public); +STRING(slots); +STRING(signals); +STRING(Q_SLOTS); +STRING(Q_SIGNALS); uint CppParser::getToken() { @@ -730,6 +737,8 @@ uint CppParser::getToken() return Tok_translateUtf8; if (yyWord == strQT_TRANSLATE_NOOP3_UTF8) return Tok_translateUtf8; + if (yyWord == strQ_SLOTS || yyWord == strQ_SIGNALS) + return Tok_Access; break; case 'T': // TR() for when all else fails @@ -768,6 +777,10 @@ uint CppParser::getToken() yyCh = getChar(); } break; + case 'p': + if (yyWord == strpublic || yyWord == strprotected || yyWord == strprivate) + return Tok_Access; + break; case 'q': if (yyWord == strqtTrId) return Tok_trid; @@ -779,6 +792,8 @@ uint CppParser::getToken() case 's': if (yyWord == strstruct) return Tok_class; + if (yyWord == strslots || yyWord == strsignals) + return Tok_Access; break; case 't': if (yyWord == strtr) @@ -1658,7 +1673,6 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac yyTok = getToken(); break; case Tok_class: - yyTokColonSeen = false; /* Partial support for inlined functions. */ @@ -1727,7 +1741,6 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac } break; case Tok_namespace: - yyTokColonSeen = false; yyTok = getToken(); if (yyTok == Tok_Ident) { text = yyWord; @@ -2138,17 +2151,25 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac msgid.clear(); extra.clear(); } - yyTokColonSeen = false; yyTok = getToken(); break; + case Tok_Access: + // Eat access specifiers, so their colons are not mistaken for c'tor initializer list starts + do { + yyTok = getToken(); + } while (yyTok == Tok_Access); // Multiple specifiers are possible, e.g. "public slots" + if (yyTok == Tok_Colon) + goto case_default; + break; case Tok_Colon: - yyTokColonSeen = true; - // fallthrough case Tok_Equals: - if (!prospectiveContext.isEmpty() - && yyBraceDepth == namespaceDepths.count() && yyParenDepth == 0) { - pendingContext = prospectiveContext; - prospectiveContext.clear(); + if (yyBraceDepth == namespaceDepths.count() && yyParenDepth == 0) { + if (!prospectiveContext.isEmpty()) { + pendingContext = prospectiveContext; + prospectiveContext.clear(); + } + if (yyTok == Tok_Colon) + yyTokColonSeen = true; } yyTok = getToken(); break; @@ -2158,10 +2179,10 @@ void CppParser::parseInternal(ConversionData &cd, const QStringList &includeStac pendingContext = prospectiveContext; prospectiveContext.clear(); } + yyTokColonSeen = false; // fallthrough case Tok_LeftParen: case Tok_RightParen: - yyTokColonSeen = false; yyTok = getToken(); break; default: diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp index 4f6de5c..f2d6532 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp +++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp @@ -365,3 +365,25 @@ public: }; const char TestClass::TEST_STRING[] = QT_TR_NOOP("Test value"); + + + +// derivation from namespaced class +class Class42 : public NameSchpase::YetMoreFun, Gui::BaseClass +{ + Q_OBJECT + + Class42() : + NameSchpase::YetMoreFun(), + Gui::BaseClass() + { + tr("does that make sense?"); + } +}; + +Class42::Class42() : + NameSchpase::YetMoreFun(), + Gui::BaseClass() +{ + tr("and does that?"); +} diff --git a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result index d7c2b14..bea8445 100644 --- a/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result +++ b/tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result @@ -35,6 +35,19 @@ backslashed \ stuff. + Class42 + + + does that make sense? + + + + + and does that? + + + + Dialog2