1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Parser of the API/interface XML files
4 // Author: Francesco Montorsi
7 // Copyright: (c) 2008 Francesco Montorsi
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
18 // for all others, include the necessary headers
22 #include "wx/xml/xml.h"
23 #include "wx/wfstream.h"
24 #include "wx/hashmap.h"
25 #include "wx/filename.h"
26 #include "xmlparser.h"
29 #include <wx/arrimpl.cpp>
30 WX_DEFINE_OBJARRAY(wxTypeArray
)
31 WX_DEFINE_OBJARRAY(wxArgumentTypeArray
)
32 WX_DEFINE_OBJARRAY(wxMethodArray
)
33 WX_DEFINE_OBJARRAY(wxClassArray
)
36 #define PROGRESS_RATE 1000 // each PROGRESS_RATE nodes processed print a dot
37 #define ESTIMATED_NUM_CLASSES 600 // used by both wxXmlInterface-derived classes to prealloc mem
40 // defined in ifacecheck.cpp
41 extern bool g_verbose
;
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
51 void wxType::SetTypeFromString(const wxString
& t
)
54 TODO: optimize the following code writing a single function
55 which works at char-level and does everything in a single pass
60 // [] is the same as * for gccxml
61 m_strType
.Replace("[]", "*");
62 m_strType
.Replace("long int", "long"); // in wx typically we never write "long int", just "long"
64 // make sure the * and & operator always use the same spacing rules
65 // (to make sure GetAsString() output is always consistent)
66 m_strType
.Replace("*", "* ");
67 m_strType
.Replace("&", "& ");
68 m_strType
.Replace(" *", "*");
69 m_strType
.Replace(" &", "&");
71 while (m_strType
.Contains(" "))
72 m_strType
.Replace(" ", " "); // do it once again
74 m_strType
.Replace(" ,", ",");
76 m_strType
= m_strType
.Strip(wxString::both
);
79 bool wxType::IsOk() const
81 // NB: m_strType can contain the :: operator; think to e.g. the
82 // "reverse_iterator_impl<wxString::const_iterator>" type
83 // It can also contain commas, * and & operators etc
85 return !GetClean().IsEmpty();
88 wxString
wxType::GetClean() const
90 wxString
ret(m_strType
);
91 ret
.Replace("const", "");
92 ret
.Replace("static", "");
95 ret
.Replace("[]", "");
96 return ret
.Strip(wxString::both
);
99 bool wxType::operator==(const wxType
& m
) const
101 // brain-dead comparison:
103 if (GetClean() == m
.GetClean() &&
104 IsConst() == m
.IsConst() &&
105 IsStatic() == m
.IsStatic() &&
106 IsPointer() == m
.IsPointer() &&
107 IsReference() == m
.IsReference())
114 // ----------------------------------------------------------------------------
116 // ----------------------------------------------------------------------------
118 void wxArgumentType::SetDefaultValue(const wxString
& defval
)
120 m_strDefaultValue
=defval
.Strip(wxString::both
);
122 // in order to make valid&simple comparison on argument defaults,
123 // we reduce some of the multiple forms in which the same things may appear
125 m_strDefaultValue
.Replace("0u", "0");
128 m_strDefaultValue
.Replace("0", "NULL");
130 m_strDefaultValue
.Replace("NULL", "0");
133 if (m_strDefaultValue
.Contains("wxGetTranslation"))
134 m_strDefaultValue
= "_(TOFIX)"; // TODO: wxGetTranslation gives problems to gccxml
137 bool wxArgumentType::operator==(const wxArgumentType
& m
) const
139 if ((const wxType
&)(*this) != (const wxType
&)m
)
142 if (m_strDefaultValue
!= m
.m_strDefaultValue
)
145 // we deliberately avoid checks on the argument name
151 // ----------------------------------------------------------------------------
153 // ----------------------------------------------------------------------------
155 bool wxMethod::IsOk() const
157 // NOTE: m_retType can be a wxEmptyType, and means that this method
158 // is a ctor or a dtor.
159 if (!m_retType
.IsOk() && m_retType
!=wxEmptyType
) {
160 LogError("'%s' method has invalid return type: %s", m_retType
.GetAsString());
164 if (m_strName
.IsEmpty())
167 // a function can't be both const and static or virtual and static!
168 if ((m_bConst
&& m_bStatic
) || ((m_bVirtual
|| m_bPureVirtual
) && m_bStatic
)) {
169 LogError("'%s' method can't be both const/static or virtual/static", m_strName
);
173 wxASSERT((m_bVirtual
&& m_bPureVirtual
) || !m_bVirtual
);
175 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
176 if (!m_args
[i
].IsOk()) {
177 LogError("'%s' method has invalid %d-th argument type: %s",
178 m_strName
, i
+1, m_args
[i
].GetAsString());
182 // NB: the default value of the arguments can contain pretty much everything
183 // (think to e.g. wxPoint(3+4/2,0) or *wxBLACK or someClass<type>)
184 // so we don't do any test on their contents
185 if (m_args
.GetCount()>0)
187 bool previousArgHasDefault
= m_args
[0].HasDefaultValue();
188 for (unsigned int i
=1; i
<m_args
.GetCount(); i
++)
190 if (previousArgHasDefault
&& !m_args
[i
].HasDefaultValue()) {
191 LogError("'%s' method has %d-th argument which has no default value "
192 "(while the previous one had one!)",
197 previousArgHasDefault
= m_args
[i
].HasDefaultValue();
204 bool wxMethod::operator==(const wxMethod
& m
) const
206 if (GetReturnType() != m
.GetReturnType() ||
207 GetName() != m
.GetName() ||
208 IsConst() != m
.IsConst() ||
209 IsStatic() != m
.IsStatic() ||
210 IsVirtual() != m
.IsVirtual() ||
211 IsPureVirtual() != m
.IsPureVirtual() ||
212 IsDeprecated() != m
.IsDeprecated())
215 if (m_args
.GetCount()!=m
.m_args
.GetCount())
218 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
219 if (m_args
[i
] != m
.m_args
[i
])
225 wxString
wxMethod::GetAsString(bool bWithArgumentNames
) const
229 if (m_retType
!=wxEmptyType
)
230 ret
+= m_retType
.GetAsString() + " ";
231 //else; this is a ctor or dtor
233 ret
+= m_strName
+ "(";
235 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
237 ret
+= m_args
[i
].GetAsString();
239 const wxString
& name
= m_args
[i
].GetArgumentName();
240 if (bWithArgumentNames
&& !name
.IsEmpty())
243 const wxString
& def
= m_args
[i
].GetDefaultValue();
250 if (m_args
.GetCount()>0)
251 ret
= ret
.Left(ret
.Len()-2);
258 ret
= "static " + ret
;
259 if (m_bVirtual
|| m_bPureVirtual
)
260 ret
= "virtual " + ret
;
264 // in doxygen headers we don't need wxDEPRECATED:
266 // ret = "wxDEPRECATED( " + ret + " )";
271 void wxMethod::Dump(wxTextOutputStream
& stream
) const
273 stream
<< "[" + m_retType
.GetAsString() + "]";
274 stream
<< "[" + m_strName
+ "]";
276 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
277 stream
<< "[" + m_args
[i
].GetAsString() + " " + m_args
[i
].GetArgumentName() +
278 "=" + m_args
[i
].GetDefaultValue() + "]";
285 stream
<< " VIRTUAL";
287 stream
<< " PURE-VIRTUAL";
289 stream
<< " DEPRECATED";
294 // ----------------------------------------------------------------------------
296 // ----------------------------------------------------------------------------
298 wxString
wxClass::GetNameWithoutTemplate() const
300 // NB: I'm not sure this is the right terminology for this function!
302 if (m_strName
.Contains("<"))
303 return m_strName
.Left(m_strName
.Find("<"));
307 bool wxClass::IsValidCtorForThisClass(const wxMethod
& m
) const
309 // remember that e.g. the ctor for wxWritableCharTypeBuffer<wchar_t> is
310 // named wxWritableCharTypeBuffer, without the <...> part!
312 if (m
.IsCtor() && m
.GetName() == GetNameWithoutTemplate())
318 bool wxClass::IsValidDtorForThisClass(const wxMethod
& m
) const
320 if (m
.IsDtor() && m
.GetName() == "~" + GetNameWithoutTemplate())
326 void wxClass::Dump(wxTextOutputStream
& out
) const
328 out
<< m_strName
+ "\n";
330 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++) {
332 // dump all our methods
334 m_methods
[i
].Dump(out
);
341 bool wxClass::CheckConsistency() const
343 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++)
344 for (unsigned int j
=0; j
<m_methods
.GetCount(); j
++)
345 if (i
!=j
&& m_methods
[i
] == m_methods
[j
])
347 LogError("class %s has two methods with the same prototype: '%s'",
348 m_strName
, m_methods
[i
].GetAsString());
355 const wxMethod
* wxClass::FindMethod(const wxMethod
& m
) const
357 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++)
358 if (m_methods
[i
] == m
)
359 return &m_methods
[i
];
363 wxMethodPtrArray
wxClass::FindMethodNamed(const wxString
& name
) const
365 wxMethodPtrArray ret
;
367 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++)
368 if (m_methods
[i
].GetName() == name
)
369 ret
.Add(&m_methods
[i
]);
375 // ----------------------------------------------------------------------------
377 // ----------------------------------------------------------------------------
379 WX_DEFINE_SORTED_ARRAY(wxClass
*, wxSortedClassArray
);
381 int CompareWxClassObjects(wxClass
*item1
, wxClass
*item2
)
383 // sort alphabetically
384 return item1
->GetName().Cmp(item2
->GetName());
387 void wxXmlInterface::Dump(const wxString
& filename
)
389 wxFFileOutputStream
apioutput( filename
);
390 wxTextOutputStream
apiout( apioutput
);
392 // dump the classes in alphabetical order
393 wxSortedClassArray
sorted(CompareWxClassObjects
);
394 sorted
.Alloc(m_classes
.GetCount());
395 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
396 sorted
.Add(&m_classes
[i
]);
398 // now they have been sorted
399 for (unsigned int i
=0; i
<sorted
.GetCount(); i
++)
400 sorted
[i
]->Dump(apiout
);
403 bool wxXmlInterface::CheckParseResults() const
405 // this check can be quite slow, so do it only for debug releases:
407 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
408 if (!m_classes
[i
].CheckConsistency())
415 wxClassPtrArray
wxXmlInterface::FindClassesDefinedIn(const wxString
& headerfile
) const
419 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
420 if (m_classes
[i
].GetHeader() == headerfile
)
421 ret
.Add(&m_classes
[i
]);
427 // ----------------------------------------------------------------------------
428 // wxXmlGccInterface helper declarations
429 // ----------------------------------------------------------------------------
431 #define ATTRIB_CONST 1
432 #define ATTRIB_REFERENCE 2
433 #define ATTRIB_POINTER 4
434 #define ATTRIB_ARRAY 8
436 #define GCCXML_BASE 35
438 class toResolveTypeItem
441 toResolveTypeItem() { attribs
=0; }
442 toResolveTypeItem(unsigned int refID
, unsigned int attribint
)
443 : ref(refID
), attribs(attribint
) {}
445 unsigned long ref
, attribs
;
450 // for wxToResolveTypeHashMap, keys == gccXML IDs and values == toResolveTypeItem
451 WX_DECLARE_HASH_MAP( unsigned long, toResolveTypeItem
,
452 wxIntegerHash
, wxIntegerEqual
,
453 wxToResolveTypeHashMap
);
455 // for wxClassMemberIdHashMap, keys == gccXML IDs and values == wxClass which owns that member ID
456 WX_DECLARE_HASH_MAP( unsigned long, wxClass
*,
457 wxIntegerHash
, wxIntegerEqual
,
458 wxClassMemberIdHashMap
);
461 typedef std::map
<unsigned long, toResolveTypeItem
> wxToResolveTypeHashMap
;
465 // utility to parse gccXML ID values;
466 // this function is equivalent to wxString(str).Mid(1).ToULong(&id, GCCXML_BASE)
467 // but is a little bit faster
468 bool getID(unsigned long *id
, const wxStringCharType
* str
)
470 wxStringCharType
*end
;
471 #if wxUSE_UNICODE_UTF8
472 unsigned long val
= strtoul(str
+1, &end
, GCCXML_BASE
);
474 unsigned long val
= wcstoul(str
+1, &end
, GCCXML_BASE
);
477 // return true only if scan was stopped by the terminating NUL and
478 // if the string was not empty to start with and no under/overflow
480 if ( *end
!= '\0' || end
== str
+1 || errno
== ERANGE
|| errno
== EINVAL
)
487 // utility specialized to parse efficiently the gccXML list of IDs which occur
488 // in nodes like <Class> ones... i.e. numeric values separed by " _" token
489 bool getMemberIDs(wxClassMemberIdHashMap
* map
, wxClass
* p
, const wxStringCharType
* str
)
491 #if wxUSE_UNICODE_UTF8
492 size_t len
= strlen(str
);
494 size_t len
= wcslen(str
);
497 if (len
== 0 || str
[0] != '_')
500 const wxStringCharType
*curpos
= str
,
502 wxStringCharType
*nexttoken
;
506 // curpos always points to the underscore of the next token to parse:
507 #if wxUSE_UNICODE_UTF8
508 unsigned long id
= strtoul(curpos
+1, &nexttoken
, GCCXML_BASE
);
510 unsigned long id
= wcstoul(curpos
+1, &nexttoken
, GCCXML_BASE
);
512 if ( *nexttoken
!= ' ' || errno
== ERANGE
|| errno
== EINVAL
)
515 // advance current position
516 curpos
= nexttoken
+ 1;
518 // add this ID to the hashmap
519 wxClassMemberIdHashMap::value_type
v(id
, p
);
527 // ----------------------------------------------------------------------------
529 // ----------------------------------------------------------------------------
531 bool wxXmlGccInterface::Parse(const wxString
& filename
)
537 LogMessage("Parsing %s...", filename
);
539 if (!doc
.Load(filename
)) {
540 LogError("can't load %s", filename
);
544 // start processing the XML file
545 if (doc
.GetRoot()->GetName() != "GCC_XML") {
546 LogError("invalid root node for %s", filename
);
550 wxToResolveTypeHashMap toResolveTypes
;
551 wxClassMemberIdHashMap members
;
552 wxTypeIdHashMap types
;
553 wxTypeIdHashMap files
;
555 // prealloc quite a lot of memory!
556 m_classes
.Alloc(ESTIMATED_NUM_CLASSES
);
558 // build a list of wx classes and in general of all existent types
559 child
= doc
.GetRoot()->GetChildren();
562 const wxString
& n
= child
->GetName();
564 unsigned long id
= 0;
565 if (!getID(&id
, child
->GetAttribute("id")) || (id
== 0 && n
!= "File")) {
567 // NOTE: <File> nodes can have an id == "f0"...
569 LogError("Invalid id for node %s: %s", n
, child
->GetAttribute("id"));
575 wxString cname
= child
->GetAttribute("name");
576 if (cname
.IsEmpty()) {
577 LogError("Invalid empty name for '%s' node", n
);
581 // only register wx classes (do remember also the IDs of their members)
582 if (cname
.StartsWith("wx"))
584 // NB: "file" attribute contains an ID value that we'll resolve later
585 m_classes
.Add(wxClass(cname
, child
->GetAttribute("file")));
587 const wxString
& ids
= child
->GetAttribute("members");
590 if (child
->GetAttribute("incomplete") != "1") {
591 LogError("Invalid member IDs for '%s' class node: %s",
592 cname
, child
->GetAttribute("id"));
595 //else: don't warn the user; it looks like "incomplete" classes
596 // never have any member...
600 // decode the non-empty list of IDs:
601 if (!getMemberIDs(&members
, &m_classes
.Last(), ids
)) {
602 LogError("Invalid member IDs for '%s' class node: %s",
603 cname
, child
->GetAttribute("id"));
609 // register this class also as possible return/argument type:
612 else if (n
== "PointerType" || n
== "ReferenceType" ||
613 n
== "CvQualifiedType" || n
== "ArrayType")
615 unsigned long type
= 0;
616 if (!getID(&type
, child
->GetAttribute("type")) || type
== 0) {
617 LogError("Invalid type for node %s: %s", n
, child
->GetAttribute("type"));
621 unsigned long attr
= 0;
622 if (n
== "PointerType")
623 attr
= ATTRIB_POINTER
;
624 else if (n
== "ReferenceType")
625 attr
= ATTRIB_REFERENCE
;
626 else if (n
== "CvQualifiedType" && child
->GetAttribute("const") == "1")
628 else if (n
== "ArrayType")
631 // these nodes make reference to other types... we'll resolve them later
632 toResolveTypes
[id
] = toResolveTypeItem(type
, attr
);
634 else if (n
== "FunctionType" || n
== "MethodType")
637 TODO: parsing FunctionType and MethodType nodes is not as easy
638 as for other "simple" types.
642 wxXmlNode
*arg
= child
->GetChildren();
645 if (arg
->GetName() == "Argument")
646 argstr
+= arg
->GetAttribute("type") + ", ";
647 arg
= arg
->GetNext();
650 if (argstr
.Len() > 0)
651 argstr
= argstr
.Left(argstr
.Len()-2);
653 // these nodes make reference to other types... we'll resolve them later
654 //toResolveTypes[id] = toResolveTypeItem(ret, 0);
655 types
[id
] = child
->GetAttribute("returns") + "(" + argstr
+ ")";
657 else if (n
== "File")
659 if (!child
->GetAttribute("id").StartsWith("f")) {
660 LogError("Unexpected file ID: %s", child
->GetAttribute("id"));
664 // just ignore this node... all file IDs/names were already parsed
665 files
[id
] = child
->GetAttribute("name");
669 // we register everything else as a possible return/argument type:
670 const wxString
& name
= child
->GetAttribute("name");
675 //typeNames.Add(name);
680 // this may happen with unnamed structs/union, special ctors,
681 // or other exotic things which we are not interested to, since
682 // they're never used as return/argument types by wxWidgets methods
685 LogWarning("Type node '%s' with ID '%s' does not have name attribute",
686 n
, child
->GetAttribute("id"));
692 child
= child
->GetNext();
694 // give feedback to the user about the progress...
695 if ((++nodes%PROGRESS_RATE
)==0) ShowProgress();
698 // some nodes with IDs referenced by methods as return/argument types, do reference
699 // in turn o ther nodes (see PointerType, ReferenceType and CvQualifierType above);
700 // thus we need to resolve their name iteratively:
701 while (toResolveTypes
.size()>0)
704 LogMessage("%d types were collected; %d types need yet to be resolved...",
705 types
.size(), toResolveTypes
.size());
707 for (wxToResolveTypeHashMap::iterator i
= toResolveTypes
.begin();
708 i
!= toResolveTypes
.end();)
710 unsigned long id
= i
->first
;
711 unsigned long referenced
= i
->second
.ref
;
713 wxTypeIdHashMap::iterator primary
= types
.find(referenced
);
714 if (primary
!= types
.end())
716 // this to-resolve-type references a "primary" type
718 wxString newtype
= primary
->second
;
719 int attribs
= i
->second
.attribs
;
721 // attribs may contain a combination of ATTRIB_* flags:
722 if (attribs
& ATTRIB_CONST
)
723 newtype
= "const " + newtype
;
724 if (attribs
& ATTRIB_REFERENCE
)
725 newtype
= newtype
+ "&";
726 if (attribs
& ATTRIB_POINTER
)
727 newtype
= newtype
+ "*";
728 if (attribs
& ATTRIB_ARRAY
)
729 newtype
= newtype
+ "[]";
731 // add the resolved type to the list of "primary" types
734 // this one has been resolved; erase it through its iterator!
735 toResolveTypes
.erase(i
);
737 // now iterator i is invalid; assign it again to the beginning
738 i
= toResolveTypes
.begin();
742 // then search in the referenced types themselves:
743 wxToResolveTypeHashMap::iterator idx2
= toResolveTypes
.find(referenced
);
744 if (idx2
!= toResolveTypes
.end())
746 // merge this to-resolve-type with the idx2->second type
747 i
->second
.ref
= idx2
->second
.ref
;
748 i
->second
.attribs
|= idx2
->second
.attribs
;
750 // this type will eventually be solved in the next while() iteration
755 LogError("Cannot solve '%s' reference type!", referenced
);
762 // resolve header names
763 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
765 unsigned long fileID
= 0;
766 if (!getID(&fileID
, m_classes
[i
].GetHeader()) || fileID
== 0) {
767 LogError("invalid header id: %s", m_classes
[i
].GetHeader());
772 wxTypeIdHashMap::const_iterator idx
= files
.find(fileID
);
773 if (idx
== files
.end())
776 LogError("couldn't find file ID '%s'", m_classes
[i
].GetHeader());
779 m_classes
[i
].SetHeader(idx
->second
);
782 // build the list of the wx methods
783 child
= doc
.GetRoot()->GetChildren();
786 wxString n
= child
->GetName();
788 // only register public methods
789 if (child
->GetAttribute("access") == "public" &&
790 (n
== "Method" || n
== "Constructor" || n
== "Destructor" || n
== "OperatorMethod"))
792 unsigned long id
= 0;
793 if (!getID(&id
, child
->GetAttribute("id"))) {
794 LogError("invalid ID for node '%s' with ID '%s'", n
, child
->GetAttribute("id"));
798 wxClassMemberIdHashMap::const_iterator it
= members
.find(id
);
799 if (it
!= members
.end())
801 wxClass
*p
= it
->second
;
803 // this <Method> node is a method of the i-th class!
805 if (!ParseMethod(child
, types
, newfunc
)) {
806 LogError("The method '%s' could not be added to class '%s'",
807 child
->GetAttribute("demangled"), p
->GetName());
811 if (newfunc
.IsCtor() && !p
->IsValidCtorForThisClass(newfunc
)) {
812 LogError("The method '%s' does not seem to be a ctor for '%s'",
813 newfunc
.GetName(), p
->GetName());
816 if (newfunc
.IsDtor() && !p
->IsValidDtorForThisClass(newfunc
)) {
817 LogError("The method '%s' does not seem to be a dtor for '%s'",
818 newfunc
.GetName(), p
->GetName());
822 p
->AddMethod(newfunc
);
826 child
= child
->GetNext();
828 // give feedback to the user about the progress...
829 if ((++nodes%PROGRESS_RATE
)==0) ShowProgress();
832 if (!CheckParseResults())
838 bool wxXmlGccInterface::ParseMethod(const wxXmlNode
*p
,
839 const wxTypeIdHashMap
& types
,
843 wxString name
= p
->GetAttribute("name").Strip(wxString::both
);
844 if (p
->GetName() == "Destructor")
846 else if (p
->GetName() == "OperatorMethod")
847 name
= "operator" + name
;
849 // resolve return type
851 unsigned long retid
= 0;
852 if (!getID(&retid
, p
->GetAttribute("returns")) || retid
== 0)
854 if (p
->GetName() != "Destructor" && p
->GetName() != "Constructor") {
855 LogError("Empty return ID for method '%s', with ID '%s'",
856 name
, p
->GetAttribute("id"));
862 wxTypeIdHashMap::const_iterator retidx
= types
.find(retid
);
863 if (retidx
== types
.end()) {
864 LogError("Could not find return type ID '%s'", retid
);
868 ret
= wxType(retidx
->second
);
870 LogError("Invalid return type '%s' for method '%s', with ID '%s'",
871 retidx
->second
, name
, p
->GetAttribute("id"));
876 // resolve argument types
877 wxArgumentTypeArray argtypes
;
878 wxXmlNode
*arg
= p
->GetChildren();
881 if (arg
->GetName() == "Argument")
883 unsigned long id
= 0;
884 if (!getID(&id
, arg
->GetAttribute("type")) || id
== 0) {
885 LogError("Invalid argument type ID '%s' for method '%s' with ID %s",
886 arg
->GetAttribute("type"), name
, p
->GetAttribute("id"));
890 wxTypeIdHashMap::const_iterator idx
= types
.find(id
);
891 if (idx
== types
.end()) {
892 LogError("Could not find argument type ID '%s'", id
);
896 argtypes
.Add(wxArgumentType(idx
->second
, arg
->GetAttribute("default")));
899 arg
= arg
->GetNext();
902 m
.SetReturnType(ret
);
904 m
.SetArgumentTypes(argtypes
);
905 m
.SetConst(p
->GetAttribute("const") == "1");
906 m
.SetStatic(p
->GetAttribute("static") == "1");
908 // NOTE: gccxml is smart enough to mark as virtual those functions
909 // which are declared virtual in base classes but don't have
910 // the "virtual" keyword explicitely indicated in the derived
911 // classes... so we don't need any further logic for virtuals
913 m
.SetVirtual(p
->GetAttribute("virtual") == "1");
914 m
.SetPureVirtual(p
->GetAttribute("pure_virtual") == "1");
915 m
.SetDeprecated(p
->GetAttribute("attributes") == "deprecated");
918 LogError("The prototype '%s' is not valid!", m
.GetAsString());
926 // ----------------------------------------------------------------------------
927 // wxXmlDoxygenInterface
928 // ----------------------------------------------------------------------------
930 bool wxXmlDoxygenInterface::Parse(const wxString
& filename
)
935 LogMessage("Parsing %s...", filename
);
937 if (!index
.Load(filename
)) {
938 LogError("can't load %s", filename
);
942 // start processing the index:
943 if (index
.GetRoot()->GetName() != "doxygenindex") {
944 LogError("invalid root node for %s", filename
);
948 m_classes
.Alloc(ESTIMATED_NUM_CLASSES
);
950 // process files referenced by this index file
951 compound
= index
.GetRoot()->GetChildren();
954 if (compound
->GetName() == "compound" &&
955 compound
->GetAttribute("kind") == "class")
957 wxString refid
= compound
->GetAttribute("refid");
959 wxFileName
fn(filename
);
960 if (!ParseCompoundDefinition(fn
.GetPath(wxPATH_GET_SEPARATOR
) + refid
+ ".xml"))
964 compound
= compound
->GetNext();
968 if (!CheckParseResults())
974 bool wxXmlDoxygenInterface::ParseCompoundDefinition(const wxString
& filename
)
981 LogMessage("Parsing %s...", filename
);
983 if (!doc
.Load(filename
)) {
984 LogError("can't load %s", filename
);
988 // start processing this compound definition XML
989 if (doc
.GetRoot()->GetName() != "doxygen") {
990 LogError("invalid root node for %s", filename
);
994 // build a list of wx classes
995 child
= doc
.GetRoot()->GetChildren();
998 if (child
->GetName() == "compounddef" &&
999 child
->GetAttribute("kind") == "class")
1003 wxString absoluteFile
, header
;
1005 wxXmlNode
*subchild
= child
->GetChildren();
1008 if (subchild
->GetName() == "sectiondef" &&
1009 subchild
->GetAttribute("kind") == "public-func")
1012 wxXmlNode
*membernode
= subchild
->GetChildren();
1015 if (membernode
->GetName() == "memberdef" &&
1016 membernode
->GetAttribute("kind") == "function")
1020 if (!ParseMethod(membernode
, m
, header
)) {
1021 LogError("The method '%s' could not be added to class '%s'",
1022 m
.GetName(), klass
.GetName());
1026 if (absoluteFile
.IsEmpty())
1027 absoluteFile
= header
;
1028 else if (header
!= absoluteFile
)
1030 LogError("The method '%s' is documented in a different "
1031 "file from others (which belong to '%s') ?",
1032 header
, absoluteFile
);
1039 membernode
= membernode
->GetNext();
1042 // all methods of this class were taken from the header "absoluteFile":
1043 klass
.SetHeader(absoluteFile
);
1045 else if (subchild
->GetName() == "compoundname")
1047 klass
.SetName(subchild
->GetNodeContent());
1049 /*else if (subchild->GetName() == "includes")
1051 // NOTE: we'll get the header from the <location> tags
1052 // scattered inside <memberdef> tags instead of
1053 // this <includes> tag since it does not contain
1054 // the absolute path of the header
1056 klass.SetHeader(subchild->GetNodeContent());
1059 subchild
= subchild
->GetNext();
1064 m_classes
.Add(klass
);
1066 LogWarning("discarding class '%s' with %d methods...",
1067 klass
.GetName(), klass
.GetMethodCount());
1070 child
= child
->GetNext();
1072 // give feedback to the user about the progress...
1073 if ((++nodes%PROGRESS_RATE
)==0) ShowProgress();
1079 static wxString
GetTextFromChildren(const wxXmlNode
*n
)
1083 // consider the tree
1085 // <a><b>this</b> is a <b>string</b></a>
1094 // unlike wxXmlNode::GetNodeContent() which would return " is a "
1095 // this function returns "this is a string"
1097 wxXmlNode
*ref
= n
->GetChildren();
1099 if (ref
->GetType() == wxXML_ELEMENT_NODE
)
1100 text
+= ref
->GetNodeContent();
1101 else if (ref
->GetType() == wxXML_TEXT_NODE
)
1102 text
+= ref
->GetContent();
1104 LogWarning("Unexpected node type while getting text from '%s' node", n
->GetName());
1106 ref
= ref
->GetNext();
1112 static bool HasTextNodeContaining(const wxXmlNode
*parent
, const wxString
& name
)
1114 wxXmlNode
*p
= parent
->GetChildren();
1117 switch (p
->GetType())
1119 case wxXML_TEXT_NODE
:
1120 if (p
->GetContent() == name
)
1124 case wxXML_ELEMENT_NODE
:
1125 // recurse into this node...
1126 if (HasTextNodeContaining(p
, name
))
1141 bool wxXmlDoxygenInterface::ParseMethod(const wxXmlNode
* p
, wxMethod
& m
, wxString
& header
)
1143 wxArgumentTypeArray args
;
1146 wxXmlNode
*child
= p
->GetChildren();
1149 if (child
->GetName() == "name")
1150 m
.SetName(child
->GetNodeContent());
1151 else if (child
->GetName() == "type")
1152 m
.SetReturnType(wxType(GetTextFromChildren(child
)));
1153 else if (child
->GetName() == "param")
1155 wxString typestr
, namestr
, defstr
, arrstr
;
1156 wxXmlNode
*n
= child
->GetChildren();
1159 if (n
->GetName() == "type")
1160 // if the <type> node has children, they should be all TEXT and <ref> nodes
1161 // and we need to take the text they contain, in the order they appear
1162 typestr
= GetTextFromChildren(n
);
1163 else if (n
->GetName() == "declname")
1164 namestr
= GetTextFromChildren(n
);
1165 else if (n
->GetName() == "defval")
1166 defstr
= GetTextFromChildren(n
);
1167 else if (n
->GetName() == "array")
1168 arrstr
= GetTextFromChildren(n
);
1173 if (typestr
.IsEmpty()) {
1174 LogError("cannot find type node for a param in method '%s'", m
.GetName());
1178 args
.Add(wxArgumentType(typestr
+ arrstr
, defstr
, namestr
));
1180 else if (child
->GetName() == "location")
1183 if (child
->GetAttribute("line").ToLong(&line
))
1184 m
.SetLocation((int)line
);
1185 header
= child
->GetAttribute("file");
1187 else if (child
->GetName() == "detaileddescription")
1189 // when a method has a @deprecated tag inside its description,
1190 // Doxygen outputs somewhere nested inside <detaileddescription>
1191 // a <xreftitle>Deprecated</xreftitle> tag.
1192 m
.SetDeprecated(HasTextNodeContaining(child
, "Deprecated"));
1195 child
= child
->GetNext();
1198 m
.SetArgumentTypes(args
);
1199 m
.SetConst(p
->GetAttribute("const")=="yes");
1200 m
.SetStatic(p
->GetAttribute("static")=="yes");
1202 // NOTE: Doxygen is smart enough to mark as virtual those functions
1203 // which are declared virtual in base classes but don't have
1204 // the "virtual" keyword explicitely indicated in the derived
1205 // classes... so we don't need any further logic for virtuals
1207 m
.SetVirtual(p
->GetAttribute("virt")=="virtual");
1208 m
.SetPureVirtual(p
->GetAttribute("virt")=="pure-virtual");
1211 LogError("The prototype '%s' is not valid!", m
.GetAsString());