xmlgen.cpp 59.9 KB
Newer Older
1 2
/******************************************************************************
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
3
 * Copyright (C) 1997-2013 by Dimitri van Heesch.
4 5 6 7 8 9 10 11 12 13 14 15 16 17
 *
 * 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 <stdlib.h>

18 19 20 21 22
#include <qdir.h>
#include <qfile.h>
#include <qtextstream.h>
#include <qintdict.h>

23 24 25 26 27 28 29
#include "xmlgen.h"
#include "doxygen.h"
#include "message.h"
#include "config.h"
#include "classlist.h"
#include "util.h"
#include "defargs.h"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
30
#include "outputgen.h"
31
#include "dot.h"
32
#include "pagedef.h"
33
#include "filename.h"
34
#include "version.h"
35 36
#include "xmldocvisitor.h"
#include "docparser.h"
37
#include "language.h"
38
#include "parserintf.h"
39
#include "arguments.h"
40 41 42 43 44 45 46 47
#include "memberlist.h"
#include "groupdef.h"
#include "memberdef.h"
#include "namespacedef.h"
#include "membername.h"
#include "membergroup.h"
#include "dirdef.h"
#include "section.h"
48

Dimitri van Heesch's avatar
Dimitri van Heesch committed
49 50 51 52 53 54
// no debug info
#define XML_DB(x) do {} while(0)
// debug to stdout
//#define XML_DB(x) printf x
// debug inside output
//#define XML_DB(x) QCString __t;__t.sprintf x;m_t << __t
Dimitri van Heesch's avatar
Dimitri van Heesch committed
55

56 57 58 59 60 61
//------------------

static const char index_xsd[] =
#include "index_xsd.h"
;

62 63 64 65 66 67
//------------------
//
static const char compound_xsd[] =
#include "compound_xsd.h"
;

68 69
//------------------

Dimitri van Heesch's avatar
Dimitri van Heesch committed
70
/** Helper class mapping MemberList::ListType to a string representing */
71 72 73 74 75
class XmlSectionMapper : public QIntDict<char>
{
  public:
    XmlSectionMapper() : QIntDict<char>(47)
    {
76 77 78 79 80 81 82 83
      insert(MemberListType_pubTypes,"public-type");
      insert(MemberListType_pubMethods,"public-func");
      insert(MemberListType_pubAttribs,"public-attrib");
      insert(MemberListType_pubSlots,"public-slot");
      insert(MemberListType_signals,"signal");
      insert(MemberListType_dcopMethods,"dcop-func");
      insert(MemberListType_properties,"property");
      insert(MemberListType_events,"event");
84 85
      insert(MemberListType_interfaces,"interfaces");
      insert(MemberListType_services,"services");
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
      insert(MemberListType_pubStaticMethods,"public-static-func");
      insert(MemberListType_pubStaticAttribs,"public-static-attrib");
      insert(MemberListType_proTypes,"protected-type");
      insert(MemberListType_proMethods,"protected-func");
      insert(MemberListType_proAttribs,"protected-attrib");
      insert(MemberListType_proSlots,"protected-slot");
      insert(MemberListType_proStaticMethods,"protected-static-func");
      insert(MemberListType_proStaticAttribs,"protected-static-attrib");
      insert(MemberListType_pacTypes,"package-type");
      insert(MemberListType_pacMethods,"package-func");
      insert(MemberListType_pacAttribs,"package-attrib");
      insert(MemberListType_pacStaticMethods,"package-static-func");
      insert(MemberListType_pacStaticAttribs,"package-static-attrib");
      insert(MemberListType_priTypes,"private-type");
      insert(MemberListType_priMethods,"private-func");
      insert(MemberListType_priAttribs,"private-attrib");
      insert(MemberListType_priSlots,"private-slot");
      insert(MemberListType_priStaticMethods,"private-static-func");
      insert(MemberListType_priStaticAttribs,"private-static-attrib");
      insert(MemberListType_friends,"friend");
      insert(MemberListType_related,"related");
      insert(MemberListType_decDefineMembers,"define");
      insert(MemberListType_decProtoMembers,"prototype");
      insert(MemberListType_decTypedefMembers,"typedef");
      insert(MemberListType_decEnumMembers,"enum");
      insert(MemberListType_decFuncMembers,"func");
      insert(MemberListType_decVarMembers,"var");
113 114 115 116 117
    }
};

static XmlSectionMapper g_xmlSectionMapper;

118

119
inline void writeXMLString(FTextStream &t,const char *s)
120 121 122 123
{
  t << convertToXML(s);
}

124
inline void writeXMLCodeString(FTextStream &t,const char *s, int &col)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
125 126 127 128
{
  char c;
  while ((c=*s++))
  {
129 130
    switch(c)
    {
131 132
      case '\t': 
      { 
133 134
        static int tabSize = Config_getInt("TAB_SIZE");
	int spacesToNextTabStop = tabSize - (col%tabSize); 
135 136 137 138 139 140 141 142 143 144
	col+=spacesToNextTabStop;
	while (spacesToNextTabStop--) t << "<sp/>";
	break;
	}
      case ' ':  t << "<sp/>"; col++;  break;
      case '<':  t << "&lt;"; col++;   break;
      case '>':  t << "&gt;"; col++;   break;
      case '&':  t << "&amp;"; col++;  break;
      case '\'': t << "&apos;"; col++; break; 
      case '"':  t << "&quot;"; col++; break;
145
      default:   s=writeUtf8Char(t,s-1); col++; break;         
146
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
147 148 149 150
  } 
}


151
static void writeXMLHeader(FTextStream &t)
152
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
153
  t << "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" << endl;;
154 155
  t << "<doxygen xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
  t << "xsi:noNamespaceSchemaLocation=\"compound.xsd\" ";
156 157 158
  t << "version=\"" << versionString << "\">" << endl;
}

159 160 161 162 163 164 165 166 167 168
static void writeCombineScript()
{
  QCString outputDirectory = Config_getString("XML_OUTPUT");
  QCString fileName=outputDirectory+"/combine.xslt";
  QFile f(fileName);
  if (!f.open(IO_WriteOnly))
  {
    err("Cannot open file %s for writing!\n",fileName.data());
    return;
  }
169 170
  FTextStream t(&f);
  //t.setEncoding(FTextStream::UnicodeUTF8);
171 172 173 174 175 176 177

  t <<
  "<!-- XSLT script to combine the generated output into a single file. \n"
  "     If you have xsltproc you could use:\n"
  "     xsltproc combine.xslt index.xml >all.xml\n"
  "-->\n"
  "<xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\">\n"
178
  "  <xsl:output method=\"xml\" version=\"1.0\" indent=\"no\" standalone=\"yes\" />\n"
179 180 181 182 183 184 185 186 187 188 189 190
  "  <xsl:template match=\"/\">\n"
  "    <doxygen version=\"{doxygenindex/@version}\">\n"
  "      <!-- Load all doxgen generated xml files -->\n"
  "      <xsl:for-each select=\"doxygenindex/compound\">\n"
  "        <xsl:copy-of select=\"document( concat( @refid, '.xml' ) )/doxygen/*\" />\n"
  "      </xsl:for-each>\n"
  "    </doxygen>\n"
  "  </xsl:template>\n"
  "</xsl:stylesheet>\n";

}

191
void writeXMLLink(FTextStream &t,const char *extRef,const char *compoundId,
192
                  const char *anchorId,const char *text,const char *tooltip)
193
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
194 195 196 197
  t << "<ref refid=\"" << compoundId;
  if (anchorId) t << "_1" << anchorId;
  t << "\" kindref=\"";
  if (anchorId) t << "member"; else t << "compound"; 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
198
  t << "\"";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
199
  if (extRef) t << " external=\"" << extRef << "\"";
200
  if (tooltip) t << " tooltip=\"" << convertToXML(tooltip) << "\"";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
201 202 203
  t << ">";
  writeXMLString(t,text);
  t << "</ref>";
204 205
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
206
/** Implements TextGeneratorIntf for an XML stream. */
207 208 209
class TextGeneratorXMLImpl : public TextGeneratorIntf
{
  public:
210
    TextGeneratorXMLImpl(FTextStream &t): m_t(t) {}
Dimitri van Heesch's avatar
Dimitri van Heesch committed
211
    void writeString(const char *s,bool /*keepSpaces*/) const
212 213 214
    {
      writeXMLString(m_t,s); 
    }
215
    void writeBreak(int) const {}
216 217 218 219
    void writeLink(const char *extRef,const char *file,
                   const char *anchor,const char *text
                  ) const
    {
220
      writeXMLLink(m_t,extRef,file,anchor,text,0);
221 222
    }
  private:
223
    FTextStream &m_t;
224 225
};

Dimitri van Heesch's avatar
Dimitri van Heesch committed
226

Dimitri van Heesch's avatar
Dimitri van Heesch committed
227
/** Generator for producing XML formatted source code. */
228
class XMLCodeGenerator : public CodeOutputInterface
Dimitri van Heesch's avatar
Dimitri van Heesch committed
229 230 231
{
  public:

232
    XMLCodeGenerator(FTextStream &t) : m_t(t), m_lineNumber(-1),
233 234
      m_insideCodeLine(FALSE), m_normalHLNeedStartTag(TRUE), 
      m_insideSpecialHL(FALSE) {}
235
    virtual ~XMLCodeGenerator() { }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
236
    
237
    void codify(const char *text) 
238
    {
239 240
      XML_DB(("(codify \"%s\")\n",text));
      if (m_insideCodeLine && !m_insideSpecialHL && m_normalHLNeedStartTag)
241
      {
242 243
        m_t << "<highlight class=\"normal\">";
        m_normalHLNeedStartTag=FALSE;
244
      }
245
      writeXMLCodeString(m_t,text,col);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
246 247
    }
    void writeCodeLink(const char *ref,const char *file,
248 249
                       const char *anchor,const char *name,
                       const char *tooltip) 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
250
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
251
      XML_DB(("(writeCodeLink)\n"));
252
      if (m_insideCodeLine && !m_insideSpecialHL && m_normalHLNeedStartTag)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
253
      {
254 255
        m_t << "<highlight class=\"normal\">";
        m_normalHLNeedStartTag=FALSE;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
256
      }
257
      writeXMLLink(m_t,ref,file,anchor,name,tooltip);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
258
      col+=qstrlen(name);
259
    }
260 261 262 263 264 265
    void writeTooltip(const char *, const DocLinkInfo &, const char *,
                      const char *, const SourceLinkInfo &, const SourceLinkInfo &
                     )
    {
      XML_DB(("(writeToolTip)\n"));
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
266
    void startCodeLine(bool) 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
267
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
268
      XML_DB(("(startCodeLine)\n"));
269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
      m_t << "<codeline";
      if (m_lineNumber!=-1)
      {
        m_t << " lineno=\"" << m_lineNumber << "\"";
        if (!m_refId.isEmpty())
        {
          m_t << " refid=\"" << m_refId << "\"";
          if (m_isMemberRef)
          {
            m_t << " refkind=\"member\"";
          }
          else
          {
            m_t << " refkind=\"compound\"";
          }
        }
        if (!m_external.isEmpty())
        {
          m_t << " external=\"" << m_external << "\"";
        }
      }
      m_t << ">"; 
      m_insideCodeLine=TRUE;
292
      col=0;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
293 294 295
    }
    void endCodeLine() 
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
296
      XML_DB(("(endCodeLine)\n"));
297 298 299 300 301
      if (!m_insideSpecialHL && !m_normalHLNeedStartTag)
      {
        m_t << "</highlight>";
        m_normalHLNeedStartTag=TRUE;
      }
302
      m_t << "</codeline>" << endl; // non DocBook
303 304 305 306
      m_lineNumber = -1;
      m_refId.resize(0);
      m_external.resize(0);
      m_insideCodeLine=FALSE;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
307 308 309
    }
    void startFontClass(const char *colorClass) 
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
310
      XML_DB(("(startFontClass)\n"));
311 312 313 314 315
      if (m_insideCodeLine && !m_insideSpecialHL && !m_normalHLNeedStartTag)
      {
        m_t << "</highlight>";
        m_normalHLNeedStartTag=TRUE;
      }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
316
      m_t << "<highlight class=\"" << colorClass << "\">"; // non DocBook
317
      m_insideSpecialHL=TRUE;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
318 319 320
    }
    void endFontClass()
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
321
      XML_DB(("(endFontClass)\n"));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
322
      m_t << "</highlight>"; // non DocBook
323
      m_insideSpecialHL=FALSE;
324
    }
325
    void writeCodeAnchor(const char *)
326
    {
327
      XML_DB(("(writeCodeAnchor)\n"));
328
    }
329 330
    void writeLineNumber(const char *extRef,const char *compId,
                         const char *anchorId,int l)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
331
    {
332 333 334 335 336 337 338 339 340 341 342
      XML_DB(("(writeLineNumber)\n"));
      // we remember the information provided here to use it 
      // at the <codeline> start tag.
      m_lineNumber = l;
      if (compId)
      {
        m_refId=compId;
        if (anchorId) m_refId+=(QCString)"_1"+anchorId;
        m_isMemberRef = anchorId!=0;
        if (extRef) m_external=extRef;
      }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
343
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
344 345 346 347 348 349
    void setCurrentDoc(Definition *,const char *,bool)
    {
    }
    void addWord(const char *,bool)
    {
    }
350

351 352 353 354
    void finish()
    {
      if (m_insideCodeLine) endCodeLine();
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
355 356

  private:
357
    FTextStream &m_t;  
358 359 360 361
    QCString m_refId;
    QCString m_external;
    int m_lineNumber;
    bool m_isMemberRef;
362
    int col;
363 364 365 366

    bool m_insideCodeLine;
    bool m_normalHLNeedStartTag;
    bool m_insideSpecialHL;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
367 368
};

369

370
static void writeTemplateArgumentList(ArgumentList *al,
371
                                      FTextStream &t,
372 373 374
                                      Definition *scope,
                                      FileDef *fileScope,
                                      int indent)
375 376 377 378 379 380 381 382 383 384 385 386 387 388
{
  QCString indentStr;
  indentStr.fill(' ',indent);
  if (al)
  {
    t << indentStr << "<templateparamlist>" << endl;
    ArgumentListIterator ali(*al);
    Argument *a;
    for (ali.toFirst();(a=ali.current());++ali)
    {
      t << indentStr << "  <param>" << endl;
      if (!a->type.isEmpty())
      {
        t << indentStr <<  "    <type>";
389
        linkifyText(TextGeneratorXMLImpl(t),scope,fileScope,0,a->type);
390 391 392 393 394 395 396 397 398 399
        t << "</type>" << endl;
      }
      if (!a->name.isEmpty())
      {
        t << indentStr <<  "    <declname>" << a->name << "</declname>" << endl;
        t << indentStr <<  "    <defname>" << a->name << "</defname>" << endl;
      }
      if (!a->defval.isEmpty())
      {
        t << indentStr << "    <defval>";
400
        linkifyText(TextGeneratorXMLImpl(t),scope,fileScope,0,a->defval);
401 402 403 404 405 406 407 408
        t << "</defval>" << endl;
      }
      t << indentStr << "  </param>" << endl;
    }
    t << indentStr << "</templateparamlist>" << endl;
  }
}

409
static void writeMemberTemplateLists(MemberDef *md,FTextStream &t)
410
{
411 412
  ArgumentList *templMd = md->templateArguments();
  if (templMd) // function template prefix
413
  {
414
    writeTemplateArgumentList(templMd,t,md->getClassDef(),md->getFileDef(),8);
415 416 417
  }
}

418
static void writeTemplateList(ClassDef *cd,FTextStream &t)
419
{
420
  writeTemplateArgumentList(cd->templateArguments(),t,cd,0,4);
421 422
}

423
static void writeXMLDocBlock(FTextStream &t,
Dimitri van Heesch's avatar
Dimitri van Heesch committed
424 425
                      const QCString &fileName,
                      int lineNr,
426
                      Definition *scope,
427
                      MemberDef * md,
Dimitri van Heesch's avatar
Dimitri van Heesch committed
428 429
                      const QCString &text)
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
430
  QCString stext = text.stripWhiteSpace();
431
  if (stext.isEmpty()) return;
432
  // convert the documentation string into an abstract syntax tree
433
  DocNode *root = validatingParseDoc(fileName,lineNr,scope,md,text,FALSE,FALSE);
434 435 436 437 438 439 440 441 442 443 444
  // create a code generator
  XMLCodeGenerator *xmlCodeGen = new XMLCodeGenerator(t);
  // create a parse tree visitor for XML
  XmlDocVisitor *visitor = new XmlDocVisitor(t,*xmlCodeGen);
  // visit all nodes
  root->accept(visitor);
  // clean up
  delete visitor;
  delete xmlCodeGen;
  delete root;
  
Dimitri van Heesch's avatar
Dimitri van Heesch committed
445 446
}

447
void writeXMLCodeBlock(FTextStream &t,FileDef *fd)
448
{
449
  ParserInterface *pIntf=Doxygen::parserManager->getParser(fd->getDefFileExtension());
450
  SrcLangExt langExt = getLanguageFromFileName(fd->getDefFileExtension());
451
  pIntf->resetCodeParserState();
452
  XMLCodeGenerator *xmlGen = new XMLCodeGenerator(t);
453 454
  pIntf->parseCode(*xmlGen,  // codeOutIntf
                0,           // scopeName
455
                fileToString(fd->absFilePath(),Config_getBool("FILTER_SOURCE_FILES")),
456
                langExt,     // lang
457 458 459 460 461 462 463 464 465
                FALSE,       // isExampleBlock
                0,           // exampleName
                fd,          // fileDef
                -1,          // startLine
                -1,          // endLine
                FALSE,       // inlineFragement
                0,           // memberDef
                TRUE         // showLineNumbers
                );
466
  xmlGen->finish();
467 468 469
  delete xmlGen;
}

470
static void writeMemberReference(FTextStream &t,Definition *def,MemberDef *rmd,const char *tagName)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
471 472 473 474 475
{
  QCString scope = rmd->getScopeString();
  QCString name = rmd->name();
  if (!scope.isEmpty() && scope!=def->name())
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
476
    name.prepend(scope+getLanguageSpecificSeparator(rmd->getLanguage()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
477
  }
478
  t << "        <" << tagName << " refid=\"";
479 480 481 482 483 484 485 486 487 488 489 490
  t << rmd->getOutputFileBase() << "_1" << rmd->anchor() << "\"";
  if (rmd->getStartBodyLine()!=-1 && rmd->getBodyDef()) 
  {
    t << " compoundref=\"" << rmd->getBodyDef()->getOutputFileBase() << "\"";
    t << " startline=\"" << rmd->getStartBodyLine() << "\"";
    if (rmd->getEndBodyLine()!=-1)
    {
      t << " endline=\"" << rmd->getEndBodyLine() << "\"";
    }
  }
  t << ">" << convertToXML(name) << "</" << tagName << ">" << endl;
  
Dimitri van Heesch's avatar
Dimitri van Heesch committed
491
}
492

493 494 495 496 497
static void stripQualifiers(QCString &typeStr)
{
  bool done=FALSE;
  while (!done)
  {
498 499 500
    if (typeStr.stripPrefix("static "));
    else if (typeStr.stripPrefix("virtual "));
    else if (typeStr.stripPrefix("volatile "));
501
    else if (typeStr=="virtual") typeStr="";
502 503 504 505
    else done=TRUE;
  }
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
506 507
static QCString classOutputFileBase(ClassDef *cd)
{
508 509 510 511 512
  //static bool inlineGroupedClasses = Config_getBool("INLINE_GROUPED_CLASSES");
  //if (inlineGroupedClasses && cd->partOfGroups()!=0) 
  return cd->getOutputFileBase();
  //else 
  //  return cd->getOutputFileBase();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
513 514 515 516
}

static QCString memberOutputFileBase(MemberDef *md)
{
517 518 519 520 521 522
  //static bool inlineGroupedClasses = Config_getBool("INLINE_GROUPED_CLASSES");
  //if (inlineGroupedClasses && md->getClassDef() && md->getClassDef()->partOfGroups()!=0) 
  //  return md->getClassDef()->getXmlOutputFileBase();
  //else 
  //  return md->getOutputFileBase();
  return md->getOutputFileBase();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
523 524 525
}


526
static void generateXMLForMember(MemberDef *md,FTextStream &ti,FTextStream &t,Definition *def)
527
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
528

529 530 531 532 533
  // + declaration/definition arg lists
  // + reimplements
  // + reimplementedBy
  // + exceptions
  // + const/volatile specifiers
Dimitri van Heesch's avatar
Dimitri van Heesch committed
534 535
  // - examples
  // + source definition
536 537 538
  // + source references
  // + source referenced by
  // - body code 
539
  // + template arguments 
540
  //     (templateArguments(), definitionTemplateParameterLists())
541
  // - call graph
Dimitri van Heesch's avatar
Dimitri van Heesch committed
542
  
543
  // enum values are written as part of the enum
544
  if (md->memberType()==MemberType_EnumValue) return;
545
  if (md->isHidden()) return;
546
  //if (md->name().at(0)=='@') return; // anonymous member
547

548 549 550
  // group members are only visible in their group
  //if (def->definitionType()!=Definition::TypeGroup && md->getGroupDef()) return;

551 552 553 554
  QCString memType;
  bool isFunc=FALSE;
  switch (md->memberType())
  {
555
    case MemberType_Define:      memType="define";    break;
556
    case MemberType_Function:    memType="function";  isFunc=TRUE; break;
557 558 559
    case MemberType_Variable:    memType="variable";  break;
    case MemberType_Typedef:     memType="typedef";   break;
    case MemberType_Enumeration: memType="enum";      break;
560
    case MemberType_EnumValue:   ASSERT(0);           break;
561
    case MemberType_Signal:      memType="signal";    isFunc=TRUE; break;
562
    case MemberType_Slot:        memType="slot";      isFunc=TRUE; break;
563 564
    case MemberType_Friend:      memType="friend";    isFunc=TRUE; break;
    case MemberType_DCOP:        memType="dcop";      isFunc=TRUE; break;
565 566 567 568
    case MemberType_Property:    memType="property";  break;
    case MemberType_Event:       memType="event";     break;
    case MemberType_Interface:   memType="interface"; break;
    case MemberType_Service:     memType="service";   break;
569
  }
570

Dimitri van Heesch's avatar
Dimitri van Heesch committed
571
  ti << "    <member refid=\"" << memberOutputFileBase(md) 
572 573 574 575 576 577 578 579 580 581 582
     << "_1" << md->anchor() << "\" kind=\"" << memType << "\"><name>" 
     << convertToXML(md->name()) << "</name></member>" << endl;
  
  QCString scopeName;
  if (md->getClassDef()) 
    scopeName=md->getClassDef()->name();
  else if (md->getNamespaceDef()) 
    scopeName=md->getNamespaceDef()->name();
    
  t << "      <memberdef kind=\"";
  //enum { define_t,variable_t,typedef_t,enum_t,function_t } xmlType = function_t;
583
  t << memType << "\" id=\"";
584
  if (md->getGroupDef() && def->definitionType()==Definition::TypeGroup)
585
  {
586
    t << md->getGroupDef()->getOutputFileBase();
587
  }
588 589
  else
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
590
    t << memberOutputFileBase(md);
591 592 593
  }
  t << "_1"      // encoded `:' character (see util.cpp:convertNameToFile)
    << md->anchor();
594 595 596 597 598 599
  t << "\" prot=\"";
  switch(md->protection())
  {
    case Public:    t << "public";     break;
    case Protected: t << "protected";  break;
    case Private:   t << "private";    break;
600
    case Package:   t << "package";    break;
601
  }
602
  t << "\"";
603

604 605
  t << " static=\"";
  if (md->isStatic()) t << "yes"; else t << "no";
606 607 608 609
  t << "\"";

  if (isFunc)
  {
610
    ArgumentList *al = md->argumentList();
611
    t << " const=\"";
612
    if (al!=0 && al->constSpecifier)    t << "yes"; else t << "no"; 
613
    t << "\"";
614

615
    t << " explicit=\"";
616
    if (md->isExplicit()) t << "yes"; else t << "no";
617
    t << "\"";
618

619
    t << " inline=\"";
620
    if (md->isInline()) t << "yes"; else t << "no";
621
    t << "\"";
622

623 624 625 626 627 628 629 630 631 632 633 634 635 636 637
    if (md->isFinal())
    {
      t << " final=\"yes\"";
    }

    if (md->isSealed())
    {
      t << " sealed=\"yes\"";
    }

    if (md->isNew())
    {
      t << " new=\"yes\"";
    }

638 639 640 641 642 643 644 645 646 647
    if (md->isOptional())
    {
      t << " optional=\"yes\"";
    }

    if (md->isRequired())
    {
      t << " required=\"yes\"";
    }

648 649 650 651 652 653 654 655
    t << " virt=\"";
    switch (md->virtualness())
    {
      case Normal:  t << "non-virtual";  break;
      case Virtual: t << "virtual";      break;
      case Pure:    t << "pure-virtual"; break;
      default: ASSERT(0);
    }
656 657 658
    t << "\"";
  }

659
  if (md->memberType() == MemberType_Variable)
660
  {
661 662 663
    //ArgumentList *al = md->argumentList();
    //t << " volatile=\"";
    //if (al && al->volatileSpecifier) t << "yes"; else t << "no"; 
664

665
    t << " mutable=\"";
666
    if (md->isMutable()) t << "yes"; else t << "no";
667
    t << "\"";
668
    
669 670 671 672
    if (md->isInitonly())
    {
      t << " initonly=\"yes\"";
    }
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713

    if (md->isAttribute())
    {
      t << " attribute=\"yes\"";
    }
    if (md->isUNOProperty())
    {
      t << " property=\"yes\"";
    }
    if (md->isReadonly())
    {
      t << " readonly=\"yes\"";
    }
    if (md->isBound())
    {
      t << " bound=\"yes\"";
    }
    if (md->isRemovable())
    {
      t << " removable=\"yes\"";
    }
    if (md->isConstrained())
    {
      t << " constrained=\"yes\"";
    }
    if (md->isTransient())
    {
      t << " transient=\"yes\"";
    }
    if (md->isMaybeVoid())
    {
      t << " maybevoid=\"yes\"";
    }
    if (md->isMaybeDefault())
    {
      t << " maybedefault=\"yes\"";
    }
    if (md->isMaybeAmbiguous())
    {
      t << " maybeambiguous=\"yes\"";
    }
714
  }
715
  else if (md->memberType() == MemberType_Property)
716 717 718
  {
    t << " readable=\"";
    if (md->isReadable()) t << "yes"; else t << "no";
719 720
    t << "\"";

721
    t << " writable=\"";
722 723
    if (md->isWritable()) t << "yes"; else t << "no";
    t << "\"";
724 725 726 727 728 729 730 731

    t << " gettable=\"";
    if (md->isGettable()) t << "yes"; else t << "no";
    t << "\"";

    t << " settable=\"";
    if (md->isSettable()) t << "yes"; else t << "no";
    t << "\"";
732

Dimitri van Heesch's avatar
Dimitri van Heesch committed
733
    if (md->isAssign() || md->isCopy() || md->isRetain() || md->isStrong() || md->isWeak())
734 735
    {
      t << " accessor=\"";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
736 737
      if (md->isAssign())      t << "assign";
      else if (md->isCopy())   t << "copy";
738
      else if (md->isRetain()) t << "retain";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
739 740
      else if (md->isStrong()) t << "strong";
      else if (md->isWeak())   t << "weak";
741 742
      t << "\"";
    }
743
  }
744
  else if (md->memberType() == MemberType_Event)
745 746 747 748 749 750 751 752
  {
    t << " add=\"";
    if (md->isAddable()) t << "yes"; else t << "no";
    t << "\"";

    t << " remove=\"";
    if (md->isRemovable()) t << "yes"; else t << "no";
    t << "\"";
753

754 755 756 757
    t << " raise=\"";
    if (md->isRaisable()) t << "yes"; else t << "no";
    t << "\"";
  }
758

759 760
  t << ">" << endl;

761 762
  if (md->memberType()!=MemberType_Define &&
      md->memberType()!=MemberType_Enumeration
763 764
     )
  {
765
    if (md->memberType()!=MemberType_Typedef)
766 767 768
    {
      writeMemberTemplateLists(md,t);
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
769
    QCString typeStr = md->typeString(); //replaceAnonymousScopes(md->typeString());
770
    stripQualifiers(typeStr);
771
    t << "        <type>";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
772
    linkifyText(TextGeneratorXMLImpl(t),def,md->getBodyDef(),md,typeStr);
773
    t << "</type>" << endl;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
774 775
    t << "        <definition>" << convertToXML(md->definition()) << "</definition>" << endl;
    t << "        <argsstring>" << convertToXML(md->argsString()) << "</argsstring>" << endl;
776 777
  }

778
  t << "        <name>" << convertToXML(md->name()) << "</name>" << endl;
779
  
780
  if (md->memberType() == MemberType_Property)
781 782 783 784 785 786
  {
    if (md->isReadable())
      t << "        <read>" << convertToXML(md->getReadAccessor()) << "</read>" << endl;
    if (md->isWritable())
      t << "        <write>" << convertToXML(md->getWriteAccessor()) << "</write>" << endl;
  }
787
  if (md->memberType()==MemberType_Variable && md->bitfieldString())
788 789 790 791 792
  {
    QCString bitfield = md->bitfieldString();
    if (bitfield.at(0)==':') bitfield=bitfield.mid(1);
    t << "        <bitfield>" << bitfield << "</bitfield>" << endl;
  }
793
  
794 795 796
  MemberDef *rmd = md->reimplements();
  if (rmd)
  {
797
    t << "        <reimplements refid=\"" 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
798
      << memberOutputFileBase(rmd) << "_1" << rmd->anchor() << "\">"
799
      << convertToXML(rmd->name()) << "</reimplements>" << endl;
800
  }
801 802
  MemberList *rbml = md->reimplementedBy();
  if (rbml)
803 804 805 806
  {
    MemberListIterator mli(*rbml);
    for (mli.toFirst();(rmd=mli.current());++mli)
    {
807
      t << "        <reimplementedby refid=\"" 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
808
        << memberOutputFileBase(rmd) << "_1" << rmd->anchor() << "\">"
809
        << convertToXML(rmd->name()) << "</reimplementedby>" << endl;
810 811
    }
  }
812

813 814
  if (isFunc) //function
  {
815 816 817
    ArgumentList *declAl = md->declArgumentList();
    ArgumentList *defAl = md->argumentList();
    if (declAl && declAl->count()>0)
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
    {
      ArgumentListIterator declAli(*declAl);
      ArgumentListIterator defAli(*defAl);
      Argument *a;
      for (declAli.toFirst();(a=declAli.current());++declAli)
      {
        Argument *defArg = defAli.current();
        t << "        <param>" << endl;
        if (!a->attrib.isEmpty())
        {
          t << "          <attributes>";
          writeXMLString(t,a->attrib);
          t << "</attributes>" << endl;
        }
        if (!a->type.isEmpty())
        {
          t << "          <type>";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
835
          linkifyText(TextGeneratorXMLImpl(t),def,md->getBodyDef(),md,a->type);
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858
          t << "</type>" << endl;
        }
        if (!a->name.isEmpty())
        {
          t << "          <declname>";
          writeXMLString(t,a->name); 
          t << "</declname>" << endl;
        }
        if (defArg && !defArg->name.isEmpty() && defArg->name!=a->name)
        {
          t << "          <defname>";
          writeXMLString(t,defArg->name);
          t << "</defname>" << endl;
        }
        if (!a->array.isEmpty())
        {
          t << "          <array>"; 
          writeXMLString(t,a->array); 
          t << "</array>" << endl;
        }
        if (!a->defval.isEmpty())
        {
          t << "          <defval>";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
859
          linkifyText(TextGeneratorXMLImpl(t),def,md->getBodyDef(),md,a->defval);
860 861
          t << "</defval>" << endl;
        }
862 863 864 865
        if (defArg && defArg->hasDocumentation())
        {
          t << "          <briefdescription>";
          writeXMLDocBlock(t,md->getDefFileName(),md->getDefLine(),
866
                           md->getOuterScope(),md,defArg->docs);
867 868
          t << "</briefdescription>" << endl;
        }
869 870 871 872 873
        t << "        </param>" << endl;
        if (defArg) ++defAli;
      }
    }
  }
874
  else if (md->memberType()==MemberType_Define && 
875
          md->argsString()) // define
876
  {
877 878
    if (md->argumentList()->count()==0) // special case for "foo()" to
                                        // disguish it from "foo".
879
    {
880 881 882 883 884 885 886 887 888 889
      t << "        <param></param>" << endl;
    }
    else
    {
      ArgumentListIterator ali(*md->argumentList());
      Argument *a;
      for (ali.toFirst();(a=ali.current());++ali)
      {
        t << "        <param><defname>" << a->type << "</defname></param>" << endl;
      }
890 891
    }
  }
892 893

  if (md->hasOneLineInitializer() || md->hasMultiLineInitializer())
894 895
  {
    t << "        <initializer>";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
896
    linkifyText(TextGeneratorXMLImpl(t),def,md->getBodyDef(),md,md->initializer());
897 898
    t << "</initializer>" << endl;
  }
899 900 901 902

  if (md->excpString())
  {
    t << "        <exceptions>";
Dimitri van Heesch's avatar
Dimitri van Heesch committed
903
    linkifyText(TextGeneratorXMLImpl(t),def,md->getBodyDef(),md,md->excpString());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
904
    t << "</exceptions>" << endl;
905 906
  }
  
907
  if (md->memberType()==MemberType_Enumeration) // enum
908
  {
909 910
    MemberList *enumFields = md->enumFieldList();
    if (enumFields)
911
    {
912
      MemberListIterator emli(*enumFields);
913 914 915
      MemberDef *emd;
      for (emli.toFirst();(emd=emli.current());++emli)
      {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
916
        ti << "    <member refid=\"" << memberOutputFileBase(emd) 
917 918 919
           << "_1" << emd->anchor() << "\" kind=\"enumvalue\"><name>" 
           << convertToXML(emd->name()) << "</name></member>" << endl;

Dimitri van Heesch's avatar
Dimitri van Heesch committed
920
        t << "        <enumvalue id=\"" << memberOutputFileBase(emd) << "_1" 
921 922 923 924 925 926
          << emd->anchor() << "\" prot=\"";
        switch (emd->protection())
        {
          case Public:    t << "public";    break;
          case Protected: t << "protected"; break;
          case Private:   t << "private";   break;
927
          case Package:   t << "package";   break;
928 929
        }
        t << "\">" << endl;
930 931 932 933 934 935 936 937 938
        t << "          <name>";
        writeXMLString(t,emd->name());
        t << "</name>" << endl;
        if (!emd->initializer().isEmpty())
        {
          t << "          <initializer>";
          writeXMLString(t,emd->initializer());
          t << "</initializer>" << endl;
        }
939
        t << "          <briefdescription>" << endl;
940
        writeXMLDocBlock(t,emd->briefFile(),emd->briefLine(),emd->getOuterScope(),emd,emd->briefDescription());
941 942
        t << "          </briefdescription>" << endl;
        t << "          <detaileddescription>" << endl;
943
        writeXMLDocBlock(t,emd->docFile(),emd->docLine(),emd->getOuterScope(),emd,emd->documentation());
944
        t << "          </detaileddescription>" << endl;
945 946 947 948
        t << "        </enumvalue>" << endl;
      }
    }
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
949
  t << "        <briefdescription>" << endl;
950
  writeXMLDocBlock(t,md->briefFile(),md->briefLine(),md->getOuterScope(),md,md->briefDescription());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
951 952
  t << "        </briefdescription>" << endl;
  t << "        <detaileddescription>" << endl;
953
  writeXMLDocBlock(t,md->docFile(),md->docLine(),md->getOuterScope(),md,md->documentation());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
954
  t << "        </detaileddescription>" << endl;
955 956 957
  t << "        <inbodydescription>" << endl;
  writeXMLDocBlock(t,md->docFile(),md->inbodyLine(),md->getOuterScope(),md,md->inbodyDocumentation());
  t << "        </inbodydescription>" << endl;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
958 959 960 961
  if (md->getDefLine()!=-1)
  {
    t << "        <location file=\"" 
      << md->getDefFileName() << "\" line=\"" 
962 963
      << md->getDefLine() << "\"" << " column=\"" 
      << md->getDefColumn() << "\"" ;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
964 965
    if (md->getStartBodyLine()!=-1)
    {
966 967 968 969 970
      FileDef *bodyDef = md->getBodyDef();
      if (bodyDef)
      {
        t << " bodyfile=\"" << bodyDef->absFilePath() << "\"";
      }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
971 972 973 974
      t << " bodystart=\"" << md->getStartBodyLine() << "\" bodyend=\"" 
        << md->getEndBodyLine() << "\"";
    }
    t << "/>" << endl;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
975 976
  }

977
  //printf("md->getReferencesMembers()=%p\n",md->getReferencesMembers());
978 979
  MemberSDict *mdict = md->getReferencesMembers();
  if (mdict)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
980
  {
981
    MemberSDict::Iterator mdi(*mdict);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
982 983 984
    MemberDef *rmd;
    for (mdi.toFirst();(rmd=mdi.current());++mdi)
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
985
      writeMemberReference(t,def,rmd,"references");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
986 987
    }
  }
988
  mdict = md->getReferencedByMembers();
989
  if (mdict)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
990
  {
991
    MemberSDict::Iterator mdi(*mdict);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
992 993 994
    MemberDef *rmd;
    for (mdi.toFirst();(rmd=mdi.current());++mdi)
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
995
      writeMemberReference(t,def,rmd,"referencedby");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
996 997 998
    }
  }
  
999 1000 1001
  t << "      </memberdef>" << endl;
}

1002
static void generateXMLSection(Definition *d,FTextStream &ti,FTextStream &t,
1003 1004
                      MemberList *ml,const char *kind,const char *header=0,
                      const char *documentation=0)
1005
{
1006
  if (ml==0) return;
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019
  MemberListIterator mli(*ml);
  MemberDef *md;
  int count=0;
  for (mli.toFirst();(md=mli.current());++mli)
  {
    // namespace members are also inserted in the file scope, but 
    // to prevent this duplication in the XML output, we filter those here.
    if (d->definitionType()!=Definition::TypeFile || md->getNamespaceDef()==0)
    {
      count++;
    }
  }
  if (count==0) return; // empty list
1020 1021 1022

  t << "      <sectiondef kind=\"" << kind << "\">" << endl;
  if (header)
1023
  {
1024 1025
    t << "      <header>" << convertToXML(header) << "</header>" << endl;
  }
1026 1027 1028 1029 1030 1031
  if (documentation)
  {
    t << "      <description>";
    writeXMLDocBlock(t,d->docFile(),d->docLine(),d,0,documentation);
    t << "</description>" << endl;
  }
1032 1033
  for (mli.toFirst();(md=mli.current());++mli)
  {
1034 1035 1036 1037 1038 1039
    // namespace members are also inserted in the file scope, but 
    // to prevent this duplication in the XML output, we filter those here.
    if (d->definitionType()!=Definition::TypeFile || md->getNamespaceDef()==0)
    {
      generateXMLForMember(md,ti,t,d);
    }
1040
  }
1041
  t << "      </sectiondef>" << endl;
1042 1043
}

1044
static void writeListOfAllMembers(ClassDef *cd,FTextStream &t)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1045 1046
{
  t << "    <listofallmembers>" << endl;
1047
  if (cd->memberNameInfoSDict())
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1048
  {
1049 1050 1051
    MemberNameInfoSDict::Iterator mnii(*cd->memberNameInfoSDict());
    MemberNameInfo *mni;
    for (mnii.toFirst();(mni=mnii.current());++mnii)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1052
    {
1053 1054 1055
      MemberNameInfoIterator mii(*mni);
      MemberInfo *mi;
      for (mii.toFirst();(mi=mii.current());++mii)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1056
      {
1057
        MemberDef *md=mi->memberDef;
1058
        if (md->name().at(0)!='@') // skip anonymous members
1059
        {
1060 1061
          Protection prot = mi->prot;
          Specifier virt=md->virtualness();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1062
          t << "      <member refid=\"" << memberOutputFileBase(md) << "_1" <<
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084
            md->anchor() << "\" prot=\"";
          switch (prot)
          {
            case Public:    t << "public";    break;
            case Protected: t << "protected"; break;
            case Private:   t << "private";   break;
            case Package:   t << "package";   break;
          }
          t << "\" virt=\"";
          switch(virt)
          {
            case Normal:  t << "non-virtual";  break;
            case Virtual: t << "virtual";      break;
            case Pure:    t << "pure-virtual"; break;
          }
          t << "\"";
          if (!mi->ambiguityResolutionScope.isEmpty())
          {
            t << " ambiguityscope=\"" << convertToXML(mi->ambiguityResolutionScope) << "\"";
          }
          t << "><scope>" << convertToXML(cd->name()) << "</scope><name>" << 
            convertToXML(md->name()) << "</name></member>" << endl;
1085
        }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1086 1087 1088 1089 1090 1091
      }
    }
  }
  t << "    </listofallmembers>" << endl;
}

1092
static void writeInnerClasses(const ClassSDict *cl,FTextStream &t)
1093 1094 1095 1096 1097 1098 1099
{
  if (cl)
  {
    ClassSDict::Iterator cli(*cl);
    ClassDef *cd;
    for (cli.toFirst();(cd=cli.current());++cli)
    {
1100
      if (!cd->isHidden() && cd->name().find('@')==-1) // skip anonymous scopes
1101
      {
1102
        t << "    <innerclass refid=\"" << classOutputFileBase(cd)
1103 1104 1105 1106 1107 1108 1109 1110 1111
          << "\" prot=\"";
        switch(cd->protection())
        {
           case Public:    t << "public";     break;
           case Protected: t << "protected";  break;
           case Private:   t << "private";    break;
           case Package:   t << "package";    break;
        }
        t << "\">" << convertToXML(cd->name()) << "</innerclass>" << endl;
1112 1113 1114 1115 1116
      }
    }
  }
}

1117
static void writeInnerNamespaces(const NamespaceSDict *nl,FTextStream &t)
1118 1119 1120 1121 1122 1123 1124
{
  if (nl)
  {
    NamespaceSDict::Iterator nli(*nl);
    NamespaceDef *nd;
    for (nli.toFirst();(nd=nli.current());++nli)
    {
1125
      if (!nd->isHidden() && nd->name().find('@')==-1) // skip anonymouse scopes
1126 1127 1128 1129 1130 1131 1132 1133
      {
        t << "    <innernamespace refid=\"" << nd->getOutputFileBase()
          << "\">" << convertToXML(nd->name()) << "</innernamespace>" << endl;
      }
    }
  }
}

1134
static void writeInnerFiles(const FileList *fl,FTextStream &t)
1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147
{
  if (fl)
  {
    QListIterator<FileDef> fli(*fl);
    FileDef *fd;
    for (fli.toFirst();(fd=fli.current());++fli)
    {
      t << "    <innerfile refid=\"" << fd->getOutputFileBase() 
        << "\">" << convertToXML(fd->name()) << "</innerfile>" << endl;
    }
  }
}

1148
static void writeInnerPages(const PageSDict *pl,FTextStream &t)
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165
{
  if (pl)
  {
    PageSDict::Iterator pli(*pl);
    PageDef *pd;
    for (pli.toFirst();(pd=pli.current());++pli)
    {
      t << "    <innerpage refid=\"" << pd->getOutputFileBase();
      if (pd->getGroupDef())
      {
        t << "_" << pd->name();
      }
      t << "\">" << convertToXML(pd->title()) << "</innerpage>" << endl;
    }
  }
}

1166
static void writeInnerGroups(const GroupList *gl,FTextStream &t)
1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
{
  if (gl)
  {
    GroupListIterator gli(*gl);
    GroupDef *sgd;
    for (gli.toFirst();(sgd=gli.current());++gli)
    {
      t << "    <innergroup refid=\"" << sgd->getOutputFileBase()
        << "\">" << convertToXML(sgd->groupTitle()) 
        << "</innergroup>" << endl;
    }
  }
}

1181
static void writeInnerDirs(const DirList *dl,FTextStream &t)
1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194
{
  if (dl)
  {
    QListIterator<DirDef> subdirs(*dl);
    DirDef *subdir;
    for (subdirs.toFirst();(subdir=subdirs.current());++subdirs)
    {
      t << "    <innerdir refid=\"" << subdir->getOutputFileBase() 
        << "\">" << convertToXML(subdir->displayName()) << "</innerdir>" << endl;
    }
  }
}
  
1195
static void generateXMLForClass(ClassDef *cd,FTextStream &ti)
1196
{
1197 1198
  // + brief description
  // + detailed description
1199
  // + template argument list(s)
1200
  // - include file
1201
  // + member groups
1202 1203 1204
  // + inheritance diagram
  // + list of direct super classes
  // + list of direct sub classes
1205
  // + list of inner classes
1206
  // + collaboration diagram
1207
  // + list of all members
1208 1209 1210
  // + user defined member sections
  // + standard member sections
  // + detailed member documentation
1211
  // - examples using the class
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1212

1213
  if (cd->isReference())        return; // skip external references.
1214
  if (cd->isHidden())           return; // skip hidden classes.
1215
  if (cd->name().find('@')!=-1) return; // skip anonymous compounds.
1216
  if (cd->templateMaster()!=0)  return; // skip generated template instances.
1217
  if (cd->isArtificial())       return; // skip artificially created classes
1218

1219 1220
  msg("Generating XML output for class %s\n",cd->name().data());

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1221
  ti << "  <compound refid=\"" << classOutputFileBase(cd) 
1222
     << "\" kind=\"" << cd->compoundTypeString()
1223
     << "\"><name>" << convertToXML(cd->name()) << "</name>" << endl;
1224
  
1225
  QCString outputDirectory = Config_getString("XML_OUTPUT");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1226
  QCString fileName=outputDirectory+"/"+ classOutputFileBase(cd)+".xml";
1227 1228 1229 1230 1231 1232
  QFile f(fileName);
  if (!f.open(IO_WriteOnly))
  {
    err("Cannot open file %s for writing!\n",fileName.data());
    return;
  }
1233 1234
  FTextStream t(&f);
  //t.setEncoding(FTextStream::UnicodeUTF8);
1235

1236
  writeXMLHeader(t);
1237
  t << "  <compounddef id=\"" 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1238
    << classOutputFileBase(cd) << "\" kind=\"" 
1239 1240 1241 1242 1243 1244 1245 1246
    << cd->compoundTypeString() << "\" prot=\"";
  switch (cd->protection())
  {
    case Public:    t << "public";    break;
    case Protected: t << "protected"; break;
    case Private:   t << "private";   break;
    case Package:   t << "package";   break;
  }
1247 1248 1249
  if (cd->isFinal()) t << "\" final=\"yes";
  if (cd->isSealed()) t << "\" sealed=\"yes";
  if (cd->isAbstract()) t << "\" abstract=\"yes";
1250
  t << "\">" << endl;
1251 1252 1253
  t << "    <compoundname>"; 
  writeXMLString(t,cd->name()); 
  t << "</compoundname>" << endl;
1254
  if (cd->baseClasses())
1255 1256 1257 1258 1259
  {
    BaseClassListIterator bcli(*cd->baseClasses());
    BaseClassDef *bcd;
    for (bcli.toFirst();(bcd=bcli.current());++bcli)
    {
1260 1261 1262
      t << "    <basecompoundref ";
      if (bcd->classDef->isLinkable())
      {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1263
        t << "refid=\"" << classOutputFileBase(bcd->classDef) << "\" ";
1264 1265
      }
      t << "prot=\"";
1266 1267 1268 1269 1270
      switch (bcd->prot)
      {
        case Public:    t << "public";    break;
        case Protected: t << "protected"; break;
        case Private:   t << "private";   break;
1271
        case Package: ASSERT(0); break;
1272 1273 1274 1275 1276 1277 1278 1279
      }
      t << "\" virt=\"";
      switch(bcd->virt)
      {
        case Normal:  t << "non-virtual";  break;
        case Virtual: t << "virtual";      break;
        case Pure:    t <<"pure-virtual"; break;
      }
1280 1281 1282
      t << "\">";
      if (!bcd->templSpecifiers.isEmpty())
      {
1283 1284
        t << convertToXML(
              insertTemplateSpecifierInScope(
1285
              bcd->classDef->name(),bcd->templSpecifiers)
1286 1287 1288 1289
           );
      }
      else
      {
1290
        t << convertToXML(bcd->classDef->displayName());
1291 1292
      }
      t  << "</basecompoundref>" << endl;
1293 1294
    }
  }
1295
  if (cd->subClasses())
1296 1297 1298 1299 1300
  {
    BaseClassListIterator bcli(*cd->subClasses());
    BaseClassDef *bcd;
    for (bcli.toFirst();(bcd=bcli.current());++bcli)
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1301
      t << "    <derivedcompoundref refid=\"" 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1302
        << classOutputFileBase(bcd->classDef)
1303 1304 1305 1306 1307 1308
        << "\" prot=\"";
      switch (bcd->prot)
      {
        case Public:    t << "public";    break;
        case Protected: t << "protected"; break;
        case Private:   t << "private";   break;
1309
        case Package: ASSERT(0); break;
1310 1311 1312 1313 1314 1315 1316 1317
      }
      t << "\" virt=\"";
      switch(bcd->virt)
      {
        case Normal:  t << "non-virtual";  break;
        case Virtual: t << "virtual";      break;
        case Pure:    t << "pure-virtual"; break;
      }
1318
      t << "\">" << convertToXML(bcd->classDef->displayName()) 
1319
        << "</derivedcompoundref>" << endl;
1320 1321
    }
  }
1322

1323 1324 1325 1326 1327 1328 1329 1330 1331 1332
  IncludeInfo *ii=cd->includeInfo();
  if (ii)
  {
    QCString nm = ii->includeName;
    if (nm.isEmpty() && ii->fileDef) nm = ii->fileDef->docName();
    if (!nm.isEmpty())
    {
      t << "    <includes";
      if (ii->fileDef && !ii->fileDef->isReference()) // TODO: support external references
      {
1333
        t << " refid=\"" << ii->fileDef->getOutputFileBase() << "\"";
1334
      }
1335
      t << " local=\"" << (ii->local ? "yes" : "no") << "\">";
1336 1337 1338 1339 1340
      t << nm;
      t << "</includes>" << endl;
    }
  }

1341
  writeInnerClasses(cd->getClassSDict(),t);
1342

1343
  writeTemplateList(cd,t);
1344
  if (cd->getMemberGroupSDict())
1345
  {
1346
    MemberGroupSDict::Iterator mgli(*cd->getMemberGroupSDict());
1347 1348 1349 1350 1351 1352
    MemberGroup *mg;
    for (;(mg=mgli.current());++mgli)
    {
      generateXMLSection(cd,ti,t,mg->members(),"user-defined",mg->header(),
          mg->documentation());
    }
1353
  }
1354

1355 1356 1357 1358
  QListIterator<MemberList> mli(cd->getMemberLists());
  MemberList *ml;
  for (mli.toFirst();(ml=mli.current());++mli)
  {
1359
    if ((ml->listType()&MemberListType_detailedLists)==0)
1360 1361 1362 1363 1364
    {
      generateXMLSection(cd,ti,t,ml,g_xmlSectionMapper.find(ml->listType()));
    }
  }
#if 0
1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393
  generateXMLSection(cd,ti,t,cd->pubTypes,"public-type");
  generateXMLSection(cd,ti,t,cd->pubMethods,"public-func");
  generateXMLSection(cd,ti,t,cd->pubAttribs,"public-attrib");
  generateXMLSection(cd,ti,t,cd->pubSlots,"public-slot");
  generateXMLSection(cd,ti,t,cd->signals,"signal");
  generateXMLSection(cd,ti,t,cd->dcopMethods,"dcop-func");
  generateXMLSection(cd,ti,t,cd->properties,"property");
  generateXMLSection(cd,ti,t,cd->events,"event");
  generateXMLSection(cd,ti,t,cd->pubStaticMethods,"public-static-func");
  generateXMLSection(cd,ti,t,cd->pubStaticAttribs,"public-static-attrib");
  generateXMLSection(cd,ti,t,cd->proTypes,"protected-type");
  generateXMLSection(cd,ti,t,cd->proMethods,"protected-func");
  generateXMLSection(cd,ti,t,cd->proAttribs,"protected-attrib");
  generateXMLSection(cd,ti,t,cd->proSlots,"protected-slot");
  generateXMLSection(cd,ti,t,cd->proStaticMethods,"protected-static-func");
  generateXMLSection(cd,ti,t,cd->proStaticAttribs,"protected-static-attrib");
  generateXMLSection(cd,ti,t,cd->pacTypes,"package-type");
  generateXMLSection(cd,ti,t,cd->pacMethods,"package-func");
  generateXMLSection(cd,ti,t,cd->pacAttribs,"package-attrib");
  generateXMLSection(cd,ti,t,cd->pacStaticMethods,"package-static-func");
  generateXMLSection(cd,ti,t,cd->pacStaticAttribs,"package-static-attrib");
  generateXMLSection(cd,ti,t,cd->priTypes,"private-type");
  generateXMLSection(cd,ti,t,cd->priMethods,"private-func");
  generateXMLSection(cd,ti,t,cd->priAttribs,"private-attrib");
  generateXMLSection(cd,ti,t,cd->priSlots,"private-slot");
  generateXMLSection(cd,ti,t,cd->priStaticMethods,"private-static-func");
  generateXMLSection(cd,ti,t,cd->priStaticAttribs,"private-static-attrib");
  generateXMLSection(cd,ti,t,cd->friends,"friend");
  generateXMLSection(cd,ti,t,cd->related,"related");
1394
#endif
1395

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1396
  t << "    <briefdescription>" << endl;
1397
  writeXMLDocBlock(t,cd->briefFile(),cd->briefLine(),cd,0,cd->briefDescription());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1398 1399
  t << "    </briefdescription>" << endl;
  t << "    <detaileddescription>" << endl;
1400
  writeXMLDocBlock(t,cd->docFile(),cd->docLine(),cd,0,cd->documentation());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1401
  t << "    </detaileddescription>" << endl;
1402
  DotClassGraph inheritanceGraph(cd,DotNode::Inheritance);
1403 1404 1405 1406 1407 1408
  if (!inheritanceGraph.isTrivial())
  {
    t << "    <inheritancegraph>" << endl;
    inheritanceGraph.writeXML(t);
    t << "    </inheritancegraph>" << endl;
  }
1409
  DotClassGraph collaborationGraph(cd,DotNode::Collaboration);
1410 1411 1412 1413 1414 1415
  if (!collaborationGraph.isTrivial())
  {
    t << "    <collaborationgraph>" << endl;
    collaborationGraph.writeXML(t);
    t << "    </collaborationgraph>" << endl;
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1416
  t << "    <location file=\"" 
1417
    << cd->getDefFileName() << "\" line=\"" 
1418 1419
    << cd->getDefLine() << "\"" << " column=\"" 
    << cd->getDefColumn() << "\"" ;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1420 1421
    if (cd->getStartBodyLine()!=-1)
    {
1422 1423 1424 1425 1426
      FileDef *bodyDef = cd->getBodyDef();
      if (bodyDef)
      {
        t << " bodyfile=\"" << bodyDef->absFilePath() << "\"";
      }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1427 1428 1429 1430
      t << " bodystart=\"" << cd->getStartBodyLine() << "\" bodyend=\"" 
        << cd->getEndBodyLine() << "\"";
    }
  t << "/>" << endl;
1431
  writeListOfAllMembers(cd,t);
1432
  t << "  </compounddef>" << endl;
1433 1434 1435
  t << "</doxygen>" << endl;

  ti << "  </compound>" << endl;
1436 1437
}

1438
static void generateXMLForNamespace(NamespaceDef *nd,FTextStream &ti)
1439
{
1440 1441 1442
  // + contained class definitions
  // + contained namespace definitions
  // + member groups
1443 1444 1445 1446 1447
  // + normal members
  // + brief desc
  // + detailed desc
  // + location
  // - files containing (parts of) the namespace definition
1448

1449
  if (nd->isReference() || nd->isHidden()) return; // skip external references
1450

1451 1452 1453
  ti << "  <compound refid=\"" << nd->getOutputFileBase() 
     << "\" kind=\"namespace\"" << "><name>" 
     << convertToXML(nd->name()) << "</name>" << endl;
1454
  
1455 1456
  QCString outputDirectory = Config_getString("XML_OUTPUT");
  QCString fileName=outputDirectory+"/"+nd->getOutputFileBase()+".xml";
1457 1458 1459 1460 1461 1462
  QFile f(fileName);
  if (!f.open(IO_WriteOnly))
  {
    err("Cannot open file %s for writing!\n",fileName.data());
    return;
  }
1463 1464
  FTextStream t(&f);
  //t.setEncoding(FTextStream::UnicodeUTF8);
1465
  
1466
  writeXMLHeader(t);
1467 1468 1469 1470 1471
  t << "  <compounddef id=\"" 
    << nd->getOutputFileBase() << "\" kind=\"namespace\">" << endl;
  t << "    <compoundname>";
  writeXMLString(t,nd->name());
  t << "</compoundname>" << endl;
1472

1473 1474
  writeInnerClasses(nd->getClassSDict(),t);
  writeInnerNamespaces(nd->getNamespaceSDict(),t);
1475

1476
  if (nd->getMemberGroupSDict())
1477
  {
1478
    MemberGroupSDict::Iterator mgli(*nd->getMemberGroupSDict());
1479 1480 1481 1482 1483 1484
    MemberGroup *mg;
    for (;(mg=mgli.current());++mgli)
    {
      generateXMLSection(nd,ti,t,mg->members(),"user-defined",mg->header(),
          mg->documentation());
    }
1485
  }
1486

1487 1488 1489 1490
  QListIterator<MemberList> mli(nd->getMemberLists());
  MemberList *ml;
  for (mli.toFirst();(ml=mli.current());++mli)
  {
1491
    if ((ml->listType()&MemberListType_declarationLists)!=0)
1492 1493 1494 1495 1496
    {
      generateXMLSection(nd,ti,t,ml,g_xmlSectionMapper.find(ml->listType()));
    }
  }
#if 0
1497 1498 1499 1500 1501 1502
  generateXMLSection(nd,ti,t,&nd->decDefineMembers,"define");
  generateXMLSection(nd,ti,t,&nd->decProtoMembers,"prototype");
  generateXMLSection(nd,ti,t,&nd->decTypedefMembers,"typedef");
  generateXMLSection(nd,ti,t,&nd->decEnumMembers,"enum");
  generateXMLSection(nd,ti,t,&nd->decFuncMembers,"func");
  generateXMLSection(nd,ti,t,&nd->decVarMembers,"var");
1503
#endif
1504

1505
  t << "    <briefdescription>" << endl;
1506
  writeXMLDocBlock(t,nd->briefFile(),nd->briefLine(),nd,0,nd->briefDescription());
1507 1508
  t << "    </briefdescription>" << endl;
  t << "    <detaileddescription>" << endl;
1509
  writeXMLDocBlock(t,nd->docFile(),nd->docLine(),nd,0,nd->documentation());
1510
  t << "    </detaileddescription>" << endl;
1511 1512 1513 1514
  t << "    <location file=\""
    << nd->getDefFileName() << "\" line=\""
    << nd->getDefLine() << "\"" << " column=\""
    << nd->getDefColumn() << "\"/>" << endl ;
1515
  t << "  </compounddef>" << endl;
1516 1517 1518
  t << "</doxygen>" << endl;

  ti << "  </compound>" << endl;
1519 1520
}

1521
static void generateXMLForFile(FileDef *fd,FTextStream &ti)
1522
{
1523 1524 1525 1526
  // + includes files
  // + includedby files
  // + include graph
  // + included by graph
1527 1528 1529
  // + contained class definitions
  // + contained namespace definitions
  // + member groups
1530 1531 1532 1533 1534 1535 1536
  // + normal members
  // + brief desc
  // + detailed desc
  // + source code
  // + location
  // - number of lines
  
1537
  if (fd->isReference()) return; // skip external references
1538
  
1539 1540 1541
  ti << "  <compound refid=\"" << fd->getOutputFileBase() 
     << "\" kind=\"file\"><name>" << convertToXML(fd->name()) 
     << "</name>" << endl;
1542
  
1543 1544
  QCString outputDirectory = Config_getString("XML_OUTPUT");
  QCString fileName=outputDirectory+"/"+fd->getOutputFileBase()+".xml";
1545 1546 1547 1548 1549 1550
  QFile f(fileName);
  if (!f.open(IO_WriteOnly))
  {
    err("Cannot open file %s for writing!\n",fileName.data());
    return;
  }
1551 1552
  FTextStream t(&f);
  //t.setEncoding(FTextStream::UnicodeUTF8);
1553

1554
  writeXMLHeader(t);
1555 1556 1557 1558 1559
  t << "  <compounddef id=\"" 
    << fd->getOutputFileBase() << "\" kind=\"file\">" << endl;
  t << "    <compoundname>";
  writeXMLString(t,fd->name());
  t << "</compoundname>" << endl;
1560 1561

  IncludeInfo *inc;
1562 1563

  if (fd->includeFileList())
1564
  {
1565 1566
    QListIterator<IncludeInfo> ili1(*fd->includeFileList());
    for (ili1.toFirst();(inc=ili1.current());++ili1)
1567
    {
1568 1569 1570 1571 1572 1573 1574 1575
      t << "    <includes";
      if (inc->fileDef && !inc->fileDef->isReference()) // TODO: support external references
      {
        t << " refid=\"" << inc->fileDef->getOutputFileBase() << "\"";
      }
      t << " local=\"" << (inc->local ? "yes" : "no") << "\">";
      t << inc->includeName;
      t << "</includes>" << endl;
1576 1577 1578
    }
  }

1579
  if (fd->includedByFileList())
1580
  {
1581 1582
    QListIterator<IncludeInfo> ili2(*fd->includedByFileList());
    for (ili2.toFirst();(inc=ili2.current());++ili2)
1583
    {
1584 1585 1586 1587 1588 1589 1590 1591
      t << "    <includedby";
      if (inc->fileDef && !inc->fileDef->isReference()) // TODO: support external references
      {
        t << " refid=\"" << inc->fileDef->getOutputFileBase() << "\"";
      }
      t << " local=\"" << (inc->local ? "yes" : "no") << "\">";
      t << inc->includeName;
      t << "</includedby>" << endl;
1592 1593 1594
    }
  }

1595
  DotInclDepGraph incDepGraph(fd,FALSE);
1596 1597 1598 1599 1600 1601 1602
  if (!incDepGraph.isTrivial())
  {
    t << "    <incdepgraph>" << endl;
    incDepGraph.writeXML(t);
    t << "    </incdepgraph>" << endl;
  }

1603
  DotInclDepGraph invIncDepGraph(fd,TRUE);
1604 1605 1606 1607 1608 1609 1610
  if (!invIncDepGraph.isTrivial())
  {
    t << "    <invincdepgraph>" << endl;
    invIncDepGraph.writeXML(t);
    t << "    </invincdepgraph>" << endl;
  }

1611
  if (fd->getClassSDict())
1612
  {
1613
    writeInnerClasses(fd->getClassSDict(),t);
1614
  }
1615
  if (fd->getNamespaceSDict())
1616
  {
1617
    writeInnerNamespaces(fd->getNamespaceSDict(),t);
1618
  }
1619

1620
  if (fd->getMemberGroupSDict())
1621
  {
1622
    MemberGroupSDict::Iterator mgli(*fd->getMemberGroupSDict());
1623 1624 1625 1626 1627 1628
    MemberGroup *mg;
    for (;(mg=mgli.current());++mgli)
    {
      generateXMLSection(fd,ti,t,mg->members(),"user-defined",mg->header(),
          mg->documentation());
    }
1629
  }
1630

1631 1632 1633 1634
  QListIterator<MemberList> mli(fd->getMemberLists());
  MemberList *ml;
  for (mli.toFirst();(ml=mli.current());++mli)
  {
1635
    if ((ml->listType()&MemberListType_declarationLists)!=0)
1636 1637 1638 1639 1640
    {
      generateXMLSection(fd,ti,t,ml,g_xmlSectionMapper.find(ml->listType()));
    }
  }
#if 0
1641 1642 1643 1644 1645 1646
  generateXMLSection(fd,ti,t,fd->decDefineMembers,"define");
  generateXMLSection(fd,ti,t,fd->decProtoMembers,"prototype");
  generateXMLSection(fd,ti,t,fd->decTypedefMembers,"typedef");
  generateXMLSection(fd,ti,t,fd->decEnumMembers,"enum");
  generateXMLSection(fd,ti,t,fd->decFuncMembers,"func");
  generateXMLSection(fd,ti,t,fd->decVarMembers,"var");
1647
#endif
1648

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1649
  t << "    <briefdescription>" << endl;
1650
  writeXMLDocBlock(t,fd->briefFile(),fd->briefLine(),fd,0,fd->briefDescription());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1651 1652
  t << "    </briefdescription>" << endl;
  t << "    <detaileddescription>" << endl;
1653
  writeXMLDocBlock(t,fd->docFile(),fd->docLine(),fd,0,fd->documentation());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1654
  t << "    </detaileddescription>" << endl;
1655 1656 1657 1658 1659 1660
  if (Config_getBool("XML_PROGRAMLISTING"))
  {
    t << "    <programlisting>" << endl;
    writeXMLCodeBlock(t,fd);
    t << "    </programlisting>" << endl;
  }
1661
  t << "    <location file=\"" << fd->getDefFileName() << "\"/>" << endl;
1662
  t << "  </compounddef>" << endl;
1663 1664 1665
  t << "</doxygen>" << endl;

  ti << "  </compound>" << endl;
1666 1667
}

1668
static void generateXMLForGroup(GroupDef *gd,FTextStream &ti)
1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681
{
  // + members
  // + member groups
  // + files
  // + classes
  // + namespaces
  // - packages
  // + pages
  // + child groups
  // - examples
  // + brief description
  // + detailed description

1682 1683
  if (gd->isReference()) return; // skip external references

1684 1685
  ti << "  <compound refid=\"" << gd->getOutputFileBase() 
     << "\" kind=\"group\"><name>" << convertToXML(gd->name()) << "</name>" << endl;
1686
  
1687 1688
  QCString outputDirectory = Config_getString("XML_OUTPUT");
  QCString fileName=outputDirectory+"/"+gd->getOutputFileBase()+".xml";
1689 1690 1691 1692 1693 1694 1695
  QFile f(fileName);
  if (!f.open(IO_WriteOnly))
  {
    err("Cannot open file %s for writing!\n",fileName.data());
    return;
  }

1696 1697
  FTextStream t(&f);
  //t.setEncoding(FTextStream::UnicodeUTF8);
1698
  writeXMLHeader(t);
1699 1700
  t << "  <compounddef id=\"" 
    << gd->getOutputFileBase() << "\" kind=\"group\">" << endl;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1701
  t << "    <compoundname>" << convertToXML(gd->name()) << "</compoundname>" << endl;
1702 1703
  t << "    <title>" << convertToXML(gd->groupTitle()) << "</title>" << endl;

1704 1705 1706 1707 1708
  writeInnerFiles(gd->getFiles(),t);
  writeInnerClasses(gd->getClasses(),t);
  writeInnerNamespaces(gd->getNamespaces(),t);
  writeInnerPages(gd->getPages(),t);
  writeInnerGroups(gd->getSubGroups(),t);
1709

1710
  if (gd->getMemberGroupSDict())
1711
  {
1712
    MemberGroupSDict::Iterator mgli(*gd->getMemberGroupSDict());
1713 1714 1715 1716 1717 1718
    MemberGroup *mg;
    for (;(mg=mgli.current());++mgli)
    {
      generateXMLSection(gd,ti,t,mg->members(),"user-defined",mg->header(),
          mg->documentation());
    }
1719 1720
  }

1721 1722 1723 1724
  QListIterator<MemberList> mli(gd->getMemberLists());
  MemberList *ml;
  for (mli.toFirst();(ml=mli.current());++mli)
  {
1725
    if ((ml->listType()&MemberListType_declarationLists)!=0)
1726 1727 1728 1729 1730
    {
      generateXMLSection(gd,ti,t,ml,g_xmlSectionMapper.find(ml->listType()));
    }
  }
#if 0
1731 1732 1733 1734 1735 1736
  generateXMLSection(gd,ti,t,&gd->decDefineMembers,"define");
  generateXMLSection(gd,ti,t,&gd->decProtoMembers,"prototype");
  generateXMLSection(gd,ti,t,&gd->decTypedefMembers,"typedef");
  generateXMLSection(gd,ti,t,&gd->decEnumMembers,"enum");
  generateXMLSection(gd,ti,t,&gd->decFuncMembers,"func");
  generateXMLSection(gd,ti,t,&gd->decVarMembers,"var");
1737
#endif
1738 1739

  t << "    <briefdescription>" << endl;
1740
  writeXMLDocBlock(t,gd->briefFile(),gd->briefLine(),gd,0,gd->briefDescription());
1741 1742
  t << "    </briefdescription>" << endl;
  t << "    <detaileddescription>" << endl;
1743
  writeXMLDocBlock(t,gd->docFile(),gd->docLine(),gd,0,gd->documentation());
1744 1745
  t << "    </detaileddescription>" << endl;
  t << "  </compounddef>" << endl;
1746 1747 1748
  t << "</doxygen>" << endl;

  ti << "  </compound>" << endl;
1749 1750
}

1751
static void generateXMLForDir(DirDef *dd,FTextStream &ti)
1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766
{
  if (dd->isReference()) return; // skip external references
  ti << "  <compound refid=\"" << dd->getOutputFileBase() 
     << "\" kind=\"dir\"><name>" << convertToXML(dd->displayName()) 
     << "</name>" << endl;

  QCString outputDirectory = Config_getString("XML_OUTPUT");
  QCString fileName=outputDirectory+"/"+dd->getOutputFileBase()+".xml";
  QFile f(fileName);
  if (!f.open(IO_WriteOnly))
  {
    err("Cannot open file %s for writing!\n",fileName.data());
    return;
  }

1767 1768
  FTextStream t(&f);
  //t.setEncoding(FTextStream::UnicodeUTF8);
1769 1770 1771 1772 1773
  writeXMLHeader(t);
  t << "  <compounddef id=\"" 
    << dd->getOutputFileBase() << "\" kind=\"dir\">" << endl;
  t << "    <compoundname>" << convertToXML(dd->displayName()) << "</compoundname>" << endl;

1774 1775 1776
  writeInnerDirs(&dd->subDirs(),t);
  writeInnerFiles(dd->getFiles(),t);

1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789
  t << "    <briefdescription>" << endl;
  writeXMLDocBlock(t,dd->briefFile(),dd->briefLine(),dd,0,dd->briefDescription());
  t << "    </briefdescription>" << endl;
  t << "    <detaileddescription>" << endl;
  writeXMLDocBlock(t,dd->docFile(),dd->docLine(),dd,0,dd->documentation());
  t << "    </detaileddescription>" << endl;
  t << "    <location file=\"" << dd->name() << "\"/>" << endl; 
  t << "  </compounddef>" << endl;
  t << "</doxygen>" << endl;

  ti << "  </compound>" << endl;
}

1790
static void generateXMLForPage(PageDef *pd,FTextStream &ti,bool isExample)
1791 1792 1793 1794 1795
{
  // + name
  // + title
  // + documentation

1796 1797
  const char *kindName = isExample ? "example" : "page";

1798
  if (pd->isReference()) return;
1799
  
1800
  QCString pageName = pd->getOutputFileBase();
1801 1802 1803 1804
  if (pd->getGroupDef())
  {
    pageName+=(QCString)"_"+pd->name();
  }
1805 1806 1807
  if (pageName=="index") pageName="indexpage"; // to prevent overwriting the generated index page.
  
  ti << "  <compound refid=\"" << pageName
1808
     << "\" kind=\"" << kindName << "\"><name>" << convertToXML(pd->name()) 
1809
     << "</name>" << endl;
1810
  
1811 1812
  QCString outputDirectory = Config_getString("XML_OUTPUT");
  QCString fileName=outputDirectory+"/"+pageName+".xml";
1813 1814 1815 1816 1817 1818 1819
  QFile f(fileName);
  if (!f.open(IO_WriteOnly))
  {
    err("Cannot open file %s for writing!\n",fileName.data());
    return;
  }

1820 1821
  FTextStream t(&f);
  //t.setEncoding(FTextStream::UnicodeUTF8);
1822
  writeXMLHeader(t);
1823
  t << "  <compounddef id=\"" << pageName;
1824
  t << "\" kind=\"" << kindName << "\">" << endl;
1825 1826
  t << "    <compoundname>" << convertToXML(pd->name()) 
    << "</compoundname>" << endl;
1827

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1828
  if (pd==Doxygen::mainPage) // main page is special
1829
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1830 1831 1832
    QCString title;
    if (!pd->title().isEmpty() && pd->title().lower()!="notitle")
    {
1833
      title = filterTitle(convertCharEntitiesToUTF8(Doxygen::mainPage->title()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1834 1835 1836 1837 1838
    }
    else 
    {
      title = Config_getString("PROJECT_NAME");
    }
1839 1840
    t << "    <title>" << convertToXML(convertCharEntitiesToUTF8(title)) 
      << "</title>" << endl;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1841 1842 1843 1844 1845 1846
  }
  else
  {
    SectionInfo *si = Doxygen::sectionDict->find(pd->name());
    if (si)
    {
1847 1848
      t << "    <title>" << convertToXML(convertCharEntitiesToUTF8(si->title)) 
        << "</title>" << endl;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1849
    }
1850
  }
1851
  writeInnerPages(pd->getSubPages(),t);
1852
  t << "    <detaileddescription>" << endl;
1853 1854 1855 1856 1857 1858 1859 1860 1861 1862
  if (isExample)
  {
    writeXMLDocBlock(t,pd->docFile(),pd->docLine(),pd,0,
        pd->documentation()+"\n\\include "+pd->name());
  }
  else
  {
    writeXMLDocBlock(t,pd->docFile(),pd->docLine(),pd,0,
        pd->documentation());
  }
1863
  t << "    </detaileddescription>" << endl;
1864

1865
  t << "  </compounddef>" << endl;
1866 1867 1868
  t << "</doxygen>" << endl;

  ti << "  </compound>" << endl;
1869
}
1870 1871 1872

void generateXML()
{
1873 1874 1875
  // + classes
  // + namespaces
  // + files
1876 1877 1878
  // + groups
  // + related pages
  // - examples
1879
  
1880 1881
  QCString outputDirectory = Config_getString("XML_OUTPUT");
  QDir xmlDir(outputDirectory);
1882
  createSubDirs(xmlDir);
1883
  QCString fileName=outputDirectory+"/index.xsd";
1884 1885 1886 1887 1888 1889
  QFile f(fileName);
  if (!f.open(IO_WriteOnly))
  {
    err("Cannot open file %s for writing!\n",fileName.data());
    return;
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1890
  f.writeBlock(index_xsd,qstrlen(index_xsd));
1891 1892
  f.close();

1893 1894 1895 1896 1897 1898 1899
  fileName=outputDirectory+"/compound.xsd";
  f.setName(fileName);
  if (!f.open(IO_WriteOnly))
  {
    err("Cannot open file %s for writing!\n",fileName.data());
    return;
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1900
  f.writeBlock(compound_xsd,qstrlen(compound_xsd));
1901 1902
  f.close();

1903 1904 1905 1906 1907 1908 1909
  fileName=outputDirectory+"/index.xml";
  f.setName(fileName);
  if (!f.open(IO_WriteOnly))
  {
    err("Cannot open file %s for writing!\n",fileName.data());
    return;
  }
1910 1911
  FTextStream t(&f);
  //t.setEncoding(FTextStream::UnicodeUTF8);
1912 1913

  // write index header
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1914
  t << "<?xml version='1.0' encoding='UTF-8' standalone='no'?>" << endl;;
1915
  t << "<doxygenindex xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
1916 1917 1918
  t << "xsi:noNamespaceSchemaLocation=\"index.xsd\" ";
  t << "version=\"" << versionString << "\">" << endl;

1919
  {
1920
    ClassSDict::Iterator cli(*Doxygen::classSDict);
1921 1922 1923 1924 1925 1926
    ClassDef *cd;
    for (cli.toFirst();(cd=cli.current());++cli)
    {
      generateXMLForClass(cd,t);
    }
  }
1927 1928 1929 1930 1931 1932 1933 1934 1935
  //{
  //  ClassSDict::Iterator cli(Doxygen::hiddenClasses);
  //  ClassDef *cd;
  //  for (cli.toFirst();(cd=cli.current());++cli)
  //  {
  //    msg("Generating XML output for class %s\n",cd->name().data());
  //    generateXMLForClass(cd,t);
  //  }
  //}
1936
  NamespaceSDict::Iterator nli(*Doxygen::namespaceSDict);
1937 1938 1939
  NamespaceDef *nd;
  for (nli.toFirst();(nd=nli.current());++nli)
  {
1940
    msg("Generating XML output for namespace %s\n",nd->name().data());
1941 1942
    generateXMLForNamespace(nd,t);
  }
1943
  FileNameListIterator fnli(*Doxygen::inputNameList);
1944 1945 1946 1947 1948 1949
  FileName *fn;
  for (;(fn=fnli.current());++fnli)
  {
    FileNameIterator fni(*fn);
    FileDef *fd;
    for (;(fd=fni.current());++fni)
1950
    {
1951
      msg("Generating XML output for file %s\n",fd->name().data());
1952
      generateXMLForFile(fd,t);
1953
    }
1954
  }
1955
  GroupSDict::Iterator gli(*Doxygen::groupSDict);
1956 1957 1958
  GroupDef *gd;
  for (;(gd=gli.current());++gli)
  {
1959
    msg("Generating XML output for group %s\n",gd->name().data());
1960 1961 1962
    generateXMLForGroup(gd,t);
  }
  {
1963 1964 1965 1966 1967 1968 1969 1970
    PageSDict::Iterator pdi(*Doxygen::pageSDict);
    PageDef *pd=0;
    for (pdi.toFirst();(pd=pdi.current());++pdi)
    {
      msg("Generating XML output for page %s\n",pd->name().data());
      generateXMLForPage(pd,t,FALSE);
    }
  }
1971 1972
  {
    DirDef *dir;
1973
    DirSDict::Iterator sdi(*Doxygen::directories);
1974 1975 1976 1977 1978 1979
    for (sdi.toFirst();(dir=sdi.current());++sdi)
    {
      msg("Generate XML output for dir %s\n",dir->name().data());
      generateXMLForDir(dir,t);
    }
  }
1980 1981 1982 1983 1984 1985 1986 1987
  {
    PageSDict::Iterator pdi(*Doxygen::exampleSDict);
    PageDef *pd=0;
    for (pdi.toFirst();(pd=pdi.current());++pdi)
    {
      msg("Generating XML output for example %s\n",pd->name().data());
      generateXMLForPage(pd,t,TRUE);
    }
1988
  }
1989 1990
  if (Doxygen::mainPage)
  {
1991
    msg("Generating XML output for the main page\n");
1992
    generateXMLForPage(Doxygen::mainPage,t,FALSE);
1993
  }
1994 1995

  //t << "  </compoundlist>" << endl;
1996
  t << "</doxygenindex>" << endl;
1997 1998

  writeCombineScript();
1999 2000 2001
}