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/arrimpl.cpp"
25 #include "wx/hashmap.h"
26 #include "wx/filename.h"
30 #include "xmlparser.h"
32 #define PROGRESS_RATE 1000 // each PROGRESS_RATE nodes processed print a dot
33 #define ESTIMATED_NUM_CLASSES 600 // used by both wxXmlInterface-derived classes to prealloc mem
35 WX_DEFINE_OBJARRAY(wxTypeArray
)
36 WX_DEFINE_OBJARRAY(wxMethodArray
)
37 WX_DEFINE_OBJARRAY(wxClassArray
)
40 // declared in ifacecheck.cpp
41 extern bool g_verbose
;
45 // ----------------------------------------------------------------------------
47 // ----------------------------------------------------------------------------
51 void wxType::SetFromString(const wxString
& t
)
53 m_strType
= t
.Strip(wxString::both
);
55 // [] is the same as * for gccxml
56 m_strType
.Replace("[]", "*");
59 bool wxType::IsOk() const
61 // NB: m_strType can contain the :: operator; think to e.g. the
62 // "reverse_iterator_impl<wxString::const_iterator>" type
63 // It can also contain commas, * and & operators etc
65 return !GetClean().IsEmpty();
68 wxString
wxType::GetClean() const
70 wxString
ret(m_strType
);
71 ret
.Replace("const", "");
72 ret
.Replace("static", "");
75 ret
.Replace("[]", "");
76 return ret
.Strip(wxString::both
);
79 bool wxType::operator==(const wxType
& m
) const
81 // brain-dead comparison:
83 if (GetClean() == m
.GetClean() &&
84 IsConst() == m
.IsConst() &&
85 IsStatic() == m
.IsStatic() &&
86 IsPointer() == m
.IsPointer() &&
87 IsReference() == m
.IsReference())
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 bool wxMethod::IsOk() const
99 // NOTE: m_retType can be a wxEmptyType, and means that this method
100 // is a ctor or a dtor.
101 if (!m_retType
.IsOk() && m_retType
!=wxEmptyType
) {
102 LogError("'%s' method has invalid return type: %s", m_retType
.GetAsString());
106 if (m_strName
.IsEmpty())
109 // a function can't be both const and static or virtual and static!
110 if ((m_bConst
&& m_bStatic
) || (m_bVirtual
&& m_bStatic
)) {
111 LogError("'%s' method can't be both const/static or virtual/static", m_strName
);
115 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
116 if (!m_args
[i
].IsOk()) {
117 LogError("'%s' method has invalid %d-th argument type: %s",
118 m_strName
, i
, m_args
[i
].GetAsString());
122 // NB: the default value of the arguments can contain pretty much everything
123 // (think to e.g. wxPoint(3+4/2,0) or *wxBLACK or someClass<type>)
124 // so we don't do any test on them.
129 void wxMethod::SetArgumentTypes(const wxTypeArray
& arr
, const wxArrayString
& defaults
)
131 wxASSERT(arr
.GetCount()==defaults
.GetCount());
134 m_argDefaults
=defaults
;
136 // in order to make valid&simple comparison on argument defaults,
137 // we reduce some of the multiple forms in which the same things may appear
139 for (unsigned int i
=0; i
<m_argDefaults
.GetCount(); i
++)
141 m_argDefaults
[i
].Replace("NULL", "0");
142 m_argDefaults
[i
].Replace("0u", "0");
146 bool wxMethod::operator==(const wxMethod
& m
) const
148 if (GetReturnType() != m
.GetReturnType() ||
149 GetName() != m
.GetName() ||
150 IsConst() != m
.IsConst() ||
151 IsStatic() != m
.IsStatic() ||
152 IsVirtual() != m
.IsVirtual())
155 if (m_args
.GetCount()!=m
.m_args
.GetCount())
158 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
159 if (m_args
[i
] != m
.m_args
[i
] || m_argDefaults
[i
] != m
.m_argDefaults
[i
])
165 wxString
wxMethod::GetAsString() const
169 if (m_retType
!=wxEmptyType
)
170 ret
+= m_retType
.GetAsString() + " ";
171 //else; this is a ctor or dtor
173 ret
+= m_strName
+ "(";
175 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
177 ret
+= m_args
[i
].GetAsString();
178 if (!m_argDefaults
[i
].IsEmpty())
179 ret
+= " = " + m_argDefaults
[i
];
183 if (m_args
.GetCount()>0)
191 ret
= "static " + ret
;
193 ret
= "virtual " + ret
;
198 void wxMethod::Dump(wxTextOutputStream
& stream
) const
200 stream
<< "[" + m_retType
.GetAsString() + "]";
201 stream
<< "[" + m_strName
+ "]";
203 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
204 stream
<< "[" + m_args
[i
].GetAsString() + "=" + m_argDefaults
[i
] + "]";
211 stream
<< " VIRTUAL";
216 // ----------------------------------------------------------------------------
218 // ----------------------------------------------------------------------------
220 wxString
wxClass::GetNameWithoutTemplate() const
222 // NB: I'm not sure this is the right terminology for this function!
224 if (m_strName
.Contains("<"))
225 return m_strName
.Left(m_strName
.Find("<"));
229 bool wxClass::IsValidCtorForThisClass(const wxMethod
& m
) const
231 // remember that e.g. the ctor for wxWritableCharTypeBuffer<wchar_t> is
232 // named wxWritableCharTypeBuffer, without the <...> part!
234 if (m
.IsCtor() && m
.GetName() == GetNameWithoutTemplate())
240 bool wxClass::IsValidDtorForThisClass(const wxMethod
& m
) const
242 if (m
.IsDtor() && m
.GetName() == "~" + GetNameWithoutTemplate())
248 void wxClass::Dump(wxTextOutputStream
& out
) const
250 out
<< m_strName
+ "\n";
252 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++) {
254 // dump all our methods
256 m_methods
[i
].Dump(out
);
263 bool wxClass::CheckConsistency() const
265 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++)
266 for (unsigned int j
=0; j
<m_methods
.GetCount(); j
++)
267 if (i
!=j
&& m_methods
[i
] == m_methods
[j
])
269 LogError("class %s has two methods with the same prototype: '%s'",
270 m_strName
, m_methods
[i
].GetAsString());
277 const wxMethod
* wxClass::FindMethod(const wxMethod
& m
) const
279 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++)
280 if (m_methods
[i
] == m
)
281 return &m_methods
[i
];
285 wxMethodPtrArray
wxClass::FindMethodNamed(const wxString
& name
) const
287 wxMethodPtrArray ret
;
289 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++)
290 if (m_methods
[i
].GetName() == name
)
291 ret
.Add(&m_methods
[i
]);
297 // ----------------------------------------------------------------------------
299 // ----------------------------------------------------------------------------
301 WX_DEFINE_SORTED_ARRAY(wxClass
*, wxSortedClassArray
);
303 int CompareWxClassObjects(wxClass
*item1
, wxClass
*item2
)
305 // sort alphabetically
306 return item1
->GetName().Cmp(item2
->GetName());
309 void wxXmlInterface::Dump(const wxString
& filename
)
311 wxFFileOutputStream
apioutput( filename
);
312 wxTextOutputStream
apiout( apioutput
);
314 // dump the classes in alphabetical order
315 wxSortedClassArray
sorted(CompareWxClassObjects
);
316 sorted
.Alloc(m_classes
.GetCount());
317 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
318 sorted
.Add(&m_classes
[i
]);
320 // now they have been sorted
321 for (unsigned int i
=0; i
<sorted
.GetCount(); i
++)
322 sorted
[i
]->Dump(apiout
);
325 bool wxXmlInterface::CheckParseResults() const
327 // this check can be quite slow, so do it only for debug releases:
329 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
330 if (!m_classes
[i
].CheckConsistency())
337 // ----------------------------------------------------------------------------
338 // wxXmlGccInterface helper declarations
339 // ----------------------------------------------------------------------------
341 #define ATTRIB_CONST 1
342 #define ATTRIB_REFERENCE 2
343 #define ATTRIB_POINTER 4
344 #define ATTRIB_ARRAY 8
346 #define GCCXML_BASE 35
348 class toResolveTypeItem
351 toResolveTypeItem() { attribs
=0; }
352 toResolveTypeItem(unsigned int refID
, unsigned int attribint
)
353 : ref(refID
), attribs(attribint
) {}
355 unsigned long ref
, attribs
;
360 // for wxToResolveTypeHashMap, keys == gccXML IDs and values == toResolveTypeItem
361 WX_DECLARE_HASH_MAP( unsigned long, toResolveTypeItem
,
362 wxIntegerHash
, wxIntegerEqual
,
363 wxToResolveTypeHashMap
);
365 // for wxClassMemberIdHashMap, keys == gccXML IDs and values == wxClass which owns that member ID
366 WX_DECLARE_HASH_MAP( unsigned long, wxClass
*,
367 wxIntegerHash
, wxIntegerEqual
,
368 wxClassMemberIdHashMap
);
371 typedef std::map
<unsigned long, toResolveTypeItem
> wxToResolveTypeHashMap
;
375 // utility to parse gccXML ID values;
376 // this function is equivalent to wxString(str).Mid(1).ToULong(&id, GCCXML_BASE)
377 // but is a little bit faster
378 bool getID(unsigned long *id
, const wxStringCharType
* str
)
380 wxStringCharType
*end
;
381 #if wxUSE_UNICODE_UTF8
382 unsigned long val
= strtoul(str
+1, &end
, GCCXML_BASE
);
384 unsigned long val
= wcstoul(str
+1, &end
, GCCXML_BASE
);
387 // return true only if scan was stopped by the terminating NUL and
388 // if the string was not empty to start with and no under/overflow
390 if ( *end
!= '\0' || end
== str
+1 || errno
== ERANGE
|| errno
== EINVAL
)
397 // utility specialized to parse efficiently the gccXML list of IDs which occur
398 // in nodes like <Class> ones... i.e. numeric values separed by " _" token
399 bool getMemberIDs(wxClassMemberIdHashMap
* map
, wxClass
* p
, const wxStringCharType
* str
)
401 #if wxUSE_UNICODE_UTF8
402 size_t len
= strlen(str
);
404 size_t len
= wcslen(str
);
407 if (len
== 0 || str
[0] != '_')
410 const wxStringCharType
*curpos
= str
,
412 wxStringCharType
*nexttoken
;
416 // curpos always points to the underscore of the next token to parse:
417 #if wxUSE_UNICODE_UTF8
418 unsigned long id
= strtoul(curpos
+1, &nexttoken
, GCCXML_BASE
);
420 unsigned long id
= wcstoul(curpos
+1, &nexttoken
, GCCXML_BASE
);
422 if ( *nexttoken
!= ' ' || errno
== ERANGE
|| errno
== EINVAL
)
425 // advance current position
426 curpos
= nexttoken
+ 1;
428 // add this ID to the hashmap
429 wxClassMemberIdHashMap::value_type
v(id
, p
);
437 // ----------------------------------------------------------------------------
439 // ----------------------------------------------------------------------------
441 bool wxXmlGccInterface::Parse(const wxString
& filename
)
447 LogMessage("Parsing %s...", filename
);
449 if (!doc
.Load(filename
)) {
450 LogError("can't load %s", filename
);
454 // start processing the XML file
455 if (doc
.GetRoot()->GetName() != "GCC_XML") {
456 LogError("invalid root node for %s", filename
);
460 wxToResolveTypeHashMap toResolveTypes
;
461 wxClassMemberIdHashMap members
;
462 wxTypeIdHashMap types
;
463 wxTypeIdHashMap files
;
465 // prealloc quite a lot of memory!
466 m_classes
.Alloc(ESTIMATED_NUM_CLASSES
);
468 // build a list of wx classes and in general of all existent types
469 child
= doc
.GetRoot()->GetChildren();
472 const wxString
& n
= child
->GetName();
474 unsigned long id
= 0;
475 if (!getID(&id
, child
->GetAttribute("id")) || (id
== 0 && n
!= "File")) {
477 // NOTE: <File> nodes can have an id == "f0"...
479 LogError("Invalid id for node %s: %s", n
, child
->GetAttribute("id"));
485 wxString cname
= child
->GetAttribute("name");
486 if (cname
.IsEmpty()) {
487 LogError("Invalid empty name for '%s' node", n
);
491 // only register wx classes (do remember also the IDs of their members)
492 if (cname
.StartsWith("wx"))
494 // NB: "file" attribute contains an ID value that we'll resolve later
495 m_classes
.Add(wxClass(cname
, child
->GetAttribute("file")));
497 const wxString
& ids
= child
->GetAttribute("members");
500 if (child
->GetAttribute("incomplete") != "1") {
501 LogError("Invalid member IDs for '%s' class node (ID %s)",
502 cname
, child
->GetAttribute("id"));
505 //else: don't warn the user; it looks like "incomplete" classes
506 // never have any member...
510 // decode the non-empty list of IDs:
511 if (!getMemberIDs(&members
, &m_classes
.Last(), ids
)) {
512 LogError("Invalid member IDs for '%s' class node (ID %s)",
513 cname
, child
->GetAttribute("id"));
519 // register this class also as possible return/argument type:
522 else if (n
== "PointerType" || n
== "ReferenceType" ||
523 n
== "CvQualifiedType" || n
== "ArrayType")
525 unsigned long type
= 0;
526 if (!getID(&type
, child
->GetAttribute("type")) || type
== 0) {
527 LogError("Invalid type for node %s: %s", n
, child
->GetAttribute("type"));
531 unsigned long attr
= 0;
532 if (n
== "PointerType")
533 attr
= ATTRIB_POINTER
;
534 else if (n
== "ReferenceType")
535 attr
= ATTRIB_REFERENCE
;
536 else if (n
== "CvQualifiedType" && child
->GetAttribute("const") == "1")
538 else if (n
== "ArrayType")
541 // these nodes make reference to other types... we'll resolve them later
542 toResolveTypes
[id
] = toResolveTypeItem(type
, attr
);
544 else if (n
== "FunctionType" || n
== "MethodType")
546 /* TODO: incomplete */
548 unsigned long ret
= 0;
549 if (!getID(&ret
, child
->GetAttribute("returns")) || ret
== 0) {
550 LogError("Invalid empty returns value for '%s' node", n
);
554 // these nodes make reference to other types... we'll resolve them later
555 toResolveTypes
[id
] = toResolveTypeItem(ret
, 0);
557 else if (n
== "File")
559 if (!child
->GetAttribute("id").StartsWith("f")) {
560 LogError("Unexpected file ID: %s", id
);
564 // just ignore this node... all file IDs/names were already parsed
565 files
[id
] = child
->GetAttribute("name");
569 // we register everything else as a possible return/argument type:
570 const wxString
& name
= child
->GetAttribute("name");
575 //typeNames.Add(name);
580 // this may happen with unnamed structs/union, special ctors,
581 // or other exotic things which we are not interested to, since
582 // they're never used as return/argument types by wxWidgets methods
585 LogWarning("Type '%s' with ID '%s' does not have name attribute", n
, id
);
591 child
= child
->GetNext();
593 // give feedback to the user about the progress...
594 if ((++nodes%PROGRESS_RATE
)==0) ShowProgress();
597 // some nodes with IDs referenced by methods as return/argument types, do reference
598 // in turn o ther nodes (see PointerType, ReferenceType and CvQualifierType above);
599 // thus we need to resolve their name iteratively:
600 while (toResolveTypes
.size()>0)
603 LogMessage("%d types were collected; %d types need yet to be resolved...",
604 types
.size(), toResolveTypes
.size());
606 for (wxToResolveTypeHashMap::iterator i
= toResolveTypes
.begin();
607 i
!= toResolveTypes
.end();)
609 unsigned long id
= i
->first
;
610 unsigned long referenced
= i
->second
.ref
;
612 wxTypeIdHashMap::iterator primary
= types
.find(referenced
);
613 if (primary
!= types
.end())
615 // this to-resolve-type references a "primary" type
618 int attribs
= i
->second
.attribs
;
620 if (attribs
& ATTRIB_CONST
)
621 newtype
= "const " + primary
->second
;
622 if (attribs
& ATTRIB_REFERENCE
)
623 newtype
= primary
->second
+ "&";
624 if (attribs
& ATTRIB_POINTER
)
625 newtype
= primary
->second
+ "*";
626 if (attribs
& ATTRIB_ARRAY
)
627 newtype
= primary
->second
+ "[]";
629 // add the resolved type to the list of "primary" types
632 // this one has been resolved; erase it through its iterator!
633 toResolveTypes
.erase(i
);
635 // now iterator i is invalid; assign it again to the beginning
636 i
= toResolveTypes
.begin();
640 // then search in the referenced types themselves:
641 wxToResolveTypeHashMap::iterator idx2
= toResolveTypes
.find(referenced
);
642 if (idx2
!= toResolveTypes
.end())
644 // merge this to-resolve-type with the idx2->second type
645 i
->second
.ref
= idx2
->second
.ref
;
646 i
->second
.attribs
|= idx2
->second
.attribs
;
648 // this type will eventually be solved in the next while() iteration
654 LogError("Cannot solve '%s' reference type!", referenced
);
657 typeIds
.Add(toResolveTypeIds
[i
]);
658 typeNames
.Add("TOFIX");
660 // this one has been resolved!
661 toResolveTypeIds
.RemoveAt(i
);
662 toResolveRefType
.RemoveAt(i
);
663 toResolveAttrib
.RemoveAt(i
);
671 // resolve header names
672 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
674 unsigned long fileID
= 0;
675 if (!getID(&fileID
, m_classes
[i
].GetHeader()) || fileID
== 0) {
676 LogError("invalid header id: %s", m_classes
[i
].GetHeader());
681 wxTypeIdHashMap::const_iterator idx
= files
.find(fileID
);
682 if (idx
== files
.end())
685 LogError("couldn't find file ID '%s'", m_classes
[i
].GetHeader());
688 m_classes
[i
].SetHeader(idx
->second
);
691 // build the list of the wx methods
692 child
= doc
.GetRoot()->GetChildren();
695 wxString n
= child
->GetName();
697 // only register public methods
698 if (child
->GetAttribute("access") == "public" &&
699 (n
== "Method" || n
== "Constructor" || n
== "Destructor" || n
== "OperatorMethod"))
701 unsigned long id
= 0;
702 if (!getID(&id
, child
->GetAttribute("id"))) {
703 LogError("invalid ID for node '%s' with ID '%s'", n
, child
->GetAttribute("id"));
707 wxClassMemberIdHashMap::const_iterator it
= members
.find(id
);
708 if (it
!= members
.end())
710 wxClass
*p
= it
->second
;
712 // this <Method> node is a method of the i-th class!
714 if (!ParseMethod(child
, types
, newfunc
))
717 if (newfunc
.IsCtor() && !p
->IsValidCtorForThisClass(newfunc
)) {
718 LogError("The method '%s' does not seem to be a ctor for '%s'",
719 newfunc
.GetName(), p
->GetName());
722 if (newfunc
.IsDtor() && !p
->IsValidDtorForThisClass(newfunc
)) {
723 LogError("The method '%s' does not seem to be a dtor for '%s'",
724 newfunc
.GetName(), p
->GetName());
728 p
->AddMethod(newfunc
);
732 child
= child
->GetNext();
734 // give feedback to the user about the progress...
735 if ((++nodes%PROGRESS_RATE
)==0) ShowProgress();
739 if (!CheckParseResults())
745 bool wxXmlGccInterface::ParseMethod(const wxXmlNode
*p
,
746 const wxTypeIdHashMap
& types
,
750 wxString name
= p
->GetAttribute("name").Strip(wxString::both
);
751 if (p
->GetName() == "Destructor")
753 else if (p
->GetName() == "OperatorMethod")
754 name
= "operator" + name
;
756 // resolve return type
758 unsigned long retid
= 0;
759 if (!getID(&retid
, p
->GetAttribute("returns")) || retid
== 0)
761 if (p
->GetName() != "Destructor" && p
->GetName() != "Constructor") {
762 LogError("Empty return ID for method '%s', with ID '%s'",
763 name
, p
->GetAttribute("id"));
769 wxTypeIdHashMap::const_iterator retidx
= types
.find(retid
);
770 if (retidx
== types
.end()) {
771 LogError("Could not find return type ID '%s'", retid
);
775 ret
= wxType(retidx
->second
);
777 LogError("Invalid return type '%s' for method '%s', with ID '%s'",
778 retidx
->second
, name
, p
->GetAttribute("id"));
783 // resolve argument types
784 wxTypeArray argtypes
;
785 wxArrayString argdefs
;
786 wxXmlNode
*arg
= p
->GetChildren();
789 if (arg
->GetName() == "Argument")
791 unsigned long id
= 0;
792 if (!getID(&id
, arg
->GetAttribute("type")) || id
== 0) {
793 LogError("Invalid argument type ID '%s' for method '%s' with ID %s",
794 arg
->GetAttribute("type"), name
, p
->GetAttribute("id"));
798 wxTypeIdHashMap::const_iterator idx
= types
.find(id
);
799 if (idx
== types
.end()) {
800 LogError("Could not find argument type ID '%s'", id
);
804 argtypes
.Add(wxType(idx
->second
));
806 wxString def
= arg
->GetAttribute("default");
807 if (def
.Contains("wxGetTranslation"))
808 argdefs
.Add(wxEmptyString
); // TODO: wxGetTranslation gives problems to gccxml
813 arg
= arg
->GetNext();
816 m
.SetReturnType(ret
);
818 m
.SetArgumentTypes(argtypes
, argdefs
);
819 m
.SetConst(p
->GetAttribute("const") == "1");
820 m
.SetStatic(p
->GetAttribute("static") == "1");
821 m
.SetVirtual(p
->GetAttribute("virtual") == "1");
824 LogError("The prototype '%s' is not valid!", m
.GetAsString());
832 // ----------------------------------------------------------------------------
833 // wxXmlDoxygenInterface
834 // ----------------------------------------------------------------------------
836 bool wxXmlDoxygenInterface::Parse(const wxString
& filename
)
841 LogMessage("Parsing %s...", filename
);
843 if (!index
.Load(filename
)) {
844 LogError("can't load %s", filename
);
848 // start processing the index:
849 if (index
.GetRoot()->GetName() != "doxygenindex") {
850 LogError("invalid root node for %s", filename
);
854 m_classes
.Alloc(ESTIMATED_NUM_CLASSES
);
856 // process files referenced by this index file
857 compound
= index
.GetRoot()->GetChildren();
860 if (compound
->GetName() == "compound" &&
861 compound
->GetAttribute("kind") == "class")
863 wxString refid
= compound
->GetAttribute("refid");
865 wxFileName
fn(filename
);
866 if (!ParseCompoundDefinition(fn
.GetPath(wxPATH_GET_SEPARATOR
) + refid
+ ".xml"))
870 compound
= compound
->GetNext();
874 if (!CheckParseResults())
880 bool wxXmlDoxygenInterface::ParseCompoundDefinition(const wxString
& filename
)
887 LogMessage("Parsing %s...", filename
);
889 if (!doc
.Load(filename
)) {
890 LogError("can't load %s", filename
);
894 // start processing this compound definition XML
895 if (doc
.GetRoot()->GetName() != "doxygen") {
896 LogError("invalid root node for %s", filename
);
900 // build a list of wx classes
901 child
= doc
.GetRoot()->GetChildren();
904 if (child
->GetName() == "compounddef" &&
905 child
->GetAttribute("kind") == "class")
909 wxString absoluteFile
, header
;
911 wxXmlNode
*subchild
= child
->GetChildren();
914 if (subchild
->GetName() == "sectiondef" &&
915 subchild
->GetAttribute("kind") == "public-func")
918 wxXmlNode
*membernode
= subchild
->GetChildren();
921 if (membernode
->GetName() == "memberdef" &&
922 membernode
->GetAttribute("kind") == "function")
926 if (ParseMethod(membernode
, m
, header
))
928 if (absoluteFile
.IsEmpty())
929 absoluteFile
= header
;
930 else if (header
!= absoluteFile
)
932 LogError("The method '%s' is documented in a different "
933 "file from others (which belong to '%s') ?",
934 header
, absoluteFile
);
942 membernode
= membernode
->GetNext();
945 // all methods of this class were taken from the header "absoluteFile":
946 klass
.SetHeader(absoluteFile
);
948 else if (subchild
->GetName() == "compoundname")
950 klass
.SetName(subchild
->GetNodeContent());
952 /*else if (subchild->GetName() == "includes")
954 // NOTE: we'll get the header from the <location> tags
955 // scattered inside <memberdef> tags instead of
956 // this <includes> tag since it does not contain
957 // the absolute path of the header
959 klass.SetHeader(subchild->GetNodeContent());
962 subchild
= subchild
->GetNext();
967 m_classes
.Add(klass
);
969 LogWarning("discarding class '%s' with %d methods...",
970 klass
.GetName(), klass
.GetMethodCount());
973 child
= child
->GetNext();
975 // give feedback to the user about the progress...
976 if ((++nodes%PROGRESS_RATE
)==0) ShowProgress();
982 static wxString
GetTextFromChildren(const wxXmlNode
*n
)
988 // <a><b>this</b> is a <b>string</b></a>
997 // unlike wxXmlNode::GetNodeContent() which would return " is a "
998 // this function returns "this is a string"
1000 wxXmlNode
*ref
= n
->GetChildren();
1002 if (ref
->GetType() == wxXML_ELEMENT_NODE
)
1003 text
+= ref
->GetNodeContent();
1004 else if (ref
->GetType() == wxXML_TEXT_NODE
)
1005 text
+= ref
->GetContent();
1007 LogWarning("Unexpected node type while getting text from '%s' node", n
->GetName());
1009 ref
= ref
->GetNext();
1015 bool wxXmlDoxygenInterface::ParseMethod(const wxXmlNode
* p
, wxMethod
& m
, wxString
& header
)
1021 wxXmlNode
*child
= p
->GetChildren();
1024 if (child
->GetName() == "name")
1025 m
.SetName(child
->GetNodeContent());
1026 else if (child
->GetName() == "type")
1027 m
.SetReturnType(wxType(GetTextFromChildren(child
)));
1028 else if (child
->GetName() == "param")
1030 wxString typestr
, defstr
, arrstr
;
1031 wxXmlNode
*n
= child
->GetChildren();
1034 if (n
->GetName() == "type")
1035 // if the <type> node has children, they should be all TEXT and <ref> nodes
1036 // and we need to take the text they contain, in the order they appear
1037 typestr
= GetTextFromChildren(n
);
1038 else if (n
->GetName() == "defval")
1039 // same for the <defval> node
1040 defstr
= GetTextFromChildren(n
);
1041 else if (n
->GetName() == "array")
1042 arrstr
= GetTextFromChildren(n
);
1047 if (typestr
.IsEmpty()) {
1048 LogError("cannot find type node for a param in method '%s'", m
.GetName());
1052 args
.Add(wxType(typestr
+ arrstr
));
1055 else if (child
->GetName() == "location")
1057 if (child
->GetAttribute("line").ToLong(&line
))
1058 m
.SetLocation((int)line
);
1059 header
= child
->GetAttribute("file");
1062 child
= child
->GetNext();
1065 m
.SetArgumentTypes(args
, defs
);
1066 m
.SetConst(p
->GetAttribute("const")=="yes");
1067 m
.SetStatic(p
->GetAttribute("static")=="yes");
1068 m
.SetVirtual(p
->GetAttribute("virt")=="virtual");
1071 LogError("The prototype '%s' is not valid!", m
.GetAsString());