fix handling of c'tors with namespaced parent classes
authorOswald Buddenhagen <oswald.buddenhagen@digia.com>
Fri, 26 Jul 2013 17:46:15 +0000 (19:46 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Thu, 1 Aug 2013 11:37:37 +0000 (13:37 +0200)
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 <hjk121@nokiamail.com>
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
src/linguist/lupdate/cpp.cpp
tests/auto/linguist/lupdate/testdata/good/parsecpp/main.cpp
tests/auto/linguist/lupdate/testdata/good/parsecpp/project.ts.result

index 7cd3db0..37547bd 100644 (file)
@@ -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:
index 4f6de5c..f2d6532 100644 (file)
@@ -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?");
+}
index d7c2b14..bea8445 100644 (file)
@@ -35,6 +35,19 @@ backslashed \ stuff.</source>
     </message>
 </context>
 <context>
+    <name>Class42</name>
+    <message>
+        <location filename="main.cpp" line="380"/>
+        <source>does that make sense?</source>
+        <translation type="unfinished"></translation>
+    </message>
+    <message>
+        <location filename="main.cpp" line="388"/>
+        <source>and does that?</source>
+        <translation type="unfinished"></translation>
+    </message>
+</context>
+<context>
     <name>Dialog2</name>
     <message numerus="yes">
         <location filename="main.cpp" line="70"/>