@@ -27,6 +27,52 @@ CppcheckLibraryData::CppcheckLibraryData()
2727{
2828}
2929
30+ static CppcheckLibraryData::Container loadContainer (QXmlStreamReader &xmlReader)
31+ {
32+ CppcheckLibraryData::Container container;
33+ container.id = xmlReader.attributes ().value (" id" ).toString ();
34+ container.inherits = xmlReader.attributes ().value (" inherits" ).toString ();
35+ container.startPattern = xmlReader.attributes ().value (" startPattern" ).toString ();
36+ container.endPattern = xmlReader.attributes ().value (" endPattern" ).toString ();
37+
38+ QXmlStreamReader::TokenType type;
39+ while ((type = xmlReader.readNext ()) != QXmlStreamReader::EndElement ||
40+ xmlReader.name ().toString () != " container" ) {
41+ if (type != QXmlStreamReader::StartElement)
42+ continue ;
43+ const QString elementName = xmlReader.name ().toString ();
44+ if (elementName == " type" ) {
45+ container.type .templateParameter = xmlReader.attributes ().value (" templateParameter" ).toString ();
46+ container.type .string = xmlReader.attributes ().value (" string" ).toString ();
47+ } else if (elementName == " size" || elementName == " access" || elementName == " other" ) {
48+ const QString indexOperator = xmlReader.attributes ().value (" indexOperator" ).toString ();
49+ if (elementName == " access" && indexOperator == " array-like" )
50+ container.access_arrayLike = true ;
51+ const QString templateParameter = xmlReader.attributes ().value (" templateParameter" ).toString ();
52+ if (elementName == " size" && !templateParameter.isEmpty ())
53+ container.size_templateParameter = templateParameter.toInt ();
54+ for (;;) {
55+ type = xmlReader.readNext ();
56+ if (xmlReader.name ().toString () == elementName)
57+ break ;
58+ if (type != QXmlStreamReader::StartElement)
59+ continue ;
60+ struct CppcheckLibraryData ::Container::Function function;
61+ function.name = xmlReader.attributes ().value (" name" ).toString ();
62+ function.action = xmlReader.attributes ().value (" action" ).toString ();
63+ function.yields = xmlReader.attributes ().value (" yields" ).toString ();
64+ if (elementName == " size" )
65+ container.sizeFunctions .append (function);
66+ else if (elementName == " access" )
67+ container.accessFunctions .append (function);
68+ else
69+ container.otherFunctions .append (function);
70+ };
71+ }
72+ }
73+ return container;
74+ }
75+
3076static CppcheckLibraryData::Define loadDefine (const QXmlStreamReader &xmlReader)
3177{
3278 CppcheckLibraryData::Define define;
@@ -148,6 +194,8 @@ bool CppcheckLibraryData::open(QIODevice &file)
148194 comments.append (xmlReader.text ().toString ());
149195 break ;
150196 case QXmlStreamReader::StartElement:
197+ if (xmlReader.name () == " container" )
198+ containers.append (loadContainer (xmlReader));
151199 if (xmlReader.name () == " define" )
152200 defines.append (loadDefine (xmlReader));
153201 else if (xmlReader.name () == " function" )
@@ -166,6 +214,53 @@ bool CppcheckLibraryData::open(QIODevice &file)
166214 return true ;
167215}
168216
217+ static void writeContainerFunctions (QXmlStreamWriter &xmlWriter, const QString name, int extra, const QList<struct CppcheckLibraryData ::Container::Function> &functions)
218+ {
219+ if (functions.isEmpty () && extra <= 0 )
220+ return ;
221+ xmlWriter.writeStartElement (name);
222+ if (extra > 0 ) {
223+ if (name == " access" )
224+ xmlWriter.writeAttribute (" indexOperator" , " array-like" );
225+ else if (name == " size" )
226+ xmlWriter.writeAttribute (" templateParameter" , QString::number (extra));
227+ }
228+ foreach (const CppcheckLibraryData::Container::Function &function, functions) {
229+ xmlWriter.writeStartElement (" function" );
230+ xmlWriter.writeAttribute (" name" , function.name );
231+ if (!function.action .isEmpty ())
232+ xmlWriter.writeAttribute (" action" , function.action );
233+ if (!function.yields .isEmpty ())
234+ xmlWriter.writeAttribute (" yields" , function.yields );
235+ xmlWriter.writeEndElement ();
236+ }
237+ xmlWriter.writeEndElement ();
238+ }
239+
240+ static void writeContainer (QXmlStreamWriter &xmlWriter, const CppcheckLibraryData::Container &container)
241+ {
242+ xmlWriter.writeStartElement (" container" );
243+ xmlWriter.writeAttribute (" id" , container.id );
244+ if (!container.startPattern .isEmpty ())
245+ xmlWriter.writeAttribute (" startPattern" , container.startPattern );
246+ if (!container.endPattern .isEmpty ())
247+ xmlWriter.writeAttribute (" endPattern" , container.endPattern );
248+ if (!container.inherits .isEmpty ())
249+ xmlWriter.writeAttribute (" inherits" , container.inherits );
250+ if (!container.type .templateParameter .isEmpty () || !container.type .string .isEmpty ()) {
251+ xmlWriter.writeStartElement (" type" );
252+ if (!container.type .templateParameter .isEmpty ())
253+ xmlWriter.writeAttribute (" templateParameter" , container.type .templateParameter );
254+ if (!container.type .string .isEmpty ())
255+ xmlWriter.writeAttribute (" string" , container.type .string );
256+ xmlWriter.writeEndElement ();
257+ }
258+ writeContainerFunctions (xmlWriter, " size" , container.size_templateParameter , container.sizeFunctions );
259+ writeContainerFunctions (xmlWriter, " access" , container.access_arrayLike , container.accessFunctions );
260+ writeContainerFunctions (xmlWriter, " other" , 0 , container.otherFunctions );
261+ xmlWriter.writeEndElement ();
262+ }
263+
169264static void writeFunction (QXmlStreamWriter &xmlWriter, const CppcheckLibraryData::Function &function)
170265{
171266 foreach (const QString &comment, function.comments ) {
@@ -273,13 +368,17 @@ QString CppcheckLibraryData::toString() const
273368 writeMemoryResource (xmlWriter, mr);
274369 }
275370
371+ foreach (const Container &container, containers) {
372+ writeContainer (xmlWriter, container);
373+ }
374+
276375 foreach (const PodType &podtype, podtypes) {
277376 xmlWriter.writeStartElement (" podtype" );
278377 xmlWriter.writeAttribute (" name" , podtype.name );
279- if (!podtype.size .isEmpty ())
280- xmlWriter.writeAttribute (" size" , podtype.size );
281378 if (!podtype.sign .isEmpty ())
282379 xmlWriter.writeAttribute (" sign" , podtype.sign );
380+ if (!podtype.size .isEmpty ())
381+ xmlWriter.writeAttribute (" size" , podtype.size );
283382 xmlWriter.writeEndElement ();
284383 }
285384
0 commit comments