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
;
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
= wxEmptyString
; // 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 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
174 if (!m_args
[i
].IsOk()) {
175 LogError("'%s' method has invalid %d-th argument type: %s",
176 m_strName
, i
, m_args
[i
].GetAsString());
180 // NB: the default value of the arguments can contain pretty much everything
181 // (think to e.g. wxPoint(3+4/2,0) or *wxBLACK or someClass<type>)
182 // so we don't do any test on them.
187 bool wxMethod::operator==(const wxMethod
& m
) const
189 if (GetReturnType() != m
.GetReturnType() ||
190 GetName() != m
.GetName() ||
191 IsConst() != m
.IsConst() ||
192 IsStatic() != m
.IsStatic() ||
193 IsVirtual() != m
.IsVirtual() ||
194 IsPureVirtual() != m
.IsPureVirtual() ||
195 IsDeprecated() != m
.IsDeprecated())
198 if (m_args
.GetCount()!=m
.m_args
.GetCount())
201 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
202 if (m_args
[i
] != m
.m_args
[i
])
208 wxString
wxMethod::GetAsString(bool bWithArgumentNames
) const
212 if (m_retType
!=wxEmptyType
)
213 ret
+= m_retType
.GetAsString() + " ";
214 //else; this is a ctor or dtor
216 ret
+= m_strName
+ "(";
218 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
220 ret
+= m_args
[i
].GetAsString();
222 const wxString
& name
= m_args
[i
].GetArgumentName();
223 if (bWithArgumentNames
&& !name
.IsEmpty())
226 const wxString
& def
= m_args
[i
].GetDefaultValue();
233 if (m_args
.GetCount()>0)
234 ret
= ret
.Left(ret
.Len()-2);
241 ret
= "static " + ret
;
242 if (m_bVirtual
|| m_bPureVirtual
)
243 ret
= "virtual " + ret
;
247 // in doxygen headers we don't need wxDEPRECATED:
249 // ret = "wxDEPRECATED( " + ret + " )";
254 void wxMethod::Dump(wxTextOutputStream
& stream
) const
256 stream
<< "[" + m_retType
.GetAsString() + "]";
257 stream
<< "[" + m_strName
+ "]";
259 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
260 stream
<< "[" + m_args
[i
].GetAsString() + " " + m_args
[i
].GetArgumentName() +
261 "=" + m_args
[i
].GetDefaultValue() + "]";
268 stream
<< " VIRTUAL";
270 stream
<< " PURE-VIRTUAL";
272 stream
<< " DEPRECATED";
277 // ----------------------------------------------------------------------------
279 // ----------------------------------------------------------------------------
281 wxString
wxClass::GetNameWithoutTemplate() const
283 // NB: I'm not sure this is the right terminology for this function!
285 if (m_strName
.Contains("<"))
286 return m_strName
.Left(m_strName
.Find("<"));
290 bool wxClass::IsValidCtorForThisClass(const wxMethod
& m
) const
292 // remember that e.g. the ctor for wxWritableCharTypeBuffer<wchar_t> is
293 // named wxWritableCharTypeBuffer, without the <...> part!
295 if (m
.IsCtor() && m
.GetName() == GetNameWithoutTemplate())
301 bool wxClass::IsValidDtorForThisClass(const wxMethod
& m
) const
303 if (m
.IsDtor() && m
.GetName() == "~" + GetNameWithoutTemplate())
309 void wxClass::Dump(wxTextOutputStream
& out
) const
311 out
<< m_strName
+ "\n";
313 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++) {
315 // dump all our methods
317 m_methods
[i
].Dump(out
);
324 bool wxClass::CheckConsistency() const
326 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++)
327 for (unsigned int j
=0; j
<m_methods
.GetCount(); j
++)
328 if (i
!=j
&& m_methods
[i
] == m_methods
[j
])
330 LogError("class %s has two methods with the same prototype: '%s'",
331 m_strName
, m_methods
[i
].GetAsString());
338 const wxMethod
* wxClass::FindMethod(const wxMethod
& m
) const
340 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++)
341 if (m_methods
[i
] == m
)
342 return &m_methods
[i
];
346 wxMethodPtrArray
wxClass::FindMethodNamed(const wxString
& name
) const
348 wxMethodPtrArray ret
;
350 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++)
351 if (m_methods
[i
].GetName() == name
)
352 ret
.Add(&m_methods
[i
]);
358 // ----------------------------------------------------------------------------
360 // ----------------------------------------------------------------------------
362 WX_DEFINE_SORTED_ARRAY(wxClass
*, wxSortedClassArray
);
364 int CompareWxClassObjects(wxClass
*item1
, wxClass
*item2
)
366 // sort alphabetically
367 return item1
->GetName().Cmp(item2
->GetName());
370 void wxXmlInterface::Dump(const wxString
& filename
)
372 wxFFileOutputStream
apioutput( filename
);
373 wxTextOutputStream
apiout( apioutput
);
375 // dump the classes in alphabetical order
376 wxSortedClassArray
sorted(CompareWxClassObjects
);
377 sorted
.Alloc(m_classes
.GetCount());
378 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
379 sorted
.Add(&m_classes
[i
]);
381 // now they have been sorted
382 for (unsigned int i
=0; i
<sorted
.GetCount(); i
++)
383 sorted
[i
]->Dump(apiout
);
386 bool wxXmlInterface::CheckParseResults() const
388 // this check can be quite slow, so do it only for debug releases:
390 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
391 if (!m_classes
[i
].CheckConsistency())
398 // ----------------------------------------------------------------------------
399 // wxXmlGccInterface helper declarations
400 // ----------------------------------------------------------------------------
402 #define ATTRIB_CONST 1
403 #define ATTRIB_REFERENCE 2
404 #define ATTRIB_POINTER 4
405 #define ATTRIB_ARRAY 8
407 #define GCCXML_BASE 35
409 class toResolveTypeItem
412 toResolveTypeItem() { attribs
=0; }
413 toResolveTypeItem(unsigned int refID
, unsigned int attribint
)
414 : ref(refID
), attribs(attribint
) {}
416 unsigned long ref
, attribs
;
421 // for wxToResolveTypeHashMap, keys == gccXML IDs and values == toResolveTypeItem
422 WX_DECLARE_HASH_MAP( unsigned long, toResolveTypeItem
,
423 wxIntegerHash
, wxIntegerEqual
,
424 wxToResolveTypeHashMap
);
426 // for wxClassMemberIdHashMap, keys == gccXML IDs and values == wxClass which owns that member ID
427 WX_DECLARE_HASH_MAP( unsigned long, wxClass
*,
428 wxIntegerHash
, wxIntegerEqual
,
429 wxClassMemberIdHashMap
);
432 typedef std::map
<unsigned long, toResolveTypeItem
> wxToResolveTypeHashMap
;
436 // utility to parse gccXML ID values;
437 // this function is equivalent to wxString(str).Mid(1).ToULong(&id, GCCXML_BASE)
438 // but is a little bit faster
439 bool getID(unsigned long *id
, const wxStringCharType
* str
)
441 wxStringCharType
*end
;
442 #if wxUSE_UNICODE_UTF8
443 unsigned long val
= strtoul(str
+1, &end
, GCCXML_BASE
);
445 unsigned long val
= wcstoul(str
+1, &end
, GCCXML_BASE
);
448 // return true only if scan was stopped by the terminating NUL and
449 // if the string was not empty to start with and no under/overflow
451 if ( *end
!= '\0' || end
== str
+1 || errno
== ERANGE
|| errno
== EINVAL
)
458 // utility specialized to parse efficiently the gccXML list of IDs which occur
459 // in nodes like <Class> ones... i.e. numeric values separed by " _" token
460 bool getMemberIDs(wxClassMemberIdHashMap
* map
, wxClass
* p
, const wxStringCharType
* str
)
462 #if wxUSE_UNICODE_UTF8
463 size_t len
= strlen(str
);
465 size_t len
= wcslen(str
);
468 if (len
== 0 || str
[0] != '_')
471 const wxStringCharType
*curpos
= str
,
473 wxStringCharType
*nexttoken
;
477 // curpos always points to the underscore of the next token to parse:
478 #if wxUSE_UNICODE_UTF8
479 unsigned long id
= strtoul(curpos
+1, &nexttoken
, GCCXML_BASE
);
481 unsigned long id
= wcstoul(curpos
+1, &nexttoken
, GCCXML_BASE
);
483 if ( *nexttoken
!= ' ' || errno
== ERANGE
|| errno
== EINVAL
)
486 // advance current position
487 curpos
= nexttoken
+ 1;
489 // add this ID to the hashmap
490 wxClassMemberIdHashMap::value_type
v(id
, p
);
498 // ----------------------------------------------------------------------------
500 // ----------------------------------------------------------------------------
502 bool wxXmlGccInterface::Parse(const wxString
& filename
)
508 LogMessage("Parsing %s...", filename
);
510 if (!doc
.Load(filename
)) {
511 LogError("can't load %s", filename
);
515 // start processing the XML file
516 if (doc
.GetRoot()->GetName() != "GCC_XML") {
517 LogError("invalid root node for %s", filename
);
521 wxToResolveTypeHashMap toResolveTypes
;
522 wxClassMemberIdHashMap members
;
523 wxTypeIdHashMap types
;
524 wxTypeIdHashMap files
;
526 // prealloc quite a lot of memory!
527 m_classes
.Alloc(ESTIMATED_NUM_CLASSES
);
529 // build a list of wx classes and in general of all existent types
530 child
= doc
.GetRoot()->GetChildren();
533 const wxString
& n
= child
->GetName();
535 unsigned long id
= 0;
536 if (!getID(&id
, child
->GetAttribute("id")) || (id
== 0 && n
!= "File")) {
538 // NOTE: <File> nodes can have an id == "f0"...
540 LogError("Invalid id for node %s: %s", n
, child
->GetAttribute("id"));
546 wxString cname
= child
->GetAttribute("name");
547 if (cname
.IsEmpty()) {
548 LogError("Invalid empty name for '%s' node", n
);
552 // only register wx classes (do remember also the IDs of their members)
553 if (cname
.StartsWith("wx"))
555 // NB: "file" attribute contains an ID value that we'll resolve later
556 m_classes
.Add(wxClass(cname
, child
->GetAttribute("file")));
558 const wxString
& ids
= child
->GetAttribute("members");
561 if (child
->GetAttribute("incomplete") != "1") {
562 LogError("Invalid member IDs for '%s' class node (ID %s)",
563 cname
, child
->GetAttribute("id"));
566 //else: don't warn the user; it looks like "incomplete" classes
567 // never have any member...
571 // decode the non-empty list of IDs:
572 if (!getMemberIDs(&members
, &m_classes
.Last(), ids
)) {
573 LogError("Invalid member IDs for '%s' class node (ID %s)",
574 cname
, child
->GetAttribute("id"));
580 // register this class also as possible return/argument type:
583 else if (n
== "PointerType" || n
== "ReferenceType" ||
584 n
== "CvQualifiedType" || n
== "ArrayType")
586 unsigned long type
= 0;
587 if (!getID(&type
, child
->GetAttribute("type")) || type
== 0) {
588 LogError("Invalid type for node %s: %s", n
, child
->GetAttribute("type"));
592 unsigned long attr
= 0;
593 if (n
== "PointerType")
594 attr
= ATTRIB_POINTER
;
595 else if (n
== "ReferenceType")
596 attr
= ATTRIB_REFERENCE
;
597 else if (n
== "CvQualifiedType" && child
->GetAttribute("const") == "1")
599 else if (n
== "ArrayType")
602 // these nodes make reference to other types... we'll resolve them later
603 toResolveTypes
[id
] = toResolveTypeItem(type
, attr
);
605 else if (n
== "FunctionType" || n
== "MethodType")
608 TODO: parsing FunctionType and MethodType nodes is not as easy
609 as for other "simple" types.
613 wxXmlNode
*arg
= child
->GetChildren();
616 if (arg
->GetName() == "Argument")
617 argstr
+= arg
->GetAttribute("type") + ", ";
618 arg
= arg
->GetNext();
621 if (argstr
.Len() > 0)
622 argstr
= argstr
.Left(argstr
.Len()-2);
624 // these nodes make reference to other types... we'll resolve them later
625 //toResolveTypes[id] = toResolveTypeItem(ret, 0);
626 types
[id
] = child
->GetAttribute("returns") + "(" + argstr
+ ")";
628 else if (n
== "File")
630 if (!child
->GetAttribute("id").StartsWith("f")) {
631 LogError("Unexpected file ID: %s", id
);
635 // just ignore this node... all file IDs/names were already parsed
636 files
[id
] = child
->GetAttribute("name");
640 // we register everything else as a possible return/argument type:
641 const wxString
& name
= child
->GetAttribute("name");
646 //typeNames.Add(name);
651 // this may happen with unnamed structs/union, special ctors,
652 // or other exotic things which we are not interested to, since
653 // they're never used as return/argument types by wxWidgets methods
656 LogWarning("Type '%s' with ID '%s' does not have name attribute", n
, id
);
662 child
= child
->GetNext();
664 // give feedback to the user about the progress...
665 if ((++nodes%PROGRESS_RATE
)==0) ShowProgress();
668 // some nodes with IDs referenced by methods as return/argument types, do reference
669 // in turn o ther nodes (see PointerType, ReferenceType and CvQualifierType above);
670 // thus we need to resolve their name iteratively:
671 while (toResolveTypes
.size()>0)
674 LogMessage("%d types were collected; %d types need yet to be resolved...",
675 types
.size(), toResolveTypes
.size());
677 for (wxToResolveTypeHashMap::iterator i
= toResolveTypes
.begin();
678 i
!= toResolveTypes
.end();)
680 unsigned long id
= i
->first
;
681 unsigned long referenced
= i
->second
.ref
;
683 wxTypeIdHashMap::iterator primary
= types
.find(referenced
);
684 if (primary
!= types
.end())
686 // this to-resolve-type references a "primary" type
688 wxString newtype
= primary
->second
;
689 int attribs
= i
->second
.attribs
;
691 // attribs may contain a combination of ATTRIB_* flags:
692 if (attribs
& ATTRIB_CONST
)
693 newtype
= "const " + newtype
;
694 if (attribs
& ATTRIB_REFERENCE
)
695 newtype
= newtype
+ "&";
696 if (attribs
& ATTRIB_POINTER
)
697 newtype
= newtype
+ "*";
698 if (attribs
& ATTRIB_ARRAY
)
699 newtype
= newtype
+ "[]";
701 // add the resolved type to the list of "primary" types
704 // this one has been resolved; erase it through its iterator!
705 toResolveTypes
.erase(i
);
707 // now iterator i is invalid; assign it again to the beginning
708 i
= toResolveTypes
.begin();
712 // then search in the referenced types themselves:
713 wxToResolveTypeHashMap::iterator idx2
= toResolveTypes
.find(referenced
);
714 if (idx2
!= toResolveTypes
.end())
716 // merge this to-resolve-type with the idx2->second type
717 i
->second
.ref
= idx2
->second
.ref
;
718 i
->second
.attribs
|= idx2
->second
.attribs
;
720 // this type will eventually be solved in the next while() iteration
725 LogError("Cannot solve '%s' reference type!", referenced
);
732 // resolve header names
733 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
735 unsigned long fileID
= 0;
736 if (!getID(&fileID
, m_classes
[i
].GetHeader()) || fileID
== 0) {
737 LogError("invalid header id: %s", m_classes
[i
].GetHeader());
742 wxTypeIdHashMap::const_iterator idx
= files
.find(fileID
);
743 if (idx
== files
.end())
746 LogError("couldn't find file ID '%s'", m_classes
[i
].GetHeader());
749 m_classes
[i
].SetHeader(idx
->second
);
752 // build the list of the wx methods
753 child
= doc
.GetRoot()->GetChildren();
756 wxString n
= child
->GetName();
758 // only register public methods
759 if (child
->GetAttribute("access") == "public" &&
760 (n
== "Method" || n
== "Constructor" || n
== "Destructor" || n
== "OperatorMethod"))
762 unsigned long id
= 0;
763 if (!getID(&id
, child
->GetAttribute("id"))) {
764 LogError("invalid ID for node '%s' with ID '%s'", n
, child
->GetAttribute("id"));
768 wxClassMemberIdHashMap::const_iterator it
= members
.find(id
);
769 if (it
!= members
.end())
771 wxClass
*p
= it
->second
;
773 // this <Method> node is a method of the i-th class!
775 if (!ParseMethod(child
, types
, newfunc
))
778 if (newfunc
.IsCtor() && !p
->IsValidCtorForThisClass(newfunc
)) {
779 LogError("The method '%s' does not seem to be a ctor for '%s'",
780 newfunc
.GetName(), p
->GetName());
783 if (newfunc
.IsDtor() && !p
->IsValidDtorForThisClass(newfunc
)) {
784 LogError("The method '%s' does not seem to be a dtor for '%s'",
785 newfunc
.GetName(), p
->GetName());
789 p
->AddMethod(newfunc
);
793 child
= child
->GetNext();
795 // give feedback to the user about the progress...
796 if ((++nodes%PROGRESS_RATE
)==0) ShowProgress();
800 if (!CheckParseResults())
806 bool wxXmlGccInterface::ParseMethod(const wxXmlNode
*p
,
807 const wxTypeIdHashMap
& types
,
811 wxString name
= p
->GetAttribute("name").Strip(wxString::both
);
812 if (p
->GetName() == "Destructor")
814 else if (p
->GetName() == "OperatorMethod")
815 name
= "operator" + name
;
817 // resolve return type
819 unsigned long retid
= 0;
820 if (!getID(&retid
, p
->GetAttribute("returns")) || retid
== 0)
822 if (p
->GetName() != "Destructor" && p
->GetName() != "Constructor") {
823 LogError("Empty return ID for method '%s', with ID '%s'",
824 name
, p
->GetAttribute("id"));
830 wxTypeIdHashMap::const_iterator retidx
= types
.find(retid
);
831 if (retidx
== types
.end()) {
832 LogError("Could not find return type ID '%s'", retid
);
836 ret
= wxType(retidx
->second
);
838 LogError("Invalid return type '%s' for method '%s', with ID '%s'",
839 retidx
->second
, name
, p
->GetAttribute("id"));
844 // resolve argument types
845 wxArgumentTypeArray argtypes
;
846 wxXmlNode
*arg
= p
->GetChildren();
849 if (arg
->GetName() == "Argument")
851 unsigned long id
= 0;
852 if (!getID(&id
, arg
->GetAttribute("type")) || id
== 0) {
853 LogError("Invalid argument type ID '%s' for method '%s' with ID %s",
854 arg
->GetAttribute("type"), name
, p
->GetAttribute("id"));
858 wxTypeIdHashMap::const_iterator idx
= types
.find(id
);
859 if (idx
== types
.end()) {
860 LogError("Could not find argument type ID '%s'", id
);
864 argtypes
.Add(wxArgumentType(idx
->second
, arg
->GetAttribute("default")));
867 arg
= arg
->GetNext();
870 m
.SetReturnType(ret
);
872 m
.SetArgumentTypes(argtypes
);
873 m
.SetConst(p
->GetAttribute("const") == "1");
874 m
.SetStatic(p
->GetAttribute("static") == "1");
875 m
.SetVirtual(p
->GetAttribute("virtual") == "1");
876 m
.SetPureVirtual(p
->GetAttribute("pure_virtual") == "1");
877 m
.SetDeprecated(p
->GetAttribute("attributes") == "deprecated");
880 LogError("The prototype '%s' is not valid!", m
.GetAsString());
888 // ----------------------------------------------------------------------------
889 // wxXmlDoxygenInterface
890 // ----------------------------------------------------------------------------
892 bool wxXmlDoxygenInterface::Parse(const wxString
& filename
)
897 LogMessage("Parsing %s...", filename
);
899 if (!index
.Load(filename
)) {
900 LogError("can't load %s", filename
);
904 // start processing the index:
905 if (index
.GetRoot()->GetName() != "doxygenindex") {
906 LogError("invalid root node for %s", filename
);
910 m_classes
.Alloc(ESTIMATED_NUM_CLASSES
);
912 // process files referenced by this index file
913 compound
= index
.GetRoot()->GetChildren();
916 if (compound
->GetName() == "compound" &&
917 compound
->GetAttribute("kind") == "class")
919 wxString refid
= compound
->GetAttribute("refid");
921 wxFileName
fn(filename
);
922 if (!ParseCompoundDefinition(fn
.GetPath(wxPATH_GET_SEPARATOR
) + refid
+ ".xml"))
926 compound
= compound
->GetNext();
930 if (!CheckParseResults())
936 bool wxXmlDoxygenInterface::ParseCompoundDefinition(const wxString
& filename
)
943 LogMessage("Parsing %s...", filename
);
945 if (!doc
.Load(filename
)) {
946 LogError("can't load %s", filename
);
950 // start processing this compound definition XML
951 if (doc
.GetRoot()->GetName() != "doxygen") {
952 LogError("invalid root node for %s", filename
);
956 // build a list of wx classes
957 child
= doc
.GetRoot()->GetChildren();
960 if (child
->GetName() == "compounddef" &&
961 child
->GetAttribute("kind") == "class")
965 wxString absoluteFile
, header
;
967 wxXmlNode
*subchild
= child
->GetChildren();
970 if (subchild
->GetName() == "sectiondef" &&
971 subchild
->GetAttribute("kind") == "public-func")
974 wxXmlNode
*membernode
= subchild
->GetChildren();
977 if (membernode
->GetName() == "memberdef" &&
978 membernode
->GetAttribute("kind") == "function")
982 if (ParseMethod(membernode
, m
, header
))
984 if (absoluteFile
.IsEmpty())
985 absoluteFile
= header
;
986 else if (header
!= absoluteFile
)
988 LogError("The method '%s' is documented in a different "
989 "file from others (which belong to '%s') ?",
990 header
, absoluteFile
);
998 membernode
= membernode
->GetNext();
1001 // all methods of this class were taken from the header "absoluteFile":
1002 klass
.SetHeader(absoluteFile
);
1004 else if (subchild
->GetName() == "compoundname")
1006 klass
.SetName(subchild
->GetNodeContent());
1008 /*else if (subchild->GetName() == "includes")
1010 // NOTE: we'll get the header from the <location> tags
1011 // scattered inside <memberdef> tags instead of
1012 // this <includes> tag since it does not contain
1013 // the absolute path of the header
1015 klass.SetHeader(subchild->GetNodeContent());
1018 subchild
= subchild
->GetNext();
1023 m_classes
.Add(klass
);
1025 LogWarning("discarding class '%s' with %d methods...",
1026 klass
.GetName(), klass
.GetMethodCount());
1029 child
= child
->GetNext();
1031 // give feedback to the user about the progress...
1032 if ((++nodes%PROGRESS_RATE
)==0) ShowProgress();
1038 static wxString
GetTextFromChildren(const wxXmlNode
*n
)
1042 // consider the tree
1044 // <a><b>this</b> is a <b>string</b></a>
1053 // unlike wxXmlNode::GetNodeContent() which would return " is a "
1054 // this function returns "this is a string"
1056 wxXmlNode
*ref
= n
->GetChildren();
1058 if (ref
->GetType() == wxXML_ELEMENT_NODE
)
1059 text
+= ref
->GetNodeContent();
1060 else if (ref
->GetType() == wxXML_TEXT_NODE
)
1061 text
+= ref
->GetContent();
1063 LogWarning("Unexpected node type while getting text from '%s' node", n
->GetName());
1065 ref
= ref
->GetNext();
1071 static bool HasTextNodeContaining(const wxXmlNode
*parent
, const wxString
& name
)
1073 wxXmlNode
*p
= parent
->GetChildren();
1076 switch (p
->GetType())
1078 case wxXML_TEXT_NODE
:
1079 if (p
->GetContent() == name
)
1083 case wxXML_ELEMENT_NODE
:
1084 // recurse into this node...
1085 if (HasTextNodeContaining(p
, name
))
1100 bool wxXmlDoxygenInterface::ParseMethod(const wxXmlNode
* p
, wxMethod
& m
, wxString
& header
)
1102 wxArgumentTypeArray args
;
1105 wxXmlNode
*child
= p
->GetChildren();
1108 if (child
->GetName() == "name")
1109 m
.SetName(child
->GetNodeContent());
1110 else if (child
->GetName() == "type")
1111 m
.SetReturnType(wxType(GetTextFromChildren(child
)));
1112 else if (child
->GetName() == "param")
1114 wxString typestr
, namestr
, defstr
, arrstr
;
1115 wxXmlNode
*n
= child
->GetChildren();
1118 if (n
->GetName() == "type")
1119 // if the <type> node has children, they should be all TEXT and <ref> nodes
1120 // and we need to take the text they contain, in the order they appear
1121 typestr
= GetTextFromChildren(n
);
1122 else if (n
->GetName() == "declname")
1123 namestr
= GetTextFromChildren(n
);
1124 else if (n
->GetName() == "defval")
1125 defstr
= GetTextFromChildren(n
);
1126 else if (n
->GetName() == "array")
1127 arrstr
= GetTextFromChildren(n
);
1132 if (typestr
.IsEmpty()) {
1133 LogError("cannot find type node for a param in method '%s'", m
.GetName());
1137 args
.Add(wxArgumentType(typestr
+ arrstr
, defstr
, namestr
));
1139 else if (child
->GetName() == "location")
1142 if (child
->GetAttribute("line").ToLong(&line
))
1143 m
.SetLocation((int)line
);
1144 header
= child
->GetAttribute("file");
1146 else if (child
->GetName() == "detaileddescription")
1148 // when a method has a @deprecated tag inside its description,
1149 // Doxygen outputs somewhere nested inside <detaileddescription>
1150 // a <xreftitle>Deprecated</xreftitle> tag.
1151 m
.SetDeprecated(HasTextNodeContaining(child
, "Deprecated"));
1154 child
= child
->GetNext();
1157 m
.SetArgumentTypes(args
);
1158 m
.SetConst(p
->GetAttribute("const")=="yes");
1159 m
.SetStatic(p
->GetAttribute("static")=="yes");
1160 m
.SetVirtual(p
->GetAttribute("virt")=="virtual");
1161 m
.SetPureVirtual(p
->GetAttribute("virt")=="pure-virtual");
1164 LogError("The prototype '%s' is not valid!", m
.GetAsString());