void LatexDocVisitor::visit(DocIncOperator *op) { //printf("DocIncOperator: type=%d first=%d, last=%d text=`%s'\n", // op->type(),op->isFirst(),op->isLast(),op->text().data()); if (op->isFirst()) { if (!m_hide) m_t << "\n\\begin{DoxyCodeInclude}\n"; pushEnabled(); m_hide = TRUE; } SrcLangExt langExt = getLanguageFromFileName(m_langExt); if (op->type()!=DocIncOperator::Skip) { popEnabled(); if (!m_hide) { Doxygen::parserManager->getParser(m_langExt) ->parseCode(m_ci,op->context(),op->text(),langExt, op->isExample(),op->exampleFile()); } pushEnabled(); m_hide=TRUE; } if (op->isLast()) { popEnabled(); if (!m_hide) m_t << "\n\\end{DoxyCodeInclude}\n"; } else { if (!m_hide) m_t << endl; } }
void DocbookDocVisitor::visit(DocIncOperator *op) { if (op->isFirst()) { if (!m_hide) { m_t << "<programlisting>"; } pushEnabled(); m_hide = TRUE; } SrcLangExt langExt = getLanguageFromFileName(m_langExt); if (op->type()!=DocIncOperator::Skip) { popEnabled(); if (!m_hide) { Doxygen::parserManager->getParser(m_langExt) ->parseCode(m_ci,op->context(), op->text(),langExt,op->isExample(), op->exampleFile()); } pushEnabled(); m_hide=TRUE; } if (op->isLast()) { popEnabled(); if (!m_hide) m_t << "</programlisting>"; } else { if (!m_hide) m_t << endl; } }
void LatexDocVisitor::visit(DocIncOperator *op) { if (op->isFirst()) { if (!m_hide) { m_t << "\n\\begin{DoxyCodeInclude}\n"; } pushEnabled(); m_hide = true; } SrcLangExt langExt = getLanguageFromFileName(m_langExt); if (op->type() != DocIncOperator::Skip) { popEnabled(); if (!m_hide) { Doxy_Globals::parserManager->getParser(m_langExt) ->parseCode(m_ci, op->context(), op->text(), langExt, op->isExample(), op->exampleFile()); } pushEnabled(); m_hide = true; } if (op->isLast()) { popEnabled(); if (!m_hide) { m_t << "\n\\end{DoxyCodeInclude}\n"; } } else { if (!m_hide) { m_t << endl; } } }
NamespaceDef::NamespaceDef(const char *df,int dl, const char *name,const char *lref, const char *fName) : Definition(df,dl,name) { if (fName) { fileName = stripExtension(fName); } else { fileName="namespace"; fileName+=name; } classSDict = new ClassSDict(17); namespaceSDict = new NamespaceSDict(17); m_innerCompounds = new SDict<Definition>(17); usingDirList = 0; usingDeclList = 0; m_allMembersDict = 0; setReference(lref); memberGroupSDict = new MemberGroupSDict; memberGroupSDict->setAutoDelete(TRUE); visited=FALSE; m_subGrouping=Config_getBool("SUBGROUPING"); m_isCSharp = df && getLanguageFromFileName(df)==SrcLangExt_CSharp; }
static void findXRefSymbols(FileDef *fd) { // get the interface to a parser that matches the file extension ParserInterface *pIntf=Doxygen::parserManager->getParser(fd->getDefFileExtension()); // get the programming language from the file name SrcLangExt lang = getLanguageFromFileName(fd->name()); // reset the parsers state pIntf->resetCodeParserState(); // create a new backend object XRefDummyCodeGenerator *xrefGen = new XRefDummyCodeGenerator(fd); // parse the source code pIntf->parseCode(*xrefGen, 0, fileToString(fd->absFilePath()), lang, FALSE, 0, fd); // dismiss the object. delete xrefGen; }
void ManDocVisitor::visit(DocVerbatim *s) { if (m_hide) { return; } QString lang = m_langExt; if (!s->language().isEmpty()) { // explicit language setting lang = s->language(); } SrcLangExt langExt = getLanguageFromFileName(lang); switch (s->type()) { case DocVerbatim::Code: // fall though if (!m_firstCol) { m_t << endl; } m_t << ".PP" << endl; m_t << ".nf" << endl; Doxy_Globals::parserManager->getParser(lang) ->parseCode(m_ci, s->context(), s->text(), langExt, s->isExample(), s->exampleFile()); if (!m_firstCol) { m_t << endl; } m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol = true; break; case DocVerbatim::Verbatim: if (!m_firstCol) { m_t << endl; } m_t << ".PP" << endl; m_t << ".nf" << endl; m_t << s->text(); if (!m_firstCol) { m_t << endl; } m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol = true; break; case DocVerbatim::ManOnly: m_t << s->text(); break; case DocVerbatim::HtmlOnly: case DocVerbatim::XmlOnly: case DocVerbatim::LatexOnly: case DocVerbatim::RtfOnly: case DocVerbatim::DocbookOnly: case DocVerbatim::Dot: case DocVerbatim::Msc: case DocVerbatim::PlantUML: /* nothing */ break; } }
void XmlDocVisitor::visit(DocVerbatim *s) { if (m_hide) return; SrcLangExt langExt = getLanguageFromFileName(m_langExt); switch(s->type()) { case DocVerbatim::Code: // fall though m_t << "<programlisting>"; Doxygen::parserManager->getParser(m_langExt) ->parseCode(m_ci,s->context(),s->text(),langExt, s->isExample(),s->exampleFile()); m_t << "</programlisting>"; break; case DocVerbatim::Verbatim: m_t << "<verbatim>"; filter(s->text()); m_t << "</verbatim>"; break; case DocVerbatim::HtmlOnly: m_t << "<htmlonly>"; filter(s->text()); m_t << "</htmlonly>"; break; case DocVerbatim::RtfOnly: m_t << "<rtfonly>"; filter(s->text()); m_t << "</rtfonly>"; break; case DocVerbatim::ManOnly: m_t << "<manonly>"; filter(s->text()); m_t << "</manonly>"; break; case DocVerbatim::LatexOnly: m_t << "<latexonly>"; filter(s->text()); m_t << "</latexonly>"; break; case DocVerbatim::XmlOnly: m_t << s->text(); break; case DocVerbatim::DocbookOnly: m_t << "<docbookonly>"; filter(s->text()); m_t << "</docbookonly>"; break; case DocVerbatim::Dot: m_t << "<dot>"; filter(s->text()); m_t << "</dot>"; break; case DocVerbatim::Msc: m_t << "<msc>"; filter(s->text()); m_t << "</msc>"; break; } }
void LatexDocVisitor::visit(DocInclude *inc) { if (m_hide) { return; } SrcLangExt langExt = getLanguageFromFileName(inc->extension()); switch (inc->type()) { case DocInclude::IncWithLines: { m_t << "\n\\begin{DoxyCodeInclude}\n"; QFileInfo cfi(inc->file()); QSharedPointer<FileDef> fd = QMakeShared<FileDef>(cfi.path(), cfi.fileName()); Doxy_Globals::parserManager->getParser(inc->extension())->parseCode(m_ci, inc->context(), inc->text(), langExt, inc->isExample(), inc->exampleFile(), fd); m_t << "\\end{DoxyCodeInclude}" << endl; } break; case DocInclude::Include: m_t << "\n\\begin{DoxyCodeInclude}\n"; Doxy_Globals::parserManager->getParser(inc->extension())->parseCode(m_ci, inc->context(), inc->text(), langExt, inc->isExample(),inc->exampleFile()); m_t << "\\end{DoxyCodeInclude}\n"; break; case DocInclude::DontInclude: break; case DocInclude::HtmlInclude: break; case DocInclude::LatexInclude: m_t << inc->text(); break; case DocInclude::VerbInclude: m_t << "\n\\begin{DoxyVerbInclude}\n"; m_t << inc->text(); m_t << "\\end{DoxyVerbInclude}\n"; break; case DocInclude::Snippet: { m_t << "\n\\begin{DoxyCodeInclude}\n"; Doxy_Globals::parserManager->getParser(inc->extension()) ->parseCode(m_ci, inc->context(), extractBlock(inc->text(), inc->blockId()), langExt, inc->isExample(), inc->exampleFile() ); m_t << "\\end{DoxyCodeInclude}" << endl; } break; } }
void XmlDocVisitor::visit(DocInclude *inc) { if (m_hide) return; SrcLangExt langExt = getLanguageFromFileName(inc->extension()); switch(inc->type()) { case DocInclude::IncWithLines: { m_t << "<programlisting>"; QFileInfo cfi( inc->file() ); FileDef fd( cfi.dirPath().utf8(), cfi.fileName().utf8() ); Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), inc->exampleFile(), &fd); m_t << "</programlisting>"; } break; case DocInclude::Include: m_t << "<programlisting>"; Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), inc->exampleFile()); m_t << "</programlisting>"; break; case DocInclude::DontInclude: break; case DocInclude::HtmlInclude: m_t << "<htmlonly>"; filter(inc->text()); m_t << "</htmlonly>"; break; case DocInclude::VerbInclude: m_t << "<verbatim>"; filter(inc->text()); m_t << "</verbatim>"; break; case DocInclude::Snippet: m_t << "<programlisting>"; Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, inc->isExample(), inc->exampleFile() ); m_t << "</programlisting>"; break; } }
void XmlDocVisitor::visit(DocVerbatim *s) { if (m_hide) return; QCString lang = m_langExt; if (!s->language().isEmpty()) // explicit language setting { lang = s->language(); } SrcLangExt langExt = getLanguageFromFileName(lang); switch(s->type()) { case DocVerbatim::Code: // fall though m_t << "<programlisting"; if (!s->language().isEmpty()) m_t << " filename=\"" << lang << "\">"; else m_t << ">"; Doxygen::parserManager->getParser(lang) ->parseCode(m_ci,s->context(),s->text(),langExt, s->isExample(),s->exampleFile()); m_t << "</programlisting>"; break; case DocVerbatim::Verbatim: m_t << "<verbatim>"; filter(s->text()); m_t << "</verbatim>"; break; case DocVerbatim::HtmlOnly: case DocVerbatim::RtfOnly: case DocVerbatim::ManOnly: case DocVerbatim::LatexOnly: case DocVerbatim::DocbookOnly: /* nothing */ break; case DocVerbatim::XmlOnly: m_t << s->text(); break; case DocVerbatim::Dot: visitPreStart(m_t, "dot", s->hasCaption(), this, s->children(), QCString(""), FALSE, DocImage::Html, s->width(), s->height()); filter(s->text()); visitPostEnd(m_t, "dot"); break; case DocVerbatim::Msc: visitPreStart(m_t, "msc", s->hasCaption(), this, s->children(), QCString(""), FALSE, DocImage::Html, s->width(), s->height()); filter(s->text()); visitPostEnd(m_t, "msc"); break; case DocVerbatim::PlantUML: visitPreStart(m_t, "plantuml", s->hasCaption(), this, s->children(), QCString(""), FALSE, DocImage::Html, s->width(), s->height()); filter(s->text()); visitPostEnd(m_t, "plantuml"); break; } }
void RTFDocVisitor::visit(DocIncOperator *op) { //printf("DocIncOperator: type=%d first=%d, last=%d text=`%s'\n", // op->type(),op->isFirst(),op->isLast(),op->text().data()); DBG_RTF("{\\comment RTFDocVisitor::visit(DocIncOperator)}\n"); SrcLangExt langExt = getLanguageFromFileName(m_langExt); if (op->isFirst()) { if (!m_hide) { m_t << "{" << endl; m_t << "\\par" << endl; m_t << rtf_Style_Reset << getStyle("CodeExample"); } pushEnabled(); m_hide = TRUE; } if (op->type()!=DocIncOperator::Skip) { popEnabled(); if (!m_hide) { Doxygen::parserManager->getParser(m_langExt) ->parseCode(m_ci,op->context(),op->text(),langExt, op->isExample(),op->exampleFile()); } pushEnabled(); m_hide=TRUE; } if (op->isLast()) { popEnabled(); if (!m_hide) { m_t << "\\par"; m_t << "}" << endl; } m_lastIsPara=TRUE; } else { if (!m_hide) m_t << endl; m_lastIsPara=FALSE; } }
void ManDocVisitor::visit(DocIncOperator *op) { SrcLangExt langExt = getLanguageFromFileName(m_langExt); //printf("DocIncOperator: type=%d first=%d, last=%d text=`%s'\n", // op->type(),op->isFirst(),op->isLast(),op->text().data()); if (op->isFirst()) { if (!m_hide) { if (!m_firstCol) m_t << endl; m_t << ".PP" << endl; m_t << ".nf" << endl; } pushEnabled(); m_hide = TRUE; } if (op->type()!=DocIncOperator::Skip) { popEnabled(); if (!m_hide) { Doxygen::parserManager->getParser(m_langExt) ->parseCode(m_ci,op->context(),op->text(),langExt, op->isExample(),op->exampleFile()); } pushEnabled(); m_hide=TRUE; } if (op->isLast()) { popEnabled(); if (!m_hide) { if (!m_firstCol) m_t << endl; m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol=TRUE; } } else { if (!m_hide) m_t << endl; } }
void ManDocVisitor::visit(DocIncOperator *op) { SrcLangExt langExt = getLanguageFromFileName(m_langExt); if (op->isFirst()) { if (!m_hide) { if (!m_firstCol) { m_t << endl; } m_t << ".PP" << endl; m_t << ".nf" << endl; } pushEnabled(); m_hide = true; } if (op->type() != DocIncOperator::Skip) { popEnabled(); if (!m_hide) { Doxy_Globals::parserManager->getParser(m_langExt) ->parseCode(m_ci, op->context(), op->text(), langExt, op->isExample(), op->exampleFile()); } pushEnabled(); m_hide = true; } if (op->isLast()) { popEnabled(); if (!m_hide) { if (!m_firstCol) { m_t << endl; } m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol = true; } } else { if (!m_hide) { m_t << endl; } } }
void XmlDocVisitor::visit(DocIncOperator *op) { //printf("DocIncOperator: type=%d first=%d, last=%d text=`%s'\n", // op->type(),op->isFirst(),op->isLast(),op->text().data()); if (op->isFirst()) { if (!m_hide) { m_t << "<programlisting filename=\"" << op->includeFileName() << "\">"; } pushEnabled(); m_hide = TRUE; } SrcLangExt langExt = getLanguageFromFileName(m_langExt); if (op->type()!=DocIncOperator::Skip) { popEnabled(); if (!m_hide) { Doxygen::parserManager->getParser(m_langExt) ->parseCode(m_ci,op->context(), op->text(),langExt,op->isExample(), op->exampleFile()); } pushEnabled(); m_hide=TRUE; } if (op->isLast()) { popEnabled(); if (!m_hide) m_t << "</programlisting>"; } else { if (!m_hide) m_t << endl; } }
/*! create a new file definition, where \a p is the file path, \a nm the file name, and \a lref is an HTML anchor name if the file was read from a tag file or 0 otherwise */ FileDef::FileDef(const char *p,const char *nm, const char *lref,const char *dn) : Definition((QCString)p+nm,1,nm) { path=p; filepath=path+nm; filename=nm; diskname=dn; if (diskname.isEmpty()) diskname=nm; setReference(lref); classSDict = 0; includeList = 0; includeDict = 0; includedByList = 0; includedByDict = 0; namespaceSDict = 0; srcDefDict = 0; srcMemberDict = 0; usingDirList = 0; usingDeclList = 0; package = 0; isSource = FALSE; docname = nm; dir = 0; if (Config_getBool("FULL_PATH_NAMES")) { docname.prepend(stripFromPath(path.copy())); } SrcLangExt lang = getLanguageFromFileName(name()); setLanguage(lang); //m_isJava = lang==SrcLangExt_Java; //m_isCSharp = lang==SrcLangExt_CSharp; memberGroupSDict = 0; acquireFileVersion(); m_subGrouping=Config_getBool("SUBGROUPING"); }
void ClangParser::start(const char *fileName,QStrList &filesInTranslationUnit) { static bool clangAssistedParsing = Config_getBool(CLANG_ASSISTED_PARSING); static QStrList &includePath = Config_getList(INCLUDE_PATH); static QStrList clangOptions = Config_getList(CLANG_OPTIONS); static QCString clangCompileDatabase = Config_getList(CLANG_COMPILATION_DATABASE_PATH); if (!clangAssistedParsing) return; //printf("ClangParser::start(%s)\n",fileName); p->fileName = fileName; p->index = clang_createIndex(0, 0); p->curLine = 1; p->curToken = 0; QDictIterator<void> di(Doxygen::inputPaths); int argc=0; std::string error; // load a clang compilation database (https://clang.llvm.org/docs/JSONCompilationDatabase.html) // this only needs to be loaded once, and could be refactored to a higher level function static std::unique_ptr<clang::tooling::CompilationDatabase> db = clang::tooling::CompilationDatabase::loadFromDirectory(clangCompileDatabase.data(), error); int clang_option_len = 0; std::vector<clang::tooling::CompileCommand> command; if (strcmp(clangCompileDatabase, "0") != 0) { if (db == nullptr) { // user specified a path, but DB file was not found err("%s using clang compilation database path of: \"%s\"\n", error.c_str(), clangCompileDatabase.data()); } else { // check if the file we are parsing is in the DB command = db->getCompileCommands(fileName); if (!command.empty() ) { // it's possible to have multiple entries for the same file, so use the last entry clang_option_len = command[command.size()-1].CommandLine.size(); } } } char **argv = (char**)malloc(sizeof(char*)*(4+Doxygen::inputPaths.count()+includePath.count()+clangOptions.count()+clang_option_len)); if (!command.empty() ) { std::vector<std::string> options = command[command.size()-1].CommandLine; // copy each compiler option used from the database. Skip the first which is compiler exe. for (auto option = options.begin()+1; option != options.end(); option++) { argv[argc++] = strdup(option->c_str()); } // this extra addition to argv is accounted for as we are skipping the first entry in argv[argc++]=strdup("-w"); // finally, turn off warnings. } else { // add include paths for input files for (di.toFirst();di.current();++di,++argc) { QCString inc = QCString("-I")+di.currentKey(); argv[argc]=strdup(inc.data()); //printf("argv[%d]=%s\n",argc,argv[argc]); } // add external include paths for (uint i=0;i<includePath.count();i++) { QCString inc = QCString("-I")+includePath.at(i); argv[argc++]=strdup(inc.data()); } // user specified options for (uint i=0;i<clangOptions.count();i++) { argv[argc++]=strdup(clangOptions.at(i)); } // extra options argv[argc++]=strdup("-ferror-limit=0"); argv[argc++]=strdup("-x"); // Since we can be presented with a .h file that can contain C/C++ or // Objective C code and we need to configure the parser before knowing this, // we use the source file to detected the language. Detection will fail if you // pass a bunch of .h files containing ObjC code, and no sources :-( SrcLangExt lang = getLanguageFromFileName(fileName); if (lang==SrcLangExt_ObjC || p->detectedLang!=ClangParser::Private::Detected_Cpp) { QCString fn = fileName; if (p->detectedLang==ClangParser::Private::Detected_Cpp && (fn.right(4).lower()==".cpp" || fn.right(4).lower()==".cxx" || fn.right(3).lower()==".cc" || fn.right(2).lower()==".c")) { // fall back to C/C++ once we see an extension that indicates this p->detectedLang = ClangParser::Private::Detected_Cpp; } else if (fn.right(3).lower()==".mm") // switch to Objective C++ { p->detectedLang = ClangParser::Private::Detected_ObjCpp; } else if (fn.right(2).lower()==".m") // switch to Objective C { p->detectedLang = ClangParser::Private::Detected_ObjC; } } switch(p->detectedLang) { case ClangParser::Private::Detected_Cpp: argv[argc++]=strdup("c++"); break; case ClangParser::Private::Detected_ObjC: argv[argc++]=strdup("objective-c"); break; case ClangParser::Private::Detected_ObjCpp: argv[argc++]=strdup("objective-c++"); break; } // provide the input and and its dependencies as unsaved files so we can // pass the filtered versions argv[argc++]=strdup(fileName); } static bool filterSourceFiles = Config_getBool(FILTER_SOURCE_FILES); //printf("source %s ----------\n%s\n-------------\n\n", // fileName,p->source.data()); uint numUnsavedFiles = filesInTranslationUnit.count()+1; p->numFiles = numUnsavedFiles; p->sources = new QCString[numUnsavedFiles]; p->ufs = new CXUnsavedFile[numUnsavedFiles]; p->sources[0] = detab(fileToString(fileName,filterSourceFiles,TRUE)); p->ufs[0].Filename = strdup(fileName); p->ufs[0].Contents = p->sources[0].data(); p->ufs[0].Length = p->sources[0].length(); QStrListIterator it(filesInTranslationUnit); uint i=1; for (it.toFirst();it.current() && i<numUnsavedFiles;++it,i++) { p->fileMapping.insert(it.current(),new uint(i)); p->sources[i] = detab(fileToString(it.current(),filterSourceFiles,TRUE)); p->ufs[i].Filename = strdup(it.current()); p->ufs[i].Contents = p->sources[i].data(); p->ufs[i].Length = p->sources[i].length(); } // let libclang do the actual parsing p->tu = clang_parseTranslationUnit(p->index, 0, argv, argc, p->ufs, numUnsavedFiles, CXTranslationUnit_DetailedPreprocessingRecord); // free arguments for (int i=0;i<argc;++i) { free(argv[i]); } free(argv); if (p->tu) { // filter out any includes not found by the clang parser determineInputFilesInSameTu(filesInTranslationUnit); // show any warnings that the compiler produced for (uint i=0, n=clang_getNumDiagnostics(p->tu); i!=n; ++i) { CXDiagnostic diag = clang_getDiagnostic(p->tu, i); CXString string = clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions()); err("%s [clang]\n",clang_getCString(string)); clang_disposeString(string); clang_disposeDiagnostic(diag); } // create a source range for the given file QFileInfo fi(fileName); CXFile f = clang_getFile(p->tu, fileName); CXSourceLocation fileBegin = clang_getLocationForOffset(p->tu, f, 0); CXSourceLocation fileEnd = clang_getLocationForOffset(p->tu, f, p->ufs[0].Length); CXSourceRange fileRange = clang_getRange(fileBegin, fileEnd); // produce a token stream for the file clang_tokenize(p->tu,fileRange,&p->tokens,&p->numTokens); // produce cursors for each token in the stream p->cursors=new CXCursor[p->numTokens]; clang_annotateTokens(p->tu,p->tokens,p->numTokens,p->cursors); } else { p->tokens = 0; p->numTokens = 0; p->cursors = 0; err("clang: Failed to parse translation unit %s\n",fileName); } }
void RTFDocVisitor::visit(DocVerbatim *s) { if (m_hide) return; DBG_RTF("{\\comment RTFDocVisitor::visit(DocVerbatim)}\n"); QCString lang = m_langExt; if (!s->language().isEmpty()) // explicit language setting { lang = s->language(); } SrcLangExt langExt = getLanguageFromFileName(lang); switch(s->type()) { case DocVerbatim::Code: // fall though 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, s->isExample(),s->exampleFile()); //m_t << "\\par" << endl; m_t << "}" << endl; break; case DocVerbatim::Verbatim: m_t << "{" << endl; m_t << "\\par" << endl; m_t << rtf_Style_Reset << getStyle("CodeExample"); filter(s->text(),TRUE); //m_t << "\\par" << endl; m_t << "}" << endl; break; case DocVerbatim::RtfOnly: m_t << s->text(); break; case DocVerbatim::HtmlOnly: case DocVerbatim::LatexOnly: case DocVerbatim::XmlOnly: case DocVerbatim::ManOnly: case DocVerbatim::DocbookOnly: /* nothing */ break; case DocVerbatim::Dot: { static int dotindex = 1; QCString fileName(4096); fileName.sprintf("%s%d%s", (Config_getString("RTF_OUTPUT")+"/inline_dotgraph_").data(), dotindex++, ".dot" ); QFile file(fileName); if (!file.open(IO_WriteOnly)) { err("Could not open file %s for writing\n",fileName.data()); } file.writeBlock( s->text(), s->text().length() ); file.close(); m_t << "\\par{\\qc "; // center picture writeDotFile(fileName); m_t << "} "; if (Config_getBool("DOT_CLEANUP")) file.remove(); } break; case DocVerbatim::Msc: { static int mscindex = 1; QCString baseName(4096); baseName.sprintf("%s%d", (Config_getString("RTF_OUTPUT")+"/inline_mscgraph_").data(), mscindex++ ); QFile file(baseName+".msc"); if (!file.open(IO_WriteOnly)) { err("Could not open file %s for writing\n",baseName.data()); } QCString text = "msc {"; text+=s->text(); text+="}"; file.writeBlock( text, text.length() ); file.close(); m_t << "\\par{\\qc "; // center picture writeMscFile(baseName); m_t << "} "; if (Config_getBool("DOT_CLEANUP")) file.remove(); } break; } m_lastIsPara=FALSE; }
void RTFDocVisitor::visit(DocInclude *inc) { if (m_hide) return; SrcLangExt langExt = getLanguageFromFileName(inc->extension()); DBG_RTF("{\\comment RTFDocVisitor::visit(DocInclude)}\n"); switch(inc->type()) { case DocInclude::IncWithLines: { m_t << "{" << endl; m_t << "\\par" << endl; m_t << rtf_Style_Reset << getStyle("CodeExample"); QFileInfo cfi( inc->file() ); FileDef fd( cfi.dirPath().utf8(), cfi.fileName().utf8() ); Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), inc->exampleFile(), &fd); m_t << "\\par"; m_t << "}" << endl; } break; case DocInclude::Include: m_t << "{" << endl; m_t << "\\par" << endl; m_t << rtf_Style_Reset << getStyle("CodeExample"); Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci,inc->context(), inc->text(),langExt,inc->isExample(), inc->exampleFile()); m_t << "\\par"; m_t << "}" << endl; break; case DocInclude::DontInclude: break; case DocInclude::HtmlInclude: break; case DocInclude::LatexInclude: break; case DocInclude::VerbInclude: m_t << "{" << endl; m_t << "\\par" << endl; m_t << rtf_Style_Reset << getStyle("CodeExample"); filter(inc->text()); m_t << "\\par"; m_t << "}" << endl; break; case DocInclude::Snippet: 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, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, inc->isExample(), inc->exampleFile() ); m_t << "}"; break; } m_lastIsPara=TRUE; }
void DocbookDocVisitor::visit(DocVerbatim *s) { if (m_hide) return; SrcLangExt langExt = getLanguageFromFileName(m_langExt); switch(s->type()) { case DocVerbatim::Code: // fall though m_t << "<literallayout><computeroutput>"; Doxygen::parserManager->getParser(m_langExt) ->parseCode(m_ci,s->context(),s->text(),langExt, s->isExample(),s->exampleFile()); m_t << "</computeroutput></literallayout>"; break; case DocVerbatim::Verbatim: m_t << "<literallayout>"; filter(s->text()); m_t << "</literallayout>"; break; case DocVerbatim::HtmlOnly: break; case DocVerbatim::RtfOnly: break; case DocVerbatim::ManOnly: break; case DocVerbatim::LatexOnly: break; case DocVerbatim::XmlOnly: break; case DocVerbatim::DocbookOnly: break; m_t << s->text(); break; case DocVerbatim::Dot: { static int dotindex = 1; QCString baseName(4096); QCString name; QCString stext = s->text(); m_t << "<para>" << endl; name.sprintf("%s%d", "dot_inline_dotgraph_", dotindex); baseName.sprintf("%s%d", (Config_getString(DOCBOOK_OUTPUT)+"/inline_dotgraph_").data(), dotindex++ ); QFile file(baseName+".dot"); if (!file.open(IO_WriteOnly)) { err("Could not open file %s.msc for writing\n",baseName.data()); } file.writeBlock( stext, stext.length() ); file.close(); writeDotFile(baseName, s); m_t << "</para>" << endl; } break; case DocVerbatim::Msc: { static int mscindex = 1; QCString baseName(4096); QCString name; QCString stext = s->text(); m_t << "<para>" << endl; name.sprintf("%s%d", "msc_inline_mscgraph_", mscindex); baseName.sprintf("%s%d", (Config_getString(DOCBOOK_OUTPUT)+"/inline_mscgraph_").data(), mscindex++ ); QFile file(baseName+".msc"); if (!file.open(IO_WriteOnly)) { err("Could not open file %s.msc for writing\n",baseName.data()); } QCString text = "msc {"; text+=stext; text+="}"; file.writeBlock( text, text.length() ); file.close(); writeMscFile(baseName,s); m_t << "</para>" << endl; } break; case DocVerbatim::PlantUML: { static QCString docbookOutput = Config_getString(DOCBOOK_OUTPUT); QCString baseName = writePlantUMLSource(docbookOutput,s->exampleFile(),s->text()); QCString shortName = baseName; int i; if ((i=shortName.findRev('/'))!=-1) { shortName=shortName.right(shortName.length()-i-1); } m_t << "<para>" << endl; writePlantUMLFile(baseName,s); m_t << "</para>" << endl; } break; } }
/*! Reads a fragment of code from file \a fileName starting at * line \a startLine and ending at line \a endLine (inclusive). The fragment is * stored in \a result. If FALSE is returned the code fragment could not be * found. * * The file is scanned for a opening bracket ('{') from \a startLine onward * The line actually containing the bracket is returned via startLine. * The file is scanned for a closing bracket ('}') from \a endLine backward. * The line actually containing the bracket is returned via endLine. * Note that for VHDL code the bracket search is not done. */ bool readCodeFragment(const char *fileName, int &startLine,int &endLine,QCString &result) { static bool filterSourceFiles = Config_getBool("FILTER_SOURCE_FILES"); static int tabSize = Config_getInt("TAB_SIZE"); //printf("readCodeFragment(%s,%d,%d)\n",fileName,startLine,endLine); if (fileName==0 || fileName[0]==0) return FALSE; // not a valid file name QCString filter = getFileFilter(fileName,TRUE); FILE *f=0; bool usePipe = !filter.isEmpty() && filterSourceFiles; SrcLangExt lang = getLanguageFromFileName(fileName); if (!usePipe) // no filter given or wanted { f = portable_fopen(fileName,"r"); } else // use filter { QCString cmd=filter+" \""+fileName+"\""; Debug::print(Debug::ExtCmd,0,"Executing popen(`%s`)\n",cmd.data()); f = portable_popen(cmd,"r"); } bool found = lang==SrcLangExt_VHDL || lang==SrcLangExt_Tcl || lang==SrcLangExt_Python || lang==SrcLangExt_Fortran; // for VHDL, TCL, Python, and Fortran no bracket search is possible if (f) { int c=0; int col=0; int lineNr=1; // skip until the startLine has reached while (lineNr<startLine && !feof(f)) { while ((c=fgetc(f))!='\n' && c!=EOF) /* skip */; lineNr++; if (found && c == '\n') c = '\0'; } if (!feof(f)) { // skip until the opening bracket or lonely : is found char cn=0; while (lineNr<=endLine && !feof(f) && !found) { int pc=0; while ((c=fgetc(f))!='{' && c!=':' && c!=EOF) // } so vi matching brackets has no problem { //printf("parsing char `%c'\n",c); if (c=='\n') { lineNr++,col=0; } else if (c=='\t') { col+=tabSize - (col%tabSize); } else if (pc=='/' && c=='/') // skip single line comment { while ((c=fgetc(f))!='\n' && c!=EOF) pc=c; if (c=='\n') lineNr++,col=0; } else if (pc=='/' && c=='*') // skip C style comment { while (((c=fgetc(f))!='/' || pc!='*') && c!=EOF) { if (c=='\n') lineNr++,col=0; pc=c; } } else { col++; } pc = c; } if (c==':') { cn=fgetc(f); if (cn!=':') found=TRUE; } else if (c=='{') // } so vi matching brackets has no problem { found=TRUE; } } //printf(" -> readCodeFragment(%s,%d,%d) lineNr=%d\n",fileName,startLine,endLine,lineNr); if (found) { // For code with more than one line, // fill the line with spaces until we are at the right column // so that the opening brace lines up with the closing brace if (endLine!=startLine) { QCString spaces; spaces.fill(' ',col); result+=spaces; } // copy until end of line if (c) result+=c; startLine=lineNr; if (c==':') { result+=cn; if (cn=='\n') lineNr++; } const int maxLineLength=4096; char lineStr[maxLineLength]; do { //printf("reading line %d in range %d-%d\n",lineNr,startLine,endLine); int size_read; do { // read up to maxLineLength-1 bytes, the last byte being zero char *p = fgets(lineStr, maxLineLength,f); //printf(" read %s",p); if (p) { size_read=qstrlen(p); } else // nothing read { size_read=-1; lineStr[0]='\0'; } result+=lineStr; } while (size_read == (maxLineLength-1)); lineNr++; } while (lineNr<=endLine && !feof(f)); // strip stuff after closing bracket int newLineIndex = result.findRev('\n'); int braceIndex = result.findRev('}'); if (braceIndex > newLineIndex) { result.truncate(braceIndex+1); } endLine=lineNr-1; } } if (usePipe) { portable_pclose(f); Debug::print(Debug::FilterOutput, 0, "Filter output\n"); Debug::print(Debug::FilterOutput,0,"-------------\n%s\n-------------\n",result.data()); } else { fclose(f); } } result = transcodeCharacterStringToUTF8(result); //fprintf(stderr,"readCodeFragement(%d-%d)=%s\n",startLine,endLine,result.data()); return found; }
void ManDocVisitor::visit(DocInclude *inc) { if (m_hide) return; SrcLangExt langExt = getLanguageFromFileName(inc->extension()); switch(inc->type()) { case DocInclude::IncWithLines: { if (!m_firstCol) m_t << endl; m_t << ".PP" << endl; m_t << ".nf" << endl; QFileInfo cfi( inc->file() ); FileDef fd( cfi.dirPath().utf8(), cfi.fileName().utf8() ); Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), inc->exampleFile(), &fd, // fileDef, -1, // start line -1, // end line FALSE, // inline fragment 0, // memberDef TRUE ); if (!m_firstCol) m_t << endl; m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol=TRUE; } break; case DocInclude::Include: if (!m_firstCol) m_t << endl; m_t << ".PP" << endl; m_t << ".nf" << endl; Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), inc->exampleFile(), 0, // fileDef -1, // startLine -1, // endLine TRUE, // inlineFragment 0, // memberDef FALSE ); if (!m_firstCol) m_t << endl; m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol=TRUE; break; case DocInclude::DontInclude: break; case DocInclude::HtmlInclude: break; case DocInclude::LatexInclude: break; case DocInclude::VerbInclude: if (!m_firstCol) m_t << endl; m_t << ".PP" << endl; m_t << ".nf" << endl; m_t << inc->text(); if (!m_firstCol) m_t << endl; m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol=TRUE; break; case DocInclude::Snippet: if (!m_firstCol) m_t << endl; m_t << ".PP" << endl; m_t << ".nf" << endl; Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, inc->isExample(), inc->exampleFile() ); if (!m_firstCol) m_t << endl; m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol=TRUE; break; case DocInclude::SnipWithLines: { if (!m_firstCol) m_t << endl; m_t << ".PP" << endl; m_t << ".nf" << endl; QFileInfo cfi( inc->file() ); FileDef fd( cfi.dirPath().utf8(), cfi.fileName().utf8() ); Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, inc->isExample(), inc->exampleFile(), &fd, lineBlock(inc->text(),inc->blockId()), -1, // endLine FALSE, // inlineFragment 0, // memberDef TRUE // show line number ); if (!m_firstCol) m_t << endl; m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol=TRUE; } break; case DocInclude::SnippetDoc: case DocInclude::IncludeDoc: err("Internal inconsistency: found switch SnippetDoc / IncludeDoc in file: %s" "Please create a bug report\n",__FILE__); break; } }
void ManDocVisitor::visit(DocInclude *inc) { if (m_hide) return; SrcLangExt langExt = getLanguageFromFileName(inc->extension()); switch(inc->type()) { case DocInclude::IncWithLines: { if (!m_firstCol) m_t << endl; m_t << ".PP" << endl; m_t << ".nf" << endl; QFileInfo cfi( inc->file() ); FileDef fd( cfi.dirPath().utf8(), cfi.fileName().utf8() ); Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), inc->exampleFile(), &fd); if (!m_firstCol) m_t << endl; m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol=TRUE; } break; case DocInclude::Include: if (!m_firstCol) m_t << endl; m_t << ".PP" << endl; m_t << ".nf" << endl; Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), inc->exampleFile()); if (!m_firstCol) m_t << endl; m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol=TRUE; break; case DocInclude::DontInclude: break; case DocInclude::HtmlInclude: break; case DocInclude::LatexInclude: break; case DocInclude::VerbInclude: if (!m_firstCol) m_t << endl; m_t << ".PP" << endl; m_t << ".nf" << endl; m_t << inc->text(); if (!m_firstCol) m_t << endl; m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol=TRUE; break; case DocInclude::Snippet: if (!m_firstCol) m_t << endl; m_t << ".PP" << endl; m_t << ".nf" << endl; Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, inc->isExample(), inc->exampleFile() ); if (!m_firstCol) m_t << endl; m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol=TRUE; break; } }
void DocbookDocVisitor::visit(DocInclude *inc) { if (m_hide) return; SrcLangExt langExt = getLanguageFromFileName(inc->extension()); switch(inc->type()) { case DocInclude::IncWithLines: { m_t << "<literallayout><computeroutput>"; QFileInfo cfi( inc->file() ); FileDef fd( cfi.dirPath().utf8(), cfi.fileName().utf8() ); Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), inc->exampleFile(), &fd); m_t << "</computeroutput></literallayout>"; } break; case DocInclude::Include: m_t << "<literallayout><computeroutput>"; Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), inc->exampleFile()); m_t << "</computeroutput></literallayout>"; break; case DocInclude::DontInclude: break; case DocInclude::HtmlInclude: break; case DocInclude::LatexInclude: break; case DocInclude::VerbInclude: m_t << "<verbatim>"; filter(inc->text()); m_t << "</verbatim>"; break; case DocInclude::Snippet: m_t << "<literallayout><computeroutput>"; Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, inc->isExample(), inc->exampleFile() ); m_t << "</computeroutput></literallayout>"; break; case DocInclude::SnipWithLines: { QFileInfo cfi( inc->file() ); FileDef fd( cfi.dirPath().utf8(), cfi.fileName().utf8() ); m_t << "<literallayout><computeroutput>"; Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, inc->isExample(), inc->exampleFile(), &fd, lineBlock(inc->text(),inc->blockId()), -1, // endLine FALSE, // inlineFragment 0, // memberDef TRUE // show line number ); m_t << "</computeroutput></literallayout>"; } break; case DocInclude::SnippetDoc: case DocInclude::IncludeDoc: err("Internal inconsistency: found switch SnippetDoc / IncludeDoc in file: %s" "Please create a bug report\n",__FILE__); break; } }
void DocbookDocVisitor::visit(DocVerbatim *s) { if (m_hide) return; SrcLangExt langExt = getLanguageFromFileName(m_langExt); switch(s->type()) { case DocVerbatim::Code: // fall though m_t << "<literallayout><computeroutput>"; Doxygen::parserManager->getParser(m_langExt) ->parseCode(m_ci,s->context(),s->text(),langExt, s->isExample(),s->exampleFile()); m_t << "</computeroutput></literallayout>"; break; case DocVerbatim::Verbatim: m_t << "<literallayout>"; filter(s->text()); m_t << "</literallayout>"; break; case DocVerbatim::HtmlOnly: break; case DocVerbatim::RtfOnly: break; case DocVerbatim::ManOnly: break; case DocVerbatim::LatexOnly: break; case DocVerbatim::XmlOnly: break; case DocVerbatim::DocbookOnly: break; m_t << s->text(); break; case DocVerbatim::Dot: { static int dotindex = 1; QCString baseName(4096); QCString name; QCString stext = s->text(); m_t << "<para>" << endl; name.sprintf("%s%d", "dot_inline_dotgraph_", dotindex); baseName.sprintf("%s%d", (Config_getString("DOCBOOK_OUTPUT")+"/inline_dotgraph_").data(), dotindex++ ); QFile file(baseName+".dot"); if (!file.open(IO_WriteOnly)) { err("Could not open file %s.msc for writing\n",baseName.data()); } file.writeBlock( stext, stext.length() ); file.close(); m_t << " <figure>" << endl; m_t << " <title>" << name << "</title>" << endl; m_t << " <mediaobject>" << endl; m_t << " <imageobject>" << endl; writeDotFile(baseName); m_t << " </imageobject>" << endl; m_t << " </mediaobject>" << endl; m_t << " </figure>" << endl; m_t << "</para>" << endl; } break; case DocVerbatim::Msc: static int mscindex = 1; QCString baseName(4096); QCString name; QCString stext = s->text(); m_t << "<para>" << endl; name.sprintf("%s%d", "msc_inline_mscgraph_", mscindex); baseName.sprintf("%s%d", (Config_getString("DOCBOOK_OUTPUT")+"/inline_mscgraph_").data(), mscindex++ ); QFile file(baseName+".msc"); if (!file.open(IO_WriteOnly)) { err("Could not open file %s.msc for writing\n",baseName.data()); } QCString text = "msc {"; text+=stext; text+="}"; file.writeBlock( text, text.length() ); file.close(); m_t << " <figure>" << endl; m_t << " <title>" << name << "</title>" << endl; m_t << " <mediaobject>" << endl; m_t << " <imageobject>" << endl; writeMscFile(baseName); m_t << " </imageobject>" << endl; m_t << " </mediaobject>" << endl; m_t << " </figure>" << endl; m_t << "</para>" << endl; break; } }
void XmlDocVisitor::visit(DocInclude *inc) { if (m_hide) return; SrcLangExt langExt = getLanguageFromFileName(inc->extension()); switch(inc->type()) { case DocInclude::IncWithLines: { m_t << "<programlisting filename=\"" << inc->file() << "\">"; QFileInfo cfi( inc->file() ); FileDef fd( cfi.dirPath().utf8(), cfi.fileName().utf8() ); Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), inc->exampleFile(), &fd, // fileDef, -1, // start line -1, // end line FALSE, // inline fragment 0, // memberDef TRUE // show line numbers ); m_t << "</programlisting>"; } break; case DocInclude::Include: m_t << "<programlisting filename=\"" << inc->file() << "\">"; Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci,inc->context(), inc->text(), langExt, inc->isExample(), inc->exampleFile(), 0, // fileDef -1, // startLine -1, // endLine TRUE, // inlineFragment 0, // memberDef FALSE // show line numbers ); m_t << "</programlisting>"; break; case DocInclude::DontInclude: break; case DocInclude::HtmlInclude: m_t << "<htmlonly>"; filter(inc->text()); m_t << "</htmlonly>"; break; case DocInclude::LatexInclude: m_t << "<latexonly>"; filter(inc->text()); m_t << "</latexonly>"; break; case DocInclude::VerbInclude: m_t << "<verbatim>"; filter(inc->text()); m_t << "</verbatim>"; break; case DocInclude::Snippet: m_t << "<programlisting filename=\"" << inc->file() << "\">"; Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, inc->isExample(), inc->exampleFile() ); m_t << "</programlisting>"; break; case DocInclude::SnipWithLines: { m_t << "<programlisting filename=\"" << inc->file() << "\">"; QFileInfo cfi( inc->file() ); FileDef fd( cfi.dirPath().utf8(), cfi.fileName().utf8() ); Doxygen::parserManager->getParser(inc->extension()) ->parseCode(m_ci, inc->context(), extractBlock(inc->text(),inc->blockId()), langExt, inc->isExample(), inc->exampleFile(), &fd, lineBlock(inc->text(),inc->blockId()), -1, // endLine FALSE, // inlineFragment 0, // memberDef TRUE // show line number ); m_t << "</programlisting>"; } break; case DocInclude::SnippetDoc: case DocInclude::IncludeDoc: err("Internal inconsistency: found switch SnippetDoc / IncludeDoc in file: %s" "Please create a bug report\n",__FILE__); break; } }
void ManDocVisitor::visit(DocInclude *inc) { if (m_hide) { return; } SrcLangExt langExt = getLanguageFromFileName(inc->extension()); switch (inc->type()) { case DocInclude::IncWithLines: { if (! m_firstCol) { m_t << endl; } m_t << ".PP" << endl; m_t << ".nf" << endl; QFileInfo cfi( inc->file() ); QSharedPointer<FileDef> fd = QMakeShared<FileDef>( cfi.path(), cfi.fileName() ); Doxy_Globals::parserManager->getParser(inc->extension())->parseCode(m_ci, inc->context(), inc->text(), langExt, inc->isExample(), inc->exampleFile(), fd); if (! m_firstCol) { m_t << endl; } m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol = true; } break; case DocInclude::Include: if (!m_firstCol) { m_t << endl; } m_t << ".PP" << endl; m_t << ".nf" << endl; Doxy_Globals::parserManager->getParser(inc->extension())->parseCode(m_ci, inc->context(),inc->text(),langExt, inc->isExample(), inc->exampleFile()); if (!m_firstCol) { m_t << endl; } m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol = true; break; case DocInclude::DontInclude: break; case DocInclude::HtmlInclude: break; case DocInclude::LatexInclude: break; case DocInclude::VerbInclude: if (! m_firstCol) { m_t << endl; } m_t << ".PP" << endl; m_t << ".nf" << endl; m_t << inc->text(); if (!m_firstCol) { m_t << endl; } m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol = true; break; case DocInclude::Snippet: if (!m_firstCol) { m_t << endl; } m_t << ".PP" << endl; m_t << ".nf" << endl; Doxy_Globals::parserManager->getParser(inc->extension())->parseCode(m_ci, inc->context(), extractBlock(inc->text(), inc->blockId()), langExt, inc->isExample(), inc->exampleFile() ); if (!m_firstCol) { m_t << endl; } m_t << ".fi" << endl; m_t << ".PP" << endl; m_firstCol = true; break; } }
void ClangParser::start(const QString &fileName, QStringList &includeFiles) { static QStringList includePath = Config::getList("include-path"); static QStringList clangFlags = Config::getList("clang-flags"); p->fileName = fileName; p->index = clang_createIndex(0, 0); p->curLine = 1; p->curToken = 0; char **argv = (char **)malloc(sizeof(char *) * (4 + Doxy_Globals::inputPaths.count() + includePath.count() + clangFlags.count())); int argc = 0; // add include paths for input files for (auto item : Doxy_Globals::inputPaths) { QString inc = "-I" + item; argv[argc] = strdup(inc.toUtf8()); ++argc; } // add external include paths for (uint i = 0; i < includePath.count(); i++) { QString inc = "-I" + includePath.at(i); argv[argc++] = strdup(inc.toUtf8()); } // user specified options for (uint i = 0; i < clangFlags.count(); i++) { argv[argc++] = strdup(clangFlags.at(i).toUtf8()); } // extra options argv[argc++] = strdup("-ferror-limit=0"); argv[argc++] = strdup("-x"); // Since we can be presented with an .h file that can contain C, C++, or Objective C, // we need to configure the parser before knowing this. // Use the source file to detected the language. Detection will fail if you // pass a bunch of .h files containing ObjC code and no source SrcLangExt lang = getLanguageFromFileName(fileName); if (lang == SrcLangExt_ObjC || p->detectedLang != ClangParser::Private::Detected_Cpp) { QString fn = fileName; if (p->detectedLang == ClangParser::Private::Detected_Cpp && (fn.right(4).toLower() == ".cpp" || fn.right(4).toLower() == ".cxx" || fn.right(3).toLower() == ".cc" || fn.right(2).toLower() == ".c")) { // fall back to C/C++ once we see an extension that indicates this p->detectedLang = ClangParser::Private::Detected_Cpp; } else if (fn.right(3).toLower() == ".mm") { // switch to Objective C++ p->detectedLang = ClangParser::Private::Detected_ObjCpp; } else if (fn.right(2).toLower() == ".m") { // switch to Objective C p->detectedLang = ClangParser::Private::Detected_ObjC; } } switch (p->detectedLang) { case ClangParser::Private::Detected_Cpp: argv[argc++] = strdup("c++"); break; case ClangParser::Private::Detected_ObjC: argv[argc++] = strdup("objective-c"); break; case ClangParser::Private::Detected_ObjCpp: argv[argc++] = strdup("objective-c++"); break; } // provide the input and and its dependencies as unsaved files so we can pass the filtered versions static bool filterSourceFiles = Config::getBool("filter-source-files"); argv[argc++] = strdup(fileName.toUtf8()); uint numUnsavedFiles = includeFiles.count() + 1; p->numFiles = numUnsavedFiles; p->sources = new QByteArray[numUnsavedFiles]; p->ufs = new CXUnsavedFile[numUnsavedFiles]; p->sources[0] = detab(fileToString(fileName, filterSourceFiles, true)).toUtf8(); p->ufs[0].Filename = strdup(fileName.toUtf8()); p->ufs[0].Contents = p->sources[0].constData(); p->ufs[0].Length = p->sources[0].length(); // uint i = 1; for (auto item : includeFiles) { p->fileMapping.insert(item, i); p->sources[i] = detab(fileToString(item, filterSourceFiles, true)).toUtf8(); p->ufs[i].Filename = strdup(item.toUtf8()); p->ufs[i].Contents = p->sources[i].constData(); p->ufs[i].Length = p->sources[i].length(); i++; } // let libclang do the actual parsing CXErrorCode errorCode = clang_parseTranslationUnit2(p->index, 0, argv, argc, 0, 0, CXTranslationUnit_DetailedPreprocessingRecord, &(p->tu) ); // free arguments for (int i = 0; i < argc; ++i) { free(argv[i]); } free(argv); if (p->tu) { // filter out any includes not found by the clang parser determineInputFiles(includeFiles); // show any warnings the compiler produced uint n = clang_getNumDiagnostics(p->tu); for (uint i = 0; i != n; ++i) { CXDiagnostic diag = clang_getDiagnostic(p->tu, i); CXString string = clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions()); err("Clang parser warning -- %s\n", clang_getCString(string)); clang_disposeString(string); clang_disposeDiagnostic(diag); } // create a source range for the given file QFileInfo fi(fileName); CXFile f = clang_getFile(p->tu, fileName.toUtf8()); CXSourceLocation fileBegin = clang_getLocationForOffset(p->tu, f, 0); CXSourceLocation fileEnd = clang_getLocationForOffset(p->tu, f, p->ufs[0].Length); CXSourceRange fileRange = clang_getRange(fileBegin, fileEnd); // produce a token stream for the file clang_tokenize(p->tu, fileRange, &p->tokens, &p->numTokens); // produce cursors for each token in the stream p->cursors = new CXCursor[p->numTokens]; clang_annotateTokens(p->tu, p->tokens, p->numTokens, p->cursors); } else { p->tokens = 0; p->numTokens = 0; p->cursors = 0; err("Clang failed to parse translation unit -- %s\n", qPrintable(fileName)); } }
void LatexDocVisitor::visit(DocVerbatim *s) { if (m_hide) return; QCString lang = m_langExt; if (!s->language().isEmpty()) // explicit language setting { lang = s->language(); } SrcLangExt langExt = getLanguageFromFileName(lang); switch(s->type()) { case DocVerbatim::Code: { m_t << "\n\\begin{DoxyCode}\n"; Doxygen::parserManager->getParser(lang) ->parseCode(m_ci,s->context(),s->text(),langExt, s->isExample(),s->exampleFile()); m_t << "\\end{DoxyCode}\n"; } break; case DocVerbatim::Verbatim: m_t << "\\begin{DoxyVerb}"; m_t << s->text(); m_t << "\\end{DoxyVerb}\n"; break; case DocVerbatim::HtmlOnly: case DocVerbatim::XmlOnly: case DocVerbatim::ManOnly: case DocVerbatim::RtfOnly: case DocVerbatim::DocbookOnly: /* nothing */ break; case DocVerbatim::LatexOnly: m_t << s->text(); break; case DocVerbatim::Dot: { static int dotindex = 1; QCString fileName(4096); fileName.sprintf("%s%d%s", (Config_getString("LATEX_OUTPUT")+"/inline_dotgraph_").data(), dotindex++, ".dot" ); QFile file(fileName); if (!file.open(IO_WriteOnly)) { err("Could not open file %s for writing\n",fileName.data()); } file.writeBlock( s->text(), s->text().length() ); file.close(); m_t << "\\begin{center}\n"; startDotFile(fileName,"","",FALSE); endDotFile(FALSE); m_t << "\\end{center}\n"; if (Config_getBool("DOT_CLEANUP")) file.remove(); } break; case DocVerbatim::Msc: { static int mscindex = 1; QCString baseName(4096); baseName.sprintf("%s%d", (Config_getString("LATEX_OUTPUT")+"/inline_mscgraph_").data(), mscindex++ ); QFile file(baseName+".msc"); if (!file.open(IO_WriteOnly)) { err("Could not open file %s.msc for writing\n",baseName.data()); } QCString text = "msc {"; text+=s->text(); text+="}"; file.writeBlock( text, text.length() ); file.close(); m_t << "\\begin{center}\n"; writeMscFile(baseName); m_t << "\\end{center}\n"; if (Config_getBool("DOT_CLEANUP")) file.remove(); } break; } }
void ClangParser::start(const char *fileName,QStrList &filesInTranslationUnit) { static bool clangAssistedParsing = Config_getBool("CLANG_ASSISTED_PARSING"); static QStrList &includePath = Config_getList("INCLUDE_PATH"); static QStrList clangOptions = Config_getList("CLANG_OPTIONS"); if (!clangAssistedParsing) return; //printf("ClangParser::start(%s)\n",fileName); p->fileName = fileName; p->index = clang_createIndex(0, 0); p->curLine = 1; p->curToken = 0; char **argv = (char**)malloc(sizeof(char*)*(4+Doxygen::inputPaths.count()+includePath.count()+clangOptions.count())); QDictIterator<void> di(Doxygen::inputPaths); int argc=0; // add include paths for input files for (di.toFirst();di.current();++di,++argc) { QCString inc = QCString("-I")+di.currentKey(); argv[argc]=strdup(inc.data()); //printf("argv[%d]=%s\n",argc,argv[argc]); } // add external include paths for (uint i=0;i<includePath.count();i++) { QCString inc = QCString("-I")+includePath.at(i); argv[argc++]=strdup(inc.data()); } // user specified options for (uint i=0;i<clangOptions.count();i++) { argv[argc++]=strdup(clangOptions.at(i)); } // extra options argv[argc++]=strdup("-ferror-limit=0"); argv[argc++]=strdup("-x"); // Since we can be presented with a .h file that can contain C/C++ or // Objective C code and we need to configure the parser before knowing this, // we use the source file to detected the language. Detection will fail if you // pass a bunch of .h files containing ObjC code, and no sources :-( SrcLangExt lang = getLanguageFromFileName(fileName); if (lang==SrcLangExt_ObjC || p->detectedLang!=ClangParser::Private::Detected_Cpp) { QCString fn = fileName; if (p->detectedLang==ClangParser::Private::Detected_Cpp && (fn.right(4).lower()==".cpp" || fn.right(4).lower()==".cxx" || fn.right(3).lower()==".cc" || fn.right(2).lower()==".c")) { // fall back to C/C++ once we see an extension that indicates this p->detectedLang = ClangParser::Private::Detected_Cpp; } else if (fn.right(3).lower()==".mm") // switch to Objective C++ { p->detectedLang = ClangParser::Private::Detected_ObjCpp; } else if (fn.right(2).lower()==".m") // switch to Objective C { p->detectedLang = ClangParser::Private::Detected_ObjC; } } switch(p->detectedLang) { case ClangParser::Private::Detected_Cpp: argv[argc++]=strdup("c++"); break; case ClangParser::Private::Detected_ObjC: argv[argc++]=strdup("objective-c"); break; case ClangParser::Private::Detected_ObjCpp: argv[argc++]=strdup("objective-c++"); break; } // provide the input and and its dependencies as unsaved files so we can // pass the filtered versions argv[argc++]=strdup(fileName); static bool filterSourceFiles = Config_getBool("FILTER_SOURCE_FILES"); //printf("source %s ----------\n%s\n-------------\n\n", // fileName,p->source.data()); uint numUnsavedFiles = filesInTranslationUnit.count()+1; p->numFiles = numUnsavedFiles; p->sources = new QCString[numUnsavedFiles]; p->ufs = new CXUnsavedFile[numUnsavedFiles]; p->sources[0] = detab(fileToString(fileName,filterSourceFiles,TRUE)); p->ufs[0].Filename = strdup(fileName); p->ufs[0].Contents = p->sources[0].data(); p->ufs[0].Length = p->sources[0].length(); QStrListIterator it(filesInTranslationUnit); uint i=1; for (it.toFirst();it.current() && i<numUnsavedFiles;++it,i++) { p->fileMapping.insert(it.current(),new uint(i)); p->sources[i] = detab(fileToString(it.current(),filterSourceFiles,TRUE)); p->ufs[i].Filename = strdup(it.current()); p->ufs[i].Contents = p->sources[i].data(); p->ufs[i].Length = p->sources[i].length(); } // let libclang do the actual parsing p->tu = clang_parseTranslationUnit(p->index, 0, argv, argc, p->ufs, numUnsavedFiles, CXTranslationUnit_DetailedPreprocessingRecord); // free arguments for (int i=0;i<argc;++i) { free(argv[i]); } free(argv); if (p->tu) { // filter out any includes not found by the clang parser determineInputFilesInSameTu(filesInTranslationUnit); // show any warnings that the compiler produced for (uint i=0, n=clang_getNumDiagnostics(p->tu); i!=n; ++i) { CXDiagnostic diag = clang_getDiagnostic(p->tu, i); CXString string = clang_formatDiagnostic(diag, clang_defaultDiagnosticDisplayOptions()); err("%s [clang]\n",clang_getCString(string)); clang_disposeString(string); clang_disposeDiagnostic(diag); } // create a source range for the given file QFileInfo fi(fileName); CXFile f = clang_getFile(p->tu, fileName); CXSourceLocation fileBegin = clang_getLocationForOffset(p->tu, f, 0); CXSourceLocation fileEnd = clang_getLocationForOffset(p->tu, f, p->ufs[0].Length); CXSourceRange fileRange = clang_getRange(fileBegin, fileEnd); // produce a token stream for the file clang_tokenize(p->tu,fileRange,&p->tokens,&p->numTokens); // produce cursors for each token in the stream p->cursors=new CXCursor[p->numTokens]; clang_annotateTokens(p->tu,p->tokens,p->numTokens,p->cursors); } else { p->tokens = 0; p->numTokens = 0; p->cursors = 0; err("clang: Failed to parse translation unit %s\n",fileName); } }
/** Writes the list of members to the output. * @param ol Output list to write to * @param cd non-null if this list is part of class documentation. * @param nd non-null if this list is part of namespace documentation. * @param fd non-null if this list is part of file documentation. * @param gd non-null if this list is part of group documentation. * @param title Title to use for the member list. * @param subtitle Sub title to use for the member list. * @param showEnumValues Obsolete, always set to FALSE. * @param showInline if set to TRUE if title is rendered differently * @param inheritedFrom if not 0, the list is shown inside the * given class as inherited members, parameter cd points to the * class containing the members. */ void MemberList::writeDeclarations(OutputList &ol, ClassDef *cd,NamespaceDef *nd,FileDef *fd,GroupDef *gd, const char *title,const char *subtitle, bool showEnumValues, bool showInline,ClassDef *inheritedFrom) { (void)showEnumValues; // unused //printf("----- writeDeclaration() this=%p ---- inheritedFrom=%p\n",this,inheritedFrom); static bool optimizeVhdl = Config_getBool("OPTIMIZE_OUTPUT_VHDL"); static bool optimizeVerilog = Config_getBool("OPTIMIZE_OUTPUT_VERILOG"); QCString inheritId; countDecMembers(/*showEnumValues*/FALSE,gd); // count members shown in this section Definition *ctx = cd; if (ctx==0 && nd) ctx = nd; if (ctx==0 && gd) ctx = gd; if (ctx==0 && fd) ctx = fd; //printf("%p: MemberList::writeDeclaration(title=`%s',subtitle=`%s')=%d\n", // this,title,subtitle,numDecMembers()); int num = numDecMembers(); if (inheritedFrom) { if ( cd && !optimizeVhdl && countInheritableMembers(inheritedFrom)>0 ) { ol.pushGeneratorState(); ol.disableAllBut(OutputGenerator::Html); inheritId = substitute(listTypeAsString(),"-","_")+"_"+ stripPath(cd->getOutputFileBase()); if (title) { ol.writeInheritedSectionTitle(inheritId,cd->getOutputFileBase(), cd->anchor(),title,cd->displayName()); } ol.popGeneratorState(); } } else if (num>0) { if (title) { if (showInline) { ol.startInlineHeader(); } else { ol.startMemberHeader(listTypeAsString()); } ol.parseText(title); if (showInline) { ol.endInlineHeader(); } else { ol.endMemberHeader(); } } if (subtitle) { QCString st=subtitle; st = st.stripWhiteSpace(); if (!st.isEmpty()) { ol.startMemberSubtitle(); ol.parseDoc("[generated]",-1,ctx,0,subtitle,FALSE,FALSE,0,FALSE,FALSE); ol.endMemberSubtitle(); } } } if (num>0) { // TODO: Two things need to be worked out for proper VHDL output: // 1. Signals and types under the group need to be // formatted to associate them with the group somehow // indentation, or at the very least, extra space after // the group is done // 2. This might need to be repeated below for memberGroupLists if (optimizeVhdl) // use specific declarations function { SrcLangExt lang = getLanguageFromFileName(fd->name()); if(optimizeVerilog && lang==SrcLangExt_VERILOG) { VerilogDocGen::writeVerilogDeclarations(this,ol,0,cd,0); } else if(lang==SrcLangExt_VHDL) { VhdlDocGen::writeVhdlDeclarations(this,ol,0,cd,0,0); } } else { writePlainDeclarations(ol,cd,nd,fd,gd,inheritedFrom,inheritId); } //printf("memberGroupList=%p\n",memberGroupList); if (memberGroupList) { MemberGroupListIterator mgli(*memberGroupList); MemberGroup *mg; while ((mg=mgli.current())) { bool hasHeader=!mg->header().isEmpty() && mg->header()!="[NOHEADER]"; if (inheritId.isEmpty()) { //printf("mg->header=%s hasHeader=%d\n",mg->header().data(),hasHeader); ol.startMemberGroupHeader(hasHeader); if (hasHeader) { ol.parseText(mg->header()); } ol.endMemberGroupHeader(); if (!mg->documentation().isEmpty()) { //printf("Member group has docs!\n"); ol.startMemberGroupDocs(); ol.parseDoc("[generated]",-1,ctx,0,mg->documentation()+"\n",FALSE,FALSE); ol.endMemberGroupDocs(); } ol.startMemberGroup(); } //printf("--- mg->writePlainDeclarations ---\n"); mg->writePlainDeclarations(ol,cd,nd,fd,gd,inheritedFrom,inheritId); if (inheritId.isEmpty()) { ol.endMemberGroup(hasHeader); } ++mgli; } } } if (inheritedFrom && cd) { // also add members that of this list type, that are grouped together // in a separate list in class 'inheritedFrom' cd->addGroupedInheritedMembers(ol,m_listType,inheritedFrom,inheritId); } //printf("----- end writeDeclaration() ----\n"); }