]> git.saurik.com Git - wxWidgets.git/blobdiff - utils/ifacecheck/src/ifacecheck.cpp
fix typo: s/SetTimestamp/DisableTimestamp
[wxWidgets.git] / utils / ifacecheck / src / ifacecheck.cpp
index 2a07c143a64ee81cec3e757e3206976e492056a2..92192904f2424ee33aa06a6d6e06d3be12438168 100644 (file)
@@ -82,6 +82,7 @@ public:
     bool Compare();
     int CompareClasses(const wxClass* iface, const wxClass* api);
     bool FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api);
+    bool StringContainsMethodName(const wxString& str, const wxMethod* m);
 
     void ShowProgress();
     void PrintStatistics(long secs);
@@ -264,10 +265,10 @@ bool IfaceCheckApp::Compare()
         }
     }
 
-    LogMessage("%d methods (%.1f%%) of the interface headers do not exist in the real headers",
-               mcount, (float)(100.0 * mcount/m_doxyInterface.GetMethodCount()));
-    LogMessage("%d classes (%.1f%%) of the interface headers do not exist in the real headers",
-               ccount, (float)(100.0 * ccount/m_doxyInterface.GetClassesCount()));
+    LogMessage("%d on a total of %d methods (%.1f%%) of the interface headers do not exist in the real headers",
+               mcount, m_doxyInterface.GetMethodCount(), (float)(100.0 * mcount/m_doxyInterface.GetMethodCount()));
+    LogMessage("%d on a total of %d classes (%.1f%%) of the interface headers do not exist in the real headers",
+               ccount, m_doxyInterface.GetClassesCount(), (float)(100.0 * ccount/m_doxyInterface.GetClassesCount()));
 
     return true;
 }
@@ -301,24 +302,44 @@ int IfaceCheckApp::CompareClasses(const wxClass* iface, const wxClass* api)
         // search in the methods of the api classes provided
         real = api->RecursiveUpwardFindMethod(m, &m_gccInterface);
 
-        //
+        // avoid some false positives:
         if (!real && m.ActsAsDefaultCtor())
         {
-            // build an artifical default ctor for this class:
+            // build an artificial default ctor for this class:
             wxMethod temp(m);
             temp.GetArgumentTypes().Clear();
 
+            // repeat search:
             real = api->RecursiveUpwardFindMethod(temp, &m_gccInterface);
         }
 
+        // no matches?
         if (!real)
         {
+            bool proceed = true;
             wxMethodPtrArray overloads =
                 api->RecursiveUpwardFindMethodsNamed(m.GetName(), &m_gccInterface);
 
-#define HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES        1
+            // avoid false positives:
+            for (unsigned int k=0; k<overloads.GetCount(); k++)
+                if (overloads[k]->MatchesExceptForAttributes(m) &&
+                    m.IsDeprecated() && !overloads[k]->IsDeprecated())
+                {
+                    // maybe the iface method is marked as deprecated but the
+                    // real method is not?
+                    wxMethod tmp(*overloads[k]);
+                    tmp.SetDeprecated(true);
+
+                    if (tmp == m)
+                    {
+                        // in this case, we can disregard this warning... the real
+                        // method probably is included in WXWIN_COMPAT sections!
+                        proceed = false;    // skip this method
+                    }
+                }
+
+#define HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES        0
 #if HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES
-            bool exit = false;
             for (unsigned int k=0; k<overloads.GetCount(); k++)
                 if (overloads[k]->MatchesExceptForAttributes(m))
                 {
@@ -330,74 +351,76 @@ int IfaceCheckApp::CompareClasses(const wxClass* iface, const wxClass* api)
                     if (FixMethod(iface->GetHeader(), &m, &tmp))
                         LogMessage("Adjusted attributes of '%s' method", m.GetAsString());
 
-                    exit = true;
+                    proceed = false;
                     break;
                 }
-
-            if (!exit)
-            {
 #endif // HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES
 
-            if (overloads.GetCount()==0)
+            if (proceed)
             {
-                LogMessage("%s: real '%s' class and their parents have no method '%s'",
-                            header, api->GetName(), m.GetAsString());
-                // we've found no overloads
-            }
-            else
-            {
-                // first, output a warning
-                wxString warning = header;
-                if (overloads.GetCount()>1)
-                    warning += wxString::Format(": in the real headers there are %d overloads of '%s' for "
-                                                "'%s' all with different signatures:\n",
-                                                overloads.GetCount(), m.GetName(), api->GetName());
-                else {
-                    warning += wxString::Format(": in the real headers there is a method '%s' for '%s'"
-                                                " but has different signature:\n",
-                                                m.GetName(), api->GetName());
-                }
-
-                // get a list of the prototypes with _all_ possible attributes:
-                warning += "\tdoxy header: " + m.GetAsString(true, true, true, true);
-                for (unsigned int j=0; j<overloads.GetCount(); j++)
-                    warning += "\n\treal header: " + overloads[j]->GetAsString(true, true, true, true);
-
-                wxPrint(warning + "\n");
-                count++;
-
-                if (overloads.GetCount()>1)
+                if (overloads.GetCount()==0)
                 {
-                    // TODO: decide which of these overloads is the most "similar" to m
-                    //       and eventually modify it
-                    if (m_modify)
-                        wxPrint("\tmanual fix is required\n");
+                    LogMessage("%s: real '%s' class and their parents have no method '%s'",
+                                header, api->GetName(), m.GetAsString());
+                    // we've found no overloads
                 }
                 else
                 {
-                    wxASSERT(overloads.GetCount() == 1);
+                    // first, output a warning
+                    wxString warning = header;
+                    if (overloads.GetCount()>1)
+                        warning += wxString::Format(": in the real headers there are %d overloads of '%s' for "
+                                                    "'%s' all with different signatures:\n",
+                                                    overloads.GetCount(), m.GetName(), api->GetName());
+                    else {
+                        warning += wxString::Format(": in the real headers there is a method '%s' for '%s'"
+                                                    " but has different signature:\n",
+                                                    m.GetName(), api->GetName());
+                    }
 
-                    if (m_modify || m.IsCtor())
+                    // get a list of the prototypes with _all_ possible attributes:
+                    warning += "\tdoxy header: " + m.GetAsString(true, true, true, true);
+                    for (unsigned int j=0; j<overloads.GetCount(); j++)
+                        warning += "\n\treal header: " + overloads[j]->GetAsString(true, true, true, true);
+
+                    wxPrint(warning + "\n");
+                    count++;
+
+                    if (overloads.GetCount()>1)
                     {
-                        wxPrint("\tfixing it...\n");
+                        // TODO: decide which of these overloads is the most "similar" to m
+                        //       and eventually modify it
+                        if (m_modify)
+                            wxPrint("\tmanual fix is required\n");
+                    }
+                    else
+                    {
+                        wxASSERT(overloads.GetCount() == 1);
+
+                        if (m_modify || m.IsCtor())
+                        {
+                            wxPrint("\tfixing it...\n");
 
-                        // try to modify it!
-                        FixMethod(iface->GetHeader(), &m, overloads[0]);
+                            // try to modify it!
+                            FixMethod(iface->GetHeader(), &m, overloads[0]);
+                        }
                     }
                 }
-            }
-
-            count++;
 
-#if HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES
-            }
-#endif
+                count++;
+            }       // if (proceed)
         }
     }
 
     return count;
 }
 
+bool IfaceCheckApp::StringContainsMethodName(const wxString& str, const wxMethod* m)
+{
+    return str.Contains(m->GetName()) ||
+           (m->IsOperator() && str.Contains("operator"));
+}
+
 bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api)
 {
     wxASSERT(iface && api);
@@ -408,7 +431,8 @@ bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, con
         return false;
     }
 
-    // GetLocation() returns the line where the last part of the prototype is placed:
+    // GetLocation() returns the line where the last part of the prototype is placed;
+    // i.e. the line containing the semicolon at the end of the declaration.
     int end = iface->GetLocation()-1;
     if (end <= 0 || end >= (int)file.GetLineCount()) {
         LogWarning("\tinvalid location info for method '%s': %d.",
@@ -425,7 +449,7 @@ bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, con
     // is this a one-line prototype declaration?
     bool founddecl = false;
     int start;
-    if (file.GetLine(end).Contains(iface->GetName()))
+    if (StringContainsMethodName(file.GetLine(end), iface))
     {
         // yes, this prototype is all on this line:
         start = end;
@@ -433,27 +457,27 @@ bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, con
     }
     else
     {
-        start = end-1;
+        start = end;    // will be decremented inside the while{} loop below
 
-        // find the start point of this prototype declaration:
-        while (start > 0 &&
-            !file.GetLine(start).Contains(";") &&
-            !file.GetLine(start).Contains("*/"))
+        // find the start point of this prototype declaration; i.e. the line
+        // containing the function name, which is also the line following
+        // the marker '*/' for the closure of the doxygen comment
+        do
         {
-            start--;
+            start--;        // go up one line
 
-            founddecl |= file.GetLine(start).Contains(iface->GetName());
+            if (StringContainsMethodName(file.GetLine(start), iface))
+                founddecl = true;
         }
-
-        // start-th line contains either the declaration of another prototype
-        // or the closing tag */ of a doxygen comment; start one line below
-        start++;
+        while (start > 0 && !founddecl &&
+               !file.GetLine(start).Contains(";") &&
+               !file.GetLine(start).Contains("*/"));
     }
 
     if (start <= 0 || !founddecl)
     {
-        LogError("\tcan't find the beginning of the declaration of '%s' method in '%s' header looking backwards from line %d",
-                    iface->GetAsString(), header, end);
+        LogError("\tcan't find the beginning of the declaration of '%s' method in '%s' header looking backwards from line %d; I arrived at %d and gave up",
+                 iface->GetAsString(), header, end+1 /* zero-based => 1-based */, start);
         return false;
     }
 
@@ -479,15 +503,23 @@ bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, con
 
     wxMethod tmp(*api);
 
-    // discard API argument names and replace them with those parsed from doxygen XML:
+    // discard gcc XML argument names and replace them with those parsed from doxygen XML;
+    // in this way we should avoid introducing doxygen warnings about cases where the argument
+    // 'xx' of the prototype is called 'yy' in the function's docs.
     const wxArgumentTypeArray& doxygenargs = iface->GetArgumentTypes();
     const wxArgumentTypeArray& realargs = api->GetArgumentTypes();
     if (realargs.GetCount() == doxygenargs.GetCount())
     {
         for (unsigned int j=0; j<doxygenargs.GetCount(); j++)
             if (doxygenargs[j]==realargs[j])
+            {
                 realargs[j].SetArgumentName(doxygenargs[j].GetArgumentName());
 
+                if (realargs[j].GetDefaultValue().IsNumber() &&
+                    doxygenargs[j].GetDefaultValue().StartsWith("wx"))
+                    realargs[j].SetDefaultValue(doxygenargs[j].GetDefaultValue());
+            }
+
         tmp.SetArgumentTypes(realargs);
     }