dbusxmlscanner.cpp 28.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/******************************************************************************
 *
 *
 *
 * Copyright (C) 2009 by Tobias Hunger <tobias@aquazul.com>
 *
 * Permission to use, copy, modify, and distribute this software and its
 * documentation under the terms of the GNU General Public License is hereby
 * granted. No representations are made about the suitability of this software
 * for any purpose. It is provided "as is" without express or implied warranty.
 * See the GNU General Public License for more details.
 *
 * Documents produced by Doxygen are derivative works derived from the
 * input used in their production; they are not affected by this license.
 *
 */

#include "dbusxmlscanner.h"

#include "commentscan.h"
#include "entry.h"

#include <qfile.h>
#include <qxml.h>
#include <qstring.h>

#include "message.h"
#include "util.h"
29
#include "arguments.h"
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45

// -----------------------------------------------------------------------
// Convenience defines:
// -----------------------------------------------------------------------

#define CONDITION(cond, msg) \
    do {\
        if (cond)\
        {\
            if (m_errorString.isEmpty()) { m_errorString = msg; }\
            return false;\
        }\
    }\
    while (0)

#define DOC_ERROR(msg) \
46
    warn_doc_error(m_fileName.data(), lineNumber(), msg.data())
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66

#define COND_DOC_ERROR(cond, msg) \
    do {\
        if (cond)\
        {\
             DOC_ERROR(msg);\
             return true;\
        }\
    }\
    while (0)

#define DBUS(name) isDBusElement(namespaceURI, localName, qName, name)
#define EXTENSION(name) isExtensionElement(namespaceURI, localName, qName, name)

// -----------------------------------------------------------------------
// DBusXMLHandler class
// -----------------------------------------------------------------------

const QString EXTENSION_URI("http://psiamp.org/dtd/doxygen_dbusxml.dtd");

Dimitri van Heesch's avatar
Dimitri van Heesch committed
67
/** DBus implementation of the generic QXmlDefaultHandler. */
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
class DBusXMLHandler : public QXmlDefaultHandler
{
public:
    DBusXMLHandler(ParserInterface * parser,
                   QXmlSimpleReader * reader,
                   const char * file_name,
                   Entry * root) :
        m_parser(parser),
        m_locator(reader),
        m_currentEntry(0),
        m_currentInterface(0),
        m_currentMethod(0),
        m_currentArgument(0),
        m_currentProperty(0),
        m_currentEnum(0),
        m_fileName(file_name),
        m_currentComment(0)
    {
        setDocumentLocator(&m_locator);

        m_scopeCount = 0;

        // Set up stack cleanup:
        m_structStack.setAutoDelete(TRUE);
        m_elementStack.setAutoDelete(TRUE);
        m_scopeStack.setAutoDelete(TRUE);

        openScopes(root);
    }

    ~DBusXMLHandler()
    { closeScopes(); }

    QString errorString()
    { return m_errorString; }

    bool startElement(const QString &namespaceURI,
                      const QString &localName,
                      const QString &qName,
                      const QXmlAttributes &attributes)
    {
        // add to elements stack:
110
        m_elementStack.append(new ElementData(qName.utf8()));
111 112 113 114 115 116 117

        // First we need a node.
        if (DBUS("node"))
        {
            CONDITION(!m_currentNode.isEmpty(), "Node inside a node.");

            const int idx(indexOf(attributes, "name"));
118
            COND_DOC_ERROR(idx < 0, QCString("Anonymous node found."));
119

120
            m_currentNode = attributes.value(idx).utf8();
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
            // A node is actually of little interest, so do nothing here.
            return true;
        }

        // Then we need an interface.
        if (DBUS("interface"))
        {
            // We need a nodeName for interfaces:
            CONDITION(m_currentNode.isEmpty(), "Interface without a node.");
            CONDITION(m_currentInterface, "Interface within another interface.");

            const int idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(idx < 0, QString("Interface without a name found."));

            // A interface is roughly equivalent to a class:
            m_currentInterface = createEntry();

            m_currentInterface->section = Entry::CLASS_SEC;
            m_currentInterface->spec |= Entry::Interface;
            m_currentInterface->type = "Interface";
141
            m_currentInterface->name = substitute(attributes.value(idx).utf8(), ".", "::");
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162

            openScopes(m_currentInterface);

            return true;
        }

        if (DBUS("method") || DBUS("signal"))
        {
            // We need a interfaceName for methods and signals:
            CONDITION(!m_currentInterface, "Method or signal found outside a interface.");
            CONDITION(m_currentMethod, "Method or signal found inside another method or signal.");
            CONDITION(m_currentProperty, "Methor or signal found inside a property.");
            CONDITION(!m_structStack.isEmpty(), "Method or signal found inside a struct.");
            CONDITION(m_currentEnum, "Methor or signal found inside a enum.");

            const int idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(idx < 0, QString("Method or signal without a name found."));

            m_currentMethod = createEntry();

            m_currentMethod->section = Entry::FUNCTION_SEC;
163
            m_currentMethod->name = attributes.value(idx).utf8();
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195
            m_currentMethod->mtype = Method;
            m_currentMethod->type = "void";

            if (DBUS("signal"))
            { m_currentMethod->mtype = Signal; }
        }

        if (DBUS("arg"))
        {
            // We need a method for arguments:
            CONDITION(!m_currentMethod, "Argument found outside a method or signal.");
            CONDITION(m_currentArgument, "Argument found inside another argument.");

            const int name_idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(name_idx < 0, QString("Argument without a name found."));
            COND_DOC_ERROR(!hasType(attributes), QString("Argument without a type found."));

            const int direction_idx(indexOf(attributes, "direction"));

            if ((m_currentMethod->mtype == Signal &&
                 direction_idx >= 0 &&
                 attributes.value(direction_idx) != "in") ||
                (m_currentMethod->mtype == Method &&
                 direction_idx >= 0 &&
                 attributes.value(direction_idx) != "in" &&
                 attributes.value(direction_idx) != "out"))
            {
                m_errorString = "Invalid direction found.";
                return false;
            }

            m_currentArgument = new Argument;
196 197
            m_currentArgument->type = getType(attributes).utf8();
            m_currentArgument->name = attributes.value(name_idx).utf8();
198
            if (direction_idx >= 0)
199
            { m_currentArgument->attrib = attributes.value(direction_idx).utf8(); }
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
            else
            {
                if (m_currentMethod->mtype == Signal)
                { m_currentArgument->attrib = "in"; }
                else
                { m_currentArgument->attrib = "out"; }
            }
        }

        if (DBUS("property"))
        {
            CONDITION(m_currentMethod, "Property found inside a method or signal.");
            CONDITION(!m_currentInterface, "Property found outside an interface.");
            CONDITION(m_currentProperty, "Property found inside another property.");
            CONDITION(!m_structStack.isEmpty(), "Property found inside a struct.");
            CONDITION(m_currentEnum, "Property found inside a enum.");

            const int name_idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(name_idx < 0, QString("Anonymous property found."));
            COND_DOC_ERROR(!hasType(attributes), QString("Property without a type found."));

            const int access_idx(indexOf(attributes, "access"));
            COND_DOC_ERROR(access_idx < 0, QString("Property without a access attribute found."));
            COND_DOC_ERROR(attributes.value(access_idx) != "read" &&
                           attributes.value(access_idx) != "write" &&
                           attributes.value(access_idx) != "readwrite",
                           QString("Property with invalid access attribute \"%1\" found.").
                           arg(attributes.value(access_idx)));

            m_currentProperty = createEntry();

            m_currentProperty->section = Entry::FUNCTION_SEC;

            if (attributes.value(access_idx) == "read" ||
                attributes.value(access_idx) == "readwrite")
            { m_currentProperty->spec |= Entry::Readable; }

            if (attributes.value(access_idx) == "write" ||
                attributes.value(access_idx) == "readwrite")
            { m_currentProperty->spec |= Entry::Writable; }

241
            m_currentProperty->name = attributes.value(name_idx).utf8();
242
            m_currentProperty->mtype = Property;
243
            m_currentProperty->type = getType(attributes).utf8();
244 245 246 247 248 249 250 251 252 253 254
        }

        if (EXTENSION("namespace"))
        {
            CONDITION(m_currentNode.isEmpty(), "Namespace found outside a node.");
            CONDITION(m_currentInterface, "Namespace found inside an interface.");

            const int idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(idx < 0, QString("Anonymous namespace found."));

            m_namespaceStack.append(openNamespace(attributes.value(idx)));
255
            openScopes(m_namespaceStack.getLast());
256 257 258 259 260 261 262 263 264 265 266 267 268 269
        }

        if (EXTENSION("struct"))
        {
            CONDITION(m_currentMethod, "Struct found inside a method or signal.");
            CONDITION(m_currentProperty, "Struct found inside a property.");
            CONDITION(m_currentEnum, "Struct found inside an enum.");

            const int idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(idx < 0, QString("Anonymous struct found."));

            Entry * current_struct = createEntry();
            current_struct->section = Entry::CLASS_SEC;
            current_struct->spec = Entry::Struct;
270
            current_struct->name = attributes.value(idx).utf8();
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289

            openScopes(current_struct);

            current_struct->type = current_struct->name + " struct";

            m_structStack.append(new StructData(current_struct));
        }

        if (EXTENSION("member"))
        {
            CONDITION(m_structStack.isEmpty(), "Member found outside of struct.");

            const int name_idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(name_idx < 0, QString("Anonymous member found."));
            COND_DOC_ERROR(!hasType(attributes), QString("Member without a type found."));

            createEntry();

            m_currentEntry->section = Entry::VARIABLE_SEC;
290 291
            m_currentEntry->name = attributes.value(name_idx).utf8();
            m_currentEntry->type = getType(attributes).utf8();
292 293

            QString type(getDBusType(m_currentEntry->type));
294
            m_structStack.getLast()->type.append(type.utf8());
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
        }

        if (EXTENSION("enum") || EXTENSION("flagset"))
        {
            CONDITION(m_currentMethod, "Enum found inside a method or signal.");
            CONDITION(m_currentProperty, "Enum found inside a property.");

            const int name_idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(name_idx < 0, QString("Anonymous enum found."));

            const int type_idx(indexOf(attributes, "type"));
            QString type = "u";
            if (type_idx >= 0)
            { type = attributes.value(type_idx); }
            if (type != "y" && type != "q" && type != "u" && type != "t")
            { DOC_ERROR(QString("Invalid enum type \"%1\" found.").arg(type)); }

            m_currentEnum = createEntry();
            m_currentEnum->section = Entry::ENUM_SEC;
314
            m_currentEnum->name = attributes.value(name_idx).utf8();
315 316 317 318 319

            openScopes(m_currentEnum);

            m_currentEnum->type = m_currentEntry->name + " enum";

320
            addNamedType(type.utf8());
321 322 323 324 325 326 327 328 329 330 331 332 333 334
        }

        if (EXTENSION("value"))
        {
            CONDITION(!m_currentEnum, "Value found outside an enum.");

            const int name_idx(indexOf(attributes, "name"));
            COND_DOC_ERROR(name_idx < 0, QString("Anonymous value found."));

            const int value_idx(indexOf(attributes, "value"));

            createEntry();

            m_currentEntry->section = Entry::VARIABLE_SEC;
335
            m_currentEntry->name = attributes.value(name_idx).utf8();
336 337
            m_currentEntry->type = m_currentEnum->name; // "@"; // enum marker!
            if (value_idx >= 0)
338
            { m_currentEntry->initializer = attributes.value(value_idx).utf8(); }
339 340 341 342 343 344 345 346 347 348 349 350
        }

        return true;
    }

    bool endElement(const QString &namespaceURI,
                    const QString &localName,
                    const QString &qName)
    {
        // Clean up elements stack:
        // Since we made sure to get the elements in the proper order when
        // adding we do not need to do so again here.
351
        COND_DOC_ERROR(m_elementStack.getLast()->element != qName.utf8(),
352
                       QString("Malformed XML: Unexpected closing element found.").
353
                       arg(m_elementStack.getLast()->element).utf8());
354 355 356 357 358
        m_elementStack.removeLast();

        // Interface:
        if (DBUS("interface"))
        {
359
            CONDITION(!m_currentInterface, "end of interface found without start.");
360 361 362 363 364 365 366
            m_currentInterface->endBodyLine = lineNumber();
            closeScopes();
            m_currentInterface = 0;
        }

        if (DBUS("method") || DBUS("signal"))
        {
367 368
            CONDITION(!m_currentMethod, "end of method found without start.");
            CONDITION(!m_currentInterface, "end of method found outside interface.");
369 370 371 372 373 374 375
            m_currentMethod->endBodyLine = lineNumber();
            m_currentInterface->addSubEntry(m_currentMethod);
            m_currentMethod = 0;
        }

        if (DBUS("property"))
        {
376 377
            CONDITION(!m_currentProperty, "end of property found without start.");
            CONDITION(!m_currentInterface, "end of property found outside interface.");
378 379 380 381 382 383 384
            m_currentProperty->endBodyLine = lineNumber();
            m_currentInterface->addSubEntry(m_currentProperty);
            m_currentProperty = 0;
        }

        if (DBUS("arg"))
        {
385
            CONDITION(!m_currentMethod, "end of arg found outside method.");
386 387 388 389 390 391
            m_currentMethod->argList->append(m_currentArgument);
            m_currentArgument = 0;
        }

        if (EXTENSION("namespace"))
        {
392
            Entry * current = m_namespaceStack.getLast();
393
            CONDITION(!current, "end of namespace without start.");
394 395 396 397 398 399 400 401
            m_namespaceStack.removeLast();

            current->endBodyLine = lineNumber();
            closeScopes();
        }

        if (EXTENSION("struct"))
        {
402
            StructData * data = m_structStack.getLast();
403
            CONDITION(!data, "end of struct without start.");
404 405 406 407 408 409 410 411

            data->entry->endBodyLine = lineNumber();

            QString current_type;
            current_type.append(QString("("));
            current_type.append(data->type);
            current_type.append(QString(")"));

412
            addNamedType(current_type.utf8());
413 414 415 416 417 418 419 420

            closeScopes();

            m_structStack.removeLast();
        }

        if (EXTENSION("member"))
        {
421
           StructData * data = m_structStack.getLast();
422
           CONDITION(!data, "end of member outside struct.");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
423
           data->entry->addSubEntry(m_currentEntry);
424 425 426 427
        }

        if (EXTENSION("enum") || EXTENSION("flagset"))
        {
428
            CONDITION(!m_currentEnum, "end of enum without start.");
429 430 431 432 433 434 435 436
            m_currentEnum->endBodyLine = lineNumber();
            closeScopes();

            m_currentEnum = 0;
        }

        if (EXTENSION("value"))
        {
437
            CONDITION(!m_currentEntry, "end of value without start");
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
            m_currentEntry->endBodyLine = lineNumber();

            m_currentEnum->addSubEntry(m_currentEntry);
        }

        return true;
    }

    bool characters(const QString & /*chars*/)
    { return true; }

    bool comment(const QString & comment_)
    {
        if (m_currentComment)
        { handleComment(); }

454
        m_currentComment = new CommentData(m_fileName, lineNumber(), comment_.utf8());
455

456
        if (m_currentComment->shouldIgnore)
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
        {
            delete m_currentComment;
            m_currentComment = 0;
            return true;
        }

        if (m_currentComment->associateWithPrevious)
        { handleComment(); }

        return true;
    }

    void handleComment()
    {
        if (m_currentComment == 0 || m_currentEntry == 0)
        { return; }

        QCString text(m_currentComment->text);

        m_currentEntry->docFile = m_currentComment->fileName;
        m_currentEntry->docLine = m_currentComment->line;

        int position(0);
        bool needs_entry(false);
        bool brief(false);
        Protection prot(Public);
483
        int lineNr = lineNumber();
484 485 486

        while (parseCommentBlock(m_parser,
                                 m_currentEntry,
487
                                 text, m_fileName.data(), 
488
                                 lineNr,
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513
                                 brief, m_currentComment->isJavaStyle,
                                 false,
                                 prot,
                                 position,
                                 needs_entry))
        {
            if (needs_entry) { createEntry(); }
        }
        if (needs_entry) { createEntry(); }

        delete m_currentComment;
        m_currentComment = 0;
    }

    QXmlLocator * locator()
    { return &m_locator; }

    int lineNumber()
    { return m_locator.lineNumber(); }

    void setSection()
    {
        Entry * current = createEntry();
        current->reset();

514
        current->name    = m_fileName;
515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
        current->section = Entry::SOURCE_SEC;

        // Open/Close the scope to do the bookkeeping:
        openScopes(current);
        closeScopes();
    }

private:
    bool isDBusElement(const QString & namespaceURI,
                       const QString & localName,
                       const QString & qName,
                       const QString & element)
    {
        return (namespaceURI.isEmpty() && localName == element && qName == element) ||
               (namespaceURI.isEmpty() && localName.isEmpty() && qName == element);
    }

    bool isExtensionElement(const QString & namespaceURI,
                            const QString & localName,
                            const QString & qName,
                            const QString & element)
    {
537
        (void)qName;
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554

        return namespaceURI == EXTENSION_URI && localName == element;
    }

    bool hasType(const QXmlAttributes & attributes)
    {
        const int type_idx(indexOf(attributes, "type"));
        const int named_type_idx(indexOf(attributes, "named-type"));

        return named_type_idx >= 0 || type_idx >= 0;
    }

    QString getType(const QXmlAttributes & attributes)
    {
        const int type_idx(indexOf(attributes, "type"));
        const int named_type_idx(indexOf(attributes, "named-type"));

555
        QCString type;
556 557 558

        if (named_type_idx >= 0)
        {
559 560 561
            type = attributes.value(named_type_idx).utf8();
            if (type.left(2)!="::")
            { type = getCurrentScope(attributes.value(named_type_idx).utf8()); }
562 563 564 565 566 567
            else
            { type = type.mid(2); }
            if (m_namedTypeMap.contains(type))
            {
                if (type_idx >= 0)
                {
568
                    const QCString dbus_type(attributes.value(type_idx).utf8());
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
                    if (dbus_type != m_namedTypeMap[type])
                    {
                        DOC_ERROR(QString("Type \"%1\" does not match up with "
                                          "previous definition of named type \"%2\" (which was \"%3\".").
                                          arg(dbus_type).
                                          arg(type).
                                          arg(m_namedTypeMap[type]));
                    }
                }
                return type;
            }

            DOC_ERROR(QString("Undefined named type \"%1\" used.").arg(type));
        }

        if (type_idx >= 0)
        {
586
            type = attributes.value(type_idx).utf8();
587

588 589
            QRegExp reg_exp(QCString("(a?[ybnqiuxdtsogv]|a[{]sv[}])"));
            if (reg_exp.match(type.data()))
590 591 592 593 594 595 596 597
            { return type; }

            DOC_ERROR(QString("Unnamed complex D-Bus type \"%1\" found.").arg(type));
        }

        return QString();
    }

598
    QString getDBusType(const QCString & type)
599
    {
600
        QCString scoped_type = type;
601 602 603 604 605 606 607 608 609
        if (!scoped_type.contains("::"))
        { scoped_type = getCurrentScope(type); }

        if (m_namedTypeMap.contains(scoped_type))
        { return m_namedTypeMap[scoped_type]; }
        else
        { return type; }
    }

610
    void addNamedType(const QCString &type)
611
    {
612
        QCString scoped_name(getCurrentScope());
613 614 615 616 617 618 619 620 621 622

        if (m_namedTypeMap.contains(scoped_name))
        {
            DOC_ERROR(QString("Named type \"%1\" is already defined.").arg(scoped_name));
            return;
        }

        m_namedTypeMap.insert(scoped_name, type);
    }

623
    QCString getCurrentScope(const QCString & type = QCString())
624
    {
625
        QCString scoped_name;
626 627
        if (!m_scopeStack.isEmpty())
        {
628
            scoped_name = m_scopeStack.getLast()->scope->name;
629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656
            scoped_name.append("::");
        }
        if (!type.isEmpty())
        { scoped_name.append(type); }
        else
        { scoped_name = scoped_name.left(scoped_name.length() - 2); }

        return scoped_name;
    }

    int indexOf(const QXmlAttributes & attributes, const QString & name,
                 const QString & type = "CDATA", const bool mandatory = true)
    {
        const int idx(attributes.index(name));
        if (idx < 0 || idx > attributes.length()) { return -1; }
        if (attributes.type(idx) != type) { return -1; }
        if (mandatory && attributes.value(idx).isEmpty()) { return -1; }

        return idx;
    }

    Entry * createEntry()
    {
        Entry * entry = new Entry();

        entry->protection = Public ;
        entry->virt       = Normal;
        entry->stat       = false;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
657
        entry->lang       = SrcLangExt_XML;
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
        entry->spec       = 0;

        entry->fileName  = m_fileName;
        entry->startLine = lineNumber();
        entry->bodyLine = lineNumber();

        entry->callGraph = false;
        entry->callerGraph = false;

        initGroupInfo(entry);

        m_currentEntry = entry;

        handleComment();

        return entry;
    }

    void openScopes(Entry * object)
    {
        int cur_scope_separator_pos = 0;
        int last_scope_separator_pos = 0;
        while (0 <= (cur_scope_separator_pos = object->name.find("::", last_scope_separator_pos)))
        {
            QString scope = object->name.mid(last_scope_separator_pos,
                                             cur_scope_separator_pos - last_scope_separator_pos);
            last_scope_separator_pos = cur_scope_separator_pos + 2;

            Entry * current_namespace = openNamespace(scope);

            if (!m_scopeStack.isEmpty())
689
            { m_scopeStack.getLast()->scope->addSubEntry(current_namespace); }
690 691 692 693

            m_scopeStack.append(new ScopeData(current_namespace, m_scopeCount));
        }

694
        QCString scoped_name(getCurrentScope());
695 696 697 698 699 700 701
        if (!scoped_name.isEmpty())
        { scoped_name.append("::"); }
        scoped_name.append(object->name.mid(last_scope_separator_pos));

        object->name = scoped_name;

        if (!m_scopeStack.isEmpty())
702
        { m_scopeStack.getLast()->scope->addSubEntry(object); }
703 704 705 706 707 708 709 710
        m_scopeStack.append(new ScopeData(object, m_scopeCount));

        ++m_scopeCount;
    }

    Entry * openNamespace(const QString & name)
    {
        Entry * current_namespace = createEntry();
711
        QCString scoped_name(getCurrentScope());
712 713
        if (!scoped_name.isEmpty())
        { scoped_name.append("::"); }
714
        scoped_name.append(name.utf8());
715 716 717 718 719 720 721 722 723
        current_namespace->name = scoped_name;
        current_namespace->section = Entry::NAMESPACE_SEC;
        current_namespace->type = "namespace" ;

        return current_namespace;
    }

    void closeScopes()
    {
724
        const int current_scope_count(m_scopeStack.getLast()->count);
725 726 727 728 729

        // Do not close the root scope.
        if (current_scope_count == 0)
        { return; }

730
        while (current_scope_count == m_scopeStack.getLast()->count)
731 732 733 734 735 736
        { m_scopeStack.removeLast(); }
    }

    ParserInterface * m_parser;

    QXmlLocator m_locator;
737
    QCString m_currentNode; // Nodes can not be nested, no entry necessary.
738 739 740

    struct ElementData
    {
741
        ElementData(const QCString & e) :
742 743 744 745
            element(e)
        { }
        ~ElementData() { }

746 747
        QCString element; //*< The element name
        QCString text; //*< The actual xml code.
748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
    };
    QList<ElementData> m_elementStack;

    Entry * m_currentEntry; // The currently open entry.

    Entry * m_currentInterface; // Interfaces can not be nested.
    Entry * m_currentMethod; // Methods can not be nested.
    Argument * m_currentArgument; // Arguments can not be nested.
    Entry * m_currentProperty; // Properties can not be nested.
    Entry * m_currentEnum; // Enums can not be nested.
    QList<Entry> m_namespaceStack;

    struct StructData
    {
        StructData(Entry * e) : entry(e) { }
        ~StructData() { }

765
        QCString type;
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782
        Entry * entry;
    };
    QList<StructData> m_structStack; // Structs can be nested.

    struct ScopeData
    {
        ScopeData(Entry * s, int c) :
            scope(s),
            count(c)
        { }
        ~ScopeData() { }

        Entry * scope;
        int count;
    };
    QList<ScopeData> m_scopeStack; // Scopes are nested.

783
    QCString m_fileName;
784 785 786

    struct CommentData
    {
787
        CommentData(const QCString & f, const int l, const QCString & t) :
788 789 790 791 792
            isJavaStyle(false),
            isQtStyle(false),
            line(l),
            fileName(f)
        {
793 794
            isJavaStyle = t.length()>0 && t.at(0)=='*';
            isQtStyle = t.length()>0 && t.at(0)=='!';
795
            shouldIgnore = (!isJavaStyle && !isQtStyle);
796
            associateWithPrevious = (t.length()>1 && t.at(1)=='<');
797 798 799 800 801 802 803
            if (associateWithPrevious)
            { text = t.mid(2); }
            else
            { text = t.mid(1); }
        }
        ~CommentData() { }

804
        QCString text;
805 806 807 808 809
        bool isJavaStyle;
        bool isQtStyle;
        bool shouldIgnore;
        bool associateWithPrevious;
        int line;
810
        QCString fileName;
811 812 813 814 815 816 817
    };
    CommentData * m_currentComment;

    int m_scopeCount; //*< unique scope id.

    QString m_errorString;

818
    QMap<QCString, QCString> m_namedTypeMap;
819 820 821 822 823 824 825 826 827 828 829 830 831 832
};

// -----------------------------------------------------------------------
// DBusXMLScanner
// -----------------------------------------------------------------------

DBusXMLScanner::DBusXMLScanner()
{ }

DBusXMLScanner::~DBusXMLScanner()
{ }

void DBusXMLScanner::parseInput(const char * fileName,
                                const char * /* fileBuf */,
833 834 835
                                Entry *root,
                                bool /*sameTranslationUnit*/,
                                QStrList & /*filesInSameTranslationUnit*/)
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850
{
    QFile inputFile(fileName);

    QXmlInputSource inputSource(inputFile);
    QXmlSimpleReader reader;

    DBusXMLHandler handler(this, &reader, fileName, root);
    reader.setContentHandler(&handler);
    reader.setErrorHandler(&handler);
    reader.setLexicalHandler(&handler);

    groupEnterFile(fileName, 1);
    handler.setSection();
    reader.parse(inputSource);

851
    if (!handler.errorString().isEmpty())
Dimitri van Heesch's avatar
Dimitri van Heesch committed
852 853
    { err("DBus XML Parser: Error at line %d: %s\n", 
        handler.locator()->lineNumber(),handler.errorString().utf8().data()); }
854 855 856 857 858 859 860 861 862 863

    groupLeaveFile(fileName, 1);
}

bool DBusXMLScanner::needsPreprocessing(const QCString & /* extension */)
{ return (false); }

void DBusXMLScanner::parseCode(CodeOutputInterface & /* codeOutIntf */,
                               const char * /* scopeName */,
                               const QCString & /* input */,
864
                               SrcLangExt /* lang */,
865 866 867 868 869 870
                               bool /* isExampleBlock */,
                               const char * /* exampleName */,
                               FileDef * /* fileDef */,
                               int /* startLine */,
                               int /* endLine */,
                               bool /* inlineFragment */,
871
                               MemberDef * /* memberDef */,
Dimitri van Heesch's avatar
Dimitri van Heesch committed
872
                               bool /*showLineNumbers*/,
873 874
                               Definition * /* searchCtx */,
                               bool /*collectXRefs*/ )
875 876 877 878 879 880 881
{ }

void DBusXMLScanner::resetCodeParserState()
{ }

void DBusXMLScanner::parsePrototype(const char * /* text */)
{ }