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 GetDefResult result = getDefs(input);
547 //printf("found=%d context=%s name=%s\n",result.found,qPrint(context.context),qPrint(name));
548 if (result.found && result.md)
549 {
550 *pDoc=result.md->documentation();
551 *pBrief=result.md->briefDescription();
552 *pDef=result.md;
553 AUTO_TRACE_EXIT("member");
554 return true;
555 }
556
557 int scopeOffset=static_cast<int>(context.context.length());
558 do // for each scope
559 {
560 DString fullName=cmdArg;
561 if (scopeOffset>0)
562 {
563 fullName.prepend(context.context.left(scopeOffset)+"::");
564 }
565 //printf("Trying fullName='%s'\n",qPrint(fullName));
566
567 // try class, namespace, group, page, file reference
568 const ClassDef *cd = Doxygen::classLinkedMap->find(fullName);
569 if (cd) // class
570 {
571 *pDoc=cd->documentation();
572 *pBrief=cd->briefDescription();
573 *pDef=cd;
574 AUTO_TRACE_EXIT("class");
575 return true;
576 }
577 const NamespaceDef *nd = Doxygen::namespaceLinkedMap->find(fullName);
578 if (nd) // namespace
579 {
580 *pDoc=nd->documentation();
581 *pBrief=nd->briefDescription();
582 *pDef=nd;
583 AUTO_TRACE_EXIT("namespace");
584 return true;
585 }
586 if (scopeOffset==0)
587 {
588 scopeOffset=-1;
589 }
590 else
591 {
592 size_t o = context.context.rfind("::",scopeOffset-1);
593 scopeOffset = o!=DString::npos ? static_cast<int>(o) : 0;
594 }
595 } while (scopeOffset>=0);
596
597 AUTO_TRACE_EXIT("not found");
598 return false;
599}
600
601//---------------------------------------------------------------------------
603 DocNodeList &children,const DString &txt)
604{
605 switch (tok.value())
606 {
607 case TokenRetval::TK_COMMAND_AT:
608 // fall through
609 case TokenRetval::TK_COMMAND_BS:
610 {
611 char cs[2] = { tok.command_to_char(), 0 };
612 children.append<DocWord>(this,parent,cs + context.token->name);
613 warn_doc_error(context.fileName,tokenizer.getLineNr(),"Illegal command '{:c}{}' found as part of a {}",
614 tok.command_to_char(),context.token->name,txt);
615 }
616 break;
617 case TokenRetval::TK_SYMBOL:
618 warn_doc_error(context.fileName,tokenizer.getLineNr(),"Unsupported symbol '{}' found as part of a {}",
619 qPrint(context.token->name), qPrint(txt));
620 break;
621 case TokenRetval::TK_HTMLTAG:
622 warn_doc_error(context.fileName,tokenizer.getLineNr(),"Unsupported HTML tag <{}{}> found as part of a {}",
623 context.token->endTag ? "/" : "",context.token->name, txt);
624 break;
625 default:
626 children.append<DocWord>(this,parent,context.token->name);
627 warn_doc_error(context.fileName,tokenizer.getLineNr(),"Unexpected token {} found as part of a {}",
628 tok.to_string(), txt);
629 break;
630 }
631}
632
633//---------------------------------------------------------------------------
634
636{
637 AUTO_TRACE("cmdName={}",cmdName);
638 DString saveCmdName = cmdName;
639 Token tok=tokenizer.lex();
640 size_t styleStackSizeAtStart = context.styleStack.size();
641 if (!tok.is(TokenRetval::TK_WHITESPACE))
642 {
643 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\{} command",
644 saveCmdName);
645 return tok;
646 }
647 tok = tokenizer.lex();
648 while (!tok.is_any_of(TokenRetval::TK_NONE, TokenRetval::TK_EOF, TokenRetval::TK_WHITESPACE,
649 TokenRetval::TK_NEWPARA, TokenRetval::TK_LISTITEM, TokenRetval::TK_ENDLIST)
650 )
651 {
652 static const reg::Ex specialChar(R"([.,|()\‍[\‍]:;?])");
653 if (tok.is(TokenRetval::TK_WORD) && context.token->name.length()==1 &&
654 reg::match(context.token->name.str(),specialChar))
655 {
656 // special character that ends the markup command
657 AUTO_TRACE_ADD("special character ending style argument: '{}' styleStackSize {}->{}",context.token->name,styleStackSizeAtStart,context.styleStack.size());
658 if (context.styleStack.size() > styleStackSizeAtStart) // new styles opened inside command, but not closed
659 {
660 handlePendingStyleCommands(parent,children,context.styleStack.size()-styleStackSizeAtStart);
661 }
662 return tok;
663 }
664 if (!defaultHandleToken(parent,tok,children))
665 {
666 switch (tok.value())
667 {
668 case TokenRetval::TK_HTMLTAG:
670 {
671 // ignore </li> as the end of a style command
672 }
673 else
674 {
675 AUTO_TRACE_EXIT("end tok={}",tok.to_string());
676 return tok;
677 }
678 break;
679 default:
680 errorHandleDefaultToken(parent,tok,children,"\\" + saveCmdName + " command");
681 break;
682 }
683 break;
684 }
685 tok = tokenizer.lex();
686 }
687 AUTO_TRACE_EXIT("end tok={}",tok.to_string());
688 return (tok.is_any_of(TokenRetval::TK_NEWPARA,TokenRetval::TK_LISTITEM,TokenRetval::TK_ENDLIST)) ? tok : Token::make_RetVal_OK();
689}
690
691/*! Called when a style change starts. For instance a <b> command is
692 * encountered.
693 */
695 DocStyleChange::Style s,const DString &tagName,const HtmlAttribList *attribs)
696{
697 AUTO_TRACE("tagName={}",tagName);
698 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),s,tagName,true,
700 context.styleStack.push(&children.back());
702}
703
704/*! Called when a style change ends. For instance a </b> command is
705 * encountered.
706 */
708 DocStyleChange::Style s,const DString &tagName)
709{
710 AUTO_TRACE("tagName={}",tagName);
711 DString tagNameLower = DString(tagName).lower();
712
713 auto topStyleChange = [](const DocStyleChangeStack &stack) -> const DocStyleChange &
714 {
715 return std::get<DocStyleChange>(*stack.top());
716 };
717
718 if (context.styleStack.empty() || // no style change
719 topStyleChange(context.styleStack).style()!=s || // wrong style change
720 topStyleChange(context.styleStack).tagName()!=tagNameLower || // wrong style change
721 topStyleChange(context.styleStack).position()!=context.nodeStack.size() // wrong position
722 )
723 {
724 if (context.styleStack.empty())
725 {
726 warn_doc_error(context.fileName,tokenizer.getLineNr(),"found </{0}> tag without matching <{0}>",tagName);
727 }
728 else if (topStyleChange(context.styleStack).tagName()!=tagNameLower ||
729 topStyleChange(context.styleStack).style()!=s)
730 {
731 warn_doc_error(context.fileName,tokenizer.getLineNr(),"found </{}> tag while expecting </{}>",
732 tagName,topStyleChange(context.styleStack).tagName());
733 }
734 else
735 {
736 warn_doc_error(context.fileName,tokenizer.getLineNr(),"found </{}> at different nesting level ({}) than expected ({})",
737 tagName,context.nodeStack.size(),topStyleChange(context.styleStack).position());
738 }
739 }
740 else // end the section
741 {
742 children.append<DocStyleChange>(
743 this,parent,context.nodeStack.size(),s,
744 topStyleChange(context.styleStack).tagName(),false);
745 context.styleStack.pop();
746 }
748 {
749 context.inCodeStyle = false;
750 }
751}
752
753/*! Called at the end of a paragraph to close all open style changes
754 * (e.g. a <b> without a </b>). The closed styles are pushed onto a stack
755 * and entered again at the start of a new paragraph.
756 */
757void DocParser::handlePendingStyleCommands(DocNodeVariant *parent,DocNodeList &children, size_t numberOfElementsToClose)
758{
759 AUTO_TRACE("context.styleStack.size()={} numberOfElementsToClose={}",context.styleStack.size(),numberOfElementsToClose);
760 if (!context.styleStack.empty())
761 {
762 if (numberOfElementsToClose==0) numberOfElementsToClose = context.styleStack.size(); // 0 is special value for "close all"
763 const DocStyleChange *sc = &std::get<DocStyleChange>(*context.styleStack.top());
764 while (sc && sc->position()>=context.nodeStack.size() && numberOfElementsToClose>0)
765 { // there are unclosed style modifiers in the paragraph
766 AUTO_TRACE_ADD("unclosed style {} at position {}",sc->styleString(),sc->position());
767 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),
768 sc->style(),sc->tagName(),false);
770 context.styleStack.pop();
771 sc = !context.styleStack.empty() ? &std::get<DocStyleChange>(*context.styleStack.top()) : nullptr;
772 numberOfElementsToClose--;
773 }
774 }
775}
776
778{
779 AUTO_TRACE();
780 while (!context.initialStyleStack.empty())
781 {
782 const DocStyleChange &sc = std::get<DocStyleChange>(*context.initialStyleStack.top());
783 handleStyleEnter(parent,children,sc.style(),sc.tagName(),&sc.attribs());
785 }
786}
787
789 const HtmlAttribList &tagHtmlAttribs)
790{
791 AUTO_TRACE();
792 size_t index=0;
793 Token retval = Token::make_RetVal_OK();
794 for (const auto &opt : tagHtmlAttribs)
795 {
796 if (opt.name=="name" || opt.name=="id") // <a name=label> or <a id=label> tag
797 {
798 if (!opt.value.empty())
799 {
800 children.append<DocAnchor>(this,parent,opt.value,true);
801 break; // stop looking for other tag attribs
802 }
803 else
804 {
805 warn_doc_error(context.fileName,tokenizer.getLineNr(),"found <a> tag with name option but without value!");
806 }
807 }
808 else if (opt.name=="href") // <a href=url>..</a> tag
809 {
810 // copy attributes
811 HtmlAttribList attrList = tagHtmlAttribs;
812 // and remove the href attribute
813 attrList.erase(attrList.begin()+index);
814 DString relPath;
815 if (opt.value.at(0) != '#') relPath = context.relPath;
816 children.append<DocHRef>(this, parent, attrList,
817 opt.value, relPath,
818 convertNameToFile(context.fileName, false, true));
820 retval = children.get_last<DocHRef>()->parse();
823 break;
824 }
825 else // unsupported option for tag a
826 {
827 }
828 ++index;
829 }
830 return retval;
831}
832
834{
835 AUTO_TRACE("content.initialStyleStack.size()={}",context.initialStyleStack.size());
836 if (!context.initialStyleStack.empty())
837 {
838 DString tagName = std::get<DocStyleChange>(*context.initialStyleStack.top()).tagName();
839 DString fileName = std::get<DocStyleChange>(*context.initialStyleStack.top()).fileName();
840 int lineNr = std::get<DocStyleChange>(*context.initialStyleStack.top()).lineNr();
843 if (lineNr != -1)
844 {
846 "end of comment block while expecting "
847 "command </{}> (Probable start '{}' at line {})",tagName, fileName, lineNr);
848 }
849 else
850 {
852 "end of comment block while expecting command </{}>",tagName);
853 }
854 }
855}
856
857void DocParser::handleLinkedWord(DocNodeVariant *parent,DocNodeList &children,bool ignoreAutoLinkFlag,bool typeLinkOnly)
858{
859 // helper to check if word w starts with any of the words in AUTOLINK_IGNORE_WORDS
860 auto ignoreWord = [](const DString &w) -> bool {
861 auto list = Config_getList(AUTOLINK_IGNORE_WORDS);
862 return std::find_if(list.begin(), list.end(),
863 [&w](const auto &ignore) { return w.startsWith(ignore); }
864 )!=list.end();
865 };
867 AUTO_TRACE("word={}",name);
868 if (!context.autolinkSupport || ignoreAutoLinkFlag || ignoreWord(context.token->name)) // no autolinking -> add as normal word
869 {
870 children.append<DocWord>(this,parent,name);
871 return;
872 }
873
874 // ------- try to turn the word 'name' into a link
875
876 const Definition *compound=nullptr;
877 const MemberDef *member=nullptr;
878 size_t len = context.token->name.length();
879 ClassDef *cd=nullptr;
880 bool ambig = false;
882 auto lang = context.lang;
883 bool inSeeBlock = context.inSeeBlock || context.inCodeStyle;
884 //printf("handleLinkedWord(%s) context.context=%s\n",qPrint(context.token->name),qPrint(context.context));
885 if (!context.insideHtmlLink &&
886 (resolveRef(context.context,context.token->name,inSeeBlock,&compound,&member,lang,true,fd,true)
887 || (!context.context.empty() && // also try with global scope
888 resolveRef(DString(),context.token->name,inSeeBlock,&compound,&member,lang,false,nullptr,true))
889 )
890 )
891 {
892 //printf("ADD %s = %p (linkable?=%d typeLinkOnly=%d)\n",
893 // qPrint(context.token->name),(void*)member,member ? member->isLinkable() : false, typeLinkOnly);
894 if (member && member->isLinkable())
895 {
896 if (!typeLinkOnly || context.token->name.startsWith("#") ||
897 member->isTypedef() || member->isEnumerate() || member->isEnumValue()) // filter on type links
898 {
899 AUTO_TRACE_ADD("resolved reference as member link");
900 if (member->isObjCMethod())
901 {
902 bool localLink = context.memberDef ? member->getClassDef()==context.memberDef->getClassDef() : false;
903 name = member->objCMethodName(localLink,inSeeBlock);
904 }
905 children.append<DocLinkedWord>(
906 this,parent,name,
907 member->getReference(),
908 member->getOutputFileBase(),
909 member->anchor(),
910 member->briefDescriptionAsTooltip());
911 }
912 else // explicit type link, but not a type
913 {
914 AUTO_TRACE_ADD("no link as request is type but member is not a type or explicit link");
915 children.append<DocWord>(this,parent,context.token->name);
916 }
917 }
918 else if (compound->isLinkable()) // compound link
919 {
920 AUTO_TRACE_ADD("resolved reference as compound link");
921 DString anchor = compound->anchor();
922 if (compound->definitionType()==Definition::TypeFile)
923 {
924 name=context.token->name;
925 }
926 else if (compound->definitionType()==Definition::TypeGroup)
927 {
928 name=toGroupDef(compound)->groupTitle();
929 }
930 children.append<DocLinkedWord>(
931 this,parent,name,
932 compound->getReference(),
933 compound->getOutputFileBase(),
934 anchor,
935 compound->briefDescriptionAsTooltip());
936 }
937 else if (compound->definitionType()==Definition::TypeFile &&
938 (toFileDef(compound))->generateSourceFile()
939 ) // undocumented file that has source code we can link to
940 {
941 AUTO_TRACE_ADD("resolved reference as source link");
942 children.append<DocLinkedWord>(
943 this,parent,context.token->name,
944 compound->getReference(),
945 compound->getSourceFileBase(),
946 "",
947 compound->briefDescriptionAsTooltip());
948 }
949 else // not linkable
950 {
951 AUTO_TRACE_ADD("resolved reference as unlinkable compound={} (linkable={}) member={} (linkable={})",
952 compound ? compound->name() : "<none>", compound ? (int)compound->isLinkable() : -1,
953 member ? member->name() : "<none>", member ? (int)member->isLinkable() : -1);
954 children.append<DocWord>(this,parent,name);
955 }
956 }
957 else if (!context.insideHtmlLink && len>1 && context.token->name.at(len-1)==':')
958 {
959 // special case, where matching Foo: fails to be an Obj-C reference,
960 // but Foo itself might be linkable.
962 handleLinkedWord(parent,children,ignoreAutoLinkFlag);
963 children.append<DocWord>(this,parent,":");
964 }
965 else if (!context.insideHtmlLink && (cd=getClass(context.token->name+"-p")))
966 {
967 // special case 2, where the token name is not a class, but could
968 // be a Obj-C protocol
969 children.append<DocLinkedWord>(
970 this,parent,name,
971 cd->getReference(),
972 cd->getOutputFileBase(),
973 cd->anchor(),
975 }
976 else if (const RequirementIntf *req = RequirementManager::instance().find(name); req!=nullptr) // link to requirement
977 {
978 if (Config_getBool(GENERATE_REQUIREMENTS))
979 {
980 children.append<DocLinkedWord>(
981 this,parent,name,
982 DString(), // link to local requirements overview also for external references
983 req->getOutputFileBase(),
984 req->id(),
985 req->title()
986 );
987 }
988 else // cannot link to a page that does not exist
989 {
990 children.append<DocWord>(this,parent,name);
991 }
992 }
993 else // normal non-linkable word
994 {
995 AUTO_TRACE_ADD("non-linkable");
996 if (context.token->name.startsWith("#"))
997 {
998 warn_doc_error(context.fileName,tokenizer.getLineNr(),"explicit link request to '{}' could not be resolved",name);
999 }
1000 children.append<DocWord>(this,parent,context.token->name);
1001 }
1002}
1003
1005{
1006 DString name = context.token->name; // save token name
1007 AUTO_TRACE("name={}",name);
1008 DString name1;
1009 size_t p=0, i=0, ii=0;
1010 while ((i=paramTypes.find('|',p))!=DString::npos)
1011 {
1012 name1 = paramTypes.mid(p,i-p);
1013 ii=name1.find('[');
1014 context.token->name=ii!=DString::npos ? name1.mid(0,ii) : name1; // take part without []
1015 handleLinkedWord(parent,children);
1016 if (ii!=DString::npos) children.append<DocWord>(this,parent,name1.mid(ii)); // add [] part
1017 p=i+1;
1018 children.append<DocSeparator>(this,parent,"|");
1019 }
1020 name1 = paramTypes.mid(p);
1021 ii=name1.find('[');
1022 context.token->name=ii!=DString::npos ? name1.mid(0,ii) : name1;
1023 handleLinkedWord(parent,children);
1024 if (ii!=DString::npos) children.append<DocWord>(this,parent,name1.mid(ii));
1025 context.token->name = name; // restore original token name
1026}
1027
1029{
1030 Token tok=tokenizer.lex();
1031 DString tokenName = context.token->name;
1032 AUTO_TRACE("name={}",tokenName);
1033 if (!tok.is(TokenRetval::TK_WHITESPACE))
1034 {
1035 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\{} command", tokenName);
1036 return;
1037 }
1039 tok=tokenizer.lex(); // get the reference id
1040 if (!tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_LNKWORD))
1041 {
1042 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of {}",
1043 tok.to_string(),tokenName);
1044 return;
1045 }
1046 children.append<DocInternalRef>(this,parent,context.token->name);
1047 children.get_last<DocInternalRef>()->parse();
1048}
1049
1051{
1052 AUTO_TRACE();
1053 Token tok=tokenizer.lex();
1054 if (!tok.is(TokenRetval::TK_WHITESPACE))
1055 {
1056 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\{} command",
1057 context.token->name);
1058 return;
1059 }
1060
1063 tok=tokenizer.lex();
1064 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1065 {
1066 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected end of comment block while parsing the "
1067 "argument of command {}",context.token->name);
1068 return;
1069 }
1070 else if (!tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_LNKWORD))
1071 {
1072 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of {}",
1073 tok.to_string(),context.token->name);
1074 return;
1075 }
1076 }
1077 children.append<DocAnchor>(this,parent,context.token->name,false);
1078}
1079
1081{
1082 AUTO_TRACE();
1083 // get the argument of the cite command.
1084 Token tok=tokenizer.lex();
1085
1086 CiteInfoOption option;
1087 if (tok.is(TokenRetval::TK_WORD) && context.token->name=="{")
1088 {
1090 tokenizer.lex();
1091 StringVector optList=split(context.token->name.str(),",");
1092 for (auto const &opt : optList)
1093 {
1094 if (opt == "number")
1095 {
1096 if (!option.isUnknown())
1097 {
1098 warn(context.fileName,tokenizer.getLineNr(),"Multiple options specified with \\{}, discarding '{}'", context.token->name, opt);
1099 }
1100 else
1101 {
1102 option = CiteInfoOption::makeNumber();
1103 }
1104 }
1105 else if (opt == "year")
1106 {
1107 if (!option.isUnknown())
1108 {
1109 warn(context.fileName,tokenizer.getLineNr(),"Multiple options specified with \\{}, discarding '{}'", context.token->name, opt);
1110 }
1111 else
1112 {
1113 option = CiteInfoOption::makeYear();
1114 }
1115 }
1116 else if (opt == "shortauthor")
1117 {
1118 if (!option.isUnknown())
1119 {
1120 warn(context.fileName,tokenizer.getLineNr(),"Multiple options specified with \\{}, discarding '{}'", context.token->name, opt);
1121 }
1122 else
1123 {
1125 }
1126 }
1127 else if (opt == "nopar")
1128 {
1129 option.setNoPar();
1130 }
1131 else if (opt == "nocite")
1132 {
1133 option.setNoCite();
1134 }
1135 else
1136 {
1137 warn(context.fileName,tokenizer.getLineNr(),"Unknown option specified with \\{}, discarding '{}'", context.token->name, opt);
1138 }
1139 }
1140
1141 if (option.isUnknown()) option.changeToNumber();
1142
1144 tok=tokenizer.lex();
1145 if (!tok.is(TokenRetval::TK_WHITESPACE))
1146 {
1147 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\{} command",
1148 context.token->name);
1149 return;
1150 }
1151 }
1152 else if (!tok.is(TokenRetval::TK_WHITESPACE))
1153 {
1154 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after '\\{}' command",
1155 context.token->name);
1156 return;
1157 }
1158 else
1159 {
1160 option = CiteInfoOption::makeNumber();
1161 }
1162
1165 tok=tokenizer.lex();
1166 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1167 {
1168 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected end of comment block while parsing the "
1169 "argument of command '\\{}'",context.token->name);
1170 return;
1171 }
1172 else if (!tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_LNKWORD))
1173 {
1174 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of '\\{}'",
1175 tok.to_string(),context.token->name);
1176 return;
1177 }
1179 children.append<DocCite>(this,parent,context.token->name,context.context,option);
1180 }
1181
1182}
1183
1185{
1186 AUTO_TRACE();
1187 Token tok=tokenizer.lex();
1188 if (!tok.is(TokenRetval::TK_WHITESPACE))
1189 {
1190 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\{} command", context.token->name);
1191 return;
1192 }
1194 tok=tokenizer.lex();
1195 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1196 {
1197 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected end of comment block while parsing the "
1198 "argument of command {}",context.token->name);
1199 return;
1200 }
1201 else if (!tok.is(TokenRetval::TK_WORD))
1202 {
1203 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of {}",
1204 tok.to_string(),context.token->name);
1205 return;
1206 }
1209}
1210
1211/* Helper function that deals with the title, width, and height arguments of various commands.
1212 * @param[in] cmd Command id for which to extract caption and size info.
1213 * @param[in] parent Parent node, owner of the children list passed as
1214 * the third argument.
1215 * @param[in] children The list of child nodes to which the node representing
1216 * the token can be added.
1217 * @param[out] width the extracted width specifier
1218 * @param[out] height the extracted height specifier
1219 */
1221{
1222 AUTO_TRACE();
1223 auto ns = AutoNodeStack(this,parent);
1224
1225 // parse title
1227 Token tok = tokenizer.lex();
1228 while (!tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1229 {
1230 if (tok.is(TokenRetval::TK_WORD) && (context.token->name=="width=" || context.token->name=="height="))
1231 {
1232 // special case: no title, but we do have a size indicator
1233 break;
1234 }
1235 else if (tok.is(TokenRetval::TK_HTMLTAG))
1236 {
1238 break;
1239 }
1240 if (!defaultHandleToken(parent,tok,children))
1241 {
1242 errorHandleDefaultToken(parent,tok,children,Mappers::cmdMapper->find(cmd));
1243 }
1244 tok = tokenizer.lex();
1245 }
1246 // parse size attributes
1247 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1248 {
1249 tok=tokenizer.lex();
1250 }
1251 while (tok.is_any_of(TokenRetval::TK_WHITESPACE,TokenRetval::TK_WORD,TokenRetval::TK_HTMLTAG)) // there are values following the title
1252 {
1253 if (tok.is(TokenRetval::TK_WORD))
1254 {
1255 if (context.token->name=="width=" || context.token->name=="height=")
1256 {
1259 }
1260
1261 if (context.token->name=="width")
1262 {
1263 width = context.token->chars;
1264 }
1265 else if (context.token->name=="height")
1266 {
1267 height = context.token->chars;
1268 }
1269 else // other text after the title -> treat as normal text
1270 {
1272 //warn_doc_error(context.fileName,tokenizer.getLineNr(),"Unknown option '{}' after \\{} command, expected 'width' or 'height'",
1273 // context.token->name, Mappers::cmdMapper->find(cmd));
1274 break;
1275 }
1276 }
1277
1278 tok=tokenizer.lex();
1279 // if we found something we did not expect, push it back to the stream
1280 // so it can still be processed
1281 if (tok.is_any_of(TokenRetval::TK_COMMAND_AT,TokenRetval::TK_COMMAND_BS))
1282 {
1284 tokenizer.unputString(tok.is(TokenRetval::TK_COMMAND_AT) ? "@" : "\\");
1285 break;
1286 }
1287 else if (tok.is(TokenRetval::TK_SYMBOL))
1288 {
1290 break;
1291 }
1292 else if (tok.is(TokenRetval::TK_HTMLTAG))
1293 {
1295 break;
1296 }
1297 }
1299
1301 AUTO_TRACE_EXIT("width={} height={}",width,height);
1302}
1303
1305{
1306 AUTO_TRACE();
1307 bool inlineImage = false;
1308 DString anchorStr;
1309
1310 Token tok=tokenizer.lex();
1311 if (!tok.is(TokenRetval::TK_WHITESPACE))
1312 {
1313 if (tok.is(TokenRetval::TK_WORD))
1314 {
1315 if (context.token->name == "{")
1316 {
1318 tokenizer.lex();
1320 StringVector optList=split(context.token->name.str(),",");
1321 for (const auto &opt : optList)
1322 {
1323 if (opt.empty()) continue;
1324 DString locOpt(opt);
1325 DString locOptLow;
1326 locOpt = locOpt.stripWhiteSpace();
1327 locOptLow = locOpt.lower();
1328 if (locOptLow == "inline")
1329 {
1330 inlineImage = true;
1331 }
1332 else if (locOptLow.startsWith("anchor:"))
1333 {
1334 if (!anchorStr.empty())
1335 {
1337 "multiple use of option 'anchor' for 'image' command, ignoring: '{}'",
1338 locOpt.mid(7));
1339 }
1340 else
1341 {
1342 anchorStr = locOpt.mid(7);
1343 }
1344 }
1345 else
1346 {
1348 "unknown option '{}' for 'image' command specified",
1349 locOpt);
1350 }
1351 }
1352 tok=tokenizer.lex();
1353 if (!tok.is(TokenRetval::TK_WHITESPACE))
1354 {
1355 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\image command");
1356 return;
1357 }
1358 }
1359 }
1360 else
1361 {
1362 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\image command");
1363 return;
1364 }
1365 }
1366 tok=tokenizer.lex();
1367 if (!tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_LNKWORD))
1368 {
1369 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of \\image",
1370 tok.to_string());
1371 return;
1372 }
1373 tok=tokenizer.lex();
1374 if (!tok.is(TokenRetval::TK_WHITESPACE))
1375 {
1376 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after \\image command");
1377 return;
1378 }
1380 DString imgType = context.token->name.lower();
1381 if (imgType=="html") t=DocImage::Html;
1382 else if (imgType=="latex") t=DocImage::Latex;
1383 else if (imgType=="docbook") t=DocImage::DocBook;
1384 else if (imgType=="rtf") t=DocImage::Rtf;
1385 else if (imgType=="xml") t=DocImage::Xml;
1386 else
1387 {
1388 warn_doc_error(context.fileName,tokenizer.getLineNr(),"output format `{}` specified as the first argument of "
1389 "\\image command is not valid", imgType);
1390 return;
1391 }
1393 tok=tokenizer.lex();
1395 if (!tok.is(TokenRetval::TK_WORD))
1396 {
1397 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of \\image", tok.to_string());
1398 return;
1399 }
1400 if (!anchorStr.empty())
1401 {
1402 children.append<DocAnchor>(this,parent,anchorStr,true);
1403 }
1404 HtmlAttribList attrList;
1405 children.append<DocImage>(this,parent,attrList,
1406 findAndCopyImage(context.token->name,t),t,"",inlineImage);
1407 children.get_last<DocImage>()->parse();
1408}
1409
1410void DocParser::handleRef(DocNodeVariant *parent, DocNodeList &children, char cmdChar, const DString &cmdName)
1411{
1412 AUTO_TRACE("cmdName={}",cmdName);
1413 DString saveCmdName = cmdName;
1415 Token tok=tokenizer.lex();
1416 if (!tok.is(TokenRetval::TK_WHITESPACE))
1417 {
1418 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after '{:c}{}' command",
1419 cmdChar,qPrint(saveCmdName));
1420 return;
1421 }
1423 tok=tokenizer.lex(); // get the reference id
1424 if (!tok.is(TokenRetval::TK_WORD))
1425 {
1426 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of '{:c}{}'",
1427 tok.to_string(),cmdChar,saveCmdName);
1428 return;
1429 }
1430 children.append<DocRef>(this,parent,
1433 children.get_last<DocRef>()->parse(cmdChar,saveCmdName);
1434}
1435
1436void DocParser::handleIFile(char cmdChar,const DString &cmdName)
1437{
1438 AUTO_TRACE();
1439 Token tok=tokenizer.lex();
1440 if (!tok.is(TokenRetval::TK_WHITESPACE))
1441 {
1442 warn_doc_error(context.fileName,tokenizer.getLineNr(),"expected whitespace after '{:c}{}' command",
1443 cmdChar,cmdName);
1444 return;
1445 }
1447 tok=tokenizer.lex();
1449 if (!tok.is(TokenRetval::TK_WORD))
1450 {
1451 warn_doc_error(context.fileName,tokenizer.getLineNr(),"unexpected token {} as the argument of '{:c}{}'",
1452 tok.to_string(),cmdChar,cmdName);
1453 return;
1454 }
1456}
1457
1458void DocParser::handleILine(char cmdChar,const DString &cmdName)
1459{
1460 AUTO_TRACE();
1462 Token tok = tokenizer.lex();
1464 if (!tok.is(TokenRetval::TK_WORD))
1465 {
1466 warn_doc_error(context.fileName,tokenizer.getLineNr(),"invalid argument for command '{:c}{}'",
1467 cmdChar,cmdName);
1468 return;
1469 }
1470}
1471
1472/* Helper function that deals with the most common tokens allowed in
1473 * title like sections.
1474 * @param parent Parent node, owner of the children list passed as
1475 * the third argument.
1476 * @param tok The token to process.
1477 * @param children The list of child nodes to which the node representing
1478 * the token can be added.
1479 * @param handleWord Indicates if word token should be processed
1480 * @retval true The token was handled.
1481 * @retval false The token was not handled.
1482 */
1484{
1485 AUTO_TRACE("token={} handleWord={}",tok.to_string(),handleWord);
1486 if (tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_LNKWORD,TokenRetval::TK_SYMBOL,TokenRetval::TK_URL,
1487 TokenRetval::TK_COMMAND_AT,TokenRetval::TK_COMMAND_BS,TokenRetval::TK_HTMLTAG)
1488 )
1489 {
1490 }
1491reparsetoken:
1492 DString tokenName = context.token->name;
1493 AUTO_TRACE_ADD("tokenName={}",tokenName);
1494 switch (tok.value())
1495 {
1496 case TokenRetval::TK_COMMAND_AT:
1497 // fall through
1498 case TokenRetval::TK_COMMAND_BS:
1499 switch (Mappers::cmdMapper->map(tokenName))
1500 {
1503 break;
1506 break;
1509 break;
1512 break;
1515 break;
1518 break;
1521 break;
1524 break;
1527 break;
1531 break;
1536 break;
1539 break;
1542 break;
1545 break;
1548 break;
1551 break;
1554 break;
1557 break;
1559 {
1560 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),DocStyleChange::Italic,tokenName,true);
1561 tok=handleStyleArgument(parent,children,tokenName);
1562 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),DocStyleChange::Italic,tokenName,false);
1563 if (!tok.is(TokenRetval::TK_WORD)) children.append<DocWhiteSpace>(this,parent," ");
1564 if (tok.is(TokenRetval::TK_NEWPARA)) goto handlepara;
1565 else if (tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_HTMLTAG))
1566 {
1567 AUTO_TRACE_ADD("CommandType::CMD_EMPHASIS: reparsing");
1568 goto reparsetoken;
1569 }
1570 }
1571 break;
1573 {
1574 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),DocStyleChange::Bold,tokenName,true);
1575 tok=handleStyleArgument(parent,children,tokenName);
1576 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),DocStyleChange::Bold,tokenName,false);
1577 if (!tok.is(TokenRetval::TK_WORD)) children.append<DocWhiteSpace>(this,parent," ");
1578 if (tok.is(TokenRetval::TK_NEWPARA)) goto handlepara;
1579 else if (tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_HTMLTAG))
1580 {
1581 AUTO_TRACE_ADD("CommandType::CMD_BOLD: reparsing");
1582 goto reparsetoken;
1583 }
1584 }
1585 break;
1587 {
1588 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),DocStyleChange::Code,tokenName,true);
1589 tok=handleStyleArgument(parent,children,tokenName);
1590 children.append<DocStyleChange>(this,parent,context.nodeStack.size(),DocStyleChange::Code,tokenName,false);
1591 if (!tok.is(TokenRetval::TK_WORD)) children.append<DocWhiteSpace>(this,parent," ");
1592 if (tok.is(TokenRetval::TK_NEWPARA)) goto handlepara;
1593 else if (tok.is_any_of(TokenRetval::TK_WORD,TokenRetval::TK_HTMLTAG))
1594 {
1595 AUTO_TRACE_ADD("CommandType::CMD_CODE: reparsing");
1596 goto reparsetoken;
1597 }
1598 }
1599 break;
1601 {
1603 tok = tokenizer.lex();
1605 if (tok.is_any_of(TokenRetval::TK_NONE,TokenRetval::TK_EOF))
1606 {
1607 warn_doc_error(context.fileName,tokenizer.getLineNr(),"htmlonly section ended without end marker");
1608 }
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(),"manonly 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(),"rtfonly 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(),"latexonly 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(),"xmlonly 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(),"docbookonly section ended without end marker");
1668 }
1670 }
1671 break;
1673 {
1674 children.append<DocFormula>(this,parent,context.token->id);
1675 }
1676 break;
1679 {
1680 handleAnchor(parent,children);
1681 }
1682 break;
1684 {
1685 handleCite(parent,children);
1686 }
1687 break;
1689 {
1690 handlePrefix(parent,children);
1691 }
1692 break;
1694 {
1695 handleInternalRef(parent,children);
1697 }
1698 break;
1700 {
1702 (void)tokenizer.lex();
1704 //printf("Found scope='%s'\n",qPrint(context.context));
1706 }
1707 break;
1709 handleImage(parent,children);
1710 break;
1712 handleILine(tok.command_to_char(),tokenName);
1713 break;
1715 handleIFile(tok.command_to_char(),tokenName);
1716 break;
1717 default:
1718 return false;
1719 }
1720 break;
1721 case TokenRetval::TK_HTMLTAG:
1722 {
1723 auto handleEnterLeaveStyle = [this,&parent,&children,&tokenName](DocStyleChange::Style style) {
1724 if (!context.token->endTag)
1725 {
1726 handleStyleEnter(parent,children,style,tokenName,&context.token->attribs);
1727 }
1728 else
1729 {
1730 handleStyleLeave(parent,children,style,tokenName);
1731 }
1732 };
1733 switch (Mappers::htmlTagMapper->map(tokenName))
1734 {
1736 warn_doc_error(context.fileName,tokenizer.getLineNr(),"found <div> tag in heading");
1737 break;
1739 warn_doc_error(context.fileName,tokenizer.getLineNr(),"found <pre> tag in heading");
1740 break;
1742 handleEnterLeaveStyle(DocStyleChange::Span);
1743 break;
1745 handleEnterLeaveStyle(DocStyleChange::Bold);
1746 break;
1748 handleEnterLeaveStyle(DocStyleChange::S);
1749 break;
1751 handleEnterLeaveStyle(DocStyleChange::Strike);
1752 break;
1754 handleEnterLeaveStyle(DocStyleChange::Del);
1755 break;
1757 handleEnterLeaveStyle(DocStyleChange::Underline);
1758 break;
1760 handleEnterLeaveStyle(DocStyleChange::Ins);
1761 break;
1763 case HtmlTagType::XML_C:
1764 handleEnterLeaveStyle(DocStyleChange::Code);
1765 break;
1767 handleEnterLeaveStyle(DocStyleChange::Kbd);
1768 break;
1770 handleEnterLeaveStyle(DocStyleChange::Typewriter);
1771 break;
1773 handleEnterLeaveStyle(DocStyleChange::Italic);
1774 break;
1776 handleEnterLeaveStyle(DocStyleChange::Subscript);
1777 break;
1779 handleEnterLeaveStyle(DocStyleChange::Superscript);
1780 break;
1782 handleEnterLeaveStyle(DocStyleChange::Center);
1783 break;
1785 handleEnterLeaveStyle(DocStyleChange::Small);
1786 break;
1788 handleEnterLeaveStyle(DocStyleChange::Cite);
1789 break;
1791 if (!context.token->endTag)
1792 {
1794 }
1795 break;
1796 default:
1797 return false;
1798 break;
1799 }
1800 }
1801 break;
1802 case TokenRetval::TK_SYMBOL:
1803 {
1806 {
1807 children.append<DocSymbol>(this,parent,s);
1808 }
1809 else
1810 {
1811 return false;
1812 }
1813 }
1814 break;
1815 case TokenRetval::TK_WHITESPACE:
1816 case TokenRetval::TK_NEWPARA:
1817handlepara:
1818 if (insidePRE(parent) || !children.empty())
1819 {
1820 children.append<DocWhiteSpace>(this,parent,context.token->chars);
1821 }
1822 break;
1823 case TokenRetval::TK_LNKWORD:
1824 if (handleWord)
1825 {
1826 handleLinkedWord(parent,children);
1827 }
1828 else
1829 return false;
1830 break;
1831 case TokenRetval::TK_WORD:
1832 if (handleWord)
1833 {
1834 children.append<DocWord>(this,parent,context.token->name);
1835 }
1836 else
1837 return false;
1838 break;
1839 case TokenRetval::TK_URL:
1841 {
1842 children.append<DocWord>(this,parent,context.token->name);
1843 }
1844 else
1845 {
1847 }
1848 break;
1849 default:
1850 return false;
1851 }
1852 return true;
1853}
1854
1855//---------------------------------------------------------------------------
1856
1858{
1859 AUTO_TRACE();
1860 bool found=false;
1861 size_t index=0;
1862 for (const auto &opt : tagHtmlAttribs)
1863 {
1864 AUTO_TRACE_ADD("option name={} value='{}'",opt.name,opt.value);
1865 if (opt.name=="src" && !opt.value.empty())
1866 {
1867 // copy attributes
1868 HtmlAttribList attrList = tagHtmlAttribs;
1869 // and remove the src attribute
1870 attrList.erase(attrList.begin()+index);
1872 children.append<DocImage>(
1873 this,parent,attrList,
1874 findAndCopyImage(opt.value,t,false),
1875 t,opt.value);
1876 found = true;
1877 }
1878 ++index;
1879 }
1880 if (!found)
1881 {
1882 warn_doc_error(context.fileName,tokenizer.getLineNr(),"IMG tag does not have a SRC attribute!");
1883 }
1884}
1885
1886//---------------------------------------------------------------------------
1887
1889 const DString &doc)
1890{
1891 AUTO_TRACE();
1892 Token retval = Token::make_RetVal_OK();
1893
1894 if (doc.empty()) return retval;
1895
1897
1898 // first parse any number of paragraphs
1899 bool isFirst=true;
1900 DocPara *lastPar=!children.empty() ? std::get_if<DocPara>(&children.back()): nullptr;
1901 if (lastPar)
1902 { // last child item was a paragraph
1903 isFirst=false;
1904 }
1905 do
1906 {
1907 children.append<DocPara>(this,parent);
1908 DocPara *par = children.get_last<DocPara>();
1909 if (isFirst) { par->markFirst(); isFirst=false; }
1910 retval=par->parse();
1911 if (!par->empty())
1912 {
1913 if (lastPar) lastPar->markLast(false);
1914 lastPar=par;
1915 }
1916 else
1917 {
1918 children.pop_back();
1919 }
1920 } while (retval.is(TokenRetval::TK_NEWPARA));
1921 if (lastPar) lastPar->markLast();
1922
1923 AUTO_TRACE_EXIT("isFirst={} isLast={}",lastPar?lastPar->isFirst():-1,lastPar?lastPar->isLast():-1);
1924 return retval;
1925}
1926
1927//---------------------------------------------------------------------------
1928
1930{
1931 AUTO_TRACE("file={} text={}",file,text);
1932 bool ambig = false;
1933 DString filePath = findExampleFilePath(file,ambig);
1934 if (!filePath.empty())
1935 {
1936 size_t indent = 0;
1937 text = detab(fileToString(filePath,Config_getBool(FILTER_SOURCE_FILES)),indent);
1938 if (ambig)
1939 {
1940 warn_doc_error(context.fileName,tokenizer.getLineNr(),"included file name '{}' is ambiguous"
1941 "Possible candidates:\n{}",file, Doxygen::exampleNameLinkedMap->showFileDefMatches(file));
1942 }
1943 }
1944 else
1945 {
1946 warn_doc_error(context.fileName,tokenizer.getLineNr(),"included file '{}' is not found. "
1947 "Check your EXAMPLE_PATH",file);
1948 }
1949}
1950
1951//---------------------------------------------------------------------------
1952
1953static DString extractCopyDocId(const char *data, size_t &j, size_t len)
1954{
1955 size_t s=j;
1956 int round=0;
1957 bool insideDQuote=false;
1958 bool insideSQuote=false;
1959 bool found=false;
1960 while (j<len && !found)
1961 {
1962 if (!insideSQuote && !insideDQuote)
1963 {
1964 switch (data[j])
1965 {
1966 case '(': round++; break;
1967 case ')': round--; break;
1968 case '"': insideDQuote=true; break;
1969 case '\'': insideSQuote=true; break;
1970 case '\\': // fall through, begin of command
1971 case '@': // fall through, begin of command
1972 case '\t': // fall through
1973 case '\n':
1974 found=(round==0);
1975 break;
1976 case ' ': // allow spaces in cast operator (see issue #11169)
1977 found=(round==0) && (j<8 || !literal_at(data+j-8,"operator"));
1978 break;
1979 }
1980 }
1981 else if (insideSQuote) // look for single quote end
1982 {
1983 if (data[j]=='\'' && (j==0 || data[j]!='\\'))
1984 {
1985 insideSQuote=false;
1986 }
1987 }
1988 else if (insideDQuote) // look for double quote end
1989 {
1990 if (data[j]=='"' && (j==0 || data[j]!='\\'))
1991 {
1992 insideDQuote=false;
1993 }
1994 }
1995 if (!found) j++;
1996 }
1997
1998 // include const and volatile
1999 if (literal_at(data+j," const"))
2000 {
2001 j+=6;
2002 }
2003 else if (literal_at(data+j," volatile"))
2004 {
2005 j+=9;
2006 }
2007
2008 // allow '&' or '&&' or ' &' or ' &&' at the end
2009 size_t k=j;
2010 while (k<len && data[k]==' ') k++;
2011 if (k<len-1 && data[k]=='&' && data[k+1]=='&') j=k+2;
2012 else if (k<len && data[k]=='&' ) j=k+1;
2013
2014 // do not include punctuation added by Definition::_setBriefDescription()
2015 size_t e=j;
2016 if (j>0 && data[j-1]=='.') { e--; }
2017 DString id(data+s,e-s);
2018 //printf("extractCopyDocId='%s' input='%s'\n",qPrint(id),&data[s]);
2019 return id;
2020}
2021
2022// macro to check if the input starts with a specific command.
2023// note that data[i] should point to the start of the command (\ or @ character)
2024// and the sizeof(str) returns the size of str including the '\0' terminator;
2025// a fact we abuse to skip over the start of the command character.
2026#define CHECK_FOR_COMMAND(str,action) \
2027 do if ((i+sizeof(str)<len) && literal_at(data+i+1,str)) \
2028 { j=i+sizeof(str); action; } while(0)
2029
2030static size_t isCopyBriefOrDetailsCmd(const char *data, size_t i,size_t len,bool &brief)
2031{
2032 size_t j=0;
2033 if (i==0 || (data[i-1]!='@' && data[i-1]!='\\')) // not an escaped command
2034 {
2035 CHECK_FOR_COMMAND("copybrief",brief=true); // @copybrief or \copybrief
2036 CHECK_FOR_COMMAND("copydetails",brief=false); // @copydetails or \copydetails
2037 }
2038 return j;
2039}
2040
2041static size_t isVerbatimSection(const char *data,size_t i,size_t len,DString &endMarker)
2042{
2043 size_t j=0;
2044 if (i==0 || (data[i-1]!='@' && data[i-1]!='\\')) // not an escaped command
2045 {
2046 CHECK_FOR_COMMAND("dot",endMarker="enddot");
2047 CHECK_FOR_COMMAND("icode",endMarker="endicode");
2048 CHECK_FOR_COMMAND("code",endMarker="endcode");
2049 CHECK_FOR_COMMAND("msc",endMarker="endmsc");
2050 CHECK_FOR_COMMAND("mermaid",endMarker="endmermaid");
2051 CHECK_FOR_COMMAND("iverbatim",endMarker="endiverbatim");
2052 CHECK_FOR_COMMAND("verbatim",endMarker="endverbatim");
2053 CHECK_FOR_COMMAND("iliteral",endMarker="endiliteral");
2054 CHECK_FOR_COMMAND("latexonly",endMarker="endlatexonly");
2055 CHECK_FOR_COMMAND("htmlonly",endMarker="endhtmlonly");
2056 CHECK_FOR_COMMAND("xmlonly",endMarker="endxmlonly");
2057 CHECK_FOR_COMMAND("rtfonly",endMarker="endrtfonly");
2058 CHECK_FOR_COMMAND("manonly",endMarker="endmanonly");
2059 CHECK_FOR_COMMAND("docbookonly",endMarker="enddocbookonly");
2060 CHECK_FOR_COMMAND("startuml",endMarker="enduml");
2061 }
2062 //printf("isVerbatimSection(%s)=%d)\n",qPrint(DString(&data[i]).left(10)),j);
2063 return j;
2064}
2065
2066static size_t skipToEndMarker(const char *data,size_t i,size_t len,const DString &endMarker)
2067{
2068 while (i<len)
2069 {
2070 if ((data[i]=='@' || data[i]=='\\') && // start of command character
2071 (i==0 || (data[i-1]!='@' && data[i-1]!='\\'))) // that is not escaped
2072 {
2073 if (i+endMarker.length()+1<=len && dstrncmp(data+i+1,endMarker.data(),endMarker.length())==0)
2074 {
2075 return i+endMarker.length()+1;
2076 }
2077 }
2078 i++;
2079 }
2080 // oops no endmarker found...
2081 return i<len ? i+1 : len;
2082}
2083
2084
2085DString DocParser::processCopyDoc(const char *data,size_t &len)
2086{
2087 AUTO_TRACE("data={} len={}",Trace::trunc(data),len);
2088 DString result;
2089 result.reserve(len+32);
2090 size_t i=0;
2091 int lineNr = tokenizer.getLineNr();
2092 while (i<len)
2093 {
2094 char c = data[i];
2095 if (c=='@' || c=='\\') // look for a command
2096 {
2097 bool isBrief=true;
2098 size_t j=isCopyBriefOrDetailsCmd(data,i,len,isBrief);
2099 if (j>0)
2100 {
2101 // skip whitespace
2102 while (j<len && (data[j]==' ' || data[j]=='\t')) j++;
2103 // extract the argument
2104 DString id = extractCopyDocId(data,j,len);
2105 const Definition *def = nullptr;
2106 DString doc,brief;
2107 //printf("resolving docs='%s'\n",qPrint(id));
2108 bool found = findDocsForMemberOrCompound(id,&doc,&brief,&def);
2109 if (found && def->isReference())
2110 {
2112 "@copy{} or @copydoc target '{}' found but is from a tag file, skipped",
2113 isBrief?"brief":"details", id);
2114 }
2115 else if (found)
2116 {
2117 //printf("found it def=%p brief='%s' doc='%s' isBrief=%d\n",def,qPrint(brief),qPrint(doc),isBrief);
2118 auto it = std::find(context.copyStack.begin(),context.copyStack.end(),def);
2119 if (it==context.copyStack.end()) // definition not parsed earlier
2120 {
2121 DString orgFileName = context.fileName;
2122 context.copyStack.push_back(def);
2123 auto addDocs = [&](const DString &file_,int line_,const DString &doc_)
2124 {
2125 result+=" \\ifile \""+file_+"\" ";
2126 result+="\\iline "+DString().setNum(line_)+" \\ilinebr ";
2127 size_t len_ = doc_.length();
2128 result+=processCopyDoc(doc_.data(),len_);
2129 };
2130 if (isBrief)
2131 {
2132 addDocs(def->briefFile(),def->briefLine(),brief);
2133 }
2134 else
2135 {
2136 addDocs(def->docFile(),def->docLine(),doc);
2138 {
2139 const MemberDef *md = toMemberDef(def);
2140 const ArgumentList &docArgList = md->templateMaster() ?
2141 md->templateMaster()->argumentList() :
2142 md->argumentList();
2143 result+=inlineArgListToDoc(docArgList);
2144 }
2145 }
2146 context.copyStack.pop_back();
2147 result+=" \\ilinebr \\ifile \""+context.fileName+"\" ";
2148 result+="\\iline "+DString().setNum(lineNr)+" ";
2149 }
2150 else
2151 {
2153 "Found recursive @copy{} or @copydoc relation for argument '{}'.",
2154 isBrief?"brief":"details",id);
2155 }
2156 }
2157 else
2158 {
2160 "@copy{} or @copydoc target '{}' not found", isBrief?"brief":"details",id);
2161 }
2162 // skip over command
2163 i=j;
2164 }
2165 else
2166 {
2167 DString endMarker;
2168 size_t k = isVerbatimSection(data,i,len,endMarker);
2169 if (k>0)
2170 {
2171 size_t orgPos = i;
2172 i=skipToEndMarker(data,k,len,endMarker);
2173 result+=DString(data+orgPos,i-orgPos);
2174 // TODO: adjust lineNr
2175 }
2176 else
2177 {
2178 result+=c;
2179 i++;
2180 }
2181 }
2182 }
2183 else // not a command, just copy
2184 {
2185 result+=c;
2186 i++;
2187 lineNr += (c=='\n') ? 1 : 0;
2188 }
2189 }
2190 len = result.length();
2191 AUTO_TRACE_EXIT("result={}",Trace::trunc(result));
2192 return result;
2193}
2194
2195
2196//---------------------------------------------------------------------------
2197
2199 const DString &fileName,
2200 int startLine,
2201 const Definition *ctx,
2202 const MemberDef *md,
2203 const DString &input,
2204 const DocOptions &options)
2205{
2206 DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);
2207 ASSERT(parser!=nullptr);
2208 if (parser==nullptr) return nullptr;
2209 //printf("validatingParseDoc(%s,%s)=[%s]\n",ctx?qPrint(ctx->name()):"<none>",
2210 // md?qPrint(md->name()):"<none>",
2211 // qPrint(input));
2212 //printf("========== validating %s at line %d\n",qPrint(fileName),startLine);
2213 //printf("---------------- input --------------------\n%s\n----------- end input -------------------\n",qPrint(input));
2214
2215 // set initial token
2216 parser->context.token = parser->tokenizer.resetToken();
2217
2218 if (ctx && ctx!=Doxygen::globalScope &&
2221 )
2222 )
2223 {
2225 }
2226 else if (ctx && ctx->definitionType()==Definition::TypePage)
2227 {
2228 const Definition *scope = (toPageDef(ctx))->getPageScope();
2229 if (scope && scope!=Doxygen::globalScope)
2230 {
2231 parser->context.context = substitute(scope->name(),getLanguageSpecificSeparator(scope->getLanguage(),true),"::");
2232 }
2233 }
2234 else if (ctx && ctx->definitionType()==Definition::TypeGroup)
2235 {
2236 const Definition *scope = (toGroupDef(ctx))->getGroupScope();
2237 if (scope && scope!=Doxygen::globalScope)
2238 {
2239 parser->context.context = substitute(scope->name(),getLanguageSpecificSeparator(scope->getLanguage(),true),"::");
2240 }
2241 }
2242 else
2243 {
2244 parser->context.context = "";
2245 }
2246 parser->context.scope = ctx;
2247 parser->context.lang = getLanguageFromFileName(fileName);
2248
2249 if (options.indexWords() && Doxygen::searchIndex.enabled())
2250 {
2251 if (md)
2252 {
2253 parser->context.searchUrl=md->getOutputFileBase();
2255 }
2256 else if (ctx)
2257 {
2258 parser->context.searchUrl=ctx->getOutputFileBase();
2259 Doxygen::searchIndex.setCurrentDoc(ctx,ctx->anchor(),false);
2260 }
2261 }
2262 else
2263 {
2264 parser->context.searchUrl="";
2265 }
2266
2267 parser->context.fileName = fileName;
2268 parser->context.relPath = (!options.linkFromIndex() && ctx) ?
2270 DString("");
2271 //printf("ctx->name=%s relPath=%s\n",qPrint(ctx->name()),qPrint(parser->context.relPath));
2272 parser->context.memberDef = md;
2273 while (!parser->context.nodeStack.empty()) parser->context.nodeStack.pop();
2274 while (!parser->context.styleStack.empty()) parser->context.styleStack.pop();
2275 while (!parser->context.initialStyleStack.empty()) parser->context.initialStyleStack.pop();
2276 parser->context.inSeeBlock = false;
2277 parser->context.inCodeStyle = false;
2278 parser->context.xmlComment = false;
2279 parser->context.insideHtmlLink = false;
2280 parser->context.includeFileText = "";
2281 parser->context.includeFileOffset = 0;
2282 parser->context.includeFileLength = 0;
2283 parser->context.isExample = options.isExample();
2284 parser->context.exampleName = options.exampleName();
2285 parser->context.hasParamCommand = false;
2286 parser->context.hasReturnCommand = false;
2287 parser->context.retvalsFound.clear();
2288 parser->context.paramsFound.clear();
2289 parser->context.markdownSupport = options.markdownSupport();
2290 parser->context.autolinkSupport = options.autolinkSupport();
2291 if (md)
2292 {
2293 const ArgumentList &al=md->isDocsForDefinition() ? md->argumentList() : md->declArgumentList();
2294 parser->context.numParameters = static_cast<int>(al.size());
2295 }
2296 else
2297 {
2298 parser->context.numParameters = 0;
2299 }
2300 parser->context.paramPosition = 1;
2301
2302 //printf("Starting comment block at %s:%d\n",qPrint(parser->context.fileName),startLine);
2303 parser->tokenizer.setFileName(fileName);
2304 parser->tokenizer.setLineNr(startLine);
2305 size_t ioLen = input.length();
2306 DString inpStr = parser->processCopyDoc(input.data(),ioLen);
2307 if (inpStr.empty() || inpStr.at(inpStr.length()-1)!='\n')
2308 {
2309 inpStr+='\n';
2310 }
2311 //printf("processCopyDoc(in='%s' out='%s')\n",qPrint(input),qPrint(inpStr));
2312 parser->tokenizer.init(inpStr.data(),parser->context.fileName,
2314
2315 // build abstract syntax tree
2316 auto ast = std::make_unique<DocNodeAST>(DocRoot(parser,md!=nullptr,options.singleLine()));
2317 std::get<DocRoot>(ast->root).parse();
2318
2320 {
2321 // pretty print the result
2322 std::visit(PrintDocVisitor{},ast->root);
2323 }
2324
2325 if (md && md->isFunction())
2326 {
2328 }
2330
2331 // reset token
2332 parser->tokenizer.resetToken();
2333
2334 //printf(">>>>>> end validatingParseDoc(%s,%s)\n",ctx?qPrint(ctx->name()):"<none>",
2335 // md?qPrint(md->name()):"<none>");
2336
2337 return ast;
2338}
2339
2340IDocNodeASTPtr validatingParseTitle(IDocParser &parserIntf,const DString &fileName,int lineNr,const DString &input)
2341{
2342 DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);
2343 ASSERT(parser!=nullptr);
2344 if (parser==nullptr) return nullptr;
2345
2346 // set initial token
2347 parser->context.token = parser->tokenizer.resetToken();
2348
2349 //printf("------------ input ---------\n%s\n"
2350 // "------------ end input -----\n",input);
2351 parser->context.context = "";
2352 parser->context.fileName = fileName;
2353 parser->context.relPath = "";
2354 parser->context.memberDef = nullptr;
2355 while (!parser->context.nodeStack.empty()) parser->context.nodeStack.pop();
2356 while (!parser->context.styleStack.empty()) parser->context.styleStack.pop();
2357 while (!parser->context.initialStyleStack.empty()) parser->context.initialStyleStack.pop();
2358 parser->context.inSeeBlock = false;
2359 parser->context.inCodeStyle = false;
2360 parser->context.xmlComment = false;
2361 parser->context.insideHtmlLink = false;
2362 parser->context.includeFileText = "";
2363 parser->context.includeFileOffset = 0;
2364 parser->context.includeFileLength = 0;
2365 parser->context.isExample = false;
2366 parser->context.exampleName = "";
2367 parser->context.hasParamCommand = false;
2368 parser->context.hasReturnCommand = false;
2369 parser->context.retvalsFound.clear();
2370 parser->context.paramsFound.clear();
2371 parser->context.searchUrl="";
2372 parser->context.lang = SrcLangExt::Unknown;
2373 parser->context.markdownSupport = Config_getBool(MARKDOWN_SUPPORT);
2374 parser->context.autolinkSupport = false;
2375
2376 auto ast = std::make_unique<DocNodeAST>(DocTitle(parser,nullptr));
2377
2378 if (!input.empty())
2379 {
2380 // build abstract syntax tree from title string
2381 std::get<DocTitle>(ast->root).parseFromString(nullptr,input);
2382
2384 {
2385 // pretty print the result
2386 std::visit(PrintDocVisitor{},ast->root);
2387 }
2388 }
2389
2390 return ast;
2391}
2392
2394{
2395 DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);
2396 ASSERT(parser!=nullptr);
2397 if (parser==nullptr) return nullptr;
2398
2399 // set initial token
2400 parser->context.token = parser->tokenizer.resetToken();
2401
2402 //printf("------------ input ---------\n%s\n"
2403 // "------------ end input -----\n",input);
2404 //parser->context.token = new TokenInfo;
2405 parser->context.context = "";
2406 parser->context.fileName = "<parseText>";
2407 parser->context.relPath = "";
2408 parser->context.memberDef = nullptr;
2409 while (!parser->context.nodeStack.empty()) parser->context.nodeStack.pop();
2410 while (!parser->context.styleStack.empty()) parser->context.styleStack.pop();
2411 while (!parser->context.initialStyleStack.empty()) parser->context.initialStyleStack.pop();
2412 parser->context.inSeeBlock = false;
2413 parser->context.inCodeStyle = false;
2414 parser->context.xmlComment = false;
2415 parser->context.insideHtmlLink = false;
2416 parser->context.includeFileText = "";
2417 parser->context.includeFileOffset = 0;
2418 parser->context.includeFileLength = 0;
2419 parser->context.isExample = false;
2420 parser->context.exampleName = "";
2421 parser->context.hasParamCommand = false;
2422 parser->context.hasReturnCommand = false;
2423 parser->context.retvalsFound.clear();
2424 parser->context.paramsFound.clear();
2425 parser->context.searchUrl="";
2426 parser->context.lang = SrcLangExt::Unknown;
2427 parser->context.markdownSupport = Config_getBool(MARKDOWN_SUPPORT);
2428 parser->context.autolinkSupport = false;
2429
2430
2431 auto ast = std::make_unique<DocNodeAST>(DocText(parser));
2432
2433 if (!input.empty())
2434 {
2435 parser->tokenizer.setLineNr(1);
2436 parser->tokenizer.init(input.data(),parser->context.fileName,
2438
2439 // build abstract syntax tree
2440 std::get<DocText>(ast->root).parse();
2441
2443 {
2444 // pretty print the result
2445 std::visit(PrintDocVisitor{},ast->root);
2446 }
2447 }
2448
2449 return ast;
2450}
2451
2452IDocNodeASTPtr createRef(IDocParser &parserIntf,const DString &target,const DString &context, const DString &srcFile, int srcLine )
2453{
2454 DocParser *parser = dynamic_cast<DocParser*>(&parserIntf);
2455 ASSERT(parser!=nullptr);
2456 if (parser==nullptr) return nullptr;
2457 if (!srcFile.empty())
2458 {
2459 parser->context.fileName = srcFile;
2460 parser->tokenizer.setFileName(srcFile);
2461 parser->tokenizer.setLineNr(srcLine);
2462 }
2463 return std::make_unique<DocNodeAST>(DocRef(parser,nullptr,target,context));
2464}
2465
2466void docFindSections(const DString &input,
2467 const Definition *d,
2468 const DString &fileName)
2469{
2470 DocParser parser;
2471 parser.tokenizer.findSections(input,d,fileName);
2472}
2473
2474//--------------------------------------------------------------------------------------
2475
2476static int nextUTF8CharPosition(const DString &utf8Str,uint32_t len,uint32_t startPos)
2477{
2478 if (startPos>=len) return len;
2479 uint8_t c = static_cast<uint8_t>(utf8Str[startPos]);
2480 int bytes=getUTF8CharNumBytes(c);
2481 if (c=='&') // skip over character entities
2482 {
2483 bytes=1;
2484 int (*matcher)(int) = nullptr;
2485 c = static_cast<uint8_t>(utf8Str[startPos+bytes]);
2486 if (c=='#') // numerical entity?
2487 {
2488 bytes++;
2489 c = static_cast<uint8_t>(utf8Str[startPos+bytes]);
2490 if (c=='x') // hexadecimal entity?
2491 {
2492 bytes++;
2493 matcher = std::isxdigit;
2494 }
2495 else // decimal entity
2496 {
2497 matcher = std::isdigit;
2498 }
2499 }
2500 else if (std::isalnum(c)) // named entity?
2501 {
2502 bytes++;
2503 matcher = std::isalnum;
2504 }
2505 if (matcher)
2506 {
2507 while ((c = static_cast<uint8_t>(utf8Str[startPos+bytes]))!=0 && matcher(c))
2508 {
2509 bytes++;
2510 }
2511 }
2512 if (c!=';')
2513 {
2514 bytes=1; // not a valid entity, reset bytes counter
2515 }
2516 }
2517 return startPos+bytes;
2518}
2519
2520
2522 const DString &doc,const DString &fileName,int lineNr)
2523{
2524 if (doc.empty()) return "";
2525 static std::mutex s_docCacheMutex;
2526 static std::unordered_map<std::string,DString> s_docCache;
2527
2528 std::lock_guard lock(s_docCacheMutex);
2529 auto it = s_docCache.find(doc.str());
2530 if (it != s_docCache.end())
2531 {
2532 //printf("Cache: [%s]->[%s]\n",qPrint(doc),qPrint(it->second));
2533 return it->second;
2534 }
2535 //printf("parseCommentAsText(%s)\n",qPrint(doc));
2536 TextStream t;
2537 auto parser { createDocParser() };
2538 auto ast { validatingParseDoc(*parser.get(),
2539 fileName,
2540 lineNr,
2541 scope,
2542 md,
2543 doc,
2544 DocOptions()
2545 .setAutolinkSupport(false))
2546 };
2547 auto astImpl = dynamic_cast<const DocNodeAST*>(ast.get());
2548 if (astImpl)
2549 {
2550 TextDocVisitor visitor(t);
2551 std::visit(visitor,astImpl->root);
2552 }
2554 int i=0;
2555 int charCnt=0;
2556 int l=static_cast<int>(result.length());
2557 while ((i=nextUTF8CharPosition(result,l,i))<l)
2558 {
2559 charCnt++;
2560 if (charCnt>=80) break;
2561 }
2562 if (charCnt>=80) // try to truncate the string
2563 {
2564 while ((i=nextUTF8CharPosition(result,l,i))<l && charCnt<100)
2565 {
2566 charCnt++;
2567 if (result.at(i)==',' ||
2568 result.at(i)=='.' ||
2569 result.at(i)=='!' ||
2570 result.at(i)=='?' ||
2571 result.at(i)=='}') // good for UTF-16 characters and } otherwise also a good point to stop the string
2572 {
2573 i++; // we want to be "behind" last inspected character
2574 break;
2575 }
2576 }
2577 }
2578 if ( i < l) result=result.left(i)+"...";
2579 s_docCache.insert(std::make_pair(doc.str(),result));
2580 return result.data();
2581}
2582
2583//--------------------------------------------------------------------------------------
2584
2586 const DString &doc,const DString &fileName,int lineNr)
2587{
2588 static std::mutex s_docCacheMutex;
2589 static std::unordered_map<std::string,DString> s_docCache;
2590
2591 std::lock_guard lock(s_docCacheMutex);
2592 auto it = s_docCache.find(doc.str());
2593 if (it != s_docCache.end())
2594 {
2595 //printf("Cache: [%s]->[%s]\n",qPrint(doc),qPrint(it->second));
2596 return it->second;
2597 }
2598 auto parser { createDocParser() };
2599 auto ast { validatingParseTitle(*parser.get(),fileName,lineNr,doc) };
2600 auto astImpl = dynamic_cast<const DocNodeAST*>(ast.get());
2601 DString result;
2602 if (astImpl)
2603 {
2604 TextStream t;
2605 OutputCodeList codeList;
2606 codeList.add<HtmlCodeGenerator>(&t);
2607 HtmlDocVisitor visitor(t,codeList,scope,fileName);
2608 std::visit(visitor,astImpl->root);
2609 result = t.str();
2610 }
2611 else // fallback, should not happen
2612 {
2613 result = filterTitle(doc);
2614 }
2615 //printf("Conversion: [%s]->[%s]\n",qPrint(doc),qPrint(result));
2616 s_docCache.insert(std::make_pair(doc.str(),result));
2617 return result;
2618}
2619
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:320
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:132
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:160
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:81
bool exists() const
Definition fileinfo.cpp:34
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:239
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:181
#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:1973
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)
split input string s by string delimiter delimiter.
Definition stringutil.h:117
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
bool checkCV
Definition util.h:87
const MemberDef * md
Definition util.h:95
bool found
Definition util.h:94
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:4865
DString filterTitle(const DString &title)
Definition util.cpp:4454
DString detab(const DString &s, size_t &refIndent)
Definition util.cpp:5179
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:2008
DString removeRedundantWhiteSpace(const DString &s)
Definition util.cpp:426
DString convertNameToFile(const DString &name, bool allowDots, bool allowUnderscore)
Definition util.cpp:2863
SrcLangExt getLanguageFromFileName(const DString &fileName, SrcLangExt defLang)
Definition util.cpp:4168
DString fileToString(const DString &name, bool filter, bool isSourceCode)
Definition util.cpp:1053
DString linkToText(SrcLangExt lang, const DString &link, bool ignoreDots)
Definition util.cpp:2265
DString relativePathToRoot(const DString &name)
Definition util.cpp:2912
DString argListToString(const ArgumentList &al, bool useCanonicalType, bool showDefVals)
Definition util.cpp:859
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:4619
DString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Definition util.cpp:4629
GetDefResult getDefs(const GetDefInput &input)
Definition util.cpp:1866
DString findExampleFilePath(const DString &file, bool &ambig)
Definition util.cpp:2451
A bunch of utility functions.