From: Francesco Montorsi Date: Tue, 25 Mar 2008 16:07:46 +0000 (+0000) Subject: further improve the automatic modify mode: wrap correctly inserted prototypes at... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/7fbadf873c6e4e3b91e8d91b8ff78ecda3df16f2 further improve the automatic modify mode: wrap correctly inserted prototypes at comma boundaries, add @deprecated only if needed, update the locations of the methods below the fixed one git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@52816 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/utils/ifacecheck/src/ifacecheck.cpp b/utils/ifacecheck/src/ifacecheck.cpp index c119238532..033e29e5a1 100644 --- a/utils/ifacecheck/src/ifacecheck.cpp +++ b/utils/ifacecheck/src/ifacecheck.cpp @@ -324,34 +324,39 @@ void IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, con wxTextFile file; if (!file.Open(header)) { - LogError("can't open the '%s' header file.", header); + LogError("\tcan't open the '%s' header file.", header); return; } // GetLocation() returns the line where the last part of the prototype is placed: int end = iface->GetLocation()-1; if (end <= 0 || end >= (int)file.GetLineCount()) { - LogWarning("invalid location info for method '%s': %d.", + LogWarning("\tinvalid location info for method '%s': %d.", iface->GetAsString(), iface->GetLocation()); return; } - if (!file.GetLine(end).Contains(iface->GetName())) { - LogWarning("invalid location info for method '%s': %d.", + if (!file.GetLine(end).Contains(";")) { + LogWarning("\tinvalid location info for method '%s': %d.", iface->GetAsString(), iface->GetLocation()); return; } // find the start point of this prototype declaration: int start = end-1; + bool founddecl = false; while (start > 0 && !file.GetLine(start).Contains(";") && !file.GetLine(start).Contains("*/")) + { start--; - if (start <= 0) + founddecl |= file.GetLine(start).Contains(iface->GetName()); + } + + if (start <= 0 || !founddecl) { - LogError("can't find the beginning of the declaration of '%s' method in '%s' header", + LogError("\tcan't find the beginning of the declaration of '%s' method in '%s' header", iface->GetAsString(), header); return; } @@ -366,13 +371,18 @@ void IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, con #define INDENTATION_STR wxString(" ") - // if possible, add also the @deprecated tag in the doxygen comment - if (file.GetLine(start-1).Contains("*/") && api->IsDeprecated()) + // if possible, add also the @deprecated tag in the doxygen comment if it's missing + int deprecationOffset = 0; + if (file.GetLine(start-1).Contains("*/") && + (api->IsDeprecated() && !iface->IsDeprecated())) { file.RemoveLine(start-1); file.InsertLine(INDENTATION_STR + INDENTATION_STR + "@deprecated @todo provide deprecation description", start-1); file.InsertLine(INDENTATION_STR + "*/", start++); + + // we have added a new line in the final balance + deprecationOffset=1; } wxMethod tmp(*api); @@ -389,13 +399,66 @@ void IfaceCheckApp::FixMethod(const wxString& header, const wxMethod* iface, con tmp.SetArgumentTypes(realargs); } - // insert the new one - file.InsertLine(INDENTATION_STR + tmp.GetAsString() + ";", start); +#define WRAP_COLUMN 80 + + wxArrayString toinsert; + toinsert.Add(INDENTATION_STR + tmp.GetAsString() + ";"); + + int nStartColumn = toinsert[0].Find('('); + wxASSERT(nStartColumn != wxNOT_FOUND); + + // wrap lines too long at comma boundaries + for (unsigned int i=0; i WRAP_COLUMN) + { + wxASSERT(i == toinsert.GetCount()-1); + + // break this line + wxString tmpleft = toinsert[i].Left(WRAP_COLUMN); + int comma = tmpleft.Find(',', true /* from end */); + if (comma == wxNOT_FOUND) + break; // break out of the for cycle... + + toinsert.Add(wxString(' ', nStartColumn+1) + + toinsert[i].Right(len-comma-2)); // exclude the comma and the space after it + toinsert[i] = tmpleft.Left(comma+1); // include the comma + } + } + + // insert the new lines + for (unsigned int i=0; iGetMethodCount(); j++) + { + wxMethod& m = cToUpdate[i]->GetMethod(j); + if (m.GetLocation() > iface->GetLocation()) + { + // update the location of this method + m.SetLocation(m.GetLocation()+nOffset); + } + } } } diff --git a/utils/ifacecheck/src/xmlparser.cpp b/utils/ifacecheck/src/xmlparser.cpp index 51e04d35a4..48dcdc2148 100644 --- a/utils/ifacecheck/src/xmlparser.cpp +++ b/utils/ifacecheck/src/xmlparser.cpp @@ -412,6 +412,18 @@ bool wxXmlInterface::CheckParseResults() const return true; } +wxClassPtrArray wxXmlInterface::FindClassesDefinedIn(const wxString& headerfile) const +{ + wxClassPtrArray ret; + + for (unsigned int i=0; iGetAttribute("incomplete") != "1") { - LogError("Invalid member IDs for '%s' class node (ID %s)", + LogError("Invalid member IDs for '%s' class node: %s", cname, child->GetAttribute("id")); return false; } @@ -587,7 +599,7 @@ bool wxXmlGccInterface::Parse(const wxString& filename) { // decode the non-empty list of IDs: if (!getMemberIDs(&members, &m_classes.Last(), ids)) { - LogError("Invalid member IDs for '%s' class node (ID %s)", + LogError("Invalid member IDs for '%s' class node: %s", cname, child->GetAttribute("id")); return false; } @@ -645,7 +657,7 @@ bool wxXmlGccInterface::Parse(const wxString& filename) else if (n == "File") { if (!child->GetAttribute("id").StartsWith("f")) { - LogError("Unexpected file ID: %s", id); + LogError("Unexpected file ID: %s", child->GetAttribute("id")); return false; } @@ -670,7 +682,8 @@ bool wxXmlGccInterface::Parse(const wxString& filename) // they're never used as return/argument types by wxWidgets methods if (g_verbose) - LogWarning("Type '%s' with ID '%s' does not have name attribute", n, id); + LogWarning("Type node '%s' with ID '%s' does not have name attribute", + n, child->GetAttribute("id")); types[id] = "TOFIX"; } @@ -797,12 +810,12 @@ bool wxXmlGccInterface::Parse(const wxString& filename) if (newfunc.IsCtor() && !p->IsValidCtorForThisClass(newfunc)) { LogError("The method '%s' does not seem to be a ctor for '%s'", - newfunc.GetName(), p->GetName()); + newfunc.GetName(), p->GetName()); return false; } if (newfunc.IsDtor() && !p->IsValidDtorForThisClass(newfunc)) { LogError("The method '%s' does not seem to be a dtor for '%s'", - newfunc.GetName(), p->GetName()); + newfunc.GetName(), p->GetName()); return false; } diff --git a/utils/ifacecheck/src/xmlparser.h b/utils/ifacecheck/src/xmlparser.h index b503a56d34..a002f4244d 100644 --- a/utils/ifacecheck/src/xmlparser.h +++ b/utils/ifacecheck/src/xmlparser.h @@ -294,6 +294,9 @@ public: return methods; } + // pass a full-path header filename: + wxClassPtrArray FindClassesDefinedIn(const wxString& headerfile) const; + void ShowProgress() { /*wxPrint(".");*/ }