From 3bda58a7b7b4f9094c2fcb2bad71c7174367605e Mon Sep 17 00:00:00 2001 From: Dimitri van Heesch Date: Tue, 3 Dec 2019 20:54:36 +0100 Subject: Split language parser into "outline parser" and "code parser" --- addon/doxyapp/doxyapp.cpp | 6 +-- addon/doxyparse/doxyparse.cpp | 6 +-- src/code.h | 33 +++++++----- src/code.l | 14 +++-- src/commentscan.h | 4 +- src/commentscan.l | 4 +- src/context.cpp | 16 +++--- src/definition.cpp | 30 +++++------ src/docbookvisitor.cpp | 24 ++++----- src/doxygen.cpp | 83 +++++++++++++++++++----------- src/filedef.cpp | 14 ++--- src/fileparser.cpp | 2 +- src/fileparser.h | 12 ++--- src/fortrancode.h | 46 ++++++++++++++--- src/fortrancode.l | 30 +++++++++++ src/fortranscanner.h | 30 +++-------- src/fortranscanner.l | 36 +++---------- src/htmldocvisitor.cpp | 24 ++++----- src/latexdocvisitor.cpp | 24 ++++----- src/mandocvisitor.cpp | 24 ++++----- src/markdown.cpp | 45 +++-------------- src/markdown.h | 22 +------- src/memberdef.cpp | 6 +-- src/parserintf.h | 115 ++++++++++++++++++++++++++++-------------- src/pycode.h | 29 ++++++++--- src/pycode.l | 29 +++++++++++ src/pyscanner.h | 19 +------ src/pyscanner.l | 34 ++----------- src/rtfdocvisitor.cpp | 24 ++++----- src/scanner.h | 25 ++------- src/scanner.l | 49 ++++-------------- src/sqlcode.h | 31 +++++++++--- src/sqlcode.l | 30 +++++++++++ src/sqlscanner.h | 65 ------------------------ src/tclscanner.h | 10 ++-- src/tclscanner.l | 68 +++++++++++++------------ src/vhdlcode.h | 31 +++++++++--- src/vhdlcode.l | 22 +++++--- src/vhdldocgen.cpp | 51 +++---------------- src/vhdljjparser.cpp | 6 +-- src/vhdljjparser.h | 26 ++-------- src/xmlcode.h | 31 +++++++++--- src/xmlcode.l | 28 ++++++++++ src/xmldocvisitor.cpp | 24 ++++----- src/xmlgen.cpp | 6 +-- src/xmlscanner.h | 65 ------------------------ 46 files changed, 642 insertions(+), 711 deletions(-) delete mode 100644 src/sqlscanner.h delete mode 100644 src/xmlscanner.h diff --git a/addon/doxyapp/doxyapp.cpp b/addon/doxyapp/doxyapp.cpp index c18f907..edd39e3 100644 --- a/addon/doxyapp/doxyapp.cpp +++ b/addon/doxyapp/doxyapp.cpp @@ -109,19 +109,19 @@ class XRefDummyCodeGenerator : public CodeOutputInterface static void findXRefSymbols(FileDef *fd) { // get the interface to a parser that matches the file extension - ParserInterface *pIntf=Doxygen::parserManager->getParser(fd->getDefFileExtension()); + CodeParserInterface &intf=Doxygen::parserManager->getCodeParser(fd->getDefFileExtension()); // get the programming language from the file name SrcLangExt lang = getLanguageFromFileName(fd->name()); // reset the parsers state - pIntf->resetCodeParserState(); + intf.resetCodeParserState(); // create a new backend object XRefDummyCodeGenerator *xrefGen = new XRefDummyCodeGenerator(fd); // parse the source code - pIntf->parseCode(*xrefGen, + intf.parseCode(*xrefGen, 0, fileToString(fd->absFilePath()), lang, diff --git a/addon/doxyparse/doxyparse.cpp b/addon/doxyparse/doxyparse.cpp index 415354d..59b560f 100644 --- a/addon/doxyparse/doxyparse.cpp +++ b/addon/doxyparse/doxyparse.cpp @@ -89,19 +89,19 @@ static bool is_c_code = true; static void findXRefSymbols(FileDef *fd) { // get the interface to a parser that matches the file extension - ParserInterface *pIntf=Doxygen::parserManager->getParser(fd->getDefFileExtension()); + CodeParserInterface &intf=Doxygen::parserManager->getCodeParser(fd->getDefFileExtension()); // get the programming language from the file name SrcLangExt lang = getLanguageFromFileName(fd->name()); // reset the parsers state - pIntf->resetCodeParserState(); + intf.resetCodeParserState(); // create a new backend object Doxyparse *parse = new Doxyparse(fd); // parse the source code - pIntf->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; diff --git a/src/code.h b/src/code.h index a86ecc0..42265ad 100644 --- a/src/code.h +++ b/src/code.h @@ -18,28 +18,37 @@ #ifndef CODE_H #define CODE_H -#include "types.h" +#include "parserintf.h" -class CodeOutputInterface; class FileDef; class MemberDef; class QCString; class Definition; -class CodeScanner +class CCodeParser : public CodeParserInterface { public: - CodeScanner(); - virtual ~CodeScanner(); - void parseCCode(CodeOutputInterface &,const char *,const QCString &, - SrcLangExt lang, bool isExample, const char *exName,FileDef *fd, - int startLine,int endLine,bool inlineFragment, - const MemberDef *memberDef,bool showLineNumbers,const Definition *searchCtx, - bool collectXRefs); - void reset(); + CCodeParser(); + virtual ~CCodeParser(); + void parseCode(CodeOutputInterface &codeOutIntf, + const char *scopeName, + const QCString &input, + SrcLangExt lang, + bool isExampleBlock, + const char *exampleName=0, + FileDef *fileDef=0, + int startLine=-1, + int endLine=-1, + bool inlineFragment=FALSE, + const MemberDef *memberDef=0, + bool showLineNumbers=TRUE, + const Definition *searchCtx=0, + bool collectXRefs=TRUE + ); + void resetCodeParserState(); private: struct Private; - Private *p; + std::unique_ptr p; }; #endif diff --git a/src/code.l b/src/code.l index bab6b0c..2ebc09d 100644 --- a/src/code.l +++ b/src/code.l @@ -3861,25 +3861,23 @@ static void restoreObjCContext(yyscan_t yyscanner) } } -struct CodeScanner::Private +struct CCodeParser::Private { yyscan_t yyscanner; codeYY_state state; }; -CodeScanner::CodeScanner() +CCodeParser::CCodeParser() : p(std::make_unique()) { - p = new Private; codeYYlex_init_extra(&p->state,&p->yyscanner); } -CodeScanner::~CodeScanner() +CCodeParser::~CCodeParser() { codeYYlex_destroy(p->yyscanner); - delete p; } -void CodeScanner::reset() +void CCodeParser::resetCodeParserState() { struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner; //printf("***CodeParser::reset()\n"); @@ -3895,7 +3893,7 @@ void CodeScanner::reset() yyextra->anchorCount = 0; } -void CodeScanner::parseCCode(CodeOutputInterface &od,const char *className,const QCString &s, +void CCodeParser::parseCode(CodeOutputInterface &od,const char *className,const QCString &s, SrcLangExt lang,bool exBlock, const char *exName,FileDef *fd, int startLine,int endLine,bool inlineFragment, const MemberDef *memberDef,bool showLineNumbers,const Definition *searchCtx, @@ -3912,7 +3910,7 @@ void CodeScanner::parseCCode(CodeOutputInterface &od,const char *className,const if (yyextra->codeClassSDict==0) { - reset(); + resetCodeParserState(); } yyextra->code = &od; yyextra->inputString = s; diff --git a/src/commentscan.h b/src/commentscan.h index 7d2189f..f471890 100644 --- a/src/commentscan.h +++ b/src/commentscan.h @@ -19,7 +19,7 @@ #include "types.h" class Entry; -class ParserInterface; +class OutlineParserInterface; /** @file * @brief Interface for the comment block parser */ @@ -72,7 +72,7 @@ QCString preprocessCommentBlock(const QCString &comment, * where to proceed parsing. FALSE indicates no further processing is * needed. */ -bool parseCommentBlock(ParserInterface *parser, +bool parseCommentBlock(OutlineParserInterface *parser, Entry *curEntry, const QCString &comment, const QCString &fileName, diff --git a/src/commentscan.l b/src/commentscan.l index 2b10f87..fa454e5 100644 --- a/src/commentscan.l +++ b/src/commentscan.l @@ -395,7 +395,7 @@ class GuardedSection * statics */ -static ParserInterface *langParser; // the language parser that is calling us +static OutlineParserInterface *langParser; // the language parser that is calling us static QCString inputString; // input string static int inputPosition; // read pointer static QCString yyFileName; // file name that is read from @@ -3127,7 +3127,7 @@ QCString preprocessCommentBlock(const QCString &comment, } } -bool parseCommentBlock(/* in */ ParserInterface *parser, +bool parseCommentBlock(/* in */ OutlineParserInterface *parser, /* in */ Entry *curEntry, /* in */ const QCString &comment, /* in */ const QCString &fileName, diff --git a/src/context.cpp b/src/context.cpp index ebe6857..476c15e 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -1302,8 +1302,8 @@ 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) { - ParserInterface *pIntf = Doxygen::parserManager->getParser(md->getDefFileExtension()); - pIntf->resetCodeParserState(); + CodeParserInterface &intf = Doxygen::parserManager->getCodeParser(md->getDefFileExtension()); + intf.resetCodeParserState(); QGString s; FTextStream t(&s); switch (g_globals.outputFormat) @@ -1311,14 +1311,14 @@ static TemplateVariant parseCode(MemberDef *md,const QCString &scopeName,const Q case ContextOutputFormat_Html: { HtmlCodeGenerator codeGen(t,relPath); - pIntf->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()); - pIntf->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; @@ -1333,8 +1333,8 @@ 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); - ParserInterface *pIntf = Doxygen::parserManager->getParser(fd->getDefFileExtension()); - pIntf->resetCodeParserState(); + CodeParserInterface &intf = Doxygen::parserManager->getCodeParser(fd->getDefFileExtension()); + intf.resetCodeParserState(); QGString s; FTextStream t(&s); switch (g_globals.outputFormat) @@ -1342,7 +1342,7 @@ static TemplateVariant parseCode(const FileDef *fd,const QCString &relPath) case ContextOutputFormat_Html: { HtmlCodeGenerator codeGen(t,relPath); - pIntf->parseCode(codeGen,0, + intf.parseCode(codeGen,0, fileToString(fd->absFilePath(),filterSourceFiles,TRUE), // the sources fd->getLanguage(), // lang FALSE, // isExampleBlock @@ -1361,7 +1361,7 @@ static TemplateVariant parseCode(const FileDef *fd,const QCString &relPath) case ContextOutputFormat_Latex: { LatexCodeGenerator codeGen(t,relPath,fd->docFile()); - pIntf->parseCode(codeGen,0, + intf.parseCode(codeGen,0, fileToString(fd->absFilePath(),filterSourceFiles,TRUE), // the sources fd->getLanguage(), // lang FALSE, // isExampleBlock diff --git a/src/definition.cpp b/src/definition.cpp index 80060ba..9a1519e 100644 --- a/src/definition.cpp +++ b/src/definition.cpp @@ -1262,26 +1262,26 @@ void DefinitionImpl::writeInlineCode(OutputList &ol,const char *scopeName) const { //printf("Adding code fragment '%s' ext='%s'\n", // codeFragment.data(),m_impl->defFileExt.data()); - ParserInterface *pIntf = Doxygen::parserManager->getParser(m_impl->defFileExt); - pIntf->resetCodeParserState(); + CodeParserInterface &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 (this); ol.startCodeFragment(); - pIntf->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 - ); + 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(); } } diff --git a/src/docbookvisitor.cpp b/src/docbookvisitor.cpp index ce3a845..08ec4dd 100644 --- a/src/docbookvisitor.cpp +++ b/src/docbookvisitor.cpp @@ -280,8 +280,8 @@ DB_VIS_C { case DocVerbatim::Code: // fall though m_t << ""; - Doxygen::parserManager->getParser(m_langExt) - ->parseCode(m_ci,s->context(),s->text(),langExt, + Doxygen::parserManager->getCodeParser(m_langExt) + .parseCode(m_ci,s->context(),s->text(),langExt, s->isExample(),s->exampleFile()); m_t << ""; break; @@ -389,8 +389,8 @@ DB_VIS_C m_t << ""; QFileInfo cfi( inc->file() ); FileDef *fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci,inc->context(), + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), @@ -401,8 +401,8 @@ DB_VIS_C break; case DocInclude::Include: m_t << ""; - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci,inc->context(), + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), @@ -421,8 +421,8 @@ DB_VIS_C break; case DocInclude::Snippet: m_t << ""; - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci, + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, @@ -436,8 +436,8 @@ DB_VIS_C QFileInfo cfi( inc->file() ); FileDef *fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); m_t << ""; - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci, + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, @@ -489,8 +489,8 @@ DB_VIS_C fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); } - Doxygen::parserManager->getParser(locLangExt) - ->parseCode(m_ci,op->context(), + Doxygen::parserManager->getCodeParser(locLangExt) + .parseCode(m_ci,op->context(), op->text(),langExt,op->isExample(), op->exampleFile(), fd, // fileDef diff --git a/src/doxygen.cpp b/src/doxygen.cpp index 3277bbe..f29b2f8 100644 --- a/src/doxygen.cpp +++ b/src/doxygen.cpp @@ -75,10 +75,12 @@ #include "searchindex.h" #include "parserintf.h" #include "htags.h" +#include "pycode.h" #include "pyscanner.h" +#include "fortrancode.h" #include "fortranscanner.h" -#include "xmlscanner.h" -#include "sqlscanner.h" +#include "xmlcode.h" +#include "sqlcode.h" #include "tclscanner.h" #include "code.h" #include "objcache.h" @@ -8992,8 +8994,8 @@ static void generateExampleDocs() for (pdi.toFirst();(pd=pdi.current());++pdi) { msg("Generating docs for example %s...\n",pd->name().data()); - ParserInterface *pIntf = Doxygen::parserManager->getParser(".c"); // TODO: do this on code type - pIntf->resetCodeParserState(); + CodeParserInterface &intf = Doxygen::parserManager->getCodeParser(".c"); // TODO: do this on code type + intf.resetCodeParserState(); QCString n=pd->getOutputFileBase(); startFile(*g_outputList,n,n,pd->name()); startTitle(*g_outputList,n); @@ -9349,7 +9351,7 @@ static void copyExtraFiles(QStrList files,const QCString &filesOption,const QCSt //---------------------------------------------------------------------------- -static ParserInterface *getParserForFile(const char *fn) +static OutlineParserInterface &getParserForFile(const char *fn) { QCString fileName=fn; QCString extension; @@ -9364,10 +9366,10 @@ static ParserInterface *getParserForFile(const char *fn) extension = ".no_extension"; } - return Doxygen::parserManager->getParser(extension); + return Doxygen::parserManager->getOutlineParser(extension); } -static void parseFile(ParserInterface *parser, +static void parseFile(OutlineParserInterface &parser, const std::unique_ptr &root,FileDef *fd,const char *fn, bool sameTu,QStrList &filesInSameTu) { @@ -9392,7 +9394,7 @@ static void parseFile(ParserInterface *parser, BufStr preBuf(fi.size()+4096); if (Config_getBool(ENABLE_PREPROCESSING) && - parser->needsPreprocessing(extension)) + parser.needsPreprocessing(extension)) { BufStr inBuf(fi.size()+4096); msg("Preprocessing %s...\n",fn); @@ -9423,7 +9425,7 @@ static void parseFile(ParserInterface *parser, std::unique_ptr fileRoot = std::make_unique(); // use language parse to parse the file - parser->parseInput(fileName,convBuf.data(),fileRoot,sameTu,filesInSameTu); + parser.parseInput(fileName,convBuf.data(),fileRoot,sameTu,filesInSameTu); fileRoot->setFileDef(fd); root->moveToSubEntryAndKeep(fileRoot); } @@ -9455,8 +9457,8 @@ static void parseFiles(const std::unique_ptr &root) if (fd->isSource() && !fd->isReference()) // this is a source file { QStrList filesInSameTu; - ParserInterface * parser = getParserForFile(s->data()); - parser->startTranslationUnit(s->data()); + OutlineParserInterface &parser = getParserForFile(s->data()); + parser.startTranslationUnit(s->data()); parseFile(parser,root,fd,s->data(),FALSE,filesInSameTu); //printf(" got %d extra files in tu\n",filesInSameTu.count()); @@ -9478,7 +9480,7 @@ static void parseFiles(const std::unique_ptr &root) } incFile = filesInSameTu.next(); } - parser->finishTranslationUnit(); + parser.finishTranslationUnit(); g_processedFiles.insert(*s,(void*)0x8); } } @@ -9491,10 +9493,10 @@ static void parseFiles(const std::unique_ptr &root) QStrList filesInSameTu; FileDef *fd=findFileDef(Doxygen::inputNameDict,s->data(),ambig); ASSERT(fd!=0); - ParserInterface * parser = getParserForFile(s->data()); - parser->startTranslationUnit(s->data()); + OutlineParserInterface &parser = getParserForFile(s->data()); + parser.startTranslationUnit(s->data()); parseFile(parser,root,fd,s->data(),FALSE,filesInSameTu); - parser->finishTranslationUnit(); + parser.finishTranslationUnit(); g_processedFiles.insert(*s,(void*)0x8); } } @@ -9510,8 +9512,8 @@ static void parseFiles(const std::unique_ptr &root) QStrList filesInSameTu; FileDef *fd=findFileDef(Doxygen::inputNameDict,s->data(),ambig); ASSERT(fd!=0); - ParserInterface * parser = getParserForFile(s->data()); - parser->startTranslationUnit(s->data()); + OutlineParserInterface &parser = getParserForFile(s->data()); + parser.startTranslationUnit(s->data()); parseFile(parser,root,fd,s->data(),FALSE,filesInSameTu); } } @@ -10068,6 +10070,19 @@ static const char *getArg(int argc,char **argv,int &optind) //---------------------------------------------------------------------------- +/** @brief /dev/null outline parser */ +class NullOutlineParser : public OutlineParserInterface +{ + public: + void startTranslationUnit(const char *) {} + void finishTranslationUnit() {} + void parseInput(const char *, const char *,const std::unique_ptr &, bool, QStrList &) {} + bool needsPreprocessing(const QCString &) const { return FALSE; } + void parsePrototype(const char *) {} +}; + + + void initDoxygen() { initResources(); @@ -10082,18 +10097,28 @@ void initDoxygen() Doxygen::runningTime.start(); Doxygen::preprocessor = new Preprocessor(); - Doxygen::parserManager = new ParserManager; - Doxygen::parserManager->registerDefaultParser( new FileParser); - Doxygen::parserManager->registerParser("c", new CLanguageScanner); - Doxygen::parserManager->registerParser("python", new PythonLanguageScanner); - Doxygen::parserManager->registerParser("fortran", new FortranLanguageScanner); - Doxygen::parserManager->registerParser("fortranfree", new FortranLanguageScannerFree); - Doxygen::parserManager->registerParser("fortranfixed", new FortranLanguageScannerFixed); - Doxygen::parserManager->registerParser("vhdl", new VHDLLanguageScanner); - Doxygen::parserManager->registerParser("xml", new XMLScanner); - Doxygen::parserManager->registerParser("sql", new SQLScanner); - Doxygen::parserManager->registerParser("tcl", new TclLanguageScanner); - Doxygen::parserManager->registerParser("md", new MarkdownFileParser); + Doxygen::parserManager = new ParserManager( std::make_unique(), + std::make_unique()); + Doxygen::parserManager->registerParser("c", std::make_unique(), + std::make_unique()); + Doxygen::parserManager->registerParser("python", std::make_unique(), + std::make_unique()); + Doxygen::parserManager->registerParser("fortran", std::make_unique(), + std::make_unique()); + Doxygen::parserManager->registerParser("fortranfree", std::make_unique(), + std::make_unique()); + Doxygen::parserManager->registerParser("fortranfixed", std::make_unique(), + std::make_unique()); + Doxygen::parserManager->registerParser("vhdl", std::make_unique(), + std::make_unique()); + Doxygen::parserManager->registerParser("xml", std::make_unique(), + std::make_unique()); + Doxygen::parserManager->registerParser("sql", std::make_unique(), + std::make_unique()); + Doxygen::parserManager->registerParser("tcl", std::make_unique(), + std::make_unique()); + Doxygen::parserManager->registerParser("md", std::make_unique(), + std::make_unique()); // register any additional parsers here... diff --git a/src/filedef.cpp b/src/filedef.cpp index 346fb62..0be5d75 100644 --- a/src/filedef.cpp +++ b/src/filedef.cpp @@ -1233,8 +1233,8 @@ void FileDefImpl::writeSource(OutputList &ol,bool sameTu,QStrList &filesInSameTu else #endif { - ParserInterface *pIntf = Doxygen::parserManager->getParser(getDefFileExtension()); - pIntf->resetCodeParserState(); + CodeParserInterface &intf = Doxygen::parserManager->getCodeParser(getDefFileExtension()); + intf.resetCodeParserState(); ol.startCodeFragment(); bool needs2PassParsing = Doxygen::parseSourcesNeeded && // we need to parse (filtered) sources for cross-references @@ -1244,13 +1244,13 @@ void FileDefImpl::writeSource(OutputList &ol,bool sameTu,QStrList &filesInSameTu if (needs2PassParsing) { // parse code for cross-references only (see bug707641) - pIntf->parseCode(devNullIntf,0, + intf.parseCode(devNullIntf,0, fileToString(absFilePath(),TRUE,TRUE), getLanguage(), FALSE,0,this ); } - pIntf->parseCode(ol,0, + intf.parseCode(ol,0, fileToString(absFilePath(),filterSourceFiles,TRUE), getLanguage(), // lang FALSE, // isExampleBlock @@ -1295,9 +1295,9 @@ void FileDefImpl::parseSource(bool sameTu,QStrList &filesInSameTu) else #endif { - ParserInterface *pIntf = Doxygen::parserManager->getParser(getDefFileExtension()); - pIntf->resetCodeParserState(); - pIntf->parseCode( + CodeParserInterface &intf = Doxygen::parserManager->getCodeParser(getDefFileExtension()); + intf.resetCodeParserState(); + intf.parseCode( devNullIntf,0, fileToString(absFilePath(),filterSourceFiles,TRUE), getLanguage(), diff --git a/src/fileparser.cpp b/src/fileparser.cpp index 45bdc81..34085dc 100644 --- a/src/fileparser.cpp +++ b/src/fileparser.cpp @@ -16,7 +16,7 @@ #include "fileparser.h" #include "outputgen.h" -void FileParser::parseCode(CodeOutputInterface &codeOutIntf, +void FileCodeParser::parseCode(CodeOutputInterface &codeOutIntf, const char *, // scopeName const QCString & input, SrcLangExt, // lang diff --git a/src/fileparser.h b/src/fileparser.h index 3132f92..3245878 100644 --- a/src/fileparser.h +++ b/src/fileparser.h @@ -18,15 +18,11 @@ #include "parserintf.h" -/** @brief General file parser */ -class FileParser : public ParserInterface +/** @brief Generic code parser */ +class FileCodeParser : public CodeParserInterface { public: - virtual ~FileParser() {} - void startTranslationUnit(const char *) {} - void finishTranslationUnit() {} - void parseInput(const char *, const char *,const std::unique_ptr &, bool, QStrList &) {} - bool needsPreprocessing(const QCString &) const { return FALSE; } + virtual ~FileCodeParser() {} void parseCode(CodeOutputInterface &codeOutIntf, const char *scopeName, const QCString &input, @@ -43,8 +39,6 @@ class FileParser : public ParserInterface bool collectXRefs=TRUE ); void resetCodeParserState() {} - void parsePrototype(const char *) {} }; - #endif diff --git a/src/fortrancode.h b/src/fortrancode.h index 4df20a9..8391a0b 100644 --- a/src/fortrancode.h +++ b/src/fortrancode.h @@ -18,7 +18,7 @@ #ifndef FORTRANCODE_H #define FORTRANCODE_H -#include "types.h" +#include "parserintf.h" class CodeOutputInterface; class FileDef; @@ -26,13 +26,45 @@ class MemberDef; class QCString; class Definition; -void parseFortranCode(CodeOutputInterface &,const char *,const QCString &, - bool ,const char *,FileDef *fd, - int startLine,int endLine,bool inlineFragment, - const MemberDef *memberDef,bool showLineNumbers,const Definition *searchCtx, - bool collectRefs, FortranFormat format); -void resetFortranCodeParserState(); void codeFreeScanner(); const int fixedCommentAfter = 72; + +class FortranCodeParser : public CodeParserInterface +{ + public: + FortranCodeParser(FortranFormat format=FortranFormat_Unknown) : m_format(format) { } + void parseCode(CodeOutputInterface &codeOutIntf, + const char *scopeName, + const QCString &input, + SrcLangExt lang, + bool isExampleBlock, + const char *exampleName=0, + FileDef *fileDef=0, + int startLine=-1, + int endLine=-1, + bool inlineFragment=FALSE, + const MemberDef *memberDef=0, + bool showLineNumbers=TRUE, + const Definition *searchCtx=0, + bool collectXRefs=TRUE + ); + void resetCodeParserState(); + + private: + FortranFormat m_format; +}; + +class FortranCodeParserFree : public FortranCodeParser +{ + public: + FortranCodeParserFree() : FortranCodeParser(FortranFormat_Free) { } +}; + +class FortranCodeParserFixed : public FortranCodeParser +{ + public: + FortranCodeParserFixed() : FortranCodeParser(FortranFormat_Fixed) { } +}; + #endif diff --git a/src/fortrancode.l b/src/fortrancode.l index 3bbecd8..21d1fa5 100644 --- a/src/fortrancode.l +++ b/src/fortrancode.l @@ -1395,4 +1395,34 @@ void parseFortranCode(CodeOutputInterface &od,const char *,const QCString &s, return; } +//--------------------------------------------------------- + +void FortranCodeParser::parseCode(CodeOutputInterface & codeOutIntf, + const char * scopeName, + const QCString & input, + SrcLangExt /*lang*/, + bool isExampleBlock, + const char * exampleName, + FileDef * fileDef, + int startLine, + int endLine, + bool inlineFragment, + const MemberDef *memberDef, + bool showLineNumbers, + const Definition *searchCtx, + bool collectXRefs + ) +{ + ::parseFortranCode(codeOutIntf,scopeName,input,isExampleBlock,exampleName, + fileDef,startLine,endLine,inlineFragment,memberDef, + showLineNumbers,searchCtx,collectXRefs,m_format); +} + +void FortranCodeParser::resetCodeParserState() +{ + ::resetFortranCodeParserState(); +} + +//--------------------------------------------------------- + #include "fortrancode.l.h" diff --git a/src/fortranscanner.h b/src/fortranscanner.h index 6476c98..7038882 100644 --- a/src/fortranscanner.h +++ b/src/fortranscanner.h @@ -24,11 +24,10 @@ * * This is the Fortran language parser for doxygen. */ -class FortranLanguageScanner : public ParserInterface +class FortranOutlineParser : public OutlineParserInterface { public: - FortranLanguageScanner(FortranFormat format=FortranFormat_Unknown) : m_format(format) { } - virtual ~FortranLanguageScanner() {} + FortranOutlineParser(FortranFormat format=FortranFormat_Unknown) : m_format(format) { } void startTranslationUnit(const char *) {} void finishTranslationUnit() {} void parseInput(const char *fileName, @@ -37,38 +36,23 @@ class FortranLanguageScanner : public ParserInterface bool sameTranslationUnit, QStrList &filesInSameTranslationUnit); bool needsPreprocessing(const QCString &extension) const; - void parseCode(CodeOutputInterface &codeOutIntf, - const char *scopeName, - const QCString &input, - SrcLangExt lang, - bool isExampleBlock, - const char *exampleName=0, - FileDef *fileDef=0, - int startLine=-1, - int endLine=-1, - bool inlineFragment=FALSE, - const MemberDef *memberDef=0, - bool showLineNumbers=TRUE, - const Definition *searchCtx=0, - bool collectXRefs=TRUE - ); - void resetCodeParserState(); void parsePrototype(const char *text); private: FortranFormat m_format; }; -class FortranLanguageScannerFree : public FortranLanguageScanner +class FortranOutlineParserFree : public FortranOutlineParser { public: - FortranLanguageScannerFree() : FortranLanguageScanner(FortranFormat_Free) { } + FortranOutlineParserFree() : FortranOutlineParser(FortranFormat_Free) { } }; -class FortranLanguageScannerFixed : public FortranLanguageScanner +class FortranOutlineParserFixed : public FortranOutlineParser { public: - FortranLanguageScannerFixed() : FortranLanguageScanner(FortranFormat_Fixed) { } + FortranOutlineParserFixed() : FortranOutlineParser(FortranFormat_Fixed) { } }; + #endif diff --git a/src/fortranscanner.l b/src/fortranscanner.l index e0d6d63..9178f80 100644 --- a/src/fortranscanner.l +++ b/src/fortranscanner.l @@ -136,7 +136,7 @@ static const char *directionParam[] = * * statics */ -static ParserInterface *g_thisParser; +static OutlineParserInterface *g_thisParser; static const char * inputString; static int inputPosition; static bool isFixedForm; @@ -2757,7 +2757,7 @@ static void parseMain(const char *fileName,const char *fileBuf, //---------------------------------------------------------------------------- -void FortranLanguageScanner::parseInput(const char *fileName, +void FortranOutlineParser::parseInput(const char *fileName, const char *fileBuf, const std::unique_ptr &root, bool /*sameTranslationUnit*/, @@ -2772,37 +2772,11 @@ void FortranLanguageScanner::parseInput(const char *fileName, printlex(yy_flex_debug, FALSE, __FILE__, fileName); } -void FortranLanguageScanner::parseCode(CodeOutputInterface & codeOutIntf, - const char * scopeName, - const QCString & input, - SrcLangExt /*lang*/, - bool isExampleBlock, - const char * exampleName, - FileDef * fileDef, - int startLine, - int endLine, - bool inlineFragment, - const MemberDef *memberDef, - bool showLineNumbers, - const Definition *searchCtx, - bool collectXRefs - ) -{ - ::parseFortranCode(codeOutIntf,scopeName,input,isExampleBlock,exampleName, - fileDef,startLine,endLine,inlineFragment,memberDef, - showLineNumbers,searchCtx,collectXRefs,m_format); -} - -bool FortranLanguageScanner::needsPreprocessing(const QCString &extension) const +bool FortranOutlineParser::needsPreprocessing(const QCString &extension) const { return extension!=extension.lower(); // use preprocessor only for upper case extensions } -void FortranLanguageScanner::resetCodeParserState() -{ - ::resetFortranCodeParserState(); -} - -void FortranLanguageScanner::parsePrototype(const char *text) +void FortranOutlineParser::parsePrototype(const char *text) { QCString buffer = QCString(text); pushBuffer(buffer); @@ -2813,6 +2787,8 @@ void FortranLanguageScanner::parsePrototype(const char *text) popBuffer(); } +//---------------------------------------------------------------------------- + static void scanner_abort() { fprintf(stderr,"********************************************************************\n"); diff --git a/src/htmldocvisitor.cpp b/src/htmldocvisitor.cpp index 513c3a4..3dec509 100644 --- a/src/htmldocvisitor.cpp +++ b/src/htmldocvisitor.cpp @@ -518,8 +518,8 @@ void HtmlDocVisitor::visit(DocVerbatim *s) case DocVerbatim::Code: forceEndParagraph(s); m_t << PREFRAG_START; - Doxygen::parserManager->getParser(lang) - ->parseCode(m_ci, + Doxygen::parserManager->getCodeParser(lang) + .parseCode(m_ci, s->context(), s->text(), langExt, @@ -666,8 +666,8 @@ void HtmlDocVisitor::visit(DocInclude *inc) case DocInclude::Include: forceEndParagraph(inc); m_t << PREFRAG_START; - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci, + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci, inc->context(), inc->text(), langExt, @@ -690,8 +690,8 @@ void HtmlDocVisitor::visit(DocInclude *inc) m_t << PREFRAG_START; QFileInfo cfi( inc->file() ); FileDef *fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci, + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci, inc->context(), inc->text(), langExt, @@ -732,8 +732,8 @@ void HtmlDocVisitor::visit(DocInclude *inc) { forceEndParagraph(inc); m_t << PREFRAG_START; - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci, + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, @@ -757,8 +757,8 @@ void HtmlDocVisitor::visit(DocInclude *inc) m_t << PREFRAG_START; QFileInfo cfi( inc->file() ); FileDef *fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci, + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, @@ -810,8 +810,8 @@ void HtmlDocVisitor::visit(DocIncOperator *op) QFileInfo cfi( op->includeFileName() ); fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); } - Doxygen::parserManager->getParser(locLangExt) - ->parseCode( + Doxygen::parserManager->getCodeParser(locLangExt) + .parseCode( m_ci, op->context(), op->text(), diff --git a/src/latexdocvisitor.cpp b/src/latexdocvisitor.cpp index a0bbf73..5fd2e78 100644 --- a/src/latexdocvisitor.cpp +++ b/src/latexdocvisitor.cpp @@ -349,8 +349,8 @@ void LatexDocVisitor::visit(DocVerbatim *s) { m_t << "\n\\begin{DoxyCode}{" << usedTableLevels() << "}\n"; LatexCodeGenerator::setDoxyCodeOpen(TRUE); - Doxygen::parserManager->getParser(lang) - ->parseCode(m_ci,s->context(),s->text(),langExt, + Doxygen::parserManager->getCodeParser(lang) + .parseCode(m_ci,s->context(),s->text(),langExt, s->isExample(),s->exampleFile()); LatexCodeGenerator::setDoxyCodeOpen(FALSE); m_t << "\\end{DoxyCode}\n"; @@ -461,8 +461,8 @@ void LatexDocVisitor::visit(DocInclude *inc) LatexCodeGenerator::setDoxyCodeOpen(TRUE); QFileInfo cfi( inc->file() ); FileDef *fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci,inc->context(), + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), @@ -482,8 +482,8 @@ void LatexDocVisitor::visit(DocInclude *inc) case DocInclude::Include: m_t << "\n\\begin{DoxyCodeInclude}{" << usedTableLevels() << "}\n"; LatexCodeGenerator::setDoxyCodeOpen(TRUE); - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci,inc->context(), + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci,inc->context(), inc->text(),langExt,inc->isExample(), inc->exampleFile(), 0, // fileDef @@ -512,8 +512,8 @@ void LatexDocVisitor::visit(DocInclude *inc) { m_t << "\n\\begin{DoxyCodeInclude}{" << usedTableLevels() << "}\n"; LatexCodeGenerator::setDoxyCodeOpen(TRUE); - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci, + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, @@ -530,8 +530,8 @@ void LatexDocVisitor::visit(DocInclude *inc) FileDef *fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); m_t << "\n\\begin{DoxyCodeInclude}{" << usedTableLevels() << "}\n"; LatexCodeGenerator::setDoxyCodeOpen(TRUE); - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci, + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, @@ -583,8 +583,8 @@ void LatexDocVisitor::visit(DocIncOperator *op) fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); } - Doxygen::parserManager->getParser(locLangExt) - ->parseCode(m_ci,op->context(),op->text(),langExt, + Doxygen::parserManager->getCodeParser(locLangExt) + .parseCode(m_ci,op->context(),op->text(),langExt, op->isExample(),op->exampleFile(), fd, // fileDef op->line(), // startLine diff --git a/src/mandocvisitor.cpp b/src/mandocvisitor.cpp index 21e7cb9..3db556d 100644 --- a/src/mandocvisitor.cpp +++ b/src/mandocvisitor.cpp @@ -204,8 +204,8 @@ void ManDocVisitor::visit(DocVerbatim *s) if (!m_firstCol) m_t << endl; m_t << ".PP" << endl; m_t << ".nf" << endl; - Doxygen::parserManager->getParser(lang) - ->parseCode(m_ci,s->context(),s->text(), + Doxygen::parserManager->getCodeParser(lang) + .parseCode(m_ci,s->context(),s->text(), langExt, s->isExample(),s->exampleFile()); if (!m_firstCol) m_t << endl; @@ -257,8 +257,8 @@ void ManDocVisitor::visit(DocInclude *inc) m_t << ".nf" << endl; QFileInfo cfi( inc->file() ); FileDef *fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci,inc->context(), + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), @@ -281,8 +281,8 @@ void ManDocVisitor::visit(DocInclude *inc) if (!m_firstCol) m_t << endl; m_t << ".PP" << endl; m_t << ".nf" << endl; - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci,inc->context(), + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), @@ -318,8 +318,8 @@ void ManDocVisitor::visit(DocInclude *inc) if (!m_firstCol) m_t << endl; m_t << ".PP" << endl; m_t << ".nf" << endl; - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci, + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, @@ -338,8 +338,8 @@ void ManDocVisitor::visit(DocInclude *inc) m_t << ".nf" << endl; QFileInfo cfi( inc->file() ); FileDef *fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci, + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, @@ -397,8 +397,8 @@ void ManDocVisitor::visit(DocIncOperator *op) fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); } - Doxygen::parserManager->getParser(locLangExt) - ->parseCode(m_ci,op->context(),op->text(),langExt, + Doxygen::parserManager->getCodeParser(locLangExt) + .parseCode(m_ci,op->context(),op->text(),langExt, op->isExample(),op->exampleFile(), fd, // fileDef op->line(), // startLine diff --git a/src/markdown.cpp b/src/markdown.cpp index e054941..8511da3 100644 --- a/src/markdown.cpp +++ b/src/markdown.cpp @@ -2576,7 +2576,7 @@ QCString markdownFileNameToId(const QCString &fileName) } -void MarkdownFileParser::parseInput(const char *fileName, +void MarkdownOutlineParser::parseInput(const char *fileName, const char *fileBuf, const std::unique_ptr &root, bool /*sameTranslationUnit*/, @@ -2660,47 +2660,14 @@ void MarkdownFileParser::parseInput(const char *fileName, g_indentLevel=0; } -void MarkdownFileParser::parseCode(CodeOutputInterface &codeOutIntf, - const char *scopeName, - const QCString &input, - SrcLangExt lang, - bool isExampleBlock, - const char *exampleName, - FileDef *fileDef, - int startLine, - int endLine, - bool inlineFragment, - const MemberDef *memberDef, - bool showLineNumbers, - const Definition *searchCtx, - bool collectXRefs - ) +void MarkdownOutlineParser::parsePrototype(const char *text) { - ParserInterface *pIntf = Doxygen::parserManager->getParser("*.cpp"); - if (pIntf!=this) + OutlineParserInterface &intf = Doxygen::parserManager->getOutlineParser("*.cpp"); + if (&intf!=this) { - pIntf->parseCode( - codeOutIntf,scopeName,input,lang,isExampleBlock,exampleName, - fileDef,startLine,endLine,inlineFragment,memberDef,showLineNumbers, - searchCtx,collectXRefs); + intf.parsePrototype(text); } } -void MarkdownFileParser::resetCodeParserState() -{ - ParserInterface *pIntf = Doxygen::parserManager->getParser("*.cpp"); - if (pIntf!=this) - { - pIntf->resetCodeParserState(); - } -} - -void MarkdownFileParser::parsePrototype(const char *text) -{ - ParserInterface *pIntf = Doxygen::parserManager->getParser("*.cpp"); - if (pIntf!=this) - { - pIntf->parsePrototype(text); - } -} +//------------------------------------------------------------------------ diff --git a/src/markdown.h b/src/markdown.h index 2c9a496..4ce2f62 100644 --- a/src/markdown.h +++ b/src/markdown.h @@ -25,10 +25,10 @@ class Entry; QCString processMarkdown(const QCString &fileName,const int lineNr,Entry *e,const QCString &s); QCString markdownFileNameToId(const QCString &fileName); -class MarkdownFileParser : public ParserInterface +class MarkdownOutlineParser : public OutlineParserInterface { public: - virtual ~MarkdownFileParser() {} + virtual ~MarkdownOutlineParser() {} void startTranslationUnit(const char *) {} void finishTranslationUnit() {} void parseInput(const char *fileName, @@ -37,26 +37,8 @@ class MarkdownFileParser : public ParserInterface bool sameTranslationUnit, QStrList &filesInSameTranslationUnit); bool needsPreprocessing(const QCString &) const { return FALSE; } - void parseCode(CodeOutputInterface &codeOutIntf, - const char *scopeName, - const QCString &input, - SrcLangExt lang, - bool isExampleBlock, - const char *exampleName=0, - FileDef *fileDef=0, - int startLine=-1, - int endLine=-1, - bool inlineFragment=FALSE, - const MemberDef *memberDef=0, - bool showLineNumbers=TRUE, - const Definition *searchCtx=0, - bool collectXRefs=TRUE - ); - void resetCodeParserState(); void parsePrototype(const char *text); }; - - #endif diff --git a/src/memberdef.cpp b/src/memberdef.cpp index 840dd78..40d596c 100644 --- a/src/memberdef.cpp +++ b/src/memberdef.cpp @@ -3707,10 +3707,10 @@ void MemberDefImpl::writeDocumentation(const MemberList *ml, else ol.parseText(theTranslator->trInitialValue()); ol.endBold(); - ParserInterface *pIntf = Doxygen::parserManager->getParser(getDefFileExtension()); - pIntf->resetCodeParserState(); + CodeParserInterface &intf = Doxygen::parserManager->getCodeParser(getDefFileExtension()); + intf.resetCodeParserState(); ol.startCodeFragment(); - pIntf->parseCode(ol,scopeName,m_impl->initializer,lang,FALSE,0,const_cast(getFileDef()), + intf.parseCode(ol,scopeName,m_impl->initializer,lang,FALSE,0,const_cast(getFileDef()), -1,-1,TRUE,this,FALSE,this); ol.endCodeFragment(); } diff --git a/src/parserintf.h b/src/parserintf.h index c0939c9..4be8aee 100644 --- a/src/parserintf.h +++ b/src/parserintf.h @@ -18,10 +18,11 @@ #ifndef PARSERINTF_H #define PARSERINTF_H -#include #include #include +#include +#include #include "types.h" @@ -31,16 +32,16 @@ class CodeOutputInterface; class MemberDef; class Definition; -/** \brief Abstract interface for programming language parsers. +/** \brief Abstract interface for outline parsers. * * By implementing the methods of this interface one can add - * a new language parser to doxygen. The parser can make use of the + * a new language parser to doxygen. The parser implementation can make use of the * comment block parser to parse the contents of special comment blocks. */ -class ParserInterface +class OutlineParserInterface { public: - virtual ~ParserInterface() {} + virtual ~OutlineParserInterface() {} /** Starts processing a translation unit (source files + headers). * After this call parseInput() is called with sameTranslationUnit @@ -80,6 +81,27 @@ class ParserInterface */ virtual bool needsPreprocessing(const QCString &extension) const = 0; + /** Callback function called by the comment block scanner. + * It provides a string \a text containing the prototype of a function + * or variable. The parser should parse this and store the information + * in the Entry node that corresponds with the node for which the + * comment block parser was invoked. + */ + virtual void parsePrototype(const char *text) = 0; + +}; + +/** \brief Abstract interface for code parsers. + * + * By implementing the methods of this interface one can add + * a new language parser to doxygen. This interface is used for + * syntax highlighting, but also to extract cross references and call graphs. + */ +class CodeParserInterface +{ + public: + virtual ~CodeParserInterface() {} + /** Parses a source file or fragment with the goal to produce * highlighted and cross-referenced output. * @param[in] codeOutIntf Abstract interface for writing the result. @@ -125,14 +147,6 @@ class ParserInterface */ virtual void resetCodeParserState() = 0; - /** Callback function called by the comment block scanner. - * It provides a string \a text containing the prototype of a function - * or variable. The parser should parse this and store the information - * in the Entry node that corresponds with the node for which the - * comment block parser was invoked. - */ - virtual void parsePrototype(const char *text) = 0; - }; //----------------------------------------------------------------------------- @@ -145,18 +159,22 @@ class ParserInterface class ParserManager { public: - /** Creates the parser manager object. - */ - ParserManager() - : m_defaultParser(0) { m_parsers.setAutoDelete(TRUE); } - ~ParserManager() + struct ParserPair { - delete m_defaultParser; - } + ParserPair(std::unique_ptr oli, + std::unique_ptr cpi) noexcept + : outlineParser(std::move(oli)), codeParser(std::move(cpi)) + { + } - void registerDefaultParser(ParserInterface *parser) + std::unique_ptr outlineParser; + std::unique_ptr codeParser; + }; + + ParserManager(std::unique_ptr outlineParser, + std::unique_ptr codeParser) + : m_defaultParsers(std::move(outlineParser),std::move(codeParser)) { - m_defaultParser = parser; } /** Registers an additional parser. @@ -165,9 +183,11 @@ class ParserManager * @param[in] parser The parser that is to be used for the * given name. */ - void registerParser(const char *name,ParserInterface *parser) + void registerParser(const char *name,std::unique_ptr outlineParser, + std::unique_ptr codeParser) { - m_parsers.insert(name,parser); + m_parsers.emplace(std::string(name), + ParserPair(std::move(outlineParser),std::move(codeParser))); } /** Registers a file \a extension with a parser with name \a parserName. @@ -176,13 +196,16 @@ class ParserManager bool registerExtension(const char *extension, const char *parserName) { if (parserName==0 || extension==0) return FALSE; - ParserInterface *intf = m_parsers.find(parserName); - if (intf==0) return FALSE; - if (m_extensions.find(extension)!=0) // extension already exists + + const auto &parserIt = m_parsers.find(parserName); + if (parserIt == m_parsers.end()) return FALSE; + + auto extensionIt = m_extensions.find(extension); + if (extensionIt != m_extensions.end()) // extension already exists { - m_extensions.remove(extension); // remove it + m_extensions.erase(extensionIt); // remove it (e.g. user specified extension overrules built in one) } - m_extensions.insert(extension,intf); // add new mapping + m_extensions.emplace(std::string(extension),parserIt->second); // add new mapping return TRUE; } @@ -190,22 +213,36 @@ class ParserManager * If there is no parser explicitly registered for the supplied extension, * the interface to the default parser will be returned. */ - ParserInterface *getParser(const char *extension) + OutlineParserInterface &getOutlineParser(const char *extension) { - QCString ext = QCString(extension).lower(); + return *getParsers(extension).outlineParser; + } + + /** Gets the interface to the parser associated with given \a extension. + * If there is no parser explicitly registered for the supplied extension, + * the interface to the default parser will be returned. + */ + CodeParserInterface &getCodeParser(const char *extension) + { + return *getParsers(extension).codeParser; + } + + private: + ParserPair &getParsers(const char *extension) + { + QCString ext = QCString(extension).lower().data(); if (ext.isEmpty()) ext=".no_extension"; - ParserInterface *intf = m_extensions.find(ext); - if (intf==0 && ext.length()>4) + auto it = m_extensions.find(ext.data()); + if (it==m_extensions.end() && ext.length()>4) { - intf = m_extensions.find(ext.left(4)); + it = m_extensions.find(ext.left(4).data()); } - return intf ? intf : m_defaultParser; + return it!=m_extensions.end() ? it->second : m_defaultParsers; } - private: - QDict m_parsers; - QDict m_extensions; - ParserInterface *m_defaultParser; + std::map m_parsers; + std::map m_extensions; + ParserPair m_defaultParsers; }; #endif diff --git a/src/pycode.h b/src/pycode.h index de0a8a9..e3a01b4 100644 --- a/src/pycode.h +++ b/src/pycode.h @@ -25,7 +25,7 @@ #ifndef PYCODE_H #define PYCODE_H -#include "types.h" +#include "parserintf.h" class CodeOutputInterface; class FileDef; @@ -33,11 +33,26 @@ class MemberDef; class QCString; class Definition; -extern void parsePythonCode(CodeOutputInterface &,const char *,const QCString &, - bool ,const char *,FileDef *fd, - int startLine,int endLine,bool inlineFragment, - const MemberDef *memberDef,bool showLineNumbers,const Definition *searchCtx, - bool collectXRefs); -extern void resetPythonCodeParserState(); +class PythonCodeParser : public CodeParserInterface +{ + public: + void parseCode(CodeOutputInterface &codeOutIntf, + const char *scopeName, + const QCString &input, + SrcLangExt lang, + bool isExampleBlock, + const char *exampleName=0, + FileDef *fileDef=0, + int startLine=-1, + int endLine=-1, + bool inlineFragment=FALSE, + const MemberDef *memberDef=0, + bool showLineNumbers=TRUE, + const Definition *searchCtx=0, + bool collectXrefs=TRUE + ); + void resetCodeParserState(); +}; + #endif diff --git a/src/pycode.l b/src/pycode.l index 4e53a27..f7e255f 100644 --- a/src/pycode.l +++ b/src/pycode.l @@ -1638,4 +1638,33 @@ void parsePythonCode(CodeOutputInterface &od,const char * /*className*/, return; } +//---------------------------------------------------------------------------- + +void PythonCodeParser::parseCode(CodeOutputInterface &codeOutIntf, + const char *scopeName, + const QCString &input, + SrcLangExt /*lang*/, + bool isExampleBlock, + const char *exampleName, + FileDef *fileDef, + int startLine, + int endLine, + bool inlineFragment, + const MemberDef *memberDef, + bool showLineNumbers, + const Definition *searchCtx, + bool collectXRefs + ) +{ + ::parsePythonCode(codeOutIntf,scopeName,input,isExampleBlock,exampleName, + fileDef,startLine,endLine,inlineFragment,memberDef, + showLineNumbers,searchCtx,collectXRefs); +} + +void PythonCodeParser::resetCodeParserState() +{ + ::resetPythonCodeParserState(); +} + + #include "pycode.l.h" diff --git a/src/pyscanner.h b/src/pyscanner.h index 2faffdc..73e1679 100644 --- a/src/pyscanner.h +++ b/src/pyscanner.h @@ -31,10 +31,9 @@ * * This is the Python language parser for doxygen. */ -class PythonLanguageScanner : public ParserInterface +class PythonOutlineParser : public OutlineParserInterface { public: - virtual ~PythonLanguageScanner() {} void startTranslationUnit(const char *) {} void finishTranslationUnit() {} void parseInput(const char * fileName, @@ -43,22 +42,6 @@ class PythonLanguageScanner : public ParserInterface bool sameTranslationUnit, QStrList &filesInSameTranslationUnit); bool needsPreprocessing(const QCString &extension) const; - void parseCode(CodeOutputInterface &codeOutIntf, - const char *scopeName, - const QCString &input, - SrcLangExt lang, - bool isExampleBlock, - const char *exampleName=0, - FileDef *fileDef=0, - int startLine=-1, - int endLine=-1, - bool inlineFragment=FALSE, - const MemberDef *memberDef=0, - bool showLineNumbers=TRUE, - const Definition *searchCtx=0, - bool collectXrefs=TRUE - ); - void resetCodeParserState(); void parsePrototype(const char *text); }; diff --git a/src/pyscanner.l b/src/pyscanner.l index 5d6b303..963b4e8 100644 --- a/src/pyscanner.l +++ b/src/pyscanner.l @@ -65,7 +65,7 @@ */ -static ParserInterface *g_thisParser; +static OutlineParserInterface *g_thisParser; static const char * inputString; static int inputPosition; static QFile inputFile; @@ -1886,7 +1886,7 @@ void pyscanFreeScanner() //---------------------------------------------------------------------------- -void PythonLanguageScanner::parseInput(const char *fileName, +void PythonOutlineParser::parseInput(const char *fileName, const char *fileBuf, const std::unique_ptr &root, bool /*sameTranslationUnit*/, @@ -1901,43 +1901,17 @@ void PythonLanguageScanner::parseInput(const char *fileName, // printAST(global_root); } -bool PythonLanguageScanner::needsPreprocessing(const QCString &) const +bool PythonOutlineParser::needsPreprocessing(const QCString &) const { return FALSE; } -void PythonLanguageScanner::parseCode(CodeOutputInterface &codeOutIntf, - const char *scopeName, - const QCString &input, - SrcLangExt /*lang*/, - bool isExampleBlock, - const char *exampleName, - FileDef *fileDef, - int startLine, - int endLine, - bool inlineFragment, - const MemberDef *memberDef, - bool showLineNumbers, - const Definition *searchCtx, - bool collectXRefs - ) -{ - ::parsePythonCode(codeOutIntf,scopeName,input,isExampleBlock,exampleName, - fileDef,startLine,endLine,inlineFragment,memberDef, - showLineNumbers,searchCtx,collectXRefs); -} - -void PythonLanguageScanner::parsePrototype(const char *text) +void PythonOutlineParser::parsePrototype(const char *text) { ::parsePrototype(text); } -void PythonLanguageScanner::resetCodeParserState() -{ - ::resetPythonCodeParserState(); -} - //---------------------------------------------------------------------------- #include "pyscanner.l.h" diff --git a/src/rtfdocvisitor.cpp b/src/rtfdocvisitor.cpp index 43ac362..5a8e49d 100644 --- a/src/rtfdocvisitor.cpp +++ b/src/rtfdocvisitor.cpp @@ -305,8 +305,8 @@ void RTFDocVisitor::visit(DocVerbatim *s) m_t << "{" << endl; m_t << "\\par" << endl; m_t << rtf_Style_Reset << getStyle("CodeExample"); - Doxygen::parserManager->getParser(lang) - ->parseCode(m_ci,s->context(),s->text(),langExt, + Doxygen::parserManager->getCodeParser(lang) + .parseCode(m_ci,s->context(),s->text(),langExt, s->isExample(),s->exampleFile()); //m_t << "\\par" << endl; m_t << "}" << endl; @@ -432,8 +432,8 @@ void RTFDocVisitor::visit(DocInclude *inc) m_t << rtf_Style_Reset << getStyle("CodeExample"); QFileInfo cfi( inc->file() ); FileDef *fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci,inc->context(), + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), @@ -454,8 +454,8 @@ void RTFDocVisitor::visit(DocInclude *inc) m_t << "{" << endl; m_t << "\\par" << endl; m_t << rtf_Style_Reset << getStyle("CodeExample"); - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci,inc->context(), + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci,inc->context(), inc->text(),langExt,inc->isExample(), inc->exampleFile(), 0, // fileDef @@ -485,8 +485,8 @@ void RTFDocVisitor::visit(DocInclude *inc) m_t << "{" << endl; if (!m_lastIsPara) m_t << "\\par" << endl; m_t << rtf_Style_Reset << getStyle("CodeExample"); - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci, + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, @@ -502,8 +502,8 @@ void RTFDocVisitor::visit(DocInclude *inc) m_t << "{" << endl; if (!m_lastIsPara) m_t << "\\par" << endl; m_t << rtf_Style_Reset << getStyle("CodeExample"); - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci, + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, @@ -560,8 +560,8 @@ void RTFDocVisitor::visit(DocIncOperator *op) fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); } - Doxygen::parserManager->getParser(locLangExt) - ->parseCode(m_ci,op->context(),op->text(),langExt, + Doxygen::parserManager->getCodeParser(locLangExt) + .parseCode(m_ci,op->context(),op->text(),langExt, op->isExample(),op->exampleFile(), fd, // fileDef op->line(), // startLine diff --git a/src/scanner.h b/src/scanner.h index fd40485..1c7a50c 100644 --- a/src/scanner.h +++ b/src/scanner.h @@ -26,11 +26,11 @@ * supports C++ and various languages that are closely related to C++, * such as C, C#, Objective-C, Java, PHP, and IDL. */ -class CLanguageScanner : public ParserInterface +class COutlineParser : public OutlineParserInterface { public: - CLanguageScanner(); - virtual ~CLanguageScanner(); + COutlineParser(); + virtual ~COutlineParser(); void startTranslationUnit(const char *fileName); void finishTranslationUnit(); void parseInput(const char *fileName, @@ -39,26 +39,11 @@ class CLanguageScanner : public ParserInterface bool sameTranslationUnit, QStrList &filesInSameTranslationUnit); bool needsPreprocessing(const QCString &extension) const; - void parseCode(CodeOutputInterface &codeOutIntf, - const char *scopeName, - const QCString &input, - SrcLangExt lang, - bool isExampleBlock, - const char *exampleName=0, - FileDef *fileDef=0, - int startLine=-1, - int endLine=-1, - bool inlineFragment=FALSE, - const MemberDef *memberDef=0, - bool showLineNumbers=TRUE, - const Definition *searchCtx=0, - bool collectXRefs=TRUE - ); - void resetCodeParserState(); void parsePrototype(const char *text); private: struct Private; - Private *p; + std::unique_ptr p; }; + #endif diff --git a/src/scanner.l b/src/scanner.l index 3a71535..a03b777 100644 --- a/src/scanner.l +++ b/src/scanner.l @@ -58,7 +58,7 @@ struct scannerYY_state { - ParserInterface *thisParser; + OutlineParserInterface *thisParser; const char * inputString = 0; int inputPosition = 0; int lastContext = 0; @@ -189,7 +189,6 @@ struct scannerYY_state int fencedSize = 0; bool nestedComment = 0; std::vector< std::pair > > outerScopeEntries; - CodeScanner codeScanner; }; static const char *stateToString(int state); @@ -7321,29 +7320,27 @@ static void parsePrototype(yyscan_t yyscanner,const QCString &text) //---------------------------------------------------------------------------- -struct CLanguageScanner::Private +struct COutlineParser::Private { yyscan_t yyscanner; scannerYY_state state; }; -CLanguageScanner::CLanguageScanner() +COutlineParser::COutlineParser() : p(std::make_unique()) { - p = new Private; scannerYYlex_init_extra(&p->state,&p->yyscanner); } -CLanguageScanner::~CLanguageScanner() +COutlineParser::~COutlineParser() { scannerYYlex_destroy(p->yyscanner); - delete p; } -void CLanguageScanner::startTranslationUnit(const char *) +void COutlineParser::startTranslationUnit(const char *) { } -void CLanguageScanner::finishTranslationUnit() +void COutlineParser::finishTranslationUnit() { struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner; bool processWithClang = yyextra->insideCpp || yyextra->insideObjC; @@ -7353,7 +7350,7 @@ void CLanguageScanner::finishTranslationUnit() } } -void CLanguageScanner::parseInput(const char *fileName, +void COutlineParser::parseInput(const char *fileName, const char *fileBuf, const std::unique_ptr &root, bool sameTranslationUnit, @@ -7371,29 +7368,7 @@ void CLanguageScanner::parseInput(const char *fileName, } -void CLanguageScanner::parseCode(CodeOutputInterface & codeOutIntf, - const char * scopeName, - const QCString & input, - SrcLangExt lang, - bool isExampleBlock, - const char * exampleName, - FileDef * fileDef, - int startLine, - int endLine, - bool inlineFragment, - const MemberDef *memberDef, - bool showLineNumbers, - const Definition *searchCtx, - bool collectXRefs - ) -{ - struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner; - yyextra->codeScanner.parseCCode(codeOutIntf,scopeName,input,lang,isExampleBlock,exampleName, - fileDef,startLine,endLine,inlineFragment,memberDef, - showLineNumbers,searchCtx,collectXRefs); -} - -bool CLanguageScanner::needsPreprocessing(const QCString &extension) const +bool COutlineParser::needsPreprocessing(const QCString &extension) const { QCString fe=extension.lower(); SrcLangExt lang = getLanguageFromFileName(extension); @@ -7403,13 +7378,7 @@ bool CLanguageScanner::needsPreprocessing(const QCString &extension) const ); } -void CLanguageScanner::resetCodeParserState() -{ - struct yyguts_t *yyg = (struct yyguts_t*)p->yyscanner; - yyextra->codeScanner.reset(); -} - -void CLanguageScanner::parsePrototype(const char *text) +void COutlineParser::parsePrototype(const char *text) { ::parsePrototype(p->yyscanner,text); } diff --git a/src/sqlcode.h b/src/sqlcode.h index d8a09b7..20e20f7 100644 --- a/src/sqlcode.h +++ b/src/sqlcode.h @@ -19,7 +19,7 @@ #ifndef SQLCODE_H #define SQLCODE_H -#include "types.h" +#include "parserintf.h" class CodeOutputInterface; class FileDef; @@ -27,11 +27,28 @@ class MemberDef; class QCString; class Definition; -extern void parseSqlCode(CodeOutputInterface &,const char *,const QCString &, - bool ,const char *,FileDef *fd, - int startLine,int endLine,bool inlineFragment, - const MemberDef *memberDef,bool showLineNumbers,const Definition *searchCtx, - bool collectXRefs); -extern void resetSqlCodeParserState(); +/** SQL scanner. Only support syntax highlighting of code at the moment. + */ +class SQLCodeParser : public CodeParserInterface +{ + public: + void parseCode(CodeOutputInterface &codeOutIntf, + const char *scopeName, + const QCString &input, + SrcLangExt, + bool isExampleBlock, + const char *exampleName=0, + FileDef *fileDef=0, + int startLine=-1, + int endLine=-1, + bool inlineFragment=FALSE, + const MemberDef *memberDef=0, + bool showLineNumbers=TRUE, + const Definition *searchCtx=0, + bool collectXRefs=TRUE + ); + void resetCodeParserState(); +}; + #endif diff --git a/src/sqlcode.l b/src/sqlcode.l index a9e88a7..499a512 100644 --- a/src/sqlcode.l +++ b/src/sqlcode.l @@ -454,4 +454,34 @@ void resetSqlCodeParserState() yyextra->currentMemberDef = 0; } +//--------------------------------------------------------------------------------- + +void SQLCodeParser::parseCode(CodeOutputInterface &codeOutIntf, + const char *scopeName, + const QCString &input, + SrcLangExt, + bool isExampleBlock, + const char *exampleName, + FileDef *fileDef, + int startLine, + int endLine, + bool inlineFragment, + const MemberDef *memberDef, + bool showLineNumbers, + const Definition *searchCtx, + bool collectXRefs + ) +{ + parseSqlCode(codeOutIntf,scopeName,input,isExampleBlock,exampleName, + fileDef,startLine,endLine,inlineFragment,memberDef, + showLineNumbers,searchCtx,collectXRefs); +} + +void SQLCodeParser::resetCodeParserState() +{ + resetSqlCodeParserState(); +} + +//--------------------------------------------------------------------------------- + #include "sqlcode.l.h" diff --git a/src/sqlscanner.h b/src/sqlscanner.h deleted file mode 100644 index 694bf80..0000000 --- a/src/sqlscanner.h +++ /dev/null @@ -1,65 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 1997-2015 by Dimitri van Heesch. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software - * for any purpose. It is provided "as is" without express or implied warranty. - * See the GNU General Public License for more details. - * - * Documents produced by Doxygen are derivative works derived from the - * input used in their production; they are not affected by this license. - * - */ - -#ifndef SQLSCANNER_H -#define SQLSCANNER_H - -#include "parserintf.h" -#include "sqlcode.h" - -/** SQL scanner. Only support syntax highlighting of code at the moment. - */ -class SQLScanner : public ParserInterface -{ -public: - SQLScanner() {} - virtual ~SQLScanner() {} - void startTranslationUnit(const char *) {} - void finishTranslationUnit() {} - void parseInput(const char *, const char *, const std::unique_ptr &, bool , QStrList &) {} - bool needsPreprocessing(const QCString &) const { return FALSE; } - - void parseCode(CodeOutputInterface &codeOutIntf, - const char *scopeName, - const QCString &input, - SrcLangExt, - bool isExampleBlock, - const char *exampleName=0, - FileDef *fileDef=0, - int startLine=-1, - int endLine=-1, - bool inlineFragment=FALSE, - const MemberDef *memberDef=0, - bool showLineNumbers=TRUE, - const Definition *searchCtx=0, - bool collectXRefs=TRUE - ) - { - parseSqlCode(codeOutIntf,scopeName,input,isExampleBlock,exampleName, - fileDef,startLine,endLine,inlineFragment,memberDef, - showLineNumbers,searchCtx,collectXRefs); - } - - void resetCodeParserState() - { - resetSqlCodeParserState(); - } - - void parsePrototype(const char *) {} - -private: -}; - -#endif diff --git a/src/tclscanner.h b/src/tclscanner.h index 94da68b..52ff903 100644 --- a/src/tclscanner.h +++ b/src/tclscanner.h @@ -25,10 +25,9 @@ * * This is the Tcl language parser for doxygen. */ -class TclLanguageScanner : public ParserInterface +class TclOutlineParser : public OutlineParserInterface { public: - virtual ~TclLanguageScanner() {} void startTranslationUnit(const char *) {} void finishTranslationUnit() {} void parseInput(const char *fileName, @@ -37,6 +36,12 @@ class TclLanguageScanner : public ParserInterface bool sameTranslationUnit, QStrList &filesInSameTranslationUnit); bool needsPreprocessing(const QCString &extension) const; + void parsePrototype(const char *text); +}; + +class TclCodeParser : public CodeParserInterface +{ + public: void parseCode(CodeOutputInterface &codeOutIntf, const char *scopeName, const QCString &input, @@ -53,7 +58,6 @@ class TclLanguageScanner : public ParserInterface bool collectXRefs=TRUE ); void resetCodeParserState(); - void parsePrototype(const char *text); }; #endif diff --git a/src/tclscanner.l b/src/tclscanner.l index d22c5d6..e3fd6f2 100644 --- a/src/tclscanner.l +++ b/src/tclscanner.l @@ -429,7 +429,7 @@ static struct QCString input_string; // file contents int input_position; // position in file QCString file_name; // name of used file - ParserInterface *this_parser; // myself + OutlineParserInterface *this_parser; // myself int command; // true if command was found int comment; // set true if comment was scanned int brace_level; // bookkeeping of braces @@ -2964,7 +2964,7 @@ static void tcl_parse(const QCString ns, const QCString cls) } //! Parse text file and build up entry tree. -void TclLanguageScanner::parseInput(const char *fileName, +void TclOutlineParser::parseInput(const char *fileName, const char *input, const std::unique_ptr &root, bool /*sameTranslationUnit*/, @@ -2995,8 +2995,40 @@ tcl_inf("%s\n",fileName); printlex(yy_flex_debug, FALSE, __FILE__, fileName); } + +bool TclOutlineParser::needsPreprocessing(const QCString &extension) const +{ + (void)extension; + return FALSE; +} + +void TclOutlineParser::parsePrototype(const char *text) +{ + (void)text; +} + +static int yyread(char *buf,int max_size) +{ + int c=0; + + *buf = '\0'; + while ( c < max_size && tcl.input_string.at(tcl.input_position) ) + { + *buf = tcl.input_string.at(tcl.input_position++) ; + c++; buf++; + } + //printf("Read from=%d size=%d max=%d c=%d\n",tcl.input_position,strlen(&tcl.input_string[tcl.input_position]),max_size,c); + return c; +} + +//---------------------------------------------------------------------------- + +void TclCodeParser::resetCodeParserState() +{ +} + //! Parse file and codify. -void TclLanguageScanner::parseCode(CodeOutputInterface & codeOutIntf, +void TclCodeParser::parseCode(CodeOutputInterface & codeOutIntf, const char * scopeName, const QCString & input, SrcLangExt lang, @@ -3100,36 +3132,6 @@ tcl_inf("%s (%d,%d) %d %d\n",myStr.data(),startLine,endLine,isExampleBlock,inlin tcl.entry.clear(); printlex(yy_flex_debug, FALSE, __FILE__, fileDef ? fileDef->fileName().data(): NULL); } - -bool TclLanguageScanner::needsPreprocessing(const QCString &extension) const -{ - (void)extension; - return FALSE; -} - -void TclLanguageScanner::resetCodeParserState() -{ -} - -void TclLanguageScanner::parsePrototype(const char *text) -{ - (void)text; -} - -static int yyread(char *buf,int max_size) -{ - int c=0; - - *buf = '\0'; - while ( c < max_size && tcl.input_string.at(tcl.input_position) ) - { - *buf = tcl.input_string.at(tcl.input_position++) ; - c++; buf++; - } - //printf("Read from=%d size=%d max=%d c=%d\n",tcl.input_position,strlen(&tcl.input_string[tcl.input_position]),max_size,c); - return c; -} - //---------------------------------------------------------------------------- // to avoid a warning diff --git a/src/vhdlcode.h b/src/vhdlcode.h index a7b4687..b79e2ab 100644 --- a/src/vhdlcode.h +++ b/src/vhdlcode.h @@ -1,16 +1,35 @@ #ifndef VHDLCODE_H #define VHDLCODE_H +#include "parserintf.h" + class CodeOutputInterface; class FileDef; class MemberDef; -void parseVhdlCode(CodeOutputInterface &,const char *,const QCString &, - bool ,const char *,FileDef *fd, - int startLine,int endLine,bool inlineFragment, - const MemberDef *memberDef,bool showLineNumbers,const Definition *searchCtx, - bool collectXRefs); -void resetVhdlCodeParserState(); void codeFreeVhdlScanner(); +class VHDLCodeParser : public CodeParserInterface +{ + public: + virtual ~VHDLCodeParser() {} + void parseCode(CodeOutputInterface &codeOutIntf, + const char *scopeName, + const QCString &input, + SrcLangExt lang, + bool isExampleBlock, + const char *exampleName=0, + FileDef *fileDef=0, + int startLine=-1, + int endLine=-1, + bool inlineFragment=FALSE, + const MemberDef *memberDef=0, + bool showLineNumbers=TRUE, + const Definition *searchCtx=0, + bool collectXRefs=TRUE + ); + void resetCodeParserState() {} +}; + + #endif diff --git a/src/vhdlcode.l b/src/vhdlcode.l index 53e1ed8..fe5a8d9 100644 --- a/src/vhdlcode.l +++ b/src/vhdlcode.l @@ -33,6 +33,7 @@ #include #include +#include "vhdlcode.h" #include "entry.h" #include "doxygen.h" #include "message.h" @@ -1530,17 +1531,26 @@ XILINX "INST"|"NET"|"PIN"|"BLKNM"|"BUFG"|"COLLAPSE"|"CPLD"|"COMPGRP"|"CONFI /*@ ---------------------------------------------------------------------------- */ -void resetVhdlCodeParserState() +static void resetVhdlCodeParserState() { g_vhdlKeyDict.setAutoDelete(TRUE); g_vhdlKeyDict.clear(); } -void parseVhdlCode(CodeOutputInterface &od,const char *className,const QCString &s, - bool exBlock, const char *exName,FileDef *fd, - int startLine,int endLine,bool inlineFragment, - const MemberDef *memberDef,bool,const Definition *searchCtx, - bool /* collectXRefs */) +void VHDLCodeParser::parseCode(CodeOutputInterface &od, + const char *className, + const QCString &s, + SrcLangExt, + bool exBlock, + const char *exName, + FileDef *fd, + int startLine, + int endLine, + bool inlineFragment, + const MemberDef *memberDef, + bool, + const Definition *searchCtx, + bool /* collectXRefs */) { //printf("***parseCode() exBlock=%d exName=%s fd=%p\n",exBlock,exName,fd); if (s.isEmpty()) return; diff --git a/src/vhdldocgen.cpp b/src/vhdldocgen.cpp index 90d4829..ba4d4de 100644 --- a/src/vhdldocgen.cpp +++ b/src/vhdldocgen.cpp @@ -2379,7 +2379,7 @@ void VhdlDocGen::writeStringLink(const MemberDef *mdef,QCString mem, OutputList& void VhdlDocGen::writeSource(const MemberDef *mdef,OutputList& ol,const QCString & cname) { - ParserInterface *pIntf = Doxygen::parserManager->getParser(".vhd"); + CodeParserInterface &intf = Doxygen::parserManager->getCodeParser(".vhd"); // pIntf->resetCodeParserState(); QCString codeFragment=mdef->documentation(); @@ -2405,7 +2405,7 @@ void VhdlDocGen::writeSource(const MemberDef *mdef,OutputList& ol,const QCString codeFragment.prepend("\n"); ol.pushGeneratorState(); ol.startCodeFragment(); - pIntf->parseCode(ol, // codeOutIntf + intf.parseCode( ol, // codeOutIntf 0, // scope codeFragment, // input SrcLangExt_VHDL, // lang @@ -3134,13 +3134,13 @@ void VhdlDocGen::createFlowChart(const MemberDef *mdef) bool b=readCodeFragment( fd->absFilePath().data(), actualStart,actualEnd,codeFragment); if (!b) return; - VHDLLanguageScanner *pIntf =(VHDLLanguageScanner*) Doxygen::parserManager->getParser(".vhd"); + VHDLOutlineParser &intf =dynamic_cast(Doxygen::parserManager->getOutlineParser(".vhd")); VhdlDocGen::setFlowMember(mdef); std::unique_ptr root = std::make_unique(); QStrList filesInSameTu; - pIntf->startTranslationUnit(""); - pIntf->parseInput("",codeFragment.data(),root,FALSE,filesInSameTu); - pIntf->finishTranslationUnit(); + intf.startTranslationUnit(""); + intf.parseInput("",codeFragment.data(),root,FALSE,filesInSameTu); + intf.finishTranslationUnit(); } void VhdlDocGen::resetCodeVhdlParserState() @@ -4312,42 +4312,3 @@ void FlowChart::writeFlowLinks(FTextStream &t) } //writeFlowLinks -void VHDLLanguageScanner::parseCode(CodeOutputInterface &codeOutIntf, - const char *scopeName, - const QCString &input, - SrcLangExt, // lang - bool isExampleBlock, - const char *exampleName, - FileDef *fileDef, - int startLine, - int endLine, - bool inlineFragment, - const MemberDef *memberDef, - bool showLineNumbers, - const Definition *searchCtx, - bool collectXRefs - ) -{ - -parseVhdlCode(codeOutIntf, - scopeName, - input, - isExampleBlock, - exampleName, - fileDef, - startLine, - endLine, - inlineFragment, - memberDef, - showLineNumbers, - searchCtx, - collectXRefs - -); - - - - - - -}// class diff --git a/src/vhdljjparser.cpp b/src/vhdljjparser.cpp index d6e3ac3..874980b 100644 --- a/src/vhdljjparser.cpp +++ b/src/vhdljjparser.cpp @@ -33,7 +33,7 @@ using namespace vhdl::parser; using namespace std; -static ParserInterface *g_thisParser; +static OutlineParserInterface *g_thisParser; static QCString yyFileName; static int yyLineNr = 1; @@ -105,7 +105,7 @@ bool isConstraintFile(const QCString &fileName,const QCString &ext) } -void VHDLLanguageScanner::parseInput(const char *fileName,const char *fileBuf, +void VHDLOutlineParser::parseInput(const char *fileName,const char *fileBuf, const std::unique_ptr &root, bool ,QStrList&) { g_thisParser=this; @@ -321,7 +321,7 @@ void VhdlParser::handleCommentBlock(const char* doc1,bool brief) strComment.resize(0); } -void VHDLLanguageScanner::parsePrototype(const char *text) +void VHDLOutlineParser::parsePrototype(const char *text) { varName=text; varr=TRUE; diff --git a/src/vhdljjparser.h b/src/vhdljjparser.h index f2bf60d..faa0c08 100644 --- a/src/vhdljjparser.h +++ b/src/vhdljjparser.h @@ -39,10 +39,10 @@ struct VhdlConfNode; * * This is the VHDL language parser for doxygen. */ -class VHDLLanguageScanner : public ParserInterface +class VHDLOutlineParser : public OutlineParserInterface { public: - virtual ~VHDLLanguageScanner() {} + virtual ~VHDLOutlineParser() {} void startTranslationUnit(const char *) {} void finishTranslationUnit() {} void parseInput(const char * fileName, @@ -50,25 +50,9 @@ class VHDLLanguageScanner : public ParserInterface const std::unique_ptr &root, bool sameTranslationUnit, QStrList &filesInSameTranslationUnit); - - void parseCode(CodeOutputInterface &codeOutIntf, - const char *scopeName, - const QCString &input, - SrcLangExt lang, - bool isExampleBlock, - const char *exampleName=0, - FileDef *fileDef=0, - int startLine=-1, - int endLine=-1, - bool inlineFragment=FALSE, - const MemberDef *memberDef=0, - bool showLineNumbers=TRUE, - const Definition *searchCtx=0, - bool collectXRefs=TRUE - ); - bool needsPreprocessing(const QCString &) const { return TRUE; } - void resetCodeParserState(){}; - void parsePrototype(const char *text); + + bool needsPreprocessing(const QCString &) const { return TRUE; } + void parsePrototype(const char *text); }; struct VhdlConfNode diff --git a/src/xmlcode.h b/src/xmlcode.h index e463866..4cada9b 100644 --- a/src/xmlcode.h +++ b/src/xmlcode.h @@ -19,7 +19,7 @@ #ifndef XMLCODE_H #define XMLCODE_H -#include "types.h" +#include "parserintf.h" class CodeOutputInterface; class FileDef; @@ -27,11 +27,28 @@ class MemberDef; class QCString; class Definition; -extern void parseXmlCode(CodeOutputInterface &,const char *,const QCString &, - bool ,const char *,FileDef *fd, - int startLine,int endLine,bool inlineFragment, - const MemberDef *memberDef,bool showLineNumbers,const Definition *searchCtx, - bool collectXRefs); -extern void resetXmlCodeParserState(); +/** XML scanner. Only support syntax highlighting of code at the moment. + */ +class XMLCodeParser : public CodeParserInterface +{ + public: + void parseCode(CodeOutputInterface &codeOutIntf, + const char *scopeName, + const QCString &input, + SrcLangExt, + bool isExampleBlock, + const char *exampleName=0, + FileDef *fileDef=0, + int startLine=-1, + int endLine=-1, + bool inlineFragment=FALSE, + const MemberDef *memberDef=0, + bool showLineNumbers=TRUE, + const Definition *searchCtx=0, + bool collectXRefs=TRUE + ); + void resetCodeParserState(); +}; + #endif diff --git a/src/xmlcode.l b/src/xmlcode.l index 2fedf2d..94548f8 100644 --- a/src/xmlcode.l +++ b/src/xmlcode.l @@ -407,4 +407,32 @@ void resetXmlCodeParserState() g_currentMemberDef = 0; } +//---------------------------------------------------------------------------- + +void XMLCodeParser::parseCode(CodeOutputInterface &codeOutIntf, + const char *scopeName, + const QCString &input, + SrcLangExt, + bool isExampleBlock, + const char *exampleName, + FileDef *fileDef, + int startLine, + int endLine, + bool inlineFragment, + const MemberDef *memberDef, + bool showLineNumbers, + const Definition *searchCtx, + bool collectXRefs + ) +{ + parseXmlCode(codeOutIntf,scopeName,input,isExampleBlock,exampleName, + fileDef,startLine,endLine,inlineFragment,memberDef, + showLineNumbers,searchCtx,collectXRefs); +} + +void XMLCodeParser::resetCodeParserState() +{ + resetXmlCodeParserState(); +} + #include "xmlcode.l.h" diff --git a/src/xmldocvisitor.cpp b/src/xmldocvisitor.cpp index a0afa9d..828c265 100644 --- a/src/xmldocvisitor.cpp +++ b/src/xmldocvisitor.cpp @@ -251,8 +251,8 @@ void XmlDocVisitor::visit(DocVerbatim *s) m_t << " filename=\"" << lang << "\">"; else m_t << ">"; - Doxygen::parserManager->getParser(lang) - ->parseCode(m_ci,s->context(),s->text(),langExt, + Doxygen::parserManager->getCodeParser(lang) + .parseCode(m_ci,s->context(),s->text(),langExt, s->isExample(),s->exampleFile()); m_t << ""; break; @@ -306,8 +306,8 @@ void XmlDocVisitor::visit(DocInclude *inc) m_t << "file() << "\">"; QFileInfo cfi( inc->file() ); FileDef *fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci,inc->context(), + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), @@ -325,8 +325,8 @@ void XmlDocVisitor::visit(DocInclude *inc) break; case DocInclude::Include: m_t << "file() << "\">"; - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci,inc->context(), + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), @@ -367,8 +367,8 @@ void XmlDocVisitor::visit(DocInclude *inc) break; case DocInclude::Snippet: m_t << "file() << "\">"; - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci, + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, @@ -382,8 +382,8 @@ void XmlDocVisitor::visit(DocInclude *inc) m_t << "file() << "\">"; QFileInfo cfi( inc->file() ); FileDef *fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); - Doxygen::parserManager->getParser(inc->extension()) - ->parseCode(m_ci, + Doxygen::parserManager->getCodeParser(inc->extension()) + .parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, @@ -436,8 +436,8 @@ void XmlDocVisitor::visit(DocIncOperator *op) fd = createFileDef( cfi.dirPath().utf8(), cfi.fileName().utf8() ); } - Doxygen::parserManager->getParser(locLangExt) - ->parseCode(m_ci,op->context(), + Doxygen::parserManager->getCodeParser(locLangExt) + .parseCode(m_ci,op->context(), op->text(),langExt,op->isExample(), op->exampleFile(), fd, // fileDef diff --git a/src/xmlgen.cpp b/src/xmlgen.cpp index 83e97b2..bf5af84 100644 --- a/src/xmlgen.cpp +++ b/src/xmlgen.cpp @@ -417,11 +417,11 @@ static void writeXMLDocBlock(FTextStream &t, void writeXMLCodeBlock(FTextStream &t,FileDef *fd) { - ParserInterface *pIntf=Doxygen::parserManager->getParser(fd->getDefFileExtension()); + CodeParserInterface &intf=Doxygen::parserManager->getCodeParser(fd->getDefFileExtension()); SrcLangExt langExt = getLanguageFromFileName(fd->getDefFileExtension()); - pIntf->resetCodeParserState(); + intf.resetCodeParserState(); XMLCodeGenerator *xmlGen = new XMLCodeGenerator(t); - pIntf->parseCode(*xmlGen, // codeOutIntf + intf.parseCode(*xmlGen, // codeOutIntf 0, // scopeName fileToString(fd->absFilePath(),Config_getBool(FILTER_SOURCE_FILES)), langExt, // lang diff --git a/src/xmlscanner.h b/src/xmlscanner.h deleted file mode 100644 index 0fe01a7..0000000 --- a/src/xmlscanner.h +++ /dev/null @@ -1,65 +0,0 @@ -/****************************************************************************** - * - * Copyright (C) 1997-2015 by Dimitri van Heesch. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation under the terms of the GNU General Public License is hereby - * granted. No representations are made about the suitability of this software - * for any purpose. It is provided "as is" without express or implied warranty. - * See the GNU General Public License for more details. - * - * Documents produced by Doxygen are derivative works derived from the - * input used in their production; they are not affected by this license. - * - */ - -#ifndef XMLSCANNER_H -#define XMLSCANNER_H - -#include "parserintf.h" -#include "xmlcode.h" - -/** XML scanner. Only support syntax highlighting of code at the moment. - */ -class XMLScanner : public ParserInterface -{ -public: - XMLScanner() {} - virtual ~XMLScanner() {} - void startTranslationUnit(const char *) {} - void finishTranslationUnit() {} - void parseInput(const char *, const char *, const std::unique_ptr &, bool , QStrList &) {} - bool needsPreprocessing(const QCString &) const { return FALSE; } - - void parseCode(CodeOutputInterface &codeOutIntf, - const char *scopeName, - const QCString &input, - SrcLangExt, - bool isExampleBlock, - const char *exampleName=0, - FileDef *fileDef=0, - int startLine=-1, - int endLine=-1, - bool inlineFragment=FALSE, - const MemberDef *memberDef=0, - bool showLineNumbers=TRUE, - const Definition *searchCtx=0, - bool collectXRefs=TRUE - ) - { - parseXmlCode(codeOutIntf,scopeName,input,isExampleBlock,exampleName, - fileDef,startLine,endLine,inlineFragment,memberDef, - showLineNumbers,searchCtx,collectXRefs); - } - - void resetCodeParserState() - { - resetXmlCodeParserState(); - } - - void parsePrototype(const char *) {} - -private: -}; - -#endif -- cgit v0.12