further additions to avoid false warnings (ActsAsDefaultCtor, better wxArgumentType::SetDefaultValue)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56314 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2008-10-14 19:49:48 +00:00
parent 1a78714d95
commit f3998820a3
3 changed files with 71 additions and 31 deletions

View File

@@ -301,17 +301,26 @@ int IfaceCheckApp::CompareClasses(const wxClass* iface, const wxClass* api)
// search in the methods of the api classes provided // search in the methods of the api classes provided
real = api->RecursiveUpwardFindMethod(m, &m_gccInterface); real = api->RecursiveUpwardFindMethod(m, &m_gccInterface);
//
if (!real && m.ActsAsDefaultCtor())
{
// build an artifical default ctor for this class:
wxMethod temp(m);
temp.GetArgumentTypes().Clear();
real = api->RecursiveUpwardFindMethod(temp, &m_gccInterface);
}
if (!real) if (!real)
{ {
wxMethodPtrArray overloads = wxMethodPtrArray overloads =
api->RecursiveUpwardFindMethodsNamed(m.GetName(), &m_gccInterface); api->RecursiveUpwardFindMethodsNamed(m.GetName(), &m_gccInterface);
#define HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES 0 #define HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES 1
#if HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES #if HACK_TO_AUTO_CORRECT_ONLY_METHOD_ATTRIBUTES
bool exit = false; bool exit = false;
for (unsigned int k=0; k<overloads.GetCount(); k++) for (unsigned int k=0; k<overloads.GetCount(); k++)
if (overloads[k]->MatchesExceptForAttributes(m) && if (overloads[k]->MatchesExceptForAttributes(m))
overloads[k]->IsPureVirtual() == m.IsPureVirtual())
{ {
// fix default values of results[k]: // fix default values of results[k]:
wxMethod tmp(*overloads[k]); wxMethod tmp(*overloads[k]);
@@ -368,7 +377,7 @@ int IfaceCheckApp::CompareClasses(const wxClass* iface, const wxClass* api)
{ {
wxASSERT(overloads.GetCount() == 1); wxASSERT(overloads.GetCount() == 1);
if (m_modify) if (m_modify || m.IsCtor())
{ {
wxPrint("\tfixing it...\n"); wxPrint("\tfixing it...\n");
@@ -601,6 +610,9 @@ bool IfaceCheckApp::ParsePreprocessorOutput(const wxString& filename)
void IfaceCheckApp::PrintStatistics(long secs) 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)", LogMessage("wx real headers contains declaration of %d classes (%d methods)",
m_gccInterface.GetClassesCount(), m_gccInterface.GetMethodCount()); m_gccInterface.GetClassesCount(), m_gccInterface.GetMethodCount());
LogMessage("wx interface headers contains declaration of %d classes (%d methods)", LogMessage("wx interface headers contains declaration of %d classes (%d methods)",

View File

@@ -59,11 +59,15 @@ void wxType::SetTypeFromString(const wxString& t)
which works at char-level and does everything in a single pass which works at char-level and does everything in a single pass
*/ */
// clean the type string
// ---------------------
m_strType = t; m_strType = t;
// [] is the same as * for gccxml // [] is the same as * for gccxml
m_strType.Replace("[]", "*"); m_strType.Replace("[]", "*");
m_strType.Replace("long int", "long"); // in wx typically we never write "long int", just "long" m_strType.Replace("long int", "long"); // in wx typically we never write "long int", just "long"
m_strType.Replace("long unsigned int", "unsigned long");
// make sure the * and & operator always use the same spacing rules // make sure the * and & operator always use the same spacing rules
// (to make sure GetAsString() output is always consistent) // (to make sure GetAsString() output is always consistent)
@@ -79,8 +83,12 @@ void wxType::SetTypeFromString(const wxString& t)
m_strType = m_strType.Strip(wxString::both); m_strType = m_strType.Strip(wxString::both);
// now set the clean version
m_strTypeClean = m_strType;
// clean the type string (this time for the comparison)
// ----------------------------------------------------
m_strTypeClean = m_strType; // begin with the already-cleaned string
m_strTypeClean.Replace("const", ""); m_strTypeClean.Replace("const", "");
m_strTypeClean.Replace("static", ""); m_strTypeClean.Replace("static", "");
m_strTypeClean.Replace("*", ""); m_strTypeClean.Replace("*", "");
@@ -141,25 +149,36 @@ bool wxType::operator==(const wxType& m) const
void wxArgumentType::SetDefaultValue(const wxString& defval, const wxString& defvalForCmp) void wxArgumentType::SetDefaultValue(const wxString& defval, const wxString& defvalForCmp)
{ {
m_strDefaultValue = defval.Strip(wxString::both); m_strDefaultValue = defval.Strip(wxString::both);
m_strDefaultValueForCmp = defvalForCmp.IsEmpty() ? m_strDefaultValue : defvalForCmp.Strip(wxString::both); m_strDefaultValueForCmp = defvalForCmp.IsEmpty() ?
m_strDefaultValue : defvalForCmp.Strip(wxString::both);
// adjust aesthetic form of DefaultValue for the modify mode of ifacecheck:
// we may need to write it out in an interface header
if (m_strDefaultValue == "0u")
m_strDefaultValue = "0";
// in order to make valid&simple comparison on argument defaults, // clean the default argument strings
// we reduce some of the multiple forms in which the same things may appear // ----------------------------------
// to a single form:
if (m_strDefaultValueForCmp == "0u")
m_strDefaultValueForCmp = "0";
m_strDefaultValue.Replace("0x000000001", "1"); // Note: we adjust the aesthetic form of the m_strDefaultValue string for the "modify mode"
m_strDefaultValueForCmp.Replace("0x000000001", "1"); // of ifacecheck: we may need to write it out in an interface header
// fix for unicode strings: wxString *p;
m_strDefaultValue.Replace("\\000\\000\\000", ""); for (int i=0; i<2; i++) // to avoid copying&pasting the code!
m_strDefaultValueForCmp.Replace("\\000\\000\\000", ""); {
if (i == 0) p = &m_strDefaultValue;
if (i == 1) p = &m_strDefaultValueForCmp;
if (*p == "0u") *p = "0";
p->Replace("0x000000001", "1");
p->Replace("\\000\\000\\000", ""); // fix for unicode strings:
// ADHOC-FIX: for wxConv* default values
p->Replace("wxConvAuto(wxFONTENCODING_DEFAULT)", "wxConvAuto()");
p->Replace("wxGet_wxConvUTF8()", "wxConvUTF8");
p->Replace("wxGet_wxConvLocal()", "wxConvLocal");
}
// clean ONLY the default argument string specific for comparison
// --------------------------------------------------------------
if (m_strDefaultValueForCmp.StartsWith("wxT(") && if (m_strDefaultValueForCmp.StartsWith("wxT(") &&
m_strDefaultValueForCmp.EndsWith(")")) m_strDefaultValueForCmp.EndsWith(")"))
@@ -169,21 +188,12 @@ void wxArgumentType::SetDefaultValue(const wxString& defval, const wxString& def
m_strDefaultValueForCmp = m_strDefaultValueForCmp.Mid(4,len-5); m_strDefaultValueForCmp = m_strDefaultValueForCmp.Mid(4,len-5);
} }
/*
if (IsPointer())
m_strDefaultValueForCmp.Replace("0", "NULL");
else
m_strDefaultValueForCmp.Replace("NULL", "0");
*/
// ADHOC-FIX: // ADHOC-FIX:
// doxygen likes to put wxDateTime:: in front of all wxDateTime enums; // doxygen likes to put wxDateTime:: in front of all wxDateTime enums;
// fix this to avoid false positives // fix this to avoid false positives
m_strDefaultValueForCmp.Replace("wxDateTime::", ""); m_strDefaultValueForCmp.Replace("wxDateTime::", "");
m_strDefaultValueForCmp.Replace("wxStockGDI::", ""); // same story for some other classes m_strDefaultValueForCmp.Replace("wxStockGDI::", ""); // same story for some other classes
m_strDefaultValueForCmp.Replace("wxHelpEvent::", ""); // same story for some other classes m_strDefaultValueForCmp.Replace("wxHelpEvent::", ""); // same story for some other classes
m_strDefaultValueForCmp.Replace("wxGet_wxConvLocal()", "wxConvLocal");
m_strDefaultValueForCmp.Replace("* GetColour(COLOUR_BLACK)", "*wxBLACK"); m_strDefaultValueForCmp.Replace("* GetColour(COLOUR_BLACK)", "*wxBLACK");
// ADHOC-FIX: // ADHOC-FIX:
@@ -321,6 +331,18 @@ bool wxMethod::MatchesExceptForAttributes(const wxMethod& m) const
return true; return true;
} }
bool wxMethod::ActsAsDefaultCtor() const
{
if (!IsCtor())
return false;
for (unsigned int i=0; i<m_args.GetCount(); i++)
if (!m_args[i].HasDefaultValue())
return false;
return true;
}
bool wxMethod::operator==(const wxMethod& m) const bool wxMethod::operator==(const wxMethod& m) const
{ {
// check attributes // check attributes

View File

@@ -188,7 +188,9 @@ public: // getters
{ return m_retType; } { return m_retType; }
wxString GetName() const wxString GetName() const
{ return m_strName; } { return m_strName; }
wxArgumentTypeArray GetArgumentTypes() const const wxArgumentTypeArray& GetArgumentTypes() const
{ return m_args; }
wxArgumentTypeArray& GetArgumentTypes()
{ return m_args; } { return m_args; }
int GetLocation() const int GetLocation() const
{ return m_nLine; } { return m_nLine; }
@@ -257,6 +259,10 @@ public: // misc
// except for the method attributes (const,static,virtual,pureVirtual,deprecated) // except for the method attributes (const,static,virtual,pureVirtual,deprecated)
bool MatchesExceptForAttributes(const wxMethod& m) const; bool MatchesExceptForAttributes(const wxMethod& m) const;
// returns true if this is a ctor which has default values for all its
// argument, thus is able to act also as default ctor
bool ActsAsDefaultCtor() const;
void Dump(wxTextOutputStream& stream) const; void Dump(wxTextOutputStream& stream) const;
protected: protected: