X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/83fdf79672dfe71b6c0bb9ea52a7df723a292b12..124a5e3e6ab203dcbed670d586dc53a28e4c97a7:/utils/ifacecheck/src/ifacecheck.cpp diff --git a/utils/ifacecheck/src/ifacecheck.cpp b/utils/ifacecheck/src/ifacecheck.cpp index fc71239f59..13aca6a97e 100644 --- a/utils/ifacecheck/src/ifacecheck.cpp +++ b/utils/ifacecheck/src/ifacecheck.cpp @@ -70,6 +70,19 @@ static const wxCmdLineEntryDesc g_cmdLineDesc[] = wxCMD_LINE_DESC_END }; +class IfaceCheckLog : public wxLog +{ +public: + IfaceCheckLog() {} + + virtual void DoLogText(const wxString& msg) + { + // send all messages to stdout (normal behaviour is to sent them to stderr) + wxPuts(msg); + fflush(stdout); + } +}; + class IfaceCheckApp : public wxAppConsole { public: @@ -84,7 +97,6 @@ public: 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); bool IsToProcess(const wxString& headername) const @@ -117,6 +129,10 @@ int IfaceCheckApp::OnRun() wxString::Format("wxWidgets Interface checker utility (built %s against %s)", __DATE__, wxVERSION_STRING)); + // make the output more readable: + wxLog::SetActiveTarget(new IfaceCheckLog); + wxLog::DisableTimestamp(); + // parse the command line... bool ok = true; wxString preprocFile; @@ -137,22 +153,18 @@ int IfaceCheckApp::OnRun() // in any case set basic std preprocessor #defines: m_doxyInterface.AddPreprocessorValue("NULL", "0"); - //g_bLogEnabled = false; - // parse the two XML files which contain the real and the doxygen interfaces // for wxWidgets API: if (!m_gccInterface.Parse(parser.GetParam(0)) || !m_doxyInterface.Parse(parser.GetParam(1))) return 1; - g_bLogEnabled = true; - if (parser.Found(DUMP_SWITCH)) { - LogMessage("Dumping real API to '%s'...", API_DUMP_FILE); + wxLogMessage("Dumping real API to '%s'...", API_DUMP_FILE); m_gccInterface.Dump(API_DUMP_FILE); - LogMessage("Dumping interface API to '%s'...", INTERFACE_DUMP_FILE); + wxLogMessage("Dumping interface API to '%s'...", INTERFACE_DUMP_FILE); m_doxyInterface.Dump(INTERFACE_DUMP_FILE); } else @@ -192,23 +204,19 @@ int IfaceCheckApp::OnRun() } } -void IfaceCheckApp::ShowProgress() -{ - wxPrint("."); - //fflush(stdout); -} - bool IfaceCheckApp::Compare() { const wxClassArray& interfaces = m_doxyInterface.GetClasses(); const wxClass* c; int mcount = 0, ccount = 0; - LogMessage("Comparing the interface API to the real API (%d classes to compare)...", - interfaces.GetCount()); + wxLogMessage("Comparing the interface API to the real API (%d classes to compare)...", + interfaces.GetCount()); if (!m_strToMatch.IsEmpty()) - LogMessage("Processing only header files matching '%s' expression.", m_strToMatch); + { + wxLogMessage("Processing only header files matching '%s' expression.", m_strToMatch); + } for (unsigned int i=0; iRecursiveUpwardFindMethod(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; kMatchesExceptForAttributes(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; kMatchesExceptForAttributes(m)) { @@ -329,70 +361,70 @@ int IfaceCheckApp::CompareClasses(const wxClass* iface, const wxClass* api) // modify interface header if (FixMethod(iface->GetHeader(), &m, &tmp)) - LogMessage("Adjusted attributes of '%s' method", m.GetAsString()); + { + wxLogMessage("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) - { - LogMessage("%s: real '%s' class and their parents have no method '%s'", - header, api->GetName(), m.GetAsString()); - // we've found no overloads - } - else + if (proceed) { - // 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; jGetAsString(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"); + wxLogMessage("%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; jGetAsString(true, true, true, true); + + wxLogWarning("%s", warning); + count++; + + if (overloads.GetCount()>1) + { + // TODO: decide which of these overloads is the most "similar" to m + // and eventually modify it + if (m_modify) + { + wxLogWarning("\tmanual fix is required"); + } + } + else { - wxPrint("\tfixing it...\n"); + wxASSERT(overloads.GetCount() == 1); - // try to modify it! - FixMethod(iface->GetHeader(), &m, overloads[0]); + if (m_modify || m.IsCtor()) + { + wxLogWarning("\tfixing it..."); + + // try to modify it! + FixMethod(iface->GetHeader(), &m, overloads[0]); + } } } - } - - count++; -#if HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES - } -#endif + count++; + } // if (proceed) } } @@ -407,11 +439,12 @@ bool IfaceCheckApp::StringContainsMethodName(const wxString& str, const wxMethod bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api) { + unsigned int i,j; wxASSERT(iface && api); wxTextFile file; if (!file.Open(header)) { - LogError("\tcan't open the '%s' header file.", header); + wxLogError("\tcan't open the '%s' header file.", header); return false; } @@ -419,13 +452,13 @@ bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, con // 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.", + wxLogWarning("\tinvalid location info for method '%s': %d.", iface->GetAsString(), iface->GetLocation()); return false; } if (!file.GetLine(end).Contains(";")) { - LogWarning("\tinvalid location info for method '%s': %d.", + wxLogWarning("\tinvalid location info for method '%s': %d.", iface->GetAsString(), iface->GetLocation()); return false; } @@ -460,13 +493,13 @@ bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, con if (start <= 0 || !founddecl) { - 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", + wxLogError("\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; } // remove the old prototype - for (int i=start; i<=end; i++) + for (int k=start; k<=end; k++) file.RemoveLine(start); // remove (end-start)-nth times the start-th line #define INDENTATION_STR wxString(" ") @@ -494,7 +527,7 @@ bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, con const wxArgumentTypeArray& realargs = api->GetArgumentTypes(); if (realargs.GetCount() == doxygenargs.GetCount()) { - for (unsigned int j=0; j WRAP_COLUMN) @@ -536,12 +569,12 @@ bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, con } // insert the new lines - for (unsigned int i=0; iGetMethodCount(); j++) + for (j=0; j < cToUpdate[i]->GetMethodCount(); j++) { wxMethod& m = cToUpdate[i]->GetMethod(j); if (m.GetLocation() > iface->GetLocation()) @@ -576,7 +611,7 @@ bool IfaceCheckApp::ParsePreprocessorOutput(const wxString& filename) { wxTextFile tf; if (!tf.Open(filename)) { - LogError("can't open the '%s' preprocessor output file.", filename); + wxLogError("can't open the '%s' preprocessor output file.", filename); return false; } @@ -589,7 +624,7 @@ bool IfaceCheckApp::ParsePreprocessorOutput(const wxString& filename) // the format of this line should be: // #define DEFNAME DEFVALUE if (!line.StartsWith("#define ")) { - LogError("unexpected content in '%s' at line %d.", filename, i+1); + wxLogError("unexpected content in '%s' at line %d.", filename, i+1); return false; } @@ -618,7 +653,7 @@ bool IfaceCheckApp::ParsePreprocessorOutput(const wxString& filename) } } - LogMessage("Parsed %d preprocessor #defines from '%s' which will be used later...", + wxLogMessage("Parsed %d preprocessor #defines from '%s' which will be used later...", useful, filename); return true; @@ -629,9 +664,9 @@ void IfaceCheckApp::PrintStatistics(long secs) // these stats, for what regards the gcc XML, are all referred to the wxWidgets // classes only! - LogMessage("wx real headers contains declaration of %d classes (%d methods)", + wxLogMessage("wx real headers contains declaration of %d classes (%d methods)", m_gccInterface.GetClassesCount(), m_gccInterface.GetMethodCount()); - LogMessage("wx interface headers contains declaration of %d classes (%d methods)", + wxLogMessage("wx interface headers contains declaration of %d classes (%d methods)", m_doxyInterface.GetClassesCount(), m_doxyInterface.GetMethodCount()); // build a list of the undocumented wx classes @@ -648,7 +683,7 @@ void IfaceCheckApp::PrintStatistics(long secs) list.RemoveLast(); list.RemoveLast(); - LogMessage("the list of the %d undocumented wx classes is: %s", undoc, list); - LogMessage("total processing took %d seconds.", secs); + wxLogMessage("the list of the %d undocumented wx classes is: %s", undoc, list); + wxLogMessage("total processing took %d seconds.", secs); }