bool ParsePreprocessorOutput(const wxString& filename);
bool Compare();
- int CompareClasses(const wxClass* iface, const wxClassPtrArray& api);
- void FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api);
+ int CompareClasses(const wxClass* iface, const wxClass* api);
+ bool FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api);
void ShowProgress();
void PrintStatistics(long secs);
}
protected:
- wxXmlGccInterface m_api; // "real" headers API
- wxXmlDoxygenInterface m_interface; // doxygen-commented headers API
+ wxXmlGccInterface m_gccInterface; // "real" headers API
+ wxXmlDoxygenInterface m_doxyInterface; // doxygen-commented headers API
// was the MODIFY_SWITCH passed?
bool m_modify;
}
// in any case set basic std preprocessor #defines:
- m_interface.AddPreprocessorValue("NULL", "0");
+ 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_api.Parse(parser.GetParam(0)) ||
- !m_interface.Parse(parser.GetParam(1)))
+ 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);
- m_api.Dump(API_DUMP_FILE);
+ m_gccInterface.Dump(API_DUMP_FILE);
LogMessage("Dumping interface API to '%s'...", INTERFACE_DUMP_FILE);
- m_interface.Dump(INTERFACE_DUMP_FILE);
+ m_doxyInterface.Dump(INTERFACE_DUMP_FILE);
}
else
{
m_strToMatch = m_strToMatch.Mid(1, len-2);
}
+
ok = Compare();
}
// HELP_SWITCH was passed or a syntax error occurred
return 0;
}
-
- return 1;
}
void IfaceCheckApp::ShowProgress()
bool IfaceCheckApp::Compare()
{
- const wxClassArray& interface = m_interface.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());
+ interfaces.GetCount());
if (!m_strToMatch.IsEmpty())
LogMessage("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 (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.",
+ 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
- // for both class cname and cnameBase as in wxWidgets world, most often
+ // 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_api.FindClass(cname);
- if (c) api.Add(c);
- c = m_api.FindClass(cname + "Base");
- if (c) api.Add(c);
+ /*c = m_gccInterface.FindClass(cname + "Base");
+ 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("%d methods (%.1f%%) of the interface headers do not exist in the real headers",
- mcount, (float)(100.0 * mcount/m_interface.GetMethodCount()));
+ 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_interface.GetClassesCount()));
+ ccount, (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;
- // 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!
+ // only compare the methods which are available for the port
+ // for which the gcc XML was produced
+ if (m.GetAvailability() != wxPORT_UNKNOWN &&
+ (m.GetAvailability() & m_gccInterface.GetInterfacePort()) == 0) {
+
+ if (g_verbose)
+ LogMessage("skipping method '%s' since it's not available for the %s port.",
+ m.GetAsString(), m_gccInterface.GetInterfacePortName());
+
+ continue; // skip this method
}
- if (matches == 0)
+ // search in the methods of the api classes provided
+ real = api->RecursiveUpwardFindMethod(m, &m_gccInterface);
+
+ if (real)
{
- wxMethodPtrArray overloads;
+ bool exit = false;
+ wxMethodPtrArray overloads =
+ api->RecursiveUpwardFindMethodsNamed(m.GetName(), &m_gccInterface);
+
+#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) &&
+ overloads[k]->IsPureVirtual() == m.IsPureVirtual())
+ {
+ // fix default values of results[k]:
+ wxMethod tmp(*overloads[k]);
+ tmp.SetArgumentTypes(m.GetArgumentTypes());
- // try searching for a method with the same name but with
- // different return type / arguments / qualifiers
- for (unsigned int j=0; j<api.GetCount(); j++)
- {
- wxMethodPtrArray results = api[j]->FindMethodNamed(m.GetName());
+ // modify interface header
+ if (FixMethod(iface->GetHeader(), &m, &tmp))
+ LogMessage("Adjusted attributes of '%s' method", m.GetAsString());
- // append "results" array to "overloads"
- WX_APPEND_ARRAY(overloads, results);
- }
+ exit = true;
+ break;
+ }
+
+ if (!exit)
+ {
+#endif
if (overloads.GetCount()==0)
{
- /*
- 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());
+ LogMessage("%s: real '%s' class and their parents have no method '%s'",
+ header, api->GetName(), m.GetAsString());
// we've found no overloads
}
else
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);
+ 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(), searchedclasses);
+ m.GetName(), api->GetName());
- warning += "\tdoxy header: " + m.GetAsString();
+ // 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();
+ warning += "\n\treal header: " + overloads[j]->GetAsString(true, true, true, true);
wxPrint(warning + "\n");
count++;
}
count++;
+
+#if HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES
+ }
+#endif
}
}
return count;
}
-void IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api)
+bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api)
{
wxASSERT(iface && api);
wxTextFile file;
if (!file.Open(header)) {
LogError("\tcan't open the '%s' header file.", header);
- return;
+ return false;
}
// GetLocation() returns the line where the last part of the prototype is placed:
if (end <= 0 || end >= (int)file.GetLineCount()) {
LogWarning("\tinvalid location info for method '%s': %d.",
iface->GetAsString(), iface->GetLocation());
- return;
+ return false;
}
if (!file.GetLine(end).Contains(";")) {
LogWarning("\tinvalid location info for method '%s': %d.",
iface->GetAsString(), iface->GetLocation());
- return;
+ return false;
}
- // find the start point of this prototype declaration:
- int start = end-1;
+ // is this a one-line prototype declaration?
bool founddecl = false;
- while (start > 0 &&
- !file.GetLine(start).Contains(";") &&
- !file.GetLine(start).Contains("*/"))
+ int start;
+ if (file.GetLine(end).Contains(iface->GetName()))
+ {
+ // yes, this prototype is all on this line:
+ start = end;
+ founddecl = true;
+ }
+ else
{
- start--;
+ start = end-1;
+
+ // find the start point of this prototype declaration:
+ while (start > 0 &&
+ !file.GetLine(start).Contains(";") &&
+ !file.GetLine(start).Contains("*/"))
+ {
+ start--;
+
+ founddecl |= file.GetLine(start).Contains(iface->GetName());
+ }
- founddecl |= file.GetLine(start).Contains(iface->GetName());
+ // start-th line contains either the declaration of another prototype
+ // or the closing tag */ of a doxygen comment; start one line below
+ start++;
}
if (start <= 0 || !founddecl)
{
- LogError("\tcan't find the beginning of the declaration of '%s' method in '%s' header",
- iface->GetAsString(), header);
- return;
+ LogError("\tcan't find the beginning of the declaration of '%s' method in '%s' header looking backwards from line %d",
+ iface->GetAsString(), header, end);
+ return false;
}
- // start-th line contains either the declaration of another prototype
- // or the closing tag */ of a doxygen comment; start one line below
- start++;
-
// remove the old prototype
for (int i=start; i<=end; i++)
file.RemoveLine(start); // remove (end-start)-nth times the start-th line
// now save the modification
if (!file.Write()) {
LogError("\tcan't save the '%s' header file.", header);
- return;
+ return false;
}
// how many lines did we add/remove in total?
int nOffset = toinsert.GetCount() + deprecationOffset - (end-start+1);
if (nOffset == 0)
- return;
+ return false;
if (g_verbose)
LogMessage("\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_interface.FindClassesDefinedIn(header);
+ wxClassPtrArray cToUpdate = m_doxyInterface.FindClassesDefinedIn(header);
for (unsigned int i=0; i < cToUpdate.GetCount(); i++)
{
for (unsigned int j=0; j < cToUpdate[i]->GetMethodCount(); j++)
}
}
}
+
+ return true;
}
bool IfaceCheckApp::ParsePreprocessorOutput(const wxString& filename)
// the format of this line should be:
// #define DEFNAME DEFVALUE
- if (!line.StartsWith("#define ") || !defnameval.Contains(" ")) {
- LogError("unexpected content in '%s' at line %d.", filename, i);
+ if (!line.StartsWith("#define ")) {
+ LogError("unexpected content in '%s' at line %d.", filename, i+1);
return false;
}
- // get DEFNAME
- wxString defname = defnameval.BeforeFirst(' ');
- if (defname.Contains("("))
- continue; // this is a macro, skip it!
-
- // get DEFVAL
- wxString defval = defnameval.AfterFirst(' ').Strip(wxString::both);
- if (defval.StartsWith("(") && defval.EndsWith(")"))
- defval = defval.Mid(1, defval.Len()-2);
-
- // store this pair in the doxygen interface, where it can be useful
- m_interface.AddPreprocessorValue(defname, defval);
- useful++;
+ if (defnameval.Contains(" "))
+ {
+ // get DEFNAME
+ wxString defname = defnameval.BeforeFirst(' ');
+ if (defname.Contains("("))
+ continue; // this is a macro, skip it!
+
+ // get DEFVAL
+ wxString defval = defnameval.AfterFirst(' ').Strip(wxString::both);
+ if (defval.StartsWith("(") && defval.EndsWith(")"))
+ defval = defval.Mid(1, defval.Len()-2);
+
+ // store this pair in the doxygen interface, where it can be useful
+ m_doxyInterface.AddPreprocessorValue(defname, defval);
+ useful++;
+ }
+ else
+ {
+ // it looks like the format of this line is:
+ // #define DEFNAME
+ // we are not interested to symbols #defined to nothing,
+ // so we just ignore this line.
+ }
}
LogMessage("Parsed %d preprocessor #defines from '%s' which will be used later...",
void IfaceCheckApp::PrintStatistics(long secs)
{
LogMessage("wx real headers contains declaration of %d classes (%d methods)",
- m_api.GetClassesCount(), m_api.GetMethodCount());
+ m_gccInterface.GetClassesCount(), m_gccInterface.GetMethodCount());
LogMessage("wx interface headers contains declaration of %d classes (%d methods)",
- m_interface.GetClassesCount(), m_interface.GetMethodCount());
+ m_doxyInterface.GetClassesCount(), m_doxyInterface.GetMethodCount());
LogMessage("total processing took %d seconds.", secs);
}