filedef.cpp 54.6 KB
Newer Older
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1 2
/******************************************************************************
 *
3
 * 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
4
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
5
 * Copyright (C) 1997-2014 by Dimitri van Heesch.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
6 7 8 9 10 11 12
 *
 * 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.
 *
Dimitri van Heesch's avatar
Dimitri van Heesch committed
13 14
 * Documents produced by Doxygen are derivative works derived from the
 * input used in their production; they are not affected by this license.
Dimitri van Heesch's avatar
Dimitri van Heesch committed
15 16 17 18 19 20 21 22 23 24 25 26
 *
 */

#include "memberlist.h"
#include "classlist.h"
#include "filedef.h"
#include "doxygen.h"
#include "memberdef.h"
#include "classdef.h"
#include "namespacedef.h"
#include "util.h"
#include "language.h"
27
#include "outputlist.h"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
28 29
#include "dot.h"
#include "message.h"
30
#include "docparser.h"
Dimitri van Heesch's avatar
Dimitri van Heesch committed
31
#include "searchindex.h"
32
#include "htags.h"
33
#include "parserintf.h"
34
#include "portable.h"
35
#include "vhdldocgen.h"
36
#include "debug.h"
37
#include "layout.h"
38
#include "entry.h"
39 40 41 42 43
#include "groupdef.h"
#include "filename.h"
#include "membergroup.h"
#include "dirdef.h"
#include "config.h"
44 45
#include "clangparser.h"
#include "settings.h"
46 47

//---------------------------------------------------------------------------
48

Dimitri van Heesch's avatar
Dimitri van Heesch committed
49
/** Class implementing CodeOutputInterface by throwing away everything. */
50
class DevNullCodeDocInterface : public CodeOutputInterface
51 52 53
{
  public:
    virtual void codify(const char *) {}
54 55 56
    virtual void writeCodeLink(const char *,const char *,
                               const char *,const char *,
                               const char *) {}
57 58 59
    virtual void writeTooltip(const char *, const DocLinkInfo &, const char *,
                              const char *, const SourceLinkInfo &, const SourceLinkInfo &
                             ) {}
60 61
    virtual void writeLineNumber(const char *,const char *,
                                 const char *,int) {}
Dimitri van Heesch's avatar
Dimitri van Heesch committed
62
    virtual void startCodeLine(bool) {}
63 64 65 66
    virtual void endCodeLine() {}
    virtual void startFontClass(const char *) {}
    virtual void endFontClass() {}
    virtual void writeCodeAnchor(const char *) {}
67
    virtual void linkableSymbol(int, const char *,Definition *,Definition *) {}
Dimitri van Heesch's avatar
Dimitri van Heesch committed
68 69
    virtual void setCurrentDoc(Definition *,const char *,bool) {}
    virtual void addWord(const char *,bool) {}
70 71
};

72 73
//---------------------------------------------------------------------------

Dimitri van Heesch's avatar
Dimitri van Heesch committed
74
/*! create a new file definition, where \a p is the file path, 
75
    \a nm the file name, and \a lref is an HTML anchor name if the
Dimitri van Heesch's avatar
Dimitri van Heesch committed
76 77
    file was read from a tag file or 0 otherwise
*/
78 79
FileDef::FileDef(const char *p,const char *nm,
                 const char *lref,const char *dn)
80
   : Definition((QCString)p+nm,1,1,nm)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
81
{
82 83 84 85 86
  m_path=p;
  m_filePath=m_path+nm;
  m_fileName=nm;
  m_diskName=dn;
  if (m_diskName.isEmpty()) m_diskName=nm;
87
  setReference(lref);
88 89 90 91 92 93 94 95 96 97 98 99 100 101
  m_classSDict        = 0;
  m_includeList       = 0;
  m_includeDict       = 0; 
  m_includedByList    = 0;
  m_includedByDict    = 0; 
  m_namespaceSDict    = 0; 
  m_srcDefDict        = 0;
  m_srcMemberDict     = 0;
  m_usingDirList      = 0;
  m_usingDeclList     = 0;
  m_package           = 0;
  m_isSource          = guessSection(nm)==Entry::SOURCE_SEC; 
  m_docname           = nm;
  m_dir               = 0;
102
  if (Config_getBool("FULL_PATH_NAMES"))
Dimitri van Heesch's avatar
Dimitri van Heesch committed
103
  {
104
    m_docname.prepend(stripFromPath(m_path.copy()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
105
  }
106 107
  setLanguage(getLanguageFromFileName(name()));
  m_memberGroupSDict = 0;
108
  acquireFileVersion();
109
  m_subGrouping=Config_getBool("SUBGROUPING");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
110 111 112 113 114
}

/*! destroy the file definition */
FileDef::~FileDef()
{
115 116 117 118 119 120 121 122 123 124 125
  delete m_classSDict;
  delete m_includeDict;
  delete m_includeList;
  delete m_includedByDict;
  delete m_includedByList;
  delete m_namespaceSDict;
  delete m_srcDefDict;
  delete m_srcMemberDict;
  delete m_usingDirList;
  delete m_usingDeclList;
  delete m_memberGroupSDict;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
126 127 128 129 130
}

/*! Compute the HTML anchor names for all members in the class */ 
void FileDef::computeAnchors()
{
131 132
  MemberList *ml = getMemberList(MemberListType_allMembersList);
  if (ml) setAnchors(ml);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
133 134
}

135 136
void FileDef::distributeMemberGroupDocumentation()
{
137
  //printf("FileDef::distributeMemberGroupDocumentation()\n");
138
  if (m_memberGroupSDict)
139
  {
140
    MemberGroupSDict::Iterator mgli(*m_memberGroupSDict);
141 142 143 144 145
    MemberGroup *mg;
    for (;(mg=mgli.current());++mgli)
    {
      mg->distributeMemberGroupDocumentation();
    }
146 147 148
  }
}

149 150
void FileDef::findSectionsInDocumentation()
{
151
  docFindSections(documentation(),this,0,docFile());
152
  if (m_memberGroupSDict)
153
  {
154
    MemberGroupSDict::Iterator mgli(*m_memberGroupSDict);
155 156 157 158 159 160
    MemberGroup *mg;
    for (;(mg=mgli.current());++mgli)
    {
      mg->findSectionsInDocumentation();
    }
  }
161 162 163 164 165

  QListIterator<MemberList> mli(m_memberLists);
  MemberList *ml;
  for (mli.toFirst();(ml=mli.current());++mli)
  {
166
    if (ml->listType()&MemberListType_declarationLists)
167 168 169 170
    {
      ml->findSectionsInDocumentation();
    }
  }
171 172
}

173 174
bool FileDef::hasDetailedDescription() const
{
175
  static bool repeatBrief = Config_getBool("REPEAT_BRIEF");
176
  static bool sourceBrowser = Config_getBool("SOURCE_BROWSER");
177
  return ((!briefDescription().isEmpty() && repeatBrief) || 
178 179 180 181 182
          !documentation().stripWhiteSpace().isEmpty() || // avail empty section
          (sourceBrowser && getStartBodyLine()!=-1 && getBodyDef())
         );
}

183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 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 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288
void FileDef::writeTagFile(FTextStream &tagFile)
{
  tagFile << "  <compound kind=\"file\">" << endl;
  tagFile << "    <name>" << convertToXML(name()) << "</name>" << endl;
  tagFile << "    <path>" << convertToXML(getPath()) << "</path>" << endl;
  tagFile << "    <filename>" << convertToXML(getOutputFileBase()) << "</filename>" << endl;
  if (m_includeList && m_includeList->count()>0)
  {
    QListIterator<IncludeInfo> ili(*m_includeList);
    IncludeInfo *ii;
    for (;(ii=ili.current());++ili)
    {
      if (!ii->indirect)
      {
        FileDef *fd=ii->fileDef;
        if (fd && fd->isLinkable() && !fd->isReference()) 
        {
          bool isIDLorJava = FALSE;
          SrcLangExt lang = fd->getLanguage();
          isIDLorJava = lang==SrcLangExt_IDL || lang==SrcLangExt_Java;
          const char *locStr = (ii->local    || isIDLorJava) ? "yes" : "no";
          const char *impStr = (ii->imported || isIDLorJava) ? "yes" : "no";
          tagFile << "    <includes id=\"" 
                  << convertToXML(fd->getOutputFileBase()) << "\" "
                  << "name=\"" << convertToXML(fd->name()) << "\" "
                  << "local=\"" << locStr << "\" "
                  << "imported=\"" << impStr << "\">"
                  << convertToXML(ii->includeName)
                  << "</includes>" 
                  << endl;
        }
      }
    }
  }
  QListIterator<LayoutDocEntry> eli(
      LayoutDocManager::instance().docEntries(LayoutDocManager::File));
  LayoutDocEntry *lde;
  for (eli.toFirst();(lde=eli.current());++eli)
  {
    switch (lde->kind())
    {
      case LayoutDocEntry::FileClasses:
        {
          if (m_classSDict)
          {
            SDict<ClassDef>::Iterator ci(*m_classSDict);
            ClassDef *cd;
            for (ci.toFirst();(cd=ci.current());++ci)
            {
              if (cd->isLinkableInProject())
              {
                tagFile << "    <class kind=\"" << cd->compoundTypeString() <<
                  "\">" << convertToXML(cd->name()) << "</class>" << endl;
              }
            }
          }
        }
        break;
      case LayoutDocEntry::FileNamespaces:
        {
          if (m_namespaceSDict)
          {
            SDict<NamespaceDef>::Iterator ni(*m_namespaceSDict);
            NamespaceDef *nd;
            for (ni.toFirst();(nd=ni.current());++ni)
            {
              if (nd->isLinkableInProject())
              {
                tagFile << "    <namespace>" << convertToXML(nd->name()) << "</namespace>" << endl;
              }
            }
          }
        }
        break;
      case LayoutDocEntry::MemberDecl:
        {
          LayoutDocEntryMemberDecl *lmd = (LayoutDocEntryMemberDecl*)lde;
          MemberList * ml = getMemberList(lmd->type);
          if (ml)
          {
            ml->writeTagFile(tagFile);
          }
        }
        break;
      case LayoutDocEntry::MemberGroups:
        {
          if (m_memberGroupSDict)
          {
            MemberGroupSDict::Iterator mgli(*m_memberGroupSDict);
            MemberGroup *mg;
            for (;(mg=mgli.current());++mgli)
            {
              mg->writeTagFile(tagFile);
            }
          }
        }
        break;
      default:
        break;
    }
  }

  writeDocAnchorsToTagFile(tagFile);
  tagFile << "  </compound>" << endl;
}

289
void FileDef::writeDetailedDescription(OutputList &ol,const QCString &title)
290
{
291
  if (hasDetailedDescription())
292 293
  {
    ol.pushGeneratorState();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
294 295 296 297 298
      ol.disable(OutputGenerator::Html);
      ol.writeRuler();
    ol.popGeneratorState();
    ol.pushGeneratorState();
      ol.disableAllBut(OutputGenerator::Html);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
299
      ol.writeAnchor(0,"details"); 
300 301
    ol.popGeneratorState();
    ol.startGroupHeader();
302
    ol.parseText(title);
303
    ol.endGroupHeader();
304

305
    ol.startTextBlock();
306 307
    if (!briefDescription().isEmpty() && Config_getBool("REPEAT_BRIEF"))
    {
308
      ol.generateDoc(briefFile(),briefLine(),this,0,briefDescription(),FALSE,FALSE);
309 310 311 312
    }
    if (!briefDescription().isEmpty() && Config_getBool("REPEAT_BRIEF") && 
        !documentation().isEmpty())
    {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
313 314
      ol.pushGeneratorState();
        ol.disable(OutputGenerator::Man);
315
        ol.disable(OutputGenerator::RTF);
316
        // ol.newParagraph(); // FIXME:PARA
Dimitri van Heesch's avatar
Dimitri van Heesch committed
317 318
        ol.enableAll();
        ol.disableAllBut(OutputGenerator::Man);
319
        ol.enable(OutputGenerator::Latex);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
320 321
        ol.writeString("\n\n");
      ol.popGeneratorState();
322 323 324
    }
    if (!documentation().isEmpty())
    {
325
      ol.generateDoc(docFile(),docLine(),this,0,documentation()+"\n",TRUE,FALSE);
326 327 328 329
    }
    //printf("Writing source ref for file %s\n",name().data());
    if (Config_getBool("SOURCE_BROWSER")) 
    {
330 331 332 333 334 335 336
      //if Latex enabled and LATEX_SOURCE_CODE isn't -> skip, bug_738548
      ol.pushGeneratorState();
      if (ol.isEnabled(OutputGenerator::Latex) && !Config_getBool("LATEX_SOURCE_CODE"))
      { 
        ol.disable(OutputGenerator::Latex);
      }

337
      ol.startParagraph();
338 339 340 341
      QCString refText = theTranslator->trDefinedInSourceFile();
      int fileMarkerPos = refText.find("@0");
      if (fileMarkerPos!=-1) // should always pass this.
      {
342
        ol.parseText(refText.left(fileMarkerPos)); //text left from marker 1
343 344
        ol.writeObjectLink(0,getSourceFileBase(),
            0,name());
345
        ol.parseText(refText.right(
346 347
              refText.length()-fileMarkerPos-2)); // text right from marker 2
      }
348
      ol.endParagraph();
349 350
      //Restore settings, bug_738548
      ol.popGeneratorState();
351
    }
352
    ol.endTextBlock();
353 354 355
  }
}

356
void FileDef::writeBriefDescription(OutputList &ol)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
357
{
358
  if (!briefDescription().isEmpty() && Config_getBool("BRIEF_MEMBER_DESC"))
359
  {
360 361
    DocRoot *rootNode = validatingParseDoc(briefFile(),briefLine(),this,0,
                       briefDescription(),TRUE,FALSE,0,TRUE,FALSE);
362

363
    if (rootNode && !rootNode->isEmpty())
364
    {
365 366 367 368 369 370
      ol.startParagraph();
      ol.writeDoc(rootNode,this,0);
      ol.pushGeneratorState();
      ol.disable(OutputGenerator::RTF);
      ol.writeString(" \n");
      ol.enable(OutputGenerator::RTF);
371

372 373 374 375 376 377 378 379 380 381 382 383 384
      if (Config_getBool("REPEAT_BRIEF") ||
          !documentation().isEmpty()
         )
      {
        ol.disableAllBut(OutputGenerator::Html);
        ol.startTextLink(0,"details");
        ol.parseText(theTranslator->trMore());
        ol.endTextLink();
      }
      ol.popGeneratorState();
      ol.endParagraph();
    }
    delete rootNode;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
385 386
  }
  ol.writeSynopsis();
387 388 389 390
}

void FileDef::writeIncludeFiles(OutputList &ol)
{
391
  if (m_includeList && m_includeList->count()>0)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
392
  {
393
    ol.startTextBlock(TRUE);
394
    QListIterator<IncludeInfo> ili(*m_includeList);
395 396
    IncludeInfo *ii;
    for (;(ii=ili.current());++ili)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
397
    {
398
      if (!ii->indirect)
399
      {
400 401 402
        FileDef *fd=ii->fileDef;
        bool isIDLorJava = FALSE;
        if (fd)
403
        {
404 405
          SrcLangExt lang   = fd->getLanguage();
          isIDLorJava = lang==SrcLangExt_IDL || lang==SrcLangExt_Java;
406
        }
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424
        ol.startTypewriter();
        if (isIDLorJava) // IDL/Java include
        {
          ol.docify("import ");
        }
        else if (ii->imported) // Objective-C include
        {
          ol.docify("#import ");
        }
        else // C/C++ include
        {
          ol.docify("#include ");
        }
        if (ii->local || isIDLorJava)
          ol.docify("\"");
        else
          ol.docify("<");
        ol.disable(OutputGenerator::Html);
425
        ol.docify(ii->includeName);
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451
        ol.enableAll();
        ol.disableAllBut(OutputGenerator::Html);
        
        // Here we use the include file name as it appears in the file.
        // we could also we the name as it is used within doxygen,
        // then we should have used fd->docName() instead of ii->includeName
        if (fd && fd->isLinkable())
        {
          ol.writeObjectLink(fd->getReference(),
              fd->generateSourceFile() ? fd->includeName() : fd->getOutputFileBase(),
              0,ii->includeName);
        }
        else
        {
          ol.docify(ii->includeName);
        }
        
        ol.enableAll();
        if (ii->local || isIDLorJava)
          ol.docify("\"");
        else
          ol.docify(">");
        if (isIDLorJava) 
          ol.docify(";");
        ol.endTypewriter();
        ol.lineBreak();
452
      }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
453
    }
454
    ol.endTextBlock();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
455
  }
456 457 458 459 460
}

void FileDef::writeIncludeGraph(OutputList &ol)
{
  if (Config_getBool("HAVE_DOT") /*&& Config_getBool("INCLUDE_GRAPH")*/)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
461 462
  {
    //printf("Graph for file %s\n",name().data());
463
    DotInclDepGraph incDepGraph(this,FALSE);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
464 465
    if (incDepGraph.isTooBig())
    {
466
       warn_uncond("Include graph for '%s' not generated, too many nodes. Consider increasing DOT_GRAPH_MAX_NODES.\n",name().data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
467 468
    }
    else if (!incDepGraph.isTrivial())
Dimitri van Heesch's avatar
Dimitri van Heesch committed
469
    {
470
      ol.startTextBlock(); 
471
      ol.disable(OutputGenerator::Man);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
472
      ol.startInclDepGraph();
473
      ol.parseText(theTranslator->trInclDepGraph(name()));
Dimitri van Heesch's avatar
Dimitri van Heesch committed
474 475
      ol.endInclDepGraph(incDepGraph);
      ol.enableAll();
476
      ol.endTextBlock(TRUE);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
477
    }
478
    //incDepGraph.writeGraph(Config_getString("HTML_OUTPUT"),fd->getOutputFileBase());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
479
  }
480
}
Dimitri van Heesch's avatar
Dimitri van Heesch committed
481

482 483 484
void FileDef::writeIncludedByGraph(OutputList &ol)
{
  if (Config_getBool("HAVE_DOT") /*&& Config_getBool("INCLUDED_BY_GRAPH")*/)
485 486
  {
    //printf("Graph for file %s\n",name().data());
487
    DotInclDepGraph incDepGraph(this,TRUE);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
488 489
    if (incDepGraph.isTooBig())
    {
490
       warn_uncond("Included by graph for '%s' not generated, too many nodes. Consider increasing DOT_GRAPH_MAX_NODES.\n",name().data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
491
    }
492
    else if (!incDepGraph.isTrivial())
493
    {
494
      ol.startTextBlock(); 
495 496
      ol.disable(OutputGenerator::Man);
      ol.startInclDepGraph();
497
      ol.parseText(theTranslator->trInclByDepGraph());
498 499
      ol.endInclDepGraph(incDepGraph);
      ol.enableAll();
500
      ol.endTextBlock(TRUE);
501
    }
502
    //incDepGraph.writeGraph(Config_getString("HTML_OUTPUT"),fd->getOutputFileBase());
503
  }
504 505
}

506

507 508
void FileDef::writeSourceLink(OutputList &ol)
{
509
  //printf("%s: generateSourceFile()=%d\n",name().data(),generateSourceFile());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
510
  if (generateSourceFile())
Dimitri van Heesch's avatar
Dimitri van Heesch committed
511 512
  {
    ol.disableAllBut(OutputGenerator::Html);
513
    ol.startParagraph();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
514
    ol.startTextLink(includeName(),0);
515
    ol.parseText(theTranslator->trGotoSourceCode());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
516
    ol.endTextLink();
517
    ol.endParagraph();
Dimitri van Heesch's avatar
Dimitri van Heesch committed
518 519
    ol.enableAll();
  }
520 521
}

522 523
void FileDef::writeNamespaceDeclarations(OutputList &ol,const QCString &title,
            bool const isConstantGroup)
524 525
{
  // write list of namespaces
526
  if (m_namespaceSDict) m_namespaceSDict->writeDeclaration(ol,title,isConstantGroup);
527 528 529 530 531
}

void FileDef::writeClassDeclarations(OutputList &ol,const QCString &title)
{
  // write list of classes
532
  if (m_classSDict) m_classSDict->writeDeclaration(ol,0,title,FALSE);
533 534
}

535 536
void FileDef::writeInlineClasses(OutputList &ol)
{
537 538 539 540 541
  // temporarily undo the disbling could be done by startMemberDocumentation()
  // as a result of setting SEPARATE_MEMBER_PAGES to YES; see bug730512
  bool isEnabled = ol.isEnabled(OutputGenerator::Html);
  ol.enable(OutputGenerator::Html);

542
  if (m_classSDict) m_classSDict->writeDocumentation(ol,this);
543 544 545

  // restore the initial state if needed
  if (!isEnabled) ol.disable(OutputGenerator::Html);
546 547
}

548 549
void FileDef::startMemberDeclarations(OutputList &ol)
{
550
  ol.startMemberSections();
551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
}

void FileDef::endMemberDeclarations(OutputList &ol)
{
  ol.endMemberSections();
}

void FileDef::startMemberDocumentation(OutputList &ol)
{
  if (Config_getBool("SEPARATE_MEMBER_PAGES"))
  {
    ol.disable(OutputGenerator::Html);
    Doxygen::suppressDocWarnings = TRUE;
  }
}

void FileDef::endMemberDocumentation(OutputList &ol)
{
  if (Config_getBool("SEPARATE_MEMBER_PAGES"))
  {
    ol.enable(OutputGenerator::Html);
    Doxygen::suppressDocWarnings = FALSE;
  }
}
575

576 577 578
void FileDef::writeMemberGroups(OutputList &ol)
{
  /* write user defined member groups */
579
  if (m_memberGroupSDict)
580
  {
581 582
    m_memberGroupSDict->sort();
    MemberGroupSDict::Iterator mgli(*m_memberGroupSDict);
583 584
    MemberGroup *mg;
    for (;(mg=mgli.current());++mgli)
585
    {
586 587
      if ((!mg->allMembersInSameSection() || !m_subGrouping) 
          && mg->header()!="[NOHEADER]")
588
      {
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606
        mg->writeDeclarations(ol,0,0,this,0);
      }
    }
  }
}

void FileDef::writeAuthorSection(OutputList &ol)
{
  // write Author section (Man only)
  ol.pushGeneratorState();
  ol.disableAllBut(OutputGenerator::Man);
  ol.startGroupHeader();
  ol.parseText(theTranslator->trAuthor(TRUE,TRUE));
  ol.endGroupHeader();
  ol.parseText(theTranslator->trGeneratedAutomatically(Config_getString("PROJECT_NAME")));
  ol.popGeneratorState();
}

607 608 609 610 611 612 613 614
void FileDef::writeSummaryLinks(OutputList &ol)
{
  ol.pushGeneratorState();
  ol.disableAllBut(OutputGenerator::Html);
  QListIterator<LayoutDocEntry> eli(
      LayoutDocManager::instance().docEntries(LayoutDocManager::File));
  LayoutDocEntry *lde;
  bool first=TRUE;
615
  SrcLangExt lang=getLanguage();
616 617
  for (eli.toFirst();(lde=eli.current());++eli)
  {
618 619 620 621
    if ((lde->kind()==LayoutDocEntry::FileClasses && 
         m_classSDict && m_classSDict->declVisible()) || 
        (lde->kind()==LayoutDocEntry::FileNamespaces && 
         m_namespaceSDict && m_namespaceSDict->declVisible())
622 623 624 625
       )
    {
      LayoutDocEntrySection *ls = (LayoutDocEntrySection*)lde;
      QCString label = lde->kind()==LayoutDocEntry::FileClasses ? "nested-classes" : "namespaces";
626
      ol.writeSummaryLink(0,label,ls->title(lang),first);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
627
      first=FALSE;
628 629 630 631 632 633 634
    }
    else if (lde->kind()==LayoutDocEntry::MemberDecl)
    {
      LayoutDocEntryMemberDecl *lmd = (LayoutDocEntryMemberDecl*)lde;
      MemberList * ml = getMemberList(lmd->type);
      if (ml && ml->declVisible())
      {
635
        ol.writeSummaryLink(0,MemberList::listTypeAsString(ml->listType()),lmd->title(lang),first);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
636
        first=FALSE;
637 638 639 640 641 642 643 644 645 646
      }
    }
  }
  if (!first)
  {
    ol.writeString("  </div>\n");
  }
  ol.popGeneratorState();
}

647 648 649 650 651
/*! Write the documentation page for this file to the file of output
    generators \a ol. 
*/
void FileDef::writeDocumentation(OutputList &ol)
{
652
  static bool generateTreeView = Config_getBool("GENERATE_TREEVIEW");
653 654 655 656 657 658 659 660 661 662 663
  //funcList->countDecMembers();
  
  //QCString fn = name();
  //if (Config_getBool("FULL_PATH_NAMES"))
  //{
  //  fn.prepend(stripFromPath(getPath().copy()));
  //}

  //printf("WriteDocumentation diskname=%s\n",diskname.data());
  
  QCString versionTitle;
664
  if (!m_fileVersion.isEmpty())
665
  {
666
    versionTitle=("("+m_fileVersion+")");
667
  }
668 669
  QCString title = m_docname+versionTitle;
  QCString pageTitle=theTranslator->trFileReference(m_docname);
670

671
  if (getDirDef())
672
  {
673 674 675 676 677 678
    startFile(ol,getOutputFileBase(),name(),pageTitle,HLI_FileVisible,!generateTreeView);
    if (!generateTreeView)
    {
      getDirDef()->writeNavigationPath(ol);
      ol.endQuickIndices();
    }
679
    QCString pageTitleShort=theTranslator->trFileReference(name());
680
    startTitle(ol,getOutputFileBase(),this);
681 682 683 684 685
    ol.pushGeneratorState();
      ol.disableAllBut(OutputGenerator::Html);
      ol.parseText(pageTitleShort); // Html only
      ol.enableAll();
      ol.disable(OutputGenerator::Html);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
686
      ol.parseText(pageTitle); // other output formats
687 688 689 690 691 692
    ol.popGeneratorState();
    addGroupListToTitle(ol,this);
    endTitle(ol,getOutputFileBase(),title);
  }
  else
  {
693 694 695 696 697
    startFile(ol,getOutputFileBase(),name(),pageTitle,HLI_FileVisible,!generateTreeView);
    if (!generateTreeView)
    {
      ol.endQuickIndices();
    }
698
    startTitle(ol,getOutputFileBase(),this);
699 700 701 702
    ol.parseText(pageTitle);
    addGroupListToTitle(ol,this);
    endTitle(ol,getOutputFileBase(),title);
  }
703 704 705

  ol.startContents();

706
  if (!m_fileVersion.isEmpty())
707 708 709 710 711 712 713 714
  {
    ol.disableAllBut(OutputGenerator::Html);
    ol.startProjectNumber();
    ol.docify(versionTitle);
    ol.endProjectNumber();
    ol.enableAll();
  }
  
715 716
  if (Doxygen::searchIndex)
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
717
    Doxygen::searchIndex->setCurrentDoc(this,anchor(),FALSE);
718 719
    Doxygen::searchIndex->addWord(localName(),TRUE);
  }
720 721 722 723
  

  //---------------------------------------- start flexible part -------------------------------
  
724
  SrcLangExt lang = getLanguage();
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750
  QListIterator<LayoutDocEntry> eli(
      LayoutDocManager::instance().docEntries(LayoutDocManager::File));
  LayoutDocEntry *lde;
  for (eli.toFirst();(lde=eli.current());++eli)
  {
    switch (lde->kind())
    {
      case LayoutDocEntry::BriefDesc: 
        writeBriefDescription(ol);
        break; 
      case LayoutDocEntry::MemberDeclStart: 
        startMemberDeclarations(ol);
        break; 
      case LayoutDocEntry::FileIncludes:
        writeIncludeFiles(ol);
        break;
      case LayoutDocEntry::FileIncludeGraph:
        writeIncludeGraph(ol);
        break;
      case LayoutDocEntry::FileIncludedByGraph:
        writeIncludedByGraph(ol);
        break;
      case LayoutDocEntry::FileSourceLink:
        writeSourceLink(ol);
        break;
      case LayoutDocEntry::FileClasses: 
751
        {
752
          LayoutDocEntrySection *ls = (LayoutDocEntrySection*)lde;
753
          writeClassDeclarations(ol,ls->title(lang));
754
        }
755 756
        break; 
      case LayoutDocEntry::FileNamespaces: 
757
        {
758
          LayoutDocEntrySection *ls = (LayoutDocEntrySection*)lde;
759
          writeNamespaceDeclarations(ol,ls->title(lang),false);
760
        }
761
        break; 
762 763 764 765 766 767
      case LayoutDocEntry::FileConstantGroups:
        {
          LayoutDocEntrySection *ls = (LayoutDocEntrySection*)lde;
          writeNamespaceDeclarations(ol,ls->title(lang),true);
        }
        break;
768 769 770 771
      case LayoutDocEntry::MemberGroups: 
        writeMemberGroups(ol);
        break; 
      case LayoutDocEntry::MemberDecl: 
772
        {
773
          LayoutDocEntryMemberDecl *lmd = (LayoutDocEntryMemberDecl*)lde;
774
          writeMemberDeclarations(ol,lmd->type,lmd->title(lang));
775
        }
776 777 778 779 780
        break; 
      case LayoutDocEntry::MemberDeclEnd: 
        endMemberDeclarations(ol);
        break;
      case LayoutDocEntry::DetailedDesc: 
781
        {
782
          LayoutDocEntrySection *ls = (LayoutDocEntrySection*)lde;
783
          writeDetailedDescription(ol,ls->title(lang));
784
        }
785 786 787 788
        break;
      case LayoutDocEntry::MemberDefStart: 
        startMemberDocumentation(ol);
        break; 
789 790 791
      case LayoutDocEntry::FileInlineClasses:
        writeInlineClasses(ol);
        break;
792
      case LayoutDocEntry::MemberDef: 
793
        {
794
          LayoutDocEntryMemberDef *lmd = (LayoutDocEntryMemberDef*)lde;
795
          writeMemberDocumentation(ol,lmd->type,lmd->title(lang));
796
        }
797 798 799 800 801 802 803 804 805 806 807 808 809
        break;
      case LayoutDocEntry::MemberDefEnd: 
        endMemberDocumentation(ol);
        break;
      case LayoutDocEntry::AuthorSection: 
        writeAuthorSection(ol);
        break;
      case LayoutDocEntry::ClassIncludes:
      case LayoutDocEntry::ClassInheritanceGraph:
      case LayoutDocEntry::ClassNestedClasses:
      case LayoutDocEntry::ClassCollaborationGraph:
      case LayoutDocEntry::ClassAllMembersLink:
      case LayoutDocEntry::ClassUsedFiles:
810
      case LayoutDocEntry::ClassInlineClasses:
811
      case LayoutDocEntry::NamespaceNestedNamespaces:
812
      case LayoutDocEntry::NamespaceNestedConstantGroups:
813
      case LayoutDocEntry::NamespaceClasses:
814
      case LayoutDocEntry::NamespaceInlineClasses:
815
      case LayoutDocEntry::GroupClasses: 
Dimitri van Heesch's avatar
Dimitri van Heesch committed
816
      case LayoutDocEntry::GroupInlineClasses: 
817 818 819 820 821 822 823 824 825 826 827 828
      case LayoutDocEntry::GroupNamespaces:
      case LayoutDocEntry::GroupDirs: 
      case LayoutDocEntry::GroupNestedGroups: 
      case LayoutDocEntry::GroupFiles:
      case LayoutDocEntry::GroupGraph: 
      case LayoutDocEntry::GroupPageDocs:
      case LayoutDocEntry::DirSubDirs:
      case LayoutDocEntry::DirFiles:
      case LayoutDocEntry::DirGraph:
        err("Internal inconsistency: member %d should not be part of "
            "LayoutDocManager::File entry list\n",lde->kind());
        break;
829 830
    }
  }
831

832
  //---------------------------------------- end flexible part -------------------------------
833

834 835
  ol.endContents();

836
  endFileWithNavPath(this,ol);
837 838 839

  if (Config_getBool("SEPARATE_MEMBER_PAGES"))
  {
840
    MemberList *ml = getMemberList(MemberListType_allMembersList);
841
    if (ml) ml->sort();
842 843 844 845 846 847 848 849
    writeMemberPages(ol);
  }
}

void FileDef::writeMemberPages(OutputList &ol)
{
  ol.pushGeneratorState();
  ol.disableAllBut(OutputGenerator::Html);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
850
  
851 852 853 854
  QListIterator<MemberList> mli(m_memberLists);
  MemberList *ml;
  for (mli.toFirst();(ml=mli.current());++mli)
  {
855
    if (ml->listType()&MemberListType_documentationLists)
856 857 858 859
    {
      ml->writeDocumentationPage(ol,name(),this);
    }
  }
860

861 862 863 864 865
  ol.popGeneratorState();
}

void FileDef::writeQuickMemberLinks(OutputList &ol,MemberDef *currentMd) const
{
866 867
  static bool createSubDirs=Config_getBool("CREATE_SUBDIRS");

868 869 870
  ol.writeString("      <div class=\"navtab\">\n");
  ol.writeString("        <table>\n");

871
  MemberList *allMemberList = getMemberList(MemberListType_allMembersList);
872
  if (allMemberList)
873
  {
874 875 876
    MemberListIterator mli(*allMemberList);
    MemberDef *md;
    for (mli.toFirst();(md=mli.current());++mli)
877
    {
878
      if (md->getFileDef()==this && md->getNamespaceDef()==0 && md->isLinkable() && !md->isEnumValue())
879
      {
880 881
        ol.writeString("          <tr><td class=\"navtab\">");
        if (md->isLinkableInProject())
882
        {
883 884 885 886 887 888 889 890 891 892 893 894
          if (md==currentMd) // selected item => highlight
          {
            ol.writeString("<a class=\"qindexHL\" ");
          }
          else
          {
            ol.writeString("<a class=\"qindex\" ");
          }
          ol.writeString("href=\"");
          if (createSubDirs) ol.writeString("../../");
          ol.writeString(md->getOutputFileBase()+Doxygen::htmlFileExtension+"#"+md->anchor());
          ol.writeString("\">");
895
          ol.writeString(convertToHtml(md->localName()));
896
          ol.writeString("</a>");
897
        }
898
        ol.writeString("</td></tr>\n");
899 900
      }
    }
901 902
  }

903 904
  ol.writeString("        </table>\n");
  ol.writeString("      </div>\n");
Dimitri van Heesch's avatar
Dimitri van Heesch committed
905 906
}

907
/*! Write a source listing of this file to the output */
908
void FileDef::writeSource(OutputList &ol,bool sameTu,QStrList &filesInSameTu)
909
{
910
  static bool generateTreeView  = Config_getBool("GENERATE_TREEVIEW");
911
  static bool filterSourceFiles = Config_getBool("FILTER_SOURCE_FILES");
912
  static bool latexSourceCode   = Config_getBool("LATEX_SOURCE_CODE");
913
  DevNullCodeDocInterface devNullIntf;
914 915
  QCString title = m_docname;
  if (!m_fileVersion.isEmpty())
916
  {
917
    title+=(" ("+m_fileVersion+")");
918 919
  }
  QCString pageTitle = theTranslator->trSourceFile(title);
920 921 922
  ol.disable(OutputGenerator::Man);
  ol.disable(OutputGenerator::RTF);
  if (!latexSourceCode) ol.disable(OutputGenerator::Latex);
923

Dimitri van Heesch's avatar
Dimitri van Heesch committed
924 925
  bool isDocFile = isDocumentationFile();
  bool genSourceFile = !isDocFile && generateSourceFile();
926
  if (getDirDef())
927
  {
928
    startFile(ol,getSourceFileBase(),0,pageTitle,HLI_FileVisible,
Dimitri van Heesch's avatar
Dimitri van Heesch committed
929
        !generateTreeView,
930
        !isDocFile && genSourceFile ? QCString() : getOutputFileBase());
931 932 933 934 935
    if (!generateTreeView)
    {
      getDirDef()->writeNavigationPath(ol);
      ol.endQuickIndices();
    }
936
    startTitle(ol,getSourceFileBase());
937
    ol.parseText(name());
938
    endTitle(ol,getSourceFileBase(),title);
939 940 941
  }
  else
  {
Dimitri van Heesch's avatar
Dimitri van Heesch committed
942
    startFile(ol,getSourceFileBase(),0,pageTitle,HLI_FileVisible,FALSE,
943
        !isDocFile && genSourceFile ? QCString() : getOutputFileBase());
944
    startTitle(ol,getSourceFileBase());
945
    ol.parseText(title);
946
    endTitle(ol,getSourceFileBase(),0);
947
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
948

949 950
  ol.startContents();

Dimitri van Heesch's avatar
Dimitri van Heesch committed
951 952
  if (isLinkable())
  {
953
    if (latexSourceCode) ol.disable(OutputGenerator::Latex);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
954
    ol.startTextLink(getOutputFileBase(),0);
955
    ol.parseText(theTranslator->trGotoDocumentation());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
956
    ol.endTextLink();
957
    if (latexSourceCode) ol.enable(OutputGenerator::Latex);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
958 959
  }

960 961
  (void)sameTu;
  (void)filesInSameTu;
962 963 964 965 966 967
#if USE_LIBCLANG
  static bool clangAssistedParsing = Config_getBool("CLANG_ASSISTED_PARSING");
  if (clangAssistedParsing && 
      (getLanguage()==SrcLangExt_Cpp || getLanguage()==SrcLangExt_ObjC))
  {
    ol.startCodeFragment();
968 969 970 971 972 973 974 975
    if (!sameTu)
    {
      ClangParser::instance()->start(absFilePath(),filesInSameTu);
    }
    else
    {
      ClangParser::instance()->switchToFile(absFilePath());
    }
976 977 978 979 980 981 982 983 984
    ClangParser::instance()->writeSources(ol,this);
    ol.endCodeFragment();
  }
  else
#endif
  {
    ParserInterface *pIntf = Doxygen::parserManager->getParser(getDefFileExtension());
    pIntf->resetCodeParserState();
    ol.startCodeFragment();
985 986 987 988 989 990 991 992 993 994 995 996 997 998
    bool needs2PassParsing = 
        Doxygen::parseSourcesNeeded &&                // we need to parse (filtered) sources for cross-references
        !filterSourceFiles &&                         // but user wants to show sources as-is
        !getFileFilter(absFilePath(),TRUE).isEmpty(); // and there is a filter used while parsing

    if (needs2PassParsing)
    {
      // parse code for cross-references only (see bug707641)
      pIntf->parseCode(devNullIntf,0,
                       fileToString(absFilePath(),TRUE,TRUE),
                       getLanguage(),
                       FALSE,0,this
                      );
    }
999 1000
    pIntf->parseCode(ol,0,
        fileToString(absFilePath(),filterSourceFiles,TRUE),
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011
        getLanguage(),      // lang
        FALSE,              // isExampleBlock
        0,                  // exampleName
        this,               // fileDef
        -1,                 // startLine
        -1,                 // endLine
        FALSE,              // inlineFragment
        0,                  // memberDef
        TRUE,               // showLineNumbers
        0,                  // searchCtx
        !needs2PassParsing  // collectXRefs
1012 1013 1014
        );
    ol.endCodeFragment();
  }
1015
  ol.endContents();
1016
  endFileWithNavPath(this,ol);
1017 1018 1019
  ol.enableAll();
}

1020
void FileDef::parseSource(bool sameTu,QStrList &filesInSameTu)
1021
{
1022
  static bool filterSourceFiles = Config_getBool("FILTER_SOURCE_FILES");
1023
  DevNullCodeDocInterface devNullIntf;
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
  (void)sameTu;
  (void)filesInSameTu;
#if USE_LIBCLANG
  static bool clangAssistedParsing = Config_getBool("CLANG_ASSISTED_PARSING");
  if (clangAssistedParsing && 
      (getLanguage()==SrcLangExt_Cpp || getLanguage()==SrcLangExt_ObjC))
  {
    if (!sameTu)
    {
      ClangParser::instance()->start(absFilePath(),filesInSameTu);
    }
    else
    {
      ClangParser::instance()->switchToFile(absFilePath());
    }
    ClangParser::instance()->writeSources(devNullIntf,this);
  }
  else
#endif
  {
    ParserInterface *pIntf = Doxygen::parserManager->getParser(getDefFileExtension());
    pIntf->resetCodeParserState();
    pIntf->parseCode(
1047
            devNullIntf,0,
1048
            fileToString(absFilePath(),filterSourceFiles,TRUE),
1049
            getLanguage(),
1050 1051
            FALSE,0,this
           );
1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
  }
}

void FileDef::startParsing()
{
}

void FileDef::finishParsing()
{
  ClangParser::instance()->finish();
1062
}
1063

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1064 1065
void FileDef::addMembersToMemberGroup()
{
1066 1067 1068 1069
  QListIterator<MemberList> mli(m_memberLists);
  MemberList *ml;
  for (mli.toFirst();(ml=mli.current());++mli)
  {
1070
    if (ml->listType()&MemberListType_declarationLists)
1071
    {
1072
      ::addMembersToMemberGroup(ml,&m_memberGroupSDict,this);
1073 1074
    }
  }
1075 1076

  // add members inside sections to their groups
1077
  if (m_memberGroupSDict)
1078
  {
1079
    MemberGroupSDict::Iterator mgli(*m_memberGroupSDict);
1080 1081 1082 1083 1084 1085 1086 1087 1088 1089
    MemberGroup *mg;
    for (;(mg=mgli.current());++mgli)
    {
      if (mg->allMembersInSameSection() && m_subGrouping)
      {
        //printf("----> addToDeclarationSection(%s)\n",mg->header().data());
        mg->addToDeclarationSection();
      }
    }
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1090 1091
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1092
/*! Adds member definition \a md to the list of all members of this file */
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1093
void FileDef::insertMember(MemberDef *md)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1094
{
1095
  if (md->isHidden()) return;
1096 1097
  //printf("%s:FileDef::insertMember(%s (=%p) list has %d elements)\n",
  //    name().data(),md->name().data(),md,allMemberList.count());
1098
  MemberList *allMemberList = getMemberList(MemberListType_allMembersList);
1099
  if (allMemberList && allMemberList->findRef(md)!=-1)  // TODO optimize the findRef!
1100 1101 1102
  { 
    return;
  }
1103

1104 1105
  if (allMemberList==0)
  {
1106
    allMemberList = new MemberList(MemberListType_allMembersList);
1107
    m_memberLists.append(allMemberList);
1108 1109
  }
  allMemberList->append(md); 
1110
  //::addFileMemberNameToIndex(md);
1111
  switch (md->memberType())
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1112
  {
1113 1114 1115 1116
    case MemberType_Variable:     
    case MemberType_Property:     
      addMemberToList(MemberListType_decVarMembers,md);
      addMemberToList(MemberListType_docVarMembers,md);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1117
      break;
1118 1119 1120
    case MemberType_Function: 
      addMemberToList(MemberListType_decFuncMembers,md);
      addMemberToList(MemberListType_docFuncMembers,md);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1121
      break;
1122 1123 1124
    case MemberType_Typedef:      
      addMemberToList(MemberListType_decTypedefMembers,md);
      addMemberToList(MemberListType_docTypedefMembers,md);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1125
      break;
1126 1127 1128
    case MemberType_Enumeration:  
      addMemberToList(MemberListType_decEnumMembers,md);
      addMemberToList(MemberListType_docEnumMembers,md);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1129
      break;
1130
    case MemberType_EnumValue:    // enum values are shown inside their enums
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1131
      break;
1132 1133 1134
    case MemberType_Define:       
      addMemberToList(MemberListType_decDefineMembers,md);
      addMemberToList(MemberListType_docDefineMembers,md);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1135
      break;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1136
    default:
1137 1138 1139
       err("FileDef::insertMembers(): "
           "member `%s' with class scope `%s' inserted in file scope `%s'!\n",
           md->name().data(),
1140
           md->getClassDef() ? md->getClassDef()->name().data() : "<global>",
1141
           name().data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1142
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1143
  //addMemberToGroup(md,groupId);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1144 1145 1146 1147 1148
}

/*! Adds compound definition \a cd to the list of all compounds of this file */
void FileDef::insertClass(ClassDef *cd)
{
1149
  if (cd->isHidden()) return;
1150
  if (m_classSDict==0)
1151
  {
1152
    m_classSDict = new ClassSDict(17);
1153
  }
1154
  if (Config_getBool("SORT_BRIEF_DOCS"))
1155 1156 1157
  {
    m_classSDict->inSort(cd->name(),cd);
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1158
  else
1159 1160 1161
  {
    m_classSDict->append(cd->name(),cd);
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1162 1163 1164 1165 1166
}

/*! Adds namespace definition \a nd to the list of all compounds of this file */
void FileDef::insertNamespace(NamespaceDef *nd)
{
1167
  if (nd->isHidden()) return;
1168
  if (!nd->name().isEmpty() && 
1169
      (m_namespaceSDict==0 || m_namespaceSDict->find(nd->name())==0))
1170
  {
1171
    if (m_namespaceSDict==0)
1172
    {
1173
      m_namespaceSDict = new NamespaceSDict;
1174
    }
1175
    if (Config_getBool("SORT_BRIEF_DOCS"))
1176 1177 1178
    {
      m_namespaceSDict->inSort(nd->name(),nd);
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1179
    else
1180 1181 1182
    {
      m_namespaceSDict->append(nd->name(),nd);
    }
1183
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1184 1185
}

1186 1187 1188
QCString FileDef::name() const 
{ 
  if (Config_getBool("FULL_PATH_NAMES")) 
1189
    return m_fileName; 
1190 1191 1192 1193
  else 
    return Definition::name(); 
} 

1194
void FileDef::addSourceRef(int line,Definition *d,MemberDef *md)
1195
{
1196
  //printf("FileDef::addSourceDef(%d,%p,%p)\n",line,d,md);
1197 1198
  if (d)
  {
1199 1200 1201 1202
    if (m_srcDefDict==0)    m_srcDefDict    = new QIntDict<Definition>(257);
    if (m_srcMemberDict==0) m_srcMemberDict = new QIntDict<MemberDef>(257);
    m_srcDefDict->insert(line,d);
    if (md) m_srcMemberDict->insert(line,md);
1203
    //printf("Adding member %s with anchor %s at line %d to file %s\n",
1204
    //    md?md->name().data():"<none>",md?md->anchor().data():"<none>",line,name().data());
1205 1206 1207
  }
}

1208
Definition *FileDef::getSourceDefinition(int lineNr) const
1209 1210
{
  Definition *result=0;
1211
  if (m_srcDefDict)
1212
  {
1213
    result = m_srcDefDict->find(lineNr);
1214
  }
1215
  //printf("%s::getSourceDefinition(%d)=%s\n",name().data(),lineNr,result?result->name().data():"none");
1216 1217 1218
  return result;
}

1219
MemberDef *FileDef::getSourceMember(int lineNr) const
1220
{
1221
  MemberDef *result=0;
1222
  if (m_srcMemberDict)
1223
  {
1224
    result = m_srcMemberDict->find(lineNr);
1225
  }
1226
  //printf("%s::getSourceMember(%d)=%s\n",name().data(),lineNr,result?result->name().data():"none");
1227 1228 1229
  return result;
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1230

1231 1232
void FileDef::addUsingDirective(NamespaceDef *nd)
{
1233
  if (m_usingDirList==0)
1234
  {
1235
    m_usingDirList = new NamespaceSDict;
1236
  }
1237
  if (m_usingDirList->find(nd->qualifiedName())==0)
1238
  {
1239
    m_usingDirList->append(nd->qualifiedName(),nd);
1240
  }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1241 1242 1243 1244 1245 1246
  //printf("%p: FileDef::addUsingDirective: %s:%d\n",this,name().data(),usingDirList->count());
}

NamespaceSDict *FileDef::getUsedNamespaces() const 
{ 
  //printf("%p: FileDef::getUsedNamespace: %s:%d\n",this,name().data(),usingDirList?usingDirList->count():0);
1247
  return m_usingDirList; 
1248 1249
}

1250
void FileDef::addUsingDeclaration(Definition *d)
1251
{
1252
  if (m_usingDeclList==0)
1253
  {
1254
    m_usingDeclList = new SDict<Definition>(17);
1255
  }
1256
  if (m_usingDeclList->find(d->qualifiedName())==0)
1257
  {
1258
    m_usingDeclList->append(d->qualifiedName(),d);
1259 1260 1261
  }
}

1262
void FileDef::addIncludeDependency(FileDef *fd,const char *incName,bool local,
1263
                                   bool imported,bool indirect)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1264
{
1265
  //printf("FileDef::addIncludeDependency(%p,%s,%d)\n",fd,incName,local);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1266
  QCString iName = fd ? fd->absFilePath().data() : incName;
1267
  if (!iName.isEmpty() && (!m_includeDict || m_includeDict->find(iName)==0))
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1268
  {
1269
    if (m_includeDict==0)
1270
    {
1271 1272 1273
      m_includeDict   = new QDict<IncludeInfo>(61);
      m_includeList   = new QList<IncludeInfo>;
      m_includeList->setAutoDelete(TRUE);
1274
    }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1275 1276 1277 1278
    IncludeInfo *ii = new IncludeInfo;
    ii->fileDef     = fd;
    ii->includeName = incName;
    ii->local       = local;
1279
    ii->imported    = imported;
1280
    ii->indirect    = indirect;
1281 1282
    m_includeList->append(ii);
    m_includeDict->insert(iName,ii);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1283 1284 1285
  }
}

Dimitri van Heesch's avatar
Dimitri van Heesch committed
1286 1287
void FileDef::addIncludedUsingDirectives()
{
1288 1289 1290 1291 1292
  if (visited) return;
  visited=TRUE;
  //printf("( FileDef::addIncludedUsingDirectives for file %s\n",name().data());

  NamespaceList nl;
1293
  if (m_includeList) // file contains #includes
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1294 1295
  {
    {
1296
      QListIterator<IncludeInfo> iii(*m_includeList);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1297
      IncludeInfo *ii;
1298
      for (iii.toFirst();(ii=iii.current());++iii) // foreach #include...
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1299
      {
1300
        if (ii->fileDef && !ii->fileDef->visited) // ...that is a known file
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1301 1302 1303 1304 1305
        {
          // recurse into this file
          ii->fileDef->addIncludedUsingDirectives();
        }
      }
1306 1307
    }
    {
1308
      QListIterator<IncludeInfo> iii(*m_includeList);
1309
      IncludeInfo *ii;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1310 1311 1312
      // iterate through list from last to first
      for (iii.toLast();(ii=iii.current());--iii)
      {
1313
        if (ii->fileDef && ii->fileDef!=this)
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1314
        {
1315
          // add using directives
1316
          NamespaceSDict *unl = ii->fileDef->m_usingDirList;
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1317 1318
          if (unl)
          {
1319
            NamespaceSDict::Iterator nli(*unl);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1320 1321 1322 1323
            NamespaceDef *nd;
            for (nli.toLast();(nd=nli.current());--nli)
            {
              // append each using directive found in a #include file
1324
              if (m_usingDirList==0) m_usingDirList = new NamespaceSDict;
1325 1326
              //printf("Prepending used namespace %s to the list of file %s\n",
              //    nd->name().data(),name().data());
1327
              if (m_usingDirList->find(nd->qualifiedName())==0) // not yet added
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1328
              {
1329
                m_usingDirList->prepend(nd->qualifiedName(),nd);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1330
              }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1331 1332
            }
          }
1333
          // add using declarations
1334
          SDict<Definition> *udl = ii->fileDef->m_usingDeclList;
1335 1336 1337 1338 1339 1340 1341
          if (udl)
          {
            SDict<Definition>::Iterator udi(*udl);
            Definition *d;
            for (udi.toLast();(d=udi.current());--udi)
            {
              //printf("Adding using declaration %s\n",d->name().data());
1342
              if (m_usingDeclList==0)
1343
              {
1344
                m_usingDeclList = new SDict<Definition>(17);
1345
              }
1346
              if (m_usingDeclList->find(d->qualifiedName())==0)
1347
              {
1348
                m_usingDeclList->prepend(d->qualifiedName(),d);
1349 1350 1351
              }
            }
          }
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1352 1353 1354 1355
        }
      }
    }
  }
1356
  //printf(") end FileDef::addIncludedUsingDirectives for file %s\n",name().data());
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1357 1358 1359
}


1360 1361
void FileDef::addIncludedByDependency(FileDef *fd,const char *incName,
                                      bool local,bool imported)
1362 1363 1364
{
  //printf("FileDef::addIncludedByDependency(%p,%s,%d)\n",fd,incName,local);
  QCString iName = fd ? fd->absFilePath().data() : incName;
1365
  if (!iName.isEmpty() && (m_includedByDict==0 || m_includedByDict->find(iName)==0))
1366
  {
1367
    if (m_includedByDict==0)
1368
    {
1369 1370 1371
      m_includedByDict = new QDict<IncludeInfo>(61);
      m_includedByList = new QList<IncludeInfo>;
      m_includedByList->setAutoDelete(TRUE);
1372
    }
1373 1374 1375 1376
    IncludeInfo *ii = new IncludeInfo;
    ii->fileDef     = fd;
    ii->includeName = incName;
    ii->local       = local;
1377
    ii->imported    = imported;
1378
    ii->indirect    = FALSE;
1379 1380
    m_includedByList->append(ii);
    m_includedByDict->insert(iName,ii);
1381 1382 1383
  }
}

1384 1385 1386
bool FileDef::isIncluded(const QCString &name) const
{
  if (name.isEmpty()) return FALSE;
1387
  return m_includeDict!=0 && m_includeDict->find(name)!=0;
1388 1389
}

1390 1391
bool FileDef::generateSourceFile() const 
{ 
1392 1393
  static bool sourceBrowser = Config_getBool("SOURCE_BROWSER");
  static bool verbatimHeaders = Config_getBool("VERBATIM_HEADERS");
1394
  QCString extension = name().right(4);
1395
  return !isReference() && 
1396 1397
         (sourceBrowser || 
           (verbatimHeaders && guessSection(name())==Entry::HEADER_SEC) 
1398
         ) &&
1399
         extension!=".doc" && extension!=".txt" && extension!=".dox" &&
1400
         extension!=".md" && name().right(9)!=".markdown";  
1401 1402
}

1403 1404 1405

void FileDef::addListReferences()
{
1406
  {
1407 1408
    QList<ListItemInfo> *xrefItems = xrefListItems();
    addRefItem(xrefItems,
1409
               getOutputFileBase(),
1410
               theTranslator->trFile(TRUE,TRUE),
1411
               getOutputFileBase(),name(),
1412
               0,
1413
               0
1414 1415
              );
  }
1416
  if (m_memberGroupSDict)
1417
  {
1418
    MemberGroupSDict::Iterator mgli(*m_memberGroupSDict);
1419 1420 1421 1422 1423 1424
    MemberGroup *mg;
    for (;(mg=mgli.current());++mgli)
    {
      mg->addListReferences(this);
    }
  }
1425 1426 1427 1428
  QListIterator<MemberList> mli(m_memberLists);
  MemberList *ml;
  for (mli.toFirst();(ml=mli.current());++mli)
  {
1429
    if (ml->listType()&MemberListType_documentationLists)
1430 1431 1432 1433
    {
      ml->addListReferences(this);
    }
  }
1434 1435
}

1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508
//-------------------------------------------------------------------

static int findMatchingPart(const QCString &path,const QCString dir)
{
  int si1;
  int pos1=0,pos2=0;
  while ((si1=path.find('/',pos1))!=-1)
  {
    int si2=dir.find('/',pos2);
    //printf("  found slash at pos %d in path %d: %s<->%s\n",si1,si2,
    //    path.mid(pos1,si1-pos2).data(),dir.mid(pos2).data());
    if (si2==-1 && path.mid(pos1,si1-pos2)==dir.mid(pos2)) // match at end
    {
      return dir.length();
    }
    if (si1!=si2 || path.mid(pos1,si1-pos2)!=dir.mid(pos2,si2-pos2)) // no match in middle
    {
      return QMAX(pos1-1,0);
    }
    pos1=si1+1;
    pos2=si2+1;
  }
  return 0;
}

static Directory *findDirNode(Directory *root,const QCString &name)
{
  QListIterator<DirEntry> dli(root->children());
  DirEntry *de;
  for (dli.toFirst();(de=dli.current());++dli)
  {
    if (de->kind()==DirEntry::Dir)
    {
      Directory *dir = (Directory *)de;
      QCString dirName=dir->name();
      int sp=findMatchingPart(name,dirName);
      //printf("findMatchingPart(%s,%s)=%d\n",name.data(),dirName.data(),sp);
      if (sp>0) // match found
      {
        if ((uint)sp==dirName.length()) // whole directory matches
        {
          // recurse into the directory
          return findDirNode(dir,name.mid(dirName.length()+1));
        } 
        else // partial match => we need to split the path into three parts
        {
          QCString baseName     =dirName.left(sp);
          QCString oldBranchName=dirName.mid(sp+1);
          QCString newBranchName=name.mid(sp+1);
          // strip file name from path
          int newIndex=newBranchName.findRev('/');
          if (newIndex>0) newBranchName=newBranchName.left(newIndex);

          //printf("Splitting off part in new branch \n"
          //    "base=%s old=%s new=%s\n",
          //    baseName.data(),
          //    oldBranchName.data(),
          //    newBranchName.data()
          //      );
          Directory *base = new Directory(root,baseName);
          Directory *newBranch = new Directory(base,newBranchName);
          dir->reParent(base);
          dir->rename(oldBranchName);
          base->addChild(dir);
          base->addChild(newBranch);
          dir->setLast(FALSE);
          // remove DirEntry container from list (without deleting it)
          root->children().setAutoDelete(FALSE);
          root->children().removeRef(dir);
          root->children().setAutoDelete(TRUE);
          // add new branch to the root
          if (!root->children().isEmpty())
          {
1509
            root->children().getLast()->setLast(FALSE); 
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528
          }
          root->addChild(base);
          return newBranch;
        }
      }
    }
  }
  int si=name.findRev('/');
  if (si==-1) // no subdir
  {
    return root; // put the file under the root node.
  }
  else // need to create a subdir 
  {
    QCString baseName = name.left(si);
    //printf("new subdir %s\n",baseName.data());
    Directory *newBranch = new Directory(root,baseName);
    if (!root->children().isEmpty())
    {
1529
      root->children().getLast()->setLast(FALSE); 
1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543
    }
    root->addChild(newBranch);
    return newBranch;
  }
}

static void mergeFileDef(Directory *root,FileDef *fd)
{
  QCString rootPath = root->name();
  QCString filePath = fd->absFilePath();
  //printf("merging %s\n",filePath.data());
  Directory *dirNode = findDirNode(root,filePath);
  if (!dirNode->children().isEmpty())
  {
1544
    dirNode->children().getLast()->setLast(FALSE); 
1545 1546 1547 1548 1549
  }
  DirEntry *e=new DirEntry(dirNode,fd);
  dirNode->addChild(e);
}

1550
#if 0
1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625
static void generateIndent(QTextStream &t,DirEntry *de,int level)
{
  if (de->parent())
  {
    generateIndent(t,de->parent(),level+1);
  }
  // from the root up to node n do...
  if (level==0) // item before a dir or document
  {
    if (de->isLast())
    {
      if (de->kind()==DirEntry::Dir)
      {
        t << "<img " << FTV_IMGATTRIBS(plastnode) << "/>";
      }
      else
      {
        t << "<img " << FTV_IMGATTRIBS(lastnode) << "/>";
      }
    }
    else
    {
      if (de->kind()==DirEntry::Dir)
      {
        t << "<img " << FTV_IMGATTRIBS(pnode) << "/>";
      }
      else
      {
        t << "<img " << FTV_IMGATTRIBS(node) << "/>";
      }
    }
  }
  else // item at another level
  {
    if (de->isLast())
    {
      t << "<img " << FTV_IMGATTRIBS(blank) << "/>";
    }
    else
    {
      t << "<img " << FTV_IMGATTRIBS(vertline) << "/>";
    }
  }
}

static void writeDirTreeNode(QTextStream &t,Directory *root,int level)
{
  QCString indent;
  indent.fill(' ',level*2);
  QListIterator<DirEntry> dli(root->children());
  DirEntry *de;
  for (dli.toFirst();(de=dli.current());++dli)
  {
    t << indent << "<p>";
    generateIndent(t,de,0);
    if (de->kind()==DirEntry::Dir)
    {
      Directory *dir=(Directory *)de;
      //printf("%s [dir]: %s (last=%d,dir=%d)\n",indent.data(),dir->name().data(),dir->isLast(),dir->kind()==DirEntry::Dir);
      t << "<img " << FTV_IMGATTRIBS(folderclosed) << "/>";
      t << dir->name();
      t << "</p>\n";
      t << indent << "<div>\n";
      writeDirTreeNode(t,dir,level+1);
      t << indent << "</div>\n";
    }
    else
    {
      //printf("%s [file]: %s (last=%d,dir=%d)\n",indent.data(),de->file()->name().data(),de->isLast(),de->kind()==DirEntry::Dir);
      t << "<img " << FTV_IMGATTRIBS(doc) << "/>";
      t << de->file()->name();
      t << "</p>\n";
    }
  }
}
1626
#endif
1627

1628 1629 1630 1631 1632
static void addDirsAsGroups(Directory *root,GroupDef *parent,int level)
{
  GroupDef *gd=0;
  if (root->kind()==DirEntry::Dir)
  {
1633
    gd = new GroupDef("[generated]",
1634
                      1,
1635
                      root->path(), // name
1636 1637 1638 1639 1640
                      root->name()  // title
                     );
    if (parent) 
    {
      parent->addGroup(gd);
1641
      gd->makePartOfGroup(parent);
1642 1643 1644
    }
    else
    {
1645
      Doxygen::groupSDict->append(root->path(),gd);
1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659
    }
  }
  QListIterator<DirEntry> dli(root->children());
  DirEntry *de;
  for (dli.toFirst();(de=dli.current());++dli)
  {
    if (de->kind()==DirEntry::Dir)
    {
      addDirsAsGroups((Directory *)de,gd,level+1);
    }
  }
}

void generateFileTree()
1660
{
1661
  Directory *root=new Directory(0,"root");
1662
  root->setLast(TRUE);
1663
  FileNameListIterator fnli(*Doxygen::inputNameList); 
1664 1665 1666 1667 1668 1669 1670 1671 1672 1673
  FileName *fn;
  for (fnli.toFirst();(fn=fnli.current());++fnli)
  {
    FileNameIterator fni(*fn);
    FileDef *fd;
    for (;(fd=fni.current());++fni)
    {
      mergeFileDef(root,fd);
    }
  }
1674 1675 1676 1677
  //t << "<div class=\"directory\">\n";
  //writeDirTreeNode(t,root,0);
  //t << "</div>\n";
  addDirsAsGroups(root,0,0);
1678 1679 1680
  delete root;
}

1681 1682
//-------------------------------------------------------------------

1683 1684 1685 1686
void FileDef::combineUsingRelations()
{
  if (visited) return; // already done
  visited=TRUE;
1687
  if (m_usingDirList)
1688
  {
1689
    NamespaceSDict::Iterator nli(*m_usingDirList);
1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710
    NamespaceDef *nd;
    for (nli.toFirst();(nd=nli.current());++nli)
    {
      nd->combineUsingRelations();
    }
    for (nli.toFirst();(nd=nli.current());++nli)
    {
      // add used namespaces of namespace nd to this namespace
      if (nd->getUsedNamespaces())
      {
        NamespaceSDict::Iterator unli(*nd->getUsedNamespaces());
        NamespaceDef *und;
        for (unli.toFirst();(und=unli.current());++unli)
        {
          //printf("Adding namespace %s to the using list of %s\n",und->qualifiedName().data(),qualifiedName().data());
          addUsingDirective(und);
        }
      }
      // add used classes of namespace nd to this namespace
      if (nd->getUsedClasses())
      {
1711 1712
        SDict<Definition>::Iterator cli(*nd->getUsedClasses());
        Definition *ucd;
1713 1714 1715 1716 1717 1718 1719 1720 1721 1722
        for (cli.toFirst();(ucd=cli.current());++cli)
        {
          //printf("Adding class %s to the using list of %s\n",cd->qualifiedName().data(),qualifiedName().data());
          addUsingDeclaration(ucd);
        }
      }
    }
  }
}

1723 1724 1725 1726
bool FileDef::isDocumentationFile() const
{
  return name().right(4)==".doc" ||
         name().right(4)==".txt" ||
1727 1728 1729
         name().right(4)==".dox" ||
         name().right(3)==".md"  ||
         name().right(9)==".markdown";
1730
}
1731 1732 1733 1734

void FileDef::acquireFileVersion()
{
  QCString vercmd = Config_getString("FILE_VERSION_FILTER");
1735
  if (!vercmd.isEmpty() && !m_filePath.isEmpty() && m_filePath!="generated") 
1736
  {
1737 1738
    msg("Version of %s : ",m_filePath.data());
    QCString cmd = vercmd+" \""+m_filePath+"\"";
1739 1740
    Debug::print(Debug::ExtCmd,0,"Executing popen(`%s`)\n",cmd.data());
    FILE *f=portable_popen(cmd,"r");
1741 1742
    if (!f)
    {
1743
      err("could not execute %s\n",vercmd.data());
1744 1745 1746 1747
      return;
    }
    const int bufSize=1024;
    char buf[bufSize];
1748
    int numRead = (int)fread(buf,1,bufSize-1,f);
1749
    portable_pclose(f);
1750
    if (numRead>0 && numRead<bufSize)
1751
    {
1752 1753 1754 1755 1756 1757 1758
      buf[numRead]='\0';
      m_fileVersion=QCString(buf,numRead).stripWhiteSpace();
      if (!m_fileVersion.isEmpty())
      {
        msg("%s\n",m_fileVersion.data());
        return;
      }
1759
    }
1760
    msg("no version available\n");
1761 1762 1763 1764
  }
}


1765 1766 1767 1768
QCString FileDef::getSourceFileBase() const
{ 
  if (Htags::useHtags)
  {
1769
    return Htags::path2URL(m_filePath);
1770 1771 1772
  }
  else
  {
1773
    return convertNameToFile(m_diskName)+"_source"; 
1774 1775 1776 1777 1778 1779
  }
}

/*! Returns the name of the verbatim copy of this file (if any). */
QCString FileDef::includeName() const 
{ 
1780
  return getSourceFileBase();
1781 1782
}

1783
MemberList *FileDef::createMemberList(MemberListType lt)
1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800
{
  m_memberLists.setAutoDelete(TRUE);
  QListIterator<MemberList> mli(m_memberLists);
  MemberList *ml;
  for (mli.toFirst();(ml=mli.current());++mli)
  {
    if (ml->listType()==lt)
    {
      return ml;
    }
  }
  // not found, create a new member list
  ml = new MemberList(lt);
  m_memberLists.append(ml);
  return ml;
}

1801
void FileDef::addMemberToList(MemberListType lt,MemberDef *md)
1802 1803 1804 1805
{
  static bool sortBriefDocs = Config_getBool("SORT_BRIEF_DOCS");
  static bool sortMemberDocs = Config_getBool("SORT_MEMBER_DOCS");
  MemberList *ml = createMemberList(lt);
1806
  ml->setNeedsSorting(
1807 1808
       ((ml->listType()&MemberListType_declarationLists) && sortBriefDocs) ||
       ((ml->listType()&MemberListType_documentationLists) && sortMemberDocs));
1809 1810 1811
  ml->append(md);
#if 0
  if (ml->needsSorting())
1812 1813 1814
    ml->inSort(md);
  else
    ml->append(md);
1815
#endif
1816
  if (lt&MemberListType_documentationLists)
1817 1818 1819
  {
    ml->setInFile(TRUE);
  }
1820
  if (ml->listType()&MemberListType_declarationLists) md->setSectionList(this,ml);
1821 1822
}

1823 1824
void FileDef::sortMemberLists()
{
1825 1826 1827
  QListIterator<MemberList> mli(m_memberLists);
  MemberList *ml;
  for (;(ml=mli.current());++mli)
1828 1829 1830 1831 1832
  {
    if (ml->needsSorting()) { ml->sort(); ml->setNeedsSorting(FALSE); }
  }
}

1833
MemberList *FileDef::getMemberList(MemberListType lt) const
1834
{
1835 1836 1837
  QListIterator<MemberList> mli(m_memberLists);
  MemberList *ml;
  for (;(ml=mli.current());++mli)
1838 1839 1840 1841 1842 1843 1844 1845 1846
  {
    if (ml->listType()==lt)
    {
      return ml;
    }
  }
  return 0;
}

1847
void FileDef::writeMemberDeclarations(OutputList &ol,MemberListType lt,const QCString &title)
1848
{
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1849
  static bool optVhdl = Config_getBool("OPTIMIZE_OUTPUT_VHDL");
1850
  MemberList * ml = getMemberList(lt);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1851 1852 1853 1854
  if (ml) 
  {
    if (optVhdl) // use specific declarations function
    {
1855 1856

      VhdlDocGen::writeVhdlDeclarations(ml,ol,0,0,this,0);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1857 1858 1859
    }
    else
    {
1860
      ml->writeDeclarations(ol,0,0,this,0,title,0);
Dimitri van Heesch's avatar
Dimitri van Heesch committed
1861 1862
    }
  }
1863 1864
}

1865
void FileDef::writeMemberDocumentation(OutputList &ol,MemberListType lt,const QCString &title)
1866 1867 1868 1869
{
  MemberList * ml = getMemberList(lt);
  if (ml) ml->writeDocumentation(ol,name(),this,title);
}
1870 1871 1872 1873 1874 1875 1876

bool FileDef::isLinkableInProject() const
{
  static bool showFiles = Config_getBool("SHOW_FILES");
  return hasDocumentation() && !isReference() && showFiles;
}

1877 1878
static void getAllIncludeFilesRecursively(
    QDict<void> *filesVisited,const FileDef *fd,QStrList &incFiles)
1879
{
1880
  if (fd->includeFileList())
1881
  {
1882
    QListIterator<IncludeInfo> iii(*fd->includeFileList());
1883
    IncludeInfo *ii;
1884
    for (iii.toFirst();(ii=iii.current());++iii)
1885
    {
1886 1887 1888 1889 1890 1891 1892 1893
      if (ii->fileDef && !ii->fileDef->isReference() &&
          !filesVisited->find(ii->fileDef->absFilePath()))
      {
        //printf("FileDef::addIncludeDependency(%s)\n",ii->fileDef->absFilePath().data());
        incFiles.append(ii->fileDef->absFilePath());
        filesVisited->insert(ii->fileDef->absFilePath(),(void*)0x8);
        getAllIncludeFilesRecursively(filesVisited,ii->fileDef,incFiles);
      }
1894 1895 1896 1897
    }
  }
}

1898
void FileDef::getAllIncludeFilesRecursively(QStrList &incFiles) const
1899
{
1900 1901
  QDict<void> includes(257);
  ::getAllIncludeFilesRecursively(&includes,this,incFiles);
1902
}
1903 1904 1905 1906 1907 1908

QCString FileDef::title() const
{
  return theTranslator->trFileReference(name());
}

1909 1910 1911 1912
QCString FileDef::fileVersion() const
{
  return m_fileVersion;
}