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(wxMethodArray
)
32 WX_DEFINE_OBJARRAY(wxClassArray
)
35 #define PROGRESS_RATE 1000 // each PROGRESS_RATE nodes processed print a dot
36 #define ESTIMATED_NUM_CLASSES 600 // used by both wxXmlInterface-derived classes to prealloc mem
39 // defined in ifacecheck.cpp
40 extern bool g_verbose
;
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
50 void wxType::SetFromString(const wxString
& t
)
52 m_strType
= t
.Strip(wxString::both
);
54 // [] is the same as * for gccxml
55 m_strType
.Replace("[]", "*");
58 bool wxType::IsOk() const
60 // NB: m_strType can contain the :: operator; think to e.g. the
61 // "reverse_iterator_impl<wxString::const_iterator>" type
62 // It can also contain commas, * and & operators etc
64 return !GetClean().IsEmpty();
67 wxString
wxType::GetClean() const
69 wxString
ret(m_strType
);
70 ret
.Replace("const", "");
71 ret
.Replace("static", "");
74 ret
.Replace("[]", "");
75 return ret
.Strip(wxString::both
);
78 bool wxType::operator==(const wxType
& m
) const
80 // brain-dead comparison:
82 if (GetClean() == m
.GetClean() &&
83 IsConst() == m
.IsConst() &&
84 IsStatic() == m
.IsStatic() &&
85 IsPointer() == m
.IsPointer() &&
86 IsReference() == m
.IsReference())
92 // ----------------------------------------------------------------------------
94 // ----------------------------------------------------------------------------
96 bool wxMethod::IsOk() const
98 // NOTE: m_retType can be a wxEmptyType, and means that this method
99 // is a ctor or a dtor.
100 if (!m_retType
.IsOk() && m_retType
!=wxEmptyType
) {
101 LogError("'%s' method has invalid return type: %s", m_retType
.GetAsString());
105 if (m_strName
.IsEmpty())
108 // a function can't be both const and static or virtual and static!
109 if ((m_bConst
&& m_bStatic
) || (m_bVirtual
&& m_bStatic
)) {
110 LogError("'%s' method can't be both const/static or virtual/static", m_strName
);
114 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
115 if (!m_args
[i
].IsOk()) {
116 LogError("'%s' method has invalid %d-th argument type: %s",
117 m_strName
, i
, m_args
[i
].GetAsString());
121 // NB: the default value of the arguments can contain pretty much everything
122 // (think to e.g. wxPoint(3+4/2,0) or *wxBLACK or someClass<type>)
123 // so we don't do any test on them.
128 void wxMethod::SetArgumentTypes(const wxTypeArray
& arr
, const wxArrayString
& defaults
)
130 wxASSERT(arr
.GetCount()==defaults
.GetCount());
133 m_argDefaults
=defaults
;
135 // in order to make valid&simple comparison on argument defaults,
136 // we reduce some of the multiple forms in which the same things may appear
138 for (unsigned int i
=0; i
<m_argDefaults
.GetCount(); i
++)
140 m_argDefaults
[i
].Replace("NULL", "0");
141 m_argDefaults
[i
].Replace("0u", "0");
145 bool wxMethod::operator==(const wxMethod
& m
) const
147 if (GetReturnType() != m
.GetReturnType() ||
148 GetName() != m
.GetName() ||
149 IsConst() != m
.IsConst() ||
150 IsStatic() != m
.IsStatic() ||
151 IsVirtual() != m
.IsVirtual() ||
152 IsDeprecated() != m
.IsDeprecated())
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)
184 ret
= ret
.Left(ret
.Len()-2);
191 ret
= "static " + ret
;
193 ret
= "virtual " + ret
;
195 // in doxygen headers we don't need wxDEPRECATED:
197 // ret = "wxDEPRECATED( " + ret + " )";
202 void wxMethod::Dump(wxTextOutputStream
& stream
) const
204 stream
<< "[" + m_retType
.GetAsString() + "]";
205 stream
<< "[" + m_strName
+ "]";
207 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
208 stream
<< "[" + m_args
[i
].GetAsString() + "=" + m_argDefaults
[i
] + "]";
215 stream
<< " VIRTUAL";
217 stream
<< " DEPRECATED";
222 // ----------------------------------------------------------------------------
224 // ----------------------------------------------------------------------------
226 wxString
wxClass::GetNameWithoutTemplate() const
228 // NB: I'm not sure this is the right terminology for this function!
230 if (m_strName
.Contains("<"))
231 return m_strName
.Left(m_strName
.Find("<"));
235 bool wxClass::IsValidCtorForThisClass(const wxMethod
& m
) const
237 // remember that e.g. the ctor for wxWritableCharTypeBuffer<wchar_t> is
238 // named wxWritableCharTypeBuffer, without the <...> part!
240 if (m
.IsCtor() && m
.GetName() == GetNameWithoutTemplate())
246 bool wxClass::IsValidDtorForThisClass(const wxMethod
& m
) const
248 if (m
.IsDtor() && m
.GetName() == "~" + GetNameWithoutTemplate())
254 void wxClass::Dump(wxTextOutputStream
& out
) const
256 out
<< m_strName
+ "\n";
258 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++) {
260 // dump all our methods
262 m_methods
[i
].Dump(out
);
269 bool wxClass::CheckConsistency() const
271 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++)
272 for (unsigned int j
=0; j
<m_methods
.GetCount(); j
++)
273 if (i
!=j
&& m_methods
[i
] == m_methods
[j
])
275 LogError("class %s has two methods with the same prototype: '%s'",
276 m_strName
, m_methods
[i
].GetAsString());
283 const wxMethod
* wxClass::FindMethod(const wxMethod
& m
) const
285 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++)
286 if (m_methods
[i
] == m
)
287 return &m_methods
[i
];
291 wxMethodPtrArray
wxClass::FindMethodNamed(const wxString
& name
) const
293 wxMethodPtrArray ret
;
295 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++)
296 if (m_methods
[i
].GetName() == name
)
297 ret
.Add(&m_methods
[i
]);
303 // ----------------------------------------------------------------------------
305 // ----------------------------------------------------------------------------
307 WX_DEFINE_SORTED_ARRAY(wxClass
*, wxSortedClassArray
);
309 int CompareWxClassObjects(wxClass
*item1
, wxClass
*item2
)
311 // sort alphabetically
312 return item1
->GetName().Cmp(item2
->GetName());
315 void wxXmlInterface::Dump(const wxString
& filename
)
317 wxFFileOutputStream
apioutput( filename
);
318 wxTextOutputStream
apiout( apioutput
);
320 // dump the classes in alphabetical order
321 wxSortedClassArray
sorted(CompareWxClassObjects
);
322 sorted
.Alloc(m_classes
.GetCount());
323 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
324 sorted
.Add(&m_classes
[i
]);
326 // now they have been sorted
327 for (unsigned int i
=0; i
<sorted
.GetCount(); i
++)
328 sorted
[i
]->Dump(apiout
);
331 bool wxXmlInterface::CheckParseResults() const
333 // this check can be quite slow, so do it only for debug releases:
335 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
336 if (!m_classes
[i
].CheckConsistency())
343 // ----------------------------------------------------------------------------
344 // wxXmlGccInterface helper declarations
345 // ----------------------------------------------------------------------------
347 #define ATTRIB_CONST 1
348 #define ATTRIB_REFERENCE 2
349 #define ATTRIB_POINTER 4
350 #define ATTRIB_ARRAY 8
352 #define GCCXML_BASE 35
354 class toResolveTypeItem
357 toResolveTypeItem() { attribs
=0; }
358 toResolveTypeItem(unsigned int refID
, unsigned int attribint
)
359 : ref(refID
), attribs(attribint
) {}
361 unsigned long ref
, attribs
;
366 // for wxToResolveTypeHashMap, keys == gccXML IDs and values == toResolveTypeItem
367 WX_DECLARE_HASH_MAP( unsigned long, toResolveTypeItem
,
368 wxIntegerHash
, wxIntegerEqual
,
369 wxToResolveTypeHashMap
);
371 // for wxClassMemberIdHashMap, keys == gccXML IDs and values == wxClass which owns that member ID
372 WX_DECLARE_HASH_MAP( unsigned long, wxClass
*,
373 wxIntegerHash
, wxIntegerEqual
,
374 wxClassMemberIdHashMap
);
377 typedef std::map
<unsigned long, toResolveTypeItem
> wxToResolveTypeHashMap
;
381 // utility to parse gccXML ID values;
382 // this function is equivalent to wxString(str).Mid(1).ToULong(&id, GCCXML_BASE)
383 // but is a little bit faster
384 bool getID(unsigned long *id
, const wxStringCharType
* str
)
386 wxStringCharType
*end
;
387 #if wxUSE_UNICODE_UTF8
388 unsigned long val
= strtoul(str
+1, &end
, GCCXML_BASE
);
390 unsigned long val
= wcstoul(str
+1, &end
, GCCXML_BASE
);
393 // return true only if scan was stopped by the terminating NUL and
394 // if the string was not empty to start with and no under/overflow
396 if ( *end
!= '\0' || end
== str
+1 || errno
== ERANGE
|| errno
== EINVAL
)
403 // utility specialized to parse efficiently the gccXML list of IDs which occur
404 // in nodes like <Class> ones... i.e. numeric values separed by " _" token
405 bool getMemberIDs(wxClassMemberIdHashMap
* map
, wxClass
* p
, const wxStringCharType
* str
)
407 #if wxUSE_UNICODE_UTF8
408 size_t len
= strlen(str
);
410 size_t len
= wcslen(str
);
413 if (len
== 0 || str
[0] != '_')
416 const wxStringCharType
*curpos
= str
,
418 wxStringCharType
*nexttoken
;
422 // curpos always points to the underscore of the next token to parse:
423 #if wxUSE_UNICODE_UTF8
424 unsigned long id
= strtoul(curpos
+1, &nexttoken
, GCCXML_BASE
);
426 unsigned long id
= wcstoul(curpos
+1, &nexttoken
, GCCXML_BASE
);
428 if ( *nexttoken
!= ' ' || errno
== ERANGE
|| errno
== EINVAL
)
431 // advance current position
432 curpos
= nexttoken
+ 1;
434 // add this ID to the hashmap
435 wxClassMemberIdHashMap::value_type
v(id
, p
);
443 // ----------------------------------------------------------------------------
445 // ----------------------------------------------------------------------------
447 bool wxXmlGccInterface::Parse(const wxString
& filename
)
453 LogMessage("Parsing %s...", filename
);
455 if (!doc
.Load(filename
)) {
456 LogError("can't load %s", filename
);
460 // start processing the XML file
461 if (doc
.GetRoot()->GetName() != "GCC_XML") {
462 LogError("invalid root node for %s", filename
);
466 wxToResolveTypeHashMap toResolveTypes
;
467 wxClassMemberIdHashMap members
;
468 wxTypeIdHashMap types
;
469 wxTypeIdHashMap files
;
471 // prealloc quite a lot of memory!
472 m_classes
.Alloc(ESTIMATED_NUM_CLASSES
);
474 // build a list of wx classes and in general of all existent types
475 child
= doc
.GetRoot()->GetChildren();
478 const wxString
& n
= child
->GetName();
480 unsigned long id
= 0;
481 if (!getID(&id
, child
->GetAttribute("id")) || (id
== 0 && n
!= "File")) {
483 // NOTE: <File> nodes can have an id == "f0"...
485 LogError("Invalid id for node %s: %s", n
, child
->GetAttribute("id"));
491 wxString cname
= child
->GetAttribute("name");
492 if (cname
.IsEmpty()) {
493 LogError("Invalid empty name for '%s' node", n
);
497 // only register wx classes (do remember also the IDs of their members)
498 if (cname
.StartsWith("wx"))
500 // NB: "file" attribute contains an ID value that we'll resolve later
501 m_classes
.Add(wxClass(cname
, child
->GetAttribute("file")));
503 const wxString
& ids
= child
->GetAttribute("members");
506 if (child
->GetAttribute("incomplete") != "1") {
507 LogError("Invalid member IDs for '%s' class node (ID %s)",
508 cname
, child
->GetAttribute("id"));
511 //else: don't warn the user; it looks like "incomplete" classes
512 // never have any member...
516 // decode the non-empty list of IDs:
517 if (!getMemberIDs(&members
, &m_classes
.Last(), ids
)) {
518 LogError("Invalid member IDs for '%s' class node (ID %s)",
519 cname
, child
->GetAttribute("id"));
525 // register this class also as possible return/argument type:
528 else if (n
== "PointerType" || n
== "ReferenceType" ||
529 n
== "CvQualifiedType" || n
== "ArrayType")
531 unsigned long type
= 0;
532 if (!getID(&type
, child
->GetAttribute("type")) || type
== 0) {
533 LogError("Invalid type for node %s: %s", n
, child
->GetAttribute("type"));
537 unsigned long attr
= 0;
538 if (n
== "PointerType")
539 attr
= ATTRIB_POINTER
;
540 else if (n
== "ReferenceType")
541 attr
= ATTRIB_REFERENCE
;
542 else if (n
== "CvQualifiedType" && child
->GetAttribute("const") == "1")
544 else if (n
== "ArrayType")
547 // these nodes make reference to other types... we'll resolve them later
548 toResolveTypes
[id
] = toResolveTypeItem(type
, attr
);
550 else if (n
== "FunctionType" || n
== "MethodType")
553 TODO: parsing FunctionType and MethodType nodes is not as easy
554 as for other "simple" types.
558 wxXmlNode
*arg
= child
->GetChildren();
561 if (arg
->GetName() == "Argument")
562 argstr
+= arg
->GetAttribute("type") + ", ";
563 arg
= arg
->GetNext();
566 if (argstr
.Len() > 0)
567 argstr
= argstr
.Left(argstr
.Len()-2);
569 // these nodes make reference to other types... we'll resolve them later
570 //toResolveTypes[id] = toResolveTypeItem(ret, 0);
571 types
[id
] = child
->GetAttribute("returns") + "(" + argstr
+ ")";
573 else if (n
== "File")
575 if (!child
->GetAttribute("id").StartsWith("f")) {
576 LogError("Unexpected file ID: %s", id
);
580 // just ignore this node... all file IDs/names were already parsed
581 files
[id
] = child
->GetAttribute("name");
585 // we register everything else as a possible return/argument type:
586 const wxString
& name
= child
->GetAttribute("name");
591 //typeNames.Add(name);
596 // this may happen with unnamed structs/union, special ctors,
597 // or other exotic things which we are not interested to, since
598 // they're never used as return/argument types by wxWidgets methods
601 LogWarning("Type '%s' with ID '%s' does not have name attribute", n
, id
);
607 child
= child
->GetNext();
609 // give feedback to the user about the progress...
610 if ((++nodes%PROGRESS_RATE
)==0) ShowProgress();
613 // some nodes with IDs referenced by methods as return/argument types, do reference
614 // in turn o ther nodes (see PointerType, ReferenceType and CvQualifierType above);
615 // thus we need to resolve their name iteratively:
616 while (toResolveTypes
.size()>0)
619 LogMessage("%d types were collected; %d types need yet to be resolved...",
620 types
.size(), toResolveTypes
.size());
622 for (wxToResolveTypeHashMap::iterator i
= toResolveTypes
.begin();
623 i
!= toResolveTypes
.end();)
625 unsigned long id
= i
->first
;
626 unsigned long referenced
= i
->second
.ref
;
628 wxTypeIdHashMap::iterator primary
= types
.find(referenced
);
629 if (primary
!= types
.end())
631 // this to-resolve-type references a "primary" type
633 wxString newtype
= primary
->second
;
634 int attribs
= i
->second
.attribs
;
636 // attribs may contain a combination of ATTRIB_* flags:
637 if (attribs
& ATTRIB_CONST
)
638 newtype
= "const " + newtype
;
639 if (attribs
& ATTRIB_REFERENCE
)
640 newtype
= newtype
+ "&";
641 if (attribs
& ATTRIB_POINTER
)
642 newtype
= newtype
+ "*";
643 if (attribs
& ATTRIB_ARRAY
)
644 newtype
= newtype
+ "[]";
646 // add the resolved type to the list of "primary" types
649 // this one has been resolved; erase it through its iterator!
650 toResolveTypes
.erase(i
);
652 // now iterator i is invalid; assign it again to the beginning
653 i
= toResolveTypes
.begin();
657 // then search in the referenced types themselves:
658 wxToResolveTypeHashMap::iterator idx2
= toResolveTypes
.find(referenced
);
659 if (idx2
!= toResolveTypes
.end())
661 // merge this to-resolve-type with the idx2->second type
662 i
->second
.ref
= idx2
->second
.ref
;
663 i
->second
.attribs
|= idx2
->second
.attribs
;
665 // this type will eventually be solved in the next while() iteration
670 LogError("Cannot solve '%s' reference type!", referenced
);
677 // resolve header names
678 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
680 unsigned long fileID
= 0;
681 if (!getID(&fileID
, m_classes
[i
].GetHeader()) || fileID
== 0) {
682 LogError("invalid header id: %s", m_classes
[i
].GetHeader());
687 wxTypeIdHashMap::const_iterator idx
= files
.find(fileID
);
688 if (idx
== files
.end())
691 LogError("couldn't find file ID '%s'", m_classes
[i
].GetHeader());
694 m_classes
[i
].SetHeader(idx
->second
);
697 // build the list of the wx methods
698 child
= doc
.GetRoot()->GetChildren();
701 wxString n
= child
->GetName();
703 // only register public methods
704 if (child
->GetAttribute("access") == "public" &&
705 (n
== "Method" || n
== "Constructor" || n
== "Destructor" || n
== "OperatorMethod"))
707 unsigned long id
= 0;
708 if (!getID(&id
, child
->GetAttribute("id"))) {
709 LogError("invalid ID for node '%s' with ID '%s'", n
, child
->GetAttribute("id"));
713 wxClassMemberIdHashMap::const_iterator it
= members
.find(id
);
714 if (it
!= members
.end())
716 wxClass
*p
= it
->second
;
718 // this <Method> node is a method of the i-th class!
720 if (!ParseMethod(child
, types
, newfunc
))
723 if (newfunc
.IsCtor() && !p
->IsValidCtorForThisClass(newfunc
)) {
724 LogError("The method '%s' does not seem to be a ctor for '%s'",
725 newfunc
.GetName(), p
->GetName());
728 if (newfunc
.IsDtor() && !p
->IsValidDtorForThisClass(newfunc
)) {
729 LogError("The method '%s' does not seem to be a dtor for '%s'",
730 newfunc
.GetName(), p
->GetName());
734 p
->AddMethod(newfunc
);
738 child
= child
->GetNext();
740 // give feedback to the user about the progress...
741 if ((++nodes%PROGRESS_RATE
)==0) ShowProgress();
745 if (!CheckParseResults())
751 bool wxXmlGccInterface::ParseMethod(const wxXmlNode
*p
,
752 const wxTypeIdHashMap
& types
,
756 wxString name
= p
->GetAttribute("name").Strip(wxString::both
);
757 if (p
->GetName() == "Destructor")
759 else if (p
->GetName() == "OperatorMethod")
760 name
= "operator" + name
;
762 // resolve return type
764 unsigned long retid
= 0;
765 if (!getID(&retid
, p
->GetAttribute("returns")) || retid
== 0)
767 if (p
->GetName() != "Destructor" && p
->GetName() != "Constructor") {
768 LogError("Empty return ID for method '%s', with ID '%s'",
769 name
, p
->GetAttribute("id"));
775 wxTypeIdHashMap::const_iterator retidx
= types
.find(retid
);
776 if (retidx
== types
.end()) {
777 LogError("Could not find return type ID '%s'", retid
);
781 ret
= wxType(retidx
->second
);
783 LogError("Invalid return type '%s' for method '%s', with ID '%s'",
784 retidx
->second
, name
, p
->GetAttribute("id"));
789 // resolve argument types
790 wxTypeArray argtypes
;
791 wxArrayString argdefs
;
792 wxXmlNode
*arg
= p
->GetChildren();
795 if (arg
->GetName() == "Argument")
797 unsigned long id
= 0;
798 if (!getID(&id
, arg
->GetAttribute("type")) || id
== 0) {
799 LogError("Invalid argument type ID '%s' for method '%s' with ID %s",
800 arg
->GetAttribute("type"), name
, p
->GetAttribute("id"));
804 wxTypeIdHashMap::const_iterator idx
= types
.find(id
);
805 if (idx
== types
.end()) {
806 LogError("Could not find argument type ID '%s'", id
);
810 argtypes
.Add(wxType(idx
->second
));
812 wxString def
= arg
->GetAttribute("default");
813 if (def
.Contains("wxGetTranslation"))
814 argdefs
.Add(wxEmptyString
); // TODO: wxGetTranslation gives problems to gccxml
819 arg
= arg
->GetNext();
822 m
.SetReturnType(ret
);
824 m
.SetArgumentTypes(argtypes
, argdefs
);
825 m
.SetConst(p
->GetAttribute("const") == "1");
826 m
.SetStatic(p
->GetAttribute("static") == "1");
827 m
.SetVirtual(p
->GetAttribute("virtual") == "1");
828 m
.SetDeprecated(p
->GetAttribute("attributes") == "deprecated");
831 LogError("The prototype '%s' is not valid!", m
.GetAsString());
839 // ----------------------------------------------------------------------------
840 // wxXmlDoxygenInterface
841 // ----------------------------------------------------------------------------
843 bool wxXmlDoxygenInterface::Parse(const wxString
& filename
)
848 LogMessage("Parsing %s...", filename
);
850 if (!index
.Load(filename
)) {
851 LogError("can't load %s", filename
);
855 // start processing the index:
856 if (index
.GetRoot()->GetName() != "doxygenindex") {
857 LogError("invalid root node for %s", filename
);
861 m_classes
.Alloc(ESTIMATED_NUM_CLASSES
);
863 // process files referenced by this index file
864 compound
= index
.GetRoot()->GetChildren();
867 if (compound
->GetName() == "compound" &&
868 compound
->GetAttribute("kind") == "class")
870 wxString refid
= compound
->GetAttribute("refid");
872 wxFileName
fn(filename
);
873 if (!ParseCompoundDefinition(fn
.GetPath(wxPATH_GET_SEPARATOR
) + refid
+ ".xml"))
877 compound
= compound
->GetNext();
881 if (!CheckParseResults())
887 bool wxXmlDoxygenInterface::ParseCompoundDefinition(const wxString
& filename
)
894 LogMessage("Parsing %s...", filename
);
896 if (!doc
.Load(filename
)) {
897 LogError("can't load %s", filename
);
901 // start processing this compound definition XML
902 if (doc
.GetRoot()->GetName() != "doxygen") {
903 LogError("invalid root node for %s", filename
);
907 // build a list of wx classes
908 child
= doc
.GetRoot()->GetChildren();
911 if (child
->GetName() == "compounddef" &&
912 child
->GetAttribute("kind") == "class")
916 wxString absoluteFile
, header
;
918 wxXmlNode
*subchild
= child
->GetChildren();
921 if (subchild
->GetName() == "sectiondef" &&
922 subchild
->GetAttribute("kind") == "public-func")
925 wxXmlNode
*membernode
= subchild
->GetChildren();
928 if (membernode
->GetName() == "memberdef" &&
929 membernode
->GetAttribute("kind") == "function")
933 if (ParseMethod(membernode
, m
, header
))
935 if (absoluteFile
.IsEmpty())
936 absoluteFile
= header
;
937 else if (header
!= absoluteFile
)
939 LogError("The method '%s' is documented in a different "
940 "file from others (which belong to '%s') ?",
941 header
, absoluteFile
);
949 membernode
= membernode
->GetNext();
952 // all methods of this class were taken from the header "absoluteFile":
953 klass
.SetHeader(absoluteFile
);
955 else if (subchild
->GetName() == "compoundname")
957 klass
.SetName(subchild
->GetNodeContent());
959 /*else if (subchild->GetName() == "includes")
961 // NOTE: we'll get the header from the <location> tags
962 // scattered inside <memberdef> tags instead of
963 // this <includes> tag since it does not contain
964 // the absolute path of the header
966 klass.SetHeader(subchild->GetNodeContent());
969 subchild
= subchild
->GetNext();
974 m_classes
.Add(klass
);
976 LogWarning("discarding class '%s' with %d methods...",
977 klass
.GetName(), klass
.GetMethodCount());
980 child
= child
->GetNext();
982 // give feedback to the user about the progress...
983 if ((++nodes%PROGRESS_RATE
)==0) ShowProgress();
989 static wxString
GetTextFromChildren(const wxXmlNode
*n
)
995 // <a><b>this</b> is a <b>string</b></a>
1004 // unlike wxXmlNode::GetNodeContent() which would return " is a "
1005 // this function returns "this is a string"
1007 wxXmlNode
*ref
= n
->GetChildren();
1009 if (ref
->GetType() == wxXML_ELEMENT_NODE
)
1010 text
+= ref
->GetNodeContent();
1011 else if (ref
->GetType() == wxXML_TEXT_NODE
)
1012 text
+= ref
->GetContent();
1014 LogWarning("Unexpected node type while getting text from '%s' node", n
->GetName());
1016 ref
= ref
->GetNext();
1022 static bool HasTextNodeContaining(const wxXmlNode
*parent
, const wxString
& name
)
1024 wxXmlNode
*p
= parent
->GetChildren();
1027 switch (p
->GetType())
1029 case wxXML_TEXT_NODE
:
1030 if (p
->GetContent() == name
)
1034 case wxXML_ELEMENT_NODE
:
1035 // recurse into this node...
1036 if (HasTextNodeContaining(p
, name
))
1051 bool wxXmlDoxygenInterface::ParseMethod(const wxXmlNode
* p
, wxMethod
& m
, wxString
& header
)
1057 wxXmlNode
*child
= p
->GetChildren();
1060 if (child
->GetName() == "name")
1061 m
.SetName(child
->GetNodeContent());
1062 else if (child
->GetName() == "type")
1063 m
.SetReturnType(wxType(GetTextFromChildren(child
)));
1064 else if (child
->GetName() == "param")
1066 wxString typestr
, defstr
, arrstr
;
1067 wxXmlNode
*n
= child
->GetChildren();
1070 if (n
->GetName() == "type")
1071 // if the <type> node has children, they should be all TEXT and <ref> nodes
1072 // and we need to take the text they contain, in the order they appear
1073 typestr
= GetTextFromChildren(n
);
1074 else if (n
->GetName() == "defval")
1075 // same for the <defval> node
1076 defstr
= GetTextFromChildren(n
);
1077 else if (n
->GetName() == "array")
1078 arrstr
= GetTextFromChildren(n
);
1083 if (typestr
.IsEmpty()) {
1084 LogError("cannot find type node for a param in method '%s'", m
.GetName());
1088 args
.Add(wxType(typestr
+ arrstr
));
1091 else if (child
->GetName() == "location")
1094 if (child
->GetAttribute("line").ToLong(&line
))
1095 m
.SetLocation((int)line
);
1096 header
= child
->GetAttribute("file");
1098 else if (child
->GetName() == "detaileddescription")
1100 // when a method has a @deprecated tag inside its description,
1101 // Doxygen outputs somewhere nested inside <detaileddescription>
1102 // a <xreftitle>Deprecated</xreftitle> tag.
1103 m
.SetDeprecated(HasTextNodeContaining(child
, "Deprecated"));
1106 child
= child
->GetNext();
1109 m
.SetArgumentTypes(args
, defs
);
1110 m
.SetConst(p
->GetAttribute("const")=="yes");
1111 m
.SetStatic(p
->GetAttribute("static")=="yes");
1112 m
.SetVirtual(p
->GetAttribute("virt")=="virtual");
1115 LogError("The prototype '%s' is not valid!", m
.GetAsString());