Skip to content

Commit

Permalink
Refactoring: prepare output generators for multi-threaded use
Browse files Browse the repository at this point in the history
  • Loading branch information
doxygen committed Sep 27, 2020
1 parent 55e15c8 commit cfdabb5
Show file tree
Hide file tree
Showing 36 changed files with 872 additions and 756 deletions.
8 changes: 5 additions & 3 deletions addon/doxyapp/doxyapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ class XRefDummyCodeGenerator : public CodeOutputInterface
void writeCodeAnchor(const char *) {}
void setCurrentDoc(const Definition *,const char *,bool) {}
void addWord(const char *,bool) {}
void startCodeFragment(const char *) {}
void endCodeFragment() {}

// here we are presented with the symbols found by the code parser
void linkableSymbol(int l, const char *sym,Definition *symDef,Definition *context)
Expand Down Expand Up @@ -109,19 +111,19 @@ class XRefDummyCodeGenerator : public CodeOutputInterface
static void findXRefSymbols(FileDef *fd)
{
// get the interface to a parser that matches the file extension
CodeParserInterface &intf=Doxygen::parserManager->getCodeParser(fd->getDefFileExtension());
auto intf=Doxygen::parserManager->getCodeParser(fd->getDefFileExtension());

// get the programming language from the file name
SrcLangExt lang = getLanguageFromFileName(fd->name());

// reset the parsers state
intf.resetCodeParserState();
intf->resetCodeParserState();

// create a new backend object
XRefDummyCodeGenerator *xrefGen = new XRefDummyCodeGenerator(fd);

// parse the source code
intf.parseCode(*xrefGen,
intf->parseCode(*xrefGen,
0,
fileToString(fd->absFilePath()),
lang,
Expand Down
8 changes: 5 additions & 3 deletions addon/doxyparse/doxyparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ class Doxyparse : public CodeOutputInterface
void startCodeLine(bool) {}
void setCurrentDoc(const Definition *,const char *,bool) {}
void addWord(const char *,bool) {}
void startCodeFragment(const char *) {}
void endCodeFragment() {}

void linkableSymbol(int l, const char *sym, Definition *symDef, Definition *context)
{
Expand All @@ -90,19 +92,19 @@ static bool is_c_code = true;
static void findXRefSymbols(FileDef *fd)
{
// get the interface to a parser that matches the file extension
CodeParserInterface &intf=Doxygen::parserManager->getCodeParser(fd->getDefFileExtension());
auto intf=Doxygen::parserManager->getCodeParser(fd->getDefFileExtension());

// get the programming language from the file name
SrcLangExt lang = getLanguageFromFileName(fd->name());

// reset the parsers state
intf.resetCodeParserState();
intf->resetCodeParserState();

// create a new backend object
Doxyparse *parse = new Doxyparse(fd);

// parse the source code
intf.parseCode(*parse, 0, fileToString(fd->absFilePath()), lang, FALSE, 0, fd);
intf->parseCode(*parse, 0, fileToString(fd->absFilePath()), lang, FALSE, 0, fd);

// dismiss the object.
delete parse;
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ add_library(doxymain STATIC
docgroup.cpp
docparser.cpp
docsets.cpp
docvisitor.cpp
dot.cpp
dotcallgraph.cpp
dotclassgraph.cpp
Expand Down
32 changes: 22 additions & 10 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1301,23 +1301,23 @@ static TemplateVariant parseDoc(const Definition *def,const QCString &file,int l
static TemplateVariant parseCode(MemberDef *md,const QCString &scopeName,const QCString &relPath,
const QCString &code,int startLine=-1,int endLine=-1,bool showLineNumbers=FALSE)
{
CodeParserInterface &intf = Doxygen::parserManager->getCodeParser(md->getDefFileExtension());
intf.resetCodeParserState();
auto intf = Doxygen::parserManager->getCodeParser(md->getDefFileExtension());
intf->resetCodeParserState();
QGString s;
FTextStream t(&s);
switch (g_globals.outputFormat)
{
case ContextOutputFormat_Html:
{
HtmlCodeGenerator codeGen(t,relPath);
intf.parseCode(codeGen,scopeName,code,md->getLanguage(),FALSE,0,md->getBodyDef(),
intf->parseCode(codeGen,scopeName,code,md->getLanguage(),FALSE,0,md->getBodyDef(),
startLine,endLine,TRUE,md,showLineNumbers,md);
}
break;
case ContextOutputFormat_Latex:
{
LatexCodeGenerator codeGen(t,relPath,md->docFile());
intf.parseCode(codeGen,scopeName,code,md->getLanguage(),FALSE,0,md->getBodyDef(),
intf->parseCode(codeGen,scopeName,code,md->getLanguage(),FALSE,0,md->getBodyDef(),
startLine,endLine,TRUE,md,showLineNumbers,md);
}
break;
Expand All @@ -1332,16 +1332,16 @@ static TemplateVariant parseCode(MemberDef *md,const QCString &scopeName,const Q
static TemplateVariant parseCode(const FileDef *fd,const QCString &relPath)
{
static bool filterSourceFiles = Config_getBool(FILTER_SOURCE_FILES);
CodeParserInterface &intf = Doxygen::parserManager->getCodeParser(fd->getDefFileExtension());
intf.resetCodeParserState();
auto intf = Doxygen::parserManager->getCodeParser(fd->getDefFileExtension());
intf->resetCodeParserState();
QGString s;
FTextStream t(&s);
switch (g_globals.outputFormat)
{
case ContextOutputFormat_Html:
{
HtmlCodeGenerator codeGen(t,relPath);
intf.parseCode(codeGen,0,
intf->parseCode(codeGen,0,
fileToString(fd->absFilePath(),filterSourceFiles,TRUE), // the sources
fd->getLanguage(), // lang
FALSE, // isExampleBlock
Expand All @@ -1360,7 +1360,7 @@ static TemplateVariant parseCode(const FileDef *fd,const QCString &relPath)
case ContextOutputFormat_Latex:
{
LatexCodeGenerator codeGen(t,relPath,fd->docFile());
intf.parseCode(codeGen,0,
intf->parseCode(codeGen,0,
fileToString(fd->absFilePath(),filterSourceFiles,TRUE), // the sources
fd->getLanguage(), // lang
FALSE, // isExampleBlock
Expand Down Expand Up @@ -3896,13 +3896,25 @@ class TextGeneratorLatex : public TextGeneratorIntf
if (f && anchor) m_ts << "_";
if (anchor) m_ts << anchor;
m_ts << "}{";
filterLatexString(m_ts,text);
filterLatexString(m_ts,text,
false, // insideTabbing
false, // insidePre
false, // insideItem
false, // insideTable
false // keepSpaces
);
m_ts << "}}";
}
else
{
m_ts << "\\textbf{ ";
filterLatexString(m_ts,text);
filterLatexString(m_ts,text,
false, // insideTabbing
false, // insidePre
false, // insideItem
false, // insideTable
false // keepSpaces
);
m_ts << "}";
}
}
Expand Down
32 changes: 16 additions & 16 deletions src/definition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1236,26 +1236,26 @@ void DefinitionImpl::writeInlineCode(OutputList &ol,const char *scopeName) const
{
//printf("Adding code fragment '%s' ext='%s'\n",
// codeFragment.data(),m_impl->defFileExt.data());
CodeParserInterface &intf = Doxygen::parserManager->getCodeParser(m_impl->defFileExt);
intf.resetCodeParserState();
auto intf = Doxygen::parserManager->getCodeParser(m_impl->defFileExt);
intf->resetCodeParserState();
//printf("Read:\n'%s'\n\n",codeFragment.data());
const MemberDef *thisMd = 0;
if (definitionType()==TypeMember) thisMd = dynamic_cast <const MemberDef*>(this);

ol.startCodeFragment();
intf.parseCode(ol, // codeOutIntf
scopeName, // scope
codeFragment, // input
m_impl->lang, // lang
FALSE, // isExample
0, // exampleName
m_impl->body->fileDef, // fileDef
actualStart, // startLine
actualEnd, // endLine
TRUE, // inlineFragment
thisMd, // memberDef
TRUE // show line numbers
);
ol.startCodeFragment("DoxyCode");
intf->parseCode(ol, // codeOutIntf
scopeName, // scope
codeFragment, // input
m_impl->lang, // lang
FALSE, // isExample
0, // exampleName
m_impl->body->fileDef, // fileDef
actualStart, // startLine
actualEnd, // endLine
TRUE, // inlineFragment
thisMd, // memberDef
TRUE // show line numbers
);
ol.endCodeFragment();
}
}
Expand Down
34 changes: 13 additions & 21 deletions src/docbookgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,18 +242,23 @@ void DocbookCodeGenerator::finish()
{
endCodeLine();
}
void DocbookCodeGenerator::startCodeFragment()
void DocbookCodeGenerator::startCodeFragment(const char *)
{
m_t << "<literallayout><computeroutput>" << endl;
DB_GEN_C
m_t << "<programlisting>";
}

void DocbookCodeGenerator::endCodeFragment()
{
DB_GEN_C
//endCodeLine checks is there is still an open code line, if so closes it.
endCodeLine();

m_t << "</computeroutput></literallayout>" << endl;
m_t << "</programlisting>";
}

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

DocbookGenerator::DocbookGenerator() : OutputGenerator(Config_getString(DOCBOOK_OUTPUT))
{
DB_GEN_C
Expand Down Expand Up @@ -732,12 +737,12 @@ void DocbookGenerator::endMemberItem()
DB_GEN_C
t << "</para>" << endl;
}
void DocbookGenerator::startBold(void)
void DocbookGenerator::startBold()
{
DB_GEN_C
t << "<emphasis role=\"strong\">";
}
void DocbookGenerator::endBold(void)
void DocbookGenerator::endBold()
{
DB_GEN_C
t << "</emphasis>";
Expand All @@ -755,7 +760,7 @@ DB_GEN_C2("extraIndentLevel " << extraIndentLevel)
t << "<section>" << endl;
t << "<title>";
}
void DocbookGenerator::writeRuler(void)
void DocbookGenerator::writeRuler()
{
DB_GEN_C2("m_inLevel " << m_inLevel)
DB_GEN_C2("m_inGroup " << m_inGroup)
Expand Down Expand Up @@ -945,12 +950,12 @@ void DocbookGenerator::endExamples()
DB_GEN_C
t << "</simplesect>" << endl;
}
void DocbookGenerator::startSubsubsection(void)
void DocbookGenerator::startSubsubsection()
{
DB_GEN_C
t << "<simplesect><title>";
}
void DocbookGenerator::endSubsubsection(void)
void DocbookGenerator::endSubsubsection()
{
DB_GEN_C
t << "</title></simplesect>" << endl;
Expand Down Expand Up @@ -995,19 +1000,6 @@ DB_GEN_C
if (closeBracket) t << ")";
}
}
void DocbookGenerator::startCodeFragment()
{
DB_GEN_C
t << "<programlisting>";
}
void DocbookGenerator::endCodeFragment()
{
DB_GEN_C
//endCodeLine checks is there is still an open code line, if so closes it.
endCodeLine();

t << "</programlisting>";
}
void DocbookGenerator::startMemberTemplateParams()
{
DB_GEN_C
Expand Down
Loading

0 comments on commit cfdabb5

Please sign in to comment.