Doxygen
Loading...
Searching...
No Matches
util.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 *
3 * Copyright (C) 1997-2026 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15
16// own include
17#include "util.h"
18
19// std includes (sorted)
20#include <algorithm>
21#include <cctype>
22#include <cinttypes>
23#include <cstdlib>
24#include <cstring>
25#include <ctime>
26#include <mutex>
27#include <unordered_set>
28
29// other includes (sorted)
30#include "arguments.h"
31#include "classdef.h"
32#include "classlist.h"
33#include "conceptdef.h"
34#include "config.h"
35#include "datetime.h"
36#include "debug.h"
37#include "defargs.h"
38#include "dir.h"
39#include "dirdef.h"
40#include "doxygen.h"
41#include "example.h"
42#include "filedef.h"
43#include "fileinfo.h"
44#include "filename.h"
45#include "groupdef.h"
46#include "htmlentity.h"
47#include "image.h"
48#include "language.h"
49#include "md5hash.h"
50#include "membername.h"
51#include "message.h"
52#include "moduledef.h"
53#include "namespacedef.h"
54#include "outputlist.h"
55#include "pagedef.h"
56#include "parserintf.h"
57#include "portable.h"
58#include "regex.h"
59#include "stringutil.h"
60#include "symbolresolver.h"
61#include "textstream.h"
62#include "trace.h"
63#include "utf8.h"
64
65#define ENABLE_TRACINGSUPPORT 0
66
67#if defined(__APPLE__) && ENABLE_TRACINGSUPPORT
68#define TRACINGSUPPORT
69#endif
70
71#ifdef TRACINGSUPPORT
72#include <execinfo.h>
73#include <unistd.h>
74#endif
75
76//------------------------------------------------------------------------
77
78#define REL_PATH_TO_ROOT "../../"
79
80static const char *hex = "0123456789ABCDEF";
81
82//------------------------------------------------------------------------
83
84/*!
85 Removes all anonymous scopes from string s
86 Possible examples:
87\verbatim
88 "bla::@10::blep" => "bla::blep"
89 "bla::@10::@11::blep" => "bla::blep"
90 "@10::blep" => "blep"
91 " @10::blep" => "blep"
92 "@9::@10::blep" => "blep"
93 "bla::@1" => "bla"
94 "bla::@1::@2" => "bla"
95 "bla @1" => "bla"
96\endverbatim
97 */
99{
100 std::string result;
101 if (str.empty()) return result;
102
103 // helper to check if the found delimiter starts with a colon
104 auto startsWithColon = [](const std::string &del)
105 {
106 for (size_t i=0;i<del.size();i++)
107 {
108 if (del[i]=='@') return false;
109 else if (del[i]==':') return true;
110 }
111 return false;
112 };
113
114 // helper to check if the found delimiter ends with a colon
115 auto endsWithColon = [](const std::string &del)
116 {
117 for (int i=static_cast<int>(del.size())-1;i>=0;i--)
118 {
119 if (del[i]=='@') return false;
120 else if (del[i]==':') return true;
121 }
122 return false;
123 };
124
125 static const reg::Ex re(R"([\s:]*@\d+[\s:]*)");
126 std::string s = str.str();
127 reg::Iterator iter(s,re);
129 size_t p=0;
130 size_t sl=s.length();
131 bool needsSeparator=false;
132 for ( ; iter!=end ; ++iter)
133 {
134 const auto &match = *iter;
135 size_t i = match.position();
136 if (i>p) // add non-matching prefix
137 {
138 if (needsSeparator) result+="::";
139 needsSeparator=false;
140 result+=s.substr(p,i-p);
141 }
142 std::string delim = match.str();
143 needsSeparator = needsSeparator || (startsWithColon(delim) && endsWithColon(delim));
144 p = match.position()+match.length();
145 }
146 if (p<sl) // add trailing remainder
147 {
148 if (needsSeparator) result+="::";
149 result+=s.substr(p);
150 }
151 return result;
152}
153
154// replace anonymous scopes with __anonymous__ or replacement if provided
155DString replaceAnonymousScopes(const DString &s,const DString &replacement)
156{
157 if (s.empty()) return s;
158 static const reg::Ex marker(R"(@\d+)");
159 std::string result = reg::replace(s.str(),marker,
160 !replacement.empty() ? replacement.data() : "__anonymous__");
161 //printf("replaceAnonymousScopes('%s')='%s'\n",qPrint(s),qPrint(result));
162 return result;
163}
164
165
166// strip anonymous left hand side part of the scope
168{
169 int i=0,p=0,l=0;
170 DString newScope;
171 int sl = static_cast<int>(s.length());
172 while ((i=getScopeFragment(s,p,&l))!=-1)
173 {
174 //printf("Scope fragment %s\n",qPrint(s.mid(i,l)));
175 if (Doxygen::namespaceLinkedMap->find(s.left(i+l))!=nullptr)
176 {
177 if (s.at(i)!='@')
178 {
179 if (!newScope.empty()) newScope+="::";
180 newScope+=s.mid(i,l);
181 }
182 }
183 else if (i<sl)
184 {
185 if (!newScope.empty()) newScope+="::";
186 newScope+=s.right(sl-i);
187 goto done;
188 }
189 p=i+l;
190 }
191done:
192 //printf("stripAnonymousNamespaceScope('%s')='%s'\n",qPrint(s),qPrint(newScope));
193 return newScope;
194}
195
196static inline DString stripFromPath(const DString &p,StringVector l)
197{
198 // look at all the strings in the list and strip the longest match
199 DString potential;
201 size_t length = 0;
202 for (const auto &s : l)
203 {
204 DString prefix = s;
205 if (prefix.length() > length &&
206 dstricmp(path.left(prefix.length()),prefix)==0) // case insensitive compare
207 {
208 length = prefix.length();
209 potential = path.mid(prefix.length());
210 }
211 }
212 if (length>0) return potential;
213 return path;
214}
215
216/*! strip part of \a path if it matches
217 * one of the paths in the Config_getList(STRIP_FROM_PATH) list
218 */
220{
221 return stripFromPath(path,Config_getList(STRIP_FROM_PATH));
222}
223
224/*! strip part of \a path if it matches
225 * one of the paths in the Config_getList(INCLUDE_PATH) list
226 */
228{
229 return stripFromPath(path,Config_getList(STRIP_FROM_INC_PATH));
230}
231
232DString resolveTypeDef(const Definition *context,const DString &qualifiedName,
233 const Definition **typedefContext)
234{
235 AUTO_TRACE("context='{}' qualifiedName='{}'",context?context->name():"",qualifiedName);
236 DString result;
237 if (qualifiedName.empty())
238 {
239 AUTO_TRACE_EXIT("empty name");
240 return result;
241 }
242
243 const Definition *mContext=context;
244 if (typedefContext) *typedefContext=context;
245
246 // see if the qualified name has a scope part
247 if (qualifiedName.find('<')!=DString::npos)
248 {
249 AUTO_TRACE_EXIT("template");
250 return result;
251 }
252 size_t scopeIndex = qualifiedName.rfind("::");
253 DString resName=qualifiedName;
254 if (scopeIndex!=DString::npos) // strip scope part for the name
255 {
256 resName=qualifiedName.mid(scopeIndex+2);
257 if (resName.empty())
258 {
259 AUTO_TRACE_EXIT("invalid format");
260 return result;
261 }
262 }
263 const MemberDef *md=nullptr;
264 while (mContext && md==nullptr)
265 {
266 // step 1: get the right scope
267 const Definition *resScope=mContext;
268 if (scopeIndex!=DString::npos)
269 {
270 // split-off scope part
271 DString resScopeName = qualifiedName.left(scopeIndex);
272 //printf("resScopeName='%s'\n",qPrint(resScopeName));
273
274 // look-up scope in context
275 int is=0,ps=0,l=0;
276 while ((is=getScopeFragment(resScopeName,ps,&l))!=-1)
277 {
278 DString qualScopePart = resScopeName.mid(is,l);
279 DString tmp = resolveTypeDef(mContext,qualScopePart);
280 if (!tmp.empty()) qualScopePart=tmp;
281 resScope = resScope->findInnerCompound(qualScopePart);
282 //printf("qualScopePart='%s' resScope=%p\n",qPrint(qualScopePart),resScope);
283 if (resScope==nullptr) break;
284 ps=is+l;
285 }
286 }
287 AUTO_TRACE_ADD("resScope='{}' resName='{}'",resScope?resScope->name():"",resName);
288
289 // step 2: get the member
290 if (resScope) // no scope or scope found in the current context
291 {
292 //printf("scope found: %s, look for typedef %s\n",
293 // qPrint(resScope->qualifiedName()),qPrint(resName));
294 MemberNameLinkedMap *mnd=nullptr;
295 bool searchRelated=false;
296 bool mustBeRelated=false;
297 if (resScope->definitionType()==Definition::TypeClass)
298 {
300 }
301 else
302 {
304 searchRelated=true;
305 }
306 MemberName *mn=mnd->find(resName);
307 if (mn==0 && searchRelated)
308 {
310 mustBeRelated=true;
311 }
312 if (mn)
313 {
314 int minDist=-1;
315 for (const auto &tmd_p : *mn)
316 {
317 const MemberDef *tmd = tmd_p.get();
318 AUTO_TRACE_ADD("found candidate member '{}' isTypeDef={}' isRelated={} mustBeRelated={}",
319 tmd->name(),tmd->isTypedef(),tmd->isRelated(),mustBeRelated);
320 //printf("Found member %s resScope=%s outerScope=%s mContext=%p\n",
321 // qPrint(tmd->name()),qPrint( resScope->name()),
322 // qPrint(tmd->getOuterScope()->name()), mContext);
323 if (tmd->isTypedef())
324 {
325 if (resScope==Doxygen::globalScope && tmd->isRelated() && mustBeRelated)
326 {
327 md = tmd;
328 }
329 else
330 {
331 SymbolResolver resolver;
332 int dist=resolver.isAccessibleFrom(resScope,tmd);
333 if (dist!=-1 && (md==nullptr || dist<minDist))
334 {
335 md = tmd;
336 minDist = dist;
337 }
338 }
339 }
340 }
341 }
342 }
343 mContext=mContext->getOuterScope();
344 }
345
346 AUTO_TRACE_ADD("md='{}'",md?md->name():"");
347 // step 3: get the member's type
348 if (md)
349 {
350 //printf(">>resolveTypeDef: Found typedef name '%s' in scope '%s' value='%s' args='%s'\n",
351 // qPrint(qualifiedName),qPrint(context->name()),qPrint(md->typeString()),qPrint(md->argsString())
352 // );
353 result=md->typeString();
354 DString args = md->argsString();
355 if (args.find(")(")!=DString::npos) // typedef of a function/member pointer
356 {
357 result+=args;
358 }
359 else if (args.find('[')!=DString::npos) // typedef of an array
360 {
361 result+=args;
362 }
363 if (typedefContext) *typedefContext=md->getOuterScope();
364 }
365 else
366 {
367 //printf(">>resolveTypeDef: Typedef '%s' not found in scope '%s'!\n",
368 // qPrint(qualifiedName),context ? qPrint(context->name()) : "<global>");
369 }
370 AUTO_TRACE_EXIT("result='{}'",result);
371 return result;
372}
373
374//-------------------------------------------------------------------------
375//-------------------------------------------------------------------------
376//-------------------------------------------------------------------------
377//-------------------------------------------------------------------------
378
379static const char constScope[] = { 'c', 'o', 'n', 's', 't', ':' };
380static const char volatileScope[] = { 'v', 'o', 'l', 'a', 't', 'i', 'l', 'e', ':' };
381static const char virtualScope[] = { 'v', 'i', 'r', 't', 'u', 'a', 'l', ':' };
382static const char operatorScope[] = { 'o', 'p', 'e', 'r', 'a', 't', 'o', 'r', '?', '?', '?' };
383static const char staticScope[] = { 's', 't', 'a', 't', 'i', 'c', ' ' };
384
386{
388 {
389 charMap[static_cast<int>('(')].before=false;
390 charMap[static_cast<int>('=')].before=false;
391 charMap[static_cast<int>('&')].before=false;
392 charMap[static_cast<int>('*')].before=false;
393 charMap[static_cast<int>('[')].before=false;
394 charMap[static_cast<int>('|')].before=false;
395 charMap[static_cast<int>('+')].before=false;
396 charMap[static_cast<int>(';')].before=false;
397 charMap[static_cast<int>(':')].before=false;
398 charMap[static_cast<int>('/')].before=false;
399
400 charMap[static_cast<int>('=')].after=false;
401 charMap[static_cast<int>(' ')].after=false;
402 charMap[static_cast<int>('[')].after=false;
403 charMap[static_cast<int>(']')].after=false;
404 charMap[static_cast<int>('\t')].after=false;
405 charMap[static_cast<int>('\n')].after=false;
406 charMap[static_cast<int>(')')].after=false;
407 charMap[static_cast<int>(',')].after=false;
408 charMap[static_cast<int>('<')].after=false;
409 charMap[static_cast<int>('|')].after=false;
410 charMap[static_cast<int>('+')].after=false;
411 charMap[static_cast<int>('(')].after=false;
412 charMap[static_cast<int>('/')].after=false;
413 }
414 struct CharElem
415 {
416 CharElem() : before(true), after(true) {}
417 bool before;
418 bool after;
419 };
420
422};
423
425
426// Note: this function is not reentrant due to the use of static buffer!
428{
429 bool cliSupport = Config_getBool(CPP_CLI_SUPPORT);
430 bool vhdl = Config_getBool(OPTIMIZE_OUTPUT_VHDL);
431
432 if (s.empty() || vhdl) return s;
433
434 // We use a static character array to
435 // improve the performance of this function
436 // and thread_local is needed to make it multi-thread safe
437 static THREAD_LOCAL std::vector<char> growBuf;
438 if (s.length()*3+1 > growBuf.size()) // For input character we produce at most 3 output characters,
439 {
440 growBuf.resize(s.length()*3+1); // add 1 for 0-terminator
441 }
442
443 const char *src=s.data();
444 char *dst=growBuf.data();
445
446 size_t i=0;
447 size_t l=s.length();
448 size_t csp=0;
449 size_t vosp=0;
450 size_t vsp=0;
451 size_t osp=0;
452 size_t ssp=0;
453 char pc=0;
454 // skip leading whitespace
455 while (i<l && isspace(static_cast<uint8_t>(src[i])))
456 {
457 i++;
458 }
459 for (;i<l;i++)
460 {
461 char c=src[i];
462 char nc=i+1<l ? src[i+1] : ' ';
463
464 auto searchForKeyword = [&](const char *kw,size_t &matchLen,size_t totalLen)
465 {
466 if (matchLen<=totalLen && c==kw[matchLen] && // character matches substring kw
467 (matchLen>0 || // inside search string
468 i==0 || // if it is the first character
469 !isId(pc) // the previous may not be a digit
470 )
471 )
472 matchLen++;
473 else // reset counter
474 matchLen=0;
475 };
476 searchForKeyword(constScope, csp, 5); // keyword: const
477 searchForKeyword(volatileScope, vosp, 8); // keyword: volatile
478 searchForKeyword(virtualScope, vsp, 7); // keyword: virtual
479 searchForKeyword(staticScope, ssp, 6); // keyword: static
480
481 // search for "operator"
482 if (osp<11 && (osp>=8 || c==operatorScope[osp]) && // character matches substring "operator" followed by 3 arbitrary characters
483 (osp>0 || // inside search string
484 i==0 || // if it is the first character
485 !isId(pc) // the previous may not be a digit
486 )
487 )
488 osp++;
489 else // reset counter
490 osp=0;
491
492 switch(c)
493 {
494 case '"': // quoted string
495 {
496 *dst++=c;
497 i++;
498 for (;i<l;i++) // find end of string
499 {
500 c = src[i];
501 *dst++=c;
502 if (c=='\\' && i+1<l)
503 {
504 i++;
505 c = src[i];
506 *dst++=c;
507 }
508 else if (c=='"')
509 {
510 break;
511 }
512 }
513 }
514 break;
515 case '<': // current char is a <
516 *dst++=c;
517 if (i+1<l &&
518 (isId(nc)) && // next char is an id char
519 (osp<8) // string in front is not "operator"
520 )
521 {
522 *dst++=' '; // add extra space
523 }
524 break;
525 case '>': // current char is a >
526 if (i>0 && !isspace(static_cast<uint8_t>(pc)) &&
527 (isId(pc) || pc=='*' || pc=='&' || pc=='.' || pc=='>') && // prev char is an id char or space or *&.
528 (osp<8 || (osp==8 && pc!='-')) // string in front is not "operator>" or "operator->"
529 )
530 {
531 *dst++=' '; // add extra space in front
532 }
533 *dst++=c;
534 if (i+1<l && (nc=='-' || nc=='&')) // '>-' -> '> -'
535 {
536 *dst++=' '; // add extra space after
537 }
538 break;
539 case ',': // current char is a ,
540 *dst++=c;
541 if (i>0 && !isspace(static_cast<uint8_t>(pc)) &&
542 ((i+1<l && (isId(nc) || nc=='[')) || // the [ is for attributes (see bug702170)
543 (i+2<l && nc=='$' && isId(src[i+2])) || // for PHP: ',$name' -> ', $name'
544 (i+3<l && nc=='&' && src[i+2]=='$' && isId(src[i+3])) // for PHP: ',&$name' -> ', &$name'
545 )
546 )
547 {
548 *dst++=' '; // add extra space after
549 }
550 break;
551 case '^': // CLI 'Type^name' -> 'Type^ name'
552 case '%': // CLI 'Type%name' -> 'Type% name'
553 *dst++=c;
554 if (cliSupport && i+1<l && (isId(nc) || nc=='-'))
555 {
556 *dst++=' '; // add extra space after
557 }
558 break;
559 case ')': // current char is a ) -> ')name' -> ') name'
560 *dst++=c;
561 if (i+1<l && (isId(nc) || nc=='-'))
562 {
563 *dst++=' '; // add extra space after
564 }
565 break;
566 case '*':
567 if (i>0 && pc!=' ' && pc!='\t' && pc!=':' &&
568 pc!='*' && pc!='&' && pc!='(' && pc!='/' && pc!='[' &&
569 pc!='.' && osp<9
570 )
571 // avoid splitting &&, **, .*, operator*, operator->*
572 {
573 *dst++=' ';
574 }
575 *dst++=c;
576 break;
577 case '&':
578 if (i>0 && isId(pc) && osp<9)
579 {
580 if (nc != '=')
581 // avoid splitting operator&=
582 {
583 *dst++=' ';
584 }
585 }
586 *dst++=c;
587 break;
588 case '$': // '$name' -> ' $name'
589 // 'name$name' -> 'name$name'
590 if (isId(pc))
591 {
592 *dst++=c;
593 break;
594 }
595 // else fallthrough
596 case '@': // '@name' -> ' @name'
597 case '\'': // ''name' -> '' name'
598 if (i>0 && i+1<l && pc!='=' && pc!=':' && !isspace(static_cast<uint8_t>(pc)) &&
599 isId(nc) && osp<8) // ")id" -> ") id"
600 {
601 *dst++=' ';
602 }
603 *dst++=c;
604 break;
605 case ':': // current char is a :
606 if (csp==6) // replace const::A by const ::A
607 {
608 *dst++=' ';
609 csp=0;
610 }
611 else if (vosp==9) // replace volatile::A by volatile ::A
612 {
613 *dst++=' ';
614 vosp=0;
615 }
616 else if (vsp==8) // replace virtual::A by virtual ::A
617 {
618 *dst++=' ';
619 vsp=0;
620 }
621 *dst++=c;
622 break;
623 case ' ': // fallthrough
624 case '\n': // fallthrough
625 case '\t':
626 {
627 if (g_charAroundSpace.charMap[static_cast<uint8_t>(pc)].before &&
628 g_charAroundSpace.charMap[static_cast<uint8_t>(nc)].after &&
629 !(pc==',' && nc=='.') &&
630 (osp<8 || (osp>=8 && isId(pc) && isId(nc)))
631 // e.g. 'operator >>' -> 'operator>>',
632 // 'operator "" _x' -> 'operator""_x',
633 // but not 'operator int' -> 'operatorint'
634 )
635 { // keep space
636 *dst++=' ';
637 }
638 else if (ssp==7 && nc=='(') // keep space for 'static ('
639 {
640 *dst++=' ';
641 ssp=0;
642 }
643 else if ((pc=='*' || pc=='&' || pc=='.') && nc=='>')
644 {
645 *dst++=' ';
646 }
647 }
648 break;
649 default:
650 *dst++=c;
651 auto correctKeywordAllowedInsideScope = [&](char cc,size_t &matchLen,size_t totalLen) {
652 if (c==cc && matchLen==totalLen)
653 {
654 if ((i+2<l && src[i+1] == ':' && src[i+2] == ':') || // keyword::
655 ((i>matchLen && src[i-matchLen] == ':' && src[i-matchLen-1] == ':')) // ::keyword
656 ) matchLen = 0;
657 };
658 };
659 correctKeywordAllowedInsideScope('t',csp, 5); // keyword: const
660 correctKeywordAllowedInsideScope('e',vosp,8); // keyword: volatile
661 correctKeywordAllowedInsideScope('l',vsp, 7); // keyword: virtual
662
663 auto correctKeywordNotPartOfScope = [&](char cc,size_t &matchLen,size_t totalLen)
664 {
665 if (c==cc && matchLen==totalLen && i+1<l && // found matching keyword
666 !(isId(nc) || nc==')' || nc==',' || disspace(nc))
667 ) // prevent keyword ::A from being converted to keyword::A
668 {
669 *dst++=' ';
670 matchLen=0;
671 }
672 };
673 correctKeywordNotPartOfScope('t',csp, 5); // keyword: const
674 correctKeywordNotPartOfScope('e',vosp,8); // keyword: volatile
675 correctKeywordNotPartOfScope('l',vsp, 7); // keyword: virtual
676 break;
677 }
678 pc=c;
679 }
680 *dst++='\0';
681 //printf("removeRedundantWhitespace(%s)->%s\n",qPrint(s),growBuf.data());
682 return growBuf.data();
683}
684
685/**
686 * Returns the position in the string where a function parameter list
687 * begins, or DString::npos if one is not found.
688 */
689static size_t findParameterList(const DString &name)
690{
691 size_t pos=DString::npos;
692 int templateDepth=0;
693 do
694 {
695 if (templateDepth > 0)
696 {
697 size_t nextOpenPos = name.rfind('>', pos);
698 size_t nextClosePos = name.rfind('<', pos);
699 if (nextOpenPos!=DString::npos && nextClosePos!=DString::npos && nextOpenPos>nextClosePos)
700 {
701 ++templateDepth;
702 pos=nextOpenPos-1;
703 }
704 else if (nextClosePos!=DString::npos)
705 {
706 --templateDepth;
707 pos=nextClosePos-1;
708 }
709 else // more >'s than <'s, see bug701295
710 {
711 return -1;
712 }
713 }
714 else
715 {
716 size_t lastAnglePos = name.rfind('>', pos);
717 size_t bracePos = name.rfind('(', pos);
718 if (lastAnglePos!=DString::npos && bracePos!=DString::npos && lastAnglePos>bracePos)
719 {
720 ++templateDepth;
721 pos=lastAnglePos-1;
722 }
723 else
724 {
725 size_t bp = bracePos>0 ? name.rfind('(',bracePos-1) : DString::npos;
726 // bp test is to allow foo(int(&)[10]), but we need to make an exception for operator()
727 return bp==DString::npos || (bp>=8 && name.mid(bp-8,10)=="operator()") ? bracePos : bp;
728 }
729 }
730 } while (pos!=DString::npos);
731 return DString::npos;
732}
733
734bool rightScopeMatch(const DString &scope, const DString &name)
735{
736 size_t sl=scope.length();
737 size_t nl=name.length();
738 return (name==scope || // equal
739 (scope.right(nl)==name && // substring
740 sl>1+nl && scope.at(sl-nl-1)==':' && scope.at(sl-nl-2)==':' // scope
741 )
742 );
743}
744
745bool leftScopeMatch(const DString &scope, const DString &name)
746{
747 size_t sl=scope.length();
748 size_t nl=name.length();
749 return (name==scope || // equal
750 (name.left(sl)==scope && // substring
751 nl>sl+1 && name.at(sl)==':' && name.at(sl+1)==':' // scope
752 )
753 );
754}
755
756
757
758void writeMarkerList(OutputList &ol,const std::string &markerText,size_t numMarkers,
759 std::function<void(size_t)> replaceFunc)
760{
761 static const reg::Ex marker(R"(@(\d+))");
762 reg::Iterator it(markerText,marker);
764 size_t index=0;
765 for ( ; it!=end ; ++it)
766 {
767 const auto &match = *it;
768 size_t newIndex = match.position();
769 size_t matchLen = match.length();
770 ol.parseText(markerText.substr(index,newIndex-index));
771 unsigned long entryIndex = std::stoul(match[1].str());
772 if (entryIndex<static_cast<unsigned long>(numMarkers))
773 {
774 replaceFunc(entryIndex);
775 }
776 index=newIndex+matchLen;
777 }
778 ol.parseText(markerText.substr(index));
779}
780
781DString writeMarkerList(const std::string &markerText,size_t numMarkers,
782 std::function<DString(size_t)> replaceFunc)
783{
784 DString result;
785 static const reg::Ex marker(R"(@(\d+))");
786 reg::Iterator it(markerText,marker);
788 size_t index=0;
789 for ( ; it!=end ; ++it)
790 {
791 const auto &match = *it;
792 size_t newIndex = match.position();
793 size_t matchLen = match.length();
794 result += markerText.substr(index,newIndex-index);
795 unsigned long entryIndex = std::stoul(match[1].str());
796 if (entryIndex<static_cast<unsigned long>(numMarkers))
797 {
798 result+=replaceFunc(entryIndex);
799 }
800 index=newIndex+matchLen;
801 }
802 if (index<markerText.size())
803 {
804 result += markerText.substr(index);
805 }
806 return result;
807}
808
810{
811 auto replaceFunc = [&list,&ol](size_t entryIndex)
812 {
813 const auto &e = list[entryIndex];
818 // link for Html / man
819 //printf("writeObjectLink(file=%s)\n",qPrint(e->file));
820 ol.writeObjectLink(DString(),e.file,e.anchor,e.name);
822
826 // link for Latex / pdf with anchor because the sources
827 // are not hyperlinked (not possible with a verbatim environment).
828 ol.writeObjectLink(DString(),e.file,DString(),e.name);
830 };
831
832 writeMarkerList(ol, theTranslator->trWriteList(static_cast<int>(list.size())).str(), list.size(), replaceFunc);
833
834 ol.writeString(".");
835}
836
838{
839 DString paramDocs;
841 {
842 for (const Argument &a : al)
843 {
844 if (!a.docs.empty())
845 {
846 if (!a.name.empty())
847 {
848 paramDocs+=" \\ilinebr @tparam "+a.name+" "+a.docs;
849 }
850 else if (!a.type.empty())
851 {
852 DString type = a.type;
853 type.stripPrefix("class ");
854 type.stripPrefix("typename ");
855 type = type.stripWhiteSpace();
856 paramDocs+=" \\ilinebr @tparam "+type+" "+a.docs;
857 }
858 }
859 }
860 }
861 return paramDocs;
862}
863
864DString argListToString(const ArgumentList &al,bool useCanonicalType,bool showDefVals)
865{
866 DString result;
867 if (!al.hasParameters()) return result;
868 result+="(";
869 for (auto it = al.begin() ; it!=al.end() ;)
870 {
871 Argument a = *it;
872 DString type1 = useCanonicalType && !a.canType.empty() ? a.canType : a.type;
873 DString type2;
874 if (size_t i=type1.find(")("); i!=DString::npos) // hack to deal with function pointers
875 {
876 type2=type1.mid(i);
877 type1=type1.left(i);
878 }
879 if (!a.attrib.empty())
880 {
881 result+=a.attrib+" ";
882 }
883 if (!a.name.empty() || !a.array.empty())
884 {
885 result+= type1+" "+a.name+type2+a.array;
886 }
887 else
888 {
889 result+= type1+type2;
890 }
891 if (!a.defval.empty() && showDefVals)
892 {
893 result+="="+a.defval;
894 }
895 ++it;
896 if (it!=al.end()) result+=", ";
897 }
898 result+=")";
899 if (al.constSpecifier()) result+=" const";
900 if (al.volatileSpecifier()) result+=" volatile";
901 if (al.refQualifier()==RefQualifierType::LValue) result+=" &";
902 else if (al.refQualifier()==RefQualifierType::RValue) result+=" &&";
903 if (!al.trailingReturnType().empty()) result+=al.trailingReturnType();
904 if (al.pureSpecifier()) result+=" =0";
905 return removeRedundantWhiteSpace(result);
906}
907
908DString tempArgListToString(const ArgumentList &al,SrcLangExt lang,bool includeDefault)
909{
910 DString result;
911 if (al.empty()) return result;
912 result="<";
913 bool first=true;
914 for (const auto &a : al)
915 {
916 if (a.defval.empty() || includeDefault)
917 {
918 if (!first) result+=", ";
919 if (!a.name.empty()) // add template argument name
920 {
921 if (lang==SrcLangExt::Java || lang==SrcLangExt::CSharp)
922 {
923 result+=a.type+" ";
924 }
925 result+=a.name;
926 }
927 else // extract name from type
928 {
929 int i = static_cast<int>(a.type.length())-1;
930 while (i>=0 && isId(a.type.at(i))) i--;
931 if (i>0)
932 {
933 result+=a.type.right(a.type.length()-i-1);
934 if (a.type.find("...")!=DString::npos)
935 {
936 result+="...";
937 }
938 }
939 else // nothing found -> take whole name
940 {
941 result+=a.type;
942 }
943 }
944 if (!a.typeConstraint.empty() && lang==SrcLangExt::Java)
945 {
946 result+=" extends "; // TODO: now Java specific, C# has where...
947 result+=a.typeConstraint;
948 }
949 first=false;
950 }
951 }
952 result+=">";
953 return removeRedundantWhiteSpace(result);
954}
955
956
957//----------------------------------------------------------------------------
958
959/*! takes the \a buf of the given length \a len and converts CR LF (DOS)
960 * or CR (MAC) line ending to LF (Unix). Returns the length of the
961 * converted content (i.e. the same as \a len (Unix, MAC) or
962 * smaller (DOS)).
963 */
964static void filterCRLF(std::string &contents)
965{
966 size_t src = 0; // source index
967 size_t dest = 0; // destination index
968 size_t len = contents.length();
969
970 while (src<len)
971 {
972 char c = contents[src++]; // Remember the processed character.
973 if (c == '\r') // CR to be solved (MAC, DOS)
974 {
975 c = '\n'; // each CR to LF
976 if (src<len && contents[src] == '\n')
977 {
978 ++src; // skip LF just after CR (DOS)
979 }
980 }
981 else if ( c == '\0' && src<len-1) // filter out internal \0 characters, as it will confuse the parser
982 {
983 c = ' '; // turn into a space
984 }
985 contents[dest++] = c; // copy the (modified) character to dest
986 }
987 contents.resize(dest);
988}
989
990static DString getFilterFromList(const DString &name,const StringVector &filterList,bool &found)
991{
992 found=false;
993 // compare the file name to the filter pattern list
994 for (const auto &filterStr : filterList)
995 {
996 DString fs = filterStr;
997 if (size_t i_equals=fs.find('='); i_equals!=DString::npos)
998 {
999 DString filterPattern = fs.left(i_equals);
1000 DString input = name;
1002 {
1003 filterPattern = filterPattern.lower();
1004 input = input.lower();
1005 }
1006 reg::Ex re(filterPattern.str(),reg::Ex::Mode::Wildcard);
1007 if (re.isValid() && reg::match(input.str(),re))
1008 {
1009 // found a match!
1010 DString filterName = fs.mid(i_equals+1);
1011 if (filterName.find(' ')!=DString::npos)
1012 { // add quotes if the name has spaces
1013 filterName="\""+filterName+"\"";
1014 }
1015 found=true;
1016 return filterName;
1017 }
1018 }
1019 }
1020
1021 // no match
1022 return "";
1023}
1024
1025DString getFileFilter(const DString &name,bool isSourceCode)
1026{
1027 // sanity check
1028 if (name.empty()) return "";
1029
1030 StringVector filterSrcList = Config_getList(FILTER_SOURCE_PATTERNS);
1031 StringVector filterList = Config_getList(FILTER_PATTERNS);
1032
1033 DString filterName;
1034 bool found=false;
1035 if (isSourceCode && !filterSrcList.empty())
1036 { // first look for source filter pattern list
1037 filterName = getFilterFromList(name,filterSrcList,found);
1038 }
1039 if (!found && filterName.empty())
1040 { // then look for filter pattern list
1041 filterName = getFilterFromList(name,filterList,found);
1042 }
1043 if (!found)
1044 { // then use the generic input filter
1045 return Config_getString(INPUT_FILTER);
1046 }
1047 else
1048 {
1049 /* remove surrounding double quotes */
1050 if (filterName.length()>=2 && filterName[0]=='"' && filterName[static_cast<int>(filterName.length())-1]=='"')
1051 {
1052 filterName = filterName.mid(1,filterName.length()-2);
1053 }
1054 return filterName;
1055 }
1056}
1057
1058DString fileToString(const DString &name,bool filter,bool isSourceCode)
1059{
1060 if (name.empty()) return DString();
1061 bool fileOpened=false;
1062 if (name[0]=='-' && name[1]==0) // read from stdin
1063 {
1064 std::string contents;
1065 std::string line;
1066 while (getline(std::cin,line))
1067 {
1068 contents+=line+'\n';
1069 }
1070 return contents;
1071 }
1072 else // read from file
1073 {
1074 FileInfo fi(name.str());
1075 if (!fi.exists() || !fi.isFile())
1076 {
1077 err("file '{}' not found\n",name);
1078 return "";
1079 }
1080 std::string buf;
1081 fileOpened=readInputFile(name,buf,ReadInputFileOptions().setFilter(filter).setIsSourceCode(isSourceCode));
1082 if (fileOpened)
1083 {
1084 addTerminalCharIfMissing(buf,'\n');
1085 return buf;
1086 }
1087 }
1088 if (!fileOpened)
1089 {
1090 err("cannot open file '{}' for reading\n",name);
1091 }
1092 return "";
1093}
1094
1095void trimBaseClassScope(const BaseClassList &bcl,DString &s,int level=0)
1096{
1097 //printf("trimBaseClassScope level=%d '%s'\n",level,qPrint(s));
1098 for (const auto &bcd : bcl)
1099 {
1100 ClassDef *cd=bcd.classDef;
1101 //printf("Trying class %s\n",qPrint(cd->name()));
1102 if (size_t spos=s.find(cd->name()+"::"); spos!=DString::npos)
1103 {
1104 s = s.left(spos)+s.right(
1105 s.length()-spos-cd->name().length()-2
1106 );
1107 }
1108 //printf("base class '%s'\n",qPrint(cd->name()));
1109 if (!cd->baseClasses().empty())
1110 {
1111 trimBaseClassScope(cd->baseClasses(),s,level+1);
1112 }
1113 }
1114}
1115
1116static void stripIrrelevantString(DString &target,const DString &str,bool insideTemplate)
1117{
1118 AUTO_TRACE("target='{}' str='{}'",target,str);
1119 if (target==str) { target.clear(); return; }
1120 size_t i=0,p=0;
1121 size_t l=str.length();
1122 bool changed=false;
1123 int sharpCount=0;
1124 while ((i=target.find(str,p))!=DString::npos)
1125 {
1126 for (size_t q=p;q<i;q++)
1127 {
1128 if (target[q]=='<') sharpCount++;
1129 else if (target[q]=='>' && sharpCount>0) sharpCount--;
1130 }
1131 bool isMatch = (i==0 || !isId(target.at(i-1))) && // not a character before str
1132 (i+l==target.length() || !isId(target.at(i+l))) && // not a character after str
1133 !insideTemplate && sharpCount==0; // not inside template, because e.g. <const A> is different than <A>, see issue #11663
1134 if (isMatch)
1135 {
1136 size_t i1=target.find('*',i+l);
1137 size_t i2=target.find('&',i+l);
1138 if (i1==DString::npos && i2==DString::npos)
1139 {
1140 // strip str from target at index i
1141 target=target.left(i)+target.mid(i+l);
1142 changed=true;
1143 i-=l;
1144 }
1145 else if ((i1!=DString::npos && i<i1) || (i2!=DString::npos && i<i2)) // str before * or &
1146 {
1147 // move str to front
1148 target=str+" "+target.left(i)+target.mid(i+l);
1149 changed=true;
1150 i++;
1151 }
1152 }
1153 p = i+l;
1154 }
1155 if (changed) target=target.stripWhiteSpace();
1156 AUTO_TRACE_EXIT("target='{}'",target,str);
1157}
1158
1159/*! According to the C++ spec and Ivan Vecerina:
1160
1161 Parameter declarations that differ only in the presence or absence
1162 of const and/or volatile are equivalent.
1163
1164 So the following example, show what is stripped by this routine
1165 for const. The same is done for volatile.
1166
1167 For Java code we also strip the "final" keyword, see bug 765070.
1168
1169 \code
1170 const T param -> T param // not relevant
1171 const T& param -> const T& param // const needed
1172 T* const param -> T* param // not relevant
1173 const T* param -> const T* param // const needed
1174 \endcode
1175 */
1176void stripIrrelevantConstVolatile(DString &s,bool insideTemplate)
1177{
1178 //printf("stripIrrelevantConstVolatile(%s)=",qPrint(s));
1179 stripIrrelevantString(s,"const",insideTemplate);
1180 stripIrrelevantString(s,"volatile",insideTemplate);
1181 stripIrrelevantString(s,"final",insideTemplate);
1182 //printf("%s\n",qPrint(s));
1183}
1184
1185
1187{
1188 size_t i=s.find(" class ");
1189 if (i!=DString::npos) return s.left(i)+s.mid(i+6);
1190 i=s.find(" typename ");
1191 if (i!=DString::npos) return s.left(i)+s.mid(i+9);
1192 i=s.find(" union ");
1193 if (i!=DString::npos) return s.left(i)+s.mid(i+6);
1194 i=s.find(" struct ");
1195 if (i!=DString::npos) return s.left(i)+s.mid(i+7);
1196 i=s.find(" record ");
1197 if (i!=DString::npos) return s.left(i)+s.mid(i+7);
1198 return s;
1199}
1200
1201// forward decl for circular dependencies
1202static DString extractCanonicalType(const Definition *d,const FileDef *fs,DString type,SrcLangExt lang,bool insideTemplate);
1203
1204static DString getCanonicalTemplateSpec(const Definition *d,const FileDef *fs,const DString& spec,SrcLangExt lang)
1205{
1206 AUTO_TRACE("spec={}",spec);
1207 DString templSpec = spec.stripWhiteSpace();
1208 // this part had been commented out before... but it is needed to match for instance
1209 // std::list<std::string> against list<string> so it is now back again!
1210 if (!templSpec.empty() && templSpec.at(0) == '<')
1211 {
1212 templSpec = "< " + extractCanonicalType(d,fs,templSpec.mid(1).stripWhiteSpace(),lang,true);
1213 }
1214 DString resolvedType = lang==SrcLangExt::Java ? templSpec : resolveTypeDef(d,templSpec);
1215 if (!resolvedType.empty()) // not known as a typedef either
1216 {
1217 templSpec = resolvedType;
1218 }
1219 //printf("getCanonicalTemplateSpec(%s)=%s\n",qPrint(spec),qPrint(templSpec));
1220 AUTO_TRACE_EXIT("result={}",templSpec);
1221 return templSpec;
1222}
1223
1224
1226 const Definition *d,const FileDef *fs,const DString &word,SrcLangExt lang,
1227 DString *tSpec,int count=0)
1228{
1229 if (count>10) return word; // oops recursion
1230
1231 DString symName,result,templSpec,tmpName;
1232 if (tSpec && !tSpec->empty())
1233 templSpec = stripDeclKeywords(getCanonicalTemplateSpec(d,fs,*tSpec,lang));
1234
1235 AUTO_TRACE("d='{}' fs='{}' word='{}' templSpec='{}'",d?d->name():"",fs?fs->name():"",word,templSpec);
1236
1237 if (word.rfind("::")!=DString::npos && !(tmpName=stripScope(word)).empty())
1238 {
1239 symName=tmpName; // name without scope
1240 }
1241 else
1242 {
1243 symName=word;
1244 }
1245
1246 // lookup class / class template instance
1247 SymbolResolver resolver(fs);
1248 const ClassDef *cd = resolver.resolveClass(d,word+templSpec,true,true);
1249 const MemberDef *mType = resolver.getTypedef();
1250 DString ts = resolver.getTemplateSpec();
1251 DString resolvedType = resolver.getResolvedType();
1252
1253 bool isTemplInst = cd && !templSpec.empty();
1254 if (!cd && !templSpec.empty())
1255 {
1256 // class template specialization not known, look up class template
1257 cd = resolver.resolveClass(d,word,true,true);
1258 mType = resolver.getTypedef();
1259 ts = resolver.getTemplateSpec();
1260 resolvedType = resolver.getResolvedType();
1261 }
1262 if (cd && cd->isUsedOnly()) cd=nullptr; // ignore types introduced by usage relations
1263
1264 AUTO_TRACE_ADD("cd='{}' mType='{}' ts='{}' resolvedType='{}'",
1265 cd?cd->name():"",mType?mType->name():"",ts,resolvedType);
1266 //printf("cd=%p mtype=%p\n",cd,mType);
1267 //printf(" getCanonicalTypeForIdentifier: symbol=%s word=%s cd=%s d=%s fs=%s cd->isTemplate=%d\n",
1268 // qPrint(symName),
1269 // qPrint(word),
1270 // cd ? qPrint(cd->name()) : "<none>",
1271 // d ? qPrint( d->name()) : "<none>",
1272 // fs ? qPrint(fs->name()) : "<none>",
1273 // cd ? cd->isTemplate():-1
1274 // );
1275
1276 //printf(" >>>> word '%s' => '%s' templSpec=%s ts=%s tSpec=%s isTemplate=%d resolvedType=%s\n",
1277 // qPrint((word+templSpec)),
1278 // cd ? qPrint(cd->qualifiedName()) : "<none>",
1279 // qPrint(templSpec), qPrint(ts),
1280 // tSpec ? qPrint(tSpec) : "<null>",
1281 // cd ? cd->isTemplate():false,
1282 // qPrint(resolvedType));
1283
1284 //printf(" mtype=%s\n",mType ? qPrint(mType->name()) : "<none>");
1285
1286 if (cd) // resolves to a known class type
1287 {
1288 if (cd==d && tSpec) *tSpec="";
1289
1290 if (mType && mType->isTypedef()) // but via a typedef
1291 {
1292 result = resolvedType+ts; // the +ts was added for bug 685125
1293 }
1294 else
1295 {
1296 if (isTemplInst)
1297 {
1298 // spec is already part of class type
1299 templSpec="";
1300 if (tSpec) *tSpec="";
1301 }
1302 else if (!ts.empty() && templSpec.empty())
1303 {
1304 // use formal template args for spec
1305 templSpec = stripDeclKeywords(getCanonicalTemplateSpec(d,fs,ts,lang));
1306 }
1307
1308 result = removeRedundantWhiteSpace(cd->qualifiedName() + templSpec);
1309
1310 if (cd->isTemplate() && tSpec) //
1311 {
1312 if (!templSpec.empty()) // specific instance
1313 {
1314 result=cd->name()+templSpec;
1315 }
1316 else // use template type
1317 {
1319 }
1320 // template class, so remove the template part (it is part of the class name)
1321 *tSpec="";
1322 }
1323 else if (ts.empty() && !templSpec.empty() && cd && !cd->isTemplate() && tSpec)
1324 {
1325 // obscure case, where a class is used as a template, but doxygen think it is
1326 // not (could happen when loading the class from a tag file).
1327 *tSpec="";
1328 }
1329 }
1330 }
1331 else if (mType && mType->isEnumerate()) // an enum
1332 {
1333 result = mType->qualifiedName();
1334 }
1335 else if (mType && mType->isTypedef()) // a typedef
1336 {
1337 //result = mType->qualifiedName(); // changed after 1.7.2
1338 //result = mType->typeString();
1339 //printf("word=%s typeString=%s\n",qPrint(word),mType->typeString());
1340 if (word!=mType->typeString())
1341 {
1342 DString type = mType->typeString();
1343 if (type.startsWith("typename "))
1344 {
1345 type.stripPrefix("typename ");
1346 type = stripTemplateSpecifiersFromScope(type,false);
1347 }
1348 if (!type.empty()) // see issue #11065
1349 {
1350 result = getCanonicalTypeForIdentifier(d,fs,type,mType->getLanguage(),tSpec,count+1);
1351 }
1352 else
1353 {
1354 result = word;
1355 }
1356 }
1357 else
1358 {
1359 result = mType->typeString();
1360 }
1361 }
1362 else // fallback
1363 {
1364 resolvedType = lang==SrcLangExt::Java ? word : resolveTypeDef(d,word);
1365 AUTO_TRACE_ADD("fallback resolvedType='{}'",resolvedType);
1366 if (resolvedType.empty()) // not known as a typedef either
1367 {
1368 result = word;
1369 }
1370 else
1371 {
1372 result = resolvedType;
1373 }
1374 }
1375 AUTO_TRACE_EXIT("result='{}'",result);
1376 return result;
1377}
1378
1379static DString extractCanonicalType(const Definition *d,const FileDef *fs,DString type,SrcLangExt lang,bool insideTemplate)
1380{
1381 AUTO_TRACE("d={} fs={} type='{}'",d?d->name():"",fs?fs->name():"",type);
1382 type = type.stripWhiteSpace();
1383
1384 // strip const and volatile keywords that are not relevant for the type
1385 stripIrrelevantConstVolatile(type,insideTemplate);
1386
1387 // strip leading keywords
1388 type.stripPrefix("class ");
1389 type.stripPrefix("struct ");
1390 type.stripPrefix("record ");
1391 type.stripPrefix("union ");
1392 type.stripPrefix("enum ");
1393 type.stripPrefix("typename ");
1394
1395 type = removeRedundantWhiteSpace(type);
1396 //printf("extractCanonicalType(type=%s) start: def=%s file=%s\n",qPrint(type),
1397 // d ? qPrint(d->name()) : "<null>", fs ? qPrint(fs->name()) : "<null>");
1398
1399 DString canType;
1400 DString templSpec,word;
1401 int i=0,p=0,pp=0;
1402 while ((i=extractClassNameFromType(type,p,word,templSpec))!=-1)
1403 // foreach identifier in the type
1404 {
1405 //printf(" i=%d p=%d\n",i,p);
1406 if (i>pp)
1407 {
1408 if (i-pp>=2 && type[i-2]==':' && type[i-1]==':') // skip over leading ::, see issue #12021
1409 {
1410 canType += type.mid(pp,i-pp-2);
1411 }
1412 else
1413 {
1414 canType += type.mid(pp,i-pp);
1415 }
1416 }
1417
1418 DString ct = getCanonicalTypeForIdentifier(d,fs,word,lang,&templSpec);
1419
1420 // in case the ct is empty it means that "word" represents scope "d"
1421 // and this does not need to be added to the canonical
1422 // type (it is redundant), so/ we skip it. This solves problem 589616.
1423 if (ct.empty() && type.mid(p,2)=="::")
1424 {
1425 p+=2;
1426 }
1427 else
1428 {
1429 canType += ct;
1430 }
1431 //printf(" word=%s templSpec=%s canType=%s ct=%s\n",
1432 // qPrint(word), qPrint(templSpec), qPrint(canType), qPrint(ct));
1433 if (!templSpec.empty()) // if we didn't use up the templSpec already
1434 // (i.e. type is not a template specialization)
1435 // then resolve any identifiers inside.
1436 {
1437 std::string ts = templSpec.str();
1438 static const reg::Ex re(R"(\a\w*)");
1439 reg::Iterator it(ts,re);
1441
1442 size_t tp=0;
1443 // for each identifier template specifier
1444 //printf("adding resolved %s to %s\n",qPrint(templSpec),qPrint(canType));
1445 for (; it!=end ; ++it)
1446 {
1447 const auto &match = *it;
1448 size_t ti = match.position();
1449 size_t tl = match.length();
1450 std::string matchStr = match.str();
1451 canType += ts.substr(tp,ti-tp);
1452 canType += getCanonicalTypeForIdentifier(d,fs,matchStr,lang,nullptr);
1453 tp=ti+tl;
1454 }
1455 canType+=ts.substr(tp);
1456 }
1457
1458 pp=p;
1459 }
1460 canType += type.mid(pp);
1461 AUTO_TRACE_EXIT("canType='{}'",canType);
1462
1463 return removeRedundantWhiteSpace(canType);
1464}
1465
1466static DString extractCanonicalArgType(const Definition *d,const FileDef *fs,const Argument &arg,SrcLangExt lang)
1467{
1468 DString type = arg.type.stripWhiteSpace();
1469 DString name = arg.name;
1470 //printf("----- extractCanonicalArgType(type=%s,name=%s)\n",qPrint(type),qPrint(name));
1471 if ((type=="const" || type=="volatile") && !name.empty())
1472 { // name is part of type => correct
1473 type+=" ";
1474 type+=name;
1475 }
1476 if (name=="const" || name=="volatile")
1477 { // name is part of type => correct
1478 if (!type.empty()) type+=" ";
1479 type+=name;
1480 }
1481 if (!arg.array.empty())
1482 {
1483 type+=arg.array;
1484 }
1485
1486 return extractCanonicalType(d,fs,type,lang,false);
1487}
1488
1489static std::mutex g_matchArgsMutex;
1490
1491// a bit of debug support for matchArguments
1492//#define MATCH
1493//#define NOMATCH
1494//#define MATCH printf("Match at line %d\n",__LINE__);
1495//#define NOMATCH printf("Nomatch at line %d\n",__LINE__);
1496#define MATCH AUTO_TRACE_EXIT("match at line {}",__LINE__);
1497#define NOMATCH AUTO_TRACE_EXIT("no match at line {}",__LINE__);
1498
1500 const Definition *srcScope,const FileDef *srcFileScope,const DString &srcType,
1501 const Definition *dstScope,const FileDef *dstFileScope,const DString &dstType,
1502 SrcLangExt lang)
1503{
1504 AUTO_TRACE("srcType='{}' dstType='{}'",srcType,dstType);
1505 if (srcType==dstType) return true;
1506
1507 // check if the types are function pointers
1508 size_t i1=srcType.find(")(");
1509 if (i1==DString::npos) return false;
1510 size_t i2=dstType.find(")(");
1511 if (i1!=i2) return false;
1512
1513 // check if the result part of the function pointer types matches
1514 size_t j1=srcType.find("(");
1515 if (j1==DString::npos || j1>i1) return false;
1516 size_t j2=dstType.find("(");
1517 if (j2!=j1) return false;
1518 if (srcType.left(j1)!=dstType.left(j2)) return false; // different return types
1519
1520 // if srcType and dstType are both function pointers with the same return type,
1521 // then match against the parameter lists.
1522 // This way srcType='void (*fptr)(int x)' will match against `void (*fptr)(int y)' because
1523 // 'int x' matches 'int y'. A simple literal string match would treat these as different.
1524 auto srcAl = stringToArgumentList(lang,srcType.mid(i1+1));
1525 auto dstAl = stringToArgumentList(lang,dstType.mid(i2+1));
1526 return matchArguments2(srcScope,srcFileScope,srcType.left(j1),srcAl.get(),
1527 dstScope,dstFileScope,dstType.left(j2),dstAl.get(),
1528 true,lang);
1529}
1530
1531static bool matchUnresolvedTypes(const Definition *srcScope,const FileDef *srcFileScope,const DString &srcType,
1532 const Definition *dstScope,const FileDef *dstFileScope,const DString &dstType)
1533{
1534 // Do not infer names inside expressions, template arguments, or declarators.
1535 if (srcType.find('<')!=DString::npos || dstType.find('<')!=DString::npos ||
1536 srcType.find('(')!=DString::npos || dstType.find('(')!=DString::npos ||
1537 srcType.find('[')!=DString::npos || dstType.find('[')!=DString::npos) return false;
1538 static const reg::Ex re(R"(\a[\w:]*)");
1539 std::string src = srcType.str();
1540 std::string dst = dstType.str();
1541 reg::Iterator srcIt(src,re), dstIt(dst,re), end;
1542 size_t srcPos=0, dstPos=0;
1543 for (; srcIt!=end && dstIt!=end; ++srcIt,++dstIt)
1544 {
1545 const auto &srcMatch=*srcIt;
1546 const auto &dstMatch=*dstIt;
1547 if (src.substr(srcPos,srcMatch.position()-srcPos)!=dst.substr(dstPos,dstMatch.position()-dstPos)) return false;
1548 DString srcWord=srcMatch.str();
1549 DString dstWord=dstMatch.str();
1550 if (srcWord!=dstWord)
1551 {
1552 const Definition *scope;
1553 const FileDef *fileScope;
1554 DString unqualified;
1555 if (srcWord.find("::")==DString::npos && rightScopeMatch(dstWord,srcWord))
1556 {
1557 scope=srcScope;
1558 fileScope=srcFileScope;
1559 unqualified=srcWord;
1560 }
1561 else if (dstWord.find("::")==DString::npos && rightScopeMatch(srcWord,dstWord))
1562 {
1563 scope=dstScope;
1564 fileScope=dstFileScope;
1565 unqualified=dstWord;
1566 }
1567 else
1568 {
1569 return false;
1570 }
1571 SymbolResolver resolver(fileScope);
1572 const ClassDef *cd=resolver.resolveClass(scope,unqualified,true,true);
1573 if (cd || resolver.getTypedef()) return false;
1574 }
1575 srcPos=srcMatch.position()+srcMatch.length();
1576 dstPos=dstMatch.position()+dstMatch.length();
1577 }
1578 return srcIt==end && dstIt==end && src.substr(srcPos)==dst.substr(dstPos);
1579}
1580
1581static bool matchArgument2(
1582 const Definition *srcScope,const FileDef *srcFileScope,Argument &srcA,
1583 const Definition *dstScope,const FileDef *dstFileScope,Argument &dstA,
1584 SrcLangExt lang,bool allowUnresolved
1585 )
1586{
1587 AUTO_TRACE("src: scope={} type={} name={} canType={}, dst: scope={} type={} name={} canType={}",
1588 srcScope?srcScope->name():"",srcA.type,srcA.name,srcA.canType,
1589 dstScope?dstScope->name():"",dstA.type,dstA.name,dstA.canType);
1590 //printf(">> match argument: %s::'%s|%s' (%s) <-> %s::'%s|%s' (%s)\n",
1591 // srcScope ? qPrint(srcScope->name()) : "",
1592 // qPrint(srcA.type), qPrint(srcA.name), qPrint(srcA.canType),
1593 // dstScope ? qPrint(dstScope->name()) : "",
1594 // qPrint(dstA.type), qPrint(dstA.name), qPrint(dstA.canType));
1595
1596 DString sSrcName = " "+srcA.name;
1597 DString sDstName = " "+dstA.name;
1598 DString srcType = srcA.type;
1599 DString dstType = dstA.type;
1600 stripIrrelevantConstVolatile(srcType,false);
1601 stripIrrelevantConstVolatile(dstType,false);
1602 //printf("'%s'<->'%s'\n",qPrint(sSrcName),qPrint(dstType.right(sSrcName.length())));
1603 //printf("'%s'<->'%s'\n",qPrint(sDstName),qPrint(srcType.right(sDstName.length())));
1604 if (sSrcName==dstType.right(sSrcName.length()))
1605 { // case "unsigned int" <-> "unsigned int i"
1606 srcA.type+=sSrcName;
1607 srcA.name="";
1608 srcA.canType=""; // invalidate cached type value
1609 }
1610 else if (sDstName==srcType.right(sDstName.length()))
1611 { // case "unsigned int i" <-> "unsigned int"
1612 dstA.type+=sDstName;
1613 dstA.name="";
1614 dstA.canType=""; // invalidate cached type value
1615 }
1616
1617 {
1618 std::lock_guard lock(g_matchArgsMutex);
1619 if (srcA.canType.empty() || dstA.canType.empty())
1620 {
1621 // need to re-evaluate both see issue #8370
1622 srcA.canType = extractCanonicalArgType(srcScope,srcFileScope,srcA,lang);
1623 dstA.canType = extractCanonicalArgType(dstScope,dstFileScope,dstA,lang);
1624 }
1625 }
1626
1627 if (matchCanonicalTypes(srcScope,srcFileScope,srcA.canType,
1628 dstScope,dstFileScope,dstA.canType,
1629 lang) ||
1630 (allowUnresolved && matchUnresolvedTypes(srcScope,srcFileScope,srcA.canType,
1631 dstScope,dstFileScope,dstA.canType)))
1632 {
1633 MATCH
1634 AUTO_TRACE_EXIT("true");
1635 return true;
1636 }
1637 else
1638 {
1639 //printf(" Canonical types do not match [%s]<->[%s]\n",
1640 // qPrint(srcA->canType),qPrint(dstA->canType));
1641 NOMATCH
1642 AUTO_TRACE_EXIT("false");
1643 return false;
1644 }
1645}
1646
1647
1648// new algorithm for argument matching
1649bool matchArguments2(const Definition *srcScope,const FileDef *srcFileScope,const DString &srcReturnType,const ArgumentList *srcAl,
1650 const Definition *dstScope,const FileDef *dstFileScope,const DString &dstReturnType,const ArgumentList *dstAl,
1651 bool checkCV,SrcLangExt lang,bool allowUnresolved)
1652{
1653 ASSERT(srcScope!=nullptr && dstScope!=nullptr);
1654
1655 AUTO_TRACE("srcScope='{}' dstScope='{}' srcArgs='{}' dstArgs='{}' checkCV={} lang={}",
1656 srcScope->name(),dstScope->name(),srcAl?argListToString(*srcAl):"",dstAl?argListToString(*dstAl):"",checkCV,lang);
1657
1658 if (srcAl==nullptr || dstAl==nullptr)
1659 {
1660 bool match = srcAl==dstAl;
1661 if (match)
1662 {
1663 MATCH
1664 return true;
1665 }
1666 else
1667 {
1668 NOMATCH
1669 return false;
1670 }
1671 }
1672
1673 // handle special case with void argument
1674 if ( srcAl->empty() && dstAl->size()==1 && dstAl->front().type=="void" )
1675 { // special case for finding match between func() and func(void)
1676 Argument a;
1677 a.type = "void";
1678 const_cast<ArgumentList*>(srcAl)->push_back(a);
1679 MATCH
1680 return true;
1681 }
1682 if ( dstAl->empty() && srcAl->size()==1 && srcAl->front().type=="void" )
1683 { // special case for finding match between func(void) and func()
1684 Argument a;
1685 a.type = "void";
1686 const_cast<ArgumentList*>(dstAl)->push_back(a);
1687 MATCH
1688 return true;
1689 }
1690
1691 if (srcAl->size() != dstAl->size())
1692 {
1693 NOMATCH
1694 return false; // different number of arguments -> no match
1695 }
1696
1697 if (checkCV)
1698 {
1699 if (srcAl->constSpecifier() != dstAl->constSpecifier())
1700 {
1701 NOMATCH
1702 return false; // one member is const, the other not -> no match
1703 }
1704 if (srcAl->volatileSpecifier() != dstAl->volatileSpecifier())
1705 {
1706 NOMATCH
1707 return false; // one member is volatile, the other not -> no match
1708 }
1709 }
1710
1711 if (srcAl->refQualifier() != dstAl->refQualifier())
1712 {
1713 NOMATCH
1714 return false; // one member is has a different ref-qualifier than the other
1715 }
1716
1717 if (srcReturnType=="auto" && dstReturnType=="auto" && srcAl->trailingReturnType()!=dstAl->trailingReturnType())
1718 {
1719 NOMATCH
1720 return false; // one member is has a different return type than the other
1721 }
1722
1723 // so far the argument list could match, so we need to compare the types of
1724 // all arguments.
1725 auto srcIt = srcAl->begin();
1726 auto dstIt = dstAl->begin();
1727 for (;srcIt!=srcAl->end() && dstIt!=dstAl->end();++srcIt,++dstIt)
1728 {
1729 Argument &srcA = const_cast<Argument&>(*srcIt);
1730 Argument &dstA = const_cast<Argument&>(*dstIt);
1731 if (!matchArgument2(srcScope,srcFileScope,srcA,
1732 dstScope,dstFileScope,dstA,
1733 lang,allowUnresolved)
1734 )
1735 {
1736 NOMATCH
1737 return false;
1738 }
1739 }
1740 MATCH
1741 return true; // all arguments match
1742}
1743
1744#undef MATCH
1745#undef NOMATCH
1746
1747// merges the initializer of two argument lists
1748// pre: the types of the arguments in the list should match.
1749void mergeArguments(ArgumentList &srcAl,ArgumentList &dstAl,bool forceNameOverwrite)
1750{
1751 AUTO_TRACE("srcAl='{}',dstAl='{}',forceNameOverwrite={}",
1752 qPrint(argListToString(srcAl)),qPrint(argListToString(dstAl)),forceNameOverwrite);
1753
1754 if (srcAl.size()!=dstAl.size())
1755 {
1756 return; // invalid argument lists -> do not merge
1757 }
1758
1759 auto srcIt=srcAl.begin();
1760 auto dstIt=dstAl.begin();
1761 while (srcIt!=srcAl.end() && dstIt!=dstAl.end())
1762 {
1763 Argument &srcA = *srcIt;
1764 Argument &dstA = *dstIt;
1765
1766 AUTO_TRACE_ADD("before merge: src=[type='{}',name='{}',def='{}'] dst=[type='{}',name='{}',def='{}']",
1767 srcA.type,srcA.name,srcA.defval,
1768 dstA.type,dstA.name,dstA.defval);
1769 if (srcA.defval.empty() && !dstA.defval.empty())
1770 {
1771 //printf("Defval changing '%s'->'%s'\n",qPrint(srcA.defval),qPrint(dstA.defval));
1772 srcA.defval=dstA.defval;
1773 }
1774 else if (!srcA.defval.empty() && dstA.defval.empty())
1775 {
1776 //printf("Defval changing '%s'->'%s'\n",qPrint(dstA.defval),qPrint(srcA.defval));
1777 dstA.defval=srcA.defval;
1778 }
1779
1780 // fix wrongly detected const or volatile specifiers before merging.
1781 // example: "const A *const" is detected as type="const A *" name="const"
1782 if (srcA.name=="const" || srcA.name=="volatile")
1783 {
1784 srcA.type+=" "+srcA.name;
1785 srcA.name.clear();
1786 }
1787 if (dstA.name=="const" || dstA.name=="volatile")
1788 {
1789 dstA.type+=" "+dstA.name;
1790 dstA.name.clear();
1791 }
1792
1793 if (srcA.type==dstA.type)
1794 {
1795 //printf("1. merging %s:%s <-> %s:%s\n",qPrint(srcA.type),qPrint(srcA.name),qPrint(dstA.type),qPrint(dstA.name));
1796 if (srcA.name.empty() && !dstA.name.empty())
1797 {
1798 //printf("type: '%s':='%s'\n",qPrint(srcA.type),qPrint(dstA.type));
1799 //printf("name: '%s':='%s'\n",qPrint(srcA.name),qPrint(dstA.name));
1800 srcA.type = dstA.type;
1801 srcA.name = dstA.name;
1802 }
1803 else if (!srcA.name.empty() && dstA.name.empty())
1804 {
1805 //printf("type: '%s':='%s'\n",qPrint(dstA.type),qPrint(srcA.type));
1806 //printf("name: '%s':='%s'\n",qPrint(dstA.name),qPrint(srcA.name));
1807 dstA.type = srcA.type;
1808 dstA.name = srcA.name;
1809 }
1810 else if (!srcA.name.empty() && !dstA.name.empty())
1811 {
1812 //printf("srcA.name=%s dstA.name=%s\n",qPrint(srcA.name),qPrint(dstA.name));
1813 if (forceNameOverwrite)
1814 {
1815 srcA.name = dstA.name;
1816 }
1817 else
1818 {
1819 if (srcA.docs.empty() && !dstA.docs.empty())
1820 {
1821 srcA.name = dstA.name;
1822 }
1823 else if (!srcA.docs.empty() && dstA.docs.empty())
1824 {
1825 dstA.name = srcA.name;
1826 }
1827 }
1828 }
1829 }
1830 else
1831 {
1832 //printf("2. merging '%s':'%s' <-> '%s':'%s'\n",qPrint(srcA.type),qPrint(srcA.name),qPrint(dstA.type),qPrint(dstA.name));
1833 srcA.type=srcA.type.stripWhiteSpace();
1834 dstA.type=dstA.type.stripWhiteSpace();
1835 if (srcA.type+" "+srcA.name==dstA.type) // "unsigned long:int" <-> "unsigned long int:bla"
1836 {
1837 srcA.type+=" "+srcA.name;
1838 srcA.name=dstA.name;
1839 }
1840 else if (dstA.type+" "+dstA.name==srcA.type) // "unsigned long int bla" <-> "unsigned long int"
1841 {
1842 dstA.type+=" "+dstA.name;
1843 dstA.name=srcA.name;
1844 }
1845 else if (srcA.name.empty() && !dstA.name.empty())
1846 {
1847 srcA.name = dstA.name;
1848 }
1849 else if (dstA.name.empty() && !srcA.name.empty())
1850 {
1851 dstA.name = srcA.name;
1852 }
1853 }
1854 size_t i1=srcA.type.find("::"),
1855 i2=dstA.type.find("::"),
1856 j1=srcA.type.length()-i1-2,
1857 j2=dstA.type.length()-i2-2;
1858 if (i1!=DString::npos && i2==DString::npos && srcA.type.right(j1)==dstA.type)
1859 {
1860 //printf("type: '%s':='%s'\n",qPrint(dstA.type),qPrint(srcA.type));
1861 //printf("name: '%s':='%s'\n",qPrint(dstA.name),qPrint(srcA.name));
1862 dstA.type = srcA.type.left(i1+2)+dstA.type;
1863 dstA.name = srcA.name;
1864 }
1865 else if (i1==DString::npos && i2!=DString::npos && dstA.type.right(j2)==srcA.type)
1866 {
1867 //printf("type: '%s':='%s'\n",qPrint(srcA.type),qPrint(dstA.type));
1868 //printf("name: '%s':='%s'\n",qPrint(dstA.name),qPrint(srcA.name));
1869 srcA.type = dstA.type.left(i2+2)+srcA.type;
1870 srcA.name = dstA.name;
1871 }
1872 if (srcA.docs.empty() && !dstA.docs.empty())
1873 {
1874 srcA.docs = dstA.docs;
1875 }
1876 else if (dstA.docs.empty() && !srcA.docs.empty())
1877 {
1878 dstA.docs = srcA.docs;
1879 }
1880 //printf("Merge argument '%s|%s' '%s|%s'\n",
1881 // qPrint(srcA.type), qPrint(srcA.name),
1882 // qPrint(dstA.type), qPrint(dstA.name));
1883 ++srcIt;
1884 ++dstIt;
1885 AUTO_TRACE_ADD("after merge: src=[type='{}',name='{}',def='{}'] dst=[type='{}',name='{}',def='{}']",
1886 srcA.type,srcA.name,srcA.defval,
1887 dstA.type,dstA.name,dstA.defval);
1888 }
1889}
1890
1891//---------------------------------------------------------------------------------------
1892
1893bool matchTemplateArguments(const ArgumentList &srcAl,const ArgumentList &dstAl)
1894{
1895 AUTO_TRACE("srcAl={} dstAl={}",argListToString(srcAl),argListToString(dstAl));
1896 if (srcAl.size()!=dstAl.size()) // different number of template parameters -> overload
1897 {
1898 AUTO_TRACE_EXIT("different number of parameters");
1899 return false;
1900 }
1901 auto isUnconstraintTemplate = [](const DString &type)
1902 {
1903 return type=="typename" || type=="class" || type.startsWith("typename ") || type.startsWith("class ");
1904 };
1905 auto srcIt = srcAl.begin();
1906 auto dstIt = dstAl.begin();
1907 while (srcIt!=srcAl.end() && dstIt!=dstAl.end())
1908 {
1909 const Argument &srcA = *srcIt;
1910 const Argument &dstA = *dstIt;
1911 if ((!isUnconstraintTemplate(srcA.type) || !isUnconstraintTemplate(dstA.type)) && srcA.type!=dstA.type) // different constraints -> overload
1912 {
1913 AUTO_TRACE_EXIT("different constraints");
1914 return false;
1915 }
1916 ++srcIt;
1917 ++dstIt;
1918 }
1919 AUTO_TRACE_EXIT("same");
1920 // no overload with respect to the template parameters
1921 return true;
1922}
1923
1924//---------------------------------------------------------------------------------------
1925
1927{
1928 GetDefResult result;
1929 if (input.memberName.empty()) return result;
1930 AUTO_TRACE("scopeName={},memberName={},forceEmptyScope={}",
1931 input.scopeName,input.memberName,input.forceEmptyScope);
1932
1933 //printf("@@ --- getDefsNew(%s,%s)-----------\n",qPrint(scName),qPrint(mbName));
1934 const Definition *scope = Doxygen::globalScope;
1935 SymbolResolver resolver;
1936 if (input.currentFile) resolver.setFileScope(input.currentFile);
1937 if (!input.scopeName.empty() && !input.forceEmptyScope)
1938 {
1939 scope = resolver.resolveSymbol(scope,input.scopeName);
1940 // A C++ module name does not introduce a scope for its exported class members.
1941 if (scope && scope->definitionType() == Definition::TypeModule)
1942 {
1943 if (const ClassDef *cd = getClass(input.scopeName)) scope = cd;
1944 }
1945 }
1946 if (scope==Doxygen::globalScope)
1947 {
1948 scope = input.currentFile;
1949 }
1950 //printf("@@ -> found scope scope=%s member=%s out=%s\n",qPrint(input.scopeName),qPrint(input.memberName),qPrint(scope?scope->name():""));
1951 //
1952 const Definition *symbol = resolver.resolveSymbol(scope,input.memberName,input.args,input.checkCV,input.insideCode,true);
1953 if (!symbol && input.allowCrossFileStatic)
1954 {
1955 DString memberName=input.memberName;
1956 DString explicitFile;
1957 size_t qualifierIndex=memberName.rfind("::");
1958 if (qualifierIndex!=DString::npos)
1959 {
1960 explicitFile=memberName.left(qualifierIndex);
1961 memberName=memberName.mid(qualifierIndex+2);
1962 std::string normalized=explicitFile.str();
1963 for (size_t i=0; i+1<normalized.size(); )
1964 {
1965 if (normalized[i]==':' && normalized[i+1]==':')
1966 {
1967 normalized.replace(i,2,".");
1968 i++;
1969 }
1970 else
1971 {
1972 i++;
1973 }
1974 }
1975 explicitFile=normalized.c_str();
1976 }
1977
1978 MemberDef *uniqueStatic=nullptr;
1979 const auto &range=Doxygen::symbolMap->find(memberName);
1980 for (Definition *candidate : range)
1981 {
1982 if (candidate->definitionType()!=Definition::TypeMember) continue;
1983 MemberDef *md=toMemberDef(candidate);
1984 if (!md->isStatic() || md->getClassDef()!=nullptr) continue;
1985 const FileDef *mdFile=md->getFileDef();
1986 if (!mdFile) continue;
1987 if (!explicitFile.empty())
1988 {
1989 DString fileName=mdFile->name();
1990 if (fileName!=explicitFile &&
1991 !fileName.endsWith("/"+explicitFile) &&
1992 !fileName.endsWith("\\"+explicitFile))
1993 {
1994 continue;
1995 }
1996 }
1997
1998 const Definition *resolved=md;
1999 if (explicitFile.empty())
2000 {
2001 SymbolResolver candidateResolver(mdFile);
2002 resolved=candidateResolver.resolveSymbol(Doxygen::globalScope,memberName,input.args,input.checkCV,input.insideCode,true);
2003 }
2004 if (resolved==md)
2005 {
2006 if (uniqueStatic && uniqueStatic!=md)
2007 {
2008 uniqueStatic=nullptr;
2009 break;
2010 }
2011 uniqueStatic=md;
2012 }
2013 }
2014 if (uniqueStatic)
2015 {
2016 symbol=uniqueStatic;
2017 }
2018 }
2019 //printf("@@ -> found symbol in=%s out=%s\n",qPrint(input.memberName),qPrint(symbol?symbol->qualifiedName():DString()));
2020 if (symbol && symbol->definitionType()==Definition::TypeMember)
2021 {
2022 result.md = toMemberDef(symbol);
2023 result.cd = result.md->getClassDef();
2024 if (result.cd==nullptr) result.nd = result.md->getNamespaceDef();
2025 if (result.cd==nullptr && result.nd==nullptr) result.fd = result.md->getFileDef();
2026 result.gd = result.md->getGroupDef();
2027 result.found = true;
2028 }
2029 else if (symbol && symbol->definitionType()==Definition::TypeClass)
2030 {
2031 result.cd = toClassDef(symbol);
2032 result.found = true;
2033 }
2034 else if (symbol && symbol->definitionType()==Definition::TypeNamespace)
2035 {
2036 result.nd = toNamespaceDef(symbol);
2037 result.found = true;
2038 }
2039 else if (symbol && symbol->definitionType()==Definition::TypeConcept)
2040 {
2041 result.cnd = toConceptDef(symbol);
2042 result.found = true;
2043 }
2044 else if (symbol && symbol->definitionType()==Definition::TypeModule)
2045 {
2046 result.modd = toModuleDef(symbol);
2047 result.found = true;
2048 }
2049 return result;
2050}
2051
2052
2053/*!
2054 * Searches for a scope definition given its name as a string via parameter
2055 * `scope`.
2056 *
2057 * The parameter `docScope` is a string representing the name of the scope in
2058 * which the `scope` string was found.
2059 *
2060 * The function returns true if the scope is known and documented or
2061 * false if it is not.
2062 * If true is returned exactly one of the parameter `cd`, `nd`
2063 * will be non-zero:
2064 * - if `cd` is non zero, the scope was a class pointed to by cd.
2065 * - if `nd` is non zero, the scope was a namespace pointed to by nd.
2066 */
2067static bool getScopeDefs(const DString &docScope,const DString &scope,
2068 ClassDef *&cd, ConceptDef *&cnd, NamespaceDef *&nd,ModuleDef *&modd)
2069{
2070 cd=nullptr;
2071 cnd=nullptr;
2072 nd=nullptr;
2073 modd=nullptr;
2074
2075 DString scopeName=scope;
2076 //printf("getScopeDefs: docScope='%s' scope='%s'\n",qPrint(docScope),qPrint(scope));
2077 if (scopeName.empty()) return false;
2078
2079 bool explicitGlobalScope=false;
2080 if (scopeName.at(0)==':' && scopeName.at(1)==':')
2081 {
2082 scopeName=scopeName.mid(2);
2083 explicitGlobalScope=true;
2084 }
2085 if (scopeName.empty())
2086 {
2087 return false;
2088 }
2089
2090 DString docScopeName=docScope;
2091 int scopeOffset=explicitGlobalScope ? 0 : static_cast<int>(docScopeName.length());
2092
2093 do // for each possible docScope (from largest to and including empty)
2094 {
2095 DString fullName=scopeName;
2096 if (scopeOffset>0) fullName.prepend(docScopeName.left(scopeOffset)+"::");
2097
2098 if (((cd=getClass(fullName)) || // normal class
2099 (cd=getClass(fullName+"-p")) // ObjC protocol
2100 ) && cd->isLinkable())
2101 {
2102 return true; // class link written => quit
2103 }
2104 else if ((nd=Doxygen::namespaceLinkedMap->find(fullName)) && nd->isLinkable())
2105 {
2106 return true; // namespace link written => quit
2107 }
2108 else if ((cnd=Doxygen::conceptLinkedMap->find(fullName)) && cnd->isLinkable())
2109 {
2110 return true; // concept link written => quit
2111 }
2112 else if ((modd=ModuleManager::instance().modules().find(fullName)) && modd->isLinkable())
2113 {
2114 return true; // module link written => quit
2115 }
2116 if (scopeOffset==0)
2117 {
2118 scopeOffset=-1;
2119 }
2120 else
2121 {
2122 size_t o = docScopeName.rfind("::",scopeOffset-1);
2123 scopeOffset = o!=DString::npos ? static_cast<int>(o) : 0;
2124 }
2125 } while (scopeOffset>=0);
2126
2127 return false;
2128}
2129
2130static bool isLowerCase(DString &s)
2131{
2132 if (s.empty()) return true;
2133 const char *p=s.data();
2134 int c=0;
2135 while ((c=static_cast<uint8_t>(*p++))) if (!islower(c)) return false;
2136 return true;
2137}
2138
2139bool resolveRef(/* in */ const DString &scName,
2140 /* in */ const DString &name,
2141 /* in */ bool inSeeBlock,
2142 /* out */ const Definition **resContext,
2143 /* out */ const MemberDef **resMember,
2144 /* in */ SrcLangExt lang,
2145 bool lookForSpecialization,
2146 const FileDef *currentFile,
2147 bool checkScope
2148 )
2149{
2150 AUTO_TRACE("scope={} name={} inSeeBlock={} lang={} lookForSpecialization={} currentFile={} checkScope={}",
2151 scName,name,inSeeBlock,lang,lookForSpecialization,currentFile ? currentFile->name() : "", checkScope);
2152 //printf("resolveRef(scope=%s,name=%s,inSeeBlock=%d)\n",qPrint(scName),qPrint(name),inSeeBlock);
2153 DString tsName = name;
2154 //bool memberScopeFirst = tsName.find('#')!=-1;
2155 DString fullName = substitute(tsName,"#","::");
2156 if (fullName.find("anonymous_namespace{")==DString::npos)
2157 {
2158 fullName = removeRedundantWhiteSpace(substitute(fullName,".","::",3));
2159 }
2160 else
2161 {
2162 fullName = removeRedundantWhiteSpace(fullName);
2163 }
2164
2165 size_t templStartPos;
2166 if (lang==SrcLangExt::CSharp && (templStartPos=fullName.find('<'))!=DString::npos)
2167 {
2168 size_t templEndPos = fullName.rfind('>');
2169 if (templEndPos!=DString::npos)
2170 {
2171 fullName = mangleCSharpGenericName(fullName.left(templEndPos+1))+fullName.mid(templEndPos+1);
2172 AUTO_TRACE_ADD("C# mangled name='{}'",fullName);
2173 }
2174 }
2175
2176 size_t bracePos = findParameterList(fullName);
2177 size_t endNamePos = bracePos!=DString::npos ? bracePos : fullName.length();
2178 size_t scopePos = fullName.rfind("::",endNamePos);
2179 bool explicitScope = fullName.startsWith("::") && // ::scope or #scope
2180 ((scopePos!=DString::npos && scopePos>2) || // ::N::A
2181 tsName.startsWith("::") || // ::foo in local scope
2182 scName==nullptr // #foo in global scope
2183 );
2184 bool allowTypeOnly=false;
2185
2186 // default result values
2187 *resContext=nullptr;
2188 *resMember=nullptr;
2189
2190 if (bracePos==DString::npos) // simple name
2191 {
2192 // the following if() was commented out for releases in the range
2193 // 1.5.2 to 1.6.1, but has been restored as a result of bug report 594787.
2194 if (!inSeeBlock && scopePos==DString::npos && isLowerCase(tsName))
2195 { // link to lower case only name => do not try to autolink
2196 AUTO_TRACE_ADD("false");
2197 return false;
2198 }
2199
2200 ClassDef *cd=nullptr;
2201 NamespaceDef *nd=nullptr;
2202 ConceptDef *cnd=nullptr;
2203 ModuleDef *modd=nullptr;
2204
2205 //printf("scName=%s fullName=%s\n",qPrint(scName),qPrint(fullName));
2206
2207 // check if this is a class or namespace reference
2208 if (scName!=fullName && getScopeDefs(scName,fullName,cd,cnd,nd,modd))
2209 {
2210 //printf("found scopeDef\n");
2211 if (cd) // scope matches that of a class
2212 {
2213 *resContext = cd;
2214 }
2215 else if (cnd)
2216 {
2217 *resContext = cnd;
2218 }
2219 else if (modd)
2220 {
2221 *resContext = modd;
2222 }
2223 else // scope matches that of a namespace
2224 {
2225 ASSERT(nd!=nullptr);
2226 *resContext = nd;
2227 }
2228 AUTO_TRACE_ADD("true");
2229 return true;
2230 }
2231 else if (scName==fullName || (!inSeeBlock && scopePos==DString::npos))
2232 // nothing to link => output plain text
2233 {
2234 //printf("found scName=%s fullName=%s scName==fullName=%d "
2235 // "inSeeBlock=%d scopePos=%d!\n",
2236 // qPrint(scName),qPrint(fullName),scName==fullName,inSeeBlock,scopePos);
2237
2238 // at this point we have a bare word that is not a class or namespace
2239 // we should also allow typedefs or enums to be linked, but not for instance member
2240 // functions, otherwise 'Foo' would always link to the 'Foo()' constructor instead of the
2241 // 'Foo' class. So we use this flag as a filter.
2242 allowTypeOnly=true;
2243 }
2244
2245 // continue search...
2246 }
2247
2248 // extract userscope+name
2249 DString nameStr=fullName.left(endNamePos);
2250 if (explicitScope) nameStr=nameStr.mid(2);
2251
2252
2253 // extract arguments
2254 DString argsStr;
2255 if (bracePos!=DString::npos) argsStr=fullName.mid(bracePos);
2256
2257 // strip template specifier
2258 // TODO: match against the correct partial template instantiation
2259 size_t templPos = nameStr.find('<');
2260 bool tryUnspecializedVersion = false;
2261 if (templPos!=DString::npos && nameStr.find("operator")==DString::npos)
2262 {
2263 size_t endTemplPos=nameStr.rfind('>');
2264 if (endTemplPos!=DString::npos)
2265 {
2266 if (!lookForSpecialization)
2267 {
2268 nameStr=nameStr.left(templPos)+nameStr.mid(endTemplPos+1);
2269 }
2270 else
2271 {
2272 tryUnspecializedVersion = true;
2273 }
2274 }
2275 }
2276
2277 DString scopeStr=scName;
2278 if (!explicitScope && nameStr.length()>scopeStr.length() && leftScopeMatch(scopeStr,nameStr))
2279 {
2280 nameStr=nameStr.mid(scopeStr.length()+2);
2281 }
2282
2283 const GroupDef *gd = nullptr;
2284 const ConceptDef *cnd = nullptr;
2285 const ModuleDef *modd = nullptr;
2286
2287 // check if nameStr is a member or global.
2288 //printf("getDefs(scope=%s,name=%s,args=%s checkScope=%d)\n",
2289 // qPrint(scopeStr), qPrint(nameStr), qPrint(argsStr),checkScope);
2290 GetDefInput input(scopeStr,nameStr,argsStr);
2291 input.forceEmptyScope = explicitScope;
2292 input.currentFile = currentFile;
2293 input.checkCV = true;
2294 GetDefResult result = getDefs(input);
2295 if (result.found)
2296 {
2297 //printf("after getDefs checkScope=%d nameStr=%s\n",checkScope,qPrint(nameStr));
2298 size_t np = nameStr.find("::");
2299 if (checkScope && result.md && result.md->getOuterScope()==Doxygen::globalScope &&
2300 !result.md->isStrongEnumValue() &&
2301 (!scopeStr.empty() || (np!=DString::npos && np>0)))
2302 {
2303 // we did find a member, but it is a global one while we were explicitly
2304 // looking for a scoped variable. See bug 616387 for an example why this check is needed.
2305 // note we do need to support autolinking to "::symbol" hence the >0
2306 //printf("not global member!\n");
2307 *resContext=nullptr;
2308 *resMember=nullptr;
2309 AUTO_TRACE_ADD("false");
2310 return false;
2311 }
2312 //printf("after getDefs md=%p cd=%p fd=%p nd=%p gd=%p\n",md,cd,fd,nd,gd);
2313 if (result.md)
2314 {
2315 if (!allowTypeOnly || result.md->isTypedef() || result.md->isEnumerate())
2316 {
2317 *resMember=result.md;
2318 *resContext=result.md;
2319 }
2320 else // md is not a type, but we explicitly expect one
2321 {
2322 *resContext=nullptr;
2323 *resMember=nullptr;
2324 AUTO_TRACE_ADD("false");
2325 return false;
2326 }
2327 }
2328 else if (result.cd) *resContext=result.cd;
2329 else if (result.nd) *resContext=result.nd;
2330 else if (result.fd) *resContext=result.fd;
2331 else if (result.gd) *resContext=result.gd;
2332 else if (result.cnd) *resContext=result.cnd;
2333 else if (result.modd) *resContext=result.modd;
2334 else
2335 {
2336 *resContext=nullptr; *resMember=nullptr;
2337 AUTO_TRACE_ADD("false");
2338 return false;
2339 }
2340 //printf("member=%s (md=%p) anchor=%s linkable()=%d context=%s\n",
2341 // qPrint(md->name()), md, qPrint(md->anchor()), md->isLinkable(), qPrint((*resContext)->name()));
2342 AUTO_TRACE_ADD("true");
2343 return true;
2344 }
2345 else if (inSeeBlock && !nameStr.empty() && (gd=Doxygen::groupLinkedMap->find(nameStr)))
2346 { // group link
2347 *resContext=gd;
2348 AUTO_TRACE_ADD("true");
2349 return true;
2350 }
2351 else if ((cnd=Doxygen::conceptLinkedMap->find(nameStr)))
2352 {
2353 *resContext=cnd;
2354 AUTO_TRACE_ADD("true");
2355 return true;
2356 }
2357 else if ((modd=ModuleManager::instance().modules().find(nameStr)))
2358 {
2359 *resContext=modd;
2360 AUTO_TRACE_ADD("true");
2361 return true;
2362 }
2363 else if (tsName.find('.')!=DString::npos) // maybe a link to a file
2364 {
2365 bool ambig = false;
2366 const FileDef *fd=Doxygen::inputNameLinkedMap->findFileDef(tsName,ambig);
2367 if (fd && !ambig)
2368 {
2369 *resContext=fd;
2370 AUTO_TRACE_ADD("true");
2371 return true;
2372 }
2373 }
2374
2375 if (tryUnspecializedVersion)
2376 {
2377 bool b = resolveRef(scName,name,inSeeBlock,resContext,resMember,lang,false,nullptr,checkScope);
2378 AUTO_TRACE_ADD("{}",b);
2379 return b;
2380 }
2381 if (bracePos!=DString::npos) // Try without parameters as well, could be a constructor invocation
2382 {
2383 *resContext=getClass(fullName.left(bracePos));
2384 if (*resContext)
2385 {
2386 AUTO_TRACE_ADD("true");
2387 return true;
2388 }
2389 }
2390 //printf("resolveRef: %s not found!\n",qPrint(name));
2391
2392 AUTO_TRACE_ADD("false");
2393 return false;
2394}
2395
2396DString linkToText(SrcLangExt lang,const DString &link,bool ignoreDots)
2397{
2398 //bool optimizeOutputJava = Config_getBool(OPTIMIZE_OUTPUT_JAVA);
2399 DString result=link;
2400 if (!result.empty())
2401 {
2402 // replace # by ::
2403 result=substitute(result,"#","::");
2404 // replace . by ::
2405 if (!ignoreDots && result.find('<')==DString::npos) result=substitute(result,".","::",3);
2406 // strip leading :: prefix if present
2407 if (result.at(0)==':' && result.at(1)==':')
2408 {
2409 result=result.mid(2);
2410 }
2412 if (sep!="::")
2413 {
2414 result=substitute(result,"::",sep);
2415 }
2416 }
2417 //printf("linkToText(%s,lang=%d)=%s\n",qPrint(link),lang,qPrint(result));
2418 return result;
2419}
2420
2421static const DirDef *resolveDirLink(const DString &linkRef)
2422{
2423 const DirDef *dd = Doxygen::dirLinkedMap->find(FileInfo(linkRef.str()).absFilePath()+"/");
2424 //printf("resolveDirLink(%s) -> %s\n",qPrint(linkRef),dd?qPrint(dd->name()):"<none>");
2425 if (dd==nullptr)
2426 {
2427 StringVector stripPaths = Config_getList(STRIP_FROM_PATH);
2428 for (const auto &path : stripPaths)
2429 {
2430 FileInfo fi(path+linkRef.str());
2431 //printf(" trying to strip path '%s' from linkRef '%s' fi='%s'\n",qPrint(path),qPrint(linkRef),qPrint(fi.absFilePath()));
2432 dd = Doxygen::dirLinkedMap->find(fi.absFilePath()+"/");
2433 if (dd) break;
2434 }
2435 }
2436 return dd;
2437}
2438
2439bool resolveLink(/* in */ const DString &scName,
2440 /* in */ const DString &lr,
2441 /* in */ bool /*inSeeBlock*/,
2442 /* out */ const Definition **resContext,
2443 /* out */ DString &resAnchor,
2444 /* in */ SrcLangExt lang,
2445 /* in */ const DString &prefix,
2446 /* in */ const FileDef *currentFile
2447 )
2448{
2449 *resContext=nullptr;
2450
2451 DString linkRef=lr;
2452 if (lang==SrcLangExt::CSharp)
2453 {
2454 linkRef = mangleCSharpGenericName(linkRef);
2455 }
2456 DString linkRefWithoutTemplates = stripTemplateSpecifiersFromScope(linkRef,false);
2457 AUTO_TRACE("scName='{}',ref='{}'",scName,lr);
2458 const FileDef *fd = nullptr;
2459 const GroupDef *gd = nullptr;
2460 const PageDef *pd = nullptr;
2461 const ClassDef *cd = nullptr;
2462 const DirDef *dir = nullptr;
2463 const ConceptDef *cnd = nullptr;
2464 const ModuleDef *modd = nullptr;
2465 const NamespaceDef *nd = nullptr;
2466 const SectionInfo *si = nullptr;
2467 bool ambig = false;
2468 if (linkRef.empty()) // no reference name!
2469 {
2470 AUTO_TRACE_EXIT("no_ref");
2471 return false;
2472 }
2473 else if ((pd=Doxygen::pageLinkedMap->find(linkRef))) // link to a page
2474 {
2475 gd = pd->getGroupDef();
2476 if (gd)
2477 {
2478 if (!pd->name().empty()) si=SectionManager::instance().find(pd->name());
2479 *resContext=gd;
2480 if (si) resAnchor = si->label();
2481 }
2482 else
2483 {
2484 *resContext=pd;
2485 }
2486 AUTO_TRACE_EXIT("page");
2487 return true;
2488 }
2489 else if ((si=SectionManager::instance().find(prefix+linkRef)))
2490 {
2491 *resContext=si->definition();
2492 resAnchor = si->label();
2493 AUTO_TRACE_EXIT("section anchor={} def={}",resAnchor,si->definition()?si->definition()->name():"<none>");
2494 return true;
2495 }
2496 else if (!prefix.empty() && (si=SectionManager::instance().find(linkRef)))
2497 {
2498 *resContext=si->definition();
2499 resAnchor = si->label();
2500 AUTO_TRACE_EXIT("section anchor={} def={}",resAnchor,si->definition()?si->definition()->name():"<none>");
2501 return true;
2502 }
2503 else if ((pd=Doxygen::exampleLinkedMap->find(linkRef))) // link to an example
2504 {
2505 *resContext=pd;
2506 AUTO_TRACE_EXIT("example");
2507 return true;
2508 }
2509 else if ((gd=Doxygen::groupLinkedMap->find(linkRef))) // link to a group
2510 {
2511 *resContext=gd;
2512 AUTO_TRACE_EXIT("group");
2513 return true;
2514 }
2515 else if ((fd=Doxygen::inputNameLinkedMap->findFileDef(linkRef,ambig)) // file link
2516 && fd->isLinkable())
2517 {
2518 *resContext=fd;
2519 AUTO_TRACE_EXIT("file");
2520 return true;
2521 }
2522 else if ((cd=getClass(linkRef))) // class link
2523 {
2524 *resContext=cd;
2525 resAnchor=cd->anchor();
2526 AUTO_TRACE_EXIT("class");
2527 return true;
2528 }
2529 else if (lang==SrcLangExt::Java &&
2530 (cd=getClass(linkRefWithoutTemplates))) // Java generic class link
2531 {
2532 *resContext=cd;
2533 resAnchor=cd->anchor();
2534 AUTO_TRACE_EXIT("generic");
2535 return true;
2536 }
2537 else if ((cd=getClass(linkRef+"-p"))) // Obj-C protocol link
2538 {
2539 *resContext=cd;
2540 resAnchor=cd->anchor();
2541 AUTO_TRACE_EXIT("protocol");
2542 return true;
2543 }
2544 else if ((cnd=getConcept(linkRef))) // C++20 concept definition
2545 {
2546 *resContext=cnd;
2547 resAnchor=cnd->anchor();
2548 AUTO_TRACE_EXIT("concept");
2549 return true;
2550 }
2551 else if ((modd=ModuleManager::instance().modules().find(linkRef)))
2552 {
2553 *resContext=modd;
2554 resAnchor=modd->anchor();
2555 AUTO_TRACE_EXIT("module");
2556 return true;
2557 }
2558 else if ((nd=Doxygen::namespaceLinkedMap->find(linkRef)))
2559 {
2560 *resContext=nd;
2561 AUTO_TRACE_EXIT("namespace");
2562 return true;
2563 }
2564 else if ((dir=resolveDirLink(linkRef)) && dir->isLinkable())
2565 {
2566 *resContext=dir;
2567 AUTO_TRACE_EXIT("directory");
2568 return true;
2569 }
2570 else // probably a member reference
2571 {
2572 const MemberDef *md = nullptr;
2573 bool res = resolveRef(scName,lr,true,resContext,&md,lang,true,currentFile);
2574 if (md) resAnchor=md->anchor();
2575 AUTO_TRACE_EXIT("member? res={}",res);
2576 return res;
2577 }
2578}
2579
2580//----------------------------------------------------------------------
2581
2582
2583DString findExampleFilePath(const DString &file,bool &ambig)
2584{
2585 ambig=false;
2586 DString result;
2587 bool found=false;
2588 if (!found)
2589 {
2590 FileInfo fi(file.str());
2591 if (fi.exists())
2592 {
2593 result=fi.absFilePath();
2594 found=true;
2595 }
2596 }
2597 if (!found)
2598 {
2599 StringVector examplePathList = Config_getList(EXAMPLE_PATH);
2600 for (const auto &s : examplePathList)
2601 {
2602 std::string absFileName = s+(Portable::pathSeparator()+file).str();
2603 FileInfo fi(absFileName);
2604 if (fi.exists())
2605 {
2606 result=fi.absFilePath();
2607 found=true;
2608 }
2609 }
2610 }
2611
2612 if (!found)
2613 {
2614 // as a fallback we also look in the exampleNameDict
2616 if (fd && !ambig)
2617 {
2618 result=fd->absFilePath();
2619 }
2620 }
2621 return result;
2622}
2623
2624//----------------------------------------------------------------------
2625
2627{
2628 std::string substRes;
2629 int line = 1;
2630 const char *p = s.data();
2631 if (p)
2632 {
2633 // reserve some room for expansion
2634 substRes.reserve(s.length()+1024);
2635 char c = 0;
2636 while ((c=*p))
2637 {
2638 bool found = false;
2639 if (c=='$')
2640 {
2641 for (const auto &kw : keywords)
2642 {
2643 size_t keyLen = dstrlen(kw.keyword);
2644 if (dstrncmp(p,kw.keyword,keyLen)==0)
2645 {
2646 const char *startArg = p+keyLen;
2647 bool expectParam = std::holds_alternative<KeywordSubstitution::GetValueWithParam>(kw.getValueVariant);
2648 //printf("%s: expectParam=%d *startArg=%c\n",kw.keyword,expectParam,*startArg);
2649 if (expectParam && *startArg=='(') // $key(value)
2650 {
2651 size_t j=1;
2652 const char *endArg = nullptr;
2653 while ((c=*(startArg+j)) && c!=')' && c!='\n' && c!=0) j++;
2654 if (c==')') endArg=startArg+j;
2655 if (endArg)
2656 {
2657 DString value = DString(startArg+1).left(endArg-startArg-1);
2658 auto &&getValue = std::get<KeywordSubstitution::GetValueWithParam>(kw.getValueVariant);
2659 substRes+=getValue(value).str();
2660 p=endArg+1;
2661 //printf("found '%s'->'%s'\n",kw.keyword,qPrint(getValue(value)));
2662 }
2663 else
2664 {
2665 //printf("missing argument\n");
2666 warn(file,line,"Missing argument for '{}'",kw.keyword);
2667 p+=keyLen;
2668 }
2669 }
2670 else if (!expectParam) // $key
2671 {
2672 auto &&getValue = std::get<KeywordSubstitution::GetValue>(kw.getValueVariant);
2673 substRes+=getValue().str();
2674 //printf("found '%s'->'%s'\n",kw.keyword,qPrint(getValue()));
2675 p+=keyLen;
2676 }
2677 else
2678 {
2679 //printf("%s %d Expected arguments, none specified '%s'\n",qPrint(file), line, qPrint(kw.keyword));
2680 warn(file,line,"Expected arguments for '{}' but none were specified",kw.keyword);
2681 p+=keyLen;
2682 }
2683 found = true;
2684 break;
2685 }
2686 }
2687 }
2688 if (!found) // copy
2689 {
2690 if (c=='\n') line++;
2691 substRes+=c;
2692 p++;
2693 }
2694 }
2695 }
2696 return substRes;
2697}
2698
2700{
2701 // get the current date and time
2702 std::tm dat{};
2703 int specFormat=0;
2704 DString specDate = "";
2705 DString err = dateTimeFromString(specDate,dat,specFormat);
2706
2707 // do the conversion
2708 int usedFormat=0;
2709 return formatDateTime(fmt,dat,usedFormat);
2710}
2711
2713{
2714 DString projectLogo = Config_getString(PROJECT_LOGO);
2715 if (!projectLogo.empty())
2716 {
2717 // check for optional width= and height= specifier
2718 if (size_t wi = projectLogo.find(" width="); wi!=DString::npos) // and strip them
2719 {
2720 projectLogo = projectLogo.left(wi);
2721 }
2722 if (size_t hi = projectLogo.find(" height="); hi!=DString::npos)
2723 {
2724 projectLogo = projectLogo.left(hi);
2725 }
2726 }
2727 //printf("projectlogo='%s'\n",qPrint(projectLogo));
2728 return projectLogo;
2729}
2730
2732{
2733 DString sizeVal;
2734 DString projectLogo = Config_getString(PROJECT_LOGO);
2735 if (!projectLogo.empty())
2736 {
2737 auto extractDimension = [&projectLogo](const char *startMarker,size_t startPos,size_t endPos) -> DString
2738 {
2739 DString result = projectLogo.mid(startPos,endPos-startPos).stripWhiteSpace().quoted();
2740 if (result.length()>=2 && result.at(0)!='"' && result.at(result.length()-1)!='"')
2741 {
2742 result="\""+result+"\"";
2743 }
2744 result.prepend(startMarker);
2745 return result;
2746 };
2747 // check for optional width= and height= specifier
2748 size_t wi = projectLogo.find(" width=");
2749 size_t hi = projectLogo.find(" height=");
2750 if (wi!=DString::npos && hi!=DString::npos)
2751 {
2752 if (wi<hi) // "... width=x height=y..."
2753 {
2754 sizeVal = extractDimension(" width=", wi+7, hi) + " "
2755 + extractDimension(" height=", hi+8, projectLogo.length());
2756 }
2757 else // "... height=y width=x..."
2758 {
2759 sizeVal = extractDimension(" height=", hi+8, wi) + " "
2760 + extractDimension(" width=", wi+7, projectLogo.length());
2761 }
2762 }
2763 else if (wi!=DString::npos) // ... width=x..."
2764 {
2765 sizeVal = extractDimension(" width=", wi+7, projectLogo.length());
2766 }
2767 else if (hi!=DString::npos) // ... height=x..."
2768 {
2769 sizeVal = extractDimension(" height=", hi+8, projectLogo.length());
2770 }
2771 }
2772 //printf("projectsize='%s'\n",qPrint(sizeVal));
2773 return sizeVal;
2774}
2775
2776
2777//----------------------------------------------------------------------
2778
2779/*! Returns the character index within \a name of the first prefix
2780 * in Config_getList(IGNORE_PREFIX) that matches \a name at the left hand side,
2781 * or zero if no match was found
2782 */
2783int getPrefixIndex(const DString &name)
2784{
2785 if (name.empty()) return 0;
2786 int result=0;
2787 StringVector sl = Config_getList(IGNORE_PREFIX);
2788 for (const auto &s : sl)
2789 {
2790 const char *ps=s.c_str();
2791 const char *pd=name.data();
2792 int i=0;
2793 while (*ps!=0 && *pd!=0 && *ps==*pd)
2794 {
2795 ps++;
2796 pd++;
2797 i++;
2798 }
2799 if (*ps==0 && *pd!=0)
2800 {
2801 result=i;
2802 break;
2803 }
2804 }
2805 if (result<static_cast<int>(name.length())-1 && name.at(result)=='[') result++; // for e.g. [union] return u
2806 return result;
2807}
2808
2809//----------------------------------------------------------------------------
2810
2812{
2813 auto caseSenseNames = Config_getEnum(CASE_SENSE_NAMES);
2814
2815 if (caseSenseNames == CASE_SENSE_NAMES_t::YES) return true;
2816 else if (caseSenseNames == CASE_SENSE_NAMES_t::NO) return false;
2818}
2819
2820DString escapeCharsInString(const DString &name,bool allowDots,bool allowUnderscore)
2821{
2822 if (name.empty()) return name;
2823 bool caseSenseNames = useCaseSenseNames();
2824 bool allowUnicodeNames = Config_getBool(ALLOW_UNICODE_NAMES);
2825 DString result;
2826 result.reserve(name.length()+8);
2827 signed char c = 0;
2828 const char *p=name.data();
2829 while ((c=*p++)!=0)
2830 {
2831 switch(c)
2832 {
2833 case '_': if (allowUnderscore) result+='_'; else result+="__"; break;
2834 case '-': result+='-'; break;
2835 case ':': result+="_1"; break;
2836 case '/': result+="_2"; break;
2837 case '<': result+="_3"; break;
2838 case '>': result+="_4"; break;
2839 case '*': result+="_5"; break;
2840 case '&': result+="_6"; break;
2841 case '|': result+="_7"; break;
2842 case '.': if (allowDots) result+='.'; else result+="_8"; break;
2843 case '!': result+="_9"; break;
2844 case ',': result+="_00"; break;
2845 case ' ': result+="_01"; break;
2846 case '{': result+="_02"; break;
2847 case '}': result+="_03"; break;
2848 case '?': result+="_04"; break;
2849 case '^': result+="_05"; break;
2850 case '%': result+="_06"; break;
2851 case '(': result+="_07"; break;
2852 case ')': result+="_08"; break;
2853 case '+': result+="_09"; break;
2854 case '=': result+="_0a"; break;
2855 case '$': result+="_0b"; break;
2856 case '\\': result+="_0c"; break;
2857 case '@': result+="_0d"; break;
2858 case ']': result+="_0e"; break;
2859 case '[': result+="_0f"; break;
2860 case '#': result+="_0g"; break;
2861 case '"': result+="_0h"; break;
2862 case '~': result+="_0i"; break;
2863 case '\'': result+="_0j"; break;
2864 case ';': result+="_0k"; break;
2865 case '`': result+="_0l"; break;
2866 default:
2867 if (c<0)
2868 {
2869 bool doEscape = true;
2870 if (allowUnicodeNames)
2871 {
2872 int charLen = getUTF8CharNumBytes(c);
2873 if (charLen>0)
2874 {
2875 result+=DString(p-1,charLen);
2876 p+=charLen;
2877 doEscape = false;
2878 }
2879 }
2880 if (doEscape) // not a valid unicode char or escaping needed
2881 {
2882 char ids[5];
2883 unsigned char id = static_cast<unsigned char>(c);
2884 ids[0]='_';
2885 ids[1]='x';
2886 ids[2]=hex[id>>4];
2887 ids[3]=hex[id&0xF];
2888 ids[4]=0;
2889 result+=ids;
2890 }
2891 }
2892 else if (caseSenseNames || !isupper(c))
2893 {
2894 result+=c;
2895 }
2896 else
2897 {
2898 result+='_';
2899 result+=static_cast<char>(tolower(c));
2900 }
2901 break;
2902 }
2903 }
2904 return result;
2905}
2906
2908{
2909 if (s.empty()) return s;
2910 bool caseSenseNames = useCaseSenseNames();
2911 DString result;
2912 result.reserve(s.length());
2913 const char *p = s.data();
2914 if (p)
2915 {
2916 char c = 0;
2917 while ((c=*p++))
2918 {
2919 if (c=='_') // 2 or 3 character escape
2920 {
2921 switch (*p)
2922 {
2923 case '_': result+=c; p++; break; // __ -> '_'
2924 case '1': result+=':'; p++; break; // _1 -> ':'
2925 case '2': result+='/'; p++; break; // _2 -> '/'
2926 case '3': result+='<'; p++; break; // _3 -> '<'
2927 case '4': result+='>'; p++; break; // _4 -> '>'
2928 case '5': result+='*'; p++; break; // _5 -> '*'
2929 case '6': result+='&'; p++; break; // _6 -> '&'
2930 case '7': result+='|'; p++; break; // _7 -> '|'
2931 case '8': result+='.'; p++; break; // _8 -> '.'
2932 case '9': result+='!'; p++; break; // _9 -> '!'
2933 case '0': // 3 character escape
2934 switch (*(p+1))
2935 {
2936 case '0': result+=','; p+=2; break; // _00 -> ','
2937 case '1': result+=' '; p+=2; break; // _01 -> ' '
2938 case '2': result+='{'; p+=2; break; // _02 -> '{'
2939 case '3': result+='}'; p+=2; break; // _03 -> '}'
2940 case '4': result+='?'; p+=2; break; // _04 -> '?'
2941 case '5': result+='^'; p+=2; break; // _05 -> '^'
2942 case '6': result+='%'; p+=2; break; // _06 -> '%'
2943 case '7': result+='('; p+=2; break; // _07 -> '('
2944 case '8': result+=')'; p+=2; break; // _08 -> ')'
2945 case '9': result+='+'; p+=2; break; // _09 -> '+'
2946 case 'a': result+='='; p+=2; break; // _0a -> '='
2947 case 'b': result+='$'; p+=2; break; // _0b -> '$'
2948 case 'c': result+='\\'; p+=2; break;// _0c -> '\'
2949 case 'd': result+='@'; p+=2; break; // _0d -> '@'
2950 case 'e': result+=']'; p+=2; break; // _0e -> ']'
2951 case 'f': result+='['; p+=2; break; // _0f -> '['
2952 case 'g': result+='#'; p+=2; break; // _0g -> '#'
2953 case 'h': result+='"'; p+=2; break; // _0h -> '"'
2954 case 'i': result+='~'; p+=2; break; // _0i -> '~'
2955 case 'j': result+='\''; p+=2; break;// _0j -> '\'
2956 case 'k': result+=';'; p+=2; break; // _0k -> ';'
2957 case 'l': result+='`'; p+=2; break; // _0l -> '`'
2958 default: // unknown escape, just pass underscore character as-is
2959 result+=c;
2960 break;
2961 }
2962 break;
2963 default:
2964 if (!caseSenseNames && c>='a' && c<='z') // lower to upper case escape, _a -> 'A'
2965 {
2966 result+=static_cast<char>(toupper(*p));
2967 p++;
2968 }
2969 else // unknown escape, pass underscore character as-is
2970 {
2971 result+=c;
2972 }
2973 break;
2974 }
2975 }
2976 else // normal character; pass as is
2977 {
2978 result+=c;
2979 }
2980 }
2981 }
2982 return result;
2983}
2984
2985static std::unordered_map<std::string,int> g_usedNames;
2986static std::mutex g_usedNamesMutex;
2987static int g_usedNamesCount=1;
2988
2989
2990
2991/*! This function determines the file name on disk of an item
2992 * given its name, which could be a class name with template
2993 * arguments, so special characters need to be escaped.
2994 */
2995DString convertNameToFile(const DString &name,bool allowDots,bool allowUnderscore)
2996{
2997 if (name.empty()) return name;
2998 bool shortNames = Config_getBool(SHORT_NAMES);
2999 bool createSubdirs = Config_getBool(CREATE_SUBDIRS);
3000 DString result;
3001 if (shortNames) // use short names only
3002 {
3003 std::lock_guard<std::mutex> lock(g_usedNamesMutex);
3004 auto kv = g_usedNames.find(name.str());
3005 uint32_t num=0;
3006 if (kv!=g_usedNames.end())
3007 {
3008 num = kv->second;
3009 }
3010 else
3011 {
3012 num = g_usedNamesCount;
3013 g_usedNames.emplace(name.str(),g_usedNamesCount++);
3014 }
3015 result.sprintf("a%05d",num);
3016 }
3017 else // long names
3018 {
3019 result=escapeCharsInString(name,allowDots,allowUnderscore);
3020 size_t resultLen = result.length();
3021 if (resultLen>=128) // prevent names that cannot be created!
3022 {
3023 // third algorithm based on MD5 hash
3024 result=result.left(128-32)+md5str(result.view());
3025 }
3026 }
3027 if (createSubdirs)
3028 {
3029 int l1Dir=0,l2Dir=0;
3030 int createSubdirsLevel = Config_getInt(CREATE_SUBDIRS_LEVEL);
3031 int createSubdirsBitmaskL2 = (1<<createSubdirsLevel)-1;
3032
3033 // compute md5 hash to determine sub directory to use
3034 auto md5_sig = md5hash(result.view());
3035 l1Dir = md5_sig[14] & 0xf;
3036 l2Dir = md5_sig[15] & createSubdirsBitmaskL2;
3037
3038 result.prepend(DString().sprintf("d%x/d%02x/",l1Dir,l2Dir));
3039 }
3040 //printf("*** convertNameToFile(%s)->%s\n",qPrint(name),qPrint(result));
3041 return result;
3042}
3043
3045{
3046 DString result;
3047 if (Config_getBool(CREATE_SUBDIRS))
3048 {
3049 if (name.empty())
3050 {
3051 return REL_PATH_TO_ROOT;
3052 }
3053 else if (size_t i = name.rfind('/'); i!=DString::npos)
3054 {
3055 result=REL_PATH_TO_ROOT;
3056 }
3057 }
3058 return result;
3059}
3060
3061DString determineAbsoluteIncludeName(const DString &curFile,const DString &incFileName)
3062{
3063 bool searchIncludes = Config_getBool(SEARCH_INCLUDES);
3064 DString absIncFileName = incFileName;
3065 FileInfo fi(curFile.str());
3066 if (fi.exists())
3067 {
3068 DString absName = fi.dirPath(true)+"/"+incFileName;
3069 FileInfo fi2(absName.str());
3070 if (fi2.exists())
3071 {
3072 absIncFileName=fi2.absFilePath();
3073 }
3074 else if (searchIncludes) // search in INCLUDE_PATH as well
3075 {
3076 StringVector includePath = Config_getList(INCLUDE_PATH);
3077 for (const auto &incPath : includePath)
3078 {
3079 FileInfo fi3(incPath);
3080 if (fi3.exists() && fi3.isDir())
3081 {
3082 absName = fi3.absFilePath()+"/"+incFileName;
3083 //printf("trying absName=%s\n",qPrint(absName));
3084 FileInfo fi4(absName.str());
3085 if (fi4.exists())
3086 {
3087 absIncFileName=fi4.absFilePath();
3088 break;
3089 }
3090 //printf( "absIncFileName = %s\n", qPrint(absIncFileName) );
3091 }
3092 }
3093 }
3094 //printf( "absIncFileName = %s\n", qPrint(absIncFileName) );
3095 }
3096 return absIncFileName;
3097}
3098
3099
3100
3101void createSubDirs(const Dir &d)
3102{
3103 if (Config_getBool(CREATE_SUBDIRS))
3104 {
3105 // create up to 4096 subdirectories
3106 int createSubdirsLevelPow2 = 1 << Config_getInt(CREATE_SUBDIRS_LEVEL);
3107 for (int l1=0; l1<16; l1++)
3108 {
3109 DString subdir;
3110 subdir.sprintf("d%x",l1);
3111 if (!d.exists(subdir.str()) && !d.mkdir(subdir.str()))
3112 {
3113 term("Failed to create output directory '{}'\n",subdir);
3114 }
3115 for (int l2=0; l2<createSubdirsLevelPow2; l2++)
3116 {
3117 DString subsubdir;
3118 subsubdir.sprintf("d%x/d%02x",l1,l2);
3119 if (!d.exists(subsubdir.str()) && !d.mkdir(subsubdir.str()))
3120 {
3121 term("Failed to create output directory '{}'\n",subsubdir);
3122 }
3123 }
3124 }
3125 }
3126}
3127
3128void clearSubDirs(const Dir &d)
3129{
3130 if (Config_getBool(CREATE_SUBDIRS))
3131 {
3132 // remove empty subdirectories
3133 int createSubdirsLevelPow2 = 1 << Config_getInt(CREATE_SUBDIRS_LEVEL);
3134 for (int l1=0;l1<16;l1++)
3135 {
3136 DString subdir;
3137 subdir.sprintf("d%x",l1);
3138 for (int l2=0; l2 < createSubdirsLevelPow2; l2++)
3139 {
3140 DString subsubdir;
3141 subsubdir.sprintf("d%x/d%02x",l1,l2);
3142 if (d.exists(subsubdir.str()) && d.empty(subsubdir.str()))
3143 {
3144 d.rmdir(subsubdir.str());
3145 }
3146 }
3147 if (d.exists(subdir.str()) && d.empty(subdir.str()))
3148 {
3149 d.rmdir(subdir.str());
3150 }
3151 }
3152 }
3153}
3154
3155/*! Input is a scopeName, output is the scopename split into a
3156 * namespace part (as large as possible) and a classname part.
3157 */
3158void extractNamespaceName(const DString &scopeName,
3159 DString &className,DString &namespaceName,
3160 bool allowEmptyClass)
3161{
3162 DString clName=scopeName;
3163 NamespaceDef *nd = nullptr;
3164 size_t i=0;
3165 int p=0;
3166 if (!clName.empty() && (nd=getResolvedNamespace(clName)) && getClass(clName)==nullptr)
3167 { // the whole name is a namespace (and not a class)
3168 namespaceName=nd->name();
3169 className.clear();
3170 goto done;
3171 }
3172 p=static_cast<int>(clName.length())-2;
3173 while (p>=0 && (i=clName.rfind("::",p))!=DString::npos)
3174 // see if the first part is a namespace (and not a class)
3175 {
3176 //printf("Trying %s\n",qPrint(clName.left(i)));
3177 if (i>0 && (nd=getResolvedNamespace(clName.left(i))) && getClass(clName.left(i))==nullptr)
3178 {
3179 //printf("found!\n");
3180 namespaceName=nd->name();
3181 className=clName.mid(i+2);
3182 goto done;
3183 }
3184 p=static_cast<int>(i)-2; // try a smaller piece of the scope
3185 }
3186 //printf("not found!\n");
3187
3188 // not found, so we just have to guess.
3189 className=scopeName;
3190 namespaceName.clear();
3191
3192done:
3193 if (className.empty() && !namespaceName.empty() && !allowEmptyClass)
3194 {
3195 // class and namespace with the same name, correct to return the class.
3196 className=namespaceName;
3197 namespaceName.clear();
3198 }
3199 //printf("extractNamespace '%s' => '%s|%s'\n",qPrint(scopeName),
3200 // qPrint(className),qPrint(namespaceName));
3201 if (className.endsWith("-p"))
3202 {
3203 className = className.left(className.length()-2);
3204 }
3205 return;
3206}
3207
3209{
3210 DString result=scope;
3211 if (!templ.empty() && scope.find('<')==DString::npos)
3212 {
3213 size_t si=0, pi=0;
3214 ClassDef *cd=nullptr;
3215 while (
3216 (si=scope.find("::",pi))!=DString::npos && !getClass(scope.left(si)+templ) &&
3217 ((cd=getClass(scope.left(si)))==nullptr || cd->templateArguments().empty())
3218 )
3219 {
3220 //printf("Tried '%s'\n",qPrint((scope.left(si)+templ)));
3221 pi=si+2;
3222 }
3223 if (si==DString::npos) // not nested => append template specifier
3224 {
3225 result+=templ;
3226 }
3227 else // nested => insert template specifier before after first class name
3228 {
3229 result=scope.left(si) + templ + scope.mid(si);
3230 }
3231 }
3232 //printf("insertTemplateSpecifierInScope('%s','%s')=%s\n",
3233 // qPrint(scope),qPrint(templ),qPrint(result));
3234 return result;
3235}
3236
3237
3238/*! Strips the scope from a name. Examples: A::B will return A
3239 * and A<T>::B<N::C<D> > will return A<T>.
3240 */
3242{
3243 DString result = name;
3244 int l = static_cast<int>(result.length());
3245 int p = 0;
3246 bool done = false;
3247 bool skipBracket=false; // if brackets do not match properly, ignore them altogether
3248 int count=0;
3249 int round=0;
3250
3251 do
3252 {
3253 p=l-1; // start at the end of the string
3254 while (p>=0 && count>=0)
3255 {
3256 char c=result.at(p);
3257 switch (c)
3258 {
3259 case ':':
3260 // only exit in the case of ::
3261 //printf("stripScope(%s)=%s\n",name,qPrint(result.right(l-p-1)));
3262 if (p>0 && result.at(p-1)==':' && (count==0 || skipBracket))
3263 {
3264 return result.right(l-p-1);
3265 }
3266 p--;
3267 break;
3268 case '>':
3269 if (skipBracket) // we don't care about brackets
3270 {
3271 p--;
3272 }
3273 else // count open/close brackets
3274 {
3275 if (p>0 && result.at(p-1)=='>') // skip >> operator
3276 {
3277 p-=2;
3278 break;
3279 }
3280 count=1;
3281 //printf("pos < = %d\n",p);
3282 p--;
3283 bool foundMatch=false;
3284 while (p>=0 && !foundMatch)
3285 {
3286 c=result.at(p--);
3287 switch (c)
3288 {
3289 case ')':
3290 round++;
3291 break;
3292 case '(':
3293 round--;
3294 break;
3295 case '>': // ignore > inside (...) to support e.g. (sizeof(T)>0) inside template parameters
3296 if (round==0) count++;
3297 break;
3298 case '<':
3299 if (round==0)
3300 {
3301 if (p>0)
3302 {
3303 if (result.at(p-1) == '<') // skip << operator
3304 {
3305 p--;
3306 break;
3307 }
3308 }
3309 count--;
3310 foundMatch = count==0;
3311 }
3312 break;
3313 default:
3314 //printf("c=%c count=%d\n",c,count);
3315 break;
3316 }
3317 }
3318 }
3319 //printf("pos > = %d\n",p+1);
3320 break;
3321 default:
3322 p--;
3323 }
3324 }
3325 done = count==0 || skipBracket; // reparse if brackets do not match
3326 skipBracket=true;
3327 }
3328 while (!done); // if < > unbalanced repeat ignoring them
3329 //printf("stripScope(%s)=%s\n",name,name);
3330 return name;
3331}
3332
3333/*! Converts a string to a HTML id string */
3335{
3336 if (s.empty()) return s;
3337 DString result;
3338 result.reserve(s.length()+8);
3339 const char *p = s.data();
3340 char c = 0;
3341 bool first = true;
3342 while ((c=*p++))
3343 {
3344 char encChar[4];
3345 if ((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') || c=='-')
3346 { // any permissive character except _
3347 if (first && c>='0' && c<='9') result+='a'; // don't start with a digit
3348 result+=c;
3349 }
3350 else
3351 {
3352 encChar[0]='_';
3353 encChar[1]=hex[static_cast<unsigned char>(c)>>4];
3354 encChar[2]=hex[static_cast<unsigned char>(c)&0xF];
3355 encChar[3]=0;
3356 result+=encChar;
3357 }
3358 first=false;
3359 }
3360 return result;
3361}
3362
3363/*! Converts a string to an XML-encoded string */
3364DString convertToXML(const DString &s, bool keepEntities, const bool citeEntry)
3365{
3366 if (s.empty()) return s;
3367 DString result;
3368 result.reserve(s.length()+32);
3369 const char *p = s.data();
3370 char c = 0;
3371 while ((c=*p++))
3372 {
3373 switch (c)
3374 {
3375 case '<': result+="&lt;"; break;
3376 case '>': result+="&gt;"; break;
3377 case '&': if (keepEntities)
3378 {
3379 const char *e=p;
3380 char ce = 0;
3381 while ((ce=*e++))
3382 {
3383 if (ce==';' || (!(isId(ce) || ce=='#'))) break;
3384 }
3385 if (ce==';') // found end of an entity
3386 {
3387 // copy entry verbatim
3388 result+=c;
3389 while (p<e) result+=*p++;
3390 }
3391 else
3392 {
3393 result+="&amp;";
3394 }
3395 }
3396 else if (citeEntry)
3397 {
3399 result,
3400 p-1,
3401 [](HtmlEntityMapper::SymType symType) { return HtmlEntityMapper::instance().xml(symType); },
3402 "&amp;");
3403 }
3404 else
3405 {
3406 result+="&amp;";
3407 }
3408 break;
3409 case '\'': result+="&apos;"; break;
3410 case '"': result+="&quot;"; break;
3411 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
3412 case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18:
3413 case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26:
3414 case 27: case 28: case 29: case 30: case 31:
3415 break; // skip invalid XML characters (see http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char)
3416 default: result+=c; break;
3417 }
3418 }
3419 return result;
3420}
3421
3422/*! Converts a string to a HTML-encoded string */
3423DString convertToHtml(const DString &s,bool keepEntities)
3424{
3425 if (s.empty()) return s;
3426 DString result;
3427 result.reserve(s.length()+32);
3428 const char *p=s.data();
3429 char c = 0;
3430 while ((c=*p++))
3431 {
3432 switch (c)
3433 {
3434 case '<': result+="&lt;"; break;
3435 case '>': result+="&gt;"; break;
3436 case '&': if (keepEntities)
3437 {
3438 const char *e=p;
3439 char ce = 0;
3440 while ((ce=*e++))
3441 {
3442 if (ce==';' || (!(isId(ce) || ce=='#'))) break;
3443 }
3444 if (ce==';') // found end of an entity
3445 {
3446 // copy entry verbatim
3447 result+=c;
3448 while (p<e) result+=*p++;
3449 }
3450 else
3451 {
3452 result+="&amp;";
3453 }
3454 }
3455 else
3456 {
3457 result+="&amp;";
3458 }
3459 break;
3460 case '\'': result+="&#39;"; break;
3461 case '"': result+="&quot;"; break;
3462 default:
3463 {
3464 uint8_t uc = static_cast<uint8_t>(c);
3465 if (uc<32 && !isspace(c))
3466 {
3467 result+="&#x24";
3468 result+=hex[uc>>4];
3469 result+=hex[uc&0xF];
3470 result+=';';
3471 }
3472 else
3473 {
3474 result+=c;
3475 }
3476 }
3477 break;
3478 }
3479 }
3480 return result;
3481}
3482
3483DString convertToJSString(const DString &s,bool keepEntities,bool singleQuotes)
3484{
3485 if (s.empty()) return s;
3486 DString result;
3487 result.reserve(s.length()+32);
3488 const char *p=s.data();
3489 char c = 0;
3490 while ((c=*p++))
3491 {
3492 switch (c)
3493 {
3494 case '"': if (!singleQuotes) result+="\\\""; else result+=c;
3495 break;
3496 case '\'': if (singleQuotes) result+="\\\'"; else result+=c;
3497 break;
3498 case '\\': if (*p=='u' && *(p+1)=='{') result+="\\"; // keep \u{..} unicode escapes
3499 else result+="\\\\";
3500 break;
3501 default: result+=c; break;
3502 }
3503 }
3504 return keepEntities ? result : HtmlEntityMapper::instance().convertCharEntitiesToUTF8(result);
3505}
3506
3507/*! Extracts a (sub-)string from \a type starting at \a pos that
3508 * could form a class. The index of the match is returned and the found
3509 * class \a name and a template argument list \a templSpec. If -1 is returned
3510 * there are no more matches.
3511 */
3512int extractClassNameFromType(const DString &type,int &pos,DString &name,DString &templSpec,SrcLangExt lang)
3513{
3514 AUTO_TRACE("type='{}' pos={} name='{}' lang={}",type,pos,name,lang);
3515 static const reg::Ex re_norm(R"(\a[\w:]*)");
3516 static const reg::Ex re_fortran(R"(\a[\w:()=]*)");
3517 const reg::Ex *re = &re_norm;
3518
3519 name.clear();
3520 templSpec.clear();
3521 if (type.empty())
3522 {
3523 AUTO_TRACE_EXIT("empty type");
3524 return -1;
3525 }
3526 size_t typeLen=type.length();
3527 if (typeLen>0)
3528 {
3529 if (lang == SrcLangExt::Fortran)
3530 {
3531 if (type[pos]==',')
3532 {
3533 AUTO_TRACE_EXIT("comma");
3534 return -1;
3535 }
3536 if (!type.lower().startsWith("type"))
3537 {
3538 re = &re_fortran;
3539 }
3540 }
3541 std::string s = type.str();
3542 reg::Iterator it(s,*re,static_cast<int>(pos));
3544
3545 if (it!=end)
3546 {
3547 const auto &match = *it;
3548 size_t i = match.position();
3549 size_t l = match.length();
3550 size_t ts = i+l;
3551 size_t te = ts;
3552 size_t tl = 0;
3553
3554 while (ts<typeLen && type[static_cast<uint32_t>(ts)]==' ') { ts++; tl++; } // skip any whitespace
3555 if (ts<typeLen && type[static_cast<uint32_t>(ts)]=='<') // assume template instance
3556 {
3557 // locate end of template
3558 te=ts+1;
3559 int brCount=1;
3560 while (te<typeLen && brCount!=0)
3561 {
3562 if (type[static_cast<uint32_t>(te)]=='<')
3563 {
3564 if (te<typeLen-1 && type[static_cast<uint32_t>(te)+1]=='<') te++; else brCount++;
3565 }
3566 if (type[static_cast<uint32_t>(te)]=='>')
3567 {
3568 if (te<typeLen-1 && type[static_cast<uint32_t>(te)+1]=='>') te++; else brCount--;
3569 }
3570 te++;
3571 }
3572 }
3573 name = match.str();
3574 if (te>ts)
3575 {
3576 templSpec = DString(type).mid(ts,te-ts);
3577 tl+=te-ts;
3578 pos=static_cast<int>(i+l+tl);
3579 }
3580 else // no template part
3581 {
3582 pos=static_cast<int>(i+l);
3583 }
3584 //printf("extractClassNameFromType([in] type=%s,[out] pos=%d,[out] name=%s,[out] templ=%s)=true i=%d\n",
3585 // qPrint(type),pos,qPrint(name),qPrint(templSpec),i);
3586 AUTO_TRACE_EXIT("pos={} templSpec='{}' return={}",pos,templSpec,i);
3587 return static_cast<int>(i);
3588 }
3589 }
3590 pos = static_cast<int>(typeLen);
3591 //printf("extractClassNameFromType([in] type=%s,[out] pos=%d,[out] name=%s,[out] templ=%s)=false\n",
3592 // qPrint(type),pos,qPrint(name),qPrint(templSpec));
3593 AUTO_TRACE_EXIT("not found");
3594 return -1;
3595}
3596
3598 const DString &name,
3599 const Definition *context,
3600 const ArgumentList &formalArgs)
3601{
3602 // skip until <
3603 size_t p=name.find('<');
3604 if (p==DString::npos) return name;
3605 p++;
3606 DString result = name.left(p);
3607
3608 std::string s = name.mid(p).str();
3609 static const reg::Ex re(R"([\a:][\w:]*)");
3610 reg::Iterator it(s,re);
3612 size_t pi=0;
3613 // for each identifier in the template part (e.g. B<T> -> T)
3614 for (; it!=end ; ++it)
3615 {
3616 const auto &match = *it;
3617 size_t i = match.position();
3618 size_t l = match.length();
3619 result += s.substr(pi,i-pi);
3620 DString n(match.str());
3621 bool found=false;
3622 for (const Argument &formArg : formalArgs)
3623 {
3624 if (formArg.name == n)
3625 {
3626 found=true;
3627 break;
3628 }
3629 }
3630 if (!found)
3631 {
3632 // try to resolve the type
3633 SymbolResolver resolver;
3634 const ClassDef *cd = resolver.resolveClass(context,n);
3635 if (cd)
3636 {
3637 result+=cd->name();
3638 }
3639 else
3640 {
3641 result+=n;
3642 }
3643 }
3644 else
3645 {
3646 result+=n;
3647 }
3648 pi=i+l;
3649 }
3650 result+=s.substr(pi);
3651 //printf("normalizeNonTemplateArgumentInString(%s)=%s\n",qPrint(name),qPrint(result));
3652 return removeRedundantWhiteSpace(result);
3653}
3654
3655
3657 const DString &nm,
3658 const ArgumentList &formalArgs,
3659 const ArgumentList *actualArgs)
3660{
3661 AUTO_TRACE("name={} formalArgs={} actualArgs={}",nm,argListToString(formalArgs),actualArgs ? argListToString(*actualArgs) : DString());
3662 if (formalArgs.empty()) return nm;
3663 DString result;
3664
3665 static const reg::Ex re(R"(\a\w*)");
3666 std::string name = nm.str();
3667 reg::Iterator it(name,re);
3669 size_t p=0;
3670
3671 for (; it!=end ; ++it)
3672 {
3673 const auto &match = *it;
3674 size_t i = match.position();
3675 size_t l = match.length();
3676 if (i>p) result += name.substr(p,i-p);
3677 DString n(match.str());
3679 if (actualArgs)
3680 {
3681 actIt = actualArgs->begin();
3682 }
3683 //printf(": name=%s\n",qPrint(name));
3684
3685 // if n is a template argument, then we substitute it
3686 // for its template instance argument.
3687 bool found=false;
3688 for (auto formIt = formalArgs.begin();
3689 formIt!=formalArgs.end() && !found;
3690 ++formIt
3691 )
3692 {
3693 Argument formArg = *formIt;
3694 Argument actArg;
3695 if (actualArgs && actIt!=actualArgs->end())
3696 {
3697 actArg = *actIt;
3698 }
3699 if (formArg.type.startsWith("class ") && formArg.name.empty())
3700 {
3701 formArg.name = formArg.type.mid(6);
3702 formArg.type = "class";
3703 }
3704 else if (formArg.type.startsWith("typename ") && formArg.name.empty())
3705 {
3706 formArg.name = formArg.type.mid(9);
3707 formArg.type = "typename";
3708 }
3709 else if (formArg.type.startsWith("class...")) // match 'class... name' to 'name...'
3710 {
3711 formArg.name += "...";
3712 formArg.type = formArg.type.left(5)+formArg.type.mid(8);
3713 }
3714 else if (formArg.type.startsWith("typename...")) // match 'typename... name' to 'name...'
3715 {
3716 formArg.name += "...";
3717 formArg.type = formArg.type.left(8)+formArg.type.mid(11);
3718 }
3719 //printf(": n=%s formArg->type='%s' formArg->name='%s' formArg->defval='%s' actArg->type='%s' actArg->name='%s' \n",
3720 // qPrint(n),qPrint(formArg.type),qPrint(formArg.name),qPrint(formArg.defval),qPrint(actArg.type),qPrint(actArg.name));
3721 if (formArg.type=="class" || formArg.type=="typename" || formArg.type.startsWith("template"))
3722 {
3723 if (formArg.name==n && actualArgs && actIt!=actualArgs->end() && !actArg.type.empty()) // base class is a template argument
3724 {
3725 static constexpr auto hasRecursion = [](const DString &prefix,const DString &nameArg,const DString &subst) -> bool
3726 {
3727 size_t ii=0;
3728 size_t pp=0;
3729
3730 ii = subst.find('<');
3731 //printf("prefix='%s' subst='%s'\n",qPrint(prefix.mid(prefix.length()-ii-2,ii+1)),qPrint(subst.left(ii+1)));
3732 if (ii!=DString::npos && prefix.length()>=ii+2 && prefix.mid(prefix.length()-ii-2,ii+1)==subst.left(ii+1))
3733 {
3734 return true; // don't replace 'A< ' with 'A< A<...', see issue #10951
3735 }
3736
3737 while ((ii=subst.find(nameArg,pp))!=DString::npos)
3738 {
3739 bool beforeNonWord = ii==0 || !isId(subst.at(ii-1));
3740 bool afterNonWord = subst.length()==ii+nameArg.length() || !isId(subst.at(ii+nameArg.length()));
3741 if (beforeNonWord && afterNonWord)
3742 {
3743 return true; // if nameArg=='A' then subst=='A::Z' or 'S<A>' or 'Z::A' should return true, but 'AA::ZZ' or 'BAH' should not match
3744 }
3745 pp=ii+nameArg.length();
3746 }
3747 return false;
3748 };
3749 // replace formal argument with the actual argument of the instance
3750 AUTO_TRACE_ADD("result={} n={} type={} hasRecursion={}",result,n,actArg.type,hasRecursion(result,n,actArg.type));
3751 if (!hasRecursion(result,n,actArg.type))
3752 // the scope guard is to prevent recursive lockup for
3753 // template<class A> class C : public<A::T>,
3754 // where A::T would become A::T::T here,
3755 // since n==A and actArg->type==A::T
3756 // see bug595833 for an example
3757 //
3758 // Also prevent recursive substitution if n is part of actArg.type, i.e.
3759 // n='A' in argType='S< A >' would produce 'S< S< A > >'
3760 {
3761 if (actArg.name.empty())
3762 {
3763 result += actArg.type;
3764 }
3765 else
3766 // for case where the actual arg is something like "unsigned int"
3767 // the "int" part is in actArg->name.
3768 {
3769 result += actArg.type+" "+actArg.name;
3770 }
3771 found=true;
3772 }
3773 }
3774 else if (formArg.name==n &&
3775 (actualArgs==nullptr || actIt==actualArgs->end()) &&
3776 !formArg.defval.empty() &&
3777 formArg.defval!=nm /* to prevent recursion */
3778 )
3779 {
3780 result += substituteTemplateArgumentsInString(formArg.defval,formalArgs,actualArgs);
3781 found=true;
3782 }
3783 }
3784 else if (formArg.name==n &&
3785 (actualArgs==nullptr || actIt==actualArgs->end()) &&
3786 !formArg.defval.empty() &&
3787 formArg.defval!=nm /* to prevent recursion */
3788 )
3789 {
3790 result += substituteTemplateArgumentsInString(formArg.defval,formalArgs,actualArgs);
3791 found=true;
3792 }
3793 if (actualArgs && actIt!=actualArgs->end())
3794 {
3795 actIt++;
3796 }
3797 }
3798 if (!found)
3799 {
3800 result += n;
3801 }
3802 p=i+l;
3803 }
3804 result+=name.substr(p);
3805 result=result.simplifyWhiteSpace();
3806 AUTO_TRACE_EXIT("result={}",result);
3807 return result.stripWhiteSpace();
3808}
3809
3810
3811/*! Strips template specifiers from scope \a fullName, except those
3812 * that make up specialized classes. The switch \a parentOnly
3813 * determines whether or not a template "at the end" of a scope
3814 * should be considered, e.g. with \a parentOnly is \c true, `A<T>::B<S>` will
3815 * try to strip `<T>` and not `<S>`, while \a parentOnly is \c false will
3816 * strip both unless `A<T>` or `B<S>` are specialized template classes.
3817 */
3819 bool parentOnly,
3820 DString *pLastScopeStripped,
3821 DString scopeName,
3822 bool allowArtificial)
3823{
3824 //printf("stripTemplateSpecifiersFromScope(name=%s,scopeName=%s)\n",qPrint(fullName),qPrint(scopeName));
3825 size_t i=fullName.find('<');
3826 if (i==DString::npos) return fullName;
3827 DString result;
3828 size_t p=0;
3829 size_t l=fullName.length();
3830 while (i!=DString::npos)
3831 {
3832 //printf("1:result+=%s\n",qPrint(fullName.mid(p,i-p)));
3833 size_t e=i+1;
3834 int count=1;
3835 int round=0;
3836 while (e<l && count>0)
3837 {
3838 char c=fullName.at(e++);
3839 switch (c)
3840 {
3841 case '(': round++; break;
3842 case ')': if (round>0) round--; break;
3843 case '<': if (round==0) count++; break;
3844 case '>': if (round==0) count--; break;
3845 default:
3846 break;
3847 }
3848 }
3849 size_t si = fullName.find("::",e);
3850
3851 if (parentOnly && si==DString::npos) break;
3852 // we only do the parent scope, so we stop here if needed
3853
3854 result+=fullName.mid(p,i-p);
3855 //printf(" trying %s\n",qPrint(mergeScopes(scopeName,result+fullName.mid(i,e-i))));
3856 ClassDef *cd = getClass(mergeScopes(scopeName,result+fullName.mid(i,e-i)));
3857 if (cd!=nullptr && (allowArtificial || !cd->isArtificial()))
3858 {
3859 result+=fullName.mid(i,e-i);
3860 //printf(" 2:result+=%s\n",qPrint(fullName.mid(i,e-i-1)));
3861 }
3862 else if (pLastScopeStripped)
3863 {
3864 //printf(" last stripped scope '%s'\n",qPrint(fullName.mid(i,e-i)));
3865 *pLastScopeStripped=fullName.mid(i,e-i);
3866 }
3867 p=e;
3868 i=fullName.find('<',p);
3869 }
3870 result+=fullName.right(l-p);
3871 //printf("3:result+=%s\n",qPrint(fullName.right(l-p)));
3872 //printf("end result=%s\n",qPrint(result));
3873 return result;
3874}
3875
3876/*! Merges two scope parts together. The parts may (partially) overlap.
3877 * Example1: \c A::B and \c B::C will result in \c A::B::C <br>
3878 * Example2: \c A and \c B will be \c A::B <br>
3879 * Example3: \c A::B and B will be \c A::B
3880 *
3881 * @param leftScope the left hand part of the scope.
3882 * @param rightScope the right hand part of the scope.
3883 * @returns the merged scope.
3884 */
3885DString mergeScopes(const DString &leftScope,const DString &rightScope)
3886{
3887 AUTO_TRACE("leftScope='{}' rightScope='{}'",leftScope,rightScope);
3888 // case leftScope=="A" rightScope=="A::B" => result = "A::B"
3889 if (leftScopeMatch(leftScope,rightScope))
3890 {
3891 AUTO_TRACE_EXIT("case1={}",rightScope);
3892 return rightScope;
3893 }
3894 DString result;
3895 size_t i=0,p=leftScope.length();
3896
3897 // case leftScope=="A::B" rightScope=="B::C" => result = "A::B::C"
3898 // case leftScope=="A::B" rightScope=="B" => result = "A::B"
3899 bool found=false;
3900 while ((i=leftScope.rfind("::",p))!=DString::npos && i>0)
3901 {
3902 if (leftScopeMatch(rightScope,leftScope.mid(i+2)))
3903 {
3904 result = leftScope.left(i+2)+rightScope;
3905 found=true;
3906 }
3907 p=i-1;
3908 }
3909 if (found)
3910 {
3911 AUTO_TRACE_EXIT("case2={}",result);
3912 return result;
3913 }
3914
3915 // case leftScope=="A" rightScope=="B" => result = "A::B"
3916 result=leftScope;
3917 if (!result.empty() && !rightScope.empty()) result+="::";
3918 result+=rightScope;
3919 AUTO_TRACE_EXIT("case3={}",result);
3920 return result;
3921}
3922
3923/*! Returns a fragment from scope \a s, starting at position \a p.
3924 *
3925 * @param s the scope name as a string.
3926 * @param p the start position (0 is the first).
3927 * @param l the resulting length of the fragment.
3928 * @returns the location of the fragment, or -1 if non is found.
3929 */
3930int getScopeFragment(const DString &s,int p,int *l)
3931{
3932 int sl=static_cast<int>(s.length());
3933 int sp=p;
3934 int count=0;
3935 bool done=false;
3936 if (sp>=sl) return -1;
3937 while (sp<sl)
3938 {
3939 char c=s.at(sp);
3940 if (c==':')
3941 {
3942 sp++;
3943 p++;
3944 }
3945 else
3946 {
3947 break;
3948 }
3949 }
3950 while (sp<sl)
3951 {
3952 char c=s.at(sp);
3953 switch (c)
3954 {
3955 case ':': // found next part
3956 goto found;
3957 case '<': // skip template specifier
3958 count=1;sp++;
3959 done=false;
3960 while (sp<sl && !done)
3961 {
3962 // TODO: deal with << and >> operators!
3963 c=s.at(sp++);
3964 switch(c)
3965 {
3966 case '<': count++; break;
3967 case '>': count--; if (count==0) done=true; break;
3968 default: break;
3969 }
3970 }
3971 break;
3972 default:
3973 sp++;
3974 break;
3975 }
3976 }
3977found:
3978 *l=sp-p;
3979 //printf("getScopeFragment(%s,%d)=%s\n",qPrint(s),p,qPrint(s.mid(p,*l)));
3980 return p;
3981}
3982
3983//----------------------------------------------------------------------------
3984
3986{
3987 ModuleDef *mod = nullptr;
3989 {
3990 const FileDef *fd = toFileDef(d);
3991 if (fd) mod = fd->getModuleDef();
3992 }
3994 {
3995 const ClassDef *cd = toClassDef(d);
3996 if (cd)
3997 {
3998 const FileDef *fd = cd->getFileDef();
3999 if (fd) mod = fd->getModuleDef();
4000 }
4001 }
4003 {
4004 const ConceptDef *cd = toConceptDef(d);
4005 if (cd)
4006 {
4007 const FileDef *fd = cd->getFileDef();
4008 if (fd) mod = fd->getModuleDef();
4009 }
4010 }
4011 return mod;
4012}
4013
4014static bool recursivelyAddGroupListToTitle(OutputList &ol,const Definition *d,bool root)
4015{
4016 ModuleDef *mod = root ? findModuleDef(d) : nullptr;
4017 if (!d->partOfGroups().empty() || mod!=nullptr) // write list of group to which this definition belongs
4018 {
4019 if (root)
4020 {
4021 ol.pushGeneratorState();
4023 ol.writeString("<div class=\"ingroups\">");
4024 }
4025 bool first=true;
4026 for (const auto &gd : d->partOfGroups())
4027 {
4028 if (!first) { ol.writeString(" &#124; "); } else first=false;
4029 if (recursivelyAddGroupListToTitle(ol, gd, false))
4030 {
4031 ol.writeString(" &raquo; ");
4032 }
4033 ol.writeObjectLink(gd->getReference(),gd->getOutputFileBase(),DString(),gd->groupTitle());
4034 }
4035 if (root)
4036 {
4037 // add module as a group to the file as well
4038 if (mod)
4039 {
4040 if (!first) { ol.writeString(" &#124; "); } else first=false;
4041 ol.writeString(theTranslator->trModule(false,true)+" ");
4043 mod->displayName());
4044 }
4045 ol.writeString("</div>");
4046 ol.popGeneratorState();
4047 }
4048 return true;
4049 }
4050 return false;
4051}
4052
4054{
4056}
4057
4058bool checkExtension(const DString &fName, const DString &ext)
4059{
4060 return fName.right(ext.length())==ext;
4061}
4062
4064{
4065 if (fName.empty()) return;
4066 size_t i_fs = fName.rfind('/');
4067 size_t i_bs = fName.rfind('\\');
4068 size_t p = i_fs!=DString::npos && i_bs!=DString::npos ? std::max(i_fs, i_bs) :
4069 i_fs!=DString::npos ? i_fs : i_bs!=DString::npos ? i_bs : 0;
4070 size_t i = fName.find('.',p); // search for . after path part
4071 if (i==DString::npos)
4072 {
4074 }
4075}
4076
4078{
4079 DString result=fName;
4080 if (result.right(ext.length())==ext)
4081 {
4082 result=result.left(result.length()-ext.length());
4083 }
4084 return result;
4085}
4086
4091
4093{
4094 DString result=s;
4095 if (size_t i=result.rfind('/'); i!=DString::npos)
4096 {
4097 result=result.mid(i+1);
4098 }
4099 if (size_t i=result.rfind('\\'); i!=DString::npos)
4100 {
4101 result=result.mid(i+1);
4102 }
4103 return result;
4104}
4105
4106DString makeBaseName(const DString &name, const DString &ext)
4107{
4108 return stripExtensionGeneral(stripPath(name), ext);
4109}
4110
4111/** Special version of DString::stripWhiteSpace() that only strips
4112 * completely blank lines.
4113 * @param s the string to be stripped
4114 * @param docLine the line number corresponding to the start of the
4115 * string. This will be adjusted based on the number of lines stripped
4116 * from the start.
4117 * @returns The stripped string.
4118 */
4120{
4121 if (s.empty()) return DString();
4122 const char *p = s.data();
4123
4124 // search for leading empty lines
4125 int i=0,li=-1,l=static_cast<int>(s.length());
4126 char c = 0;
4127 while ((c=*p))
4128 {
4129 if (c==' ' || c=='\t' || c=='\r') { i++; p++; }
4130 else if (c=='\\' && literal_at(p,"\\ilinebr")) { i+=8; li=i; p+=8; }
4131 else if (c=='\n') { i++; li=i; docLine++; p++; }
4132 else break;
4133 }
4134
4135 // search for trailing empty lines
4136 int b=l-1,bi=-1;
4137 p=s.data()+b;
4138 while (b>=0)
4139 {
4140 c=*p;
4141 if (c==' ' || c=='\t' || c=='\r') { b--; p--; }
4142 else if (c=='r' && b>=7 && literal_at(p-7,"\\ilinebr")) { bi=b-7; b-=8; p-=8; }
4143 else if (c=='>' && b>=11 && literal_at(p-11,"\\ilinebr<br>")) { bi=b-11; b-=12; p-=12; }
4144 else if (c=='\n') { bi=b; b--; p--; }
4145 else break;
4146 }
4147
4148 // return whole string if no leading or trailing lines where found
4149 if (li==-1 && bi==-1) return s;
4150
4151 // return substring
4152 if (bi==-1) bi=l;
4153 if (li==-1) li=0;
4154 if (bi<=li) return DString(); // only empty lines
4155 //printf("docLine='%s' len=%d li=%d bi=%d\n",qPrint(s),s.length(),li,bi);
4156 return s.mid(li,bi-li);
4157}
4158
4159//--------------------------------------------------------------------------
4160
4161static std::unordered_map<std::string,SrcLangExt> g_extLookup;
4162
4164{
4165 const char *langName;
4166 const char *parserName;
4168 const char *defExt;
4169};
4170
4171static std::vector<Lang2ExtMap> g_lang2extMap =
4172{
4173// language parser parser option
4174 { "idl", "c", SrcLangExt::IDL, ".idl" },
4175 { "java", "c", SrcLangExt::Java, ".java"},
4176 { "javascript", "c", SrcLangExt::JS, ".js" },
4177 { "csharp", "c", SrcLangExt::CSharp, ".cs" },
4178 { "d", "c", SrcLangExt::D, ".d" },
4179 { "php", "c", SrcLangExt::PHP, ".php" },
4180 { "objective-c", "c", SrcLangExt::ObjC, ".m" },
4181 { "c", "c", SrcLangExt::Cpp, ".c" },
4182 { "c++", "c", SrcLangExt::Cpp, ".cpp" },
4183 { "slice", "c", SrcLangExt::Slice, ".ice" },
4184 { "python", "python", SrcLangExt::Python, ".py" },
4185 { "fortran", "fortran", SrcLangExt::Fortran, ".f" },
4186 { "fortranfree", "fortranfree", SrcLangExt::Fortran, ".f90" },
4187 { "fortranfixed", "fortranfixed", SrcLangExt::Fortran, ".f" },
4188 { "vhdl", "vhdl", SrcLangExt::VHDL, ".vhdl"},
4189 { "xml", "xml", SrcLangExt::XML, ".xml" },
4190 { "sql", "sql", SrcLangExt::SQL, ".sql" },
4191 { "md", "md", SrcLangExt::Markdown, ".md" },
4192 { "lex", "lex", SrcLangExt::Lex, ".l" },
4193};
4194
4195bool updateLanguageMapping(const DString &extension,const DString &language)
4196{
4197 DString langName = language.lower();
4198 auto it1 = std::find_if(g_lang2extMap.begin(),g_lang2extMap.end(),
4199 [&langName](const auto &info) { return info.langName==langName; });
4200 if (it1 == g_lang2extMap.end()) return false;
4201
4202 // found the language
4203 SrcLangExt parserId = it1->parserId;
4204 DString extName = extension.lower();
4205 if (extName.empty()) return false;
4206 if (extName.at(0)!='.') extName.prepend(".");
4207 auto it2 = g_extLookup.find(extName.str());
4208 if (it2!=g_extLookup.end())
4209 {
4210 g_extLookup.erase(it2); // language was already register for this ext
4211 }
4212 //printf("registering extension %s\n",qPrint(extName));
4213 g_extLookup.emplace(extName.str(),parserId);
4214 if (!Doxygen::parserManager->registerExtension(extName,it1->parserName))
4215 {
4216 err("Failed to assign extension {} to parser {} for language {}\n",
4217 extName.data(),it1->parserName,language);
4218 }
4219 else
4220 {
4221 //msg("Registered extension {} to language parser {}...\n",
4222 // extName,language);
4223 }
4224 return true;
4225}
4226
4228{
4229 // NOTE: when adding an extension, also add the extension in config.xml
4230 // extension parser id
4231 updateLanguageMapping(".dox", "c");
4232 updateLanguageMapping(".txt", "c"); // see bug 760836
4233 updateLanguageMapping(".doc", "c");
4234 updateLanguageMapping(".c", "c");
4235 updateLanguageMapping(".C", "c");
4236 updateLanguageMapping(".cc", "c");
4237 updateLanguageMapping(".CC", "c");
4238 updateLanguageMapping(".cxx", "c");
4239 updateLanguageMapping(".cpp", "c");
4240 updateLanguageMapping(".c++", "c");
4241 updateLanguageMapping(".cxxm", "c"); // C++20 modules
4242 updateLanguageMapping(".cppm", "c"); // C++20 modules
4243 updateLanguageMapping(".ccm", "c"); // C++20 modules
4244 updateLanguageMapping(".c++m", "c"); // C++20 modules
4245 updateLanguageMapping(".ii", "c");
4246 updateLanguageMapping(".ixx", "c");
4247 updateLanguageMapping(".ipp", "c");
4248 updateLanguageMapping(".i++", "c");
4249 updateLanguageMapping(".inl", "c");
4250 updateLanguageMapping(".h", "c");
4251 updateLanguageMapping(".H", "c");
4252 updateLanguageMapping(".hh", "c");
4253 updateLanguageMapping(".HH", "c");
4254 updateLanguageMapping(".hxx", "c");
4255 updateLanguageMapping(".hpp", "c");
4256 updateLanguageMapping(".h++", "c");
4257 updateLanguageMapping(".idl", "idl");
4258 updateLanguageMapping(".ddl", "idl");
4259 updateLanguageMapping(".odl", "idl");
4260 updateLanguageMapping(".java", "java");
4261 //updateLanguageMapping(".as", "javascript"); // not officially supported
4262 //updateLanguageMapping(".js", "javascript"); // not officially supported
4263 updateLanguageMapping(".cs", "csharp");
4264 updateLanguageMapping(".d", "d");
4265 updateLanguageMapping(".php", "php");
4266 updateLanguageMapping(".php4", "php");
4267 updateLanguageMapping(".php5", "php");
4268 updateLanguageMapping(".inc", "php");
4269 updateLanguageMapping(".phtml", "php");
4270 updateLanguageMapping(".m", "objective-c");
4271 updateLanguageMapping(".M", "objective-c");
4272 updateLanguageMapping(".mm", "c"); // see bug746361
4273 updateLanguageMapping(".py", "python");
4274 updateLanguageMapping(".pyw", "python");
4275 updateLanguageMapping(".f", "fortran");
4276 updateLanguageMapping(".for", "fortran");
4277 updateLanguageMapping(".f90", "fortran");
4278 updateLanguageMapping(".f95", "fortran");
4279 updateLanguageMapping(".f03", "fortran");
4280 updateLanguageMapping(".f08", "fortran");
4281 updateLanguageMapping(".f18", "fortran");
4282 updateLanguageMapping(".vhd", "vhdl");
4283 updateLanguageMapping(".vhdl", "vhdl");
4284 updateLanguageMapping(".ucf", "vhdl");
4285 updateLanguageMapping(".qsf", "vhdl");
4286 updateLanguageMapping(".md", "md");
4287 updateLanguageMapping(".markdown", "md");
4288 updateLanguageMapping(".ice", "slice");
4289 updateLanguageMapping(".l", "lex");
4290 updateLanguageMapping(".doxygen_lex_c", "c"); // this is a placeholder so we can map initializations
4291 // in the lex scanning to cpp
4292}
4293
4295{
4296 updateLanguageMapping(".xml", "xml");
4297 updateLanguageMapping(".sql", "sql");
4298}
4299
4301{
4302 FileInfo fi(fileName.str());
4303 // we need only the part after the last ".", newer implementations of FileInfo have 'suffix()' for this.
4304 DString extName = DString(fi.extension(false)).lower();
4305 if (extName.empty()) extName=".no_extension";
4306 if (extName.at(0)!='.') extName.prepend(".");
4307 auto it = g_extLookup.find(extName.str());
4308 if (it!=g_extLookup.end()) // listed extension
4309 {
4310 //printf("getLanguageFromFileName(%s)=%x\n",qPrint(fi.extension()),*pVal);
4311 return it->second;
4312 }
4313 //printf("getLanguageFromFileName(%s) not found!\n",qPrint(fileName));
4314 return defLang; // not listed => assume C-ish language.
4315}
4316
4317/// Routine to handle the language attribute of the `\code` command
4319{
4320 // try the extension
4321 auto lang = getLanguageFromFileName(fileName, SrcLangExt::Unknown);
4322 if (lang == SrcLangExt::Unknown)
4323 {
4324 // try the language names
4325 DString langName = fileName.lower();
4326 if (langName.at(0)=='.') langName = langName.mid(1);
4327 auto it = std::find_if(g_lang2extMap.begin(),g_lang2extMap.end(),
4328 [&langName](const auto &info) { return info.langName==langName; });
4329 if (it != g_lang2extMap.end())
4330 {
4331 lang = it->parserId;
4332 fileName = it->defExt;
4333 }
4334 else // default to C++
4335 {
4336 return SrcLangExt::Cpp;
4337 }
4338 }
4339 return lang;
4340}
4341
4343{
4344 if (fn.empty()) return "";
4345 if (size_t lastDot = fn.rfind('.'); lastDot!=DString::npos) return fn.mid(lastDot);
4346 return "";
4347}
4348
4349//--------------------------------------------------------------------------
4350
4351static MemberDef *getMemberFromSymbol(const Definition *scope,const FileDef *fileScope,
4352 const DString &n)
4353{
4354 if (scope==nullptr ||
4357 )
4358 )
4359 {
4361 }
4362
4363 DString name = n;
4364 if (name.empty())
4365 return nullptr; // no name was given
4366
4367 auto &range = Doxygen::symbolMap->find(name);
4368 if (range.empty())
4369 return nullptr; // could not find any matching symbols
4370
4371 // mostly copied from getResolvedClassRec()
4372 DString explicitScopePart;
4373 int qualifierIndex = computeQualifiedIndex(name);
4374 if (qualifierIndex!=-1)
4375 {
4376 explicitScopePart = name.left(qualifierIndex);
4377 replaceNamespaceAliases(explicitScopePart);
4378 name = name.mid(qualifierIndex+2);
4379 }
4380 //printf("explicitScopePart=%s\n",qPrint(explicitScopePart));
4381
4382 int minDistance = 10000;
4383 MemberDef *bestMatch = nullptr;
4384
4385 for (Definition *d : range)
4386 {
4387 if (d->definitionType()==Definition::TypeMember)
4388 {
4389 SymbolResolver resolver(fileScope);
4390 int distance = resolver.isAccessibleFromWithExpScope(scope,d,explicitScopePart);
4391 if (distance!=-1 && distance<minDistance)
4392 {
4393 minDistance = distance;
4394 bestMatch = toMemberDef(d);
4395 //printf("new best match %s distance=%d\n",qPrint(bestMatch->qualifiedName()),distance);
4396 }
4397 }
4398 }
4399 return bestMatch;
4400}
4401
4402/*! Returns true iff the given name string appears to be a typedef in scope. */
4403bool checkIfTypedef(const Definition *scope,const FileDef *fileScope,const DString &n)
4404{
4405 MemberDef *bestMatch = getMemberFromSymbol(scope,fileScope,n);
4406
4407 if (bestMatch && bestMatch->isTypedef())
4408 return true; // closest matching symbol is a typedef
4409 else
4410 return false;
4411}
4412
4413//--------------------------------------------------------------------------------------
4414
4416{
4417 if (al.empty()) return;
4419 for (const Argument &a : al)
4420 {
4422 ol.parseText(a.name);
4423 ol.endConstraintParam();
4425 linkifyText(TextGeneratorOLImpl(ol),a.type,LinkifyTextOptions().setScope(d));
4426 ol.endConstraintType();
4428 ol.generateDoc(d->docFile(),
4429 d->docLine(),
4430 d,
4431 nullptr,
4432 a.docs,
4433 DocOptions()
4434 .setIndexWords(true));
4435 ol.endConstraintDocs();
4436 }
4437 ol.endConstraintList();
4438}
4439
4440//----------------------------------------------------------------------------
4441
4443{
4444#ifdef TRACINGSUPPORT
4445 void *backtraceFrames[128];
4446 int frameCount = backtrace(backtraceFrames, 128);
4447 const size_t cmdLen = 40960;
4448 static char cmd[cmdLen];
4449 char *p = cmd;
4450 p += snprintf(p,cmdLen,"/usr/bin/atos -p %d ", (int)getpid());
4451 for (int x = 0; x < frameCount; x++)
4452 {
4453 p += snprintf(p,cmdLen,"%p ", backtraceFrames[x]);
4454 }
4455 fprintf(stderr,"========== STACKTRACE START ==============\n");
4456 if (FILE *fp = Portable::popen(cmd, "r"))
4457 {
4458 char resBuf[512];
4459 while (size_t len = fread(resBuf, 1, sizeof(resBuf), fp))
4460 {
4461 fwrite(resBuf, 1, len, stderr);
4462 }
4463 Portable::pclose(fp);
4464 }
4465 fprintf(stderr,"============ STACKTRACE END ==============\n");
4466 //fprintf(stderr,"%s\n", frameStrings[x]);
4467#endif
4468}
4469
4470static void transcodeCharacterBuffer(const DString &fileName,std::string &contents,
4471 const DString &inputEncoding,const DString &outputEncoding)
4472{
4473 if (inputEncoding.empty() || outputEncoding.empty()) return; // no encoding specified
4474 if (dstricmp(inputEncoding,outputEncoding)==0) return; // input encoding same as output encoding
4475 void *cd = portable_iconv_open(outputEncoding.data(),inputEncoding.data());
4476 if (cd==reinterpret_cast<void *>(-1))
4477 {
4478 term("unsupported character conversion: '{}'->'{}': {}\n"
4479 "Check the INPUT_ENCODING setting in the config file!\n",
4480 inputEncoding,outputEncoding,strerror(errno));
4481 }
4482 size_t iLeft = contents.size();
4483 const char *srcPtr = contents.data();
4484 size_t tmpBufSize = contents.size()*4+1;
4485 size_t oLeft = tmpBufSize;
4486 std::string tmpBuf;
4487 tmpBuf.resize(tmpBufSize);
4488 char *dstPtr = tmpBuf.data();
4489 size_t newSize=0;
4490 if (!portable_iconv(cd, &srcPtr, &iLeft, &dstPtr, &oLeft))
4491 {
4492 newSize = tmpBufSize-oLeft;
4493 tmpBuf.resize(newSize);
4494 std::swap(contents,tmpBuf);
4495 //printf("iconv: input size=%d output size=%d\n[%s]\n",size,newSize,qPrint(srcBuf));
4496 }
4497 else
4498 {
4499 term("{}: failed to translate characters from {} to {}: check INPUT_ENCODING\n",
4500 fileName,inputEncoding,outputEncoding);
4501 }
4503}
4504
4505//! read a file name \a fileName and optionally filter and transcode it
4506bool readInputFile(const DString &fileName,std::string &contents,const ReadInputFileOptions &options)
4507{
4508 // try to open file
4509 FileInfo fi(fileName.str());
4510 if (!fi.exists()) return false;
4511 DString filterName = getFileFilter(fileName,options.isSourceCode());
4512 if (filterName.empty() || !options.filter())
4513 {
4514 std::ifstream f = Portable::openInputStream(fileName,true);
4515 if (!f.is_open())
4516 {
4517 err("could not open file {}\n",fileName);
4518 return false;
4519 }
4520 // read the file
4521 auto fileSize = fi.size();
4522 contents.resize(fileSize);
4523 f.read(contents.data(),fileSize);
4524 if (f.fail())
4525 {
4526 err("problems while reading file {}\n",fileName);
4527 return false;
4528 }
4529 }
4530 else
4531 {
4532 DString cmd=filterName+" \""+fileName+"\"";
4533 Debug::print(Debug::ExtCmd,0,"Executing popen(`{}`)\n",cmd);
4534 FILE *f=Portable::popen(cmd,"r");
4535 if (!f)
4536 {
4537 err("could not execute filter {}\n",filterName);
4538 return false;
4539 }
4540 const int bufSize=4096;
4541 char buf[bufSize];
4542 int numRead = 0;
4543 while ((numRead=static_cast<int>(fread(buf,1,bufSize,f)))>0)
4544 {
4545 //printf(">>>>>>>>Reading %d bytes\n",numRead);
4546 contents.append(buf,numRead);
4547 }
4549 Debug::print(Debug::FilterOutput, 0, "Filter output\n");
4550 Debug::print(Debug::FilterOutput,0,"-------------\n{}\n-------------\n",contents);
4551 }
4552 if (options.binary())
4553 {
4554 return true;
4555 }
4556
4557 if (contents.size()>=2 &&
4558 static_cast<uint8_t>(contents[0])==0xFF &&
4559 static_cast<uint8_t>(contents[1])==0xFE // Little endian BOM
4560 ) // UCS-2LE encoded file
4561 {
4562 transcodeCharacterBuffer(fileName,contents,"UCS-2LE","UTF-8");
4563 }
4564 else if (contents.size()>=2 &&
4565 static_cast<uint8_t>(contents[0])==0xFE &&
4566 static_cast<uint8_t>(contents[1])==0xFF // big endian BOM
4567 ) // UCS-2BE encoded file
4568 {
4569 transcodeCharacterBuffer(fileName,contents,"UCS-2BE","UTF-8");
4570 }
4571 else if (contents.size()>=3 &&
4572 static_cast<uint8_t>(contents[0])==0xEF &&
4573 static_cast<uint8_t>(contents[1])==0xBB &&
4574 static_cast<uint8_t>(contents[2])==0xBF
4575 ) // UTF-8 encoded file
4576 {
4577 contents.erase(0,3); // remove UTF-8 BOM: no translation needed
4578 }
4579 else // transcode according to the INPUT_ENCODING setting
4580 {
4581 // do character transcoding if needed.
4582 transcodeCharacterBuffer(fileName,contents,getEncoding(fi),"UTF-8");
4583 }
4584
4585 filterCRLF(contents);
4586 return true;
4587}
4588
4589// Replace %word by word in title
4591{
4592 std::string tf;
4593 std::string t = title.str();
4594 static const reg::Ex re(R"(%[a-z_A-Z]+)");
4595 reg::Iterator it(t,re);
4597 size_t p = 0;
4598 for (; it!=end ; ++it)
4599 {
4600 const auto &match = *it;
4601 size_t i = match.position();
4602 size_t l = match.length();
4603 if (i>p) tf+=t.substr(p,i-p);
4604 tf+=match.str().substr(1); // skip %
4605 p=i+l;
4606 }
4607 tf+=t.substr(p);
4608 return tf;
4609}
4610
4611//----------------------------------------------------------------------------
4612
4614{
4615 InputFileEncoding elem;
4616 auto getter = [](const InputFileEncoding &e) { return e.pattern.str(); };
4617 if (fi.match(Doxygen::inputFileEncodingList,useCaseSenseNames(),&elem,getter)) // check for file specific encoding
4618 {
4619 return elem.encoding;
4620 }
4621 else // fall back to default encoding
4622 {
4623 return Config_getString(INPUT_ENCODING);
4624 }
4625}
4626
4628{
4629 bool extLinksInWindow = Config_getBool(EXT_LINKS_IN_WINDOW);
4630 if (extLinksInWindow)
4631 return "target=\"_blank\" ";
4632 else if (parent)
4633 return "target=\"_parent\" ";
4634 else
4635 return "";
4636}
4637
4639 const DString &ref,
4640 bool isLocalFile,
4641 const DString &targetFileName,
4642 const DString &anchor)
4643{
4644 DString url;
4645 if (!ref.empty())
4646 {
4647 url = externalRef(relPath,ref);
4648 }
4649 if (!targetFileName.empty())
4650 {
4651 DString fn = targetFileName;
4652 if (ref.empty())
4653 {
4654 if (!anchor.empty() && isLocalFile)
4655 {
4656 fn=""; // omit file name for local links
4657 }
4658 else
4659 {
4660 url = relPath;
4661 }
4662 }
4663 url+=fn;
4664 }
4665 if (!anchor.empty())
4666 {
4667 if (!url.endsWith("=")) url+="#";
4668 url+=anchor;
4669 }
4670 //printf("createHtmlUrl(relPath=%s,local=%d,target=%s,anchor=%s)=%s\n",qPrint(relPath),isLocalFile,qPrint(targetFileName),qPrint(anchor),qPrint(url));
4671 return url;
4672}
4673
4674DString externalRef(const DString &relPath,const DString &ref)
4675{
4676 DString result;
4677 if (!ref.empty())
4678 {
4679 auto it = Doxygen::tagDestinationMap.find(ref.str());
4681 {
4682 result = it->second;
4683 size_t l = result.length();
4684 if (!relPath.empty() && l>0 && result.at(0)=='.')
4685 { // relative path -> prepend relPath.
4686 result.prepend(relPath);
4687 l+=relPath.length();
4688 }
4689 if (l>0 && result.at(l-1)!='/') result+='/';
4690 }
4691 }
4692 else
4693 {
4694 result = relPath;
4695 }
4696 return result;
4697}
4698
4699/** Replaces any markers of the form \#\#AA in input string \a str
4700 * by new markers of the form \#AABBCC, where \#AABBCC represents a
4701 * valid color, based on the intensity represented by hex number AA
4702 * and the current HTML_COLORSTYLE_* settings.
4703 */
4705{
4706 if (str.empty()) return DString();
4707 std::string result;
4708 std::string s=str.str();
4709 static const reg::Ex re(R"(##[0-9A-Fa-f][0-9A-Fa-f])");
4710 reg::Iterator it(s,re);
4712 int hue = Config_getInt(HTML_COLORSTYLE_HUE);
4713 int sat = Config_getInt(HTML_COLORSTYLE_SAT);
4714 int gamma = Config_getInt(HTML_COLORSTYLE_GAMMA);
4715 size_t sl=s.length();
4716 size_t p=0;
4717 for (; it!=end ; ++it)
4718 {
4719 const auto &match = *it;
4720 size_t i = match.position();
4721 size_t l = match.length();
4722 if (i>p) result+=s.substr(p,i-p);
4723 std::string lumStr = match.str().substr(2);
4724#define HEXTONUM(x) (((x)>='0' && (x)<='9') ? ((x)-'0') : \
4725 ((x)>='a' && (x)<='f') ? ((x)-'a'+10) : \
4726 ((x)>='A' && (x)<='F') ? ((x)-'A'+10) : 0)
4727
4728 double r = 0,g = 0,b = 0;
4729 int level = HEXTONUM(lumStr[0])*16+HEXTONUM(lumStr[1]);
4730 ColoredImage::hsl2rgb(hue/360.0,sat/255.0,
4731 pow(level/255.0,gamma/100.0),&r,&g,&b);
4732 int red = static_cast<int>(r*255.0);
4733 int green = static_cast<int>(g*255.0);
4734 int blue = static_cast<int>(b*255.0);
4735 char colStr[8];
4736 colStr[0]='#';
4737 colStr[1]=hex[red>>4];
4738 colStr[2]=hex[red&0xf];
4739 colStr[3]=hex[green>>4];
4740 colStr[4]=hex[green&0xf];
4741 colStr[5]=hex[blue>>4];
4742 colStr[6]=hex[blue&0xf];
4743 colStr[7]=0;
4744 //printf("replacing %s->%s (level=%d)\n",qPrint(lumStr),colStr,level);
4745 result+=colStr;
4746 p=i+l;
4747 }
4748 if (p<sl) result+=s.substr(p);
4749 return result;
4750}
4751
4752/** Copies the contents of file with name \a src to the newly created
4753 * file with name \a dest. Returns true if successful.
4754 */
4755bool copyFile(const DString &src,const DString &dest)
4756{
4757 if (!Dir().copy(src.str(),dest.str()))
4758 {
4759 err("could not copy file {} to {}\n",src,dest);
4760 return false;
4761 }
4762 return true;
4763}
4764
4766{
4767 if (lang==SrcLangExt::Java || lang==SrcLangExt::CSharp || lang==SrcLangExt::VHDL || lang==SrcLangExt::Python)
4768 {
4769 return ".";
4770 }
4771 else if (lang==SrcLangExt::PHP && !classScope)
4772 {
4773 return "\\";
4774 }
4775 else
4776 {
4777 return "::";
4778 }
4779}
4780
4781/** Checks whether the given url starts with a supported protocol */
4782bool isURL(const DString &url)
4783{
4784 static const std::unordered_set<std::string> schemes = {
4785 "http", "https", "ftp", "ftps", "sftp", "file", "news", "irc", "ircs"
4786 };
4787 DString loc_url = url.stripWhiteSpace();
4788 size_t colonPos = loc_url.find(':');
4789 return colonPos!=DString::npos && schemes.find(loc_url.left(colonPos).str())!=schemes.end();
4790}
4791
4792/** Corrects URL \a url according to the relative path \a relPath.
4793 * Returns the corrected URL. For absolute URLs no correction will be done.
4794 */
4795DString correctURL(const DString &url,const DString &relPath)
4796{
4797 DString result = url;
4798 if (!relPath.empty() && !isURL(url))
4799 {
4800 result.prepend(relPath);
4801 }
4802 return result;
4803}
4804
4805//---------------------------------------------------------------------------
4806
4808{
4809 bool extractPrivate = Config_getBool(EXTRACT_PRIVATE);
4810 bool extractPackage = Config_getBool(EXTRACT_PACKAGE);
4811
4812 return (prot!=Protection::Private && prot!=Protection::Package) ||
4813 (prot==Protection::Private && extractPrivate) ||
4814 (prot==Protection::Package && extractPackage);
4815}
4816
4817//---------------------------------------------------------------------------
4818
4819DString stripIndentation(const DString &s,bool skipFirstLine)
4820{
4821 if (s.empty()) return s; // empty string -> we're done
4822
4823 //printf("stripIndentation:\n%s\n------\n",qPrint(s));
4824 // compute minimum indentation over all lines
4825 const char *p=s.data();
4826 char c=0;
4827 int indent=0;
4828 int minIndent=1000000; // "infinite"
4829 bool searchIndent=true;
4830 int tabSize=Config_getInt(TAB_SIZE);
4831 bool skipFirst = skipFirstLine;
4832 while ((c=*p++))
4833 {
4834 if (c=='\t') { indent+=tabSize - (indent%tabSize); }
4835 else if (c=='\n') { indent=0; searchIndent=true; skipFirst=false; }
4836 else if (c==' ') { indent++; }
4837 else if (searchIndent && !skipFirst)
4838 {
4839 searchIndent=false;
4840 if (indent<minIndent) minIndent=indent;
4841 }
4842 }
4843
4844 // no indent to remove -> we're done
4845 if (minIndent==0) return substitute(s,"@ilinebr","\\ilinebr");
4846
4847 // remove minimum indentation for each line
4848 TextStream result;
4849 p=s.data();
4850 indent=0;
4851 skipFirst=skipFirstLine;
4852 while ((c=*p++))
4853 {
4854 if (c=='\n') // start of new line
4855 {
4856 indent=0;
4857 result << c;
4858 skipFirst=false;
4859 }
4860 else if (indent<minIndent && !skipFirst) // skip until we reach minIndent
4861 {
4862 if (c=='\t')
4863 {
4864 int newIndent = indent+tabSize-(indent%tabSize);
4865 int i=newIndent;
4866 while (i>minIndent) // if a tab crosses the minIndent boundary fill the rest with spaces
4867 {
4868 result << ' ';
4869 i--;
4870 }
4871 indent=newIndent;
4872 }
4873 else // space
4874 {
4875 indent++;
4876 }
4877 }
4878 else if (c=='\\' && literal_at(p,"ilinebr "))
4879 // we also need to remove the indentation after a \ilinebr command at the end of a line
4880 {
4881 result << "\\ilinebr ";
4882 p+=8;
4883 int skipAmount=0;
4884 for (int j=0;j<minIndent;j++) if (*(p+j)==' ') skipAmount++; // test to see if we have the indent
4885 if (skipAmount==minIndent)
4886 {
4887 p+=skipAmount; // remove the indent
4888 }
4889 }
4890 else if (c=='@' && literal_at(p,"ilinebr"))
4891 {
4892 result << "\\ilinebr";
4893 p+=7;
4894 }
4895 else // copy anything until the end of the line
4896 {
4897 result << c;
4898 }
4899 }
4900
4901 //printf("stripIndentation: result=\n%s\n------\n",qPrint(result.str()));
4902
4903 return result.str();
4904}
4905
4906// strip up to \a indentationLevel spaces from each line in \a doc (excluding the first line
4907// when skipFirstLine is set to true)
4908void stripIndentationVerbatim(DString &doc,size_t indentationLevel, bool skipFirstLine)
4909{
4910 //printf("stripIndentationVerbatim(level=%d):\n%s\n------\n",indentationLevel,qPrint(doc));
4911 if (indentationLevel <= 0 || doc.empty()) return; // nothing to strip
4912
4913 // by stripping content the string will only become shorter so we write the results
4914 // back into the input string and then resize it at the end.
4915 char c = 0;
4916 const char *src = doc.data();
4917 char *dst = doc.rawData();
4918 bool insideIndent = !skipFirstLine; // skip the initial line from stripping
4919 size_t cnt = 0;
4920 if (!skipFirstLine) cnt = indentationLevel;
4921 while ((c=*src++))
4922 {
4923 // invariant: dst<=src
4924 switch(c)
4925 {
4926 case '\n':
4927 *dst++ = c;
4928 insideIndent = true;
4929 cnt = indentationLevel;
4930 break;
4931 case ' ':
4932 if (insideIndent)
4933 {
4934 if (cnt>0) // count down the spacing until the end of the indent
4935 {
4936 cnt--;
4937 }
4938 else // reached the end of the indent, start of the part of the line to keep
4939 {
4940 insideIndent = false;
4941 *dst++ = c;
4942 }
4943 }
4944 else // part after indent, copy to the output
4945 {
4946 *dst++ = c;
4947 }
4948 break;
4949 default:
4950 insideIndent = false;
4951 *dst++ = c;
4952 break;
4953 }
4954 }
4955 doc.resize(static_cast<uint32_t>(dst-doc.data()));
4956 //printf("stripIndentationVerbatim: result=\n%s\n------\n",qPrint(doc));
4957}
4958
4959//----------------------------------------------------------------------------
4960
4961/** Strip the direction part from docs and return it as a string in canonical form.
4962 * The input \a docs string can start with e.g. "[in]", "[in, out]", "[inout]", "[out,in]"...
4963 * @returns either "[in,out]", "[in]", or "[out]" or the empty string.
4964 */
4966{
4967 std::string s = docs.str();
4968 static const reg::Ex re(R"(\‍[([ inout,]+)\‍])");
4969 reg::Iterator it(s,re);
4971 if (it!=end)
4972 {
4973 const auto &match = *it;
4974 size_t p = match.position();
4975 size_t l = match.length();
4976 if (p==0 && l>2)
4977 {
4978 // make dir the part inside [...] without separators
4979 std::string dir = match[1].str();
4980 // strip , and ' ' from dir
4981 dir.erase(std::remove_if(dir.begin(),dir.end(),
4982 [](const char c) { return c==' ' || c==','; }
4983 ),dir.end());
4984 unsigned char ioMask=0;
4985 size_t inIndex = dir.find( "in");
4986 if ( inIndex!=std::string::npos) { dir.erase( inIndex,2); ioMask|=(1<<0); }
4987 size_t outIndex = dir.find("out");
4988 if (outIndex!=std::string::npos) { dir.erase(outIndex,3); ioMask|=(1<<1); }
4989 if (dir.empty() && ioMask!=0) // only in and/or out attributes found
4990 {
4991 docs = s.substr(l); // strip attributes
4992 if (ioMask==((1<<0)|(1<<1))) return "[in,out]";
4993 else if (ioMask==(1<<0)) return "[in]";
4994 else if (ioMask==(1<<1)) return "[out]";
4995 }
4996 }
4997 }
4998 return "";
4999}
5000
5002{
5003 DString paramDocs;
5004 if (al.hasDocumentation(true))
5005 {
5006 for (const Argument &a : al)
5007 {
5008 if (a.hasDocumentation(true))
5009 {
5010 DString docsWithoutDir = a.docs;
5011 DString direction = extractDirection(docsWithoutDir);
5012 DString name = a.name;
5013 if (name.empty())
5014 {
5015 name = "-";
5016 }
5017 paramDocs+=" \\ilinebr @param"+direction+" "+name+" "+docsWithoutDir;
5018 }
5019 }
5020 }
5021 return paramDocs;
5022}
5023
5024
5025//-----------------------------------------------------------
5026
5027/** Computes for a given list type \a inListType, which are the
5028 * the corresponding list type(s) in the base class that are to be
5029 * added to this list.
5030 *
5031 * So for public inheritance, the mapping is 1-1, so outListType1=inListType
5032 * Private members are to be hidden completely.
5033 *
5034 * For protected inheritance, both protected and public members of the
5035 * base class should be joined in the protected member section.
5036 *
5037 * For private inheritance, both protected and public members of the
5038 * base class should be joined in the private member section.
5039 */
5041 MemberListType inListType,
5042 Protection inProt,
5043 MemberListType *outListType1,
5044 MemberListType *outListType2
5045 )
5046{
5047 bool extractPrivate = Config_getBool(EXTRACT_PRIVATE);
5048
5049 // default representing 1-1 mapping
5050 *outListType1=inListType;
5051 *outListType2=MemberListType::Invalid();
5052
5053 if (inProt==Protection::Public)
5054 {
5055 if (inListType.isPrivate())
5056 {
5057 *outListType1=MemberListType::Invalid();
5058 }
5059 }
5060 else if (inProt==Protection::Protected)
5061 {
5062 if (inListType.isPrivate() || inListType.isPublic())
5063 {
5064 *outListType1=MemberListType::Invalid();
5065 }
5066 else if (inListType.isProtected())
5067 {
5068 *outListType2=inListType.toPublic();
5069 }
5070 }
5071 else if (inProt==Protection::Private)
5072 {
5073 if (inListType.isPublic() || inListType.isProtected())
5074 {
5075 *outListType1=MemberListType::Invalid();
5076 }
5077 else if (inListType.isPrivate())
5078 {
5079 if (extractPrivate)
5080 {
5081 *outListType1=inListType.toPublic();
5082 *outListType2=inListType.toProtected();
5083 }
5084 else
5085 {
5086 *outListType1=MemberListType::Invalid();
5087 }
5088 }
5089 }
5090
5091 //printf("convertProtectionLevel(type=%s prot=%d): %s,%s\n",
5092 // qPrint(inListType.to_string()),inProt,qPrint(outListType1->to_string()),qPrint(outListType2->to_string()));
5093}
5094
5096{
5097 return Doxygen::mainPage!=nullptr && Doxygen::mainPage->hasTitle();
5098}
5099
5101{
5102 return getDotImageExtension(Config_getEnumAsString(DOT_IMAGE_FORMAT));
5103}
5105{
5106 size_t i= format.find(':'); // strip renderer part when using e.g. 'png:cairo:gd' as format
5107 return i==DString::npos ? format : format.left(i);
5108}
5109
5111{
5112 StringVector splitExt = split(format.str(),":");
5113 DString extGen;
5114 for (size_t i = splitExt.size(); i > 0; )
5115 {
5116 --i;
5117 extGen += splitExt[i] + (i!=0 ? "." : "");
5118 }
5119 return extGen;
5120}
5121
5122bool openOutputFile(const DString &outFile,std::ofstream &f)
5123{
5124 ASSERT(!f.is_open());
5125 bool fileOpened=false;
5126 bool writeToStdout=outFile=="-";
5127 if (writeToStdout) // write to stdout
5128 {
5129 f.basic_ios<char>::rdbuf(std::cout.rdbuf());
5130 fileOpened = true;
5131 }
5132 else // write to file
5133 {
5134 FileInfo fi(outFile.str());
5135 if (fi.exists()) // create a backup
5136 {
5137 Dir dir;
5138 FileInfo backup(fi.filePath()+".bak");
5139 if (backup.exists()) // remove existing backup
5140 dir.remove(backup.filePath());
5141 dir.rename(fi.filePath(),fi.filePath()+".bak");
5142 }
5143 f = Portable::openOutputStream(outFile);
5144 fileOpened = f.is_open();
5145 }
5146 return fileOpened;
5147}
5148
5149//------------------------------------------------------
5150
5151//! remove disabled blocks and all block markers from \a s and return the result as a string
5152DString selectBlocks(const DString &s,const SelectionBlockList &blockList,const SelectionMarkerInfo &markerInfo)
5153{
5154 if (s.empty()) return s;
5155
5156 // helper to find the end of a block
5157 auto skipBlock = [&markerInfo](const char *p,const SelectionBlock &blk)
5158 {
5159 char c = 0;
5160 while ((c=*p))
5161 {
5162 if (c==markerInfo.markerChar && dstrncmp(p,markerInfo.endStr,markerInfo.endLen)==0) // end marker
5163 {
5164 size_t len = markerInfo.endLen;
5165 bool negate = *(p+markerInfo.endLen)=='!';
5166 if (negate) len++;
5167 size_t blkNameLen = dstrlen(blk.name);
5168 if (dstrncmp(p+len,blk.name,blkNameLen)==0 && // matching marker name
5169 dstrncmp(p+len+blkNameLen,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
5170 {
5171 //printf("Found end marker %s enabled=%d negate=%d\n",blk.name,blk.enabled,negate);
5172 return p+len+blkNameLen+markerInfo.closeLen;
5173 }
5174 else // not the right marker id
5175 {
5176 p++;
5177 }
5178 }
5179 else // not and end marker
5180 {
5181 p++;
5182 }
5183 }
5184 return p;
5185 };
5186
5187 DString result;
5188 result.reserve(s.length());
5189 const char *p = s.data();
5190 char c = 0;
5191 while ((c=*p))
5192 {
5193 if (c==markerInfo.markerChar) // potential start of marker
5194 {
5195 if (dstrncmp(p,markerInfo.beginStr,markerInfo.beginLen)==0) // start of begin marker
5196 {
5197 bool found = false;
5198 size_t len = markerInfo.beginLen;
5199 bool negate = *(p+len)=='!';
5200 if (negate) len++;
5201 for (const auto &blk : blockList)
5202 {
5203 size_t blkNameLen = dstrlen(blk.name);
5204 if (dstrncmp(p+len,blk.name,blkNameLen)==0 && // matching marker name
5205 dstrncmp(p+len+blkNameLen,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
5206 {
5207 bool blockEnabled = blk.enabled!=negate;
5208 //printf("Found start marker %s enabled=%d negate=%d\n",blk.name,blk.enabled,negate);
5209 p+=len+blkNameLen+markerInfo.closeLen;
5210 if (!blockEnabled) // skip until the end of the block
5211 {
5212 //printf("skipping block\n");
5213 p=skipBlock(p,blk);
5214 }
5215 found=true;
5216 break;
5217 }
5218 }
5219 if (!found) // unknown marker id
5220 {
5221 result+=c;
5222 p++;
5223 }
5224 }
5225 else if (dstrncmp(p,markerInfo.endStr,markerInfo.endLen)==0) // start of end marker
5226 {
5227 bool found = false;
5228 size_t len = markerInfo.endLen;
5229 bool negate = *(p+len)=='!';
5230 if (negate) len++;
5231 for (const auto &blk : blockList)
5232 {
5233 size_t blkNameLen = dstrlen(blk.name);
5234 if (dstrncmp(p+len,blk.name,blkNameLen)==0 && // matching marker name
5235 dstrncmp(p+len+blkNameLen,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
5236 {
5237 //printf("Found end marker %s enabled=%d negate=%d\n",blk.name,blk.enabled,negate);
5238 p+=len+blkNameLen+markerInfo.closeLen;
5239 found=true;
5240 break;
5241 }
5242 }
5243 if (!found) // unknown marker id
5244 {
5245 result+=c;
5246 p++;
5247 }
5248 }
5249 else // not a start or end marker
5250 {
5251 result+=c;
5252 p++;
5253 }
5254 }
5255 else // not a marker character
5256 {
5257 result+=c;
5258 p++;
5259 }
5260 }
5261 //printf("====\n%s\n-----\n%s\n~~~~\n",qPrint(s),qPrint(result));
5262 return result;
5263}
5264
5265void checkBlocks(const DString &s, const DString fileName,const SelectionMarkerInfo &markerInfo)
5266{
5267 if (s.empty()) return;
5268
5269 const char *p = s.data();
5270 char c = 0;
5271 while ((c=*p))
5272 {
5273 if (c==markerInfo.markerChar) // potential start of marker
5274 {
5275 if (dstrncmp(p,markerInfo.beginStr,markerInfo.beginLen)==0) // start of begin marker
5276 {
5277 size_t len = markerInfo.beginLen;
5278 bool negate = *(p+len)=='!';
5279 if (negate) len++;
5280 p += len;
5281 DString marker;
5282 while (*p)
5283 {
5284 if (markerInfo.closeLen==0 && *p=='\n') // matching end of line
5285 {
5286 warn(fileName,-1,"Remaining begin replacement with marker '{}'",marker);
5287 break;
5288 }
5289 else if (markerInfo.closeLen!= 0 && dstrncmp(p,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
5290 {
5291 p += markerInfo.closeLen;
5292 warn(fileName,-1,"Remaining begin replacement with marker '{}'",marker);
5293 break;
5294 }
5295 marker += *p;
5296 p++;
5297 }
5298 }
5299 else if (dstrncmp(p,markerInfo.endStr,markerInfo.endLen)==0) // start of end marker
5300 {
5301 size_t len = markerInfo.endLen;
5302 bool negate = *(p+len)=='!';
5303 if (negate) len++;
5304 p += len;
5305 DString marker;
5306 while (*p)
5307 {
5308 if (markerInfo.closeLen==0 && *p=='\n') // matching end of line
5309 {
5310 warn(fileName,-1,"Remaining end replacement with marker '{}'",marker);
5311 break;
5312 }
5313 else if (markerInfo.closeLen!= 0 && dstrncmp(p,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
5314 {
5315 p += markerInfo.closeLen;
5316 warn(fileName,-1,"Remaining end replacement with marker '{}'",marker);
5317 break;
5318 }
5319 marker += *p;
5320 p++;
5321 }
5322 }
5323 }
5324 p++;
5325 }
5326}
5327
5328
5329
5330DString detab(const DString &s,size_t &refIndent)
5331{
5332 int tabSize = Config_getInt(TAB_SIZE);
5333 size_t size = s.length();
5334 DString result;
5335 result.reserve(size+256);
5336 const char *data = s.data();
5337 size_t i=0;
5338 int col=0;
5339 constexpr auto doxy_nbsp = "&_doxy_nbsp;"; // doxygen escape command for UTF-8 nbsp
5340 const int maxIndent=1000000; // value representing infinity
5341 int minIndent=maxIndent;
5342 bool skip = false;
5343 while (i<size)
5344 {
5345 char c = data[i++];
5346 switch(c)
5347 {
5348 case '\t': // expand tab
5349 {
5350 int stop = tabSize - (col%tabSize);
5351 //printf("expand at %d stop=%d\n",col,stop);
5352 col+=stop;
5353 while (stop--) result+=' ';
5354 }
5355 break;
5356 case '\\':
5357 if (skip && data[i] == '\\' && i+8<size && literal_at(data+i+1,"endiskip"))
5358 {
5359 // literal backslash directly followed by , e.g. `\` in a code span
5360 result+=c;
5361 col++;
5362 }
5363 else if (data[i] == '\\') // escaped command -> ignore
5364 {
5365 result+=c;
5366 result+=data[i++];
5367 col+=2;
5368 }
5369 else if (i+5<size && literal_at(data+i,"iskip")) // command
5370 {
5371 i+=5;
5372 skip = true;
5373 }
5374 else if (i+8<size && literal_at(data+i,"endiskip")) // command
5375 {
5376 i+=8;
5377 skip = false;
5378 }
5379 else // some other command
5380 {
5381 result+=c;
5382 col++;
5383 }
5384 break;
5385 case '\n': // reset column counter
5386 result+=c;
5387 col=0;
5388 break;
5389 case ' ': // increment column counter
5390 result+=c;
5391 col++;
5392 break;
5393 default: // non-whitespace => update minIndent
5394 if (static_cast<signed char>(c)<0 && i<size) // multibyte sequence
5395 {
5396 // special handling of the UTF-8 nbsp character 0xC2 0xA0
5397 int nb = isUTF8NonBreakableSpace(data);
5398 if (nb>0)
5399 {
5400 result+=doxy_nbsp;
5401 i+=nb-1;
5402 }
5403 else
5404 {
5405 int bytes = getUTF8CharNumBytes(c);
5406 for (int j=0;j<bytes-1 && c;j++)
5407 {
5408 result+=c;
5409 c = data[i++];
5410 }
5411 result+=c;
5412 }
5413 }
5414 else
5415 {
5416 result+=c;
5417 }
5418 if (!skip && col<minIndent) minIndent=col;
5419 col++;
5420 }
5421 }
5422 if (minIndent!=maxIndent) refIndent=minIndent; else refIndent=0;
5423 //printf("detab(\n%s\n)=[\n%s\n]\n",qPrint(s),qPrint(out.get()));
5424 return result;
5425}
5426
5428{
5429 DString projectCookie = Config_getString(HTML_PROJECT_COOKIE);
5430 if (projectCookie.empty()) return DString();
5431 return md5str(projectCookie.view())+"_";
5432}
5433
5434//! Return the index of the last :: in the string \a name that is still before the first <
5436{
5437 int l = static_cast<int>(name.length());
5438 int lastSepPos = -1;
5439 const char *p = name.data();
5440 int i=l-2;
5441 int sharpCount=0;
5442 // --- begin optimized version of ts=name.findRev(">::");
5443 int ts = -1;
5444 while (i>=0)
5445 {
5446 if (p[i]=='>')
5447 {
5448 if (sharpCount==0 && p[i+1]==':' && p[i+2]==':')
5449 {
5450 ts=i;
5451 break;
5452 }
5453 sharpCount++;
5454 }
5455 else if (p[i]=='<')
5456 {
5457 sharpCount--;
5458 }
5459 i--;
5460 }
5461 // --- end optimized version
5462 if (ts==-1) ts=0; else p+=++ts;
5463 for (i=ts;i<l-1;i++)
5464 {
5465 char c=*p++;
5466 if (c==':' && *p==':') lastSepPos=i;
5467 if (c=='<') break;
5468 }
5469 return lastSepPos;
5470}
5471
5472// in C# A, A<T>, and A<T,S> are different classes, so we need some way to disguish them using this name mangling
5473// A -> A
5474// A<T> -> A-1-g
5475// A<T,S> -> A-2-g
5476// A<T>::B -> A-1-g::B
5478{
5479 DString result;
5480 size_t p=0;
5481 size_t idx;
5482 while ((idx=name.find('<',p))!=DString::npos)
5483 {
5484 result+=name.mid(p,idx-p);
5485 // count the top level arguments of the balanced <...> group
5486 int depth=0;
5487 int count=1;
5488 size_t i=idx;
5489 for (; i<name.length(); i++)
5490 {
5491 char c=name[i];
5492 if (c=='<') depth++;
5493 else if (c=='>' && --depth==0) break;
5494 else if (c==',' && depth==1) count++;
5495 }
5496 result+="-"+DString().setNum(count)+"-g";
5497 p=i+1;
5498 }
5499 if (p<name.length()) result+=name.mid(p);
5500 return result;
5501}
5502
5504{
5505 DString result=name;
5506 if (result.endsWith("-g"))
5507 {
5508 size_t idx = result.find('-');
5509 result = result.left(idx)+templArgs;
5510 }
5511 return result;
5512}
5513
5515{
5516 DString text=rawStart;
5517 size_t i = text.find('"');
5519 return text.mid(i+1,text.length()-i-2); // text=...R"xyz( -> delimiter=xyz
5520}
5521
5523{
5524 DString text=rawEnd;
5525 return text.mid(1,text.length()-2); // text=)xyz" -> delimiter=xyz
5526}
5527
5528//----------------------------------------------------------------------------------------------------------
5529
5530static std::mutex writeFileContents_lock;
5532
5533DString writeInlineGraph(const DString &baseName,const DString &extension,const DString &content,bool &exists)
5534{
5535 DString fileName = baseName + md5str(content.view()) + extension;
5536 { // ==== start atomic section
5537 std::lock_guard lock(writeFileContents_lock);
5538 auto it=writeFileContents_set.find(fileName.str());
5539 exists = it!=writeFileContents_set.end();
5540 if (!exists)
5541 {
5542 writeFileContents_set.insert(fileName.str());
5543 if (auto file = Portable::openOutputStream(fileName); file.is_open())
5544 {
5545 file.write( content.data(), content.length() );
5546 file.close();
5547 }
5548 else
5549 {
5550 err("Could not open file {} for writing\n",fileName);
5551 return DString();
5552 }
5553 }
5554 } // ==== end atomic section
5555 return fileName;
5556}
5557
5559{
5560 if (Config_getBool(DOT_CLEANUP))
5561 {
5562 for (const auto& fileName: writeFileContents_set)
5563 {
5564 Dir().remove(qPrint(fileName));
5565 }
5566 }
5567}
5568
constexpr auto prefix
Definition anchor.cpp:47
This class contains the information about the argument of a function or template.
Definition arguments.h:27
DString docs
Definition arguments.h:48
DString attrib
Definition arguments.h:42
DString defval
Definition arguments.h:47
DString array
Definition arguments.h:46
DString name
Definition arguments.h:45
DString type
Definition arguments.h:43
DString canType
Definition arguments.h:44
This class represents an function or template argument list.
Definition arguments.h:66
RefQualifierType refQualifier() const
Definition arguments.h:117
bool pureSpecifier() const
Definition arguments.h:114
iterator end()
Definition arguments.h:95
bool hasParameters() const
Definition arguments.h:77
Argument & front()
Definition arguments.h:106
DString trailingReturnType() const
Definition arguments.h:115
size_t size() const
Definition arguments.h:101
typename Vec::const_iterator const_iterator
Definition arguments.h:70
bool constSpecifier() const
Definition arguments.h:112
bool hasDocumentation(bool allowEmptyNames=false) const
Definition arguments.cpp:26
bool empty() const
Definition arguments.h:100
bool hasTemplateDocumentation() const
Definition arguments.cpp:34
iterator begin()
Definition arguments.h:94
bool volatileSpecifier() const
Definition arguments.h:113
A abstract class representing of a compound symbol.
Definition classdef.h:100
virtual const ArgumentList & templateArguments() const =0
Returns the template arguments of this class.
virtual bool isTemplate() const =0
Returns true if this class is a template.
virtual const BaseClassList & baseClasses() const =0
Returns the list of base classes from which this class directly inherits.
virtual DString qualifiedNameWithTemplateParameters(const ArgumentLists *actualParams=nullptr, uint32_t *actualParamIndex=nullptr) const =0
virtual FileDef * getFileDef() const =0
Returns the file in which this compound's definition can be found.
virtual bool isUsedOnly() const =0
static void hsl2rgb(double h, double s, double l, double *pRed, double *pGreen, double *pBlue)
Definition image.cpp:373
virtual const FileDef * getFileDef() const =0
A String class for use with Doxygen wrapping std::string and adding some additional functionality off...
Definition dstring.h:84
void clear()
Definition dstring.h:214
DString & setNum(short n)
Definition dstring.h:552
void resize(size_t newlen)
Definition dstring.h:209
size_t rfind(char c, size_t pos=npos) const
Definition dstring.h:244
DString mid(size_t index, size_t len=npos) const
Definition dstring.h:318
DString lower() const
Definition dstring.h:326
DString simplifyWhiteSpace() const
return a copy of this string with leading and trailing whitespace removed and multiple internal white...
Definition dstring.cpp:127
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
DString substr(size_t pos=0, size_t count=npos) const
Returns a substring of length count starting at pos.
Definition dstring.h:223
char * rawData()
Returns a writable pointer to the data.
Definition dstring.h:166
const char * c_str() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:160
std::string_view view() const
Definition dstring.h:162
static constexpr size_t npos
value used to indicate 'not found' or 'to the end of the string', matching std::string::npos
Definition dstring.h:178
char & at(size_t i)
Returns a reference to the character at index i.
Definition dstring.h:686
DString quoted() const
Definition dstring.h:352
DString right(size_t len) const
Definition dstring.h:311
DString & prepend(const char *s)
Definition dstring.h:515
size_t find(char c, size_t pos=0) const
Definition dstring.h:239
DString & sprintf(const char *format,...)
Definition dstring.cpp:34
void reserve(size_t size)
Reserve space for size bytes without changing the string contents.
Definition dstring.h:217
DString stripWhiteSpace() const
returns a copy of this string with leading and trailing whitespace removed
Definition dstring.h:337
DString left(size_t len) const
Definition dstring.h:306
const std::string & str() const
Definition dstring.h:645
bool stripPrefix(const DString &prefix)
Definition dstring.h:290
const char * data() const
Returns a pointer to the contents of the string in the form of a 0-terminated C string.
Definition dstring.h:157
bool startsWith(const char *s) const
Definition dstring.h:600
bool endsWith(const char *s) const
Definition dstring.h:617
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151
@ FilterOutput
Definition debug.h:39
@ ExtCmd
Definition debug.h:37
static void print(DebugMask mask, int prio, fmt::format_string< Args... > fmt, Args &&... args)
Definition debug.h:78
The common base class of all entity definitions found in the sources.
Definition definition.h:77
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 const DString & name() const =0
virtual DString displayName(bool includeScope=true) const =0
virtual DString qualifiedName() const =0
virtual DString anchor() const =0
virtual DString getReference() const =0
virtual const GroupList & partOfGroups() const =0
virtual bool isArtificial() const =0
virtual Definition * getOuterScope() const =0
virtual DString docFile() const =0
virtual const Definition * findInnerCompound(const DString &name) const =0
virtual DString getOutputFileBase() const =0
A model of a directory symbol.
Definition dirdef.h:108
Class representing a directory in the file system.
Definition dir.h:73
bool mkdir(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:300
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:319
bool empty(const std::string &subdir) const
Definition dir.cpp:268
bool rmdir(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:314
bool rename(const std::string &orgName, const std::string &newName, bool acceptsAbsPath=true) const
Definition dir.cpp:326
bool exists() const
Definition dir.cpp:262
static NamespaceLinkedMap * namespaceLinkedMap
Definition doxygen.h:108
static ConceptLinkedMap * conceptLinkedMap
Definition doxygen.h:90
static std::unique_ptr< PageDef > mainPage
Definition doxygen.h:93
static FileNameLinkedMap * inputNameLinkedMap
Definition doxygen.h:97
static ParserManager * parserManager
Definition doxygen.h:122
static InputFileEncodingList inputFileEncodingList
Definition doxygen.h:131
static MemberNameLinkedMap * functionNameLinkedMap
Definition doxygen.h:105
static PageLinkedMap * exampleLinkedMap
Definition doxygen.h:91
static NamespaceDefMutable * globalScope
Definition doxygen.h:114
static StringMap tagDestinationMap
Definition doxygen.h:109
static PageLinkedMap * pageLinkedMap
Definition doxygen.h:92
static DString htmlFileExtension
Definition doxygen.h:115
static DirLinkedMap * dirLinkedMap
Definition doxygen.h:120
static MemberNameLinkedMap * memberNameLinkedMap
Definition doxygen.h:104
static SymbolMap< Definition > * symbolMap
Definition doxygen.h:118
static FileNameLinkedMap * exampleNameLinkedMap
Definition doxygen.h:95
static GroupLinkedMap * groupLinkedMap
Definition doxygen.h:107
A model of a file symbol.
Definition filedef.h:97
virtual ModuleDef * getModuleDef() const =0
virtual DString absFilePath() const =0
Minimal replacement for QFileInfo.
Definition fileinfo.h:26
bool exists() const
Definition fileinfo.cpp:35
size_t size() const
Definition fileinfo.cpp:28
std::string extension(bool complete) const
Definition fileinfo.cpp:135
bool match(const PatternList &patList, bool caseSenseNames, PatternElem *elem=nullptr, PatternGet getter=[](const std::string &s){ return s;}) const
Match the file name against a list of patterns.
Definition fileinfo.h:60
bool isDir() const
Definition fileinfo.cpp:75
bool isFile() const
Definition fileinfo.cpp:68
std::string dirPath(bool absPath=true) const
Definition fileinfo.cpp:142
std::string filePath() const
Definition fileinfo.cpp:96
std::string absFilePath() const
Definition fileinfo.cpp:106
FileDef * findFileDef(const DString &n, bool &ambig) const
Returns the file definition in fnMap that matches the file name n.
Definition filename.cpp:38
A model of a group of symbols.
Definition groupdef.h:48
const char * writeHtmlEntity(T &result, const char *s, HtmlEntityMapperFunc &&mapper, const char *fallback)
Definition htmlentity.h:127
const char * xml(SymType symb) const
Access routine to the XML code of the HTML entity.
static HtmlEntityMapper & instance()
Returns the one and only instance of the HTML entity mapper.
DString convertCharEntitiesToUTF8(const DString &s) const
const T * find(const std::string &key) const
Definition linkedmap.h:47
A model of a class/file/namespace member symbol.
Definition memberdef.h:45
virtual DString argsString() const =0
virtual bool isRelated() const =0
virtual const ClassDef * getClassDef() const =0
virtual GroupDef * getGroupDef()=0
virtual bool isTypedef() const =0
virtual const FileDef * getFileDef() const =0
virtual bool isStrongEnumValue() const =0
virtual bool isStatic() const =0
virtual const NamespaceDef * getNamespaceDef() const =0
virtual bool isEnumerate() const =0
virtual DString typeString() const =0
Wrapper class for the MemberListType type.
Definition types.h:346
constexpr bool isPrivate() const noexcept
Definition types.h:382
constexpr MemberListType toPublic() const noexcept
Definition types.h:426
static constexpr MemberListType Invalid() noexcept
Definition types.h:371
constexpr MemberListType toProtected() const noexcept
Definition types.h:438
constexpr bool isProtected() const noexcept
Definition types.h:380
ML_TYPES constexpr bool isPublic() const noexcept
Definition types.h:378
Ordered dictionary of MemberName objects.
Definition membername.h:61
static ModuleManager & instance()
An abstract interface of a namespace symbol.
Class representing a list of output generators that are written to in parallel.
Definition outputlist.h:311
void parseText(const DString &textStr)
void endConstraintType()
Definition outputlist.h:710
void disable(OutputType o)
void writeObjectLink(const DString &ref, const DString &file, const DString &anchor, const DString &name)
Definition outputlist.h:435
void endConstraintList()
Definition outputlist.h:716
void startConstraintList(const DString &header)
Definition outputlist.h:702
void startConstraintParam()
Definition outputlist.h:704
void writeString(const DString &text)
Definition outputlist.h:407
void startConstraintDocs()
Definition outputlist.h:712
void startConstraintType()
Definition outputlist.h:708
void endConstraintDocs()
Definition outputlist.h:714
void pushGeneratorState()
void disableAllBut(OutputType o)
void popGeneratorState()
void endConstraintParam()
Definition outputlist.h:706
void generateDoc(const DString &fileName, int startLine, const Definition *ctx, const MemberDef *md, const DString &docStr, const DocOptions &options)
A model of a page symbol.
Definition pagedef.h:27
virtual const GroupDef * getGroupDef() const =0
class that provide information about a section.
Definition section.h:58
Definition * definition() const
Definition section.h:77
DString label() const
Definition section.h:69
static SectionManager & instance()
returns a reference to the singleton
Definition section.h:179
const VectorPtr & find(const DString &name)
Definition symbolmap.h:74
int isAccessibleFrom(const Definition *scope, const Definition *item)
Checks if symbol item is accessible from within scope.
const ClassDef * resolveClass(const Definition *scope, const DString &name, bool maybeUnlinkable=false, bool mayBeHidden=false)
Find the class definition matching name within the scope set.
const Definition * resolveSymbol(const Definition *scope, const DString &name, const DString &args=DString(), bool checkCV=false, bool insideCode=false, bool onlyLinkable=false)
Find the symbool definition matching name within the scope set.
DString getResolvedType() const
In case a call to resolveClass() points to a typedef or using declaration.
int isAccessibleFromWithExpScope(const Definition *scope, const Definition *item, const DString &explicitScopePart)
Check if symbol item is accessible from within scope, where it has to match the explicitScopePart.
DString getTemplateSpec() const
In case a call to resolveClass() points to a template specialization, the template part is return via...
void setFileScope(const FileDef *fd)
Sets or updates the file scope using when resolving symbols.
const MemberDef * getTypedef() const
In case a call to resolveClass() resolves to a type member (e.g. an enum) this method will return it.
Implements TextGeneratorIntf for an OutputDocInterface stream.
Definition outputlist.h:786
Text streaming class that buffers data.
Definition textstream.h:36
std::string str() const
Return the contents of the buffer as a std::string object.
Definition textstream.h:232
virtual DString trTypeConstraints()=0
virtual DString trModule(bool first_capital, bool singular)=0
virtual DString trWriteList(int numEntries)=0
ClassDef * getClass(const DString &n)
ClassDef * toClassDef(Definition *d)
std::vector< BaseClassDef > BaseClassList
Definition classdef.h:77
Class representing a regular expression.
Definition regex.h:39
@ Wildcard
simple globbing pattern.
Definition regex.h:45
bool isValid() const
Definition regex.cpp:843
Class to iterate through matches.
Definition regex.h:245
ConceptDef * getConcept(const DString &n)
ConceptDef * toConceptDef(Definition *d)
#define Config_getInt(name)
Definition config.h:34
#define Config_getList(name)
Definition config.h:38
#define Config_getEnumAsString(name)
Definition config.h:36
#define Config_getBool(name)
Definition config.h:33
#define Config_getString(name)
Definition config.h:32
#define Config_getEnum(name)
Definition config.h:35
std::unordered_set< std::string > StringUnorderedSet
Definition containers.h:29
std::vector< std::string > StringVector
Definition containers.h:33
DString formatDateTime(const DString &format, const std::tm &dt, int &formatUsed)
Return a string representation for a given std::tm value that is formatted according to the pattern g...
Definition datetime.cpp:176
DString dateTimeFromString(const DString &spec, std::tm &dt, int &format)
Returns the filled in std::tm for a given string representing a date and/or time.
Definition datetime.cpp:135
std::unique_ptr< ArgumentList > stringToArgumentList(SrcLangExt lang, const DString &argsString, DString *extraTypeChars=nullptr)
Definition defargs.l:822
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:180
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:54
#define AUTO_TRACE(...)
Definition docnode.cpp:53
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:55
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
#define THREAD_LOCAL
Definition doxygen.h:29
DString substitute(const DString &s, const DString &src, const DString &dst)
substitute all occurrences of src in s by dst
Definition dstring.cpp:485
int dstricmp(const char *s1, const char *s2)
Definition dstring.cpp:444
bool isId(char c)
Returns true if c is a valid character for an identifier.
Definition dstring.h:895
int dstrncmp(const char *str1, const char *str2, size_t len)
Definition dstring.h:56
uint32_t dstrlen(const char *str)
Returns the length of string str, or 0 if a null pointer is passed.
Definition dstring.h:39
const char * qPrint(const char *s)
Definition dstring.h:783
bool disspace(char c)
Definition dstring.h:62
FileDef * toFileDef(Definition *d)
Definition filedef.cpp:2054
Translator * theTranslator
Definition language.cpp:76
void linkifyText(const TextGeneratorIntf &out, const DString &text, const LinkifyTextOptions &options)
DString md5str(const std::string_view &str)
Definition md5hash.h:33
std::array< uint8_t, 16 > md5hash(const std::string_view &str)
Definition md5hash.h:26
MemberDef * toMemberDef(Definition *d)
#define warn(file, line, fmt,...)
Definition message.h:97
#define err(fmt,...)
Definition message.h:127
#define ASSERT(x)
Definition message.h:142
#define term(fmt,...)
Definition message.h:137
ModuleDef * toModuleDef(Definition *d)
FILE * popen(const DString &name, const DString &type)
Definition portable.cpp:495
std::ifstream openInputStream(const DString &name, bool binary=false, bool openAtEnd=false)
Definition portable.cpp:690
int pclose(FILE *stream)
Definition portable.cpp:504
DString removeLongPathMarker(const DString &path)
Definition portable.cpp:656
bool fileSystemIsCaseSensitive()
Definition portable.cpp:486
DString pathSeparator()
Definition portable.cpp:390
std::ofstream openOutputStream(const DString &name, bool append=false)
Definition portable.cpp:679
void replaceNamespaceAliases(DString &name)
NamespaceDef * getResolvedNamespace(const DString &name)
NamespaceDef * toNamespaceDef(Definition *d)
Definition message.h:146
std::string replace(std::string_view str, const Ex &re, std::string_view replacement)
Searching in a given input string for parts that match regular expression re and replaces those parts...
Definition regex.cpp:872
bool match(std::string_view str, Match &match, const Ex &re)
Matches a given string str for a match against regular expression re.
Definition regex.cpp:861
Token literal values and constants.
Definition CharStream.h:12
Portable versions of functions that are platform dependent.
int portable_iconv_close(void *cd)
size_t portable_iconv(void *cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft)
void * portable_iconv_open(const char *tocode, const char *fromcode)
Some helper functions for std::string.
void addTerminalCharIfMissing(std::string &s, char c)
Definition stringutil.h:87
bool literal_at(const char *data, const char(&str)[N])
returns true iff data points to a substring that matches string literal str
Definition stringutil.h:101
StringVector split(const std::string &s, const std::string &delimiter, bool retainEmpty=false)
split input string s by string delimiter delimiter.
Definition stringutil.h:119
CharElem charMap[256]
Definition util.cpp:421
Helper class to pass options when calling OutputList::generateDoc().
Definition docoptions.h:24
bool forceEmptyScope
Definition util.h:102
const FileDef * currentFile
Definition util.h:103
bool insideCode
Definition util.h:105
DString args
Definition util.h:101
DString memberName
Definition util.h:100
bool checkCV
Definition util.h:104
DString scopeName
Definition util.h:99
bool allowCrossFileStatic
Definition util.h:106
const MemberDef * md
Definition util.h:113
const ConceptDef * cnd
Definition util.h:118
const FileDef * fd
Definition util.h:115
const ModuleDef * modd
Definition util.h:119
const GroupDef * gd
Definition util.h:117
bool found
Definition util.h:112
const ClassDef * cd
Definition util.h:114
const NamespaceDef * nd
Definition util.h:116
DString encoding
Definition doxygen.h:63
SrcLangExt parserId
Definition util.cpp:4167
const char * langName
Definition util.cpp:4165
const char * parserName
Definition util.cpp:4166
const char * defExt
Definition util.cpp:4168
bool binary() const
Definition util.h:64
bool filter() const
Definition util.h:62
bool isSourceCode() const
Definition util.h:63
size_t beginLen
Definition util.h:238
const char * closeStr
Definition util.h:241
const char * beginStr
Definition util.h:237
size_t closeLen
Definition util.h:242
const char * endStr
Definition util.h:239
Protection
Definition types.h:32
SrcLangExt
Definition types.h:207
int isUTF8NonBreakableSpace(const char *input)
Check if the first character pointed at by input is a non-breakable whitespace character.
Definition utf8.cpp:232
uint8_t getUTF8CharNumBytes(char c)
Returns the number of bytes making up a single UTF8 character given the first byte in the sequence.
Definition utf8.cpp:27
Various UTF8 related helper functions.
bool readInputFile(const DString &fileName, std::string &contents, const ReadInputFileOptions &options)
read a file name fileName and optionally filter and transcode it
Definition util.cpp:4506
DString stripExtension(const DString &fName)
Definition util.cpp:4087
bool useCaseSenseNames()
Returns true if the names of the symbols can be case sensitive.
Definition util.cpp:2811
bool isURL(const DString &url)
Checks whether the given url starts with a supported protocol.
Definition util.cpp:4782
DString substituteTemplateArgumentsInString(const DString &nm, const ArgumentList &formalArgs, const ArgumentList *actualArgs)
Definition util.cpp:3656
static DString extractDirection(DString &docs)
Strip the direction part from docs and return it as a string in canonical form.
Definition util.cpp:4965
static size_t findParameterList(const DString &name)
Returns the position in the string where a function parameter list begins, or DString::npos if one is...
Definition util.cpp:689
static std::mutex writeFileContents_lock
Definition util.cpp:5530
DString inlineArgListToDoc(const ArgumentList &al)
Definition util.cpp:5001
DString stripLeadingAndTrailingEmptyLines(const DString &s, int &docLine)
Special version of DString::stripWhiteSpace() that only strips completely blank lines.
Definition util.cpp:4119
bool mainPageHasTitle()
Definition util.cpp:5095
DString replaceColorMarkers(const DString &str)
Replaces any markers of the form ##AA in input string str by new markers of the form #AABBCC,...
Definition util.cpp:4704
bool protectionLevelVisible(Protection prot)
Definition util.cpp:4807
DString stripFromIncludePath(const DString &path)
Definition util.cpp:227
static bool matchUnresolvedTypes(const Definition *srcScope, const FileDef *srcFileScope, const DString &srcType, const Definition *dstScope, const FileDef *dstFileScope, const DString &dstType)
Definition util.cpp:1531
DString mergeScopes(const DString &leftScope, const DString &rightScope)
Definition util.cpp:3885
DString filterTitle(const DString &title)
Definition util.cpp:4590
DString detab(const DString &s, size_t &refIndent)
Definition util.cpp:5330
DString selectBlocks(const DString &s, const SelectionBlockList &blockList, const SelectionMarkerInfo &markerInfo)
remove disabled blocks and all block markers from s and return the result as a string
Definition util.cpp:5152
bool matchTemplateArguments(const ArgumentList &srcAl, const ArgumentList &dstAl)
Definition util.cpp:1893
void stripIndentationVerbatim(DString &doc, size_t indentationLevel, bool skipFirstLine)
Definition util.cpp:4908
void addCodeOnlyMappings()
Definition util.cpp:4294
static int g_usedNamesCount
Definition util.cpp:2987
static void filterCRLF(std::string &contents)
Definition util.cpp:964
static void stripIrrelevantString(DString &target, const DString &str, bool insideTemplate)
Definition util.cpp:1116
static DString stripDeclKeywords(const DString &s)
Definition util.cpp:1186
void writeTypeConstraints(OutputList &ol, const Definition *d, const ArgumentList &al)
Definition util.cpp:4415
DString extractBeginRawStringDelimiter(const char *rawStart)
Definition util.cpp:5514
void stripIrrelevantConstVolatile(DString &s, bool insideTemplate)
Definition util.cpp:1176
static DString getFilterFromList(const DString &name, const StringVector &filterList, bool &found)
Definition util.cpp:990
DString getProjectId()
Definition util.cpp:5427
#define REL_PATH_TO_ROOT
Definition util.cpp:78
static DString extractCanonicalArgType(const Definition *d, const FileDef *fs, const Argument &arg, SrcLangExt lang)
Definition util.cpp:1466
static DString getCanonicalTemplateSpec(const Definition *d, const FileDef *fs, const DString &spec, SrcLangExt lang)
Definition util.cpp:1204
DString writeInlineGraph(const DString &baseName, const DString &extension, const DString &content, bool &exists)
Definition util.cpp:5533
bool resolveLink(const DString &scName, const DString &lr, bool, const Definition **resContext, DString &resAnchor, SrcLangExt lang, const DString &prefix, const FileDef *currentFile)
Definition util.cpp:2439
bool rightScopeMatch(const DString &scope, const DString &name)
Definition util.cpp:734
bool checkIfTypedef(const Definition *scope, const FileDef *fileScope, const DString &n)
Definition util.cpp:4403
static const char constScope[]
Definition util.cpp:379
static bool recursivelyAddGroupListToTitle(OutputList &ol, const Definition *d, bool root)
Definition util.cpp:4014
DString unescapeCharsInString(const DString &s)
Definition util.cpp:2907
bool resolveRef(const DString &scName, const DString &name, bool inSeeBlock, const Definition **resContext, const MemberDef **resMember, SrcLangExt lang, bool lookForSpecialization, const FileDef *currentFile, bool checkScope)
Definition util.cpp:2139
DString externalLinkTarget(const bool parent)
Definition util.cpp:4627
DString replaceAnonymousScopes(const DString &s, const DString &replacement)
Definition util.cpp:155
void cleanupInlineGraphs()
Definition util.cpp:5558
DString correctURL(const DString &url, const DString &relPath)
Corrects URL url according to the relative path relPath.
Definition util.cpp:4795
int computeQualifiedIndex(const DString &name)
Return the index of the last :: in the string name that is still before the first <.
Definition util.cpp:5435
DString convertToJSString(const DString &s, bool keepEntities, bool singleQuotes)
Definition util.cpp:3483
DString convertToId(const DString &s)
Definition util.cpp:3334
void trimBaseClassScope(const BaseClassList &bcl, DString &s, int level=0)
Definition util.cpp:1095
DString insertTemplateSpecifierInScope(const DString &scope, const DString &templ)
Definition util.cpp:3208
DString removeRedundantWhiteSpace(const DString &s)
Definition util.cpp:427
static std::unordered_map< std::string, SrcLangExt > g_extLookup
Definition util.cpp:4161
bool checkExtension(const DString &fName, const DString &ext)
Definition util.cpp:4058
DString convertNameToFile(const DString &name, bool allowDots, bool allowUnderscore)
Definition util.cpp:2995
DString showDate(const DString &fmt)
Definition util.cpp:2699
bool leftScopeMatch(const DString &scope, const DString &name)
Definition util.cpp:745
DString stripExtensionGeneral(const DString &fName, const DString &ext)
Definition util.cpp:4077
DString tempArgListToString(const ArgumentList &al, SrcLangExt lang, bool includeDefault)
Definition util.cpp:908
static const char staticScope[]
Definition util.cpp:383
static ModuleDef * findModuleDef(const Definition *d)
Definition util.cpp:3985
void addGroupListToTitle(OutputList &ol, const Definition *d)
Definition util.cpp:4053
DString extractEndRawStringDelimiter(const char *rawEnd)
Definition util.cpp:5522
static DString extractCanonicalType(const Definition *d, const FileDef *fs, DString type, SrcLangExt lang, bool insideTemplate)
Definition util.cpp:1379
#define MATCH
Definition util.cpp:1496
void clearSubDirs(const Dir &d)
Definition util.cpp:3128
DString stripScope(const DString &name)
Definition util.cpp:3241
DString getFileNameExtension(const DString &fn)
Definition util.cpp:4342
void createSubDirs(const Dir &d)
Definition util.cpp:3101
DString convertToHtml(const DString &s, bool keepEntities)
Definition util.cpp:3423
static bool matchArgument2(const Definition *srcScope, const FileDef *srcFileScope, Argument &srcA, const Definition *dstScope, const FileDef *dstFileScope, Argument &dstA, SrcLangExt lang, bool allowUnresolved)
Definition util.cpp:1581
DString resolveTypeDef(const Definition *context, const DString &qualifiedName, const Definition **typedefContext)
Definition util.cpp:232
DString normalizeNonTemplateArgumentsInString(const DString &name, const Definition *context, const ArgumentList &formalArgs)
Definition util.cpp:3597
SrcLangExt getLanguageFromFileName(const DString &fileName, SrcLangExt defLang)
Definition util.cpp:4300
DString getFileFilter(const DString &name, bool isSourceCode)
Definition util.cpp:1025
static MemberDef * getMemberFromSymbol(const Definition *scope, const FileDef *fileScope, const DString &n)
Definition util.cpp:4351
void initDefaultExtensionMapping()
Definition util.cpp:4227
void addHtmlExtensionIfMissing(DString &fName)
Definition util.cpp:4063
void checkBlocks(const DString &s, const DString fileName, const SelectionMarkerInfo &markerInfo)
Definition util.cpp:5265
static void transcodeCharacterBuffer(const DString &fileName, std::string &contents, const DString &inputEncoding, const DString &outputEncoding)
Definition util.cpp:4470
DString fileToString(const DString &name, bool filter, bool isSourceCode)
Definition util.cpp:1058
static const char virtualScope[]
Definition util.cpp:381
DString linkToText(SrcLangExt lang, const DString &link, bool ignoreDots)
Definition util.cpp:2396
DString substituteKeywords(const DString &file, const DString &s, const KeywordSubstitutionList &keywords)
Definition util.cpp:2626
void extractNamespaceName(const DString &scopeName, DString &className, DString &namespaceName, bool allowEmptyClass)
Definition util.cpp:3158
DString convertToXML(const DString &s, bool keepEntities, const bool citeEntry)
Definition util.cpp:3364
DString stripTemplateSpecifiersFromScope(const DString &fullName, bool parentOnly, DString *pLastScopeStripped, DString scopeName, bool allowArtificial)
Definition util.cpp:3818
DString relativePathToRoot(const DString &name)
Definition util.cpp:3044
static const DirDef * resolveDirLink(const DString &linkRef)
Definition util.cpp:2421
DString argListToString(const ArgumentList &al, bool useCanonicalType, bool showDefVals)
Definition util.cpp:864
DString projectLogoFile()
Definition util.cpp:2712
static StringUnorderedSet writeFileContents_set
Definition util.cpp:5531
void convertProtectionLevel(MemberListType inListType, Protection inProt, MemberListType *outListType1, MemberListType *outListType2)
Computes for a given list type inListType, which are the the corresponding list type(s) in the base c...
Definition util.cpp:5040
static const char volatileScope[]
Definition util.cpp:380
DString getEncoding(const FileInfo &fi)
Definition util.cpp:4613
bool copyFile(const DString &src, const DString &dest)
Copies the contents of file with name src to the newly created file with name dest.
Definition util.cpp:4755
int getPrefixIndex(const DString &name)
Definition util.cpp:2783
DString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Definition util.cpp:4765
bool updateLanguageMapping(const DString &extension, const DString &language)
Definition util.cpp:4195
bool matchArguments2(const Definition *srcScope, const FileDef *srcFileScope, const DString &srcReturnType, const ArgumentList *srcAl, const Definition *dstScope, const FileDef *dstFileScope, const DString &dstReturnType, const ArgumentList *dstAl, bool checkCV, SrcLangExt lang, bool allowUnresolved)
Definition util.cpp:1649
void stackTrace()
Definition util.cpp:4442
DString demangleCSharpGenericName(const DString &name, const DString &templArgs)
Definition util.cpp:5503
DString createHtmlUrl(const DString &relPath, const DString &ref, bool isLocalFile, const DString &targetFileName, const DString &anchor)
Definition util.cpp:4638
DString projectLogoSize()
Definition util.cpp:2731
static DString getCanonicalTypeForIdentifier(const Definition *d, const FileDef *fs, const DString &word, SrcLangExt lang, DString *tSpec, int count=0)
Definition util.cpp:1225
DString mangleCSharpGenericName(const DString &name)
Definition util.cpp:5477
GetDefResult getDefs(const GetDefInput &input)
Definition util.cpp:1926
DString getDotImageExtension()
Definition util.cpp:5100
#define NOMATCH
Definition util.cpp:1497
DString escapeCharsInString(const DString &name, bool allowDots, bool allowUnderscore)
Definition util.cpp:2820
static std::mutex g_usedNamesMutex
Definition util.cpp:2986
void mergeArguments(ArgumentList &srcAl, ArgumentList &dstAl, bool forceNameOverwrite)
Definition util.cpp:1749
int getScopeFragment(const DString &s, int p, int *l)
Definition util.cpp:3930
static bool getScopeDefs(const DString &docScope, const DString &scope, ClassDef *&cd, ConceptDef *&cnd, NamespaceDef *&nd, ModuleDef *&modd)
Definition util.cpp:2067
DString stripIndentation(const DString &s, bool skipFirstLine)
Definition util.cpp:4819
static bool matchCanonicalTypes(const Definition *srcScope, const FileDef *srcFileScope, const DString &srcType, const Definition *dstScope, const FileDef *dstFileScope, const DString &dstType, SrcLangExt lang)
Definition util.cpp:1499
int extractClassNameFromType(const DString &type, int &pos, DString &name, DString &templSpec, SrcLangExt lang)
Definition util.cpp:3512
DString determineAbsoluteIncludeName(const DString &curFile, const DString &incFileName)
Definition util.cpp:3061
static DString stripFromPath(const DString &p, StringVector l)
Definition util.cpp:196
DString removeAnonymousScopes(const DString &str)
Definition util.cpp:98
DString makeBaseName(const DString &name, const DString &ext)
Definition util.cpp:4106
DString getDotImageExtensionGenerated(const DString &format)
Definition util.cpp:5110
void writeMarkerList(OutputList &ol, const std::string &markerText, size_t numMarkers, std::function< void(size_t)> replaceFunc)
Definition util.cpp:758
DString externalRef(const DString &relPath, const DString &ref)
Definition util.cpp:4674
static bool isLowerCase(DString &s)
Definition util.cpp:2130
DString stripPath(const DString &s)
Definition util.cpp:4092
static std::unordered_map< std::string, int > g_usedNames
Definition util.cpp:2985
static CharAroundSpace g_charAroundSpace
Definition util.cpp:424
DString inlineTemplateArgListToDoc(const ArgumentList &al)
Definition util.cpp:837
#define HEXTONUM(x)
void writeExamples(OutputList &ol, const ExampleList &list)
Definition util.cpp:809
static std::mutex g_matchArgsMutex
Definition util.cpp:1489
static const char * hex
Definition util.cpp:80
static const char operatorScope[]
Definition util.cpp:382
bool openOutputFile(const DString &outFile, std::ofstream &f)
Definition util.cpp:5122
static std::vector< Lang2ExtMap > g_lang2extMap
Definition util.cpp:4171
DString stripAnonymousNamespaceScope(const DString &s)
Definition util.cpp:167
DString findExampleFilePath(const DString &file, bool &ambig)
Definition util.cpp:2583
SrcLangExt getLanguageFromCodeLang(DString &fileName)
Routine to handle the language attribute of the \code command.
Definition util.cpp:4318
A bunch of utility functions.
std::vector< KeywordSubstitution > KeywordSubstitutionList
Definition util.h:284
std::vector< SelectionBlock > SelectionBlockList
Definition util.h:232