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,filter,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 return s;
1197}
1198
1199// forward decl for circular dependencies
1200static DString extractCanonicalType(const Definition *d,const FileDef *fs,DString type,SrcLangExt lang,bool insideTemplate);
1201
1202static DString getCanonicalTemplateSpec(const Definition *d,const FileDef *fs,const DString& spec,SrcLangExt lang)
1203{
1204 AUTO_TRACE("spec={}",spec);
1205 DString templSpec = spec.stripWhiteSpace();
1206 // this part had been commented out before... but it is needed to match for instance
1207 // std::list<std::string> against list<string> so it is now back again!
1208 if (!templSpec.empty() && templSpec.at(0) == '<')
1209 {
1210 templSpec = "< " + extractCanonicalType(d,fs,templSpec.mid(1).stripWhiteSpace(),lang,true);
1211 }
1212 DString resolvedType = lang==SrcLangExt::Java ? templSpec : resolveTypeDef(d,templSpec);
1213 if (!resolvedType.empty()) // not known as a typedef either
1214 {
1215 templSpec = resolvedType;
1216 }
1217 //printf("getCanonicalTemplateSpec(%s)=%s\n",qPrint(spec),qPrint(templSpec));
1218 AUTO_TRACE_EXIT("result={}",templSpec);
1219 return templSpec;
1220}
1221
1222
1224 const Definition *d,const FileDef *fs,const DString &word,SrcLangExt lang,
1225 DString *tSpec,int count=0)
1226{
1227 if (count>10) return word; // oops recursion
1228
1229 DString symName,result,templSpec,tmpName;
1230 if (tSpec && !tSpec->empty())
1231 templSpec = stripDeclKeywords(getCanonicalTemplateSpec(d,fs,*tSpec,lang));
1232
1233 AUTO_TRACE("d='{}' fs='{}' word='{}' templSpec='{}'",d?d->name():"",fs?fs->name():"",word,templSpec);
1234
1235 if (word.rfind("::")!=DString::npos && !(tmpName=stripScope(word)).empty())
1236 {
1237 symName=tmpName; // name without scope
1238 }
1239 else
1240 {
1241 symName=word;
1242 }
1243
1244 // lookup class / class template instance
1245 SymbolResolver resolver(fs);
1246 const ClassDef *cd = resolver.resolveClass(d,word+templSpec,true,true);
1247 const MemberDef *mType = resolver.getTypedef();
1248 DString ts = resolver.getTemplateSpec();
1249 DString resolvedType = resolver.getResolvedType();
1250
1251 bool isTemplInst = cd && !templSpec.empty();
1252 if (!cd && !templSpec.empty())
1253 {
1254 // class template specialization not known, look up class template
1255 cd = resolver.resolveClass(d,word,true,true);
1256 mType = resolver.getTypedef();
1257 ts = resolver.getTemplateSpec();
1258 resolvedType = resolver.getResolvedType();
1259 }
1260 if (cd && cd->isUsedOnly()) cd=nullptr; // ignore types introduced by usage relations
1261
1262 AUTO_TRACE_ADD("cd='{}' mType='{}' ts='{}' resolvedType='{}'",
1263 cd?cd->name():"",mType?mType->name():"",ts,resolvedType);
1264 //printf("cd=%p mtype=%p\n",cd,mType);
1265 //printf(" getCanonicalTypeForIdentifier: symbol=%s word=%s cd=%s d=%s fs=%s cd->isTemplate=%d\n",
1266 // qPrint(symName),
1267 // qPrint(word),
1268 // cd ? qPrint(cd->name()) : "<none>",
1269 // d ? qPrint( d->name()) : "<none>",
1270 // fs ? qPrint(fs->name()) : "<none>",
1271 // cd ? cd->isTemplate():-1
1272 // );
1273
1274 //printf(" >>>> word '%s' => '%s' templSpec=%s ts=%s tSpec=%s isTemplate=%d resolvedType=%s\n",
1275 // qPrint((word+templSpec)),
1276 // cd ? qPrint(cd->qualifiedName()) : "<none>",
1277 // qPrint(templSpec), qPrint(ts),
1278 // tSpec ? qPrint(tSpec) : "<null>",
1279 // cd ? cd->isTemplate():false,
1280 // qPrint(resolvedType));
1281
1282 //printf(" mtype=%s\n",mType ? qPrint(mType->name()) : "<none>");
1283
1284 if (cd) // resolves to a known class type
1285 {
1286 if (cd==d && tSpec) *tSpec="";
1287
1288 if (mType && mType->isTypedef()) // but via a typedef
1289 {
1290 result = resolvedType+ts; // the +ts was added for bug 685125
1291 }
1292 else
1293 {
1294 if (isTemplInst)
1295 {
1296 // spec is already part of class type
1297 templSpec="";
1298 if (tSpec) *tSpec="";
1299 }
1300 else if (!ts.empty() && templSpec.empty())
1301 {
1302 // use formal template args for spec
1303 templSpec = stripDeclKeywords(getCanonicalTemplateSpec(d,fs,ts,lang));
1304 }
1305
1306 result = removeRedundantWhiteSpace(cd->qualifiedName() + templSpec);
1307
1308 if (cd->isTemplate() && tSpec) //
1309 {
1310 if (!templSpec.empty()) // specific instance
1311 {
1312 result=cd->name()+templSpec;
1313 }
1314 else // use template type
1315 {
1317 }
1318 // template class, so remove the template part (it is part of the class name)
1319 *tSpec="";
1320 }
1321 else if (ts.empty() && !templSpec.empty() && cd && !cd->isTemplate() && tSpec)
1322 {
1323 // obscure case, where a class is used as a template, but doxygen think it is
1324 // not (could happen when loading the class from a tag file).
1325 *tSpec="";
1326 }
1327 }
1328 }
1329 else if (mType && mType->isEnumerate()) // an enum
1330 {
1331 result = mType->qualifiedName();
1332 }
1333 else if (mType && mType->isTypedef()) // a typedef
1334 {
1335 //result = mType->qualifiedName(); // changed after 1.7.2
1336 //result = mType->typeString();
1337 //printf("word=%s typeString=%s\n",qPrint(word),mType->typeString());
1338 if (word!=mType->typeString())
1339 {
1340 DString type = mType->typeString();
1341 if (type.startsWith("typename "))
1342 {
1343 type.stripPrefix("typename ");
1344 type = stripTemplateSpecifiersFromScope(type,false);
1345 }
1346 if (!type.empty()) // see issue #11065
1347 {
1348 result = getCanonicalTypeForIdentifier(d,fs,type,mType->getLanguage(),tSpec,count+1);
1349 }
1350 else
1351 {
1352 result = word;
1353 }
1354 }
1355 else
1356 {
1357 result = mType->typeString();
1358 }
1359 }
1360 else // fallback
1361 {
1362 resolvedType = lang==SrcLangExt::Java ? word : resolveTypeDef(d,word);
1363 AUTO_TRACE_ADD("fallback resolvedType='{}'",resolvedType);
1364 if (resolvedType.empty()) // not known as a typedef either
1365 {
1366 result = word;
1367 }
1368 else
1369 {
1370 result = resolvedType;
1371 }
1372 }
1373 AUTO_TRACE_EXIT("result='{}'",result);
1374 return result;
1375}
1376
1377static DString extractCanonicalType(const Definition *d,const FileDef *fs,DString type,SrcLangExt lang,bool insideTemplate)
1378{
1379 AUTO_TRACE("d={} fs={} type='{}'",d?d->name():"",fs?fs->name():"",type);
1380 type = type.stripWhiteSpace();
1381
1382 // strip const and volatile keywords that are not relevant for the type
1383 stripIrrelevantConstVolatile(type,insideTemplate);
1384
1385 // strip leading keywords
1386 type.stripPrefix("class ");
1387 type.stripPrefix("struct ");
1388 type.stripPrefix("union ");
1389 type.stripPrefix("enum ");
1390 type.stripPrefix("typename ");
1391
1392 type = removeRedundantWhiteSpace(type);
1393 //printf("extractCanonicalType(type=%s) start: def=%s file=%s\n",qPrint(type),
1394 // d ? qPrint(d->name()) : "<null>", fs ? qPrint(fs->name()) : "<null>");
1395
1396 DString canType;
1397 DString templSpec,word;
1398 int i=0,p=0,pp=0;
1399 while ((i=extractClassNameFromType(type,p,word,templSpec))!=-1)
1400 // foreach identifier in the type
1401 {
1402 //printf(" i=%d p=%d\n",i,p);
1403 if (i>pp)
1404 {
1405 if (i-pp>=2 && type[i-2]==':' && type[i-1]==':') // skip over leading ::, see issue #12021
1406 {
1407 canType += type.mid(pp,i-pp-2);
1408 }
1409 else
1410 {
1411 canType += type.mid(pp,i-pp);
1412 }
1413 }
1414
1415 DString ct = getCanonicalTypeForIdentifier(d,fs,word,lang,&templSpec);
1416
1417 // in case the ct is empty it means that "word" represents scope "d"
1418 // and this does not need to be added to the canonical
1419 // type (it is redundant), so/ we skip it. This solves problem 589616.
1420 if (ct.empty() && type.mid(p,2)=="::")
1421 {
1422 p+=2;
1423 }
1424 else
1425 {
1426 canType += ct;
1427 }
1428 //printf(" word=%s templSpec=%s canType=%s ct=%s\n",
1429 // qPrint(word), qPrint(templSpec), qPrint(canType), qPrint(ct));
1430 if (!templSpec.empty()) // if we didn't use up the templSpec already
1431 // (i.e. type is not a template specialization)
1432 // then resolve any identifiers inside.
1433 {
1434 std::string ts = templSpec.str();
1435 static const reg::Ex re(R"(\a\w*)");
1436 reg::Iterator it(ts,re);
1438
1439 size_t tp=0;
1440 // for each identifier template specifier
1441 //printf("adding resolved %s to %s\n",qPrint(templSpec),qPrint(canType));
1442 for (; it!=end ; ++it)
1443 {
1444 const auto &match = *it;
1445 size_t ti = match.position();
1446 size_t tl = match.length();
1447 std::string matchStr = match.str();
1448 canType += ts.substr(tp,ti-tp);
1449 canType += getCanonicalTypeForIdentifier(d,fs,matchStr,lang,nullptr);
1450 tp=ti+tl;
1451 }
1452 canType+=ts.substr(tp);
1453 }
1454
1455 pp=p;
1456 }
1457 canType += type.mid(pp);
1458 AUTO_TRACE_EXIT("canType='{}'",canType);
1459
1460 return removeRedundantWhiteSpace(canType);
1461}
1462
1463static DString extractCanonicalArgType(const Definition *d,const FileDef *fs,const Argument &arg,SrcLangExt lang)
1464{
1465 DString type = arg.type.stripWhiteSpace();
1466 DString name = arg.name;
1467 //printf("----- extractCanonicalArgType(type=%s,name=%s)\n",qPrint(type),qPrint(name));
1468 if ((type=="const" || type=="volatile") && !name.empty())
1469 { // name is part of type => correct
1470 type+=" ";
1471 type+=name;
1472 }
1473 if (name=="const" || name=="volatile")
1474 { // name is part of type => correct
1475 if (!type.empty()) type+=" ";
1476 type+=name;
1477 }
1478 if (!arg.array.empty())
1479 {
1480 type+=arg.array;
1481 }
1482
1483 return extractCanonicalType(d,fs,type,lang,false);
1484}
1485
1486static std::mutex g_matchArgsMutex;
1487
1488// a bit of debug support for matchArguments
1489//#define MATCH
1490//#define NOMATCH
1491//#define MATCH printf("Match at line %d\n",__LINE__);
1492//#define NOMATCH printf("Nomatch at line %d\n",__LINE__);
1493#define MATCH AUTO_TRACE_EXIT("match at line {}",__LINE__);
1494#define NOMATCH AUTO_TRACE_EXIT("no match at line {}",__LINE__);
1495
1497 const Definition *srcScope,const FileDef *srcFileScope,const DString &srcType,
1498 const Definition *dstScope,const FileDef *dstFileScope,const DString &dstType,
1499 SrcLangExt lang)
1500{
1501 AUTO_TRACE("srcType='{}' dstType='{}'",srcType,dstType);
1502 if (srcType==dstType) return true;
1503
1504 // check if the types are function pointers
1505 size_t i1=srcType.find(")(");
1506 if (i1==DString::npos) return false;
1507 size_t i2=dstType.find(")(");
1508 if (i1!=i2) return false;
1509
1510 // check if the result part of the function pointer types matches
1511 size_t j1=srcType.find("(");
1512 if (j1==DString::npos || j1>i1) return false;
1513 size_t j2=dstType.find("(");
1514 if (j2!=j1) return false;
1515 if (srcType.left(j1)!=dstType.left(j2)) return false; // different return types
1516
1517 // if srcType and dstType are both function pointers with the same return type,
1518 // then match against the parameter lists.
1519 // This way srcType='void (*fptr)(int x)' will match against `void (*fptr)(int y)' because
1520 // 'int x' matches 'int y'. A simple literal string match would treat these as different.
1521 auto srcAl = stringToArgumentList(lang,srcType.mid(i1+1));
1522 auto dstAl = stringToArgumentList(lang,dstType.mid(i2+1));
1523 return matchArguments2(srcScope,srcFileScope,srcType.left(j1),srcAl.get(),
1524 dstScope,dstFileScope,dstType.left(j2),dstAl.get(),
1525 true,lang);
1526}
1527
1528static bool matchArgument2(
1529 const Definition *srcScope,const FileDef *srcFileScope,Argument &srcA,
1530 const Definition *dstScope,const FileDef *dstFileScope,Argument &dstA,
1531 SrcLangExt lang
1532 )
1533{
1534 AUTO_TRACE("src: scope={} type={} name={} canType={}, dst: scope={} type={} name={} canType={}",
1535 srcScope?srcScope->name():"",srcA.type,srcA.name,srcA.canType,
1536 dstScope?dstScope->name():"",dstA.type,dstA.name,dstA.canType);
1537 //printf(">> match argument: %s::'%s|%s' (%s) <-> %s::'%s|%s' (%s)\n",
1538 // srcScope ? qPrint(srcScope->name()) : "",
1539 // qPrint(srcA.type), qPrint(srcA.name), qPrint(srcA.canType),
1540 // dstScope ? qPrint(dstScope->name()) : "",
1541 // qPrint(dstA.type), qPrint(dstA.name), qPrint(dstA.canType));
1542
1543 DString sSrcName = " "+srcA.name;
1544 DString sDstName = " "+dstA.name;
1545 DString srcType = srcA.type;
1546 DString dstType = dstA.type;
1547 stripIrrelevantConstVolatile(srcType,false);
1548 stripIrrelevantConstVolatile(dstType,false);
1549 //printf("'%s'<->'%s'\n",qPrint(sSrcName),qPrint(dstType.right(sSrcName.length())));
1550 //printf("'%s'<->'%s'\n",qPrint(sDstName),qPrint(srcType.right(sDstName.length())));
1551 if (sSrcName==dstType.right(sSrcName.length()))
1552 { // case "unsigned int" <-> "unsigned int i"
1553 srcA.type+=sSrcName;
1554 srcA.name="";
1555 srcA.canType=""; // invalidate cached type value
1556 }
1557 else if (sDstName==srcType.right(sDstName.length()))
1558 { // case "unsigned int i" <-> "unsigned int"
1559 dstA.type+=sDstName;
1560 dstA.name="";
1561 dstA.canType=""; // invalidate cached type value
1562 }
1563
1564 {
1565 std::lock_guard lock(g_matchArgsMutex);
1566 if (srcA.canType.empty() || dstA.canType.empty())
1567 {
1568 // need to re-evaluate both see issue #8370
1569 srcA.canType = extractCanonicalArgType(srcScope,srcFileScope,srcA,lang);
1570 dstA.canType = extractCanonicalArgType(dstScope,dstFileScope,dstA,lang);
1571 }
1572 }
1573
1574 if (matchCanonicalTypes(srcScope,srcFileScope,srcA.canType,
1575 dstScope,dstFileScope,dstA.canType,
1576 lang))
1577 {
1578 MATCH
1579 AUTO_TRACE_EXIT("true");
1580 return true;
1581 }
1582 else
1583 {
1584 //printf(" Canonical types do not match [%s]<->[%s]\n",
1585 // qPrint(srcA->canType),qPrint(dstA->canType));
1586 NOMATCH
1587 AUTO_TRACE_EXIT("false");
1588 return false;
1589 }
1590}
1591
1592
1593// new algorithm for argument matching
1594bool matchArguments2(const Definition *srcScope,const FileDef *srcFileScope,const DString &srcReturnType,const ArgumentList *srcAl,
1595 const Definition *dstScope,const FileDef *dstFileScope,const DString &dstReturnType,const ArgumentList *dstAl,
1596 bool checkCV,SrcLangExt lang)
1597{
1598 ASSERT(srcScope!=nullptr && dstScope!=nullptr);
1599
1600 AUTO_TRACE("srcScope='{}' dstScope='{}' srcArgs='{}' dstArgs='{}' checkCV={} lang={}",
1601 srcScope->name(),dstScope->name(),srcAl?argListToString(*srcAl):"",dstAl?argListToString(*dstAl):"",checkCV,lang);
1602
1603 if (srcAl==nullptr || dstAl==nullptr)
1604 {
1605 bool match = srcAl==dstAl;
1606 if (match)
1607 {
1608 MATCH
1609 return true;
1610 }
1611 else
1612 {
1613 NOMATCH
1614 return false;
1615 }
1616 }
1617
1618 // handle special case with void argument
1619 if ( srcAl->empty() && dstAl->size()==1 && dstAl->front().type=="void" )
1620 { // special case for finding match between func() and func(void)
1621 Argument a;
1622 a.type = "void";
1623 const_cast<ArgumentList*>(srcAl)->push_back(a);
1624 MATCH
1625 return true;
1626 }
1627 if ( dstAl->empty() && srcAl->size()==1 && srcAl->front().type=="void" )
1628 { // special case for finding match between func(void) and func()
1629 Argument a;
1630 a.type = "void";
1631 const_cast<ArgumentList*>(dstAl)->push_back(a);
1632 MATCH
1633 return true;
1634 }
1635
1636 if (srcAl->size() != dstAl->size())
1637 {
1638 NOMATCH
1639 return false; // different number of arguments -> no match
1640 }
1641
1642 if (checkCV)
1643 {
1644 if (srcAl->constSpecifier() != dstAl->constSpecifier())
1645 {
1646 NOMATCH
1647 return false; // one member is const, the other not -> no match
1648 }
1649 if (srcAl->volatileSpecifier() != dstAl->volatileSpecifier())
1650 {
1651 NOMATCH
1652 return false; // one member is volatile, the other not -> no match
1653 }
1654 }
1655
1656 if (srcAl->refQualifier() != dstAl->refQualifier())
1657 {
1658 NOMATCH
1659 return false; // one member is has a different ref-qualifier than the other
1660 }
1661
1662 if (srcReturnType=="auto" && dstReturnType=="auto" && srcAl->trailingReturnType()!=dstAl->trailingReturnType())
1663 {
1664 NOMATCH
1665 return false; // one member is has a different return type than the other
1666 }
1667
1668 // so far the argument list could match, so we need to compare the types of
1669 // all arguments.
1670 auto srcIt = srcAl->begin();
1671 auto dstIt = dstAl->begin();
1672 for (;srcIt!=srcAl->end() && dstIt!=dstAl->end();++srcIt,++dstIt)
1673 {
1674 Argument &srcA = const_cast<Argument&>(*srcIt);
1675 Argument &dstA = const_cast<Argument&>(*dstIt);
1676 if (!matchArgument2(srcScope,srcFileScope,srcA,
1677 dstScope,dstFileScope,dstA,
1678 lang)
1679 )
1680 {
1681 NOMATCH
1682 return false;
1683 }
1684 }
1685 MATCH
1686 return true; // all arguments match
1687}
1688
1689#undef MATCH
1690#undef NOMATCH
1691
1692// merges the initializer of two argument lists
1693// pre: the types of the arguments in the list should match.
1694void mergeArguments(ArgumentList &srcAl,ArgumentList &dstAl,bool forceNameOverwrite)
1695{
1696 AUTO_TRACE("srcAl='{}',dstAl='{}',forceNameOverwrite={}",
1697 qPrint(argListToString(srcAl)),qPrint(argListToString(dstAl)),forceNameOverwrite);
1698
1699 if (srcAl.size()!=dstAl.size())
1700 {
1701 return; // invalid argument lists -> do not merge
1702 }
1703
1704 auto srcIt=srcAl.begin();
1705 auto dstIt=dstAl.begin();
1706 while (srcIt!=srcAl.end() && dstIt!=dstAl.end())
1707 {
1708 Argument &srcA = *srcIt;
1709 Argument &dstA = *dstIt;
1710
1711 AUTO_TRACE_ADD("before merge: src=[type='{}',name='{}',def='{}'] dst=[type='{}',name='{}',def='{}']",
1712 srcA.type,srcA.name,srcA.defval,
1713 dstA.type,dstA.name,dstA.defval);
1714 if (srcA.defval.empty() && !dstA.defval.empty())
1715 {
1716 //printf("Defval changing '%s'->'%s'\n",qPrint(srcA.defval),qPrint(dstA.defval));
1717 srcA.defval=dstA.defval;
1718 }
1719 else if (!srcA.defval.empty() && dstA.defval.empty())
1720 {
1721 //printf("Defval changing '%s'->'%s'\n",qPrint(dstA.defval),qPrint(srcA.defval));
1722 dstA.defval=srcA.defval;
1723 }
1724
1725 // fix wrongly detected const or volatile specifiers before merging.
1726 // example: "const A *const" is detected as type="const A *" name="const"
1727 if (srcA.name=="const" || srcA.name=="volatile")
1728 {
1729 srcA.type+=" "+srcA.name;
1730 srcA.name.clear();
1731 }
1732 if (dstA.name=="const" || dstA.name=="volatile")
1733 {
1734 dstA.type+=" "+dstA.name;
1735 dstA.name.clear();
1736 }
1737
1738 if (srcA.type==dstA.type)
1739 {
1740 //printf("1. merging %s:%s <-> %s:%s\n",qPrint(srcA.type),qPrint(srcA.name),qPrint(dstA.type),qPrint(dstA.name));
1741 if (srcA.name.empty() && !dstA.name.empty())
1742 {
1743 //printf("type: '%s':='%s'\n",qPrint(srcA.type),qPrint(dstA.type));
1744 //printf("name: '%s':='%s'\n",qPrint(srcA.name),qPrint(dstA.name));
1745 srcA.type = dstA.type;
1746 srcA.name = dstA.name;
1747 }
1748 else if (!srcA.name.empty() && dstA.name.empty())
1749 {
1750 //printf("type: '%s':='%s'\n",qPrint(dstA.type),qPrint(srcA.type));
1751 //printf("name: '%s':='%s'\n",qPrint(dstA.name),qPrint(srcA.name));
1752 dstA.type = srcA.type;
1753 dstA.name = srcA.name;
1754 }
1755 else if (!srcA.name.empty() && !dstA.name.empty())
1756 {
1757 //printf("srcA.name=%s dstA.name=%s\n",qPrint(srcA.name),qPrint(dstA.name));
1758 if (forceNameOverwrite)
1759 {
1760 srcA.name = dstA.name;
1761 }
1762 else
1763 {
1764 if (srcA.docs.empty() && !dstA.docs.empty())
1765 {
1766 srcA.name = dstA.name;
1767 }
1768 else if (!srcA.docs.empty() && dstA.docs.empty())
1769 {
1770 dstA.name = srcA.name;
1771 }
1772 }
1773 }
1774 }
1775 else
1776 {
1777 //printf("2. merging '%s':'%s' <-> '%s':'%s'\n",qPrint(srcA.type),qPrint(srcA.name),qPrint(dstA.type),qPrint(dstA.name));
1778 srcA.type=srcA.type.stripWhiteSpace();
1779 dstA.type=dstA.type.stripWhiteSpace();
1780 if (srcA.type+" "+srcA.name==dstA.type) // "unsigned long:int" <-> "unsigned long int:bla"
1781 {
1782 srcA.type+=" "+srcA.name;
1783 srcA.name=dstA.name;
1784 }
1785 else if (dstA.type+" "+dstA.name==srcA.type) // "unsigned long int bla" <-> "unsigned long int"
1786 {
1787 dstA.type+=" "+dstA.name;
1788 dstA.name=srcA.name;
1789 }
1790 else if (srcA.name.empty() && !dstA.name.empty())
1791 {
1792 srcA.name = dstA.name;
1793 }
1794 else if (dstA.name.empty() && !srcA.name.empty())
1795 {
1796 dstA.name = srcA.name;
1797 }
1798 }
1799 size_t i1=srcA.type.find("::"),
1800 i2=dstA.type.find("::"),
1801 j1=srcA.type.length()-i1-2,
1802 j2=dstA.type.length()-i2-2;
1803 if (i1!=DString::npos && i2==DString::npos && srcA.type.right(j1)==dstA.type)
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.left(i1+2)+dstA.type;
1808 dstA.name = srcA.name;
1809 }
1810 else if (i1==DString::npos && i2!=DString::npos && dstA.type.right(j2)==srcA.type)
1811 {
1812 //printf("type: '%s':='%s'\n",qPrint(srcA.type),qPrint(dstA.type));
1813 //printf("name: '%s':='%s'\n",qPrint(dstA.name),qPrint(srcA.name));
1814 srcA.type = dstA.type.left(i2+2)+srcA.type;
1815 srcA.name = dstA.name;
1816 }
1817 if (srcA.docs.empty() && !dstA.docs.empty())
1818 {
1819 srcA.docs = dstA.docs;
1820 }
1821 else if (dstA.docs.empty() && !srcA.docs.empty())
1822 {
1823 dstA.docs = srcA.docs;
1824 }
1825 //printf("Merge argument '%s|%s' '%s|%s'\n",
1826 // qPrint(srcA.type), qPrint(srcA.name),
1827 // qPrint(dstA.type), qPrint(dstA.name));
1828 ++srcIt;
1829 ++dstIt;
1830 AUTO_TRACE_ADD("after merge: src=[type='{}',name='{}',def='{}'] dst=[type='{}',name='{}',def='{}']",
1831 srcA.type,srcA.name,srcA.defval,
1832 dstA.type,dstA.name,dstA.defval);
1833 }
1834}
1835
1836//---------------------------------------------------------------------------------------
1837
1838bool matchTemplateArguments(const ArgumentList &srcAl,const ArgumentList &dstAl)
1839{
1840 AUTO_TRACE("srcAl={} dstAl={}",argListToString(srcAl),argListToString(dstAl));
1841 if (srcAl.size()!=dstAl.size()) // different number of template parameters -> overload
1842 {
1843 AUTO_TRACE_EXIT("different number of parameters");
1844 return false;
1845 }
1846 auto isUnconstraintTemplate = [](const DString &type)
1847 {
1848 return type=="typename" || type=="class" || type.startsWith("typename ") || type.startsWith("class ");
1849 };
1850 auto srcIt = srcAl.begin();
1851 auto dstIt = dstAl.begin();
1852 while (srcIt!=srcAl.end() && dstIt!=dstAl.end())
1853 {
1854 const Argument &srcA = *srcIt;
1855 const Argument &dstA = *dstIt;
1856 if ((!isUnconstraintTemplate(srcA.type) || !isUnconstraintTemplate(dstA.type)) && srcA.type!=dstA.type) // different constraints -> overload
1857 {
1858 AUTO_TRACE_EXIT("different constraints");
1859 return false;
1860 }
1861 ++srcIt;
1862 ++dstIt;
1863 }
1864 AUTO_TRACE_EXIT("same");
1865 // no overload with respect to the template parameters
1866 return true;
1867}
1868
1869//---------------------------------------------------------------------------------------
1870
1872{
1873 GetDefResult result;
1874 if (input.memberName.empty()) return result;
1875 AUTO_TRACE("scopeName={},memberName={},forceEmptyScope={}",
1876 input.scopeName,input.memberName,input.forceEmptyScope);
1877
1878 //printf("@@ --- getDefsNew(%s,%s)-----------\n",qPrint(scName),qPrint(mbName));
1879 const Definition *scope = Doxygen::globalScope;
1880 SymbolResolver resolver;
1881 if (input.currentFile) resolver.setFileScope(input.currentFile);
1882 if (!input.scopeName.empty() && !input.forceEmptyScope)
1883 {
1884 scope = resolver.resolveSymbol(scope,input.scopeName);
1885 }
1886 if (scope==Doxygen::globalScope)
1887 {
1888 scope = input.currentFile;
1889 }
1890 //printf("@@ -> found scope scope=%s member=%s out=%s\n",qPrint(input.scopeName),qPrint(input.memberName),qPrint(scope?scope->name():""));
1891 //
1892 const Definition *symbol = resolver.resolveSymbol(scope,input.memberName,input.args,input.checkCV,input.insideCode,true);
1893 //printf("@@ -> found symbol in=%s out=%s\n",qPrint(input.memberName),qPrint(symbol?symbol->qualifiedName():DString()));
1894 if (symbol && symbol->definitionType()==Definition::TypeMember)
1895 {
1896 result.md = toMemberDef(symbol);
1897 result.cd = result.md->getClassDef();
1898 if (result.cd==nullptr) result.nd = result.md->getNamespaceDef();
1899 if (result.cd==nullptr && result.nd==nullptr) result.fd = result.md->getFileDef();
1900 result.gd = result.md->getGroupDef();
1901 result.found = true;
1902 }
1903 else if (symbol && symbol->definitionType()==Definition::TypeClass)
1904 {
1905 result.cd = toClassDef(symbol);
1906 result.found = true;
1907 }
1908 else if (symbol && symbol->definitionType()==Definition::TypeNamespace)
1909 {
1910 result.nd = toNamespaceDef(symbol);
1911 result.found = true;
1912 }
1913 else if (symbol && symbol->definitionType()==Definition::TypeConcept)
1914 {
1915 result.cnd = toConceptDef(symbol);
1916 result.found = true;
1917 }
1918 else if (symbol && symbol->definitionType()==Definition::TypeModule)
1919 {
1920 result.modd = toModuleDef(symbol);
1921 result.found = true;
1922 }
1923 return result;
1924}
1925
1926
1927/*!
1928 * Searches for a scope definition given its name as a string via parameter
1929 * `scope`.
1930 *
1931 * The parameter `docScope` is a string representing the name of the scope in
1932 * which the `scope` string was found.
1933 *
1934 * The function returns true if the scope is known and documented or
1935 * false if it is not.
1936 * If true is returned exactly one of the parameter `cd`, `nd`
1937 * will be non-zero:
1938 * - if `cd` is non zero, the scope was a class pointed to by cd.
1939 * - if `nd` is non zero, the scope was a namespace pointed to by nd.
1940 */
1941static bool getScopeDefs(const DString &docScope,const DString &scope,
1942 ClassDef *&cd, ConceptDef *&cnd, NamespaceDef *&nd,ModuleDef *&modd)
1943{
1944 cd=nullptr;
1945 cnd=nullptr;
1946 nd=nullptr;
1947 modd=nullptr;
1948
1949 DString scopeName=scope;
1950 //printf("getScopeDefs: docScope='%s' scope='%s'\n",qPrint(docScope),qPrint(scope));
1951 if (scopeName.empty()) return false;
1952
1953 bool explicitGlobalScope=false;
1954 if (scopeName.at(0)==':' && scopeName.at(1)==':')
1955 {
1956 scopeName=scopeName.mid(2);
1957 explicitGlobalScope=true;
1958 }
1959 if (scopeName.empty())
1960 {
1961 return false;
1962 }
1963
1964 DString docScopeName=docScope;
1965 int scopeOffset=explicitGlobalScope ? 0 : static_cast<int>(docScopeName.length());
1966
1967 do // for each possible docScope (from largest to and including empty)
1968 {
1969 DString fullName=scopeName;
1970 if (scopeOffset>0) fullName.prepend(docScopeName.left(scopeOffset)+"::");
1971
1972 if (((cd=getClass(fullName)) || // normal class
1973 (cd=getClass(fullName+"-p")) // ObjC protocol
1974 ) && cd->isLinkable())
1975 {
1976 return true; // class link written => quit
1977 }
1978 else if ((nd=Doxygen::namespaceLinkedMap->find(fullName)) && nd->isLinkable())
1979 {
1980 return true; // namespace link written => quit
1981 }
1982 else if ((cnd=Doxygen::conceptLinkedMap->find(fullName)) && cnd->isLinkable())
1983 {
1984 return true; // concept link written => quit
1985 }
1986 else if ((modd=ModuleManager::instance().modules().find(fullName)) && modd->isLinkable())
1987 {
1988 return true; // module link written => quit
1989 }
1990 if (scopeOffset==0)
1991 {
1992 scopeOffset=-1;
1993 }
1994 else
1995 {
1996 size_t o = docScopeName.rfind("::",scopeOffset-1);
1997 scopeOffset = o!=DString::npos ? static_cast<int>(o) : 0;
1998 }
1999 } while (scopeOffset>=0);
2000
2001 return false;
2002}
2003
2004static bool isLowerCase(DString &s)
2005{
2006 if (s.empty()) return true;
2007 const char *p=s.data();
2008 int c=0;
2009 while ((c=static_cast<uint8_t>(*p++))) if (!islower(c)) return false;
2010 return true;
2011}
2012
2013bool resolveRef(/* in */ const DString &scName,
2014 /* in */ const DString &name,
2015 /* in */ bool inSeeBlock,
2016 /* out */ const Definition **resContext,
2017 /* out */ const MemberDef **resMember,
2018 /* in */ SrcLangExt lang,
2019 bool lookForSpecialization,
2020 const FileDef *currentFile,
2021 bool checkScope
2022 )
2023{
2024 AUTO_TRACE("scope={} name={} inSeeBlock={} lang={} lookForSpecialization={} currentFile={} checkScope={}",
2025 scName,name,inSeeBlock,lang,lookForSpecialization,currentFile ? currentFile->name() : "", checkScope);
2026 //printf("resolveRef(scope=%s,name=%s,inSeeBlock=%d)\n",qPrint(scName),qPrint(name),inSeeBlock);
2027 DString tsName = name;
2028 //bool memberScopeFirst = tsName.find('#')!=-1;
2029 DString fullName = substitute(tsName,"#","::");
2030 if (fullName.find("anonymous_namespace{")==DString::npos)
2031 {
2032 fullName = removeRedundantWhiteSpace(substitute(fullName,".","::",3));
2033 }
2034 else
2035 {
2036 fullName = removeRedundantWhiteSpace(fullName);
2037 }
2038
2039 size_t templStartPos;
2040 if (lang==SrcLangExt::CSharp && (templStartPos=fullName.find('<'))!=DString::npos)
2041 {
2042 size_t templEndPos = fullName.rfind('>');
2043 if (templEndPos!=DString::npos)
2044 {
2045 fullName = mangleCSharpGenericName(fullName.left(templEndPos+1))+fullName.mid(templEndPos+1);
2046 AUTO_TRACE_ADD("C# mangled name='{}'",fullName);
2047 }
2048 }
2049
2050 size_t bracePos = findParameterList(fullName);
2051 size_t endNamePos = bracePos!=DString::npos ? bracePos : fullName.length();
2052 size_t scopePos = fullName.rfind("::",endNamePos);
2053 bool explicitScope = fullName.startsWith("::") && // ::scope or #scope
2054 ((scopePos!=DString::npos && scopePos>2) || // ::N::A
2055 tsName.startsWith("::") || // ::foo in local scope
2056 scName==nullptr // #foo in global scope
2057 );
2058 bool allowTypeOnly=false;
2059
2060 // default result values
2061 *resContext=nullptr;
2062 *resMember=nullptr;
2063
2064 if (bracePos==DString::npos) // simple name
2065 {
2066 // the following if() was commented out for releases in the range
2067 // 1.5.2 to 1.6.1, but has been restored as a result of bug report 594787.
2068 if (!inSeeBlock && scopePos==DString::npos && isLowerCase(tsName))
2069 { // link to lower case only name => do not try to autolink
2070 AUTO_TRACE_ADD("false");
2071 return false;
2072 }
2073
2074 ClassDef *cd=nullptr;
2075 NamespaceDef *nd=nullptr;
2076 ConceptDef *cnd=nullptr;
2077 ModuleDef *modd=nullptr;
2078
2079 //printf("scName=%s fullName=%s\n",qPrint(scName),qPrint(fullName));
2080
2081 // check if this is a class or namespace reference
2082 if (scName!=fullName && getScopeDefs(scName,fullName,cd,cnd,nd,modd))
2083 {
2084 //printf("found scopeDef\n");
2085 if (cd) // scope matches that of a class
2086 {
2087 *resContext = cd;
2088 }
2089 else if (cnd)
2090 {
2091 *resContext = cnd;
2092 }
2093 else if (modd)
2094 {
2095 *resContext = modd;
2096 }
2097 else // scope matches that of a namespace
2098 {
2099 ASSERT(nd!=nullptr);
2100 *resContext = nd;
2101 }
2102 AUTO_TRACE_ADD("true");
2103 return true;
2104 }
2105 else if (scName==fullName || (!inSeeBlock && scopePos==DString::npos))
2106 // nothing to link => output plain text
2107 {
2108 //printf("found scName=%s fullName=%s scName==fullName=%d "
2109 // "inSeeBlock=%d scopePos=%d!\n",
2110 // qPrint(scName),qPrint(fullName),scName==fullName,inSeeBlock,scopePos);
2111
2112 // at this point we have a bare word that is not a class or namespace
2113 // we should also allow typedefs or enums to be linked, but not for instance member
2114 // functions, otherwise 'Foo' would always link to the 'Foo()' constructor instead of the
2115 // 'Foo' class. So we use this flag as a filter.
2116 allowTypeOnly=true;
2117 }
2118
2119 // continue search...
2120 }
2121
2122 // extract userscope+name
2123 DString nameStr=fullName.left(endNamePos);
2124 if (explicitScope) nameStr=nameStr.mid(2);
2125
2126
2127 // extract arguments
2128 DString argsStr;
2129 if (bracePos!=DString::npos) argsStr=fullName.mid(bracePos);
2130
2131 // strip template specifier
2132 // TODO: match against the correct partial template instantiation
2133 size_t templPos = nameStr.find('<');
2134 bool tryUnspecializedVersion = false;
2135 if (templPos!=DString::npos && nameStr.find("operator")==DString::npos)
2136 {
2137 size_t endTemplPos=nameStr.rfind('>');
2138 if (endTemplPos!=DString::npos)
2139 {
2140 if (!lookForSpecialization)
2141 {
2142 nameStr=nameStr.left(templPos)+nameStr.mid(endTemplPos+1);
2143 }
2144 else
2145 {
2146 tryUnspecializedVersion = true;
2147 }
2148 }
2149 }
2150
2151 DString scopeStr=scName;
2152 if (!explicitScope && nameStr.length()>scopeStr.length() && leftScopeMatch(scopeStr,nameStr))
2153 {
2154 nameStr=nameStr.mid(scopeStr.length()+2);
2155 }
2156
2157 const GroupDef *gd = nullptr;
2158 const ConceptDef *cnd = nullptr;
2159 const ModuleDef *modd = nullptr;
2160
2161 // check if nameStr is a member or global.
2162 //printf("getDefs(scope=%s,name=%s,args=%s checkScope=%d)\n",
2163 // qPrint(scopeStr), qPrint(nameStr), qPrint(argsStr),checkScope);
2164 GetDefInput input(scopeStr,nameStr,argsStr);
2165 input.forceEmptyScope = explicitScope;
2166 input.currentFile = currentFile;
2167 input.checkCV = true;
2168 GetDefResult result = getDefs(input);
2169 if (result.found)
2170 {
2171 //printf("after getDefs checkScope=%d nameStr=%s\n",checkScope,qPrint(nameStr));
2172 size_t np = nameStr.find("::");
2173 if (checkScope && result.md && result.md->getOuterScope()==Doxygen::globalScope &&
2174 !result.md->isStrongEnumValue() &&
2175 (!scopeStr.empty() || (np!=DString::npos && np>0)))
2176 {
2177 // we did find a member, but it is a global one while we were explicitly
2178 // looking for a scoped variable. See bug 616387 for an example why this check is needed.
2179 // note we do need to support autolinking to "::symbol" hence the >0
2180 //printf("not global member!\n");
2181 *resContext=nullptr;
2182 *resMember=nullptr;
2183 AUTO_TRACE_ADD("false");
2184 return false;
2185 }
2186 //printf("after getDefs md=%p cd=%p fd=%p nd=%p gd=%p\n",md,cd,fd,nd,gd);
2187 if (result.md)
2188 {
2189 if (!allowTypeOnly || result.md->isTypedef() || result.md->isEnumerate())
2190 {
2191 *resMember=result.md;
2192 *resContext=result.md;
2193 }
2194 else // md is not a type, but we explicitly expect one
2195 {
2196 *resContext=nullptr;
2197 *resMember=nullptr;
2198 AUTO_TRACE_ADD("false");
2199 return false;
2200 }
2201 }
2202 else if (result.cd) *resContext=result.cd;
2203 else if (result.nd) *resContext=result.nd;
2204 else if (result.fd) *resContext=result.fd;
2205 else if (result.gd) *resContext=result.gd;
2206 else if (result.cnd) *resContext=result.cnd;
2207 else if (result.modd) *resContext=result.modd;
2208 else
2209 {
2210 *resContext=nullptr; *resMember=nullptr;
2211 AUTO_TRACE_ADD("false");
2212 return false;
2213 }
2214 //printf("member=%s (md=%p) anchor=%s linkable()=%d context=%s\n",
2215 // qPrint(md->name()), md, qPrint(md->anchor()), md->isLinkable(), qPrint((*resContext)->name()));
2216 AUTO_TRACE_ADD("true");
2217 return true;
2218 }
2219 else if (inSeeBlock && !nameStr.empty() && (gd=Doxygen::groupLinkedMap->find(nameStr)))
2220 { // group link
2221 *resContext=gd;
2222 AUTO_TRACE_ADD("true");
2223 return true;
2224 }
2225 else if ((cnd=Doxygen::conceptLinkedMap->find(nameStr)))
2226 {
2227 *resContext=cnd;
2228 AUTO_TRACE_ADD("true");
2229 return true;
2230 }
2231 else if ((modd=ModuleManager::instance().modules().find(nameStr)))
2232 {
2233 *resContext=modd;
2234 AUTO_TRACE_ADD("true");
2235 return true;
2236 }
2237 else if (tsName.find('.')!=DString::npos) // maybe a link to a file
2238 {
2239 bool ambig = false;
2240 const FileDef *fd=Doxygen::inputNameLinkedMap->findFileDef(tsName,ambig);
2241 if (fd && !ambig)
2242 {
2243 *resContext=fd;
2244 AUTO_TRACE_ADD("true");
2245 return true;
2246 }
2247 }
2248
2249 if (tryUnspecializedVersion)
2250 {
2251 bool b = resolveRef(scName,name,inSeeBlock,resContext,resMember,lang,false,nullptr,checkScope);
2252 AUTO_TRACE_ADD("{}",b);
2253 return b;
2254 }
2255 if (bracePos!=DString::npos) // Try without parameters as well, could be a constructor invocation
2256 {
2257 *resContext=getClass(fullName.left(bracePos));
2258 if (*resContext)
2259 {
2260 AUTO_TRACE_ADD("true");
2261 return true;
2262 }
2263 }
2264 //printf("resolveRef: %s not found!\n",qPrint(name));
2265
2266 AUTO_TRACE_ADD("false");
2267 return false;
2268}
2269
2270DString linkToText(SrcLangExt lang,const DString &link,bool ignoreDots)
2271{
2272 //bool optimizeOutputJava = Config_getBool(OPTIMIZE_OUTPUT_JAVA);
2273 DString result=link;
2274 if (!result.empty())
2275 {
2276 // replace # by ::
2277 result=substitute(result,"#","::");
2278 // replace . by ::
2279 if (!ignoreDots && result.find('<')==DString::npos) result=substitute(result,".","::",3);
2280 // strip leading :: prefix if present
2281 if (result.at(0)==':' && result.at(1)==':')
2282 {
2283 result=result.mid(2);
2284 }
2286 if (sep!="::")
2287 {
2288 result=substitute(result,"::",sep);
2289 }
2290 }
2291 //printf("linkToText(%s,lang=%d)=%s\n",qPrint(link),lang,qPrint(result));
2292 return result;
2293}
2294
2295static const DirDef *resolveDirLink(const DString &linkRef)
2296{
2297 const DirDef *dd = Doxygen::dirLinkedMap->find(FileInfo(linkRef.str()).absFilePath()+"/");
2298 //printf("resolveDirLink(%s) -> %s\n",qPrint(linkRef),dd?qPrint(dd->name()):"<none>");
2299 if (dd==nullptr)
2300 {
2301 StringVector stripPaths = Config_getList(STRIP_FROM_PATH);
2302 for (const auto &path : stripPaths)
2303 {
2304 FileInfo fi(path+linkRef.str());
2305 //printf(" trying to strip path '%s' from linkRef '%s' fi='%s'\n",qPrint(path),qPrint(linkRef),qPrint(fi.absFilePath()));
2306 dd = Doxygen::dirLinkedMap->find(fi.absFilePath()+"/");
2307 if (dd) break;
2308 }
2309 }
2310 return dd;
2311}
2312
2313bool resolveLink(/* in */ const DString &scName,
2314 /* in */ const DString &lr,
2315 /* in */ bool /*inSeeBlock*/,
2316 /* out */ const Definition **resContext,
2317 /* out */ DString &resAnchor,
2318 /* in */ SrcLangExt lang,
2319 /* in */ const DString &prefix,
2320 /* in */ const FileDef *currentFile
2321 )
2322{
2323 *resContext=nullptr;
2324
2325 DString linkRef=lr;
2326 if (lang==SrcLangExt::CSharp)
2327 {
2328 linkRef = mangleCSharpGenericName(linkRef);
2329 }
2330 DString linkRefWithoutTemplates = stripTemplateSpecifiersFromScope(linkRef,false);
2331 AUTO_TRACE("scName='{}',ref='{}'",scName,lr);
2332 const FileDef *fd = nullptr;
2333 const GroupDef *gd = nullptr;
2334 const PageDef *pd = nullptr;
2335 const ClassDef *cd = nullptr;
2336 const DirDef *dir = nullptr;
2337 const ConceptDef *cnd = nullptr;
2338 const ModuleDef *modd = nullptr;
2339 const NamespaceDef *nd = nullptr;
2340 const SectionInfo *si = nullptr;
2341 bool ambig = false;
2342 if (linkRef.empty()) // no reference name!
2343 {
2344 AUTO_TRACE_EXIT("no_ref");
2345 return false;
2346 }
2347 else if ((pd=Doxygen::pageLinkedMap->find(linkRef))) // link to a page
2348 {
2349 gd = pd->getGroupDef();
2350 if (gd)
2351 {
2352 if (!pd->name().empty()) si=SectionManager::instance().find(pd->name());
2353 *resContext=gd;
2354 if (si) resAnchor = si->label();
2355 }
2356 else
2357 {
2358 *resContext=pd;
2359 }
2360 AUTO_TRACE_EXIT("page");
2361 return true;
2362 }
2363 else if ((si=SectionManager::instance().find(prefix+linkRef)))
2364 {
2365 *resContext=si->definition();
2366 resAnchor = si->label();
2367 AUTO_TRACE_EXIT("section anchor={} def={}",resAnchor,si->definition()?si->definition()->name():"<none>");
2368 return true;
2369 }
2370 else if (!prefix.empty() && (si=SectionManager::instance().find(linkRef)))
2371 {
2372 *resContext=si->definition();
2373 resAnchor = si->label();
2374 AUTO_TRACE_EXIT("section anchor={} def={}",resAnchor,si->definition()?si->definition()->name():"<none>");
2375 return true;
2376 }
2377 else if ((pd=Doxygen::exampleLinkedMap->find(linkRef))) // link to an example
2378 {
2379 *resContext=pd;
2380 AUTO_TRACE_EXIT("example");
2381 return true;
2382 }
2383 else if ((gd=Doxygen::groupLinkedMap->find(linkRef))) // link to a group
2384 {
2385 *resContext=gd;
2386 AUTO_TRACE_EXIT("group");
2387 return true;
2388 }
2389 else if ((fd=Doxygen::inputNameLinkedMap->findFileDef(linkRef,ambig)) // file link
2390 && fd->isLinkable())
2391 {
2392 *resContext=fd;
2393 AUTO_TRACE_EXIT("file");
2394 return true;
2395 }
2396 else if ((cd=getClass(linkRef))) // class link
2397 {
2398 *resContext=cd;
2399 resAnchor=cd->anchor();
2400 AUTO_TRACE_EXIT("class");
2401 return true;
2402 }
2403 else if (lang==SrcLangExt::Java &&
2404 (cd=getClass(linkRefWithoutTemplates))) // Java generic class link
2405 {
2406 *resContext=cd;
2407 resAnchor=cd->anchor();
2408 AUTO_TRACE_EXIT("generic");
2409 return true;
2410 }
2411 else if ((cd=getClass(linkRef+"-p"))) // Obj-C protocol link
2412 {
2413 *resContext=cd;
2414 resAnchor=cd->anchor();
2415 AUTO_TRACE_EXIT("protocol");
2416 return true;
2417 }
2418 else if ((cnd=getConcept(linkRef))) // C++20 concept definition
2419 {
2420 *resContext=cnd;
2421 resAnchor=cnd->anchor();
2422 AUTO_TRACE_EXIT("concept");
2423 return true;
2424 }
2425 else if ((modd=ModuleManager::instance().modules().find(linkRef)))
2426 {
2427 *resContext=modd;
2428 resAnchor=modd->anchor();
2429 AUTO_TRACE_EXIT("module");
2430 return true;
2431 }
2432 else if ((nd=Doxygen::namespaceLinkedMap->find(linkRef)))
2433 {
2434 *resContext=nd;
2435 AUTO_TRACE_EXIT("namespace");
2436 return true;
2437 }
2438 else if ((dir=resolveDirLink(linkRef)) && dir->isLinkable())
2439 {
2440 *resContext=dir;
2441 AUTO_TRACE_EXIT("directory");
2442 return true;
2443 }
2444 else // probably a member reference
2445 {
2446 const MemberDef *md = nullptr;
2447 bool res = resolveRef(scName,lr,true,resContext,&md,lang,true,currentFile);
2448 if (md) resAnchor=md->anchor();
2449 AUTO_TRACE_EXIT("member? res={}",res);
2450 return res;
2451 }
2452}
2453
2454//----------------------------------------------------------------------
2455
2456
2457DString findExampleFilePath(const DString &file,bool &ambig)
2458{
2459 ambig=false;
2460 DString result;
2461 bool found=false;
2462 if (!found)
2463 {
2464 FileInfo fi(file.str());
2465 if (fi.exists())
2466 {
2467 result=fi.absFilePath();
2468 found=true;
2469 }
2470 }
2471 if (!found)
2472 {
2473 StringVector examplePathList = Config_getList(EXAMPLE_PATH);
2474 for (const auto &s : examplePathList)
2475 {
2476 std::string absFileName = s+(Portable::pathSeparator()+file).str();
2477 FileInfo fi(absFileName);
2478 if (fi.exists())
2479 {
2480 result=fi.absFilePath();
2481 found=true;
2482 }
2483 }
2484 }
2485
2486 if (!found)
2487 {
2488 // as a fallback we also look in the exampleNameDict
2490 if (fd && !ambig)
2491 {
2492 result=fd->absFilePath();
2493 }
2494 }
2495 return result;
2496}
2497
2498//----------------------------------------------------------------------
2499
2501{
2502 std::string substRes;
2503 int line = 1;
2504 const char *p = s.data();
2505 if (p)
2506 {
2507 // reserve some room for expansion
2508 substRes.reserve(s.length()+1024);
2509 char c = 0;
2510 while ((c=*p))
2511 {
2512 bool found = false;
2513 if (c=='$')
2514 {
2515 for (const auto &kw : keywords)
2516 {
2517 size_t keyLen = dstrlen(kw.keyword);
2518 if (dstrncmp(p,kw.keyword,keyLen)==0)
2519 {
2520 const char *startArg = p+keyLen;
2521 bool expectParam = std::holds_alternative<KeywordSubstitution::GetValueWithParam>(kw.getValueVariant);
2522 //printf("%s: expectParam=%d *startArg=%c\n",kw.keyword,expectParam,*startArg);
2523 if (expectParam && *startArg=='(') // $key(value)
2524 {
2525 size_t j=1;
2526 const char *endArg = nullptr;
2527 while ((c=*(startArg+j)) && c!=')' && c!='\n' && c!=0) j++;
2528 if (c==')') endArg=startArg+j;
2529 if (endArg)
2530 {
2531 DString value = DString(startArg+1).left(endArg-startArg-1);
2532 auto &&getValue = std::get<KeywordSubstitution::GetValueWithParam>(kw.getValueVariant);
2533 substRes+=getValue(value).str();
2534 p=endArg+1;
2535 //printf("found '%s'->'%s'\n",kw.keyword,qPrint(getValue(value)));
2536 }
2537 else
2538 {
2539 //printf("missing argument\n");
2540 warn(file,line,"Missing argument for '{}'",kw.keyword);
2541 p+=keyLen;
2542 }
2543 }
2544 else if (!expectParam) // $key
2545 {
2546 auto &&getValue = std::get<KeywordSubstitution::GetValue>(kw.getValueVariant);
2547 substRes+=getValue().str();
2548 //printf("found '%s'->'%s'\n",kw.keyword,qPrint(getValue()));
2549 p+=keyLen;
2550 }
2551 else
2552 {
2553 //printf("%s %d Expected arguments, none specified '%s'\n",qPrint(file), line, qPrint(kw.keyword));
2554 warn(file,line,"Expected arguments for '{}' but none were specified",kw.keyword);
2555 p+=keyLen;
2556 }
2557 found = true;
2558 break;
2559 }
2560 }
2561 }
2562 if (!found) // copy
2563 {
2564 if (c=='\n') line++;
2565 substRes+=c;
2566 p++;
2567 }
2568 }
2569 }
2570 return substRes;
2571}
2572
2574{
2575 // get the current date and time
2576 std::tm dat{};
2577 int specFormat=0;
2578 DString specDate = "";
2579 DString err = dateTimeFromString(specDate,dat,specFormat);
2580
2581 // do the conversion
2582 int usedFormat=0;
2583 return formatDateTime(fmt,dat,usedFormat);
2584}
2585
2587{
2588 DString projectLogo = Config_getString(PROJECT_LOGO);
2589 if (!projectLogo.empty())
2590 {
2591 // check for optional width= and height= specifier
2592 if (size_t wi = projectLogo.find(" width="); wi!=DString::npos) // and strip them
2593 {
2594 projectLogo = projectLogo.left(wi);
2595 }
2596 if (size_t hi = projectLogo.find(" height="); hi!=DString::npos)
2597 {
2598 projectLogo = projectLogo.left(hi);
2599 }
2600 }
2601 //printf("projectlogo='%s'\n",qPrint(projectLogo));
2602 return projectLogo;
2603}
2604
2606{
2607 DString sizeVal;
2608 DString projectLogo = Config_getString(PROJECT_LOGO);
2609 if (!projectLogo.empty())
2610 {
2611 auto extractDimension = [&projectLogo](const char *startMarker,size_t startPos,size_t endPos) -> DString
2612 {
2613 DString result = projectLogo.mid(startPos,endPos-startPos).stripWhiteSpace().quoted();
2614 if (result.length()>=2 && result.at(0)!='"' && result.at(result.length()-1)!='"')
2615 {
2616 result="\""+result+"\"";
2617 }
2618 result.prepend(startMarker);
2619 return result;
2620 };
2621 // check for optional width= and height= specifier
2622 size_t wi = projectLogo.find(" width=");
2623 size_t hi = projectLogo.find(" height=");
2624 if (wi!=DString::npos && hi!=DString::npos)
2625 {
2626 if (wi<hi) // "... width=x height=y..."
2627 {
2628 sizeVal = extractDimension(" width=", wi+7, hi) + " "
2629 + extractDimension(" height=", hi+8, projectLogo.length());
2630 }
2631 else // "... height=y width=x..."
2632 {
2633 sizeVal = extractDimension(" height=", hi+8, wi) + " "
2634 + extractDimension(" width=", wi+7, projectLogo.length());
2635 }
2636 }
2637 else if (wi!=DString::npos) // ... width=x..."
2638 {
2639 sizeVal = extractDimension(" width=", wi+7, projectLogo.length());
2640 }
2641 else if (hi!=DString::npos) // ... height=x..."
2642 {
2643 sizeVal = extractDimension(" height=", hi+8, projectLogo.length());
2644 }
2645 }
2646 //printf("projectsize='%s'\n",qPrint(sizeVal));
2647 return sizeVal;
2648}
2649
2650
2651//----------------------------------------------------------------------
2652
2653/*! Returns the character index within \a name of the first prefix
2654 * in Config_getList(IGNORE_PREFIX) that matches \a name at the left hand side,
2655 * or zero if no match was found
2656 */
2657int getPrefixIndex(const DString &name)
2658{
2659 if (name.empty()) return 0;
2660 int result=0;
2661 StringVector sl = Config_getList(IGNORE_PREFIX);
2662 for (const auto &s : sl)
2663 {
2664 const char *ps=s.c_str();
2665 const char *pd=name.data();
2666 int i=0;
2667 while (*ps!=0 && *pd!=0 && *ps==*pd)
2668 {
2669 ps++;
2670 pd++;
2671 i++;
2672 }
2673 if (*ps==0 && *pd!=0)
2674 {
2675 result=i;
2676 break;
2677 }
2678 }
2679 if (result<static_cast<int>(name.length())-1 && name.at(result)=='[') result++; // for e.g. [union] return u
2680 return result;
2681}
2682
2683//----------------------------------------------------------------------------
2684
2686{
2687 auto caseSenseNames = Config_getEnum(CASE_SENSE_NAMES);
2688
2689 if (caseSenseNames == CASE_SENSE_NAMES_t::YES) return true;
2690 else if (caseSenseNames == CASE_SENSE_NAMES_t::NO) return false;
2692}
2693
2694DString escapeCharsInString(const DString &name,bool allowDots,bool allowUnderscore)
2695{
2696 if (name.empty()) return name;
2697 bool caseSenseNames = useCaseSenseNames();
2698 bool allowUnicodeNames = Config_getBool(ALLOW_UNICODE_NAMES);
2699 DString result;
2700 result.reserve(name.length()+8);
2701 signed char c = 0;
2702 const char *p=name.data();
2703 while ((c=*p++)!=0)
2704 {
2705 switch(c)
2706 {
2707 case '_': if (allowUnderscore) result+='_'; else result+="__"; break;
2708 case '-': result+='-'; break;
2709 case ':': result+="_1"; break;
2710 case '/': result+="_2"; break;
2711 case '<': result+="_3"; break;
2712 case '>': result+="_4"; break;
2713 case '*': result+="_5"; break;
2714 case '&': result+="_6"; break;
2715 case '|': result+="_7"; break;
2716 case '.': if (allowDots) result+='.'; else result+="_8"; break;
2717 case '!': result+="_9"; break;
2718 case ',': result+="_00"; break;
2719 case ' ': result+="_01"; break;
2720 case '{': result+="_02"; break;
2721 case '}': result+="_03"; break;
2722 case '?': result+="_04"; break;
2723 case '^': result+="_05"; break;
2724 case '%': result+="_06"; break;
2725 case '(': result+="_07"; break;
2726 case ')': result+="_08"; break;
2727 case '+': result+="_09"; break;
2728 case '=': result+="_0a"; break;
2729 case '$': result+="_0b"; break;
2730 case '\\': result+="_0c"; break;
2731 case '@': result+="_0d"; break;
2732 case ']': result+="_0e"; break;
2733 case '[': result+="_0f"; break;
2734 case '#': result+="_0g"; break;
2735 case '"': result+="_0h"; break;
2736 case '~': result+="_0i"; break;
2737 case '\'': result+="_0j"; break;
2738 case ';': result+="_0k"; break;
2739 case '`': result+="_0l"; break;
2740 default:
2741 if (c<0)
2742 {
2743 bool doEscape = true;
2744 if (allowUnicodeNames)
2745 {
2746 int charLen = getUTF8CharNumBytes(c);
2747 if (charLen>0)
2748 {
2749 result+=DString(p-1,charLen);
2750 p+=charLen;
2751 doEscape = false;
2752 }
2753 }
2754 if (doEscape) // not a valid unicode char or escaping needed
2755 {
2756 char ids[5];
2757 unsigned char id = static_cast<unsigned char>(c);
2758 ids[0]='_';
2759 ids[1]='x';
2760 ids[2]=hex[id>>4];
2761 ids[3]=hex[id&0xF];
2762 ids[4]=0;
2763 result+=ids;
2764 }
2765 }
2766 else if (caseSenseNames || !isupper(c))
2767 {
2768 result+=c;
2769 }
2770 else
2771 {
2772 result+='_';
2773 result+=static_cast<char>(tolower(c));
2774 }
2775 break;
2776 }
2777 }
2778 return result;
2779}
2780
2782{
2783 if (s.empty()) return s;
2784 bool caseSenseNames = useCaseSenseNames();
2785 DString result;
2786 result.reserve(s.length());
2787 const char *p = s.data();
2788 if (p)
2789 {
2790 char c = 0;
2791 while ((c=*p++))
2792 {
2793 if (c=='_') // 2 or 3 character escape
2794 {
2795 switch (*p)
2796 {
2797 case '_': result+=c; p++; break; // __ -> '_'
2798 case '1': result+=':'; p++; break; // _1 -> ':'
2799 case '2': result+='/'; p++; break; // _2 -> '/'
2800 case '3': result+='<'; p++; break; // _3 -> '<'
2801 case '4': result+='>'; p++; break; // _4 -> '>'
2802 case '5': result+='*'; p++; break; // _5 -> '*'
2803 case '6': result+='&'; p++; break; // _6 -> '&'
2804 case '7': result+='|'; p++; break; // _7 -> '|'
2805 case '8': result+='.'; p++; break; // _8 -> '.'
2806 case '9': result+='!'; p++; break; // _9 -> '!'
2807 case '0': // 3 character escape
2808 switch (*(p+1))
2809 {
2810 case '0': result+=','; p+=2; break; // _00 -> ','
2811 case '1': result+=' '; p+=2; break; // _01 -> ' '
2812 case '2': result+='{'; p+=2; break; // _02 -> '{'
2813 case '3': result+='}'; p+=2; break; // _03 -> '}'
2814 case '4': result+='?'; p+=2; break; // _04 -> '?'
2815 case '5': result+='^'; p+=2; break; // _05 -> '^'
2816 case '6': result+='%'; p+=2; break; // _06 -> '%'
2817 case '7': result+='('; p+=2; break; // _07 -> '('
2818 case '8': result+=')'; p+=2; break; // _08 -> ')'
2819 case '9': result+='+'; p+=2; break; // _09 -> '+'
2820 case 'a': result+='='; p+=2; break; // _0a -> '='
2821 case 'b': result+='$'; p+=2; break; // _0b -> '$'
2822 case 'c': result+='\\'; p+=2; break;// _0c -> '\'
2823 case 'd': result+='@'; p+=2; break; // _0d -> '@'
2824 case 'e': result+=']'; p+=2; break; // _0e -> ']'
2825 case 'f': result+='['; p+=2; break; // _0f -> '['
2826 case 'g': result+='#'; p+=2; break; // _0g -> '#'
2827 case 'h': result+='"'; p+=2; break; // _0h -> '"'
2828 case 'i': result+='~'; p+=2; break; // _0i -> '~'
2829 case 'j': result+='\''; p+=2; break;// _0j -> '\'
2830 case 'k': result+=';'; p+=2; break; // _0k -> ';'
2831 case 'l': result+='`'; p+=2; break; // _0l -> '`'
2832 default: // unknown escape, just pass underscore character as-is
2833 result+=c;
2834 break;
2835 }
2836 break;
2837 default:
2838 if (!caseSenseNames && c>='a' && c<='z') // lower to upper case escape, _a -> 'A'
2839 {
2840 result+=static_cast<char>(toupper(*p));
2841 p++;
2842 }
2843 else // unknown escape, pass underscore character as-is
2844 {
2845 result+=c;
2846 }
2847 break;
2848 }
2849 }
2850 else // normal character; pass as is
2851 {
2852 result+=c;
2853 }
2854 }
2855 }
2856 return result;
2857}
2858
2859static std::unordered_map<std::string,int> g_usedNames;
2860static std::mutex g_usedNamesMutex;
2861static int g_usedNamesCount=1;
2862
2863
2864
2865/*! This function determines the file name on disk of an item
2866 * given its name, which could be a class name with template
2867 * arguments, so special characters need to be escaped.
2868 */
2869DString convertNameToFile(const DString &name,bool allowDots,bool allowUnderscore)
2870{
2871 if (name.empty()) return name;
2872 bool shortNames = Config_getBool(SHORT_NAMES);
2873 bool createSubdirs = Config_getBool(CREATE_SUBDIRS);
2874 DString result;
2875 if (shortNames) // use short names only
2876 {
2877 std::lock_guard<std::mutex> lock(g_usedNamesMutex);
2878 auto kv = g_usedNames.find(name.str());
2879 uint32_t num=0;
2880 if (kv!=g_usedNames.end())
2881 {
2882 num = kv->second;
2883 }
2884 else
2885 {
2886 num = g_usedNamesCount;
2887 g_usedNames.emplace(name.str(),g_usedNamesCount++);
2888 }
2889 result.sprintf("a%05d",num);
2890 }
2891 else // long names
2892 {
2893 result=escapeCharsInString(name,allowDots,allowUnderscore);
2894 size_t resultLen = result.length();
2895 if (resultLen>=128) // prevent names that cannot be created!
2896 {
2897 // third algorithm based on MD5 hash
2898 result=result.left(128-32)+md5str(result.view());
2899 }
2900 }
2901 if (createSubdirs)
2902 {
2903 int l1Dir=0,l2Dir=0;
2904 int createSubdirsLevel = Config_getInt(CREATE_SUBDIRS_LEVEL);
2905 int createSubdirsBitmaskL2 = (1<<createSubdirsLevel)-1;
2906
2907 // compute md5 hash to determine sub directory to use
2908 auto md5_sig = md5hash(result.view());
2909 l1Dir = md5_sig[14] & 0xf;
2910 l2Dir = md5_sig[15] & createSubdirsBitmaskL2;
2911
2912 result.prepend(DString().sprintf("d%x/d%02x/",l1Dir,l2Dir));
2913 }
2914 //printf("*** convertNameToFile(%s)->%s\n",qPrint(name),qPrint(result));
2915 return result;
2916}
2917
2919{
2920 DString result;
2921 if (Config_getBool(CREATE_SUBDIRS))
2922 {
2923 if (name.empty())
2924 {
2925 return REL_PATH_TO_ROOT;
2926 }
2927 else if (size_t i = name.rfind('/'); i!=DString::npos)
2928 {
2929 result=REL_PATH_TO_ROOT;
2930 }
2931 }
2932 return result;
2933}
2934
2935DString determineAbsoluteIncludeName(const DString &curFile,const DString &incFileName)
2936{
2937 bool searchIncludes = Config_getBool(SEARCH_INCLUDES);
2938 DString absIncFileName = incFileName;
2939 FileInfo fi(curFile.str());
2940 if (fi.exists())
2941 {
2942 DString absName = fi.dirPath(true)+"/"+incFileName;
2943 FileInfo fi2(absName.str());
2944 if (fi2.exists())
2945 {
2946 absIncFileName=fi2.absFilePath();
2947 }
2948 else if (searchIncludes) // search in INCLUDE_PATH as well
2949 {
2950 StringVector includePath = Config_getList(INCLUDE_PATH);
2951 for (const auto &incPath : includePath)
2952 {
2953 FileInfo fi3(incPath);
2954 if (fi3.exists() && fi3.isDir())
2955 {
2956 absName = fi3.absFilePath()+"/"+incFileName;
2957 //printf("trying absName=%s\n",qPrint(absName));
2958 FileInfo fi4(absName.str());
2959 if (fi4.exists())
2960 {
2961 absIncFileName=fi4.absFilePath();
2962 break;
2963 }
2964 //printf( "absIncFileName = %s\n", qPrint(absIncFileName) );
2965 }
2966 }
2967 }
2968 //printf( "absIncFileName = %s\n", qPrint(absIncFileName) );
2969 }
2970 return absIncFileName;
2971}
2972
2973
2974
2975void createSubDirs(const Dir &d)
2976{
2977 if (Config_getBool(CREATE_SUBDIRS))
2978 {
2979 // create up to 4096 subdirectories
2980 int createSubdirsLevelPow2 = 1 << Config_getInt(CREATE_SUBDIRS_LEVEL);
2981 for (int l1=0; l1<16; l1++)
2982 {
2983 DString subdir;
2984 subdir.sprintf("d%x",l1);
2985 if (!d.exists(subdir.str()) && !d.mkdir(subdir.str()))
2986 {
2987 term("Failed to create output directory '{}'\n",subdir);
2988 }
2989 for (int l2=0; l2<createSubdirsLevelPow2; l2++)
2990 {
2991 DString subsubdir;
2992 subsubdir.sprintf("d%x/d%02x",l1,l2);
2993 if (!d.exists(subsubdir.str()) && !d.mkdir(subsubdir.str()))
2994 {
2995 term("Failed to create output directory '{}'\n",subsubdir);
2996 }
2997 }
2998 }
2999 }
3000}
3001
3002void clearSubDirs(const Dir &d)
3003{
3004 if (Config_getBool(CREATE_SUBDIRS))
3005 {
3006 // remove empty subdirectories
3007 int createSubdirsLevelPow2 = 1 << Config_getInt(CREATE_SUBDIRS_LEVEL);
3008 for (int l1=0;l1<16;l1++)
3009 {
3010 DString subdir;
3011 subdir.sprintf("d%x",l1);
3012 for (int l2=0; l2 < createSubdirsLevelPow2; l2++)
3013 {
3014 DString subsubdir;
3015 subsubdir.sprintf("d%x/d%02x",l1,l2);
3016 if (d.exists(subsubdir.str()) && d.empty(subsubdir.str()))
3017 {
3018 d.rmdir(subsubdir.str());
3019 }
3020 }
3021 if (d.exists(subdir.str()) && d.empty(subdir.str()))
3022 {
3023 d.rmdir(subdir.str());
3024 }
3025 }
3026 }
3027}
3028
3029/*! Input is a scopeName, output is the scopename split into a
3030 * namespace part (as large as possible) and a classname part.
3031 */
3032void extractNamespaceName(const DString &scopeName,
3033 DString &className,DString &namespaceName,
3034 bool allowEmptyClass)
3035{
3036 DString clName=scopeName;
3037 NamespaceDef *nd = nullptr;
3038 size_t i=0;
3039 int p=0;
3040 if (!clName.empty() && (nd=getResolvedNamespace(clName)) && getClass(clName)==nullptr)
3041 { // the whole name is a namespace (and not a class)
3042 namespaceName=nd->name();
3043 className.clear();
3044 goto done;
3045 }
3046 p=static_cast<int>(clName.length())-2;
3047 while (p>=0 && (i=clName.rfind("::",p))!=DString::npos)
3048 // see if the first part is a namespace (and not a class)
3049 {
3050 //printf("Trying %s\n",qPrint(clName.left(i)));
3051 if (i>0 && (nd=getResolvedNamespace(clName.left(i))) && getClass(clName.left(i))==nullptr)
3052 {
3053 //printf("found!\n");
3054 namespaceName=nd->name();
3055 className=clName.mid(i+2);
3056 goto done;
3057 }
3058 p=static_cast<int>(i)-2; // try a smaller piece of the scope
3059 }
3060 //printf("not found!\n");
3061
3062 // not found, so we just have to guess.
3063 className=scopeName;
3064 namespaceName.clear();
3065
3066done:
3067 if (className.empty() && !namespaceName.empty() && !allowEmptyClass)
3068 {
3069 // class and namespace with the same name, correct to return the class.
3070 className=namespaceName;
3071 namespaceName.clear();
3072 }
3073 //printf("extractNamespace '%s' => '%s|%s'\n",qPrint(scopeName),
3074 // qPrint(className),qPrint(namespaceName));
3075 if (className.endsWith("-p"))
3076 {
3077 className = className.left(className.length()-2);
3078 }
3079 return;
3080}
3081
3083{
3084 DString result=scope;
3085 if (!templ.empty() && scope.find('<')==DString::npos)
3086 {
3087 size_t si=0, pi=0;
3088 ClassDef *cd=nullptr;
3089 while (
3090 (si=scope.find("::",pi))!=DString::npos && !getClass(scope.left(si)+templ) &&
3091 ((cd=getClass(scope.left(si)))==nullptr || cd->templateArguments().empty())
3092 )
3093 {
3094 //printf("Tried '%s'\n",qPrint((scope.left(si)+templ)));
3095 pi=si+2;
3096 }
3097 if (si==DString::npos) // not nested => append template specifier
3098 {
3099 result+=templ;
3100 }
3101 else // nested => insert template specifier before after first class name
3102 {
3103 result=scope.left(si) + templ + scope.mid(si);
3104 }
3105 }
3106 //printf("insertTemplateSpecifierInScope('%s','%s')=%s\n",
3107 // qPrint(scope),qPrint(templ),qPrint(result));
3108 return result;
3109}
3110
3111
3112/*! Strips the scope from a name. Examples: A::B will return A
3113 * and A<T>::B<N::C<D> > will return A<T>.
3114 */
3116{
3117 DString result = name;
3118 int l = static_cast<int>(result.length());
3119 int p = 0;
3120 bool done = false;
3121 bool skipBracket=false; // if brackets do not match properly, ignore them altogether
3122 int count=0;
3123 int round=0;
3124
3125 do
3126 {
3127 p=l-1; // start at the end of the string
3128 while (p>=0 && count>=0)
3129 {
3130 char c=result.at(p);
3131 switch (c)
3132 {
3133 case ':':
3134 // only exit in the case of ::
3135 //printf("stripScope(%s)=%s\n",name,qPrint(result.right(l-p-1)));
3136 if (p>0 && result.at(p-1)==':' && (count==0 || skipBracket))
3137 {
3138 return result.right(l-p-1);
3139 }
3140 p--;
3141 break;
3142 case '>':
3143 if (skipBracket) // we don't care about brackets
3144 {
3145 p--;
3146 }
3147 else // count open/close brackets
3148 {
3149 if (p>0 && result.at(p-1)=='>') // skip >> operator
3150 {
3151 p-=2;
3152 break;
3153 }
3154 count=1;
3155 //printf("pos < = %d\n",p);
3156 p--;
3157 bool foundMatch=false;
3158 while (p>=0 && !foundMatch)
3159 {
3160 c=result.at(p--);
3161 switch (c)
3162 {
3163 case ')':
3164 round++;
3165 break;
3166 case '(':
3167 round--;
3168 break;
3169 case '>': // ignore > inside (...) to support e.g. (sizeof(T)>0) inside template parameters
3170 if (round==0) count++;
3171 break;
3172 case '<':
3173 if (round==0)
3174 {
3175 if (p>0)
3176 {
3177 if (result.at(p-1) == '<') // skip << operator
3178 {
3179 p--;
3180 break;
3181 }
3182 }
3183 count--;
3184 foundMatch = count==0;
3185 }
3186 break;
3187 default:
3188 //printf("c=%c count=%d\n",c,count);
3189 break;
3190 }
3191 }
3192 }
3193 //printf("pos > = %d\n",p+1);
3194 break;
3195 default:
3196 p--;
3197 }
3198 }
3199 done = count==0 || skipBracket; // reparse if brackets do not match
3200 skipBracket=true;
3201 }
3202 while (!done); // if < > unbalanced repeat ignoring them
3203 //printf("stripScope(%s)=%s\n",name,name);
3204 return name;
3205}
3206
3207/*! Converts a string to a HTML id string */
3209{
3210 if (s.empty()) return s;
3211 DString result;
3212 result.reserve(s.length()+8);
3213 const char *p = s.data();
3214 char c = 0;
3215 bool first = true;
3216 while ((c=*p++))
3217 {
3218 char encChar[4];
3219 if ((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z') || c=='-')
3220 { // any permissive character except _
3221 if (first && c>='0' && c<='9') result+='a'; // don't start with a digit
3222 result+=c;
3223 }
3224 else
3225 {
3226 encChar[0]='_';
3227 encChar[1]=hex[static_cast<unsigned char>(c)>>4];
3228 encChar[2]=hex[static_cast<unsigned char>(c)&0xF];
3229 encChar[3]=0;
3230 result+=encChar;
3231 }
3232 first=false;
3233 }
3234 return result;
3235}
3236
3237/*! Converts a string to an XML-encoded string */
3238DString convertToXML(const DString &s, bool keepEntities, const bool citeEntry)
3239{
3240 if (s.empty()) return s;
3241 DString result;
3242 result.reserve(s.length()+32);
3243 const char *p = s.data();
3244 char c = 0;
3245 while ((c=*p++))
3246 {
3247 switch (c)
3248 {
3249 case '<': result+="&lt;"; break;
3250 case '>': result+="&gt;"; break;
3251 case '&': if (keepEntities)
3252 {
3253 const char *e=p;
3254 char ce = 0;
3255 while ((ce=*e++))
3256 {
3257 if (ce==';' || (!(isId(ce) || ce=='#'))) break;
3258 }
3259 if (ce==';') // found end of an entity
3260 {
3261 // copy entry verbatim
3262 result+=c;
3263 while (p<e) result+=*p++;
3264 }
3265 else
3266 {
3267 result+="&amp;";
3268 }
3269 }
3270 else if (citeEntry)
3271 {
3273 result,
3274 p-1,
3275 [](HtmlEntityMapper::SymType symType) { return HtmlEntityMapper::instance().xml(symType); },
3276 "&amp;");
3277 }
3278 else
3279 {
3280 result+="&amp;";
3281 }
3282 break;
3283 case '\'': result+="&apos;"; break;
3284 case '"': result+="&quot;"; break;
3285 case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8:
3286 case 11: case 12: case 13: case 14: case 15: case 16: case 17: case 18:
3287 case 19: case 20: case 21: case 22: case 23: case 24: case 25: case 26:
3288 case 27: case 28: case 29: case 30: case 31:
3289 break; // skip invalid XML characters (see http://www.w3.org/TR/2000/REC-xml-20001006#NT-Char)
3290 default: result+=c; break;
3291 }
3292 }
3293 return result;
3294}
3295
3296/*! Converts a string to a HTML-encoded string */
3297DString convertToHtml(const DString &s,bool keepEntities)
3298{
3299 if (s.empty()) return s;
3300 DString result;
3301 result.reserve(s.length()+32);
3302 const char *p=s.data();
3303 char c = 0;
3304 while ((c=*p++))
3305 {
3306 switch (c)
3307 {
3308 case '<': result+="&lt;"; break;
3309 case '>': result+="&gt;"; break;
3310 case '&': if (keepEntities)
3311 {
3312 const char *e=p;
3313 char ce = 0;
3314 while ((ce=*e++))
3315 {
3316 if (ce==';' || (!(isId(ce) || ce=='#'))) break;
3317 }
3318 if (ce==';') // found end of an entity
3319 {
3320 // copy entry verbatim
3321 result+=c;
3322 while (p<e) result+=*p++;
3323 }
3324 else
3325 {
3326 result+="&amp;";
3327 }
3328 }
3329 else
3330 {
3331 result+="&amp;";
3332 }
3333 break;
3334 case '\'': result+="&#39;"; break;
3335 case '"': result+="&quot;"; break;
3336 default:
3337 {
3338 uint8_t uc = static_cast<uint8_t>(c);
3339 if (uc<32 && !isspace(c))
3340 {
3341 result+="&#x24";
3342 result+=hex[uc>>4];
3343 result+=hex[uc&0xF];
3344 result+=';';
3345 }
3346 else
3347 {
3348 result+=c;
3349 }
3350 }
3351 break;
3352 }
3353 }
3354 return result;
3355}
3356
3357DString convertToJSString(const DString &s,bool keepEntities,bool singleQuotes)
3358{
3359 if (s.empty()) return s;
3360 DString result;
3361 result.reserve(s.length()+32);
3362 const char *p=s.data();
3363 char c = 0;
3364 while ((c=*p++))
3365 {
3366 switch (c)
3367 {
3368 case '"': if (!singleQuotes) result+="\\\""; else result+=c;
3369 break;
3370 case '\'': if (singleQuotes) result+="\\\'"; else result+=c;
3371 break;
3372 case '\\': if (*p=='u' && *(p+1)=='{') result+="\\"; // keep \u{..} unicode escapes
3373 else result+="\\\\";
3374 break;
3375 default: result+=c; break;
3376 }
3377 }
3378 return keepEntities ? result : HtmlEntityMapper::instance().convertCharEntitiesToUTF8(result);
3379}
3380
3381/*! Extracts a (sub-)string from \a type starting at \a pos that
3382 * could form a class. The index of the match is returned and the found
3383 * class \a name and a template argument list \a templSpec. If -1 is returned
3384 * there are no more matches.
3385 */
3386int extractClassNameFromType(const DString &type,int &pos,DString &name,DString &templSpec,SrcLangExt lang)
3387{
3388 AUTO_TRACE("type='{}' pos={} name='{}' lang={}",type,pos,name,lang);
3389 static const reg::Ex re_norm(R"(\a[\w:]*)");
3390 static const reg::Ex re_fortran(R"(\a[\w:()=]*)");
3391 const reg::Ex *re = &re_norm;
3392
3393 name.clear();
3394 templSpec.clear();
3395 if (type.empty())
3396 {
3397 AUTO_TRACE_EXIT("empty type");
3398 return -1;
3399 }
3400 size_t typeLen=type.length();
3401 if (typeLen>0)
3402 {
3403 if (lang == SrcLangExt::Fortran)
3404 {
3405 if (type[pos]==',')
3406 {
3407 AUTO_TRACE_EXIT("comma");
3408 return -1;
3409 }
3410 if (!type.lower().startsWith("type"))
3411 {
3412 re = &re_fortran;
3413 }
3414 }
3415 std::string s = type.str();
3416 reg::Iterator it(s,*re,static_cast<int>(pos));
3418
3419 if (it!=end)
3420 {
3421 const auto &match = *it;
3422 size_t i = match.position();
3423 size_t l = match.length();
3424 size_t ts = i+l;
3425 size_t te = ts;
3426 size_t tl = 0;
3427
3428 while (ts<typeLen && type[static_cast<uint32_t>(ts)]==' ') { ts++; tl++; } // skip any whitespace
3429 if (ts<typeLen && type[static_cast<uint32_t>(ts)]=='<') // assume template instance
3430 {
3431 // locate end of template
3432 te=ts+1;
3433 int brCount=1;
3434 while (te<typeLen && brCount!=0)
3435 {
3436 if (type[static_cast<uint32_t>(te)]=='<')
3437 {
3438 if (te<typeLen-1 && type[static_cast<uint32_t>(te)+1]=='<') te++; else brCount++;
3439 }
3440 if (type[static_cast<uint32_t>(te)]=='>')
3441 {
3442 if (te<typeLen-1 && type[static_cast<uint32_t>(te)+1]=='>') te++; else brCount--;
3443 }
3444 te++;
3445 }
3446 }
3447 name = match.str();
3448 if (te>ts)
3449 {
3450 templSpec = DString(type).mid(ts,te-ts);
3451 tl+=te-ts;
3452 pos=static_cast<int>(i+l+tl);
3453 }
3454 else // no template part
3455 {
3456 pos=static_cast<int>(i+l);
3457 }
3458 //printf("extractClassNameFromType([in] type=%s,[out] pos=%d,[out] name=%s,[out] templ=%s)=true i=%d\n",
3459 // qPrint(type),pos,qPrint(name),qPrint(templSpec),i);
3460 AUTO_TRACE_EXIT("pos={} templSpec='{}' return={}",pos,templSpec,i);
3461 return static_cast<int>(i);
3462 }
3463 }
3464 pos = static_cast<int>(typeLen);
3465 //printf("extractClassNameFromType([in] type=%s,[out] pos=%d,[out] name=%s,[out] templ=%s)=false\n",
3466 // qPrint(type),pos,qPrint(name),qPrint(templSpec));
3467 AUTO_TRACE_EXIT("not found");
3468 return -1;
3469}
3470
3472 const DString &name,
3473 const Definition *context,
3474 const ArgumentList &formalArgs)
3475{
3476 // skip until <
3477 size_t p=name.find('<');
3478 if (p==DString::npos) return name;
3479 p++;
3480 DString result = name.left(p);
3481
3482 std::string s = name.mid(p).str();
3483 static const reg::Ex re(R"([\a:][\w:]*)");
3484 reg::Iterator it(s,re);
3486 size_t pi=0;
3487 // for each identifier in the template part (e.g. B<T> -> T)
3488 for (; it!=end ; ++it)
3489 {
3490 const auto &match = *it;
3491 size_t i = match.position();
3492 size_t l = match.length();
3493 result += s.substr(pi,i-pi);
3494 DString n(match.str());
3495 bool found=false;
3496 for (const Argument &formArg : formalArgs)
3497 {
3498 if (formArg.name == n)
3499 {
3500 found=true;
3501 break;
3502 }
3503 }
3504 if (!found)
3505 {
3506 // try to resolve the type
3507 SymbolResolver resolver;
3508 const ClassDef *cd = resolver.resolveClass(context,n);
3509 if (cd)
3510 {
3511 result+=cd->name();
3512 }
3513 else
3514 {
3515 result+=n;
3516 }
3517 }
3518 else
3519 {
3520 result+=n;
3521 }
3522 pi=i+l;
3523 }
3524 result+=s.substr(pi);
3525 //printf("normalizeNonTemplateArgumentInString(%s)=%s\n",qPrint(name),qPrint(result));
3526 return removeRedundantWhiteSpace(result);
3527}
3528
3529
3531 const DString &nm,
3532 const ArgumentList &formalArgs,
3533 const ArgumentList *actualArgs)
3534{
3535 AUTO_TRACE("name={} formalArgs={} actualArgs={}",nm,argListToString(formalArgs),actualArgs ? argListToString(*actualArgs) : DString());
3536 if (formalArgs.empty()) return nm;
3537 DString result;
3538
3539 static const reg::Ex re(R"(\a\w*)");
3540 std::string name = nm.str();
3541 reg::Iterator it(name,re);
3543 size_t p=0;
3544
3545 for (; it!=end ; ++it)
3546 {
3547 const auto &match = *it;
3548 size_t i = match.position();
3549 size_t l = match.length();
3550 if (i>p) result += name.substr(p,i-p);
3551 DString n(match.str());
3553 if (actualArgs)
3554 {
3555 actIt = actualArgs->begin();
3556 }
3557 //printf(": name=%s\n",qPrint(name));
3558
3559 // if n is a template argument, then we substitute it
3560 // for its template instance argument.
3561 bool found=false;
3562 for (auto formIt = formalArgs.begin();
3563 formIt!=formalArgs.end() && !found;
3564 ++formIt
3565 )
3566 {
3567 Argument formArg = *formIt;
3568 Argument actArg;
3569 if (actualArgs && actIt!=actualArgs->end())
3570 {
3571 actArg = *actIt;
3572 }
3573 if (formArg.type.startsWith("class ") && formArg.name.empty())
3574 {
3575 formArg.name = formArg.type.mid(6);
3576 formArg.type = "class";
3577 }
3578 else if (formArg.type.startsWith("typename ") && formArg.name.empty())
3579 {
3580 formArg.name = formArg.type.mid(9);
3581 formArg.type = "typename";
3582 }
3583 else if (formArg.type.startsWith("class...")) // match 'class... name' to 'name...'
3584 {
3585 formArg.name += "...";
3586 formArg.type = formArg.type.left(5)+formArg.type.mid(8);
3587 }
3588 else if (formArg.type.startsWith("typename...")) // match 'typename... name' to 'name...'
3589 {
3590 formArg.name += "...";
3591 formArg.type = formArg.type.left(8)+formArg.type.mid(11);
3592 }
3593 //printf(": n=%s formArg->type='%s' formArg->name='%s' formArg->defval='%s' actArg->type='%s' actArg->name='%s' \n",
3594 // qPrint(n),qPrint(formArg.type),qPrint(formArg.name),qPrint(formArg.defval),qPrint(actArg.type),qPrint(actArg.name));
3595 if (formArg.type=="class" || formArg.type=="typename" || formArg.type.startsWith("template"))
3596 {
3597 if (formArg.name==n && actualArgs && actIt!=actualArgs->end() && !actArg.type.empty()) // base class is a template argument
3598 {
3599 static constexpr auto hasRecursion = [](const DString &prefix,const DString &nameArg,const DString &subst) -> bool
3600 {
3601 size_t ii=0;
3602 size_t pp=0;
3603
3604 ii = subst.find('<');
3605 //printf("prefix='%s' subst='%s'\n",qPrint(prefix.mid(prefix.length()-ii-2,ii+1)),qPrint(subst.left(ii+1)));
3606 if (ii!=DString::npos && prefix.length()>=ii+2 && prefix.mid(prefix.length()-ii-2,ii+1)==subst.left(ii+1))
3607 {
3608 return true; // don't replace 'A< ' with 'A< A<...', see issue #10951
3609 }
3610
3611 while ((ii=subst.find(nameArg,pp))!=DString::npos)
3612 {
3613 bool beforeNonWord = ii==0 || !isId(subst.at(ii-1));
3614 bool afterNonWord = subst.length()==ii+nameArg.length() || !isId(subst.at(ii+nameArg.length()));
3615 if (beforeNonWord && afterNonWord)
3616 {
3617 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
3618 }
3619 pp=ii+nameArg.length();
3620 }
3621 return false;
3622 };
3623 // replace formal argument with the actual argument of the instance
3624 AUTO_TRACE_ADD("result={} n={} type={} hasRecursion={}",result,n,actArg.type,hasRecursion(result,n,actArg.type));
3625 if (!hasRecursion(result,n,actArg.type))
3626 // the scope guard is to prevent recursive lockup for
3627 // template<class A> class C : public<A::T>,
3628 // where A::T would become A::T::T here,
3629 // since n==A and actArg->type==A::T
3630 // see bug595833 for an example
3631 //
3632 // Also prevent recursive substitution if n is part of actArg.type, i.e.
3633 // n='A' in argType='S< A >' would produce 'S< S< A > >'
3634 {
3635 if (actArg.name.empty())
3636 {
3637 result += actArg.type;
3638 }
3639 else
3640 // for case where the actual arg is something like "unsigned int"
3641 // the "int" part is in actArg->name.
3642 {
3643 result += actArg.type+" "+actArg.name;
3644 }
3645 found=true;
3646 }
3647 }
3648 else if (formArg.name==n &&
3649 (actualArgs==nullptr || actIt==actualArgs->end()) &&
3650 !formArg.defval.empty() &&
3651 formArg.defval!=nm /* to prevent recursion */
3652 )
3653 {
3654 result += substituteTemplateArgumentsInString(formArg.defval,formalArgs,actualArgs);
3655 found=true;
3656 }
3657 }
3658 else if (formArg.name==n &&
3659 (actualArgs==nullptr || actIt==actualArgs->end()) &&
3660 !formArg.defval.empty() &&
3661 formArg.defval!=nm /* to prevent recursion */
3662 )
3663 {
3664 result += substituteTemplateArgumentsInString(formArg.defval,formalArgs,actualArgs);
3665 found=true;
3666 }
3667 if (actualArgs && actIt!=actualArgs->end())
3668 {
3669 actIt++;
3670 }
3671 }
3672 if (!found)
3673 {
3674 result += n;
3675 }
3676 p=i+l;
3677 }
3678 result+=name.substr(p);
3679 result=result.simplifyWhiteSpace();
3680 AUTO_TRACE_EXIT("result={}",result);
3681 return result.stripWhiteSpace();
3682}
3683
3684
3685/*! Strips template specifiers from scope \a fullName, except those
3686 * that make up specialized classes. The switch \a parentOnly
3687 * determines whether or not a template "at the end" of a scope
3688 * should be considered, e.g. with \a parentOnly is \c true, `A<T>::B<S>` will
3689 * try to strip `<T>` and not `<S>`, while \a parentOnly is \c false will
3690 * strip both unless `A<T>` or `B<S>` are specialized template classes.
3691 */
3693 bool parentOnly,
3694 DString *pLastScopeStripped,
3695 DString scopeName,
3696 bool allowArtificial)
3697{
3698 //printf("stripTemplateSpecifiersFromScope(name=%s,scopeName=%s)\n",qPrint(fullName),qPrint(scopeName));
3699 size_t i=fullName.find('<');
3700 if (i==DString::npos) return fullName;
3701 DString result;
3702 size_t p=0;
3703 size_t l=fullName.length();
3704 while (i!=DString::npos)
3705 {
3706 //printf("1:result+=%s\n",qPrint(fullName.mid(p,i-p)));
3707 size_t e=i+1;
3708 int count=1;
3709 int round=0;
3710 while (e<l && count>0)
3711 {
3712 char c=fullName.at(e++);
3713 switch (c)
3714 {
3715 case '(': round++; break;
3716 case ')': if (round>0) round--; break;
3717 case '<': if (round==0) count++; break;
3718 case '>': if (round==0) count--; break;
3719 default:
3720 break;
3721 }
3722 }
3723 size_t si = fullName.find("::",e);
3724
3725 if (parentOnly && si==DString::npos) break;
3726 // we only do the parent scope, so we stop here if needed
3727
3728 result+=fullName.mid(p,i-p);
3729 //printf(" trying %s\n",qPrint(mergeScopes(scopeName,result+fullName.mid(i,e-i))));
3730 ClassDef *cd = getClass(mergeScopes(scopeName,result+fullName.mid(i,e-i)));
3731 if (cd!=nullptr && (allowArtificial || !cd->isArtificial()))
3732 {
3733 result+=fullName.mid(i,e-i);
3734 //printf(" 2:result+=%s\n",qPrint(fullName.mid(i,e-i-1)));
3735 }
3736 else if (pLastScopeStripped)
3737 {
3738 //printf(" last stripped scope '%s'\n",qPrint(fullName.mid(i,e-i)));
3739 *pLastScopeStripped=fullName.mid(i,e-i);
3740 }
3741 p=e;
3742 i=fullName.find('<',p);
3743 }
3744 result+=fullName.right(l-p);
3745 //printf("3:result+=%s\n",qPrint(fullName.right(l-p)));
3746 //printf("end result=%s\n",qPrint(result));
3747 return result;
3748}
3749
3750/*! Merges two scope parts together. The parts may (partially) overlap.
3751 * Example1: \c A::B and \c B::C will result in \c A::B::C <br>
3752 * Example2: \c A and \c B will be \c A::B <br>
3753 * Example3: \c A::B and B will be \c A::B
3754 *
3755 * @param leftScope the left hand part of the scope.
3756 * @param rightScope the right hand part of the scope.
3757 * @returns the merged scope.
3758 */
3759DString mergeScopes(const DString &leftScope,const DString &rightScope)
3760{
3761 AUTO_TRACE("leftScope='{}' rightScope='{}'",leftScope,rightScope);
3762 // case leftScope=="A" rightScope=="A::B" => result = "A::B"
3763 if (leftScopeMatch(leftScope,rightScope))
3764 {
3765 AUTO_TRACE_EXIT("case1={}",rightScope);
3766 return rightScope;
3767 }
3768 DString result;
3769 size_t i=0,p=leftScope.length();
3770
3771 // case leftScope=="A::B" rightScope=="B::C" => result = "A::B::C"
3772 // case leftScope=="A::B" rightScope=="B" => result = "A::B"
3773 bool found=false;
3774 while ((i=leftScope.rfind("::",p))!=DString::npos && i>0)
3775 {
3776 if (leftScopeMatch(rightScope,leftScope.mid(i+2)))
3777 {
3778 result = leftScope.left(i+2)+rightScope;
3779 found=true;
3780 }
3781 p=i-1;
3782 }
3783 if (found)
3784 {
3785 AUTO_TRACE_EXIT("case2={}",result);
3786 return result;
3787 }
3788
3789 // case leftScope=="A" rightScope=="B" => result = "A::B"
3790 result=leftScope;
3791 if (!result.empty() && !rightScope.empty()) result+="::";
3792 result+=rightScope;
3793 AUTO_TRACE_EXIT("case3={}",result);
3794 return result;
3795}
3796
3797/*! Returns a fragment from scope \a s, starting at position \a p.
3798 *
3799 * @param s the scope name as a string.
3800 * @param p the start position (0 is the first).
3801 * @param l the resulting length of the fragment.
3802 * @returns the location of the fragment, or -1 if non is found.
3803 */
3804int getScopeFragment(const DString &s,int p,int *l)
3805{
3806 int sl=static_cast<int>(s.length());
3807 int sp=p;
3808 int count=0;
3809 bool done=false;
3810 if (sp>=sl) return -1;
3811 while (sp<sl)
3812 {
3813 char c=s.at(sp);
3814 if (c==':')
3815 {
3816 sp++;
3817 p++;
3818 }
3819 else
3820 {
3821 break;
3822 }
3823 }
3824 while (sp<sl)
3825 {
3826 char c=s.at(sp);
3827 switch (c)
3828 {
3829 case ':': // found next part
3830 goto found;
3831 case '<': // skip template specifier
3832 count=1;sp++;
3833 done=false;
3834 while (sp<sl && !done)
3835 {
3836 // TODO: deal with << and >> operators!
3837 c=s.at(sp++);
3838 switch(c)
3839 {
3840 case '<': count++; break;
3841 case '>': count--; if (count==0) done=true; break;
3842 default: break;
3843 }
3844 }
3845 break;
3846 default:
3847 sp++;
3848 break;
3849 }
3850 }
3851found:
3852 *l=sp-p;
3853 //printf("getScopeFragment(%s,%d)=%s\n",qPrint(s),p,qPrint(s.mid(p,*l)));
3854 return p;
3855}
3856
3857//----------------------------------------------------------------------------
3858
3860{
3861 ModuleDef *mod = nullptr;
3863 {
3864 const FileDef *fd = toFileDef(d);
3865 if (fd) mod = fd->getModuleDef();
3866 }
3868 {
3869 const ClassDef *cd = toClassDef(d);
3870 if (cd)
3871 {
3872 const FileDef *fd = cd->getFileDef();
3873 if (fd) mod = fd->getModuleDef();
3874 }
3875 }
3877 {
3878 const ConceptDef *cd = toConceptDef(d);
3879 if (cd)
3880 {
3881 const FileDef *fd = cd->getFileDef();
3882 if (fd) mod = fd->getModuleDef();
3883 }
3884 }
3885 return mod;
3886}
3887
3888static bool recursivelyAddGroupListToTitle(OutputList &ol,const Definition *d,bool root)
3889{
3890 ModuleDef *mod = root ? findModuleDef(d) : nullptr;
3891 if (!d->partOfGroups().empty() || mod!=nullptr) // write list of group to which this definition belongs
3892 {
3893 if (root)
3894 {
3895 ol.pushGeneratorState();
3897 ol.writeString("<div class=\"ingroups\">");
3898 }
3899 bool first=true;
3900 for (const auto &gd : d->partOfGroups())
3901 {
3902 if (!first) { ol.writeString(" &#124; "); } else first=false;
3903 if (recursivelyAddGroupListToTitle(ol, gd, false))
3904 {
3905 ol.writeString(" &raquo; ");
3906 }
3907 ol.writeObjectLink(gd->getReference(),gd->getOutputFileBase(),DString(),gd->groupTitle());
3908 }
3909 if (root)
3910 {
3911 // add module as a group to the file as well
3912 if (mod)
3913 {
3914 if (!first) { ol.writeString(" &#124; "); } else first=false;
3915 ol.writeString(theTranslator->trModule(false,true)+" ");
3917 mod->displayName());
3918 }
3919 ol.writeString("</div>");
3920 ol.popGeneratorState();
3921 }
3922 return true;
3923 }
3924 return false;
3925}
3926
3928{
3930}
3931
3932bool checkExtension(const DString &fName, const DString &ext)
3933{
3934 return fName.right(ext.length())==ext;
3935}
3936
3938{
3939 if (fName.empty()) return;
3940 size_t i_fs = fName.rfind('/');
3941 size_t i_bs = fName.rfind('\\');
3942 size_t p = i_fs!=DString::npos && i_bs!=DString::npos ? std::max(i_fs, i_bs) :
3943 i_fs!=DString::npos ? i_fs : i_bs!=DString::npos ? i_bs : 0;
3944 size_t i = fName.find('.',p); // search for . after path part
3945 if (i==DString::npos)
3946 {
3948 }
3949}
3950
3952{
3953 DString result=fName;
3954 if (result.right(ext.length())==ext)
3955 {
3956 result=result.left(result.length()-ext.length());
3957 }
3958 return result;
3959}
3960
3965
3967{
3968 DString result=s;
3969 if (size_t i=result.rfind('/'); i!=DString::npos)
3970 {
3971 result=result.mid(i+1);
3972 }
3973 if (size_t i=result.rfind('\\'); i!=DString::npos)
3974 {
3975 result=result.mid(i+1);
3976 }
3977 return result;
3978}
3979
3980DString makeBaseName(const DString &name, const DString &ext)
3981{
3982 return stripExtensionGeneral(stripPath(name), ext);
3983}
3984
3985/** Special version of DString::stripWhiteSpace() that only strips
3986 * completely blank lines.
3987 * @param s the string to be stripped
3988 * @param docLine the line number corresponding to the start of the
3989 * string. This will be adjusted based on the number of lines stripped
3990 * from the start.
3991 * @returns The stripped string.
3992 */
3994{
3995 if (s.empty()) return DString();
3996 const char *p = s.data();
3997
3998 // search for leading empty lines
3999 int i=0,li=-1,l=static_cast<int>(s.length());
4000 char c = 0;
4001 while ((c=*p))
4002 {
4003 if (c==' ' || c=='\t' || c=='\r') { i++; p++; }
4004 else if (c=='\\' && literal_at(p,"\\ilinebr")) { i+=8; li=i; p+=8; }
4005 else if (c=='\n') { i++; li=i; docLine++; p++; }
4006 else break;
4007 }
4008
4009 // search for trailing empty lines
4010 int b=l-1,bi=-1;
4011 p=s.data()+b;
4012 while (b>=0)
4013 {
4014 c=*p;
4015 if (c==' ' || c=='\t' || c=='\r') { b--; p--; }
4016 else if (c=='r' && b>=7 && literal_at(p-7,"\\ilinebr")) { bi=b-7; b-=8; p-=8; }
4017 else if (c=='>' && b>=11 && literal_at(p-11,"\\ilinebr<br>")) { bi=b-11; b-=12; p-=12; }
4018 else if (c=='\n') { bi=b; b--; p--; }
4019 else break;
4020 }
4021
4022 // return whole string if no leading or trailing lines where found
4023 if (li==-1 && bi==-1) return s;
4024
4025 // return substring
4026 if (bi==-1) bi=l;
4027 if (li==-1) li=0;
4028 if (bi<=li) return DString(); // only empty lines
4029 //printf("docLine='%s' len=%d li=%d bi=%d\n",qPrint(s),s.length(),li,bi);
4030 return s.mid(li,bi-li);
4031}
4032
4033//--------------------------------------------------------------------------
4034
4035static std::unordered_map<std::string,SrcLangExt> g_extLookup;
4036
4038{
4039 const char *langName;
4040 const char *parserName;
4042 const char *defExt;
4043};
4044
4045static std::vector<Lang2ExtMap> g_lang2extMap =
4046{
4047// language parser parser option
4048 { "idl", "c", SrcLangExt::IDL, ".idl" },
4049 { "java", "c", SrcLangExt::Java, ".java"},
4050 { "javascript", "c", SrcLangExt::JS, ".js" },
4051 { "csharp", "c", SrcLangExt::CSharp, ".cs" },
4052 { "d", "c", SrcLangExt::D, ".d" },
4053 { "php", "c", SrcLangExt::PHP, ".php" },
4054 { "objective-c", "c", SrcLangExt::ObjC, ".m" },
4055 { "c", "c", SrcLangExt::Cpp, ".c" },
4056 { "c++", "c", SrcLangExt::Cpp, ".cpp" },
4057 { "slice", "c", SrcLangExt::Slice, ".ice" },
4058 { "python", "python", SrcLangExt::Python, ".py" },
4059 { "fortran", "fortran", SrcLangExt::Fortran, ".f" },
4060 { "fortranfree", "fortranfree", SrcLangExt::Fortran, ".f90" },
4061 { "fortranfixed", "fortranfixed", SrcLangExt::Fortran, ".f" },
4062 { "vhdl", "vhdl", SrcLangExt::VHDL, ".vhdl"},
4063 { "xml", "xml", SrcLangExt::XML, ".xml" },
4064 { "sql", "sql", SrcLangExt::SQL, ".sql" },
4065 { "md", "md", SrcLangExt::Markdown, ".md" },
4066 { "lex", "lex", SrcLangExt::Lex, ".l" },
4067};
4068
4069bool updateLanguageMapping(const DString &extension,const DString &language)
4070{
4071 DString langName = language.lower();
4072 auto it1 = std::find_if(g_lang2extMap.begin(),g_lang2extMap.end(),
4073 [&langName](const auto &info) { return info.langName==langName; });
4074 if (it1 == g_lang2extMap.end()) return false;
4075
4076 // found the language
4077 SrcLangExt parserId = it1->parserId;
4078 DString extName = extension.lower();
4079 if (extName.empty()) return false;
4080 if (extName.at(0)!='.') extName.prepend(".");
4081 auto it2 = g_extLookup.find(extName.str());
4082 if (it2!=g_extLookup.end())
4083 {
4084 g_extLookup.erase(it2); // language was already register for this ext
4085 }
4086 //printf("registering extension %s\n",qPrint(extName));
4087 g_extLookup.emplace(extName.str(),parserId);
4088 if (!Doxygen::parserManager->registerExtension(extName,it1->parserName))
4089 {
4090 err("Failed to assign extension {} to parser {} for language {}\n",
4091 extName.data(),it1->parserName,language);
4092 }
4093 else
4094 {
4095 //msg("Registered extension {} to language parser {}...\n",
4096 // extName,language);
4097 }
4098 return true;
4099}
4100
4102{
4103 // NOTE: when adding an extension, also add the extension in config.xml
4104 // extension parser id
4105 updateLanguageMapping(".dox", "c");
4106 updateLanguageMapping(".txt", "c"); // see bug 760836
4107 updateLanguageMapping(".doc", "c");
4108 updateLanguageMapping(".c", "c");
4109 updateLanguageMapping(".C", "c");
4110 updateLanguageMapping(".cc", "c");
4111 updateLanguageMapping(".CC", "c");
4112 updateLanguageMapping(".cxx", "c");
4113 updateLanguageMapping(".cpp", "c");
4114 updateLanguageMapping(".c++", "c");
4115 updateLanguageMapping(".cxxm", "c"); // C++20 modules
4116 updateLanguageMapping(".cppm", "c"); // C++20 modules
4117 updateLanguageMapping(".ccm", "c"); // C++20 modules
4118 updateLanguageMapping(".c++m", "c"); // C++20 modules
4119 updateLanguageMapping(".ii", "c");
4120 updateLanguageMapping(".ixx", "c");
4121 updateLanguageMapping(".ipp", "c");
4122 updateLanguageMapping(".i++", "c");
4123 updateLanguageMapping(".inl", "c");
4124 updateLanguageMapping(".h", "c");
4125 updateLanguageMapping(".H", "c");
4126 updateLanguageMapping(".hh", "c");
4127 updateLanguageMapping(".HH", "c");
4128 updateLanguageMapping(".hxx", "c");
4129 updateLanguageMapping(".hpp", "c");
4130 updateLanguageMapping(".h++", "c");
4131 updateLanguageMapping(".idl", "idl");
4132 updateLanguageMapping(".ddl", "idl");
4133 updateLanguageMapping(".odl", "idl");
4134 updateLanguageMapping(".java", "java");
4135 //updateLanguageMapping(".as", "javascript"); // not officially supported
4136 //updateLanguageMapping(".js", "javascript"); // not officially supported
4137 updateLanguageMapping(".cs", "csharp");
4138 updateLanguageMapping(".d", "d");
4139 updateLanguageMapping(".php", "php");
4140 updateLanguageMapping(".php4", "php");
4141 updateLanguageMapping(".php5", "php");
4142 updateLanguageMapping(".inc", "php");
4143 updateLanguageMapping(".phtml", "php");
4144 updateLanguageMapping(".m", "objective-c");
4145 updateLanguageMapping(".M", "objective-c");
4146 updateLanguageMapping(".mm", "c"); // see bug746361
4147 updateLanguageMapping(".py", "python");
4148 updateLanguageMapping(".pyw", "python");
4149 updateLanguageMapping(".f", "fortran");
4150 updateLanguageMapping(".for", "fortran");
4151 updateLanguageMapping(".f90", "fortran");
4152 updateLanguageMapping(".f95", "fortran");
4153 updateLanguageMapping(".f03", "fortran");
4154 updateLanguageMapping(".f08", "fortran");
4155 updateLanguageMapping(".f18", "fortran");
4156 updateLanguageMapping(".vhd", "vhdl");
4157 updateLanguageMapping(".vhdl", "vhdl");
4158 updateLanguageMapping(".ucf", "vhdl");
4159 updateLanguageMapping(".qsf", "vhdl");
4160 updateLanguageMapping(".md", "md");
4161 updateLanguageMapping(".markdown", "md");
4162 updateLanguageMapping(".ice", "slice");
4163 updateLanguageMapping(".l", "lex");
4164 updateLanguageMapping(".doxygen_lex_c", "c"); // this is a placeholder so we can map initializations
4165 // in the lex scanning to cpp
4166}
4167
4169{
4170 updateLanguageMapping(".xml", "xml");
4171 updateLanguageMapping(".sql", "sql");
4172}
4173
4175{
4176 FileInfo fi(fileName.str());
4177 // we need only the part after the last ".", newer implementations of FileInfo have 'suffix()' for this.
4178 DString extName = DString(fi.extension(false)).lower();
4179 if (extName.empty()) extName=".no_extension";
4180 if (extName.at(0)!='.') extName.prepend(".");
4181 auto it = g_extLookup.find(extName.str());
4182 if (it!=g_extLookup.end()) // listed extension
4183 {
4184 //printf("getLanguageFromFileName(%s)=%x\n",qPrint(fi.extension()),*pVal);
4185 return it->second;
4186 }
4187 //printf("getLanguageFromFileName(%s) not found!\n",qPrint(fileName));
4188 return defLang; // not listed => assume C-ish language.
4189}
4190
4191/// Routine to handle the language attribute of the `\code` command
4193{
4194 // try the extension
4195 auto lang = getLanguageFromFileName(fileName, SrcLangExt::Unknown);
4196 if (lang == SrcLangExt::Unknown)
4197 {
4198 // try the language names
4199 DString langName = fileName.lower();
4200 if (langName.at(0)=='.') langName = langName.mid(1);
4201 auto it = std::find_if(g_lang2extMap.begin(),g_lang2extMap.end(),
4202 [&langName](const auto &info) { return info.langName==langName; });
4203 if (it != g_lang2extMap.end())
4204 {
4205 lang = it->parserId;
4206 fileName = it->defExt;
4207 }
4208 else // default to C++
4209 {
4210 return SrcLangExt::Cpp;
4211 }
4212 }
4213 return lang;
4214}
4215
4217{
4218 if (fn.empty()) return "";
4219 if (size_t lastDot = fn.rfind('.'); lastDot!=DString::npos) return fn.mid(lastDot);
4220 return "";
4221}
4222
4223//--------------------------------------------------------------------------
4224
4225static MemberDef *getMemberFromSymbol(const Definition *scope,const FileDef *fileScope,
4226 const DString &n)
4227{
4228 if (scope==nullptr ||
4231 )
4232 )
4233 {
4235 }
4236
4237 DString name = n;
4238 if (name.empty())
4239 return nullptr; // no name was given
4240
4241 auto &range = Doxygen::symbolMap->find(name);
4242 if (range.empty())
4243 return nullptr; // could not find any matching symbols
4244
4245 // mostly copied from getResolvedClassRec()
4246 DString explicitScopePart;
4247 int qualifierIndex = computeQualifiedIndex(name);
4248 if (qualifierIndex!=-1)
4249 {
4250 explicitScopePart = name.left(qualifierIndex);
4251 replaceNamespaceAliases(explicitScopePart);
4252 name = name.mid(qualifierIndex+2);
4253 }
4254 //printf("explicitScopePart=%s\n",qPrint(explicitScopePart));
4255
4256 int minDistance = 10000;
4257 MemberDef *bestMatch = nullptr;
4258
4259 for (Definition *d : range)
4260 {
4261 if (d->definitionType()==Definition::TypeMember)
4262 {
4263 SymbolResolver resolver(fileScope);
4264 int distance = resolver.isAccessibleFromWithExpScope(scope,d,explicitScopePart);
4265 if (distance!=-1 && distance<minDistance)
4266 {
4267 minDistance = distance;
4268 bestMatch = toMemberDef(d);
4269 //printf("new best match %s distance=%d\n",qPrint(bestMatch->qualifiedName()),distance);
4270 }
4271 }
4272 }
4273 return bestMatch;
4274}
4275
4276/*! Returns true iff the given name string appears to be a typedef in scope. */
4277bool checkIfTypedef(const Definition *scope,const FileDef *fileScope,const DString &n)
4278{
4279 MemberDef *bestMatch = getMemberFromSymbol(scope,fileScope,n);
4280
4281 if (bestMatch && bestMatch->isTypedef())
4282 return true; // closest matching symbol is a typedef
4283 else
4284 return false;
4285}
4286
4287//--------------------------------------------------------------------------------------
4288
4290{
4291 if (al.empty()) return;
4293 for (const Argument &a : al)
4294 {
4296 ol.parseText(a.name);
4297 ol.endConstraintParam();
4299 linkifyText(TextGeneratorOLImpl(ol),a.type,LinkifyTextOptions().setScope(d));
4300 ol.endConstraintType();
4302 ol.generateDoc(d->docFile(),
4303 d->docLine(),
4304 d,
4305 nullptr,
4306 a.docs,
4307 DocOptions()
4308 .setIndexWords(true));
4309 ol.endConstraintDocs();
4310 }
4311 ol.endConstraintList();
4312}
4313
4314//----------------------------------------------------------------------------
4315
4317{
4318#ifdef TRACINGSUPPORT
4319 void *backtraceFrames[128];
4320 int frameCount = backtrace(backtraceFrames, 128);
4321 const size_t cmdLen = 40960;
4322 static char cmd[cmdLen];
4323 char *p = cmd;
4324 p += snprintf(p,cmdLen,"/usr/bin/atos -p %d ", (int)getpid());
4325 for (int x = 0; x < frameCount; x++)
4326 {
4327 p += snprintf(p,cmdLen,"%p ", backtraceFrames[x]);
4328 }
4329 fprintf(stderr,"========== STACKTRACE START ==============\n");
4330 if (FILE *fp = Portable::popen(cmd, "r"))
4331 {
4332 char resBuf[512];
4333 while (size_t len = fread(resBuf, 1, sizeof(resBuf), fp))
4334 {
4335 fwrite(resBuf, 1, len, stderr);
4336 }
4337 Portable::pclose(fp);
4338 }
4339 fprintf(stderr,"============ STACKTRACE END ==============\n");
4340 //fprintf(stderr,"%s\n", frameStrings[x]);
4341#endif
4342}
4343
4344static void transcodeCharacterBuffer(const DString &fileName,std::string &contents,
4345 const DString &inputEncoding,const DString &outputEncoding)
4346{
4347 if (inputEncoding.empty() || outputEncoding.empty()) return; // no encoding specified
4348 if (dstricmp(inputEncoding,outputEncoding)==0) return; // input encoding same as output encoding
4349 void *cd = portable_iconv_open(outputEncoding.data(),inputEncoding.data());
4350 if (cd==reinterpret_cast<void *>(-1))
4351 {
4352 term("unsupported character conversion: '{}'->'{}': {}\n"
4353 "Check the INPUT_ENCODING setting in the config file!\n",
4354 inputEncoding,outputEncoding,strerror(errno));
4355 }
4356 size_t iLeft = contents.size();
4357 const char *srcPtr = contents.data();
4358 size_t tmpBufSize = contents.size()*4+1;
4359 size_t oLeft = tmpBufSize;
4360 std::string tmpBuf;
4361 tmpBuf.resize(tmpBufSize);
4362 char *dstPtr = tmpBuf.data();
4363 size_t newSize=0;
4364 if (!portable_iconv(cd, &srcPtr, &iLeft, &dstPtr, &oLeft))
4365 {
4366 newSize = tmpBufSize-oLeft;
4367 tmpBuf.resize(newSize);
4368 std::swap(contents,tmpBuf);
4369 //printf("iconv: input size=%d output size=%d\n[%s]\n",size,newSize,qPrint(srcBuf));
4370 }
4371 else
4372 {
4373 term("{}: failed to translate characters from {} to {}: check INPUT_ENCODING\n",
4374 fileName,inputEncoding,outputEncoding);
4375 }
4377}
4378
4379//! read a file name \a fileName and optionally filter and transcode it
4380bool readInputFile(const DString &fileName,std::string &contents,bool filter,bool isSourceCode)
4381{
4382 // try to open file
4383 FileInfo fi(fileName.str());
4384 if (!fi.exists()) return false;
4385 DString filterName = getFileFilter(fileName,isSourceCode);
4386 if (filterName.empty() || !filter)
4387 {
4388 std::ifstream f = Portable::openInputStream(fileName,true);
4389 if (!f.is_open())
4390 {
4391 err("could not open file {}\n",fileName);
4392 return false;
4393 }
4394 // read the file
4395 auto fileSize = fi.size();
4396 contents.resize(fileSize);
4397 f.read(contents.data(),fileSize);
4398 if (f.fail())
4399 {
4400 err("problems while reading file {}\n",fileName);
4401 return false;
4402 }
4403 }
4404 else
4405 {
4406 DString cmd=filterName+" \""+fileName+"\"";
4407 Debug::print(Debug::ExtCmd,0,"Executing popen(`{}`)\n",cmd);
4408 FILE *f=Portable::popen(cmd,"r");
4409 if (!f)
4410 {
4411 err("could not execute filter {}\n",filterName);
4412 return false;
4413 }
4414 const int bufSize=4096;
4415 char buf[bufSize];
4416 int numRead = 0;
4417 while ((numRead=static_cast<int>(fread(buf,1,bufSize,f)))>0)
4418 {
4419 //printf(">>>>>>>>Reading %d bytes\n",numRead);
4420 contents.append(buf,numRead);
4421 }
4423 Debug::print(Debug::FilterOutput, 0, "Filter output\n");
4424 Debug::print(Debug::FilterOutput,0,"-------------\n{}\n-------------\n",contents);
4425 }
4426
4427 if (contents.size()>=2 &&
4428 static_cast<uint8_t>(contents[0])==0xFF &&
4429 static_cast<uint8_t>(contents[1])==0xFE // Little endian BOM
4430 ) // UCS-2LE encoded file
4431 {
4432 transcodeCharacterBuffer(fileName,contents,"UCS-2LE","UTF-8");
4433 }
4434 else if (contents.size()>=2 &&
4435 static_cast<uint8_t>(contents[0])==0xFE &&
4436 static_cast<uint8_t>(contents[1])==0xFF // big endian BOM
4437 ) // UCS-2BE encoded file
4438 {
4439 transcodeCharacterBuffer(fileName,contents,"UCS-2BE","UTF-8");
4440 }
4441 else if (contents.size()>=3 &&
4442 static_cast<uint8_t>(contents[0])==0xEF &&
4443 static_cast<uint8_t>(contents[1])==0xBB &&
4444 static_cast<uint8_t>(contents[2])==0xBF
4445 ) // UTF-8 encoded file
4446 {
4447 contents.erase(0,3); // remove UTF-8 BOM: no translation needed
4448 }
4449 else // transcode according to the INPUT_ENCODING setting
4450 {
4451 // do character transcoding if needed.
4452 transcodeCharacterBuffer(fileName,contents,getEncoding(fi),"UTF-8");
4453 }
4454
4455 filterCRLF(contents);
4456 return true;
4457}
4458
4459// Replace %word by word in title
4461{
4462 std::string tf;
4463 std::string t = title.str();
4464 static const reg::Ex re(R"(%[a-z_A-Z]+)");
4465 reg::Iterator it(t,re);
4467 size_t p = 0;
4468 for (; it!=end ; ++it)
4469 {
4470 const auto &match = *it;
4471 size_t i = match.position();
4472 size_t l = match.length();
4473 if (i>p) tf+=t.substr(p,i-p);
4474 tf+=match.str().substr(1); // skip %
4475 p=i+l;
4476 }
4477 tf+=t.substr(p);
4478 return tf;
4479}
4480
4481//----------------------------------------------------------------------------
4482
4484{
4485 InputFileEncoding elem;
4486 auto getter = [](const InputFileEncoding &e) { return e.pattern.str(); };
4487 if (fi.match(Doxygen::inputFileEncodingList,useCaseSenseNames(),&elem,getter)) // check for file specific encoding
4488 {
4489 return elem.encoding;
4490 }
4491 else // fall back to default encoding
4492 {
4493 return Config_getString(INPUT_ENCODING);
4494 }
4495}
4496
4498{
4499 bool extLinksInWindow = Config_getBool(EXT_LINKS_IN_WINDOW);
4500 if (extLinksInWindow)
4501 return "target=\"_blank\" ";
4502 else if (parent)
4503 return "target=\"_parent\" ";
4504 else
4505 return "";
4506}
4507
4509 const DString &ref,
4510 bool isLocalFile,
4511 const DString &targetFileName,
4512 const DString &anchor)
4513{
4514 DString url;
4515 if (!ref.empty())
4516 {
4517 url = externalRef(relPath,ref);
4518 }
4519 if (!targetFileName.empty())
4520 {
4521 DString fn = targetFileName;
4522 if (ref.empty())
4523 {
4524 if (!anchor.empty() && isLocalFile)
4525 {
4526 fn=""; // omit file name for local links
4527 }
4528 else
4529 {
4530 url = relPath;
4531 }
4532 }
4533 url+=fn;
4534 }
4535 if (!anchor.empty())
4536 {
4537 if (!url.endsWith("=")) url+="#";
4538 url+=anchor;
4539 }
4540 //printf("createHtmlUrl(relPath=%s,local=%d,target=%s,anchor=%s)=%s\n",qPrint(relPath),isLocalFile,qPrint(targetFileName),qPrint(anchor),qPrint(url));
4541 return url;
4542}
4543
4544DString externalRef(const DString &relPath,const DString &ref)
4545{
4546 DString result;
4547 if (!ref.empty())
4548 {
4549 auto it = Doxygen::tagDestinationMap.find(ref.str());
4551 {
4552 result = it->second;
4553 size_t l = result.length();
4554 if (!relPath.empty() && l>0 && result.at(0)=='.')
4555 { // relative path -> prepend relPath.
4556 result.prepend(relPath);
4557 l+=relPath.length();
4558 }
4559 if (l>0 && result.at(l-1)!='/') result+='/';
4560 }
4561 }
4562 else
4563 {
4564 result = relPath;
4565 }
4566 return result;
4567}
4568
4569/** Replaces any markers of the form \#\#AA in input string \a str
4570 * by new markers of the form \#AABBCC, where \#AABBCC represents a
4571 * valid color, based on the intensity represented by hex number AA
4572 * and the current HTML_COLORSTYLE_* settings.
4573 */
4575{
4576 if (str.empty()) return DString();
4577 std::string result;
4578 std::string s=str.str();
4579 static const reg::Ex re(R"(##[0-9A-Fa-f][0-9A-Fa-f])");
4580 reg::Iterator it(s,re);
4582 int hue = Config_getInt(HTML_COLORSTYLE_HUE);
4583 int sat = Config_getInt(HTML_COLORSTYLE_SAT);
4584 int gamma = Config_getInt(HTML_COLORSTYLE_GAMMA);
4585 size_t sl=s.length();
4586 size_t p=0;
4587 for (; it!=end ; ++it)
4588 {
4589 const auto &match = *it;
4590 size_t i = match.position();
4591 size_t l = match.length();
4592 if (i>p) result+=s.substr(p,i-p);
4593 std::string lumStr = match.str().substr(2);
4594#define HEXTONUM(x) (((x)>='0' && (x)<='9') ? ((x)-'0') : \
4595 ((x)>='a' && (x)<='f') ? ((x)-'a'+10) : \
4596 ((x)>='A' && (x)<='F') ? ((x)-'A'+10) : 0)
4597
4598 double r = 0,g = 0,b = 0;
4599 int level = HEXTONUM(lumStr[0])*16+HEXTONUM(lumStr[1]);
4600 ColoredImage::hsl2rgb(hue/360.0,sat/255.0,
4601 pow(level/255.0,gamma/100.0),&r,&g,&b);
4602 int red = static_cast<int>(r*255.0);
4603 int green = static_cast<int>(g*255.0);
4604 int blue = static_cast<int>(b*255.0);
4605 char colStr[8];
4606 colStr[0]='#';
4607 colStr[1]=hex[red>>4];
4608 colStr[2]=hex[red&0xf];
4609 colStr[3]=hex[green>>4];
4610 colStr[4]=hex[green&0xf];
4611 colStr[5]=hex[blue>>4];
4612 colStr[6]=hex[blue&0xf];
4613 colStr[7]=0;
4614 //printf("replacing %s->%s (level=%d)\n",qPrint(lumStr),colStr,level);
4615 result+=colStr;
4616 p=i+l;
4617 }
4618 if (p<sl) result+=s.substr(p);
4619 return result;
4620}
4621
4622/** Copies the contents of file with name \a src to the newly created
4623 * file with name \a dest. Returns true if successful.
4624 */
4625bool copyFile(const DString &src,const DString &dest)
4626{
4627 if (!Dir().copy(src.str(),dest.str()))
4628 {
4629 err("could not copy file {} to {}\n",src,dest);
4630 return false;
4631 }
4632 return true;
4633}
4634
4636{
4637 if (lang==SrcLangExt::Java || lang==SrcLangExt::CSharp || lang==SrcLangExt::VHDL || lang==SrcLangExt::Python)
4638 {
4639 return ".";
4640 }
4641 else if (lang==SrcLangExt::PHP && !classScope)
4642 {
4643 return "\\";
4644 }
4645 else
4646 {
4647 return "::";
4648 }
4649}
4650
4651/** Checks whether the given url starts with a supported protocol */
4652bool isURL(const DString &url)
4653{
4654 static const std::unordered_set<std::string> schemes = {
4655 "http", "https", "ftp", "ftps", "sftp", "file", "news", "irc", "ircs"
4656 };
4657 DString loc_url = url.stripWhiteSpace();
4658 size_t colonPos = loc_url.find(':');
4659 return colonPos!=DString::npos && schemes.find(loc_url.left(colonPos).str())!=schemes.end();
4660}
4661
4662/** Corrects URL \a url according to the relative path \a relPath.
4663 * Returns the corrected URL. For absolute URLs no correction will be done.
4664 */
4665DString correctURL(const DString &url,const DString &relPath)
4666{
4667 DString result = url;
4668 if (!relPath.empty() && !isURL(url))
4669 {
4670 result.prepend(relPath);
4671 }
4672 return result;
4673}
4674
4675//---------------------------------------------------------------------------
4676
4678{
4679 bool extractPrivate = Config_getBool(EXTRACT_PRIVATE);
4680 bool extractPackage = Config_getBool(EXTRACT_PACKAGE);
4681
4682 return (prot!=Protection::Private && prot!=Protection::Package) ||
4683 (prot==Protection::Private && extractPrivate) ||
4684 (prot==Protection::Package && extractPackage);
4685}
4686
4687//---------------------------------------------------------------------------
4688
4689DString stripIndentation(const DString &s,bool skipFirstLine)
4690{
4691 if (s.empty()) return s; // empty string -> we're done
4692
4693 //printf("stripIndentation:\n%s\n------\n",qPrint(s));
4694 // compute minimum indentation over all lines
4695 const char *p=s.data();
4696 char c=0;
4697 int indent=0;
4698 int minIndent=1000000; // "infinite"
4699 bool searchIndent=true;
4700 int tabSize=Config_getInt(TAB_SIZE);
4701 bool skipFirst = skipFirstLine;
4702 while ((c=*p++))
4703 {
4704 if (c=='\t') { indent+=tabSize - (indent%tabSize); }
4705 else if (c=='\n') { indent=0; searchIndent=true; skipFirst=false; }
4706 else if (c==' ') { indent++; }
4707 else if (searchIndent && !skipFirst)
4708 {
4709 searchIndent=false;
4710 if (indent<minIndent) minIndent=indent;
4711 }
4712 }
4713
4714 // no indent to remove -> we're done
4715 if (minIndent==0) return substitute(s,"@ilinebr","\\ilinebr");
4716
4717 // remove minimum indentation for each line
4718 TextStream result;
4719 p=s.data();
4720 indent=0;
4721 skipFirst=skipFirstLine;
4722 while ((c=*p++))
4723 {
4724 if (c=='\n') // start of new line
4725 {
4726 indent=0;
4727 result << c;
4728 skipFirst=false;
4729 }
4730 else if (indent<minIndent && !skipFirst) // skip until we reach minIndent
4731 {
4732 if (c=='\t')
4733 {
4734 int newIndent = indent+tabSize-(indent%tabSize);
4735 int i=newIndent;
4736 while (i>minIndent) // if a tab crosses the minIndent boundary fill the rest with spaces
4737 {
4738 result << ' ';
4739 i--;
4740 }
4741 indent=newIndent;
4742 }
4743 else // space
4744 {
4745 indent++;
4746 }
4747 }
4748 else if (c=='\\' && literal_at(p,"ilinebr "))
4749 // we also need to remove the indentation after a \ilinebr command at the end of a line
4750 {
4751 result << "\\ilinebr ";
4752 p+=8;
4753 int skipAmount=0;
4754 for (int j=0;j<minIndent;j++) if (*(p+j)==' ') skipAmount++; // test to see if we have the indent
4755 if (skipAmount==minIndent)
4756 {
4757 p+=skipAmount; // remove the indent
4758 }
4759 }
4760 else if (c=='@' && literal_at(p,"ilinebr"))
4761 {
4762 result << "\\ilinebr";
4763 p+=7;
4764 }
4765 else // copy anything until the end of the line
4766 {
4767 result << c;
4768 }
4769 }
4770
4771 //printf("stripIndentation: result=\n%s\n------\n",qPrint(result.str()));
4772
4773 return result.str();
4774}
4775
4776// strip up to \a indentationLevel spaces from each line in \a doc (excluding the first line
4777// when skipFirstLine is set to true)
4778void stripIndentationVerbatim(DString &doc,size_t indentationLevel, bool skipFirstLine)
4779{
4780 //printf("stripIndentationVerbatim(level=%d):\n%s\n------\n",indentationLevel,qPrint(doc));
4781 if (indentationLevel <= 0 || doc.empty()) return; // nothing to strip
4782
4783 // by stripping content the string will only become shorter so we write the results
4784 // back into the input string and then resize it at the end.
4785 char c = 0;
4786 const char *src = doc.data();
4787 char *dst = doc.rawData();
4788 bool insideIndent = !skipFirstLine; // skip the initial line from stripping
4789 size_t cnt = 0;
4790 if (!skipFirstLine) cnt = indentationLevel;
4791 while ((c=*src++))
4792 {
4793 // invariant: dst<=src
4794 switch(c)
4795 {
4796 case '\n':
4797 *dst++ = c;
4798 insideIndent = true;
4799 cnt = indentationLevel;
4800 break;
4801 case ' ':
4802 if (insideIndent)
4803 {
4804 if (cnt>0) // count down the spacing until the end of the indent
4805 {
4806 cnt--;
4807 }
4808 else // reached the end of the indent, start of the part of the line to keep
4809 {
4810 insideIndent = false;
4811 *dst++ = c;
4812 }
4813 }
4814 else // part after indent, copy to the output
4815 {
4816 *dst++ = c;
4817 }
4818 break;
4819 default:
4820 insideIndent = false;
4821 *dst++ = c;
4822 break;
4823 }
4824 }
4825 doc.resize(static_cast<uint32_t>(dst-doc.data()));
4826 //printf("stripIndentationVerbatim: result=\n%s\n------\n",qPrint(doc));
4827}
4828
4829//----------------------------------------------------------------------------
4830
4831/** Strip the direction part from docs and return it as a string in canonical form.
4832 * The input \a docs string can start with e.g. "[in]", "[in, out]", "[inout]", "[out,in]"...
4833 * @returns either "[in,out]", "[in]", or "[out]" or the empty string.
4834 */
4836{
4837 std::string s = docs.str();
4838 static const reg::Ex re(R"(\‍[([ inout,]+)\‍])");
4839 reg::Iterator it(s,re);
4841 if (it!=end)
4842 {
4843 const auto &match = *it;
4844 size_t p = match.position();
4845 size_t l = match.length();
4846 if (p==0 && l>2)
4847 {
4848 // make dir the part inside [...] without separators
4849 std::string dir = match[1].str();
4850 // strip , and ' ' from dir
4851 dir.erase(std::remove_if(dir.begin(),dir.end(),
4852 [](const char c) { return c==' ' || c==','; }
4853 ),dir.end());
4854 unsigned char ioMask=0;
4855 size_t inIndex = dir.find( "in");
4856 if ( inIndex!=std::string::npos) { dir.erase( inIndex,2); ioMask|=(1<<0); }
4857 size_t outIndex = dir.find("out");
4858 if (outIndex!=std::string::npos) { dir.erase(outIndex,3); ioMask|=(1<<1); }
4859 if (dir.empty() && ioMask!=0) // only in and/or out attributes found
4860 {
4861 docs = s.substr(l); // strip attributes
4862 if (ioMask==((1<<0)|(1<<1))) return "[in,out]";
4863 else if (ioMask==(1<<0)) return "[in]";
4864 else if (ioMask==(1<<1)) return "[out]";
4865 }
4866 }
4867 }
4868 return "";
4869}
4870
4872{
4873 DString paramDocs;
4874 if (al.hasDocumentation(true))
4875 {
4876 for (const Argument &a : al)
4877 {
4878 if (a.hasDocumentation(true))
4879 {
4880 DString docsWithoutDir = a.docs;
4881 DString direction = extractDirection(docsWithoutDir);
4882 DString name = a.name;
4883 if (name.empty())
4884 {
4885 name = "-";
4886 }
4887 paramDocs+=" \\ilinebr @param"+direction+" "+name+" "+docsWithoutDir;
4888 }
4889 }
4890 }
4891 return paramDocs;
4892}
4893
4894
4895//-----------------------------------------------------------
4896
4897/** Computes for a given list type \a inListType, which are the
4898 * the corresponding list type(s) in the base class that are to be
4899 * added to this list.
4900 *
4901 * So for public inheritance, the mapping is 1-1, so outListType1=inListType
4902 * Private members are to be hidden completely.
4903 *
4904 * For protected inheritance, both protected and public members of the
4905 * base class should be joined in the protected member section.
4906 *
4907 * For private inheritance, both protected and public members of the
4908 * base class should be joined in the private member section.
4909 */
4911 MemberListType inListType,
4912 Protection inProt,
4913 MemberListType *outListType1,
4914 MemberListType *outListType2
4915 )
4916{
4917 bool extractPrivate = Config_getBool(EXTRACT_PRIVATE);
4918
4919 // default representing 1-1 mapping
4920 *outListType1=inListType;
4921 *outListType2=MemberListType::Invalid();
4922
4923 if (inProt==Protection::Public)
4924 {
4925 if (inListType.isPrivate())
4926 {
4927 *outListType1=MemberListType::Invalid();
4928 }
4929 }
4930 else if (inProt==Protection::Protected)
4931 {
4932 if (inListType.isPrivate() || inListType.isPublic())
4933 {
4934 *outListType1=MemberListType::Invalid();
4935 }
4936 else if (inListType.isProtected())
4937 {
4938 *outListType2=inListType.toPublic();
4939 }
4940 }
4941 else if (inProt==Protection::Private)
4942 {
4943 if (inListType.isPublic() || inListType.isProtected())
4944 {
4945 *outListType1=MemberListType::Invalid();
4946 }
4947 else if (inListType.isPrivate())
4948 {
4949 if (extractPrivate)
4950 {
4951 *outListType1=inListType.toPublic();
4952 *outListType2=inListType.toProtected();
4953 }
4954 else
4955 {
4956 *outListType1=MemberListType::Invalid();
4957 }
4958 }
4959 }
4960
4961 //printf("convertProtectionLevel(type=%s prot=%d): %s,%s\n",
4962 // qPrint(inListType.to_string()),inProt,qPrint(outListType1->to_string()),qPrint(outListType2->to_string()));
4963}
4964
4966{
4967 return Doxygen::mainPage!=nullptr && Doxygen::mainPage->hasTitle();
4968}
4969
4971{
4972 return getDotImageExtension(Config_getEnumAsString(DOT_IMAGE_FORMAT));
4973}
4975{
4976 size_t i= format.find(':'); // strip renderer part when using e.g. 'png:cairo:gd' as format
4977 return i==DString::npos ? format : format.left(i);
4978}
4979
4981{
4982 StringVector splitExt = split(format.str(),":");
4983 DString extGen;
4984 for (size_t i = splitExt.size(); i > 0; )
4985 {
4986 --i;
4987 extGen += splitExt[i] + (i!=0 ? "." : "");
4988 }
4989 return extGen;
4990}
4991
4992bool openOutputFile(const DString &outFile,std::ofstream &f)
4993{
4994 ASSERT(!f.is_open());
4995 bool fileOpened=false;
4996 bool writeToStdout=outFile=="-";
4997 if (writeToStdout) // write to stdout
4998 {
4999 f.basic_ios<char>::rdbuf(std::cout.rdbuf());
5000 fileOpened = true;
5001 }
5002 else // write to file
5003 {
5004 FileInfo fi(outFile.str());
5005 if (fi.exists()) // create a backup
5006 {
5007 Dir dir;
5008 FileInfo backup(fi.filePath()+".bak");
5009 if (backup.exists()) // remove existing backup
5010 dir.remove(backup.filePath());
5011 dir.rename(fi.filePath(),fi.filePath()+".bak");
5012 }
5013 f = Portable::openOutputStream(outFile);
5014 fileOpened = f.is_open();
5015 }
5016 return fileOpened;
5017}
5018
5019//------------------------------------------------------
5020
5021//! remove disabled blocks and all block markers from \a s and return the result as a string
5022DString selectBlocks(const DString &s,const SelectionBlockList &blockList,const SelectionMarkerInfo &markerInfo)
5023{
5024 if (s.empty()) return s;
5025
5026 // helper to find the end of a block
5027 auto skipBlock = [&markerInfo](const char *p,const SelectionBlock &blk)
5028 {
5029 char c = 0;
5030 while ((c=*p))
5031 {
5032 if (c==markerInfo.markerChar && dstrncmp(p,markerInfo.endStr,markerInfo.endLen)==0) // end marker
5033 {
5034 size_t len = markerInfo.endLen;
5035 bool negate = *(p+markerInfo.endLen)=='!';
5036 if (negate) len++;
5037 size_t blkNameLen = dstrlen(blk.name);
5038 if (dstrncmp(p+len,blk.name,blkNameLen)==0 && // matching marker name
5039 dstrncmp(p+len+blkNameLen,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
5040 {
5041 //printf("Found end marker %s enabled=%d negate=%d\n",blk.name,blk.enabled,negate);
5042 return p+len+blkNameLen+markerInfo.closeLen;
5043 }
5044 else // not the right marker id
5045 {
5046 p++;
5047 }
5048 }
5049 else // not and end marker
5050 {
5051 p++;
5052 }
5053 }
5054 return p;
5055 };
5056
5057 DString result;
5058 result.reserve(s.length());
5059 const char *p = s.data();
5060 char c = 0;
5061 while ((c=*p))
5062 {
5063 if (c==markerInfo.markerChar) // potential start of marker
5064 {
5065 if (dstrncmp(p,markerInfo.beginStr,markerInfo.beginLen)==0) // start of begin marker
5066 {
5067 bool found = false;
5068 size_t len = markerInfo.beginLen;
5069 bool negate = *(p+len)=='!';
5070 if (negate) len++;
5071 for (const auto &blk : blockList)
5072 {
5073 size_t blkNameLen = dstrlen(blk.name);
5074 if (dstrncmp(p+len,blk.name,blkNameLen)==0 && // matching marker name
5075 dstrncmp(p+len+blkNameLen,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
5076 {
5077 bool blockEnabled = blk.enabled!=negate;
5078 //printf("Found start marker %s enabled=%d negate=%d\n",blk.name,blk.enabled,negate);
5079 p+=len+blkNameLen+markerInfo.closeLen;
5080 if (!blockEnabled) // skip until the end of the block
5081 {
5082 //printf("skipping block\n");
5083 p=skipBlock(p,blk);
5084 }
5085 found=true;
5086 break;
5087 }
5088 }
5089 if (!found) // unknown marker id
5090 {
5091 result+=c;
5092 p++;
5093 }
5094 }
5095 else if (dstrncmp(p,markerInfo.endStr,markerInfo.endLen)==0) // start of end marker
5096 {
5097 bool found = false;
5098 size_t len = markerInfo.endLen;
5099 bool negate = *(p+len)=='!';
5100 if (negate) len++;
5101 for (const auto &blk : blockList)
5102 {
5103 size_t blkNameLen = dstrlen(blk.name);
5104 if (dstrncmp(p+len,blk.name,blkNameLen)==0 && // matching marker name
5105 dstrncmp(p+len+blkNameLen,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
5106 {
5107 //printf("Found end marker %s enabled=%d negate=%d\n",blk.name,blk.enabled,negate);
5108 p+=len+blkNameLen+markerInfo.closeLen;
5109 found=true;
5110 break;
5111 }
5112 }
5113 if (!found) // unknown marker id
5114 {
5115 result+=c;
5116 p++;
5117 }
5118 }
5119 else // not a start or end marker
5120 {
5121 result+=c;
5122 p++;
5123 }
5124 }
5125 else // not a marker character
5126 {
5127 result+=c;
5128 p++;
5129 }
5130 }
5131 //printf("====\n%s\n-----\n%s\n~~~~\n",qPrint(s),qPrint(result));
5132 return result;
5133}
5134
5135void checkBlocks(const DString &s, const DString fileName,const SelectionMarkerInfo &markerInfo)
5136{
5137 if (s.empty()) return;
5138
5139 const char *p = s.data();
5140 char c = 0;
5141 while ((c=*p))
5142 {
5143 if (c==markerInfo.markerChar) // potential start of marker
5144 {
5145 if (dstrncmp(p,markerInfo.beginStr,markerInfo.beginLen)==0) // start of begin marker
5146 {
5147 size_t len = markerInfo.beginLen;
5148 bool negate = *(p+len)=='!';
5149 if (negate) len++;
5150 p += len;
5151 DString marker;
5152 while (*p)
5153 {
5154 if (markerInfo.closeLen==0 && *p=='\n') // matching end of line
5155 {
5156 warn(fileName,-1,"Remaining begin replacement with marker '{}'",marker);
5157 break;
5158 }
5159 else if (markerInfo.closeLen!= 0 && dstrncmp(p,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
5160 {
5161 p += markerInfo.closeLen;
5162 warn(fileName,-1,"Remaining begin replacement with marker '{}'",marker);
5163 break;
5164 }
5165 marker += *p;
5166 p++;
5167 }
5168 }
5169 else if (dstrncmp(p,markerInfo.endStr,markerInfo.endLen)==0) // start of end marker
5170 {
5171 size_t len = markerInfo.endLen;
5172 bool negate = *(p+len)=='!';
5173 if (negate) len++;
5174 p += len;
5175 DString marker;
5176 while (*p)
5177 {
5178 if (markerInfo.closeLen==0 && *p=='\n') // matching end of line
5179 {
5180 warn(fileName,-1,"Remaining end replacement with marker '{}'",marker);
5181 break;
5182 }
5183 else if (markerInfo.closeLen!= 0 && dstrncmp(p,markerInfo.closeStr,markerInfo.closeLen)==0) // matching marker closing
5184 {
5185 p += markerInfo.closeLen;
5186 warn(fileName,-1,"Remaining end replacement with marker '{}'",marker);
5187 break;
5188 }
5189 marker += *p;
5190 p++;
5191 }
5192 }
5193 }
5194 p++;
5195 }
5196}
5197
5198
5199
5200DString detab(const DString &s,size_t &refIndent)
5201{
5202 int tabSize = Config_getInt(TAB_SIZE);
5203 size_t size = s.length();
5204 DString result;
5205 result.reserve(size+256);
5206 const char *data = s.data();
5207 size_t i=0;
5208 int col=0;
5209 constexpr auto doxy_nbsp = "&_doxy_nbsp;"; // doxygen escape command for UTF-8 nbsp
5210 const int maxIndent=1000000; // value representing infinity
5211 int minIndent=maxIndent;
5212 bool skip = false;
5213 while (i<size)
5214 {
5215 char c = data[i++];
5216 switch(c)
5217 {
5218 case '\t': // expand tab
5219 {
5220 int stop = tabSize - (col%tabSize);
5221 //printf("expand at %d stop=%d\n",col,stop);
5222 col+=stop;
5223 while (stop--) result+=' ';
5224 }
5225 break;
5226 case '\\':
5227 if (skip && data[i] == '\\' && i+8<size && literal_at(data+i+1,"endiskip"))
5228 {
5229 // literal backslash directly followed by , e.g. `\` in a code span
5230 result+=c;
5231 col++;
5232 }
5233 else if (data[i] == '\\') // escaped command -> ignore
5234 {
5235 result+=c;
5236 result+=data[i++];
5237 col+=2;
5238 }
5239 else if (i+5<size && literal_at(data+i,"iskip")) // command
5240 {
5241 i+=5;
5242 skip = true;
5243 }
5244 else if (i+8<size && literal_at(data+i,"endiskip")) // command
5245 {
5246 i+=8;
5247 skip = false;
5248 }
5249 else // some other command
5250 {
5251 result+=c;
5252 col++;
5253 }
5254 break;
5255 case '\n': // reset column counter
5256 result+=c;
5257 col=0;
5258 break;
5259 case ' ': // increment column counter
5260 result+=c;
5261 col++;
5262 break;
5263 default: // non-whitespace => update minIndent
5264 if (static_cast<signed char>(c)<0 && i<size) // multibyte sequence
5265 {
5266 // special handling of the UTF-8 nbsp character 0xC2 0xA0
5267 int nb = isUTF8NonBreakableSpace(data);
5268 if (nb>0)
5269 {
5270 result+=doxy_nbsp;
5271 i+=nb-1;
5272 }
5273 else
5274 {
5275 int bytes = getUTF8CharNumBytes(c);
5276 for (int j=0;j<bytes-1 && c;j++)
5277 {
5278 result+=c;
5279 c = data[i++];
5280 }
5281 result+=c;
5282 }
5283 }
5284 else
5285 {
5286 result+=c;
5287 }
5288 if (!skip && col<minIndent) minIndent=col;
5289 col++;
5290 }
5291 }
5292 if (minIndent!=maxIndent) refIndent=minIndent; else refIndent=0;
5293 //printf("detab(\n%s\n)=[\n%s\n]\n",qPrint(s),qPrint(out.get()));
5294 return result;
5295}
5296
5298{
5299 DString projectCookie = Config_getString(HTML_PROJECT_COOKIE);
5300 if (projectCookie.empty()) return DString();
5301 return md5str(projectCookie.view())+"_";
5302}
5303
5304//! Return the index of the last :: in the string \a name that is still before the first <
5306{
5307 int l = static_cast<int>(name.length());
5308 int lastSepPos = -1;
5309 const char *p = name.data();
5310 int i=l-2;
5311 int sharpCount=0;
5312 // --- begin optimized version of ts=name.findRev(">::");
5313 int ts = -1;
5314 while (i>=0)
5315 {
5316 if (p[i]=='>')
5317 {
5318 if (sharpCount==0 && p[i+1]==':' && p[i+2]==':')
5319 {
5320 ts=i;
5321 break;
5322 }
5323 sharpCount++;
5324 }
5325 else if (p[i]=='<')
5326 {
5327 sharpCount--;
5328 }
5329 i--;
5330 }
5331 // --- end optimized version
5332 if (ts==-1) ts=0; else p+=++ts;
5333 for (i=ts;i<l-1;i++)
5334 {
5335 char c=*p++;
5336 if (c==':' && *p==':') lastSepPos=i;
5337 if (c=='<') break;
5338 }
5339 return lastSepPos;
5340}
5341
5342// in C# A, A<T>, and A<T,S> are different classes, so we need some way to disguish them using this name mangling
5343// A -> A
5344// A<T> -> A-1-g
5345// A<T,S> -> A-2-g
5346// A<T>::B -> A-1-g::B
5348{
5349 DString result;
5350 size_t p=0;
5351 size_t idx;
5352 while ((idx=name.find('<',p))!=DString::npos)
5353 {
5354 result+=name.mid(p,idx-p);
5355 // count the top level arguments of the balanced <...> group
5356 int depth=0;
5357 int count=1;
5358 size_t i=idx;
5359 for (; i<name.length(); i++)
5360 {
5361 char c=name[i];
5362 if (c=='<') depth++;
5363 else if (c=='>' && --depth==0) break;
5364 else if (c==',' && depth==1) count++;
5365 }
5366 result+="-"+DString().setNum(count)+"-g";
5367 p=i+1;
5368 }
5369 if (p<name.length()) result+=name.mid(p);
5370 return result;
5371}
5372
5374{
5375 DString result=name;
5376 if (result.endsWith("-g"))
5377 {
5378 size_t idx = result.find('-');
5379 result = result.left(idx)+templArgs;
5380 }
5381 return result;
5382}
5383
5385{
5386 DString text=rawStart;
5387 size_t i = text.find('"');
5389 return text.mid(i+1,text.length()-i-2); // text=...R"xyz( -> delimiter=xyz
5390}
5391
5393{
5394 DString text=rawEnd;
5395 return text.mid(1,text.length()-2); // text=)xyz" -> delimiter=xyz
5396}
5397
5398//----------------------------------------------------------------------------------------------------------
5399
5400static std::mutex writeFileContents_lock;
5402
5403DString writeInlineGraph(const DString &baseName,const DString &extension,const DString &content,bool &exists)
5404{
5405 DString fileName = baseName + md5str(content.view()) + extension;
5406 { // ==== start atomic section
5407 std::lock_guard lock(writeFileContents_lock);
5408 auto it=writeFileContents_set.find(fileName.str());
5409 exists = it!=writeFileContents_set.end();
5410 if (!exists)
5411 {
5412 writeFileContents_set.insert(fileName.str());
5413 if (auto file = Portable::openOutputStream(fileName); file.is_open())
5414 {
5415 file.write( content.data(), content.length() );
5416 file.close();
5417 }
5418 else
5419 {
5420 err("Could not open file {} for writing\n",fileName);
5421 return DString();
5422 }
5423 }
5424 } // ==== end atomic section
5425 return fileName;
5426}
5427
5429{
5430 if (Config_getBool(DOT_CLEANUP))
5431 {
5432 for (const auto& fileName: writeFileContents_set)
5433 {
5434 Dir().remove(qPrint(fileName));
5435 }
5436 }
5437}
5438
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
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:301
bool remove(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:320
bool empty(const std::string &subdir) const
Definition dir.cpp:269
bool rmdir(const std::string &path, bool acceptsAbsPath=true) const
Definition dir.cpp:315
bool rename(const std::string &orgName, const std::string &newName, bool acceptsAbsPath=true) const
Definition dir.cpp:327
bool exists() const
Definition dir.cpp:263
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:34
size_t size() const
Definition fileinfo.cpp:27
std::string extension(bool complete) const
Definition fileinfo.cpp:134
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:74
bool isFile() const
Definition fileinfo.cpp:67
std::string dirPath(bool absPath=true) const
Definition fileinfo.cpp:141
std::string filePath() const
Definition fileinfo.cpp:95
std::string absFilePath() const
Definition fileinfo.cpp:105
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 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:821
DirIterator end(const DirIterator &) noexcept
Definition dir.cpp:181
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:54
#define AUTO_TRACE(...)
Definition docnode.cpp:53
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:55
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:2033
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:692
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:681
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:85
const FileDef * currentFile
Definition util.h:86
bool insideCode
Definition util.h:88
DString args
Definition util.h:84
DString memberName
Definition util.h:83
bool checkCV
Definition util.h:87
DString scopeName
Definition util.h:82
const MemberDef * md
Definition util.h:95
const ConceptDef * cnd
Definition util.h:100
const FileDef * fd
Definition util.h:97
const ModuleDef * modd
Definition util.h:101
const GroupDef * gd
Definition util.h:99
bool found
Definition util.h:94
const ClassDef * cd
Definition util.h:96
const NamespaceDef * nd
Definition util.h:98
DString encoding
Definition doxygen.h:63
SrcLangExt parserId
Definition util.cpp:4041
const char * langName
Definition util.cpp:4039
const char * parserName
Definition util.cpp:4040
const char * defExt
Definition util.cpp:4042
size_t beginLen
Definition util.h:220
const char * closeStr
Definition util.h:223
const char * beginStr
Definition util.h:219
size_t closeLen
Definition util.h:224
const char * endStr
Definition util.h:221
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.
DString stripExtension(const DString &fName)
Definition util.cpp:3961
bool useCaseSenseNames()
Returns true if the names of the symbols can be case sensitive.
Definition util.cpp:2685
bool isURL(const DString &url)
Checks whether the given url starts with a supported protocol.
Definition util.cpp:4652
DString substituteTemplateArgumentsInString(const DString &nm, const ArgumentList &formalArgs, const ArgumentList *actualArgs)
Definition util.cpp:3530
static DString extractDirection(DString &docs)
Strip the direction part from docs and return it as a string in canonical form.
Definition util.cpp:4835
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:5400
DString inlineArgListToDoc(const ArgumentList &al)
Definition util.cpp:4871
DString stripLeadingAndTrailingEmptyLines(const DString &s, int &docLine)
Special version of DString::stripWhiteSpace() that only strips completely blank lines.
Definition util.cpp:3993
bool mainPageHasTitle()
Definition util.cpp:4965
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:4574
bool protectionLevelVisible(Protection prot)
Definition util.cpp:4677
DString stripFromIncludePath(const DString &path)
Definition util.cpp:227
DString mergeScopes(const DString &leftScope, const DString &rightScope)
Definition util.cpp:3759
DString filterTitle(const DString &title)
Definition util.cpp:4460
DString detab(const DString &s, size_t &refIndent)
Definition util.cpp:5200
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:5022
bool matchTemplateArguments(const ArgumentList &srcAl, const ArgumentList &dstAl)
Definition util.cpp:1838
void stripIndentationVerbatim(DString &doc, size_t indentationLevel, bool skipFirstLine)
Definition util.cpp:4778
void addCodeOnlyMappings()
Definition util.cpp:4168
static int g_usedNamesCount
Definition util.cpp:2861
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:4289
DString extractBeginRawStringDelimiter(const char *rawStart)
Definition util.cpp:5384
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:5297
#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:1463
static DString getCanonicalTemplateSpec(const Definition *d, const FileDef *fs, const DString &spec, SrcLangExt lang)
Definition util.cpp:1202
DString writeInlineGraph(const DString &baseName, const DString &extension, const DString &content, bool &exists)
Definition util.cpp:5403
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:2313
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:4277
static const char constScope[]
Definition util.cpp:379
static bool recursivelyAddGroupListToTitle(OutputList &ol, const Definition *d, bool root)
Definition util.cpp:3888
DString unescapeCharsInString(const DString &s)
Definition util.cpp:2781
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:2013
DString externalLinkTarget(const bool parent)
Definition util.cpp:4497
DString replaceAnonymousScopes(const DString &s, const DString &replacement)
Definition util.cpp:155
void cleanupInlineGraphs()
Definition util.cpp:5428
DString correctURL(const DString &url, const DString &relPath)
Corrects URL url according to the relative path relPath.
Definition util.cpp:4665
int computeQualifiedIndex(const DString &name)
Return the index of the last :: in the string name that is still before the first <.
Definition util.cpp:5305
DString convertToJSString(const DString &s, bool keepEntities, bool singleQuotes)
Definition util.cpp:3357
DString convertToId(const DString &s)
Definition util.cpp:3208
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:3082
DString removeRedundantWhiteSpace(const DString &s)
Definition util.cpp:427
static std::unordered_map< std::string, SrcLangExt > g_extLookup
Definition util.cpp:4035
bool checkExtension(const DString &fName, const DString &ext)
Definition util.cpp:3932
DString convertNameToFile(const DString &name, bool allowDots, bool allowUnderscore)
Definition util.cpp:2869
DString showDate(const DString &fmt)
Definition util.cpp:2573
bool leftScopeMatch(const DString &scope, const DString &name)
Definition util.cpp:745
DString stripExtensionGeneral(const DString &fName, const DString &ext)
Definition util.cpp:3951
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:3859
void addGroupListToTitle(OutputList &ol, const Definition *d)
Definition util.cpp:3927
DString extractEndRawStringDelimiter(const char *rawEnd)
Definition util.cpp:5392
static DString extractCanonicalType(const Definition *d, const FileDef *fs, DString type, SrcLangExt lang, bool insideTemplate)
Definition util.cpp:1377
#define MATCH
Definition util.cpp:1493
void clearSubDirs(const Dir &d)
Definition util.cpp:3002
DString stripScope(const DString &name)
Definition util.cpp:3115
DString getFileNameExtension(const DString &fn)
Definition util.cpp:4216
void createSubDirs(const Dir &d)
Definition util.cpp:2975
DString convertToHtml(const DString &s, bool keepEntities)
Definition util.cpp:3297
DString resolveTypeDef(const Definition *context, const DString &qualifiedName, const Definition **typedefContext)
Definition util.cpp:232
bool readInputFile(const DString &fileName, std::string &contents, bool filter, bool isSourceCode)
read a file name fileName and optionally filter and transcode it
Definition util.cpp:4380
DString normalizeNonTemplateArgumentsInString(const DString &name, const Definition *context, const ArgumentList &formalArgs)
Definition util.cpp:3471
SrcLangExt getLanguageFromFileName(const DString &fileName, SrcLangExt defLang)
Definition util.cpp:4174
DString getFileFilter(const DString &name, bool isSourceCode)
Definition util.cpp:1025
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)
Definition util.cpp:1594
static MemberDef * getMemberFromSymbol(const Definition *scope, const FileDef *fileScope, const DString &n)
Definition util.cpp:4225
void initDefaultExtensionMapping()
Definition util.cpp:4101
void addHtmlExtensionIfMissing(DString &fName)
Definition util.cpp:3937
void checkBlocks(const DString &s, const DString fileName, const SelectionMarkerInfo &markerInfo)
Definition util.cpp:5135
static void transcodeCharacterBuffer(const DString &fileName, std::string &contents, const DString &inputEncoding, const DString &outputEncoding)
Definition util.cpp:4344
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:2270
DString substituteKeywords(const DString &file, const DString &s, const KeywordSubstitutionList &keywords)
Definition util.cpp:2500
void extractNamespaceName(const DString &scopeName, DString &className, DString &namespaceName, bool allowEmptyClass)
Definition util.cpp:3032
DString convertToXML(const DString &s, bool keepEntities, const bool citeEntry)
Definition util.cpp:3238
DString stripTemplateSpecifiersFromScope(const DString &fullName, bool parentOnly, DString *pLastScopeStripped, DString scopeName, bool allowArtificial)
Definition util.cpp:3692
DString relativePathToRoot(const DString &name)
Definition util.cpp:2918
static const DirDef * resolveDirLink(const DString &linkRef)
Definition util.cpp:2295
DString argListToString(const ArgumentList &al, bool useCanonicalType, bool showDefVals)
Definition util.cpp:864
DString projectLogoFile()
Definition util.cpp:2586
static StringUnorderedSet writeFileContents_set
Definition util.cpp:5401
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:4910
static const char volatileScope[]
Definition util.cpp:380
DString getEncoding(const FileInfo &fi)
Definition util.cpp:4483
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:4625
int getPrefixIndex(const DString &name)
Definition util.cpp:2657
DString getLanguageSpecificSeparator(SrcLangExt lang, bool classScope)
Definition util.cpp:4635
bool updateLanguageMapping(const DString &extension, const DString &language)
Definition util.cpp:4069
void stackTrace()
Definition util.cpp:4316
DString demangleCSharpGenericName(const DString &name, const DString &templArgs)
Definition util.cpp:5373
DString createHtmlUrl(const DString &relPath, const DString &ref, bool isLocalFile, const DString &targetFileName, const DString &anchor)
Definition util.cpp:4508
DString projectLogoSize()
Definition util.cpp:2605
static DString getCanonicalTypeForIdentifier(const Definition *d, const FileDef *fs, const DString &word, SrcLangExt lang, DString *tSpec, int count=0)
Definition util.cpp:1223
DString mangleCSharpGenericName(const DString &name)
Definition util.cpp:5347
GetDefResult getDefs(const GetDefInput &input)
Definition util.cpp:1871
DString getDotImageExtension()
Definition util.cpp:4970
#define NOMATCH
Definition util.cpp:1494
DString escapeCharsInString(const DString &name, bool allowDots, bool allowUnderscore)
Definition util.cpp:2694
static std::mutex g_usedNamesMutex
Definition util.cpp:2860
static bool matchArgument2(const Definition *srcScope, const FileDef *srcFileScope, Argument &srcA, const Definition *dstScope, const FileDef *dstFileScope, Argument &dstA, SrcLangExt lang)
Definition util.cpp:1528
void mergeArguments(ArgumentList &srcAl, ArgumentList &dstAl, bool forceNameOverwrite)
Definition util.cpp:1694
int getScopeFragment(const DString &s, int p, int *l)
Definition util.cpp:3804
static bool getScopeDefs(const DString &docScope, const DString &scope, ClassDef *&cd, ConceptDef *&cnd, NamespaceDef *&nd, ModuleDef *&modd)
Definition util.cpp:1941
DString stripIndentation(const DString &s, bool skipFirstLine)
Definition util.cpp:4689
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:1496
int extractClassNameFromType(const DString &type, int &pos, DString &name, DString &templSpec, SrcLangExt lang)
Definition util.cpp:3386
DString determineAbsoluteIncludeName(const DString &curFile, const DString &incFileName)
Definition util.cpp:2935
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:3980
DString getDotImageExtensionGenerated(const DString &format)
Definition util.cpp:4980
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:4544
static bool isLowerCase(DString &s)
Definition util.cpp:2004
DString stripPath(const DString &s)
Definition util.cpp:3966
static std::unordered_map< std::string, int > g_usedNames
Definition util.cpp:2859
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:1486
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:4992
static std::vector< Lang2ExtMap > g_lang2extMap
Definition util.cpp:4045
DString stripAnonymousNamespaceScope(const DString &s)
Definition util.cpp:167
DString findExampleFilePath(const DString &file, bool &ambig)
Definition util.cpp:2457
SrcLangExt getLanguageFromCodeLang(DString &fileName)
Routine to handle the language attribute of the \code command.
Definition util.cpp:4192
A bunch of utility functions.
std::vector< KeywordSubstitution > KeywordSubstitutionList
Definition util.h:266
std::vector< SelectionBlock > SelectionBlockList
Definition util.h:214