improved support for typedefs

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55734 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Francesco Montorsi
2008-09-19 10:28:47 +00:00
parent dc7f9c9cee
commit 585a11d609
3 changed files with 43 additions and 10 deletions

View File

@@ -306,11 +306,11 @@ int IfaceCheckApp::CompareClasses(const wxClass* iface, const wxClassPtrArray& a
{ {
wxMethodPtrArray overloads; wxMethodPtrArray overloads;
// try searching for a method with the same name but with // try searching for methods with the same name but with
// different return type / arguments / qualifiers // different return type / arguments / qualifiers
for (unsigned int j=0; j<api.GetCount(); j++) for (unsigned int j=0; j<api.GetCount(); j++)
{ {
wxMethodPtrArray results = api[j]->FindMethodNamed(m.GetName()); wxMethodPtrArray results = api[j]->FindMethodsNamed(m.GetName());
// append "results" array to "overloads" // append "results" array to "overloads"
WX_APPEND_ARRAY(overloads, results); WX_APPEND_ARRAY(overloads, results);

View File

@@ -83,6 +83,11 @@ void wxType::SetTypeFromString(const wxString& t)
m_strTypeClean.Replace("&", ""); m_strTypeClean.Replace("&", "");
m_strTypeClean.Replace("[]", ""); m_strTypeClean.Replace("[]", "");
m_strTypeClean = m_strTypeClean.Strip(wxString::both); m_strTypeClean = m_strTypeClean.Strip(wxString::both);
// to avoid false errors types like wxStandardPaths and wxStandardPathsBase
// need to be considered as the same type
if (m_strTypeClean.EndsWith("Base"))
m_strTypeClean = m_strTypeClean.Left(m_strTypeClean.Len()-4);
} }
bool wxType::IsOk() const bool wxType::IsOk() const
@@ -363,6 +368,8 @@ bool wxClass::CheckConsistency() const
LogError("class %s has two methods with the same prototype: '%s'", LogError("class %s has two methods with the same prototype: '%s'",
m_strName, m_methods[i].GetAsString()); m_strName, m_methods[i].GetAsString());
return false; return false;
((wxClass*)this)->m_methods.RemoveAt(j);
j--;
} }
return true; return true;
@@ -376,7 +383,7 @@ const wxMethod* wxClass::FindMethod(const wxMethod& m) const
return NULL; return NULL;
} }
wxMethodPtrArray wxClass::FindMethodNamed(const wxString& name) const wxMethodPtrArray wxClass::FindMethodsNamed(const wxString& name) const
{ {
wxMethodPtrArray ret; wxMethodPtrArray ret;
@@ -444,6 +451,7 @@ wxClassPtrArray wxXmlInterface::FindClassesDefinedIn(const wxString& headerfile)
// wxXmlGccInterface helper declarations // wxXmlGccInterface helper declarations
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// or-able flags for a toResolveTypeItem->attrib:
#define ATTRIB_CONST 1 #define ATTRIB_CONST 1
#define ATTRIB_REFERENCE 2 #define ATTRIB_REFERENCE 2
#define ATTRIB_POINTER 4 #define ATTRIB_POINTER 4
@@ -458,7 +466,8 @@ public:
toResolveTypeItem(unsigned int refID, unsigned int attribint) toResolveTypeItem(unsigned int refID, unsigned int attribint)
: ref(refID), attribs(attribint) {} : ref(refID), attribs(attribint) {}
unsigned long ref, attribs; unsigned long ref, // the referenced type's ID
attribs; // the attributes of this reference
}; };
#if 1 #if 1
@@ -592,6 +601,7 @@ bool wxXmlGccInterface::Parse(const wxString& filename)
wxClassMemberIdHashMap members; wxClassMemberIdHashMap members;
wxTypeIdHashMap types; wxTypeIdHashMap types;
wxTypeIdHashMap files; wxTypeIdHashMap files;
wxTypeIdHashMap typedefs;
// prealloc quite a lot of memory! // prealloc quite a lot of memory!
m_classes.Alloc(ESTIMATED_NUM_CLASSES); m_classes.Alloc(ESTIMATED_NUM_CLASSES);
@@ -650,6 +660,23 @@ bool wxXmlGccInterface::Parse(const wxString& filename)
// register this class also as possible return/argument type: // register this class also as possible return/argument type:
types[id] = cname; types[id] = cname;
} }
else if (n == "Typedef")
{
unsigned long typeId = 0;
if (!getID(&typeId, child->GetAttribute("type"))) {
LogError("Invalid type for node %s: %s", n, child->GetAttribute("type"));
return false;
}
// this typedef node tell us that every type referenced with the
// "typeId" ID should be called with another name:
wxString name = child->GetAttribute("name");
// save this typedef in a separate hashmap...
typedefs[typeId] = name;
types[id] = name;
}
else if (n == "PointerType" || n == "ReferenceType" || else if (n == "PointerType" || n == "ReferenceType" ||
n == "CvQualifiedType" || n == "ArrayType") n == "CvQualifiedType" || n == "ArrayType")
{ {
@@ -689,11 +716,14 @@ bool wxXmlGccInterface::Parse(const wxString& filename)
} }
if (argstr.Len() > 0) if (argstr.Len() > 0)
argstr = argstr.Left(argstr.Len()-2); argstr = argstr.Left(argstr.Len()-2); // remove final comma
// these nodes make reference to other types... we'll resolve them later // these nodes make reference to other types... we'll resolve them later
//toResolveTypes[id] = toResolveTypeItem(ret, 0); //toResolveTypes[id] = toResolveTypeItem(ret, 0);
types[id] = child->GetAttribute("returns") + "(" + argstr + ")"; //types[id] = child->GetAttribute("returns") + "(" + argstr + ")";
types[id] = "TOFIX"; // typically this type will be "fixed" thanks
// to a typedef later...
} }
else if (n == "File") else if (n == "File")
{ {
@@ -737,7 +767,7 @@ bool wxXmlGccInterface::Parse(const wxString& filename)
} }
// some nodes with IDs referenced by methods as return/argument types, do reference // some nodes with IDs referenced by methods as return/argument types, do reference
// in turn o ther nodes (see PointerType, ReferenceType and CvQualifierType above); // in turn other nodes (see PointerType, ReferenceType and CvQualifierType above);
// thus we need to resolve their name iteratively: // thus we need to resolve their name iteratively:
while (toResolveTypes.size()>0) while (toResolveTypes.size()>0)
{ {
@@ -770,7 +800,10 @@ bool wxXmlGccInterface::Parse(const wxString& filename)
newtype = newtype + "[]"; newtype = newtype + "[]";
// add the resolved type to the list of "primary" types // add the resolved type to the list of "primary" types
types[id] = newtype; if (newtype.Contains("TOFIX") && typedefs[id] != "")
types[id] = typedefs[id]; // better use a typedef for this type!
else
types[id] = newtype;
// this one has been resolved; erase it through its iterator! // this one has been resolved; erase it through its iterator!
toResolveTypes.erase(i); toResolveTypes.erase(i);
@@ -793,7 +826,7 @@ bool wxXmlGccInterface::Parse(const wxString& filename)
} }
else else
{ {
LogError("Cannot solve '%s' reference type!", referenced); LogError("Cannot solve '%d' reference type!", referenced);
return false; return false;
} }
} }

View File

@@ -277,7 +277,7 @@ public: // misc
// returns an array of pointers to the overloaded methods with the // returns an array of pointers to the overloaded methods with the
// same given name // same given name
wxMethodPtrArray FindMethodNamed(const wxString& m) const; wxMethodPtrArray FindMethodsNamed(const wxString& m) const;
// dumps all methods to the given output stream // dumps all methods to the given output stream
void Dump(wxTextOutputStream& stream) const; void Dump(wxTextOutputStream& stream) const;