// for all others, include the necessary headers
#ifndef WX_PRECOMP
#include "wx/app.h"
+ #include "wx/crt.h"
#endif
#include "wx/cmdline.h"
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:
bool ParsePreprocessorOutput(const wxString& filename);
bool Compare();
- int CompareClasses(const wxClass* iface, const wxClassPtrArray& api);
+ 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);
bool IsToProcess(const wxString& headername) const
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;
// 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
// HELP_SWITCH was passed or a syntax error occurred
return 0;
}
-
- return 1;
-}
-
-void IfaceCheckApp::ShowProgress()
-{
- wxPrint(".");
- //fflush(stdout);
}
bool IfaceCheckApp::Compare()
{
- const wxClassArray& interface = m_doxyInterface.GetClasses();
+ const wxClassArray& interfaces = m_doxyInterface.GetClasses();
const wxClass* c;
- wxClassPtrArray api;
int mcount = 0, ccount = 0;
- LogMessage("Comparing the interface API to the real API (%d classes to compare)...",
- interface.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; i<interface.GetCount(); i++)
+ for (unsigned int i=0; i<interfaces.GetCount(); i++)
{
// only compare the methods which are available for the port
// for which the gcc XML was produced
- if (interface[i].GetAvailability() != wxPORT_UNKNOWN &&
- (interface[i].GetAvailability() & m_gccInterface.GetInterfacePort()) == 0) {
+ if (interfaces[i].GetAvailability() != wxPORT_UNKNOWN &&
+ (interfaces[i].GetAvailability() & m_gccInterface.GetInterfacePort()) == 0) {
if (g_verbose)
- LogMessage("skipping class '%s' since it's not available for the %s port.",
- interface[i].GetName(), m_gccInterface.GetInterfacePortName());
+ {
+ wxLogMessage("skipping class '%s' since it's not available for the %s port.",
+ interfaces[i].GetName(), m_gccInterface.GetInterfacePortName());
+ }
continue; // skip this method
}
// shorten the name of the header so the log file is more readable
// and also for calling IsToProcess() against it
- wxString header = wxFileName(interface[i].GetHeader()).GetFullName();
+ wxString header = wxFileName(interfaces[i].GetHeader()).GetFullName();
if (!IsToProcess(header))
continue; // skip this one
- wxString cname = interface[i].GetName();
-
- api.Empty();
+ wxString cname = interfaces[i].GetName();
// search in the real headers for i-th interface class; we search for
// both class cname and cnameBase since in wxWidgets world tipically
// class cname is platform-specific while the real public interface of
// that class is part of the cnameBase class.
- c = m_gccInterface.FindClass(cname);
- if (c) api.Add(c);
- c = m_gccInterface.FindClass(cname + "Base");
- if (c) api.Add(c);
+ /*c = m_gccInterface.FindClass(cname + "Base");
+ if (c) api.Add(c);*/
- // sometimes the platform-specific class is named "wxGeneric" + cname
- // or similar:
- c = m_gccInterface.FindClass("wxGeneric" + cname.Mid(2));
- if (c) api.Add(c);
- c = m_gccInterface.FindClass("wxGtk" + cname.Mid(2));
- if (c) api.Add(c);
+ c = m_gccInterface.FindClass(cname);
+ if (!c)
+ {
+ // sometimes the platform-specific class is named "wxGeneric" + cname
+ // or similar:
+ c = m_gccInterface.FindClass("wxGeneric" + cname.Mid(2));
+ if (!c)
+ {
+ c = m_gccInterface.FindClass("wxGtk" + cname.Mid(2));
+ }
+ }
- if (api.GetCount()>0) {
+ if (c) {
- // there is a class with exactly the same name!
- mcount += CompareClasses(&interface[i], api);
+ // there is a class with the same (logic) name!
+ mcount += CompareClasses(&interfaces[i], c);
} else {
- LogMessage("%s: couldn't find the real interface for the '%s' class",
+ wxLogMessage("%s: couldn't find the real interface for the '%s' class",
header, cname);
ccount++;
}
}
- 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()));
+ wxLogMessage("%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()));
+ wxLogMessage("%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;
}
-int IfaceCheckApp::CompareClasses(const wxClass* iface, const wxClassPtrArray& api)
+int IfaceCheckApp::CompareClasses(const wxClass* iface, const wxClass* api)
{
- wxString searchedclasses;
const wxMethod *real;
int count = 0;
- wxASSERT(iface && api.GetCount()>0);
-
- // build a string with the names of the API classes compared to iface
- for (unsigned int j=0; j<api.GetCount(); j++)
- searchedclasses += "/" + api[j]->GetName();
- searchedclasses.Remove(0, 1);
+ wxASSERT(iface && api);
// shorten the name of the header so the log file is more readable
wxString header = wxFileName(iface->GetHeader()).GetFullName();
for (unsigned int i=0; i<iface->GetMethodCount(); i++)
{
const wxMethod& m = iface->GetMethod(i);
- int matches = 0;
// only compare the methods which are available for the port
// for which the gcc XML was produced
(m.GetAvailability() & m_gccInterface.GetInterfacePort()) == 0) {
if (g_verbose)
- LogMessage("skipping method '%s' since it's not available for the %s port.",
+ {
+ wxLogMessage("skipping method '%s' since it's not available for the %s port.",
m.GetAsString(), m_gccInterface.GetInterfacePortName());
+ }
continue; // skip this method
}
// search in the methods of the api classes provided
- for (unsigned int j=0; j<api.GetCount(); j++)
- {
- real = api[j]->FindMethod(m);
- if (real)
- matches++; // there is a real matching prototype! It's ok!
- }
+ real = api->RecursiveUpwardFindMethod(m, &m_gccInterface);
- if (matches == 0)
+ // avoid some false positives:
+ if (!real && m.ActsAsDefaultCtor())
{
- bool exit = false;
- wxMethodPtrArray overloads;
-
- // try searching for methods with the same name but with
- // different return type / arguments / qualifiers
- for (unsigned int j=0; j<api.GetCount(); j++)
- {
- wxMethodPtrArray results = api[j]->FindMethodsNamed(m.GetName());
+ // build an artificial default ctor for this class:
+ wxMethod temp(m);
+ temp.GetArgumentTypes().Clear();
- // append "results" array to "overloads"
- WX_APPEND_ARRAY(overloads, results);
+ // repeat search:
+ real = api->RecursiveUpwardFindMethod(temp, &m_gccInterface);
+ }
+ // no matches?
+ if (!real)
+ {
+ bool proceed = true;
+ wxMethodPtrArray overloads =
+ api->RecursiveUpwardFindMethodsNamed(m.GetName(), &m_gccInterface);
+
+ // 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);
-#define HACK_TO_AUTO_CORRECT_ONLY_VIRTUAL_AND_CONST_ATTRIBUTES 1
-#if HACK_TO_AUTO_CORRECT_ONLY_VIRTUAL_AND_CONST_ATTRIBUTES
- for (unsigned int k=0; k<results.GetCount(); k++)
- if (results[k]->MatchesExceptForAttributes(m) &&
- results[k]->IsPureVirtual() == m.IsPureVirtual())
+ if (tmp == m)
{
- // fix default values of results[k]:
- wxMethod tmp(*results[k]);
- tmp.SetArgumentTypes(m.GetArgumentTypes());
+ // in this case, we can disregard this warning... the real
+ // method probably is included in WXWIN_COMPAT sections!
+ proceed = false; // skip this method
+ }
+ }
- // modify interface header
- if (FixMethod(iface->GetHeader(), &m, &tmp))
- wxLogMessage("Adjusted attributes of '%s' method", m.GetAsString());
+#define HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES 0
+#if HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES
+ for (unsigned int k=0; k<overloads.GetCount(); k++)
+ if (overloads[k]->MatchesExceptForAttributes(m))
+ {
+ // fix default values of results[k]:
+ wxMethod tmp(*overloads[k]);
+ tmp.SetArgumentTypes(m.GetArgumentTypes());
- exit = true;
- break;
+ // modify interface header
+ if (FixMethod(iface->GetHeader(), &m, &tmp))
+ {
+ wxLogMessage("Adjusted attributes of '%s' method", m.GetAsString());
}
- if (exit)
+ proceed = false;
break;
-#endif
- }
-
-#if HACK_TO_AUTO_CORRECT_ONLY_VIRTUAL_AND_CONST_ATTRIBUTES
- if (!exit)
- {
-#endif
+ }
+#endif // HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES
- if (overloads.GetCount()==0)
+ if (proceed)
{
- /*
- TODO: sometimes the interface headers re-document a method
- inherited from a base class even if the real header does
- not actually re-implement it.
- To avoid false positives, we'd need to search in the base classes
- of api[] classes and search for a matching method.
- */
- LogMessage("%s: real '%s' class has no method '%s'",
- header, searchedclasses, 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(), searchedclasses);
- else
- warning += wxString::Format(": in the real headers there is a method '%s' for '%s'"
- " but has different signature:\n",
- m.GetName(), searchedclasses);
-
- // get a list of the prototypes with _all_ possible attributes:
- warning += "\tdoxy header: " + m.GetAsString(true, true, true);
- for (unsigned int j=0; j<overloads.GetCount(); j++)
- warning += "\n\treal header: " + overloads[j]->GetAsString(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)
+ // 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);
+
+ wxLogWarning("%s", warning);
+ 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)
+ {
+ wxLogWarning("\tmanual fix is required");
+ }
+ }
+ else
+ {
+ wxASSERT(overloads.GetCount() == 1);
+
+ if (m_modify || m.IsCtor())
+ {
+ wxLogWarning("\tfixing it...");
- // 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_VIRTUAL_AND_CONST_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)
{
+ 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;
}
- // 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.",
+ 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;
}
// 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;
}
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);
+ 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(" ")
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++)
+ for (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);
}
wxASSERT(nStartColumn != wxNOT_FOUND);
// wrap lines too long at comma boundaries
- for (unsigned int i=0; i<toinsert.GetCount(); i++)
+ for (i=0; i<toinsert.GetCount(); i++)
{
size_t len = toinsert[i].Len();
if (len > WRAP_COLUMN)
}
// insert the new lines
- for (unsigned int i=0; i<toinsert.GetCount(); i++)
+ for (i=0; i<toinsert.GetCount(); i++)
file.InsertLine(toinsert[i], start+i);
// now save the modification
if (!file.Write()) {
- LogError("\tcan't save the '%s' header file.", header);
+ wxLogError("\tcan't save the '%s' header file.", header);
return false;
}
return false;
if (g_verbose)
- LogMessage("\tthe final row offset for following methods is %d lines.", nOffset);
+ {
+ wxLogMessage("\tthe final row offset for following methods is %d lines.", nOffset);
+ }
// update the other method's locations for those methods which belong to the modified header
// and are placed _below_ the modified method
wxClassPtrArray cToUpdate = m_doxyInterface.FindClassesDefinedIn(header);
- for (unsigned int i=0; i < cToUpdate.GetCount(); i++)
+ for (i=0; i < cToUpdate.GetCount(); i++)
{
- for (unsigned int j=0; j < cToUpdate[i]->GetMethodCount(); j++)
+ for (j=0; j < cToUpdate[i]->GetMethodCount(); j++)
{
wxMethod& m = cToUpdate[i]->GetMethod(j);
if (m.GetLocation() > iface->GetLocation())
{
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;
}
// 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;
}
}
}
- 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;
void IfaceCheckApp::PrintStatistics(long secs)
{
- LogMessage("wx real headers contains declaration of %d classes (%d methods)",
+ // these stats, for what regards the gcc XML, are all referred to the wxWidgets
+ // classes only!
+
+ 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());
- LogMessage("total processing took %d seconds.", secs);
+
+ // build a list of the undocumented wx classes
+ wxString list;
+ int undoc = 0;
+ const wxClassArray& arr = m_gccInterface.GetClasses();
+ for (unsigned int i=0; i<arr.GetCount(); i++) {
+ if (m_doxyInterface.FindClass(arr[i].GetName()) == NULL) {
+ list += arr[i].GetName() + ", ";
+ undoc++;
+ }
+ }
+
+ list.RemoveLast();
+ list.RemoveLast();
+
+ wxLogMessage("the list of the %d undocumented wx classes is: %s", undoc, list);
+ wxLogMessage("total processing took %d seconds.", secs);
}