Doxygen
Loading...
Searching...
No Matches
docparser.cpp
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2022 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15
16// own header
17#include "docparser.h"
18
19// standard includes
20#include <cstdint>
21#include <cstdio>
22
23// other includes
24#include "classlist.h"
25#include "config.h"
26#include "debug.h"
27#include "dir.h"
28#include "docparser_p.h"
29#include "doxygen.h"
30#include "filedef.h"
31#include "fileinfo.h"
32#include "filename.h"
33#include "groupdef.h"
34#include "htmldocvisitor.h"
35#include "indexlist.h"
36#include "message.h"
37#include "namespacedef.h"
38#include "outputlist.h"
39#include "pagedef.h"
40#include "portable.h"
41#include "printdocvisitor.h"
42#include "stringutil.h"
43#include "textdocvisitor.h"
44#include "trace.h"
45#include "util.h"
46
47#if !ENABLE_DOCPARSER_TRACING
48#undef AUTO_TRACE
49#undef AUTO_TRACE_ADD
50#undef AUTO_TRACE_EXIT
51#define AUTO_TRACE(...) (void)0
52#define AUTO_TRACE_ADD(...) (void)0
53#define AUTO_TRACE_EXIT(...) (void)0
54#endif
55
56
57//---------------------------------------------------------------------------
58
60{
61 return std::make_unique<DocParser>();
62}
63
65{
66 //DString indent;
67 //indent.fill(' ',contextStack.size()*2+2);
68 //printf("%sdocParserPushContext() count=%zu\n",qPrint(indent),context.nodeStack.size());
69
71 contextStack.emplace();
72 auto &ctx = contextStack.top();
73 ctx = context;
75 ctx.lineNo = tokenizer.getLineNr();
77}
78
80{
81 auto &ctx = contextStack.top();
82 context = ctx;
83 tokenizer.setFileName(ctx.fileName);
84 tokenizer.setLineNr(ctx.lineNo);
85 contextStack.pop();
88
89 //DString indent;
90 //indent.fill(' ',contextStack.size()*2+2);
91 //printf("%sdocParserPopContext() count=%zu\n",qPrint(indent),context.nodeStack.size());
92}
93
94//---------------------------------------------------------------------------
95
96/*! search for an image in the imageNameDict and if found
97 * copies the image to the output directory (which depends on the \a type
98 * parameter).
99 */
101{
102 DString result;
103 bool ambig = false;
104 FileDef *fd = Doxygen::imageNameLinkedMap->findFileDef(fileName,ambig);
105 //printf("Search for %s\n",fileName);
106 if (fd)
107 {
108 if (ambig & doWarn)
109 {
111 "image file name '{}' is ambiguous.\n"
112 "Possible candidates:\n{}", fileName,Doxygen::imageNameLinkedMap->showFileDefMatches(fileName));
113 }
114
115 DString inputFile = fd->absFilePath();
116 FileInfo infi(inputFile.str());
117 if (infi.exists())
118 {
119 result = fileName;
120 if (size_t i = result.rfind('/') ; i!=DString::npos || (i=result.rfind('\\'))!=DString::npos)
121 {
122 result = result.mid(i+1);
123 }
124 //printf("fileName=%s result=%s\n",fileName,qPrint(result));
125 DString outputDir;
126 switch(type)
127 {
128 case DocImage::Html:
129 if (!Config_getBool(GENERATE_HTML)) return result;
130 outputDir = Config_getString(HTML_OUTPUT);
131 break;
132 case DocImage::Latex:
133 if (!Config_getBool(GENERATE_LATEX)) return result;
134 outputDir = Config_getString(LATEX_OUTPUT);
135 break;
137 if (!Config_getBool(GENERATE_DOCBOOK)) return result;
138 outputDir = Config_getString(DOCBOOK_OUTPUT);
139 break;
140 case DocImage::Rtf:
141 if (!Config_getBool(GENERATE_RTF)) return result;
142 outputDir = Config_getString(RTF_OUTPUT);
143 break;
144 case DocImage::Xml:
145 if (!Config_getBool(GENERATE_XML)) return result;
146 outputDir = Config_getString(XML_OUTPUT);
147 break;
148 }
149 DString outputFile = outputDir+"/"+result;
150 FileInfo outfi(outputFile.str());
151 if (outfi.isSymLink())
152 {
153 Dir().remove(outputFile.str());
155 "destination of image {} is a symlink, replacing with image",
156 outputFile);
157 }
158 if (outputFile!=inputFile) // prevent copying to ourself
159 {
160 if (copyFile(inputFile,outputFile) && type==DocImage::Html)
161 {
163 }
164 }
165 }
166 else
167 {
169 "could not open image {}",fileName);
170 }
171
172 if (type==DocImage::Latex && Config_getBool(USE_PDFLATEX) &&
173 fd->name().endsWith(".eps")
174 )
175 { // we have an .eps image in pdflatex mode => convert it to a pdf.
176 DString outputDir = Config_getString(LATEX_OUTPUT);
177 DString baseName = fd->name().left(fd->name().length()-4);
178 DString epstopdfArgs(4096, DString::ExplicitSize);
179 epstopdfArgs.sprintf("\"%s/%s.eps\" --outfile=\"%s/%s.pdf\"",
180 qPrint(outputDir), qPrint(baseName),
181 qPrint(outputDir), qPrint(baseName));
182 if (Portable::system("epstopdf",epstopdfArgs)!=0)
183 {
184 err("Problems running epstopdf. Check your TeX installation!\n");
185 }
186 else
187 {
188 Dir().remove(outputDir.str()+"/"+baseName.str()+".eps");
189 }
190 return baseName;
191 }
192 }
193 else
194 {
195 result=fileName;
196 if (!result.startsWith("http:") && !result.startsWith("https:") && doWarn)
197 {
199 "image file {} is not found in IMAGE_PATH: "
200 "assuming external image.",fileName
201 );
202 }
203 }
204 return result;
205}
206
207/*! Collects the parameters found with \@param command
208 * in a list context.paramsFound. If
209 * the parameter is not an actual parameter of the current
210 * member context.memberDef, then a warning is raised (unless warnings
211 * are disabled altogether).
212 */
214{
215 if (!(Config_getBool(WARN_IF_DOC_ERROR) || Config_getBool(WARN_IF_INCOMPLETE_DOC))) return;
216 if (context.memberDef==nullptr) return; // not a member
217 std::string name = context.token->name.str();
222 context.numParameters = static_cast<int>(al.size());
223 //printf("isDocsForDefinition()=%d\n",context.memberDef->isDocsForDefinition());
224 if (al.empty()) return; // no argument list
225
226 static const reg::Ex re(R"(\$?\w+\.*)");
227 static const reg::Ex re_digits(R"(\d+)");
228 reg::Iterator it(name,re);
230 for (; it!=end ; ++it)
231 {
232 const auto &match = *it;
233 DString aName=match.str();
234 int number = reg::match(aName.view(),re_digits) ? std::atoi(aName.data()) : -1;
235 if (lang==SrcLangExt::Fortran) aName=aName.lower();
236 //printf("aName='%s'\n",qPrint(aName));
237 bool found=false;
238 int position=1;
239 for (const Argument &a : al)
240 {
241 DString argName = context.memberDef->isDefine() ? a.type : a.name;
242 if (lang==SrcLangExt::Fortran) argName=argName.lower();
243 argName=argName.stripWhiteSpace();
244 //printf("argName='%s' aName=%s\n",qPrint(argName),qPrint(aName));
245 if (argName.endsWith("...")) argName=argName.left(argName.length()-3);
246 bool sameName = aName==argName;
247 bool samePosition = position==number;
248 if (samePosition || sameName) // @param <number> or @param name
249 {
250 if (!sameName) // replace positional argument with real name or -
251 {
252 context.token->name = argName.empty() ? "-" : argName;
253 }
254 context.paramsFound.insert(aName.str());
255 found=true;
256 break;
257 }
258 else if (aName==".") // replace . by - in the output
259 {
260 context.token->name = "-";
261 }
262 position++;
263 }
264 if (!found)
265 {
266 //printf("member type=%d\n",context.memberDef->memberType());
268 if (!scope.empty()) scope+="::"; else scope="";
269 DString inheritedFrom = "";
270 DString docFile = context.memberDef->docFile();
271 int docLine = context.memberDef->docLine();
272 const MemberDef *inheritedMd = context.memberDef->inheritsDocsFrom();
273 if (inheritedMd) // documentation was inherited
274 {
275 inheritedFrom.sprintf(" inherited from member %s at line "
276 "%d in file %s",qPrint(inheritedMd->name()),
277 inheritedMd->docLine(),qPrint(inheritedMd->docFile()));
278 docFile = context.memberDef->getDefFileName();
279 docLine = context.memberDef->getDefLine();
280 }
281 DString alStr = argListToString(al);
282 if (number==0)
283 {
284 warn_doc_error(docFile,docLine,
285 "positional argument with value '0' of command @param "
286 "is invalid, first parameter has index '1' for {}{}{}{}",
287 scope, context.memberDef->name(),
288 alStr, inheritedFrom);
289 context.token->name = "-";
290 }
291 else if (number>0)
292 {
293 warn_doc_error(docFile,docLine,
294 "positional argument '{}' of command @param "
295 "is larger than the number of parameters ({}) for {}{}{}{}",
296 number, al.size(), scope, context.memberDef->name(),
297 alStr, inheritedFrom);
298 context.token->name = "-";
299 }
300 else
301 {
302 warn_doc_error(docFile,docLine,
303 "argument '{}' of command @param "
304 "is not found in the argument list of {}{}{}{}",
305 aName, scope, context.memberDef->name(),
306 alStr, inheritedFrom);
307 }
308 }
309 }
310}
311/*! Collects the return values found with \@retval command
312 * in a global list g_parserContext.retvalsFound.
313 */
315{
316 DString name = context.token->name;
317 if (!Config_getBool(WARN_IF_DOC_ERROR)) return;
318 if (context.memberDef==nullptr || name.empty()) return; // not a member or no valid name
319 if (context.retvalsFound.count(name.str())==1) // only report the first double entry
320 {
323 "return value '{}' of {} has multiple documentation sections",
325 }
326 context.retvalsFound.insert(name.str());
327}
328
329/*! Checks if the parameters that have been specified using \@param are
330 * indeed all parameters and that a parameter does not have multiple
331 * \@param blocks.
332 * Must be called after checkArgumentName() has been called for each
333 * argument.
334 */
336{
338 {
343 if (!al.empty())
344 {
345 ArgumentList undocParams;
346 int position = 1;
347 for (const Argument &a: al)
348 {
349 DString argName = context.memberDef->isDefine() ? a.type : a.name;
350 if (lang==SrcLangExt::Fortran) argName = argName.lower();
351 argName=argName.stripWhiteSpace();
352 DString aName = argName;
353 if (argName.endsWith("...")) argName=argName.left(argName.length()-3);
354 if (lang==SrcLangExt::Python && (argName=="self" || argName=="cls"))
355 {
356 // allow undocumented self / cls parameter for Python
357 }
358 else if (lang==SrcLangExt::Cpp && (a.type=="this" || a.type.startsWith("this ")))
359 {
360 // allow undocumented this (for C++23 deducing this), see issue #11123
361 }
362 else if (!argName.empty())
363 {
364 size_t count_named = context.paramsFound.count(argName.str());
365 size_t count_positional = context.paramsFound.count(std::to_string(position));
366 if (count_named==0 && count_positional==0 && a.docs.empty())
367 {
368 undocParams.push_back(a);
369 }
370 else if (count_named==1 && count_positional==1 && Config_getBool(WARN_IF_DOC_ERROR))
371 {
374 "argument {} from the argument list of {} has both named and positional @param documentation sections",
376 }
377 else if (count_named+count_positional>1 && Config_getBool(WARN_IF_DOC_ERROR))
378 {
381 "argument {} from the argument list of {} has multiple @param documentation sections",
383 }
384 }
385 position++;
386 }
387 if (!undocParams.empty() && Config_getBool(WARN_IF_INCOMPLETE_DOC))
388 {
389 bool first=true;
390 DString errMsg = "The following parameter";
391 if (undocParams.size()>1) errMsg+="s";
392 errMsg+=DString(" of ")+
394 argListToString(al) +
395 (undocParams.size()>1 ? " are" : " is") + " not documented:\n";
396 for (const Argument &a : undocParams)
397 {
398 DString argName = context.memberDef->isDefine() ? a.type : a.name;
399 if (lang==SrcLangExt::Fortran) argName = argName.lower();
400 argName=argName.stripWhiteSpace();
401 if (!first) errMsg+="\n";
402 first=false;
403 errMsg+=" parameter '"+argName+"'";
404 }
406 }
407
408 if (Config_getBool(WARN_IF_DOC_ERROR) && context.paramPosition-1 > context.numParameters)
409 {
412 "too many @param commands for function {}. Found {} while function has {} parameter{}",
414 }
415 }
416 else
417 {
418 if (context.paramsFound.empty() && Config_getBool(WARN_IF_DOC_ERROR))
419 {
422 "{} has @param documentation sections but no arguments",
424 }
425 }
426 }
427}
428
429
430//---------------------------------------------------------------------------
431
432//---------------------------------------------------------------------------
433
434//---------------------------------------------------------------------------
435/*! Looks for a documentation block with name commandName in the current
436 * context (g_parserContext.context). The resulting documentation string is
437 * put in pDoc, the definition in which the documentation was found is
438 * put in pDef.
439 * @retval true if name was found.
440 * @retval false if name was not found.
441 */
443 DString *pDoc,
444 DString *pBrief,
445 const Definition **pDef)
446{
447 AUTO_TRACE("commandName={}",commandName);
448 *pDoc="";
449 *pBrief="";
450 *pDef=nullptr;
451 DString cmdArg=commandName;
452 if (cmdArg.empty())
453 {
454 AUTO_TRACE_EXIT("empty");
455 return false;
456 }
457
458 const FileDef *fd=nullptr;
459 const GroupDef *gd=nullptr;
460 const PageDef *pd=nullptr;
461 gd = Doxygen::groupLinkedMap->find(cmdArg);
462 if (gd) // group
463 {
464 *pDoc=gd->documentation();
465 *pBrief=gd->briefDescription();
466 *pDef=gd;
467 AUTO_TRACE_EXIT("group");
468 return true;
469 }
470 pd = Doxygen::pageLinkedMap->find(cmdArg);
471 if (pd) // page
472 {
473 *pDoc=pd->documentation();
474 *pBrief=pd->briefDescription();
475 *pDef=pd;
476 AUTO_TRACE_EXIT("page");
477 return true;
478 }
479 bool ambig = false;
480 fd = Doxygen::inputNameLinkedMap->findFileDef(cmdArg,ambig);
481 if (fd && !ambig) // file
482 {
483 *pDoc=fd->documentation();
484 *pBrief=fd->briefDescription();
485 *pDef=fd;
486 AUTO_TRACE_EXIT("file");
487 return true;
488 }
489
490 // for symbols we need to normalize the separator, so A#B, or A\B, or A.B becomes A::B
491 cmdArg = substitute(cmdArg,"#","::");
492 cmdArg = substitute(cmdArg,"\\","::");
493 bool extractAnonNs = Config_getBool(EXTRACT_ANON_NSPACES);
494 if (extractAnonNs &&
495 cmdArg.startsWith("anonymous_namespace{")
496 )
497 {
498 size_t rightBracePos = cmdArg.find("}", dstrlen("anonymous_namespace{"));
499 if (rightBracePos != DString::npos)
500 {
501 DString leftPart = cmdArg.left(rightBracePos + 1);
502 DString rightPart = cmdArg.mid(rightBracePos + 1);
503 rightPart = substitute(rightPart, ".", "::");
504 cmdArg = leftPart + rightPart;
505 }
506 else
507 {
508 cmdArg = substitute(cmdArg,".","::");
509 }
510 }
511 else
512 {
513 cmdArg = substitute(cmdArg,".","::");
514 }
515
516 int l=static_cast<int>(cmdArg.length());
517
518 size_t funcStart=cmdArg.find('(');
519 if (funcStart==DString::npos)
520 {
521 funcStart=l;
522 }
523 else
524 {
525 // Check for the case of operator() and the like.
526 // beware of scenarios like operator()((foo)bar)
527 size_t secondParen = cmdArg.find('(', funcStart+1);
528 size_t leftParen = cmdArg.find(')', funcStart+1);
529 if (leftParen!=DString::npos && secondParen!=DString::npos)
530 {
531 if (leftParen<secondParen)
532 {
533 funcStart=secondParen;
534 }
535 }
536 }
537
538 DString name=removeRedundantWhiteSpace(cmdArg.left(funcStart));
539 DString args=cmdArg.right(l-funcStart);
540 // try if the link is to a member
541 GetDefInput input(
542 context.context.find('.')==DString::npos ? context.context : DString(), // find('.') is a hack to detect files
543 name,
544 args);
545 input.checkCV=true;
546 input.allowCrossFileStatic=true;
547 // the file of the documentation block, so that a static in that file can be found
548 if (input.currentFile==nullptr)
549 {
551 }
552 GetDefResult result = getDefs(input);
553 if (!result.found && input.currentFile)
554 {
555 // not found via that file, e.g. a function in a header without \file, so retry without it
556 input.currentFile=nullptr;
557 result = getDefs(input);
558 }
559 //printf("found=%d context=%s name=%s\n",result.found,qPrint(context.context),qPrint(name));
560 if (result.found && result.md)
561 {
562 *pDoc=result.md->documentation();
563 *pBrief=result.md->briefDescription();
564 *pDef=result.md;
565 AUTO_TRACE_EXIT("member");
566 return true;
567 }
568
569 int scopeOffset=static_cast<int>(context.context.length());
570 do // for each scope
571 {
572 DString fullName=cmdArg;
573 if (scopeOffset>0)
574 {
575 fullName.prepend(context.context.left(scopeOffset)+"::");
576 }
577 //printf("Trying fullName='%s'\n",qPrint(fullName));
578
579 // try class, namespace, group, page, file reference
580 const ClassDef *cd = Doxygen::classLinkedMap->find(fullName);
581 if (cd) // class
582 {
583 *pDoc=cd->documentation();
584 *pBrief=cd->briefDescription();
585 *pDef=cd;
586 AUTO_TRACE_EXIT("class");
587 return true;
588 }
589 const NamespaceDef *nd = Doxygen::namespaceLinkedMap->find(fullName);
590 if (nd) // namespace
591 {
592 *pDoc=nd->documentation();
593 *pBrief=nd->briefDescription();
594 *pDef=nd;
595 AUTO_TRACE_EXIT("namespace");
596 return true;
597 }
598 if (scopeOffset==0)
599 {
600 scopeOffset=-1;
601 }
602 else
603 {
604 size_t o = context.context.rfind("::",scopeOffset-1);
605 scopeOffset = o!=DString::npos ? static_cast<int>(o) : 0;
606 }
607 } while (scopeOffset>=0);
608
609 AUTO_TRACE_EXIT("not found");
610 return false;
611}
612
613//---------------------------------------------------------------------------
615 DocNodeList &children,const DString &txt)
616{
617 switch (tok.value())
618 {
619 case TokenRetval::TK_COMMAND_AT:
620 // fall through
621 case TokenRetval::TK_COMMAND_BS:
622 {
623 char cs[2] = { tok.command_to_char(), 0 };
624 children.append<DocWord>(this,parent,cs + context.token->name);
625 warn_doc_error(context.fileName,tokenizer.getLineNr(),"Illegal command '{:c}{}' found as part of a {}",
626 tok.command_to_char(),context.token->name,txt);
627 }
628 break;
629 case TokenRetval::TK_SYMBOL:
630 warn_doc_error(context.fileName,tokenizer.getLineNr(),"Unsupported symbol '{}' found as part of a {}",
631 qPrint(context.token->name), qPrint(txt));
632 break;
633 case TokenRetval::TK_HTMLTAG:
634 warn_doc_error(context.fileName,tokenizer.getLineNr(),"Unsupported HTML tag <{}{}> found as part of a {}",
635 context.token->endTag ? "/" : "",context.token->name, txt);
636 break;
637 default:
638 children.append<DocWord>(this,parent,context.token->name);
639 warn_doc_error(context.fileName,tokenizer.getLineNr(),"Unexpected token {} found as part of a {}",
640 tok.to_string(), txt);
641 break;
642 }
643}
644
645//---------------------------------------------------------------------------
646
648{
649 AUTO_TRACE("cmdName={}",cmdName);
650 DString saveCmdName = cmdName;
651 Token tok=tokenizer.lex();
652 size_t styleStackSizeAtStart = context.styleStack.size();
653 if (!tok.is(TokenRetval::TK_WHITESPACE))
654 {
655 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\{} command",
656 saveCmdName);
657 return tok;
658 }
659 tok = tokenizer.lex();
660 while (!tok.is_any_of(TokenRetval::TK_NONE, TokenRetval::TK_EOF, TokenRetval::TK_WHITESPACE,
661 TokenRetval::TK_NEWPARA, TokenRetval::TK_LISTITEM, TokenRetval::TK_ENDLIST)
662 )
663 {
664 static const reg::Ex specialChar(R"([.,|()\‍[\‍]:;?])");
665 if (tok.is(TokenRetval::TK_WORD) && context.token->name.length()==1 &&
666 reg::match(context.token->name.str(),specialChar))
667 {
668 // special character that ends the markup command
669 AUTO_TRACE_ADD("special character ending style argument: '{}' styleStackSize {}->{}",context.token->name,styleStackSizeAtStart,context.styleStack.size());
670 if (context.styleStack.size() > styleStackSizeAtStart) // new styles opened inside command, but not closed
671 {
672 handlePendingStyleCommands(parent,children,context.styleStack.size()-styleStackSizeAtStart);
673 }
674 return tok;
675 }
676 if (!defaultHandleToken(parent,tok,children))
677 {
678 switch (tok.value())
679 {
680 case TokenRetval::TK_HTMLTAG:
682 {
683 // ignore </li> as the end of a style command
684 }
685 else
686 {
687 AUTO_TRACE_EXIT("end tok={}",tok.to_string());
688 return tok;
689 }
690 break;
691 default:
692 errorHandleDefaultToken(parent,tok,children,"\\" + saveCmdName + " command");
693 break;
694 }
695 break;
696 }
697 tok = tokenizer.lex();
698 }
699 AUTO_TRACE_EXIT("end tok={}",tok.to_string());
700 return (tok.is_any_of(TokenRetval::TK_NEWPARA,TokenRetval::TK_LISTITEM,TokenRetval::TK_ENDLIST)) ? tok : Token::make_RetVal_OK();
701}
702
703/*! Called when a style change starts. For instance a <b> command is
704 * encountered.
705 */
707 DocStyleChange::Style s,const DString &tagName,const HtmlAttribList *attribs)
708{
709 AUTO_TRACE("tagName={}",tagName);
710 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),s,tagName,true,
712 context.styleStack.push(&children.back());
714}
715
716/*! Called when a style change ends. For instance a </b> command is
717 * encountered.
718 */
720 DocStyleChange::Style s,const DString &tagName)
721{
722 AUTO_TRACE("tagName={}",tagName);
723 DString tagNameLower = DString(tagName).lower();
724
725 auto topStyleChange = [](const DocStyleChangeStack &stack) -> const DocStyleChange &
726 {
727 return std::get<DocStyleChange>(*stack.top());
728 };
729
730 if (context.styleStack.empty() || // no style change
731 topStyleChange(context.styleStack).style()!=s || // wrong style change
732 topStyleChange(context.styleStack).tagName()!=tagNameLower || // wrong style change
733 topStyleChange(context.styleStack).position()!=context.nodeStack.size() // wrong position
734 )
735 {
736 if (context.styleStack.empty())
737 {
738 warn_doc_error(context.fileName,tokenizer.getLineNr(),"found </{0}> tag without matching <{0}>",tagName);
739 }
740 else if (topStyleChange(context.styleStack).tagName()!=tagNameLower ||
741 topStyleChange(context.styleStack).style()!=s)
742 {
743 warn_doc_error(context.fileName,tokenizer.getLineNr(),"found </{}> tag while expecting </{}>",
744 tagName,topStyleChange(context.styleStack).tagName());
745 }
746 else
747 {
748 warn_doc_error(context.fileName,tokenizer.getLineNr(),"found </{}> at different nesting level ({}) than expected ({})",
749 tagName,context.nodeStack.size(),topStyleChange(context.styleStack).position());
750 }
751 }
752 else // end the section
753 {
754 children.append<DocStyleChange>(
755 this,parent,context.nodeStack.size(),s,
756 topStyleChange(context.styleStack).tagName(),false);
757 context.styleStack.pop();
758 }
760 {
761 context.inCodeStyle = false;
762 }
763}
764
765/*! Called at the end of a paragraph to close all open style changes
766 * (e.g. a <b> without a </b>). The closed styles are pushed onto a stack
767 * and entered again at the start of a new paragraph.
768 */
769void DocParser::handlePendingStyleCommands(DocNodeVariant *parent,DocNodeList &children, size_t numberOfElementsToClose)
770{
771 AUTO_TRACE("context.styleStack.size()={} numberOfElementsToClose={}",context.styleStack.size(),numberOfElementsToClose);
772 if (!context.styleStack.empty())
773 {
774 if (numberOfElementsToClose==0) numberOfElementsToClose = context.styleStack.size(); // 0 is special value for "close all"
775 const DocStyleChange *sc = &std::get<DocStyleChange>(*context.styleStack.top());
776 while (sc && sc->position()>=context.nodeStack.size() && numberOfElementsToClose>0)
777 { // there are unclosed style modifiers in the paragraph
778 AUTO_TRACE_ADD("unclosed style {} at position {}",sc->styleString(),sc->position());
779 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),
780 sc->style(),sc->tagName(),false);
782 context.styleStack.pop();
783 sc = !context.styleStack.empty() ? &std::get<DocStyleChange>(*context.styleStack.top()) : nullptr;
784 numberOfElementsToClose--;
785 }
786 }
787}
788
790{
791 AUTO_TRACE();
792 while (!context.initialStyleStack.empty())
793 {
794 const DocStyleChange &sc = std::get<DocStyleChange>(*context.initialStyleStack.top());
795 handleStyleEnter(parent,children,sc.style(),sc.tagName(),&sc.attribs());
797 }
798}
799
801 const HtmlAttribList &tagHtmlAttribs)
802{
803 AUTO_TRACE();
804 size_t index=0;
805 Token retval = Token::make_RetVal_OK();
806 for (const auto &opt : tagHtmlAttribs)
807 {
808 if (opt.name=="name" || opt.name=="id") // <a name=label> or <a id=label> tag
809 {
810 if (!opt.value.empty())
811 {
812 children.append<DocAnchor>(this,parent,opt.value,true);
813 break; // stop looking for other tag attribs
814 }
815 else
816 {
817 warn_doc_error(context.fileName,tokenizer.getLineNr(),"found <a> tag with name option but without value!");
818 }
819 }
820 else if (opt.name=="href") // <a href=url>..</a> tag
821 {
822 // copy attributes
823 HtmlAttribList attrList = tagHtmlAttribs;
824 // and remove the href attribute
825 attrList.erase(attrList.begin()+index);
826 DString relPath;
827 if (opt.value.at(0) != '#') relPath = context.relPath;
828 children.append<DocHRef>(this, parent, attrList,
829 opt.value, relPath,
830 convertNameToFile(context.fileName, false, true));
832 retval = children.get_last<DocHRef>()->parse();
835 break;
836 }
837 else // unsupported option for tag a
838 {
839 }
840 ++index;
841 }
842 return retval;
843}
844
846{
847 AUTO_TRACE("content.initialStyleStack.size()={}",context.initialStyleStack.size());
848 if (!context.initialStyleStack.empty())
849 {
850 DString tagName = std::get<DocStyleChange>(*context.initialStyleStack.top()).tagName();
851 DString fileName = std::get<DocStyleChange>(*context.initialStyleStack.top()).fileName();
852 int lineNr = std::get<DocStyleChange>(*context.initialStyleStack.top()).lineNr();
855 if (lineNr != -1)
856 {
858 "end of comment block while expecting "
859 "command </{}> (Probable start '{}' at line {})",tagName, fileName, lineNr);
860 }
861 else
862 {
864 "end of comment block while expecting command </{}>",tagName);
865 }
866 }
867}
868
869void DocParser::handleLinkedWord(DocNodeVariant *parent,DocNodeList &children,bool ignoreAutoLinkFlag,bool typeLinkOnly)
870{
871 // helper to check if word w starts with any of the words in AUTOLINK_IGNORE_WORDS
872 auto ignoreWord = [](const DString &w) -> bool {
873 auto list = Config_getList(AUTOLINK_IGNORE_WORDS);
874 return std::find_if(list.begin(), list.end(),
875 [&w](const auto &ignore) { return w.startsWith(ignore); }
876 )!=list.end();
877 };
879 AUTO_TRACE("word={}",name);
880 if (!context.autolinkSupport || ignoreAutoLinkFlag || ignoreWord(context.token->name)) // no autolinking -> add as normal word
881 {
882 children.append<DocWord>(this,parent,name);
883 return;
884 }
885
886 // ------- try to turn the word 'name' into a link
887
888 const Definition *compound=nullptr;
889 const MemberDef *member=nullptr;
890 size_t len = context.token->name.length();
891 ClassDef *cd=nullptr;
892 bool ambig = false;
894 auto lang = context.lang;
895 bool inSeeBlock = context.inSeeBlock || context.inCodeStyle;
896 //printf("handleLinkedWord(%s) context.context=%s\n",qPrint(context.token->name),qPrint(context.context));
897 if (!context.insideHtmlLink &&
898 (resolveRef(context.context,context.token->name,inSeeBlock,&compound,&member,lang,true,fd,true)
899 || (!context.context.empty() && // also try with global scope
900 resolveRef(DString(),context.token->name,inSeeBlock,&compound,&member,lang,false,nullptr,true))
901 )
902 )
903 {
904 //printf("ADD %s = %p (linkable?=%d typeLinkOnly=%d)\n",
905 // qPrint(context.token->name),(void*)member,member ? member->isLinkable() : false, typeLinkOnly);
906 if (member && member->isLinkable())
907 {
908 if (!typeLinkOnly || context.token->name.startsWith("#") ||
909 member->isTypedef() || member->isEnumerate() || member->isEnumValue()) // filter on type links
910 {
911 AUTO_TRACE_ADD("resolved reference as member link");
912 if (member->isObjCMethod())
913 {
914 bool localLink = context.memberDef ? member->getClassDef()==context.memberDef->getClassDef() : false;
915 name = member->objCMethodName(localLink,inSeeBlock);
916 }
917 children.append<DocLinkedWord>(
918 this,parent,name,
919 member->getReference(),
920 member->getOutputFileBase(),
921 member->anchor(),
922 member->briefDescriptionAsTooltip());
923 }
924 else // explicit type link, but not a type
925 {
926 AUTO_TRACE_ADD("no link as request is type but member is not a type or explicit link");
927 children.append<DocWord>(this,parent,context.token->name);
928 }
929 }
930 else if (compound->isLinkable()) // compound link
931 {
932 AUTO_TRACE_ADD("resolved reference as compound link");
933 DString anchor = compound->anchor();
934 if (compound->definitionType()==Definition::TypeFile)
935 {
936 name=context.token->name;
937 }
938 else if (compound->definitionType()==Definition::TypeGroup)
939 {
940 name=toGroupDef(compound)->groupTitle();
941 }
942 children.append<DocLinkedWord>(
943 this,parent,name,
944 compound->getReference(),
945 compound->getOutputFileBase(),
946 anchor,
947 compound->briefDescriptionAsTooltip());
948 }
949 else if (compound->definitionType()==Definition::TypeFile &&
950 (toFileDef(compound))->generateSourceFile()
951 ) // undocumented file that has source code we can link to
952 {
953 AUTO_TRACE_ADD("resolved reference as source link");
954 children.append<DocLinkedWord>(
955 this,parent,context.token->name,
956 compound->getReference(),
957 compound->getSourceFileBase(),
958 "",
959 compound->briefDescriptionAsTooltip());
960 }
961 else // not linkable
962 {
963 AUTO_TRACE_ADD("resolved reference as unlinkable compound={} (linkable={}) member={} (linkable={})",
964 compound ? compound->name() : "<none>", compound ? (int)compound->isLinkable() : -1,
965 member ? member->name() : "<none>", member ? (int)member->isLinkable() : -1);
966 children.append<DocWord>(this,parent,name);
967 }
968 }
969 else if (!context.insideHtmlLink && len>1 && context.token->name.at(len-1)==':')
970 {
971 // special case, where matching Foo: fails to be an Obj-C reference,
972 // but Foo itself might be linkable.
974 handleLinkedWord(parent,children,ignoreAutoLinkFlag);
975 children.append<DocWord>(this,parent,":");
976 }
977 else if (!context.insideHtmlLink && (cd=getClass(context.token->name+"-p")))
978 {
979 // special case 2, where the token name is not a class, but could
980 // be a Obj-C protocol
981 children.append<DocLinkedWord>(
982 this,parent,name,
983 cd->getReference(),
984 cd->getOutputFileBase(),
985 cd->anchor(),
987 }
988 else if (const RequirementIntf *req = RequirementManager::instance().find(name); req!=nullptr) // link to requirement
989 {
990 if (Config_getBool(GENERATE_REQUIREMENTS))
991 {
992 children.append<DocLinkedWord>(
993 this,parent,name,
994 DString(), // link to local requirements overview also for external references
995 req->getOutputFileBase(),
996 req->id(),
997 req->title()
998 );
999 }
1000 else // cannot link to a page that does not exist
1001 {
1002 children.append<DocWord>(this,parent,name);
1003 }
1004 }
1005 else // normal non-linkable word
1006 {
1007 AUTO_TRACE_ADD("non-linkable");
1008 if (context.token->name.startsWith("#"))
1009 {
1010 warn_doc_error(context.fileName,tokenizer.getLineNr(),"explicit link request to '{}' could not be resolved",name);
1011 }
1012 children.append<DocWord>(this,parent,context.token->name);
1013 }
1014}
1015
1017{
1018 DString name = context.token->name; // save token name
1019 AUTO_TRACE("name={}",name);
1020 DString name1;
1021 size_t p=0, i=0, ii=0;
1022 while ((i=paramTypes.find('|',p))!=DString::npos)
1023 {
1024 name1 = paramTypes.mid(p,i-p);
1025 ii=name1.find('[');
1026 context.token->name=ii!=DString::npos ? name1.mid(0,ii) : name1; // take part without []
1027 handleLinkedWord(parent,children);
1028 if (ii!=DString::npos) children.append<DocWord>(this,parent,name1.mid(ii)); // add [] part
1029 p=i+1;
1030 children.append<DocSeparator>(this,parent,"|");
1031 }
1032 name1 = paramTypes.mid(p);
1033 ii=name1.find('[');
1034 context.token->name=ii!=DString::npos ? name1.mid(0,ii) : name1;
1035 handleLinkedWord(parent,children);
1036 if (ii!=DString::npos) children.append<DocWord>(this,parent,name1.mid(ii));
1037 context.token->name = name; // restore original token name
1038}
1039
1041{
1042 Token tok=tokenizer.lex();
1043 DString tokenName = context.token->name;
1044 AUTO_TRACE("name={}",tokenName);
1045 if (!tok.is(TokenRetval::TK_WHITESPACE))
1046 {
1047 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\{} command", tokenName);
1048 return;
1049 }
1051 tok=tokenizer.lex(); // get the reference id
1052 if (!tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_LNKWORD))
1053 {
1054 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of {}",
1055 tok.to_string(),tokenName);
1056 return;
1057 }
1058 children.append<DocInternalRef>(this,parent,context.token->name);
1059 children.get_last<DocInternalRef>()->parse();
1060}
1061
1063{
1064 AUTO_TRACE();
1065 Token tok=tokenizer.lex();
1066 if (!tok.is(TokenRetval::TK_WHITESPACE))
1067 {
1068 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\{} command",
1069 context.token->name);
1070 return;
1071 }
1072
1075 tok=tokenizer.lex();
1076 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1077 {
1078 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected end of comment block while parsing the "
1079 "argument of command {}",context.token->name);
1080 return;
1081 }
1082 else if (!tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_LNKWORD))
1083 {
1084 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of {}",
1085 tok.to_string(),context.token->name);
1086 return;
1087 }
1088 }
1089 children.append<DocAnchor>(this,parent,context.token->name,false);
1090}
1091
1093{
1094 AUTO_TRACE();
1095 // get the argument of the cite command.
1096 Token tok=tokenizer.lex();
1097
1098 CiteInfoOption option;
1099 if (tok.is(TokenRetval::TK_WORD) && context.token->name=="{")
1100 {
1102 tokenizer.lex();
1103 StringVector optList=split(context.token->name.str(),",");
1104 for (auto const &opt : optList)
1105 {
1106 if (opt == "number")
1107 {
1108 if (!option.isUnknown())
1109 {
1110 warn(context.fileName,tokenizer.getLineNr(),"Multiple options specified with \\{}, discarding '{}'", context.token->name, opt);
1111 }
1112 else
1113 {
1114 option = CiteInfoOption::makeNumber();
1115 }
1116 }
1117 else if (opt == "year")
1118 {
1119 if (!option.isUnknown())
1120 {
1121 warn(context.fileName,tokenizer.getLineNr(),"Multiple options specified with \\{}, discarding '{}'", context.token->name, opt);
1122 }
1123 else
1124 {
1125 option = CiteInfoOption::makeYear();
1126 }
1127 }
1128 else if (opt == "shortauthor")
1129 {
1130 if (!option.isUnknown())
1131 {
1132 warn(context.fileName,tokenizer.getLineNr(),"Multiple options specified with \\{}, discarding '{}'", context.token->name, opt);
1133 }
1134 else
1135 {
1137 }
1138 }
1139 else if (opt == "nopar")
1140 {
1141 option.setNoPar();
1142 }
1143 else if (opt == "nocite")
1144 {
1145 option.setNoCite();
1146 }
1147 else
1148 {
1149 warn(context.fileName,tokenizer.getLineNr(),"Unknown option specified with \\{}, discarding '{}'", context.token->name, opt);
1150 }
1151 }
1152
1153 if (option.isUnknown()) option.changeToNumber();
1154
1156 tok=tokenizer.lex();
1157 if (!tok.is(TokenRetval::TK_WHITESPACE))
1158 {
1159 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\{} command",
1160 context.token->name);
1161 return;
1162 }
1163 }
1164 else if (!tok.is(TokenRetval::TK_WHITESPACE))
1165 {
1166 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after '\\{}' command",
1167 context.token->name);
1168 return;
1169 }
1170 else
1171 {
1172 option = CiteInfoOption::makeNumber();
1173 }
1174
1177 tok=tokenizer.lex();
1178 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1179 {
1180 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected end of comment block while parsing the "
1181 "argument of command '\\{}'",context.token->name);
1182 return;
1183 }
1184 else if (!tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_LNKWORD))
1185 {
1186 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of '\\{}'",
1187 tok.to_string(),context.token->name);
1188 return;
1189 }
1191 children.append<DocCite>(this,parent,context.token->name,context.context,option);
1192 }
1193
1194}
1195
1197{
1198 AUTO_TRACE();
1199 Token tok=tokenizer.lex();
1200 if (!tok.is(TokenRetval::TK_WHITESPACE))
1201 {
1202 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\{} command", context.token->name);
1203 return;
1204 }
1206 tok=tokenizer.lex();
1207 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1208 {
1209 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected end of comment block while parsing the "
1210 "argument of command {}",context.token->name);
1211 return;
1212 }
1213 else if (!tok.is(TokenRetval::TK_WORD))
1214 {
1215 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of {}",
1216 tok.to_string(),context.token->name);
1217 return;
1218 }
1221}
1222
1223/* Helper function that deals with the title, width, and height arguments of various commands.
1224 * @param[in] cmd Command id for which to extract caption and size info.
1225 * @param[in] parent Parent node, owner of the children list passed as
1226 * the third argument.
1227 * @param[in] children The list of child nodes to which the node representing
1228 * the token can be added.
1229 * @param[out] width the extracted width specifier
1230 * @param[out] height the extracted height specifier
1231 */
1233{
1234 AUTO_TRACE();
1235 auto ns = AutoNodeStack(this,parent);
1236
1237 // parse title
1239 Token tok = tokenizer.lex();
1240 while (!tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1241 {
1242 if (tok.is(TokenRetval::TK_WORD) && (context.token->name=="width=" || context.token->name=="height="))
1243 {
1244 // special case: no title, but we do have a size indicator
1245 break;
1246 }
1247 else if (tok.is(TokenRetval::TK_HTMLTAG))
1248 {
1250 break;
1251 }
1252 if (!defaultHandleToken(parent,tok,children))
1253 {
1254 errorHandleDefaultToken(parent,tok,children,Mappers::cmdMapper->find(cmd));
1255 }
1256 tok = tokenizer.lex();
1257 }
1258 // parse size attributes
1259 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1260 {
1261 tok=tokenizer.lex();
1262 }
1263 while (tok.is_any_of(TokenRetval::TK_WHITESPACE,TokenRetval::TK_WORD,TokenRetval::TK_HTMLTAG)) // there are values following the title
1264 {
1265 if (tok.is(TokenRetval::TK_WORD))
1266 {
1267 if (context.token->name=="width=" || context.token->name=="height=")
1268 {
1271 }
1272
1273 if (context.token->name=="width")
1274 {
1275 width = context.token->chars;
1276 }
1277 else if (context.token->name=="height")
1278 {
1279 height = context.token->chars;
1280 }
1281 else // other text after the title -> treat as normal text
1282 {
1284 //warn_doc_error(context.fileName,tokenizer.getLineNr(),"Unknown option '{}' after \\{} command, expected 'width' or 'height'",
1285 // context.token->name, Mappers::cmdMapper->find(cmd));
1286 break;
1287 }
1288 }
1289
1290 tok=tokenizer.lex();
1291 // if we found something we did not expect, push it back to the stream
1292 // so it can still be processed
1293 if (tok.is_any_of(TokenRetval::TK_COMMAND_AT,TokenRetval::TK_COMMAND_BS))
1294 {
1296 tokenizer.unputString(tok.is(TokenRetval::TK_COMMAND_AT) ? "@" : "\\");
1297 break;
1298 }
1299 else if (tok.is(TokenRetval::TK_SYMBOL))
1300 {
1302 break;
1303 }
1304 else if (tok.is(TokenRetval::TK_HTMLTAG))
1305 {
1307 break;
1308 }
1309 }
1311
1313 AUTO_TRACE_EXIT("width={} height={}",width,height);
1314}
1315
1317{
1318 AUTO_TRACE();
1319 bool inlineImage = false;
1320 DString anchorStr;
1321
1322 Token tok=tokenizer.lex();
1323 if (!tok.is(TokenRetval::TK_WHITESPACE))
1324 {
1325 if (tok.is(TokenRetval::TK_WORD))
1326 {
1327 if (context.token->name == "{")
1328 {
1330 tokenizer.lex();
1332 StringVector optList=split(context.token->name.str(),",");
1333 for (const auto &opt : optList)
1334 {
1335 if (opt.empty()) continue;
1336 DString locOpt(opt);
1337 DString locOptLow;
1338 locOpt = locOpt.stripWhiteSpace();
1339 locOptLow = locOpt.lower();
1340 if (locOptLow == "inline")
1341 {
1342 inlineImage = true;
1343 }
1344 else if (locOptLow.startsWith("anchor:"))
1345 {
1346 if (!anchorStr.empty())
1347 {
1349 "multiple use of option 'anchor' for 'image' command, ignoring: '{}'",
1350 locOpt.mid(7));
1351 }
1352 else
1353 {
1354 anchorStr = locOpt.mid(7);
1355 }
1356 }
1357 else
1358 {
1360 "unknown option '{}' for 'image' command specified",
1361 locOpt);
1362 }
1363 }
1364 tok=tokenizer.lex();
1365 if (!tok.is(TokenRetval::TK_WHITESPACE))
1366 {
1367 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\image command");
1368 return;
1369 }
1370 }
1371 }
1372 else
1373 {
1374 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\image command");
1375 return;
1376 }
1377 }
1378 tok=tokenizer.lex();
1379 if (!tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_LNKWORD))
1380 {
1381 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of \\image",
1382 tok.to_string());
1383 return;
1384 }
1385 tok=tokenizer.lex();
1386 if (!tok.is(TokenRetval::TK_WHITESPACE))
1387 {
1388 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\image command");
1389 return;
1390 }
1392 DString imgType = context.token->name.lower();
1393 if (imgType=="html") t=DocImage::Html;
1394 else if (imgType=="latex") t=DocImage::Latex;
1395 else if (imgType=="docbook") t=DocImage::DocBook;
1396 else if (imgType=="rtf") t=DocImage::Rtf;
1397 else if (imgType=="xml") t=DocImage::Xml;
1398 else
1399 {
1400 warn_doc_error(context.fileName,tokenizer.getLineNr(),"output format `{}` specified as the first argument of "
1401 "\\image command is not valid", imgType);
1402 return;
1403 }
1405 tok=tokenizer.lex();
1407 if (!tok.is(TokenRetval::TK_WORD))
1408 {
1409 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of \\image", tok.to_string());
1410 return;
1411 }
1412 if (!anchorStr.empty())
1413 {
1414 children.append<DocAnchor>(this,parent,anchorStr,true);
1415 }
1416 HtmlAttribList attrList;
1417 children.append<DocImage>(this,parent,attrList,
1418 findAndCopyImage(context.token->name,t),t,"",inlineImage);
1419 children.get_last<DocImage>()->parse();
1420}
1421
1422void DocParser::handleRef(DocNodeVariant *parent, DocNodeList &children, char cmdChar, const DString &cmdName)
1423{
1424 AUTO_TRACE("cmdName={}",cmdName);
1425 DString saveCmdName = cmdName;
1427 Token tok=tokenizer.lex();
1428 if (!tok.is(TokenRetval::TK_WHITESPACE))
1429 {
1430 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after '{:c}{}' command",
1431 cmdChar,qPrint(saveCmdName));
1432 return;
1433 }
1435 tok=tokenizer.lex(); // get the reference id
1436 if (!tok.is(TokenRetval::TK_WORD))
1437 {
1438 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of '{:c}{}'",
1439 tok.to_string(),cmdChar,saveCmdName);
1440 return;
1441 }
1442 children.append<DocRef>(this,parent,
1445 children.get_last<DocRef>()->parse(cmdChar,saveCmdName);
1446}
1447
1448void DocParser::handleIFile(char cmdChar,const DString &cmdName)
1449{
1450 AUTO_TRACE();
1451 Token tok=tokenizer.lex();
1452 if (!tok.is(TokenRetval::TK_WHITESPACE))
1453 {
1454 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after '{:c}{}' command",
1455 cmdChar,cmdName);
1456 return;
1457 }
1459 tok=tokenizer.lex();
1461 if (!tok.is(TokenRetval::TK_WORD))
1462 {
1463 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of '{:c}{}'",
1464 tok.to_string(),cmdChar,cmdName);
1465 return;
1466 }
1468}
1469
1470void DocParser::handleILine(char cmdChar,const DString &cmdName)
1471{
1472 AUTO_TRACE();
1474 Token tok = tokenizer.lex();
1476 if (!tok.is(TokenRetval::TK_WORD))
1477 {
1478 warn_doc_error(context.fileName,tokenizer.getLineNr(),"invalid argument for command '{:c}{}'",
1479 cmdChar,cmdName);
1480 return;
1481 }
1482}
1483
1484/* Helper function that deals with the most common tokens allowed in
1485 * title like sections.
1486 * @param parent Parent node, owner of the children list passed as
1487 * the third argument.
1488 * @param tok The token to process.
1489 * @param children The list of child nodes to which the node representing
1490 * the token can be added.
1491 * @param handleWord Indicates if word token should be processed
1492 * @retval true The token was handled.
1493 * @retval false The token was not handled.
1494 */
1496{
1497 AUTO_TRACE("token={} handleWord={}",tok.to_string(),handleWord);
1498 if (tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_LNKWORD,TokenRetval::TK_SYMBOL,TokenRetval::TK_URL,
1499 TokenRetval::TK_COMMAND_AT,TokenRetval::TK_COMMAND_BS,TokenRetval::TK_HTMLTAG)
1500 )
1501 {
1502 }
1503reparsetoken:
1504 DString tokenName = context.token->name;
1505 AUTO_TRACE_ADD("tokenName={}",tokenName);
1506 switch (tok.value())
1507 {
1508 case TokenRetval::TK_COMMAND_AT:
1509 // fall through
1510 case TokenRetval::TK_COMMAND_BS:
1511 switch (Mappers::cmdMapper->map(tokenName))
1512 {
1515 break;
1518 break;
1521 break;
1524 break;
1527 break;
1530 break;
1533 break;
1536 break;
1539 break;
1543 break;
1548 break;
1551 break;
1554 break;
1557 break;
1560 break;
1563 break;
1566 break;
1569 break;
1571 {
1572 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),DocStyleChange::Italic,tokenName,true);
1573 tok=handleStyleArgument(parent,children,tokenName);
1574 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),DocStyleChange::Italic,tokenName,false);
1575 if (!tok.is(TokenRetval::TK_WORD)) children.append<DocWhiteSpace>(this,parent," ");
1576 if (tok.is(TokenRetval::TK_NEWPARA)) goto handlepara;
1577 else if (tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_HTMLTAG))
1578 {
1579 AUTO_TRACE_ADD("CommandType::CMD_EMPHASIS: reparsing");
1580 goto reparsetoken;
1581 }
1582 }
1583 break;
1585 {
1586 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),DocStyleChange::Bold,tokenName,true);
1587 tok=handleStyleArgument(parent,children,tokenName);
1588 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),DocStyleChange::Bold,tokenName,false);
1589 if (!tok.is(TokenRetval::TK_WORD)) children.append<DocWhiteSpace>(this,parent," ");
1590 if (tok.is(TokenRetval::TK_NEWPARA)) goto handlepara;
1591 else if (tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_HTMLTAG))
1592 {
1593 AUTO_TRACE_ADD("CommandType::CMD_BOLD: reparsing");
1594 goto reparsetoken;
1595 }
1596 }
1597 break;
1599 {
1600 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),DocStyleChange::Code,tokenName,true);
1601 tok=handleStyleArgument(parent,children,tokenName);
1602 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),DocStyleChange::Code,tokenName,false);
1603 if (!tok.is(TokenRetval::TK_WORD)) children.append<DocWhiteSpace>(this,parent," ");
1604 if (tok.is(TokenRetval::TK_NEWPARA)) goto handlepara;
1605 else if (tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_HTMLTAG))
1606 {
1607 AUTO_TRACE_ADD("CommandType::CMD_CODE: reparsing");
1608 goto reparsetoken;
1609 }
1610 }
1611 break;
1613 {
1615 tok = tokenizer.lex();
1617 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1618 {
1619 warn_doc_error(context.fileName,tokenizer.getLineNr(),"htmlonly section ended without end marker");
1620 }
1622 }
1623 break;
1625 {
1627 tok = tokenizer.lex();
1629 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1630 {
1631 warn_doc_error(context.fileName,tokenizer.getLineNr(),"manonly section ended without end marker");
1632 }
1634 }
1635 break;
1637 {
1639 tok = tokenizer.lex();
1641 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1642 {
1643 warn_doc_error(context.fileName,tokenizer.getLineNr(),"rtfonly section ended without end marker");
1644 }
1646 }
1647 break;
1649 {
1651 tok = tokenizer.lex();
1653 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1654 {
1655 warn_doc_error(context.fileName,tokenizer.getLineNr(),"latexonly section ended without end marker");
1656 }
1658 }
1659 break;
1661 {
1663 tok = tokenizer.lex();
1665 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1666 {
1667 warn_doc_error(context.fileName,tokenizer.getLineNr(),"xmlonly section ended without end marker");
1668 }
1670 }
1671 break;
1673 {
1675 tok = tokenizer.lex();
1677 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1678 {
1679 warn_doc_error(context.fileName,tokenizer.getLineNr(),"docbookonly section ended without end marker");
1680 }
1682 }
1683 break;
1685 {
1686 children.append<DocFormula>(this,parent,context.token->id);
1687 }
1688 break;
1691 {
1692 handleAnchor(parent,children);
1693 }
1694 break;
1696 {
1697 handleCite(parent,children);
1698 }
1699 break;
1701 {
1702 handlePrefix(parent,children);
1703 }
1704 break;
1706 {
1707 handleInternalRef(parent,children);
1709 }
1710 break;
1712 {
1714 (void)tokenizer.lex();
1716 //printf("Found scope='%s'\n",qPrint(context.context));
1718 }
1719 break;
1721 handleImage(parent,children);
1722 break;
1724 handleILine(tok.command_to_char(),tokenName);
1725 break;
1727 handleIFile(tok.command_to_char(),tokenName);
1728 break;
1729 default:
1730 return false;
1731 }
1732 break;
1733 case TokenRetval::TK_HTMLTAG:
1734 {
1735 auto handleEnterLeaveStyle = [this,&parent,&children,&tokenName](DocStyleChange::Style style) {
1736 if (!context.token->endTag)
1737 {
1738 handleStyleEnter(parent,children,style,tokenName,&context.token->attribs);
1739 }
1740 else
1741 {
1742 handleStyleLeave(parent,children,style,tokenName);
1743 }
1744 };
1745 switch (Mappers::htmlTagMapper->map(tokenName))
1746 {
1748 warn_doc_error(context.fileName,tokenizer.getLineNr(),"found <div> tag in heading");
1749 break;
1751 warn_doc_error(context.fileName,tokenizer.getLineNr(),"found <pre> tag in heading");
1752 break;
1754 handleEnterLeaveStyle(DocStyleChange::Span);
1755 break;
1757 handleEnterLeaveStyle(DocStyleChange::Bold);
1758 break;
1760 handleEnterLeaveStyle(DocStyleChange::S);
1761 break;
1763 handleEnterLeaveStyle(DocStyleChange::Strike);
1764 break;
1766 handleEnterLeaveStyle(DocStyleChange::Del);
1767 break;
1769 handleEnterLeaveStyle(DocStyleChange::Underline);
1770 break;
1772 handleEnterLeaveStyle(DocStyleChange::Ins);
1773 break;
1775 case HtmlTagType::XML_C:
1776 handleEnterLeaveStyle(DocStyleChange::Code);
1777 break;
1779 handleEnterLeaveStyle(DocStyleChange::Kbd);
1780 break;
1782 handleEnterLeaveStyle(DocStyleChange::Typewriter);
1783 break;
1785 handleEnterLeaveStyle(DocStyleChange::Italic);
1786 break;
1788 handleEnterLeaveStyle(DocStyleChange::Subscript);
1789 break;
1791 handleEnterLeaveStyle(DocStyleChange::Superscript);
1792 break;
1794 handleEnterLeaveStyle(DocStyleChange::Center);
1795 break;
1797 handleEnterLeaveStyle(DocStyleChange::Small);
1798 break;
1800 handleEnterLeaveStyle(DocStyleChange::Cite);
1801 break;
1803 if (!context.token->endTag)
1804 {
1806 }
1807 break;
1808 default:
1809 return false;
1810 break;
1811 }
1812 }
1813 break;
1814 case TokenRetval::TK_SYMBOL:
1815 {
1818 {
1819 children.append<DocSymbol>(this,parent,s);
1820 }
1821 else
1822 {
1823 return false;
1824 }
1825 }
1826 break;
1827 case TokenRetval::TK_WHITESPACE:
1828 case TokenRetval::TK_NEWPARA:
1829handlepara:
1830 if (insidePRE(parent) || !children.empty())
1831 {
1832 children.append<DocWhiteSpace>(this,parent,context.token->chars);
1833 }
1834 break;
1835 case TokenRetval::TK_LNKWORD:
1836 if (handleWord)
1837 {
1838 handleLinkedWord(parent,children);
1839 }
1840 else
1841 return false;
1842 break;
1843 case TokenRetval::TK_WORD:
1844 if (handleWord)
1845 {
1846 children.append<DocWord>(this,parent,context.token->name);
1847 }
1848 else
1849 return false;
1850 break;
1851 case TokenRetval::TK_URL:
1853 {
1854 children.append<DocWord>(this,parent,context.token->name);
1855 }
1856 else
1857 {
1859 }
1860 break;
1861 default:
1862 return false;
1863 }
1864 return true;
1865}
1866
1867//---------------------------------------------------------------------------
1868
1870{
1871 AUTO_TRACE();
1872 bool found=false;
1873 size_t index=0;
1874 for (const auto &opt : tagHtmlAttribs)
1875 {
1876 AUTO_TRACE_ADD("option name={} value='{}'",opt.name,opt.value);
1877 if (opt.name=="src" && !opt.value.empty())
1878 {
1879 // copy attributes
1880 HtmlAttribList attrList = tagHtmlAttribs;
1881 // and remove the src attribute
1882 attrList.erase(attrList.begin()+index);
1884 children.append<DocImage>(
1885 this,parent,attrList,
1886 findAndCopyImage(opt.value,t,false),
1887 t,opt.value);
1888 found = true;
1889 }
1890 ++index;
1891 }
1892 if (!found)
1893 {
1894 warn_doc_error(context.fileName,tokenizer.getLineNr(),"IMG tag does not have a SRC attribute!");
1895 }
1896}
1897
1898//---------------------------------------------------------------------------
1899
1901 const DString &doc)
1902{
1903 AUTO_TRACE();
1904 Token retval = Token::make_RetVal_OK();
1905
1906 if (doc.empty()) return retval;
1907
1909
1910 // first parse any number of paragraphs
1911 bool isFirst=true;
1912 DocPara *lastPar=!children.empty() ? std::get_if<DocPara>(&children.back()): nullptr;
1913 if (lastPar)
1914 { // last child item was a paragraph
1915 isFirst=false;
1916 }
1917 do
1918 {
1919 children.append<DocPara>(this,parent);
1920 DocPara *par = children.get_last<DocPara>();
1921 if (isFirst) { par->markFirst(); isFirst=false; }
1922 retval=par->parse();
1923 if (!par->empty())
1924 {
1925 if (lastPar) lastPar->markLast(false);
1926 lastPar=par;
1927 }
1928 else
1929 {
1930 children.pop_back();
1931 }
1932 } while (retval.is(TokenRetval::TK_NEWPARA));
1933 if (lastPar) lastPar->markLast();
1934
1935 AUTO_TRACE_EXIT("isFirst={} isLast={}",lastPar?lastPar->isFirst():-1,lastPar?lastPar->isLast():-1);
1936 return retval;
1937}
1938
1939//---------------------------------------------------------------------------
1940
1942{
1943 AUTO_TRACE("file={} text={}",file,text);
1944 bool ambig = false;
1945 DString filePath = findExampleFilePath(file,ambig);
1946 if (!filePath.empty())
1947 {
1948 size_t indent = 0;
1949 text = detab(fileToString(filePath,Config_getBool(FILTER_SOURCE_FILES)),indent);
1950 if (ambig)
1951 {
1952 warn_doc_error(context.fileName,tokenizer.getLineNr(),"included file name '{}' is ambiguous"
1953 "Possible candidates:\n{}",file, Doxygen::exampleNameLinkedMap->showFileDefMatches(file));
1954 }
1955 }
1956 else
1957 {
1958 warn_doc_error(context.fileName,tokenizer.getLineNr(),"included file '{}' is not found. "
1959 "Check your EXAMPLE_PATH",file);
1960 }
1961}
1962
1963//---------------------------------------------------------------------------
1964
1965static DString extractCopyDocId(const char *data, size_t &j, size_t len)
1966{
1967 size_t s=j;
1968 int round=0;
1969 bool insideDQuote=false;
1970 bool insideSQuote=false;
1971 bool found=false;
1972 while (j<len && !found)
1973 {
1974 if (!insideSQuote && !insideDQuote)
1975 {
1976 switch (data[j])
1977 {
1978 case '(': round++; break;
1979 case ')': round--; break;
1980 case '"': insideDQuote=true; break;
1981 case '\'': insideSQuote=true; break;
1982 case '\\': // fall through, begin of command
1983 case '@': // fall through, begin of command
1984 case '\t': // fall through
1985 case '\n':
1986 found=(round==0);
1987 break;
1988 case ' ': // allow spaces in cast operator (see issue #11169)
1989 found=(round==0) && (j<8 || !literal_at(data+j-8,"operator"));
1990 break;
1991 }
1992 }
1993 else if (insideSQuote) // look for single quote end
1994 {
1995 if (data[j]=='\'' && (j==0 || data[j]!='\\'))
1996 {
1997 insideSQuote=false;
1998 }
1999 }
2000 else if (insideDQuote) // look for double quote end
2001 {
2002 if (data[j]=='"' && (j==0 || data[j]!='\\'))
2003 {
2004 insideDQuote=false;
2005 }
2006 }
2007 if (!found) j++;
2008 }
2009
2010 // include const and volatile
2011 if (literal_at(data+j," const"))
2012 {
2013 j+=6;
2014 }
2015 else if (literal_at(data+j," volatile"))
2016 {
2017 j+=9;
2018 }
2019
2020 // allow '&' or '&&' or ' &' or ' &&' at the end
2021 size_t k=j;
2022 while (k<len && data[k]==' ') k++;
2023 if (k<len-1 && data[k]=='&' && data[k+1]=='&') j=k+2;
2024 else if (k<len && data[k]=='&' ) j=k+1;
2025
2026 // do not include punctuation added by Definition::_setBriefDescription()
2027 size_t e=j;
2028 if (j>0 && data[j-1]=='.') { e--; }
2029 DString id(data+s,e-s);
2030 //printf("extractCopyDocId='%s' input='%s'\n",qPrint(id),&data[s]);
2031 return id;
2032}
2033
2034// macro to check if the input starts with a specific command.
2035// note that data[i] should point to the start of the command (\ or @ character)
2036// and the sizeof(str) returns the size of str including the '\0' terminator;
2037// a fact we abuse to skip over the start of the command character.
2038// The command name must not continue with more identifier characters,
2039// so that e.g. \dotfile is not mistaken for \dot.
2040#define CHECK_FOR_COMMAND(str,action) \
2041 do if ((i+sizeof(str)<len) && literal_at(data+i+1,str) && !isId(data[i+sizeof(str)])) \
2042 { j=i+sizeof(str); action; } while(0)
2043
2044static size_t isCopyBriefOrDetailsCmd(const char *data, size_t i,size_t len,bool &brief)
2045{
2046 size_t j=0;
2047 if (i==0 || (data[i-1]!='@' && data[i-1]!='\\')) // not an escaped command
2048 {
2049 CHECK_FOR_COMMAND("copybrief",brief=true); // @copybrief or \copybrief
2050 CHECK_FOR_COMMAND("copydetails",brief=false); // @copydetails or \copydetails
2051 }
2052 return j;
2053}
2054
2055static size_t isVerbatimSection(const char *data,size_t i,size_t len,DString &endMarker)
2056{
2057 size_t j=0;
2058 if (i==0 || (data[i-1]!='@' && data[i-1]!='\\')) // not an escaped command
2059 {
2060 CHECK_FOR_COMMAND("dot",endMarker="enddot");
2061 CHECK_FOR_COMMAND("icode",endMarker="endicode");
2062 CHECK_FOR_COMMAND("code",endMarker="endcode");
2063 CHECK_FOR_COMMAND("msc",endMarker="endmsc");
2064 CHECK_FOR_COMMAND("mermaid",endMarker="endmermaid");
2065 CHECK_FOR_COMMAND("iverbatim",endMarker="endiverbatim");
2066 CHECK_FOR_COMMAND("verbatim",endMarker="endverbatim");
2067 CHECK_FOR_COMMAND("iliteral",endMarker="endiliteral");
2068 CHECK_FOR_COMMAND("latexonly",endMarker="endlatexonly");
2069 CHECK_FOR_COMMAND("htmlonly",endMarker="endhtmlonly");
2070 CHECK_FOR_COMMAND("xmlonly",endMarker="endxmlonly");
2071 CHECK_FOR_COMMAND("rtfonly",endMarker="endrtfonly");
2072 CHECK_FOR_COMMAND("manonly",endMarker="endmanonly");
2073 CHECK_FOR_COMMAND("docbookonly",endMarker="enddocbookonly");
2074 CHECK_FOR_COMMAND("startuml",endMarker="enduml");
2075 }
2076 //printf("isVerbatimSection(%s)=%d)\n",qPrint(DString(&data[i]).left(10)),j);
2077 return j;
2078}
2079
2080static size_t skipToEndMarker(const char *data,size_t i,size_t len,const DString &endMarker)
2081{
2082 while (i<len)
2083 {
2084 if ((data[i]=='@' || data[i]=='\\') && // start of command character
2085 (i==0 || (data[i-1]!='@' && data[i-1]!='\\'))) // that is not escaped
2086 {
2087 if (i+endMarker.length()+1<=len && dstrncmp(data+i+1,endMarker.data(),endMarker.length())==0)
2088 {
2089 return i+endMarker.length()+1;
2090 }
2091 }
2092 i++;
2093 }
2094 // oops no endmarker found...
2095 return i<len ? i+1 : len;
2096}
2097
2098
2099DString DocParser::processCopyDoc(const char *data,size_t &len)
2100{
2101 AUTO_TRACE("data={} len={}",Trace::trunc(data),len);
2102 DString result;
2103 result.reserve(len+32);
2104 size_t i=0;
2105 int lineNr = tokenizer.getLineNr();
2106 while (i<len)
2107 {
2108 char c = data[i];
2109 if (c=='@' || c=='\\') // look for a command
2110 {
2111 bool isBrief=true;
2112 size_t j=isCopyBriefOrDetailsCmd(data,i,len,isBrief);
2113 if (j>0)
2114 {
2115 // skip whitespace
2116 while (j<len && (data[j]==' ' || data[j]=='\t')) j++;
2117 // extract the argument
2118 DString id = extractCopyDocId(data,j,len);
2119 const Definition *def = nullptr;
2120 DString doc,brief;
2121 //printf("resolving docs='%s'\n",qPrint(id));
2122 bool found = findDocsForMemberOrCompound(id,&doc,&brief,&def);
2123 if (found && def->isReference())
2124 {
2126 "@copy{} or @copydoc target '{}' found but is from a tag file, skipped",
2127 isBrief?"brief":"details", id);
2128 }
2129 else if (found)
2130 {
2131 //printf("found it def=%p brief='%s' doc='%s' isBrief=%d\n",def,qPrint(brief),qPrint(doc),isBrief);
2132 auto it = std::find(context.copyStack.begin(),context.copyStack.end(),def);
2133 if (it==context.copyStack.end()) // definition not parsed earlier
2134 {
2135 DString orgFileName = context.fileName;
2136 context.copyStack.push_back(def);
2137 auto addDocs = [&](const DString &file_,int line_,const DString &doc_)
2138 {
2139 result+=" \\ifile \""+file_+"\" ";
2140 result+="\\iline "+DString().setNum(line_)+" \\ilinebr ";
2141 size_t len_ = doc_.length();
2142 result+=processCopyDoc(doc_.data(),len_);
2143 };
2144 if (isBrief)
2145 {
2146 addDocs(def->briefFile(),def->briefLine(),brief);
2147 }
2148 else
2149 {
2150 addDocs(def->docFile(),def->docLine(),doc);
2152 {
2153 const MemberDef *md = toMemberDef(def);
2154 const ArgumentList &docArgList = md->templateMaster() ?
2155 md->templateMaster()->argumentList() :
2156 md->argumentList();
2157 result+=inlineArgListToDoc(docArgList);
2158 }
2159 }
2160 context.copyStack.pop_back();
2161 result+=" \\ilinebr \\ifile \""+context.fileName+"\" ";
2162 result+="\\iline "+DString().setNum(lineNr)+" ";
2163 }
2164 else
2165 {
2167 "Found recursive @copy{} or @copydoc relation for argument '{}'.",
2168 isBrief?"brief":"details",id);
2169 }
2170 }
2171 else
2172 {
2174 "@copy{} or @copydoc target '{}' not found", isBrief?"brief":"details",id);
2175 }
2176 // skip over command
2177 i=j;
2178 }
2179 else
2180 {
2181 DString endMarker;
2182 size_t k = isVerbatimSection(data,i,len,endMarker);
2183 if (k>0)
2184 {
2185 size_t orgPos = i;
2186 i=skipToEndMarker(data,k,len,endMarker);
2187 result+=DString(data+orgPos,i-orgPos);
2188 // TODO: adjust lineNr
2189 }
2190 else
2191 {
2192 result+=c;
2193 i++;
2194 }
2195 }
2196 }
2197 else // not a command, just copy
2198 {
2199 result+=c;
2200 i++;
2201 lineNr += (c=='\n') ? 1 : 0;
2202 }
2203 }
2204 len = result.length();
2205 AUTO_TRACE_EXIT("result={}",Trace::trunc(result));
2206 return result;
2207}
2208
2209
2210//---------------------------------------------------------------------------
2211
2213 const DString &fileName,
2214 int startLine,
2215 const Definition *ctx,
2216 const MemberDef *md,
2217 const DString &input,
2218 const DocOptions &options)
2219{
2220 DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);
2221 ASSERT(parser!=nullptr);
2222 if (parser==nullptr) return nullptr;
2223 //printf("validatingParseDoc(%s,%s)=[%s]\n",ctx?qPrint(ctx->name()):"<none>",
2224 // md?qPrint(md->name()):"<none>",
2225 // qPrint(input));
2226 //printf("========== validating %s at line %d\n",qPrint(fileName),startLine);
2227 //printf("---------------- input --------------------\n%s\n----------- end input -------------------\n",qPrint(input));
2228
2229 // set initial token
2230 parser->context.token = parser->tokenizer.resetToken();
2231
2232 if (ctx && ctx!=Doxygen::globalScope &&
2235 )
2236 )
2237 {
2239 }
2240 else if (ctx && ctx->definitionType()==Definition::TypePage)
2241 {
2242 const Definition *scope = (toPageDef(ctx))->getPageScope();
2243 if (scope && scope!=Doxygen::globalScope)
2244 {
2245 parser->context.context = substitute(scope->name(),getLanguageSpecificSeparator(scope->getLanguage(),true),"::");
2246 }
2247 }
2248 else if (ctx && ctx->definitionType()==Definition::TypeGroup)
2249 {
2250 const Definition *scope = (toGroupDef(ctx))->getGroupScope();
2251 if (scope && scope!=Doxygen::globalScope)
2252 {
2253 parser->context.context = substitute(scope->name(),getLanguageSpecificSeparator(scope->getLanguage(),true),"::");
2254 }
2255 }
2256 else
2257 {
2258 parser->context.context = "";
2259 }
2260 parser->context.scope = ctx;
2261 parser->context.lang = getLanguageFromFileName(fileName);
2262
2263 if (options.indexWords() && Doxygen::searchIndex.enabled())
2264 {
2265 if (md)
2266 {
2267 parser->context.searchUrl=md->getOutputFileBase();
2269 }
2270 else if (ctx)
2271 {
2272 parser->context.searchUrl=ctx->getOutputFileBase();
2273 Doxygen::searchIndex.setCurrentDoc(ctx,ctx->anchor(),false);
2274 }
2275 }
2276 else
2277 {
2278 parser->context.searchUrl="";
2279 }
2280
2281 parser->context.fileName = fileName;
2282 parser->context.relPath = (!options.linkFromIndex() && ctx) ?
2284 DString("");
2285 //printf("ctx->name=%s relPath=%s\n",qPrint(ctx->name()),qPrint(parser->context.relPath));
2286 parser->context.memberDef = md;
2287 while (!parser->context.nodeStack.empty()) parser->context.nodeStack.pop();
2288 while (!parser->context.styleStack.empty()) parser->context.styleStack.pop();
2289 while (!parser->context.initialStyleStack.empty()) parser->context.initialStyleStack.pop();
2290 parser->context.inSeeBlock = false;
2291 parser->context.inCodeStyle = false;
2292 parser->context.xmlComment = false;
2293 parser->context.insideHtmlLink = false;
2294 parser->context.includeFileText = "";
2295 parser->context.includeFileOffset = 0;
2296 parser->context.includeFileLength = 0;
2297 parser->context.isExample = options.isExample();
2298 parser->context.exampleName = options.exampleName();
2299 parser->context.hasParamCommand = false;
2300 parser->context.hasReturnCommand = false;
2301 parser->context.retvalsFound.clear();
2302 parser->context.paramsFound.clear();
2303 parser->context.markdownSupport = options.markdownSupport();
2304 parser->context.autolinkSupport = options.autolinkSupport();
2305 if (md)
2306 {
2307 const ArgumentList &al=md->isDocsForDefinition() ? md->argumentList() : md->declArgumentList();
2308 parser->context.numParameters = static_cast<int>(al.size());
2309 }
2310 else
2311 {
2312 parser->context.numParameters = 0;
2313 }
2314 parser->context.paramPosition = 1;
2315
2316 //printf("Starting comment block at %s:%d\n",qPrint(parser->context.fileName),startLine);
2317 parser->tokenizer.setFileName(fileName);
2318 parser->tokenizer.setLineNr(startLine);
2319 size_t ioLen = input.length();
2320 DString inpStr = parser->processCopyDoc(input.data(),ioLen);
2321 if (inpStr.empty() || inpStr.at(inpStr.length()-1)!='\n')
2322 {
2323 inpStr+='\n';
2324 }
2325 //printf("processCopyDoc(in='%s' out='%s')\n",qPrint(input),qPrint(inpStr));
2326 parser->tokenizer.init(inpStr.data(),parser->context.fileName,
2328
2329 // build abstract syntax tree
2330 auto ast = std::make_unique<DocNodeAST>(DocRoot(parser,md!=nullptr,options.singleLine()));
2331 std::get<DocRoot>(ast->root).parse();
2332
2334 {
2335 // pretty print the result
2336 std::visit(PrintDocVisitor{},ast->root);
2337 }
2338
2339 if (md && md->isFunction())
2340 {
2342 }
2344
2345 // reset token
2346 parser->tokenizer.resetToken();
2347
2348 //printf(">>>>>> end validatingParseDoc(%s,%s)\n",ctx?qPrint(ctx->name()):"<none>",
2349 // md?qPrint(md->name()):"<none>");
2350
2351 return ast;
2352}
2353
2354IDocNodeASTPtr validatingParseTitle(IDocParser &parserIntf,const DString &fileName,int lineNr,const DString &input)
2355{
2356 DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);
2357 ASSERT(parser!=nullptr);
2358 if (parser==nullptr) return nullptr;
2359
2360 // set initial token
2361 parser->context.token = parser->tokenizer.resetToken();
2362
2363 //printf("------------ input ---------\n%s\n"
2364 // "------------ end input -----\n",input);
2365 parser->context.context = "";
2366 parser->context.fileName = fileName;
2367 parser->context.relPath = "";
2368 parser->context.memberDef = nullptr;
2369 while (!parser->context.nodeStack.empty()) parser->context.nodeStack.pop();
2370 while (!parser->context.styleStack.empty()) parser->context.styleStack.pop();
2371 while (!parser->context.initialStyleStack.empty()) parser->context.initialStyleStack.pop();
2372 parser->context.inSeeBlock = false;
2373 parser->context.inCodeStyle = false;
2374 parser->context.xmlComment = false;
2375 parser->context.insideHtmlLink = false;
2376 parser->context.includeFileText = "";
2377 parser->context.includeFileOffset = 0;
2378 parser->context.includeFileLength = 0;
2379 parser->context.isExample = false;
2380 parser->context.exampleName = "";
2381 parser->context.hasParamCommand = false;
2382 parser->context.hasReturnCommand = false;
2383 parser->context.retvalsFound.clear();
2384 parser->context.paramsFound.clear();
2385 parser->context.searchUrl="";
2386 parser->context.lang = SrcLangExt::Unknown;
2387 parser->context.markdownSupport = Config_getBool(MARKDOWN_SUPPORT);
2388 parser->context.autolinkSupport = false;
2389
2390 auto ast = std::make_unique<DocNodeAST>(DocTitle(parser,nullptr));
2391
2392 if (!input.empty())
2393 {
2394 // build abstract syntax tree from title string
2395 std::get<DocTitle>(ast->root).parseFromString(nullptr,input);
2396
2398 {
2399 // pretty print the result
2400 std::visit(PrintDocVisitor{},ast->root);
2401 }
2402 }
2403
2404 return ast;
2405}
2406
2408{
2409 DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);
2410 ASSERT(parser!=nullptr);
2411 if (parser==nullptr) return nullptr;
2412
2413 // set initial token
2414 parser->context.token = parser->tokenizer.resetToken();
2415
2416 //printf("------------ input ---------\n%s\n"
2417 // "------------ end input -----\n",input);
2418 //parser->context.token = new TokenInfo;
2419 parser->context.context = "";
2420 parser->context.fileName = "<parseText>";
2421 parser->context.relPath = "";
2422 parser->context.memberDef = nullptr;
2423 while (!parser->context.nodeStack.empty()) parser->context.nodeStack.pop();
2424 while (!parser->context.styleStack.empty()) parser->context.styleStack.pop();
2425 while (!parser->context.initialStyleStack.empty()) parser->context.initialStyleStack.pop();
2426 parser->context.inSeeBlock = false;
2427 parser->context.inCodeStyle = false;
2428 parser->context.xmlComment = false;
2429 parser->context.insideHtmlLink = false;
2430 parser->context.includeFileText = "";
2431 parser->context.includeFileOffset = 0;
2432 parser->context.includeFileLength = 0;
2433 parser->context.isExample = false;
2434 parser->context.exampleName = "";
2435 parser->context.hasParamCommand = false;
2436 parser->context.hasReturnCommand = false;
2437 parser->context.retvalsFound.clear();
2438 parser->context.paramsFound.clear();
2439 parser->context.searchUrl="";
2440 parser->context.lang = SrcLangExt::Unknown;
2441 parser->context.markdownSupport = Config_getBool(MARKDOWN_SUPPORT);
2442 parser->context.autolinkSupport = false;
2443
2444
2445 auto ast = std::make_unique<DocNodeAST>(DocText(parser));
2446
2447 if (!input.empty())
2448 {
2449 parser->tokenizer.setLineNr(1);
2450 parser->tokenizer.init(input.data(),parser->context.fileName,
2452
2453 // build abstract syntax tree
2454 std::get<DocText>(ast->root).parse();
2455
2457 {
2458 // pretty print the result
2459 std::visit(PrintDocVisitor{},ast->root);
2460 }
2461 }
2462
2463 return ast;
2464}
2465
2466IDocNodeASTPtr createRef(IDocParser &parserIntf,const DString &target,const DString &context, const DString &srcFile, int srcLine )
2467{
2468 DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);
2469 ASSERT(parser!=nullptr);
2470 if (parser==nullptr) return nullptr;
2471 if (!srcFile.empty())
2472 {
2473 parser->context.fileName = srcFile;
2474 parser->tokenizer.setFileName(srcFile);
2475 parser->tokenizer.setLineNr(srcLine);
2476 }
2477 return std::make_unique<DocNodeAST>(DocRef(parser,nullptr,target,context));
2478}
2479
2480void docFindSections(const DString &input,
2481 const Definition *d,
2482 const DString &fileName)
2483{
2484 DocParser parser;
2485 parser.tokenizer.findSections(input,d,fileName);
2486}
2487
2488//--------------------------------------------------------------------------------------
2489
2490static int nextUTF8CharPosition(const DString &utf8Str,uint32_t len,uint32_t startPos)
2491{
2492 if (startPos>=len) return len;
2493 uint8_t c = static_cast<uint8_t>(utf8Str[startPos]);
2494 int bytes=getUTF8CharNumBytes(c);
2495 if (c=='&') // skip over character entities
2496 {
2497 bytes=1;
2498 int (*matcher)(int) = nullptr;
2499 c = static_cast<uint8_t>(utf8Str[startPos+bytes]);
2500 if (c=='#') // numerical entity?
2501 {
2502 bytes++;
2503 c = static_cast<uint8_t>(utf8Str[startPos+bytes]);
2504 if (c=='x') // hexadecimal entity?
2505 {
2506 bytes++;
2507 matcher = std::isxdigit;
2508 }
2509 else // decimal entity
2510 {
2511 matcher = std::isdigit;
2512 }
2513 }
2514 else if (std::isalnum(c)) // named entity?
2515 {
2516 bytes++;
2517 matcher = std::isalnum;
2518 }
2519 if (matcher)
2520 {
2521 while ((c = static_cast<uint8_t>(utf8Str[startPos+bytes]))!=0 && matcher(c))
2522 {
2523 bytes++;
2524 }
2525 }
2526 if (c!=';')
2527 {
2528 bytes=1; // not a valid entity, reset bytes counter
2529 }
2530 }
2531 return startPos+bytes;
2532}
2533
2534
2536 const DString &doc,const DString &fileName,int lineNr)
2537{
2538 if (doc.empty()) return "";
2539 static std::mutex s_docCacheMutex;
2540 static std::unordered_map<std::string,DString> s_docCache;
2541
2542 std::lock_guard lock(s_docCacheMutex);
2543 auto it = s_docCache.find(doc.str());
2544 if (it != s_docCache.end())
2545 {
2546 //printf("Cache: [%s]->[%s]\n",qPrint(doc),qPrint(it->second));
2547 return it->second;
2548 }
2549 //printf("parseCommentAsText(%s)\n",qPrint(doc));
2550 TextStream t;
2551 auto parser { createDocParser() };
2552 auto ast { validatingParseDoc(*parser.get(),
2553 fileName,
2554 lineNr,
2555 scope,
2556 md,
2557 doc,
2558 DocOptions()
2559 .setAutolinkSupport(false))
2560 };
2561 auto astImpl = dynamic_cast<const DocNodeAST*>(ast.get());
2562 if (astImpl)
2563 {
2564 TextDocVisitor visitor(t);
2565 std::visit(visitor,astImpl->root);
2566 }
2568 int i=0;
2569 int charCnt=0;
2570 int l=static_cast<int>(result.length());
2571 while ((i=nextUTF8CharPosition(result,l,i))<l)
2572 {
2573 charCnt++;
2574 if (charCnt>=80) break;
2575 }
2576 if (charCnt>=80) // try to truncate the string
2577 {
2578 while ((i=nextUTF8CharPosition(result,l,i))<l && charCnt<100)
2579 {
2580 charCnt++;
2581 if (result.at(i)==',' ||
2582 result.at(i)=='.' ||
2583 result.at(i)=='!' ||
2584 result.at(i)=='?' ||
2585 result.at(i)=='}') // good for UTF-16 characters and } otherwise also a good point to stop the string
2586 {
2587 i++; // we want to be "behind" last inspected character
2588 break;
2589 }
2590 }
2591 }
2592 if ( i < l) result=result.left(i)+"...";
2593 s_docCache.insert(std::make_pair(doc.str(),result));
2594 return result.data();
2595}
2596
2597//--------------------------------------------------------------------------------------
2598
2600 const DString &doc,const DString &fileName,int lineNr)
2601{
2602 static std::mutex s_docCacheMutex;
2603 static std::unordered_map<std::string,DString> s_docCache;
2604
2605 std::lock_guard lock(s_docCacheMutex);
2606 auto it = s_docCache.find(doc.str());
2607 if (it != s_docCache.end())
2608 {
2609 //printf("Cache: [%s]->[%s]\n",qPrint(doc),qPrint(it->second));
2610 return it->second;
2611 }
2612 auto parser { createDocParser() };
2613 auto ast { validatingParseTitle(*parser.get(),fileName,lineNr,doc) };
2614 auto astImpl = dynamic_cast<const DocNodeAST*>(ast.get());
2615 DString result;
2616 if (astImpl)
2617 {
2618 TextStream t;
2619 OutputCodeList codeList;
2620 codeList.add<HtmlCodeGenerator>(&t);
2621 HtmlDocVisitor visitor(t,codeList,scope,fileName);
2622 std::visit(visitor,astImpl->root);
2623 result = t.str();
2624 }
2625 else // fallback, should not happen
2626 {
2627 result = filterTitle(doc);
2628 }
2629 //printf("Conversion: [%s]->[%s]\n",qPrint(doc),qPrint(result));
2630 s_docCache.insert(std::make_pair(doc.str(),result));
2631 return result;
2632}
2633
This class contains the information about the argument of a function or template.
Definition arguments.h:27
This class represents an function or template argument list.
Definition arguments.h:66
size_t size() const
Definition arguments.h:101
void push_back(const Argument &a)
Definition arguments.h:103
bool empty() const
Definition arguments.h:100
constexpr void setNoCite() noexcept
Definition cite.h:35
static constexpr CiteInfoOption makeNumber()
Definition cite.h:29
constexpr void changeToNumber() noexcept
Definition cite.h:33
constexpr void setNoPar() noexcept
Definition cite.h:34
constexpr bool isUnknown() const noexcept
Definition cite.h:37
static constexpr CiteInfoOption makeYear()
Definition cite.h:31
static constexpr CiteInfoOption makeShortAuthor()
Definition cite.h:30
A abstract class representing of a compound symbol.
Definition classdef.h:100
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
DString & setNum(short n)
Definition dstring.h:552
size_t rfind(char c, size_t pos=npos) const
Definition dstring.h:244
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
DString lower() const
Definition dstring.h:326
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
std::string_view view() const
Definition dstring.h:162
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
Definition dstring.h:178
char & at(size_t i)
Returns a reference to the character at index i.
Definition dstring.h:686
DString right(size_t len) const
Definition dstring.h:311
size_t size() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:154
DString & prepend(const char *s)
Definition dstring.h:515
size_t find(char c, size_t pos=0) const
Definition dstring.h:239
DString & sprintf(const char *format,...)
Definition dstring.cpp:34
void reserve(size_t size)
Reserve space for size bytes without changing the string contents.
Definition dstring.h:217
@ ExplicitSize
Definition dstring.h:131
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition dstring.h:337
DString left(size_t len) const
Definition dstring.h:306
const std::string & str() const
Definition dstring.h:645
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:157
bool startsWith(const char *s) const
Definition dstring.h:600
bool endsWith(const char *s) const
Definition dstring.h:617
DString & insert(size_t index, const DString &s)
Definition dstring.h:425
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151
@ PrintTree
Definition debug.h:35
static bool isFlagSet(const DebugMask mask)
Definition debug.cpp:132
The common base class of all entity definitions found in the sources.
Definition definition.h:77
virtual DString briefDescription(bool abbreviate=false) const =0
virtual DString briefFile() const =0
virtual SrcLangExt getLanguage() const =0
Returns the programming language this definition was written in.
virtual int docLine() const =0
virtual DString getDefFileName() const =0
virtual DString documentation() const =0
virtual bool isLinkable() const =0
virtual int getDefLine() const =0
virtual DefType definitionType() const =0
virtual const DString & name() const =0
virtual DString briefDescriptionAsTooltip() const =0
virtual int briefLine() const =0
virtual DString qualifiedName() const =0
virtual DString anchor() const =0
virtual DString getReference() const =0
virtual DString docFile() const =0
virtual DString getSourceFileBase() const =0
virtual bool isReference() const =0
virtual DString getOutputFileBase() const =0
Class representing a directory in the file system.
Definition dir.h:73
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:319
Node representing an anchor.
Definition docnode.h:229
Node representing a citation of some bibliographic reference.
Definition docnode.h:245
Node representing an item of a cross-referenced list.
Definition docnode.h:529
Node representing a Hypertext reference.
Definition docnode.h:832
Node representing an image.
Definition docnode.h:642
@ DocBook
Definition docnode.h:644
Node representing an internal reference to some item.
Definition docnode.h:816
Node representing a word that can be linked to something.
Definition docnode.h:165
Class representing the abstract syntax tree of a documentation block.
Definition docnode.h:1471
void append(Args &&... args)
Append a new DocNodeVariant to the list by constructing it with type T and parameters Args.
Definition docnode.h:1404
T * get_last()
Returns a pointer to the last element in the list if that element exists and holds a T,...
Definition docnode.h:1415
Node representing a paragraph in the documentation tree.
Definition docnode.h:1089
bool isLast() const
Definition docnode.h:1097
bool isFirst() const
Definition docnode.h:1096
void markLast(bool v=true)
Definition docnode.h:1095
void handleIFile(char cmdChar, const DString &cmdName)
std::stack< DocParserContext > contextStack
void handlePendingStyleCommands(DocNodeVariant *parent, DocNodeList &children, size_t numberOfElementsToClose=0)
DocTokenizer tokenizer
void handleInternalRef(DocNodeVariant *parent, DocNodeList &children)
void readTextFileByName(const DString &file, DString &text)
void checkRetvalName()
void errorHandleDefaultToken(DocNodeVariant *parent, Token tok, DocNodeList &children, const DString &txt)
void handleRef(DocNodeVariant *parent, DocNodeList &children, char cmdChar, const DString &cmdName)
Token handleAHref(DocNodeVariant *parent, DocNodeList &children, const HtmlAttribList &tagHtmlAttribs)
void handleStyleEnter(DocNodeVariant *parent, DocNodeList &children, DocStyleChange::Style s, const DString &tagName, const HtmlAttribList *attribs)
void handleParameterType(DocNodeVariant *parent, DocNodeList &children, const DString &paramTypes)
bool defaultHandleToken(DocNodeVariant *parent, Token &tok, DocNodeList &children, bool handleWord=true)
void handleInitialStyleCommands(DocNodeVariant *parent, DocNodeList &children)
bool findDocsForMemberOrCompound(const DString &commandName, DString *pDoc, DString *pBrief, const Definition **pDef)
DString processCopyDoc(const char *data, size_t &len)
Token handleStyleArgument(DocNodeVariant *parent, DocNodeList &children, const DString &cmdName)
void handleStyleLeave(DocNodeVariant *parent, DocNodeList &children, DocStyleChange::Style s, const DString &tagName)
void checkUnOrMultipleDocumentedParams()
void popContext()
Definition docparser.cpp:79
void defaultHandleTitleAndSize(const CommandType cmd, DocNodeVariant *parent, DocNodeList &children, DString &width, DString &height)
void handleImage(DocNodeVariant *parent, DocNodeList &children)
void handleLinkedWord(DocNodeVariant *parent, DocNodeList &children, bool ignoreAutoLinkFlag=false, bool typeLinkOnly=false)
void handleCite(DocNodeVariant *parent, DocNodeList &children)
void handlePrefix(DocNodeVariant *parent, DocNodeList &children)
void handleILine(char cmdChar, const DString &cmdName)
void checkArgumentName()
DocParserContext context
Token internalValidatingParseDoc(DocNodeVariant *parent, DocNodeList &children, const DString &doc)
void handleAnchor(DocNodeVariant *parent, DocNodeList &children)
void handleImg(DocNodeVariant *parent, DocNodeList &children, const HtmlAttribList &tagHtmlAttribs)
void handleUnclosedStyleCommands()
void pushContext()
Definition docparser.cpp:64
DString findAndCopyImage(const DString &fileName, DocImage::Type type, bool doWarn=true)
Node representing a reference to some item.
Definition docnode.h:787
Root node of documentation tree.
Definition docnode.h:1318
Node representing a separator.
Definition docnode.h:365
Node representing a style change.
Definition docnode.h:268
const char * styleString() const
Definition docnode.cpp:140
const HtmlAttribList & attribs() const
Definition docnode.h:311
Style style() const
Definition docnode.h:307
DString tagName() const
Definition docnode.h:312
size_t position() const
Definition docnode.h:310
Node representing a special symbol.
Definition docnode.h:328
static HtmlEntityMapper::SymType decodeSymbol(const DString &symName)
Definition docnode.cpp:168
Root node of a text fragment.
Definition docnode.h:1309
Node representing a simple section title.
Definition docnode.h:608
TokenInfo * token()
DString getFileName() const
void setStateTitleAttrValue()
void unputString(const DString &tag)
void setStateCite()
void setStatePrefix()
void setLineNr(int lineno)
void setStateIFile()
void setStateAnchor()
void setStateRtfOnly()
void setStateTitle()
void setStateFile()
void setStateLatexOnly()
void setStateManOnly()
void findSections(const DString &input, const Definition *d, const DString &fileName)
int getLineNr() const
void setStateDbOnly()
void setStateHtmlOnly()
void setStateInternalRef()
void init(const char *input, const DString &fileName, bool markdownSupport, bool insideHtmlLink)
void setStateILine()
void setFileName(const DString &fileName)
void setStateOptions()
void setStatePara()
TokenInfo * resetToken()
void setStateXmlOnly()
void setStateSetScope()
Node representing a URL (or email address).
Definition docnode.h:188
Node representing a verbatim, unparsed text fragment.
Definition docnode.h:376
Node representing some amount of white space.
Definition docnode.h:354
Node representing a word.
Definition docnode.h:153
static NamespaceLinkedMap * namespaceLinkedMap
Definition doxygen.h:108
static FileNameLinkedMap * inputNameLinkedMap
Definition doxygen.h:97
static ClassLinkedMap * classLinkedMap
Definition doxygen.h:88
static NamespaceDefMutable * globalScope
Definition doxygen.h:114
static FileNameLinkedMap * imageNameLinkedMap
Definition doxygen.h:98
static IndexList * indexList
Definition doxygen.h:125
static PageLinkedMap * pageLinkedMap
Definition doxygen.h:92
static FileNameLinkedMap * exampleNameLinkedMap
Definition doxygen.h:95
static SearchIndexIntf searchIndex
Definition doxygen.h:117
static GroupLinkedMap * groupLinkedMap
Definition doxygen.h:107
A model of a file symbol.
Definition filedef.h:97
virtual DString absFilePath() const =0
Minimal replacement for QFileInfo.
Definition fileinfo.h:26
bool isSymLink() const
Definition fileinfo.cpp:82
bool exists() const
Definition fileinfo.cpp:35
DString showFileDefMatches(const DString &n) const
Returns a list of file definitions in fnMap that match the file name n.
Definition filename.cpp:131
FileDef * findFileDef(const DString &n, bool &ambig) const
Returns the file definition in fnMap that matches the file name n.
Definition filename.cpp:38
A model of a group of symbols.
Definition groupdef.h:48
virtual DString groupTitle() const =0
T & back()
access the last element
Definition growvector.h:135
void pop_back()
removes the last element
Definition growvector.h:115
bool empty() const
checks whether the container is empty
Definition growvector.h:140
Class representing a list of HTML attributes.
Definition htmlattrib.h:31
Generator for HTML code fragments.
Definition htmlgen.h:23
Concrete visitor implementation for HTML output.
static HtmlEntityMapper & instance()
Returns the one and only instance of the HTML entity mapper.
DString convertCharEntitiesToUTF8(const DString &s) const
opaque parser interface
Definition docparser.h:35
void addImageFile(const DString &name)
Definition indexlist.h:124
const T * find(const std::string &key) const
Definition linkedmap.h:47
A model of a class/file/namespace member symbol.
Definition memberdef.h:45
virtual bool isObjCMethod() const =0
virtual const MemberDef * inheritsDocsFrom() const =0
virtual DString objCMethodName(bool localLink, bool showStatic) const =0
virtual const ClassDef * getClassDef() const =0
virtual bool isTypedef() const =0
virtual const ArgumentList & argumentList() const =0
virtual bool isFunction() const =0
virtual bool isDocsForDefinition() const =0
virtual bool isDefine() const =0
virtual DString getScopeString() const =0
virtual const MemberDef * templateMaster() const =0
virtual bool isEnumerate() const =0
virtual void detectUndocumentedParams(bool hasParamCommand, bool hasReturnCommand) const =0
virtual const ArgumentList & declArgumentList() const =0
virtual bool isEnumValue() const =0
An abstract interface of a namespace symbol.
Class representing a list of different code generators.
Definition outputlist.h:162
void add(OutputCodeIntfPtr &&p)
Definition outputlist.h:192
A model of a page symbol.
Definition pagedef.h:27
static RequirementManager & instance()
void setCurrentDoc(const Definition *ctx, const DString &anchor, bool isSourceFile)
bool enabled() const
Concrete visitor implementation for TEXT output.
Text streaming class that buffers data.
Definition textstream.h:36
std::string str() const
Return the contents of the buffer as a std::string object.
Definition textstream.h:232
bool is(TokenRetval rv) const
TOKEN_SPECIFICATIONS RETVAL_SPECIFICATIONS const char * to_string() const
TokenRetval value() const
bool is_any_of(ARGS... args) const
char command_to_char() const
DString verb
DString sectionId
DString chars
HtmlAttribList attribs
bool isEMailAddr
DString text
DString name
ClassDef * getClass(const DString &n)
Class representing a regular expression.
Definition regex.h:39
Class to iterate through matches.
Definition regex.h:245
CommandType
Definition cmdmapper.h:30
@ CMD_INTERNALREF
Definition cmdmapper.h:66
#define Config_getList(name)
Definition config.h:38
#define Config_getBool(name)
Definition config.h:33
#define Config_getString(name)
Definition config.h:32
std::vector< std::string > StringVector
Definition containers.h:33
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:180
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:54
#define AUTO_TRACE(...)
Definition docnode.cpp:53
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:55
std::variant< DocWord, DocLinkedWord, DocURL, DocLineBreak, DocHorRuler, DocAnchor, DocCite, DocStyleChange, DocSymbol, DocEmoji, DocWhiteSpace, DocSeparator, DocVerbatim, DocInclude, DocIncOperator, DocFormula, DocIndexEntry, DocAutoList, DocAutoListItem, DocTitle, DocXRefItem, DocImage, DocDotFile, DocMscFile, DocDiaFile, DocVhdlFlow, DocLink, DocRef, DocInternalRef, DocHRef, DocHtmlHeader, DocHtmlDescTitle, DocHtmlDescList, DocSection, DocSecRefItem, DocSecRefList, DocInternal, DocParBlock, DocSimpleList, DocHtmlList, DocSimpleSect, DocSimpleSectSep, DocParamSect, DocPara, DocParamList, DocSimpleListItem, DocHtmlListItem, DocHtmlDescData, DocHtmlCell, DocHtmlCaption, DocHtmlRow, DocHtmlTable, DocHtmlBlockQuote, DocText, DocRoot, DocHtmlDetails, DocHtmlSummary, DocPlantUmlFile, DocMermaidFile > DocNodeVariant
Definition docnode.h:66
constexpr DocNodeVariant * parent(DocNodeVariant *n)
returns the parent node of a given node n or nullptr if the node has no parent.
Definition docnode.h:1335
DString parseCommentAsText(const Definition *scope, const MemberDef *md, const DString &doc, const DString &fileName, int lineNr)
IDocNodeASTPtr validatingParseTitle(IDocParser &parserIntf, const DString &fileName, int lineNr, const DString &input)
IDocParserPtr createDocParser()
factory function to create a parser
Definition docparser.cpp:59
DString parseCommentAsHtml(const Definition *scope, const MemberDef *member, const DString &doc, const DString &fileName, int lineNr)
IDocNodeASTPtr createRef(IDocParser &parserIntf, const DString &target, const DString &context, const DString &srcFile, int srcLine)
static int nextUTF8CharPosition(const DString &utf8Str, uint32_t len, uint32_t startPos)
IDocNodeASTPtr validatingParseText(IDocParser &parserIntf, const DString &input)
static DString extractCopyDocId(const char *data, size_t &j, size_t len)
static size_t isVerbatimSection(const char *data, size_t i, size_t len, DString &endMarker)
void docFindSections(const DString &input, const Definition *d, const DString &fileName)
static size_t skipToEndMarker(const char *data, size_t i, size_t len, const DString &endMarker)
static size_t isCopyBriefOrDetailsCmd(const char *data, size_t i, size_t len, bool &brief)
IDocNodeASTPtr validatingParseDoc(IDocParser &parserIntf, const DString &fileName, int startLine, const Definition *ctx, const MemberDef *md, const DString &input, const DocOptions &options)
#define CHECK_FOR_COMMAND(str, action)
std::unique_ptr< IDocNodeAST > IDocNodeASTPtr
Definition docparser.h:57
std::unique_ptr< IDocParser > IDocParserPtr
pointer to parser interface
Definition docparser.h:41
Private header shared between docparser.cpp and docnode.cpp.
IterableStack< const DocNodeVariant * > DocStyleChangeStack
Definition docparser_p.h:54
bool insidePRE(const DocNodeVariant *n)
bool insideLI(const DocNodeVariant *n)
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
Definition dstring.cpp:485
int dstrncmp(const char *str1, const char *str2, size_t len)
Definition dstring.h:56
uint32_t dstrlen(const char *str)
Returns the length of string str, or 0 if a null pointer is passed.
Definition dstring.h:39
const char * qPrint(const char *s)
Definition dstring.h:783
FileDef * toFileDef(Definition *d)
Definition filedef.cpp:2054
GroupDef * toGroupDef(Definition *d)
MemberDef * toMemberDef(Definition *d)
#define warn_incomplete_doc(file, line, fmt,...)
Definition message.h:107
#define warn(file, line, fmt,...)
Definition message.h:97
#define err(fmt,...)
Definition message.h:127
#define ASSERT(x)
Definition message.h:142
#define warn_doc_error(file, line, fmt,...)
Definition message.h:112
const Mapper< HtmlTagType > * htmlTagMapper
const Mapper< CommandType > * cmdMapper
int system(const DString &command, const DString &args, bool commandHasConsole=true)
Definition portable.cpp:121
DString trunc(const DString &s, size_t numChars=15)
Definition trace.h:56
bool match(std::string_view str, Match &match, const Ex &re)
Matches a given string str for a match against regular expression re.
Definition regex.cpp:861
PageDef * toPageDef(Definition *d)
Definition pagedef.cpp:656
Portable versions of functions that are platform dependent.
Some helper functions for std::string.
bool literal_at(const char *data, const char(&str)[N])
returns true iff data points to a substring that matches string literal str
Definition stringutil.h:101
StringVector split(const std::string &s, const std::string &delimiter, bool retainEmpty=false)
split input string s by string delimiter delimiter.
Definition stringutil.h:119
Helper class to pass options when calling OutputList::generateDoc().
Definition docoptions.h:24
bool autolinkSupport() const
Definition docoptions.h:33
DString exampleName() const
Definition docoptions.h:29
bool linkFromIndex() const
Definition docoptions.h:31
bool markdownSupport() const
Definition docoptions.h:32
bool indexWords() const
Definition docoptions.h:27
bool singleLine() const
Definition docoptions.h:30
bool isExample() const
Definition docoptions.h:28
StringMultiSet retvalsFound
Definition docparser_p.h:75
DocStyleChangeStack styleStack
Definition docparser_p.h:67
size_t includeFileLength
Definition docparser_p.h:89
DString includeFileText
Definition docparser_p.h:87
DocNodeStack nodeStack
Definition docparser_p.h:66
StringMultiSet paramsFound
Definition docparser_p.h:76
DefinitionStack copyStack
Definition docparser_p.h:69
const Definition * scope
Definition docparser_p.h:60
TokenInfo * token
Definition docparser_p.h:94
DocStyleChangeStack initialStyleStack
Definition docparser_p.h:68
SrcLangExt lang
Definition docparser_p.h:84
size_t includeFileOffset
Definition docparser_p.h:88
const MemberDef * memberDef
Definition docparser_p.h:79
DString exampleName
Definition docparser_p.h:81
const FileDef * currentFile
Definition util.h:103
bool checkCV
Definition util.h:104
bool allowCrossFileStatic
Definition util.h:106
const MemberDef * md
Definition util.h:113
bool found
Definition util.h:112
SrcLangExt
Definition types.h:207
uint8_t getUTF8CharNumBytes(char c)
Returns the number of bytes making up a single UTF8 character given the first byte in the sequence.
Definition utf8.cpp:27
DString inlineArgListToDoc(const ArgumentList &al)
Definition util.cpp:5001
DString filterTitle(const DString &title)
Definition util.cpp:4590
DString detab(const DString &s, size_t &refIndent)
Definition util.cpp:5330
bool resolveRef(const DString &scName, const DString &name, bool inSeeBlock, const Definition **resContext, const MemberDef **resMember, SrcLangExt lang, bool lookForSpecialization, const FileDef *currentFile, bool checkScope)
Definition util.cpp:2139
DString removeRedundantWhiteSpace(const DString &s)
Definition util.cpp:427
DString convertNameToFile(const DString &name, bool allowDots, bool allowUnderscore)
Definition util.cpp:2995
SrcLangExt getLanguageFromFileName(const DString &fileName, SrcLangExt defLang)
Definition util.cpp:4300
DString fileToString(const DString &name, bool filter, bool isSourceCode)
Definition util.cpp:1058
DString linkToText(SrcLangExt lang, const DString &link, bool ignoreDots)
Definition util.cpp:2396
DString relativePathToRoot(const DString &name)
Definition util.cpp:3044
DString argListToString(const ArgumentList &al, bool useCanonicalType, bool showDefVals)
Definition util.cpp:864
bool copyFile(const DString &src, const DString &dest)
Copies the contents of file with name src to the newly created file with name dest.
Definition util.cpp:4755
DString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Definition util.cpp:4765
GetDefResult getDefs(const GetDefInput &input)
Definition util.cpp:1926
DString findExampleFilePath(const DString &file, bool &ambig)
Definition util.cpp:2583
A bunch of utility functions.