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
, const wxString
& defvalForCmp
)
120 m_strDefaultValue
=defval
.Strip(wxString::both
);
121 m_strDefaultValueForCmp
=defvalForCmp
.Strip(wxString::both
);
123 // in order to make valid&simple comparison on argument defaults,
124 // we reduce some of the multiple forms in which the same things may appear
126 m_strDefaultValue.Replace("0u", "0");
129 m_strDefaultValue.Replace("0", "NULL");
131 m_strDefaultValue.Replace("NULL", "0");
134 if (m_strDefaultValue
.Contains("wxGetTranslation"))
135 m_strDefaultValue
= "_(TOFIX)"; // TODO: wxGetTranslation gives problems to gccxml
138 bool wxArgumentType::operator==(const wxArgumentType
& m
) const
140 if ((const wxType
&)(*this) != (const wxType
&)m
)
143 const wxString
& def1
= m_strDefaultValueForCmp
.IsEmpty() ? m_strDefaultValue
: m_strDefaultValueForCmp
;
144 const wxString
& def2
= m
.m_strDefaultValueForCmp
.IsEmpty() ? m
.m_strDefaultValue
: m
.m_strDefaultValueForCmp
;
149 // we deliberately avoid checks on the argument name
155 // ----------------------------------------------------------------------------
157 // ----------------------------------------------------------------------------
159 bool wxMethod::IsOk() const
161 // NOTE: m_retType can be a wxEmptyType, and means that this method
162 // is a ctor or a dtor.
163 if (!m_retType
.IsOk() && m_retType
!=wxEmptyType
) {
164 LogError("'%s' method has invalid return type: %s", m_retType
.GetAsString());
168 if (m_strName
.IsEmpty())
171 // a function can't be both const and static or virtual and static!
172 if ((m_bConst
&& m_bStatic
) || ((m_bVirtual
|| m_bPureVirtual
) && m_bStatic
)) {
173 LogError("'%s' method can't be both const/static or virtual/static", m_strName
);
177 wxASSERT(!m_bPureVirtual
|| (m_bPureVirtual
&& m_bVirtual
));
179 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
180 if (!m_args
[i
].IsOk()) {
181 LogError("'%s' method has invalid %d-th argument type: %s",
182 m_strName
, i
+1, m_args
[i
].GetAsString());
186 // NB: the default value of the arguments can contain pretty much everything
187 // (think to e.g. wxPoint(3+4/2,0) or *wxBLACK or someClass<type>)
188 // so we don't do any test on their contents
189 if (m_args
.GetCount()>0)
191 bool previousArgHasDefault
= m_args
[0].HasDefaultValue();
192 for (unsigned int i
=1; i
<m_args
.GetCount(); i
++)
194 if (previousArgHasDefault
&& !m_args
[i
].HasDefaultValue()) {
195 LogError("'%s' method has %d-th argument which has no default value "
196 "(while the previous one had one!)",
201 previousArgHasDefault
= m_args
[i
].HasDefaultValue();
208 bool wxMethod::operator==(const wxMethod
& m
) const
210 if (GetReturnType() != m
.GetReturnType() ||
211 GetName() != m
.GetName() ||
212 IsConst() != m
.IsConst() ||
213 IsStatic() != m
.IsStatic() ||
214 IsVirtual() != m
.IsVirtual() ||
215 IsPureVirtual() != m
.IsPureVirtual() ||
216 IsDeprecated() != m
.IsDeprecated())
219 if (m_args
.GetCount()!=m
.m_args
.GetCount())
222 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
223 if (m_args
[i
] != m
.m_args
[i
])
229 wxString
wxMethod::GetAsString(bool bWithArgumentNames
) const
233 if (m_retType
!=wxEmptyType
)
234 ret
+= m_retType
.GetAsString() + " ";
235 //else; this is a ctor or dtor
237 ret
+= m_strName
+ "(";
239 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
241 ret
+= m_args
[i
].GetAsString();
243 const wxString
& name
= m_args
[i
].GetArgumentName();
244 if (bWithArgumentNames
&& !name
.IsEmpty())
247 const wxString
& def
= m_args
[i
].GetDefaultValue();
254 if (m_args
.GetCount()>0)
255 ret
= ret
.Left(ret
.Len()-2);
262 ret
= "static " + ret
;
263 if (m_bVirtual
|| m_bPureVirtual
)
264 ret
= "virtual " + ret
;
268 // in doxygen headers we don't need wxDEPRECATED:
270 // ret = "wxDEPRECATED( " + ret + " )";
275 void wxMethod::Dump(wxTextOutputStream
& stream
) const
277 stream
<< "[" + m_retType
.GetAsString() + "]";
278 stream
<< "[" + m_strName
+ "]";
280 for (unsigned int i
=0; i
<m_args
.GetCount(); i
++)
281 stream
<< "[" + m_args
[i
].GetAsString() + " " + m_args
[i
].GetArgumentName() +
282 "=" + m_args
[i
].GetDefaultValue() + "]";
289 stream
<< " VIRTUAL";
291 stream
<< " PURE-VIRTUAL";
293 stream
<< " DEPRECATED";
298 // ----------------------------------------------------------------------------
300 // ----------------------------------------------------------------------------
302 wxString
wxClass::GetNameWithoutTemplate() const
304 // NB: I'm not sure this is the right terminology for this function!
306 if (m_strName
.Contains("<"))
307 return m_strName
.Left(m_strName
.Find("<"));
311 bool wxClass::IsValidCtorForThisClass(const wxMethod
& m
) const
313 // remember that e.g. the ctor for wxWritableCharTypeBuffer<wchar_t> is
314 // named wxWritableCharTypeBuffer, without the <...> part!
316 if (m
.IsCtor() && m
.GetName() == GetNameWithoutTemplate())
322 bool wxClass::IsValidDtorForThisClass(const wxMethod
& m
) const
324 if (m
.IsDtor() && m
.GetName() == "~" + GetNameWithoutTemplate())
330 void wxClass::Dump(wxTextOutputStream
& out
) const
332 out
<< m_strName
+ "\n";
334 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++) {
336 // dump all our methods
338 m_methods
[i
].Dump(out
);
345 bool wxClass::CheckConsistency() const
347 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++)
348 for (unsigned int j
=0; j
<m_methods
.GetCount(); j
++)
349 if (i
!=j
&& m_methods
[i
] == m_methods
[j
])
351 LogError("class %s has two methods with the same prototype: '%s'",
352 m_strName
, m_methods
[i
].GetAsString());
359 const wxMethod
* wxClass::FindMethod(const wxMethod
& m
) const
361 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++)
362 if (m_methods
[i
] == m
)
363 return &m_methods
[i
];
367 wxMethodPtrArray
wxClass::FindMethodNamed(const wxString
& name
) const
369 wxMethodPtrArray ret
;
371 for (unsigned int i
=0; i
<m_methods
.GetCount(); i
++)
372 if (m_methods
[i
].GetName() == name
)
373 ret
.Add(&m_methods
[i
]);
379 // ----------------------------------------------------------------------------
381 // ----------------------------------------------------------------------------
383 WX_DEFINE_SORTED_ARRAY(wxClass
*, wxSortedClassArray
);
385 int CompareWxClassObjects(wxClass
*item1
, wxClass
*item2
)
387 // sort alphabetically
388 return item1
->GetName().Cmp(item2
->GetName());
391 void wxXmlInterface::Dump(const wxString
& filename
)
393 wxFFileOutputStream
apioutput( filename
);
394 wxTextOutputStream
apiout( apioutput
);
396 // dump the classes in alphabetical order
397 wxSortedClassArray
sorted(CompareWxClassObjects
);
398 sorted
.Alloc(m_classes
.GetCount());
399 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
400 sorted
.Add(&m_classes
[i
]);
402 // now they have been sorted
403 for (unsigned int i
=0; i
<sorted
.GetCount(); i
++)
404 sorted
[i
]->Dump(apiout
);
407 bool wxXmlInterface::CheckParseResults() const
409 // this check can be quite slow, so do it only for debug releases:
411 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
412 if (!m_classes
[i
].CheckConsistency())
419 wxClassPtrArray
wxXmlInterface::FindClassesDefinedIn(const wxString
& headerfile
) const
423 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
424 if (m_classes
[i
].GetHeader() == headerfile
)
425 ret
.Add(&m_classes
[i
]);
431 // ----------------------------------------------------------------------------
432 // wxXmlGccInterface helper declarations
433 // ----------------------------------------------------------------------------
435 #define ATTRIB_CONST 1
436 #define ATTRIB_REFERENCE 2
437 #define ATTRIB_POINTER 4
438 #define ATTRIB_ARRAY 8
440 #define GCCXML_BASE 35
442 class toResolveTypeItem
445 toResolveTypeItem() { attribs
=0; }
446 toResolveTypeItem(unsigned int refID
, unsigned int attribint
)
447 : ref(refID
), attribs(attribint
) {}
449 unsigned long ref
, attribs
;
454 // for wxToResolveTypeHashMap, keys == gccXML IDs and values == toResolveTypeItem
455 WX_DECLARE_HASH_MAP( unsigned long, toResolveTypeItem
,
456 wxIntegerHash
, wxIntegerEqual
,
457 wxToResolveTypeHashMap
);
459 // for wxClassMemberIdHashMap, keys == gccXML IDs and values == wxClass which owns that member ID
460 WX_DECLARE_HASH_MAP( unsigned long, wxClass
*,
461 wxIntegerHash
, wxIntegerEqual
,
462 wxClassMemberIdHashMap
);
465 typedef std::map
<unsigned long, toResolveTypeItem
> wxToResolveTypeHashMap
;
469 // utility to parse gccXML ID values;
470 // this function is equivalent to wxString(str).Mid(1).ToULong(&id, GCCXML_BASE)
471 // but is a little bit faster
472 bool getID(unsigned long *id
, const wxStringCharType
* str
)
474 wxStringCharType
*end
;
475 #if wxUSE_UNICODE_UTF8
476 unsigned long val
= strtoul(str
+1, &end
, GCCXML_BASE
);
478 unsigned long val
= wcstoul(str
+1, &end
, GCCXML_BASE
);
481 // return true only if scan was stopped by the terminating NUL and
482 // if the string was not empty to start with and no under/overflow
484 if ( *end
!= '\0' || end
== str
+1 || errno
== ERANGE
|| errno
== EINVAL
)
491 // utility specialized to parse efficiently the gccXML list of IDs which occur
492 // in nodes like <Class> ones... i.e. numeric values separed by " _" token
493 bool getMemberIDs(wxClassMemberIdHashMap
* map
, wxClass
* p
, const wxStringCharType
* str
)
495 #if wxUSE_UNICODE_UTF8
496 size_t len
= strlen(str
);
498 size_t len
= wcslen(str
);
501 if (len
== 0 || str
[0] != '_')
504 const wxStringCharType
*curpos
= str
,
506 wxStringCharType
*nexttoken
;
510 // curpos always points to the underscore of the next token to parse:
511 #if wxUSE_UNICODE_UTF8
512 unsigned long id
= strtoul(curpos
+1, &nexttoken
, GCCXML_BASE
);
514 unsigned long id
= wcstoul(curpos
+1, &nexttoken
, GCCXML_BASE
);
516 if ( *nexttoken
!= ' ' || errno
== ERANGE
|| errno
== EINVAL
)
519 // advance current position
520 curpos
= nexttoken
+ 1;
522 // add this ID to the hashmap
523 wxClassMemberIdHashMap::value_type
v(id
, p
);
531 // ----------------------------------------------------------------------------
533 // ----------------------------------------------------------------------------
535 bool wxXmlGccInterface::Parse(const wxString
& filename
)
541 LogMessage("Parsing %s...", filename
);
543 if (!doc
.Load(filename
)) {
544 LogError("can't load %s", filename
);
548 // start processing the XML file
549 if (doc
.GetRoot()->GetName() != "GCC_XML") {
550 LogError("invalid root node for %s", filename
);
554 wxToResolveTypeHashMap toResolveTypes
;
555 wxClassMemberIdHashMap members
;
556 wxTypeIdHashMap types
;
557 wxTypeIdHashMap files
;
559 // prealloc quite a lot of memory!
560 m_classes
.Alloc(ESTIMATED_NUM_CLASSES
);
562 // build a list of wx classes and in general of all existent types
563 child
= doc
.GetRoot()->GetChildren();
566 const wxString
& n
= child
->GetName();
568 unsigned long id
= 0;
569 if (!getID(&id
, child
->GetAttribute("id")) || (id
== 0 && n
!= "File")) {
571 // NOTE: <File> nodes can have an id == "f0"...
573 LogError("Invalid id for node %s: %s", n
, child
->GetAttribute("id"));
579 wxString cname
= child
->GetAttribute("name");
580 if (cname
.IsEmpty()) {
581 LogError("Invalid empty name for '%s' node", n
);
585 // only register wx classes (do remember also the IDs of their members)
586 if (cname
.StartsWith("wx"))
588 // NB: "file" attribute contains an ID value that we'll resolve later
589 m_classes
.Add(wxClass(cname
, child
->GetAttribute("file")));
591 const wxString
& ids
= child
->GetAttribute("members");
594 if (child
->GetAttribute("incomplete") != "1") {
595 LogError("Invalid member IDs for '%s' class node: %s",
596 cname
, child
->GetAttribute("id"));
599 //else: don't warn the user; it looks like "incomplete" classes
600 // never have any member...
604 // decode the non-empty list of IDs:
605 if (!getMemberIDs(&members
, &m_classes
.Last(), ids
)) {
606 LogError("Invalid member IDs for '%s' class node: %s",
607 cname
, child
->GetAttribute("id"));
613 // register this class also as possible return/argument type:
616 else if (n
== "PointerType" || n
== "ReferenceType" ||
617 n
== "CvQualifiedType" || n
== "ArrayType")
619 unsigned long type
= 0;
620 if (!getID(&type
, child
->GetAttribute("type")) || type
== 0) {
621 LogError("Invalid type for node %s: %s", n
, child
->GetAttribute("type"));
625 unsigned long attr
= 0;
626 if (n
== "PointerType")
627 attr
= ATTRIB_POINTER
;
628 else if (n
== "ReferenceType")
629 attr
= ATTRIB_REFERENCE
;
630 else if (n
== "CvQualifiedType" && child
->GetAttribute("const") == "1")
632 else if (n
== "ArrayType")
635 // these nodes make reference to other types... we'll resolve them later
636 toResolveTypes
[id
] = toResolveTypeItem(type
, attr
);
638 else if (n
== "FunctionType" || n
== "MethodType")
641 TODO: parsing FunctionType and MethodType nodes is not as easy
642 as for other "simple" types.
646 wxXmlNode
*arg
= child
->GetChildren();
649 if (arg
->GetName() == "Argument")
650 argstr
+= arg
->GetAttribute("type") + ", ";
651 arg
= arg
->GetNext();
654 if (argstr
.Len() > 0)
655 argstr
= argstr
.Left(argstr
.Len()-2);
657 // these nodes make reference to other types... we'll resolve them later
658 //toResolveTypes[id] = toResolveTypeItem(ret, 0);
659 types
[id
] = child
->GetAttribute("returns") + "(" + argstr
+ ")";
661 else if (n
== "File")
663 if (!child
->GetAttribute("id").StartsWith("f")) {
664 LogError("Unexpected file ID: %s", child
->GetAttribute("id"));
668 // just ignore this node... all file IDs/names were already parsed
669 files
[id
] = child
->GetAttribute("name");
673 // we register everything else as a possible return/argument type:
674 const wxString
& name
= child
->GetAttribute("name");
679 //typeNames.Add(name);
684 // this may happen with unnamed structs/union, special ctors,
685 // or other exotic things which we are not interested to, since
686 // they're never used as return/argument types by wxWidgets methods
689 LogWarning("Type node '%s' with ID '%s' does not have name attribute",
690 n
, child
->GetAttribute("id"));
696 child
= child
->GetNext();
698 // give feedback to the user about the progress...
699 if ((++nodes%PROGRESS_RATE
)==0) ShowProgress();
702 // some nodes with IDs referenced by methods as return/argument types, do reference
703 // in turn o ther nodes (see PointerType, ReferenceType and CvQualifierType above);
704 // thus we need to resolve their name iteratively:
705 while (toResolveTypes
.size()>0)
708 LogMessage("%d types were collected; %d types need yet to be resolved...",
709 types
.size(), toResolveTypes
.size());
711 for (wxToResolveTypeHashMap::iterator i
= toResolveTypes
.begin();
712 i
!= toResolveTypes
.end();)
714 unsigned long id
= i
->first
;
715 unsigned long referenced
= i
->second
.ref
;
717 wxTypeIdHashMap::iterator primary
= types
.find(referenced
);
718 if (primary
!= types
.end())
720 // this to-resolve-type references a "primary" type
722 wxString newtype
= primary
->second
;
723 int attribs
= i
->second
.attribs
;
725 // attribs may contain a combination of ATTRIB_* flags:
726 if (attribs
& ATTRIB_CONST
)
727 newtype
= "const " + newtype
;
728 if (attribs
& ATTRIB_REFERENCE
)
729 newtype
= newtype
+ "&";
730 if (attribs
& ATTRIB_POINTER
)
731 newtype
= newtype
+ "*";
732 if (attribs
& ATTRIB_ARRAY
)
733 newtype
= newtype
+ "[]";
735 // add the resolved type to the list of "primary" types
738 // this one has been resolved; erase it through its iterator!
739 toResolveTypes
.erase(i
);
741 // now iterator i is invalid; assign it again to the beginning
742 i
= toResolveTypes
.begin();
746 // then search in the referenced types themselves:
747 wxToResolveTypeHashMap::iterator idx2
= toResolveTypes
.find(referenced
);
748 if (idx2
!= toResolveTypes
.end())
750 // merge this to-resolve-type with the idx2->second type
751 i
->second
.ref
= idx2
->second
.ref
;
752 i
->second
.attribs
|= idx2
->second
.attribs
;
754 // this type will eventually be solved in the next while() iteration
759 LogError("Cannot solve '%s' reference type!", referenced
);
766 // resolve header names
767 for (unsigned int i
=0; i
<m_classes
.GetCount(); i
++)
769 unsigned long fileID
= 0;
770 if (!getID(&fileID
, m_classes
[i
].GetHeader()) || fileID
== 0) {
771 LogError("invalid header id: %s", m_classes
[i
].GetHeader());
776 wxTypeIdHashMap::const_iterator idx
= files
.find(fileID
);
777 if (idx
== files
.end())
780 LogError("couldn't find file ID '%s'", m_classes
[i
].GetHeader());
783 m_classes
[i
].SetHeader(idx
->second
);
786 // build the list of the wx methods
787 child
= doc
.GetRoot()->GetChildren();
790 wxString n
= child
->GetName();
792 // only register public methods
793 if (child
->GetAttribute("access") == "public" &&
794 (n
== "Method" || n
== "Constructor" || n
== "Destructor" || n
== "OperatorMethod"))
796 unsigned long id
= 0;
797 if (!getID(&id
, child
->GetAttribute("id"))) {
798 LogError("invalid ID for node '%s' with ID '%s'", n
, child
->GetAttribute("id"));
802 wxClassMemberIdHashMap::const_iterator it
= members
.find(id
);
803 if (it
!= members
.end())
805 wxClass
*p
= it
->second
;
807 // this <Method> node is a method of the i-th class!
809 if (!ParseMethod(child
, types
, newfunc
)) {
810 LogError("The method '%s' could not be added to class '%s'",
811 child
->GetAttribute("demangled"), p
->GetName());
815 if (newfunc
.IsCtor() && !p
->IsValidCtorForThisClass(newfunc
)) {
816 LogError("The method '%s' does not seem to be a ctor for '%s'",
817 newfunc
.GetName(), p
->GetName());
820 if (newfunc
.IsDtor() && !p
->IsValidDtorForThisClass(newfunc
)) {
821 LogError("The method '%s' does not seem to be a dtor for '%s'",
822 newfunc
.GetName(), p
->GetName());
826 p
->AddMethod(newfunc
);
830 child
= child
->GetNext();
832 // give feedback to the user about the progress...
833 if ((++nodes%PROGRESS_RATE
)==0) ShowProgress();
836 if (!CheckParseResults())
842 bool wxXmlGccInterface::ParseMethod(const wxXmlNode
*p
,
843 const wxTypeIdHashMap
& types
,
847 wxString name
= p
->GetAttribute("name").Strip(wxString::both
);
848 if (p
->GetName() == "Destructor")
850 else if (p
->GetName() == "OperatorMethod")
851 name
= "operator" + name
;
853 // resolve return type
855 unsigned long retid
= 0;
856 if (!getID(&retid
, p
->GetAttribute("returns")) || retid
== 0)
858 if (p
->GetName() != "Destructor" && p
->GetName() != "Constructor") {
859 LogError("Empty return ID for method '%s', with ID '%s'",
860 name
, p
->GetAttribute("id"));
866 wxTypeIdHashMap::const_iterator retidx
= types
.find(retid
);
867 if (retidx
== types
.end()) {
868 LogError("Could not find return type ID '%s'", retid
);
872 ret
= wxType(retidx
->second
);
874 LogError("Invalid return type '%s' for method '%s', with ID '%s'",
875 retidx
->second
, name
, p
->GetAttribute("id"));
880 // resolve argument types
881 wxArgumentTypeArray argtypes
;
882 wxXmlNode
*arg
= p
->GetChildren();
885 if (arg
->GetName() == "Argument")
887 unsigned long id
= 0;
888 if (!getID(&id
, arg
->GetAttribute("type")) || id
== 0) {
889 LogError("Invalid argument type ID '%s' for method '%s' with ID %s",
890 arg
->GetAttribute("type"), name
, p
->GetAttribute("id"));
894 wxTypeIdHashMap::const_iterator idx
= types
.find(id
);
895 if (idx
== types
.end()) {
896 LogError("Could not find argument type ID '%s'", id
);
900 argtypes
.Add(wxArgumentType(idx
->second
, arg
->GetAttribute("default")));
903 arg
= arg
->GetNext();
906 m
.SetReturnType(ret
);
908 m
.SetArgumentTypes(argtypes
);
909 m
.SetConst(p
->GetAttribute("const") == "1");
910 m
.SetStatic(p
->GetAttribute("static") == "1");
912 // NOTE: gccxml is smart enough to mark as virtual those functions
913 // which are declared virtual in base classes but don't have
914 // the "virtual" keyword explicitely indicated in the derived
915 // classes... so we don't need any further logic for virtuals
917 m
.SetVirtual(p
->GetAttribute("virtual") == "1");
918 m
.SetPureVirtual(p
->GetAttribute("pure_virtual") == "1");
919 m
.SetDeprecated(p
->GetAttribute("attributes") == "deprecated");
922 LogError("The prototype '%s' is not valid!", m
.GetAsString());
930 // ----------------------------------------------------------------------------
931 // wxXmlDoxygenInterface
932 // ----------------------------------------------------------------------------
934 bool wxXmlDoxygenInterface::Parse(const wxString
& filename
)
939 LogMessage("Parsing %s...", filename
);
941 if (!index
.Load(filename
)) {
942 LogError("can't load %s", filename
);
946 // start processing the index:
947 if (index
.GetRoot()->GetName() != "doxygenindex") {
948 LogError("invalid root node for %s", filename
);
952 m_classes
.Alloc(ESTIMATED_NUM_CLASSES
);
954 // process files referenced by this index file
955 compound
= index
.GetRoot()->GetChildren();
958 if (compound
->GetName() == "compound" &&
959 compound
->GetAttribute("kind") == "class")
961 wxString refid
= compound
->GetAttribute("refid");
963 wxFileName
fn(filename
);
964 if (!ParseCompoundDefinition(fn
.GetPath(wxPATH_GET_SEPARATOR
) + refid
+ ".xml"))
968 compound
= compound
->GetNext();
972 if (!CheckParseResults())
978 bool wxXmlDoxygenInterface::ParseCompoundDefinition(const wxString
& filename
)
985 LogMessage("Parsing %s...", filename
);
987 if (!doc
.Load(filename
)) {
988 LogError("can't load %s", filename
);
992 // start processing this compound definition XML
993 if (doc
.GetRoot()->GetName() != "doxygen") {
994 LogError("invalid root node for %s", filename
);
998 // build a list of wx classes
999 child
= doc
.GetRoot()->GetChildren();
1002 if (child
->GetName() == "compounddef" &&
1003 child
->GetAttribute("kind") == "class")
1007 wxString absoluteFile
, header
;
1009 wxXmlNode
*subchild
= child
->GetChildren();
1012 if (subchild
->GetName() == "sectiondef" &&
1013 subchild
->GetAttribute("kind") == "public-func")
1016 wxXmlNode
*membernode
= subchild
->GetChildren();
1019 if (membernode
->GetName() == "memberdef" &&
1020 membernode
->GetAttribute("kind") == "function")
1024 if (!ParseMethod(membernode
, m
, header
)) {
1025 LogError("The method '%s' could not be added to class '%s'",
1026 m
.GetName(), klass
.GetName());
1030 if (absoluteFile
.IsEmpty())
1031 absoluteFile
= header
;
1032 else if (header
!= absoluteFile
)
1034 LogError("The method '%s' is documented in a different "
1035 "file from others (which belong to '%s') ?",
1036 header
, absoluteFile
);
1043 membernode
= membernode
->GetNext();
1046 // all methods of this class were taken from the header "absoluteFile":
1047 klass
.SetHeader(absoluteFile
);
1049 else if (subchild
->GetName() == "compoundname")
1051 klass
.SetName(subchild
->GetNodeContent());
1053 /*else if (subchild->GetName() == "includes")
1055 // NOTE: we'll get the header from the <location> tags
1056 // scattered inside <memberdef> tags instead of
1057 // this <includes> tag since it does not contain
1058 // the absolute path of the header
1060 klass.SetHeader(subchild->GetNodeContent());
1063 subchild
= subchild
->GetNext();
1068 m_classes
.Add(klass
);
1070 LogWarning("discarding class '%s' with %d methods...",
1071 klass
.GetName(), klass
.GetMethodCount());
1074 child
= child
->GetNext();
1076 // give feedback to the user about the progress...
1077 if ((++nodes%PROGRESS_RATE
)==0) ShowProgress();
1083 static wxString
GetTextFromChildren(const wxXmlNode
*n
)
1087 // consider the tree
1089 // <a><b>this</b> is a <b>string</b></a>
1098 // unlike wxXmlNode::GetNodeContent() which would return " is a "
1099 // this function returns "this is a string"
1101 wxXmlNode
*ref
= n
->GetChildren();
1103 if (ref
->GetType() == wxXML_ELEMENT_NODE
)
1104 text
+= ref
->GetNodeContent();
1105 else if (ref
->GetType() == wxXML_TEXT_NODE
)
1106 text
+= ref
->GetContent();
1108 LogWarning("Unexpected node type while getting text from '%s' node", n
->GetName());
1110 ref
= ref
->GetNext();
1116 static bool HasTextNodeContaining(const wxXmlNode
*parent
, const wxString
& name
)
1118 wxXmlNode
*p
= parent
->GetChildren();
1121 switch (p
->GetType())
1123 case wxXML_TEXT_NODE
:
1124 if (p
->GetContent() == name
)
1128 case wxXML_ELEMENT_NODE
:
1129 // recurse into this node...
1130 if (HasTextNodeContaining(p
, name
))
1145 bool wxXmlDoxygenInterface::ParseMethod(const wxXmlNode
* p
, wxMethod
& m
, wxString
& header
)
1147 wxArgumentTypeArray args
;
1150 wxXmlNode
*child
= p
->GetChildren();
1153 if (child
->GetName() == "name")
1154 m
.SetName(child
->GetNodeContent());
1155 else if (child
->GetName() == "type")
1156 m
.SetReturnType(wxType(GetTextFromChildren(child
)));
1157 else if (child
->GetName() == "param")
1159 wxString typestr
, namestr
, defstr
, arrstr
;
1160 wxXmlNode
*n
= child
->GetChildren();
1163 if (n
->GetName() == "type")
1164 // if the <type> node has children, they should be all TEXT and <ref> nodes
1165 // and we need to take the text they contain, in the order they appear
1166 typestr
= GetTextFromChildren(n
);
1167 else if (n
->GetName() == "declname")
1168 namestr
= GetTextFromChildren(n
);
1169 else if (n
->GetName() == "defval")
1170 defstr
= GetTextFromChildren(n
).Strip(wxString::both
);
1171 else if (n
->GetName() == "array")
1172 arrstr
= GetTextFromChildren(n
);
1177 if (typestr
.IsEmpty()) {
1178 LogError("cannot find type node for a param in method '%s'", m
.GetName());
1182 wxArgumentType
newarg(typestr
+ arrstr
, defstr
, namestr
);
1184 // can we use preprocessor output to transform the default value
1185 // into the same form which gets processed by wxXmlGccInterface?
1186 wxStringHashMap::const_iterator it
= m_preproc
.find(defstr
);
1187 if (it
!= m_preproc
.end())
1188 newarg
.SetDefaultValue(defstr
, it
->second
);
1192 else if (child
->GetName() == "location")
1195 if (child
->GetAttribute("line").ToLong(&line
))
1196 m
.SetLocation((int)line
);
1197 header
= child
->GetAttribute("file");
1199 else if (child
->GetName() == "detaileddescription")
1201 // when a method has a @deprecated tag inside its description,
1202 // Doxygen outputs somewhere nested inside <detaileddescription>
1203 // a <xreftitle>Deprecated</xreftitle> tag.
1204 m
.SetDeprecated(HasTextNodeContaining(child
, "Deprecated"));
1207 child
= child
->GetNext();
1210 m
.SetArgumentTypes(args
);
1211 m
.SetConst(p
->GetAttribute("const")=="yes");
1212 m
.SetStatic(p
->GetAttribute("static")=="yes");
1214 // NOTE: Doxygen is smart enough to mark as virtual those functions
1215 // which are declared virtual in base classes but don't have
1216 // the "virtual" keyword explicitely indicated in the derived
1217 // classes... so we don't need any further logic for virtuals
1219 m
.SetVirtual(p
->GetAttribute("virt")=="virtual");
1220 m
.SetPureVirtual(p
->GetAttribute("virt")=="pure-virtual");
1223 LogError("The prototype '%s' is not valid!", m
.GetAsString());