Skip to content

Commit

Permalink
Make generateFileDocs() process files in parallel
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed Aug 24, 2021
1 parent aeded2a commit f74a0c5
Show file tree
Hide file tree
Showing 17 changed files with 257 additions and 154 deletions.
23 changes: 8 additions & 15 deletions src/classdef.cpp
Expand Up @@ -285,7 +285,7 @@ class ClassDefImpl : public DefinitionMixin<ClassDefMutable>
virtual void writeDocumentationForInnerClasses(OutputList &ol) const;
virtual void writeMemberPages(OutputList &ol) const;
virtual void writeMemberList(OutputList &ol) const;
virtual void writeDeclaration(OutputList &ol,const MemberDef *md,bool inGroup,
virtual void writeDeclaration(OutputList &ol,const MemberDef *md,bool inGroup,int indentLevel,
const ClassDef *inheritedFrom,const QCString &inheritId) const;
virtual void writeQuickMemberLinks(OutputList &ol,const MemberDef *md) const;
virtual void writeSummaryLinks(OutputList &ol) const;
Expand Down Expand Up @@ -326,13 +326,13 @@ class ClassDefImpl : public DefinitionMixin<ClassDefMutable>
bool showAlways) const;
void writeMemberDocumentation(OutputList &ol,MemberListType lt,const QCString &title,bool showInline=FALSE) const;
void writeSimpleMemberDocumentation(OutputList &ol,MemberListType lt) const;
void writePlainMemberDeclaration(OutputList &ol,MemberListType lt,bool inGroup,const ClassDef *inheritedFrom,const QCString &inheritId) const;
void writePlainMemberDeclaration(OutputList &ol,MemberListType lt,bool inGroup,
int indentLevel,const ClassDef *inheritedFrom,const QCString &inheritId) const;
void writeBriefDescription(OutputList &ol,bool exampleFlag) const;
void writeDetailedDescription(OutputList &ol,const QCString &pageType,bool exampleFlag,
const QCString &title,const QCString &anchor=QCString()) const;
void writeIncludeFiles(OutputList &ol) const;
void writeIncludeFilesForSlice(OutputList &ol) const;
//void writeAllMembersLink(OutputList &ol);
void writeInheritanceGraph(OutputList &ol) const;
void writeCollaborationGraph(OutputList &ol) const;
void writeMemberGroups(OutputList &ol,bool showInline=FALSE) const;
Expand Down Expand Up @@ -2488,13 +2488,6 @@ void ClassDefImpl::writeDocumentationContents(OutputList &ol,const QCString & /*
QCString pageType = " ";
pageType += compoundTypeString();

Doxygen::indexList->addIndexItem(this,0);

if (Doxygen::searchIndex)
{
Doxygen::searchIndex->setCurrentDoc(this,anchor(),FALSE);
Doxygen::searchIndex->addWord(localName(),TRUE);
}
bool exampleFlag=hasExamples();

//---------------------------------------- start flexible part -------------------------------
Expand Down Expand Up @@ -3230,7 +3223,7 @@ void ClassDefImpl::setRequiresClause(const QCString &req)
/*! called from MemberDef::writeDeclaration() to (recursively) write the
* definition of an anonymous struct, union or class.
*/
void ClassDefImpl::writeDeclaration(OutputList &ol,const MemberDef *md,bool inGroup,
void ClassDefImpl::writeDeclaration(OutputList &ol,const MemberDef *md,bool inGroup,int indentLevel,
const ClassDef *inheritedFrom,const QCString &inheritId) const
{
//printf("ClassName='%s' inGroup=%d\n",qPrint(name()),inGroup);
Expand All @@ -3257,15 +3250,15 @@ void ClassDefImpl::writeDeclaration(OutputList &ol,const MemberDef *md,bool inGr
// write user defined member groups
for (const auto &mg : m_impl->memberGroups)
{
mg->writePlainDeclarations(ol,inGroup,this,0,0,0,inheritedFrom,inheritId);
mg->writePlainDeclarations(ol,inGroup,this,0,0,0,indentLevel,inheritedFrom,inheritId);
}

for (const auto &lde : LayoutDocManager::instance().docEntries(LayoutDocManager::Class))
{
if (lde->kind()==LayoutDocEntry::MemberDecl)
{
const LayoutDocEntryMemberDecl *lmd = (const LayoutDocEntryMemberDecl*)lde.get();
writePlainMemberDeclaration(ol,lmd->type,inGroup,inheritedFrom,inheritId);
writePlainMemberDeclaration(ol,lmd->type,inGroup,indentLevel,inheritedFrom,inheritId);
}
}
}
Expand Down Expand Up @@ -4512,13 +4505,13 @@ void ClassDefImpl::writeSimpleMemberDocumentation(OutputList &ol,MemberListType

void ClassDefImpl::writePlainMemberDeclaration(OutputList &ol,
MemberListType lt,bool inGroup,
const ClassDef *inheritedFrom,const QCString &inheritId) const
int indentLevel,const ClassDef *inheritedFrom,const QCString &inheritId) const
{
//printf("%s: ClassDefImpl::writePlainMemberDeclaration()\n",qPrint(name()));
MemberList * ml = getMemberList(lt);
if (ml)
{
ml->writePlainDeclarations(ol,inGroup,this,0,0,0,inheritedFrom,inheritId);
ml->writePlainDeclarations(ol,inGroup,this,0,0,0,indentLevel,inheritedFrom,inheritId);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/classdef.h
Expand Up @@ -446,7 +446,7 @@ class ClassDefMutable : public DefinitionMutable, public ClassDef
virtual void writeMemberPages(OutputList &ol) const = 0;
virtual void writeMemberList(OutputList &ol) const = 0;
virtual void writeDeclaration(OutputList &ol,const MemberDef *md,bool inGroup,
const ClassDef *inheritedFrom,const QCString &inheritId) const = 0;
int indentLevel, const ClassDef *inheritedFrom,const QCString &inheritId) const = 0;
virtual void writeQuickMemberLinks(OutputList &ol,const MemberDef *md) const = 0;
virtual void writeSummaryLinks(OutputList &ol) const = 0;
virtual void writeInlineDocumentation(OutputList &ol) const = 0;
Expand Down
7 changes: 0 additions & 7 deletions src/conceptdef.cpp
Expand Up @@ -494,13 +494,6 @@ void ConceptDefImpl::writeDocumentation(OutputList &ol)

ol.startContents();

if (Doxygen::searchIndex)
{
Doxygen::searchIndex->setCurrentDoc(this,anchor(),FALSE);
Doxygen::searchIndex->addWord(localName(),TRUE);
}

Doxygen::indexList->addIndexItem(this,0);
//---------------------------------------- start flexible part -------------------------------

for (const auto &lde : LayoutDocManager::instance().docEntries(LayoutDocManager::Concept))
Expand Down
222 changes: 209 additions & 13 deletions src/doxygen.cpp
Expand Up @@ -7575,7 +7575,7 @@ static void findDocumentedEnumValues()

static void addMembersToIndex()
{
// for each member name
// for each class member name
for (const auto &mn : *Doxygen::memberNameLinkedMap)
{
// for each member definition
Expand All @@ -7584,7 +7584,7 @@ static void addMembersToIndex()
addClassMemberNameToIndex(md.get());
}
}
// for each member name
// for each file/namespace function name
for (const auto &mn : *Doxygen::functionNameLinkedMap)
{
// for each member definition
Expand All @@ -7605,6 +7605,154 @@ static void addMembersToIndex()

//----------------------------------------------------------------------

static void addToIndices()
{
for (const auto &cd : *Doxygen::classLinkedMap)
{
if (cd->isLinkableInProject())
{
Doxygen::indexList->addIndexItem(cd.get(),0);
if (Doxygen::searchIndex)
{
Doxygen::searchIndex->setCurrentDoc(cd.get(),cd->anchor(),FALSE);
Doxygen::searchIndex->addWord(cd->localName(),TRUE);
}
}
}

for (const auto &cd : *Doxygen::conceptLinkedMap)
{
if (cd->isLinkableInProject())
{
Doxygen::indexList->addIndexItem(cd.get(),0);
if (Doxygen::searchIndex)
{
Doxygen::searchIndex->setCurrentDoc(cd.get(),cd->anchor(),FALSE);
Doxygen::searchIndex->addWord(cd->localName(),TRUE);
}
}
}

for (const auto &nd : *Doxygen::namespaceLinkedMap)
{
if (nd->isLinkableInProject())
{
Doxygen::indexList->addIndexItem(nd.get(),0);
if (Doxygen::searchIndex)
{
Doxygen::searchIndex->setCurrentDoc(nd.get(),nd->anchor(),FALSE);
Doxygen::searchIndex->addWord(nd->localName(),TRUE);
}
}
}

for (const auto &fn : *Doxygen::inputNameLinkedMap)
{
for (const auto &fd : *fn)
{
if (Doxygen::searchIndex && fd->isLinkableInProject())
{
Doxygen::searchIndex->setCurrentDoc(fd.get(),fd->anchor(),FALSE);
Doxygen::searchIndex->addWord(fd->localName(),TRUE);
}
}
}

for (const auto &gd : *Doxygen::groupLinkedMap)
{
if (gd->isLinkableInProject())
{
Doxygen::indexList->addIndexItem(gd.get(),0,QCString(),gd->groupTitle());
if (Doxygen::searchIndex)
{
Doxygen::searchIndex->setCurrentDoc(gd.get(),gd->anchor(),FALSE);
std::string title = gd->groupTitle().str();
static const reg::Ex re(R"(\a[\w-]*)");
reg::Iterator it(title,re);
reg::Iterator end;
for (; it!=end ; ++it)
{
const auto &match = *it;
std::string matchStr = match.str();
Doxygen::searchIndex->addWord(matchStr.c_str(),TRUE);
}
}
}
}

for (const auto &pd : *Doxygen::pageLinkedMap)
{
if (pd->isLinkableInProject())
{
Doxygen::indexList->addIndexItem(pd.get(),0,QCString(),filterTitle(pd->title().str()));
}
}

auto addMemberToSearchIndex = [](const MemberDef *md)
{
if (Doxygen::searchIndex)
{
Doxygen::searchIndex->setCurrentDoc(md,md->anchor(),FALSE);
QCString ln=md->localName();
QCString qn=md->qualifiedName();
Doxygen::searchIndex->addWord(ln,TRUE);
if (ln!=qn)
{
Doxygen::searchIndex->addWord(qn,TRUE);
if (md->getClassDef())
{
Doxygen::searchIndex->addWord(md->getClassDef()->displayName(),TRUE);
}
if (md->getNamespaceDef())
{
Doxygen::searchIndex->addWord(md->getNamespaceDef()->displayName(),TRUE);
}
}
}
};

auto addMemberToIndices = [addMemberToSearchIndex](const MemberDef *md)
{
if (md->isLinkableInProject())
{
if (!(md->isEnumerate() && md->isAnonymous()))
{
Doxygen::indexList->addIndexItem(md->getOuterScope(),md);
addMemberToSearchIndex(md);
}
if (md->isEnumerate())
{
for (const auto &fmd : md->enumFieldList())
{
Doxygen::indexList->addIndexItem(md->getOuterScope(),fmd);
addMemberToSearchIndex(fmd);
}
}
}
};

// for each class member name
for (const auto &mn : *Doxygen::memberNameLinkedMap)
{
// for each member definition
for (const auto &md : *mn)
{
addMemberToIndices(md.get());
}
}
// for each file/namespace function name
for (const auto &mn : *Doxygen::functionNameLinkedMap)
{
// for each member definition
for (const auto &md : *mn)
{
addMemberToIndices(md.get());
}
}
}

//----------------------------------------------------------------------

static void vhdlCorrectMemberProperties()
{
// for each member name
Expand Down Expand Up @@ -7924,14 +8072,17 @@ static void generateFileSources()
auto ctx = std::make_shared<SourceContext>(fd.get(),generateSourceFile,*g_outputList);
if (generateSourceFile)
{
msg("Generating code for file %s...\n",qPrint(fd->docName()));
fd->writeSourceHeader(ctx->ol);
}
else
{
msg("Parsing code for file %s...\n",qPrint(fd->docName()));
}
auto processFile = [ctx]() {
if (ctx->generateSourceFile)
{
msg("Generating code for file %s...\n",qPrint(ctx->fd->docName()));
}
else
{
msg("Parsing code for file %s...\n",qPrint(ctx->fd->docName()));
}
StringVector filesInSameTu;
ctx->fd->getAllIncludeFilesRecursively(filesInSameTu);
if (ctx->generateSourceFile) // sources need to be shown in the output
Expand Down Expand Up @@ -7993,15 +8144,56 @@ static void generateFileDocs()

if (!Doxygen::inputNameLinkedMap->empty())
{
for (const auto &fn : *Doxygen::inputNameLinkedMap)
std::size_t numThreads = static_cast<std::size_t>(Config_getInt(NUM_PROC_THREADS));
if (numThreads==0)
{
for (const auto &fd : *fn)
numThreads = std::thread::hardware_concurrency();
}
if (numThreads>1) // multi threaded processing
{
struct DocContext
{
bool doc = fd->isLinkableInProject();
if (doc)
DocContext(FileDef *fd_,OutputList ol_)
: fd(fd_), ol(ol_) {}
FileDef *fd;
OutputList ol;
};
ThreadPool threadPool(numThreads);
std::vector< std::future< std::shared_ptr<DocContext> > > results;
for (const auto &fn : *Doxygen::inputNameLinkedMap)
{
for (const auto &fd : *fn)
{
msg("Generating docs for file %s...\n",qPrint(fd->docName()));
fd->writeDocumentation(*g_outputList);
bool doc = fd->isLinkableInProject();
if (doc)
{
auto ctx = std::make_shared<DocContext>(fd.get(),*g_outputList);
auto processFile = [ctx]() {
msg("Generating docs for file %s...\n",qPrint(ctx->fd->docName()));
ctx->fd->writeDocumentation(ctx->ol);
return ctx;
};
results.emplace_back(threadPool.queue(processFile));
}
}
}
for (auto &f : results)
{
auto ctx = f.get();
}
}
else // single threaded processing
{
for (const auto &fn : *Doxygen::inputNameLinkedMap)
{
for (const auto &fd : *fn)
{
bool doc = fd->isLinkableInProject();
if (doc)
{
msg("Generating docs for file %s...\n",qPrint(fd->docName()));
fd->writeDocumentation(*g_outputList);
}
}
}
}
Expand Down Expand Up @@ -8479,6 +8671,9 @@ static void findSectionsInDocumentation()
if (Doxygen::mainPage) Doxygen::mainPage->findSectionsInDocumentation();
}

//----------------------------------------------------------------------


static void flushCachedTemplateRelations()
{
// remove all references to classes from the cache
Expand Down Expand Up @@ -11821,6 +12016,7 @@ void parseInput()

g_s.begin("Adding members to index pages...\n");
addMembersToIndex();
addToIndices();
g_s.end();

g_s.begin("Correcting members for VHDL...\n");
Expand Down
7 changes: 0 additions & 7 deletions src/filedef.cpp
Expand Up @@ -876,13 +876,6 @@ void FileDefImpl::writeDocumentation(OutputList &ol)
ol.enableAll();
}

if (Doxygen::searchIndex)
{
Doxygen::searchIndex->setCurrentDoc(this,anchor(),FALSE);
Doxygen::searchIndex->addWord(localName(),TRUE);
}


//---------------------------------------- start flexible part -------------------------------

SrcLangExt lang = getLanguage();
Expand Down

0 comments on commit f74a0c5

Please sign in to comment.