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