fixed some false positives; fixed method declaration-position detection also for operators

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@56534 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2008-10-27 21:16:01 +00:00
parent ae3b14872b
commit 83fdf79672
3 changed files with 40 additions and 16 deletions

View File

@@ -82,6 +82,7 @@ public:
bool Compare(); bool Compare();
int CompareClasses(const wxClass* iface, const wxClass* api); int CompareClasses(const wxClass* iface, const wxClass* api);
bool FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api); bool FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api);
bool StringContainsMethodName(const wxString& str, const wxMethod* m);
void ShowProgress(); void ShowProgress();
void PrintStatistics(long secs); void PrintStatistics(long secs);
@@ -398,6 +399,12 @@ int IfaceCheckApp::CompareClasses(const wxClass* iface, const wxClass* api)
return count; 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) bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, const wxMethod* api)
{ {
wxASSERT(iface && api); wxASSERT(iface && api);
@@ -408,7 +415,8 @@ bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, con
return false; 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; int end = iface->GetLocation()-1;
if (end <= 0 || end >= (int)file.GetLineCount()) { if (end <= 0 || end >= (int)file.GetLineCount()) {
LogWarning("\tinvalid location info for method '%s': %d.", LogWarning("\tinvalid location info for method '%s': %d.",
@@ -425,7 +433,7 @@ bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, con
// is this a one-line prototype declaration? // is this a one-line prototype declaration?
bool founddecl = false; bool founddecl = false;
int start; int start;
if (file.GetLine(end).Contains(iface->GetName())) if (StringContainsMethodName(file.GetLine(end), iface))
{ {
// yes, this prototype is all on this line: // yes, this prototype is all on this line:
start = end; start = end;
@@ -433,27 +441,27 @@ bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, con
} }
else else
{ {
start = end-1; start = end; // will be decremented inside the while{} loop below
// find the start point of this prototype declaration: // find the start point of this prototype declaration; i.e. the line
while (start > 0 && // containing the function name, which is also the line following
!file.GetLine(start).Contains(";") && // the marker '*/' for the closure of the doxygen comment
!file.GetLine(start).Contains("*/")) do
{ {
start--; start--; // go up one line
founddecl |= file.GetLine(start).Contains(iface->GetName()); if (StringContainsMethodName(file.GetLine(start), iface))
founddecl = true;
} }
while (start > 0 && !founddecl &&
// start-th line contains either the declaration of another prototype !file.GetLine(start).Contains(";") &&
// or the closing tag */ of a doxygen comment; start one line below !file.GetLine(start).Contains("*/"));
start++;
} }
if (start <= 0 || !founddecl) if (start <= 0 || !founddecl)
{ {
LogError("\tcan't find the beginning of the declaration of '%s' method in '%s' header looking backwards from line %d", 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); iface->GetAsString(), header, end+1 /* zero-based => 1-based */, start);
return false; return false;
} }
@@ -479,15 +487,23 @@ bool IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, con
wxMethod tmp(*api); 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& doxygenargs = iface->GetArgumentTypes();
const wxArgumentTypeArray& realargs = api->GetArgumentTypes(); const wxArgumentTypeArray& realargs = api->GetArgumentTypes();
if (realargs.GetCount() == doxygenargs.GetCount()) if (realargs.GetCount() == doxygenargs.GetCount())
{ {
for (unsigned int j=0; j<doxygenargs.GetCount(); j++) for (unsigned int j=0; j<doxygenargs.GetCount(); j++)
if (doxygenargs[j]==realargs[j]) if (doxygenargs[j]==realargs[j])
{
realargs[j].SetArgumentName(doxygenargs[j].GetArgumentName()); 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); tmp.SetArgumentTypes(realargs);
} }

View File

@@ -81,6 +81,9 @@ void wxType::SetTypeFromString(const wxString& t)
m_strType.Replace(" ,", ","); m_strType.Replace(" ,", ",");
// ADHOC-FIX
m_strType.Replace("_wxArraywxArrayStringBase", "const wxString&");
m_strType = m_strType.Strip(wxString::both); m_strType = m_strType.Strip(wxString::both);
@@ -107,6 +110,7 @@ void wxType::SetTypeFromString(const wxString& t)
m_strTypeClean.Replace("wxDateTime::", ""); m_strTypeClean.Replace("wxDateTime::", "");
m_strTypeClean.Replace("wxStockGDI::", ""); // same story for some other classes m_strTypeClean.Replace("wxStockGDI::", ""); // same story for some other classes
m_strTypeClean.Replace("wxHelpEvent::", ""); m_strTypeClean.Replace("wxHelpEvent::", "");
m_strTypeClean.Replace("wxWindowID", "int");
} }
bool wxType::IsOk() const bool wxType::IsOk() const

View File

@@ -213,11 +213,14 @@ public: // getters
{ return m_retType==wxEmptyType && !m_strName.StartsWith("~"); } { return m_retType==wxEmptyType && !m_strName.StartsWith("~"); }
bool IsDtor() const bool IsDtor() const
{ return m_retType==wxEmptyType && m_strName.StartsWith("~"); } { return m_retType==wxEmptyType && m_strName.StartsWith("~"); }
bool IsOperator() const
{ return m_strName.StartsWith("operator"); }
bool IsDeprecated() const bool IsDeprecated() const
{ return m_bDeprecated; } { return m_bDeprecated; }
public: // setters public: // setters
void SetReturnType(const wxType& t) void SetReturnType(const wxType& t)
@@ -263,6 +266,7 @@ public: // misc
// argument, thus is able to act also as default ctor // argument, thus is able to act also as default ctor
bool ActsAsDefaultCtor() const; bool ActsAsDefaultCtor() const;
// dumps the contents of this class in the given stream
void Dump(wxTextOutputStream& stream) const; void Dump(wxTextOutputStream& stream) const;
protected: protected: