Doxygen
Loading...
Searching...
No Matches
symbolresolver.cpp
Go to the documentation of this file.
1/******************************************************************************
2 *
3 * Copyright (C) 1997-2020 by Dimitri van Heesch.
4 *
5 * Permission to use, copy, modify, and distribute this software and its
6 * documentation under the terms of the GNU General Public License is hereby
7 * granted. No representations are made about the suitability of this software
8 * for any purpose. It is provided "as is" without express or implied warranty.
9 * See the GNU General Public License for more details.
10 *
11 * Documents produced by Doxygen are derivative works derived from the
12 * input used in their production; they are not affected by this license.
13 *
14 */
15
16// own header
17#include "symbolresolver.h"
18
19// standard includes
20#include <algorithm>
21#include <mutex>
22#include <string>
23#include <unordered_map>
24#include <vector>
25
26// other includes
27#include "cache.h"
28#include "config.h"
29#include "defargs.h"
30#include "doxygen.h"
31#include "filedef.h"
32#include "namespacedef.h"
33#include "trace.h"
34#include "util.h"
35
36#if !ENABLE_SYMBOLRESOLVER_TRACING
37#undef AUTO_TRACE
38#undef AUTO_TRACE_ADD
39#undef AUTO_TRACE_EXIT
40#define AUTO_TRACE(...) (void)0
41#define AUTO_TRACE_ADD(...) (void)0
42#define AUTO_TRACE_EXIT(...) (void)0
43#endif
44
45static std::recursive_mutex g_cacheTypedefMutex;
46
48{
49 std::mutex mutex;
50 size_t size = 0;
51 size_t capacity = 0;
52 uint64_t hits = 0;
53 uint64_t misses = 0;
54};
55
58
60
62{
63 std::lock_guard lock(stats.mutex);
64 stats.size = std::max(stats.size, cache.size());
65 stats.capacity = std::max(stats.capacity, cache.capacity());
66 stats.hits = std::max(stats.hits, cache.hits());
67 stats.misses = std::max(stats.misses, cache.misses());
68}
69
71{
72 public:
73 CacheStatsWrapper(CacheStatistics &stats,size_t capacity) : m_statistics(stats), m_cache(capacity) {}
75 {
76 // merge the cache statistics at the end of a worker thread's life
78 }
79 LookupCache &cache() { return m_cache; }
80 private:
83};
84
85static size_t getCacheSize()
86{
87 int cacheSize = Config_getInt(LOOKUP_CACHE_SIZE);
88 if (cacheSize<0) cacheSize=0;
89 if (cacheSize>9) cacheSize=9;
90 return 65536u << cacheSize;
91}
92
94{
96 return wrapper.cache();
97}
98
100{
102 return wrapper.cache();
103}
104
105THREAD_LOCAL std::unordered_map<std::string, std::pair<DString,const MemberDef *> > g_substMap;
106
107//--------------------------------------------------------------------------------------
108
110{
111 return defType==Definition::TypeClass || defType==Definition::TypeNamespace ||
112 defType==Definition::TypeModule || defType==Definition::TypeMember ||
114}
115
116/** Returns the name of a class as it is used inside the class itself,
117 * so Widget for Widget<int>.
118 */
120{
121 DString name = d->localName();
122 if (size_t i=name.find('<'); i!=DString::npos) name = name.left(i);
123 return name;
124}
125
126/** Returns true for a static function or variable that is not a class member,
127 * so it is only visible within the file that defines it.
128 */
129static bool isFileLocalStatic(const Definition *d)
130{
131 const MemberDef *md = toMemberDef(d);
132 return md && md->isStatic() && md->getClassDef()==nullptr;
133}
134
135//--------------------------------------------------------------------------------------
136
137/** Helper class representing the stack of items considered while resolving
138 * the scope.
139 */
141{
142 /** Element in the stack. */
144 {
145 AccessElem(const Definition *d,const FileDef *f,const Definition *i) : scope(d), fileScope(f), item(i) {}
146 AccessElem(const Definition *d,const FileDef *f,const Definition *i,const DString &e) : scope(d), fileScope(f), item(i), expScope(e) {}
151 };
152 public:
153 void push(const Definition *scope,const FileDef *fileScope,const Definition *item)
154 {
155 m_elements.emplace_back(scope,fileScope,item);
156 }
157 void push(const Definition *scope,const FileDef *fileScope,const Definition *item,const DString &expScope)
158 {
159 m_elements.emplace_back(scope,fileScope,item,expScope);
160 }
161 void pop()
162 {
163 if (!m_elements.empty()) m_elements.pop_back();
164 }
165 bool find(const Definition *scope,const FileDef *fileScope, const Definition *item)
166 {
167 auto it = std::find_if(m_elements.begin(),m_elements.end(),
168 [&](const AccessElem &e) { return e.scope==scope && e.fileScope==fileScope && e.item==item; });
169 return it!=m_elements.end();
170 }
171 bool find(const Definition *scope,const FileDef *fileScope, const Definition *item,const DString &expScope)
172 {
173 auto it = std::find_if(m_elements.begin(),m_elements.end(),
174 [&](const AccessElem &e) { return e.scope==scope && e.fileScope==fileScope && e.item==item && e.expScope==expScope; });
175 return it!=m_elements.end();
176 }
177 void clear()
178 {
179 m_elements.clear();
180 }
181
182 private:
183 std::vector<AccessElem> m_elements;
184};
185
186//--------------------------------------------------------------------------------------
187
190using VisitedNamespaces = std::unordered_map<std::string,const Definition *>;
191
192//--------------------------------------------------------------------------------------
193
195{
196 public:
197 Private(const FileDef *f) : m_fileScope(f) {}
198 void reset()
199 {
200 m_resolvedTypedefs.clear();
202 typeDef = nullptr;
204 }
206 {
208 }
209 const FileDef *fileScope() const { return m_fileScope; }
210
212 const MemberDef *typeDef = nullptr;
214
216 LookupCache &cache, // inout
217 VisitedKeys &visitedKeys, // in
218 const Definition *scope, // in
219 const DString &n, // in
220 const MemberDef **pTypeDef, // out
221 DString *pTemplSpec, // out
222 DString *pResolvedType); // out
223
225 LookupCache &cache, // inout
226 VisitedKeys &visitedKeys, // in
227 const Definition *scope, // in
228 const DString &n, // in
229 const DString &args, // in
230 bool checkCV, // in
231 bool insideCode, // in
232 bool onlyLinkable, // in
233 const MemberDef **pTypeDef, // out
234 DString *pTemplSpec, // out
235 DString *pResolvedType); // out
236
237 int isAccessibleFrom( VisitedKeys &visitedKeys, // in
238 AccessStack &accessStack,
239 const Definition *scope,
240 const Definition *item);
241
243 VisitedKeys &visitedKeys, // in
244 VisitedNamespaces &visitedNamespaces,
245 AccessStack &accessStack,
246 const Definition *scope,
247 const Definition *item,
248 const DString &explicitScopePart);
249
250 private:
251 void getResolvedType( LookupCache &cache, // inout
252 VisitedKeys &visitedKeys,
253 const Definition *scope, // in
254 const Definition *d, // in
255 const DString &explicitScopePart, // in
256 const ArgumentList *actTemplParams, // in
257 int &minDistance, // input
258 const ClassDef *&bestMatch, // out
259 const MemberDef *&bestTypedef, // out
260 DString &bestTemplSpec, // out
261 DString &bestResolvedType // out
262 );
263
264 void getResolvedSymbol(VisitedKeys &visitedKeys, // in
265 const Definition *scope, // in
266 const Definition *d, // in
267 const DString &args, // in
268 bool checkCV, // in
269 bool insideCode, // in
270 const DString &explicitScopePart, // in
271 const DString &strippedTemplateParams, // in
272 bool forceCallable, // in
273 int &minDistance, // inout
274 const Definition *&bestMatch, // out
275 const MemberDef *&bestTypedef, // out
276 DString &bestTemplSpec, // out
277 DString &bestResolvedType // out
278 );
279
281 LookupCache &cache, // in
282 VisitedKeys &visitedKeys, // in
283 const Definition *scope, // in
284 const MemberDef *md, // in
285 const MemberDef **pMemType, // out
286 DString *pTemplSpec, // out
287 DString *pResolvedType, // out
288 const ArgumentList *actTemplParams = nullptr
289 );
290
291 const Definition *followPath(VisitedKeys &visitedKeys,
292 const Definition *start,const DString &path);
293
295
297 VisitedNamespaceKeys &visitedNamespaces,
299 const Definition *item,
300 const DString &explicitScopePart="",
301 int level=0);
304 const Definition *item,
305 const DString &explicitScopePart=""
306 );
307 DString substTypedef(VisitedKeys &visitedKeys,
308 const Definition *scope,const DString &name,
309 const MemberDef **pTypeDef=nullptr);
310
312 std::unordered_map<std::string,const MemberDef*> m_resolvedTypedefs;
313};
314
315
316
318 LookupCache &cache,
319 VisitedKeys &visitedKeys,
320 const Definition *scope,
321 const DString &n,
322 const MemberDef **pTypeDef,
323 DString *pTemplSpec,
324 DString *pResolvedType)
325{
326 AUTO_TRACE("scope={} name={}",scope->name(),n);
327 if (n.empty()) return nullptr;
328 DString explicitScopePart;
329 DString strippedTemplateParams;
330 DString scopeName=scope!=Doxygen::globalScope ? scope->name() : DString();
331 DString name=stripTemplateSpecifiersFromScope(n,true,&strippedTemplateParams,scopeName);
332 std::unique_ptr<ArgumentList> actTemplParams;
333 if (!strippedTemplateParams.empty()) // template part that was stripped
334 {
335 actTemplParams = stringToArgumentList(scope->getLanguage(),strippedTemplateParams);
336 }
337
338 int qualifierIndex = computeQualifiedIndex(name);
339 //printf("name=%s qualifierIndex=%d\n",qPrint(name),qualifierIndex);
340 if (qualifierIndex!=-1) // qualified name
341 {
342 // split off the explicit scope part
343 explicitScopePart=name.left(qualifierIndex);
344 // todo: improve namespace alias substitution
345 replaceNamespaceAliases(explicitScopePart);
346 name=name.mid(qualifierIndex+2);
347 }
348
349 if (name.empty())
350 {
351 AUTO_TRACE_EXIT("empty name");
352 return nullptr; // empty name
353 }
354
355 auto &range = Doxygen::symbolMap->find(name);
356 if (range.empty())
357 {
358 AUTO_TRACE_EXIT("no symbol with this name");
359 return nullptr;
360 }
361
362 bool hasUsingStatements =
363 (m_fileScope && (!m_fileScope->getUsedNamespaces().empty() ||
365 );
366 // Since it is often the case that the same name is searched in the same
367 // scope over an over again (especially for the linked source code generation)
368 // we use a cache to collect previous results. This is possible since the
369 // result of a lookup is deterministic. As the key we use the concatenated
370 // scope, the name to search for and the explicit scope prefix. The speedup
371 // achieved by this simple cache can be enormous.
372 size_t scopeNameLen = scope->name().length()+1;
373 size_t nameLen = name.length()+1;
374 size_t explicitPartLen = explicitScopePart.length();
375 size_t fileScopeLen = hasUsingStatements ? 1+m_fileScope->absFilePath().length() : 0;
376
377 // below is a more efficient coding of
378 // DString key=scope->name()+"+"+name+"+"+explicitScopePart+args+typesOnly?'T':'F';
379 DString key(scopeNameLen+nameLen+explicitPartLen+fileScopeLen, DString::ExplicitSize);
380 char *pk=key.rawData();
381 dstrcpy(pk,scope->name().data()); *(pk+scopeNameLen-1)='+';
382 pk+=scopeNameLen;
383 dstrcpy(pk,name.data()); *(pk+nameLen-1)='+';
384 pk+=nameLen;
385 dstrcpy(pk,explicitScopePart.data());
386 pk+=explicitPartLen;
387
388 // if a file scope is given and it contains using statements we should
389 // also use the file part in the key (as a class name can be in
390 // two different namespaces and a using statement in a file can select
391 // one of them).
392 if (hasUsingStatements)
393 {
394 // below is a more efficient coding of
395 // key+="+"+m_fileScope->name();
396 *pk++='+';
398 pk+=fileScopeLen-1;
399 }
400 *pk='\0';
401
402 const ClassDef *bestMatch=nullptr;
403 {
404 if (std::find(visitedKeys.begin(),visitedKeys.end(),key.str())!=std::end(visitedKeys))
405 {
406 // we are already in the middle of find the definition for this key.
407 // avoid recursion
408 AUTO_TRACE_EXIT("recursion detected");
409 return nullptr;
410 }
411 // remember the key
412 visitedKeys.push_back(key.str());
413
414 LookupInfo *pval = cache.find(key.str());
415 AUTO_TRACE_ADD("key={} found={}",key,pval!=nullptr);
416 if (pval)
417 {
418 if (pTemplSpec) *pTemplSpec=pval->templSpec;
419 if (pTypeDef) *pTypeDef=pval->typeDef;
420 if (pResolvedType) *pResolvedType=pval->resolvedType;
421 AUTO_TRACE_EXIT("found cached name={} templSpec={} typeDef={} resolvedTypedef={}",
422 pval->definition?pval->definition->name():DString(),
423 pval->templSpec,
424 pval->typeDef?pval->typeDef->name():DString(),
425 pval->resolvedType);
426
427 return toClassDef(pval->definition);
428 }
429
430 const MemberDef *bestTypedef=nullptr;
431 DString bestTemplSpec;
432 DString bestResolvedType;
433 int minDistance=10000; // init at "infinite"
434
435 for (Definition *d : range)
436 {
437 if (isCodeSymbol(d->definitionType()))
438 {
439 getResolvedType(cache,visitedKeys,scope,d,explicitScopePart,actTemplParams.get(),
440 minDistance,bestMatch,bestTypedef,bestTemplSpec,bestResolvedType);
441 }
442 if (minDistance==0) break; // we can stop reaching if we already reached distance 0
443 }
444
445 if (pTypeDef)
446 {
447 *pTypeDef = bestTypedef;
448 }
449 if (pTemplSpec)
450 {
451 *pTemplSpec = bestTemplSpec;
452 }
453 if (pResolvedType)
454 {
455 *pResolvedType = bestResolvedType;
456 }
457
458 cache.insert(key.str(),LookupInfo(bestMatch,bestTypedef,bestTemplSpec,bestResolvedType));
459 visitedKeys.erase(std::remove(visitedKeys.begin(), visitedKeys.end(), key.str()), visitedKeys.end());
460
461 AUTO_TRACE_EXIT("found name={} templSpec={} typeDef={} resolvedTypedef={}",
462 bestMatch?bestMatch->name():DString(),
463 bestTemplSpec,
464 bestTypedef?bestTypedef->name():DString(),
465 bestResolvedType);
466 }
467 return bestMatch;
468}
469
471 LookupCache &cache,
472 VisitedKeys &visitedKeys,
473 const Definition *scope,
474 const DString &n,
475 const DString &args,
476 bool checkCV,
477 bool insideCode,
478 bool onlyLinkable,
479 const MemberDef **pTypeDef,
480 DString *pTemplSpec,
481 DString *pResolvedType)
482{
483 AUTO_TRACE("scope={} name={} args={} checkCV={} insideCode={}",
484 scope->name(),n,args,checkCV,insideCode);
485 if (n.empty()) return nullptr;
486 DString explicitScopePart;
487 DString strippedTemplateParams;
488 DString scopeName=scope!=Doxygen::globalScope ? scope->name() : DString();
489 DString name=stripTemplateSpecifiersFromScope(n,true,&strippedTemplateParams,scopeName);
490 std::unique_ptr<ArgumentList> actTemplParams;
491 if (!strippedTemplateParams.empty()) // template part that was stripped
492 {
493 actTemplParams = stringToArgumentList(scope->getLanguage(),strippedTemplateParams);
494 }
495
496 int qualifierIndex = computeQualifiedIndex(name);
497 //printf("name=%s qualifierIndex=%d\n",qPrint(name),qualifierIndex);
498 if (qualifierIndex!=-1) // qualified name
499 {
500 // split off the explicit scope part
501 explicitScopePart=name.left(qualifierIndex);
502 // todo: improve namespace alias substitution
503 replaceNamespaceAliases(explicitScopePart);
504 name=name.mid(qualifierIndex+2);
505 }
506 AUTO_TRACE_ADD("qualifierIndex={} name={} explicitScopePart={} strippedTemplateParams={}",
507 qualifierIndex,name,explicitScopePart,strippedTemplateParams);
508
509 if (name.empty())
510 {
511 AUTO_TRACE_EXIT("empty name qualifierIndex={}",qualifierIndex);
512 return nullptr; // empty name
513 }
514
515 size_t i=0;
516 const auto &range1 = Doxygen::symbolMap->find(name);
517 const auto &range = (range1.empty() && (i=name.find('<'))!=DString::npos) ?
518 Doxygen::symbolMap->find(name.left(i)) : range1;
519 if (range.empty())
520 {
521 AUTO_TRACE_ADD("no symbols with name '{}' (including unspecialized)",name);
522 return nullptr;
523 }
524 AUTO_TRACE_ADD("{} -> {} candidates",name,range.size());
525
526 bool hasUsingStatements =
527 (m_fileScope && (!m_fileScope->getUsedNamespaces().empty() ||
528 !m_fileScope->getUsedDefinitions().empty())
529 );
530 // Since it is often the case that the same name is searched in the same
531 // scope over an over again (especially for the linked source code generation)
532 // we use a cache to collect previous results. This is possible since the
533 // result of a lookup is deterministic. As the key we use the concatenated
534 // scope, the name to search for and the explicit scope prefix. The speedup
535 // achieved by this simple cache can be enormous.
536 size_t scopeNameLen = scope!=Doxygen::globalScope ? scope->name().length()+1 : 0;
537 size_t nameLen = name.length()+1;
538 size_t explicitPartLen = explicitScopePart.length();
539 size_t strippedTemplateParamsLen = strippedTemplateParams.length();
540 bool resultDependsOnFileScope = hasUsingStatements ||
541 (m_fileScope && std::any_of(range.begin(),range.end(),isFileLocalStatic));
542 size_t fileScopeLen = resultDependsOnFileScope ? 1+m_fileScope->absFilePath().length() : 0;
543 size_t argsLen = args.length()+1;
544
545 // below is a more efficient coding of
546 // DString key=scope->name()+"+"+name+"+"+explicitScopePart+args+typesOnly?'T':'F';
547 std::string key;
548 key.reserve(scopeNameLen+nameLen+explicitPartLen+strippedTemplateParamsLen+fileScopeLen+argsLen);
549 if (scope!=Doxygen::globalScope)
550 {
551 key+=scope->name().str();
552 key+='+';
553 }
554 key+=name.str();
555 key+='+';
556 key+=explicitScopePart.str();
557 key+=strippedTemplateParams.str();
558
559 // if a file scope is given and the result can depend on it we should
560 // also use the file part in the key:
561 // - a class name can be in two different namespaces and a using
562 // statement in a file can select one of them.
563 // - skipDefinition() only accepts a file-local static from the file scope.
564 if (resultDependsOnFileScope)
565 {
566 // below is a more efficient coding of
567 // key+="+"+m_fileScope->name();
568 key+='+';
569 key+=m_fileScope->absFilePath().str();
570 }
571 if (argsLen>0)
572 {
573 key+='+';
574 key+=args.str();
575 }
576
577 const Definition *bestMatch=nullptr;
578 {
579 if (std::find(visitedKeys.begin(),visitedKeys.end(),key)!=std::end(visitedKeys))
580 {
581 // we are already in the middle of find the definition for this key.
582 // avoid recursion
583 return nullptr;
584 }
585 // remember the key
586 visitedKeys.push_back(key);
587 LookupInfo *pval = cache.find(key);
588 AUTO_TRACE_ADD("key={} found={}",key,pval!=nullptr);
589 if (pval)
590 {
591 if (pTemplSpec) *pTemplSpec=pval->templSpec;
592 if (pTypeDef) *pTypeDef=pval->typeDef;
593 if (pResolvedType) *pResolvedType=pval->resolvedType;
594 AUTO_TRACE_EXIT("found cached name={} templSpec={} typeDef={} resolvedTypedef={}",
595 pval->definition?pval->definition->name():DString(),
596 pval->templSpec,
597 pval->typeDef?pval->typeDef->name():DString(),
598 pval->resolvedType);
599 return pval->definition;
600 }
601
602 const MemberDef *bestTypedef=nullptr;
603 DString bestTemplSpec;
604 DString bestResolvedType;
605 int minDistance=10000; // init at "infinite"
606
607 // helper to skip symbol definitions that should not be considered for lookup
608 auto skipDefinition = [this,&explicitScopePart](const Definition *d) -> bool {
609 if (d->definitionType()==Definition::TypeMember)
610 {
611 const MemberDef *emd = dynamic_cast<const MemberDef *>(d);
612 if (emd &&
613 emd->isEnumValue() &&
614 emd->getEnumScope() &&
615 emd->getEnumScope()->isStrong() &&
616 explicitScopePart.empty())
617 {
618 // skip lookup for strong enum values without explicit scope, see issue #11799
619 return true;
620 }
621 if (emd &&
622 isFileLocalStatic(emd) &&
623 emd->getFileDef()!=m_fileScope) // defined in a different file
624 {
625 // skip lookup for static members that are not in the current file scope
626 return true;
627 }
628 }
629 return false;
630 };
631
632 for (Definition *d : range)
633 {
634 if (isCodeSymbol(d->definitionType()) &&
635 (!onlyLinkable ||
636 d->isLinkable() ||
637 d->isLinkableInProject() ||
638 (d->definitionType()==Definition::TypeFile &&
639 (toFileDef(d))->generateSourceFile()
640 ) // undocumented file that has source code we can link to
641 )
642 )
643 {
644 if (skipDefinition(d)) continue;
645 getResolvedSymbol(visitedKeys,scope,d,args,checkCV,insideCode,explicitScopePart,strippedTemplateParams,false,
646 minDistance,bestMatch,bestTypedef,bestTemplSpec,bestResolvedType);
647 }
648 if (minDistance==0) break; // we can stop reaching if we already reached distance 0
649 }
650
651 // in case we are looking for e.g. func() and the real function is func(int x) we also
652 // accept func(), see example 036 in the test set.
653 if (bestMatch==nullptr && args=="()")
654 {
655 for (Definition *d : range)
656 {
657 if (isCodeSymbol(d->definitionType()))
658 {
659 if (skipDefinition(d)) continue;
660 getResolvedSymbol(visitedKeys,scope,d,DString(),false,insideCode,explicitScopePart,strippedTemplateParams,true,
661 minDistance,bestMatch,bestTypedef,bestTemplSpec,bestResolvedType);
662 }
663 if (minDistance==0) break; // we can stop reaching if we already reached distance 0
664 }
665 }
666
667 if (pTypeDef)
668 {
669 *pTypeDef = bestTypedef;
670 }
671 if (pTemplSpec)
672 {
673 *pTemplSpec = bestTemplSpec;
674 }
675 if (pResolvedType)
676 {
677 *pResolvedType = bestResolvedType;
678 }
679
680 cache.insert(key,LookupInfo(bestMatch,bestTypedef,bestTemplSpec,bestResolvedType));
681 visitedKeys.erase(std::remove(visitedKeys.begin(),visitedKeys.end(),key),visitedKeys.end());
682
683 AUTO_TRACE_EXIT("found name={} templSpec={} typeDef={} resolvedTypedef={}",
684 bestMatch?bestMatch->name():DString(),
685 bestTemplSpec,
686 bestTypedef?bestTypedef->name():DString(),
687 bestResolvedType);
688 }
689 return bestMatch;
690}
691
693 LookupCache &cache, // inout
694 VisitedKeys &visitedKeys, // in
695 const Definition *scope, // in
696 const Definition *d, // in
697 const DString &explicitScopePart, // in
698 const ArgumentList *actTemplParams, // in
699 int &minDistance, // inout
700 const ClassDef *&bestMatch, // out
701 const MemberDef *&bestTypedef, // out
702 DString &bestTemplSpec, // out
703 DString &bestResolvedType // out
704 )
705{
706 AUTO_TRACE("scope={} sym={} explicitScope={}",scope->name(),d->qualifiedName(),explicitScopePart);
707 // only look at classes and members that are enums or typedefs
710 ((toMemberDef(d))->isTypedef() ||
711 (toMemberDef(d))->isEnumerate())
712 )
713 )
714 {
715 VisitedNamespaces visitedNamespaces;
716 AccessStack accessStack;
717 // test accessibility of definition within scope.
718 int distance = isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,
719 accessStack,scope,d,explicitScopePart);
720 AUTO_TRACE_ADD("distance={}",distance);
721 if (distance!=-1) // definition is accessible
722 {
723 // see if we are dealing with a class or a typedef
724 if (d->definitionType()==Definition::TypeClass) // d is a class
725 {
726 const ClassDef *cd = toClassDef(d);
727 //printf("cd=%s\n",qPrint(cd->name()));
728 if (!cd->isTemplateArgument()) // skip classes that
729 // are only there to
730 // represent a template
731 // argument
732 {
733 //printf("is not a templ arg\n");
734 if (distance<minDistance) // found a definition that is "closer"
735 {
736 AUTO_TRACE_ADD("found symbol={} at distance={} minDistance={}",cd->name(),distance,minDistance);
737 minDistance=distance;
738 bestMatch = cd;
739 bestTypedef = nullptr;
740 bestTemplSpec.clear();
741 bestResolvedType = cd->qualifiedName();
742 }
743 else if (distance==minDistance &&
744 m_fileScope && bestMatch &&
745 !m_fileScope->getUsedNamespaces().empty() &&
748 )
749 {
750 // in case the distance is equal it could be that a class X
751 // is defined in a namespace and in the global scope. When searched
752 // in the global scope the distance is 0 in both cases. We have
753 // to choose one of the definitions: we choose the one in the
754 // namespace if the fileScope imports namespaces and the definition
755 // found was in a namespace while the best match so far isn't.
756 // Just a non-perfect heuristic but it could help in some situations
757 // (kdecore code is an example).
758 AUTO_TRACE_ADD("found symbol={} at distance={} minDistance={}",cd->name(),distance,minDistance);
759 minDistance=distance;
760 bestMatch = cd;
761 bestTypedef = nullptr;
762 bestTemplSpec.clear();
763 bestResolvedType = cd->qualifiedName();
764 }
765 }
766 else
767 {
768 //printf(" is a template argument!\n");
769 }
770 }
772 {
773 const MemberDef *md = toMemberDef(d);
774 AUTO_TRACE_ADD("member={} isTypeDef={}",md->name(),md->isTypedef());
775 if (md->isTypedef()) // d is a typedef
776 {
777 DString args=md->argsString();
778 if (args.empty()) // do not expand "typedef t a[4];"
779 {
780 // we found a symbol at this distance, but if it didn't
781 // resolve to a class, we still have to make sure that
782 // something at a greater distance does not match, since
783 // that symbol is hidden by this one.
784 if (distance<minDistance)
785 {
786 DString spec;
787 DString type;
788 minDistance=distance;
789 const MemberDef *enumType = nullptr;
790 const ClassDef *cd = newResolveTypedef(cache,visitedKeys,scope,md,&enumType,&spec,&type,actTemplParams);
791 if (cd) // type resolves to a class
792 {
793 AUTO_TRACE_ADD("found symbol={} at distance={} minDistance={}",cd->name(),distance,minDistance);
794 bestMatch = cd;
795 bestTypedef = md;
796 bestTemplSpec = spec;
797 bestResolvedType = type;
798 }
799 else if (enumType) // type resolves to a member type
800 {
801 AUTO_TRACE_ADD("found enum");
802 bestMatch = nullptr;
803 bestTypedef = enumType;
804 bestTemplSpec = "";
805 bestResolvedType = enumType->qualifiedName();
806 }
807 else if (md->isReference()) // external reference
808 {
809 AUTO_TRACE_ADD("found external reference");
810 bestMatch = nullptr;
811 bestTypedef = md;
812 bestTemplSpec = spec;
813 bestResolvedType = type;
814 }
815 else
816 {
817 AUTO_TRACE_ADD("no match");
818 bestMatch = nullptr;
819 bestTypedef = md;
820 bestTemplSpec.clear();
821 bestResolvedType.clear();
822 }
823 }
824 else
825 {
826 //printf(" not the best match %d min=%d\n",distance,minDistance);
827 }
828 }
829 else
830 {
831 AUTO_TRACE_ADD("skipping complex typedef");
832 }
833 }
834 else if (md->isEnumerate())
835 {
836 if (distance<minDistance)
837 {
838 AUTO_TRACE_ADD("found enum={} at distance={} minDistance={}",md->name(),distance,minDistance);
839 minDistance=distance;
840 bestMatch = nullptr;
841 bestTypedef = md;
842 bestTemplSpec = "";
843 bestResolvedType = md->qualifiedName();
844 }
845 }
846 }
847 } // if definition accessible
848 else
849 {
850 AUTO_TRACE_ADD("not accessible");
851 }
852 } // if definition is a class or member
853 AUTO_TRACE_EXIT("bestMatch sym={} type={}",
854 bestMatch?bestMatch->name():DString("<none>"),bestResolvedType);
855}
856
857
859 VisitedKeys &visitedKeys, // in
860 const Definition *scope, // in
861 const Definition *d, // in
862 const DString &args, // in
863 bool checkCV, // in
864 bool insideCode, // in
865 const DString &explicitScopePart, // in
866 const DString &strippedTemplateParams, // in
867 bool forceCallable, // in
868 int &minDistance, // inout
869 const Definition *&bestMatch, // out
870 const MemberDef *&bestTypedef, // out
871 DString &bestTemplSpec, // out
872 DString &bestResolvedType // out
873 )
874{
875 AUTO_TRACE("scope={} sym={}",scope->name(),d->qualifiedName());
876 // only look at classes and members that are enums or typedefs
877 VisitedNamespaces visitedNamespaces;
878 AccessStack accessStack;
879 // test accessibility of definition within scope.
880 int distance = isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope,d,explicitScopePart+strippedTemplateParams);
881 if (distance==-1 && !strippedTemplateParams.empty())
882 {
883 distance = isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope,d,explicitScopePart);
884 }
885 AUTO_TRACE_ADD("distance={}",distance);
886 if (distance!=-1) // definition is accessible
887 {
888 // see if we are dealing with a class or a typedef
889 if (args.empty() && !forceCallable && d->definitionType()==Definition::TypeClass) // d is a class
890 {
891 const ClassDef *cd = toClassDef(d);
892 if (!cd->isTemplateArgument()) // skip classes that
893 // are only there to
894 // represent a template
895 // argument
896 {
897 if (distance<minDistance) // found a definition that is "closer"
898 {
899 AUTO_TRACE_ADD("found symbol={} at distance={} minDistance={}",d->name(),distance,minDistance);
900 minDistance=distance;
901 bestMatch = d;
902 bestTypedef = nullptr;
903 bestTemplSpec.clear();
904 bestResolvedType = cd->qualifiedName();
905 }
906 else if (distance==minDistance &&
907 m_fileScope && bestMatch &&
908 !m_fileScope->getUsedNamespaces().empty() &&
911 )
912 {
913 // in case the distance is equal it could be that a class X
914 // is defined in a namespace and in the global scope. When searched
915 // in the global scope the distance is 0 in both cases. We have
916 // to choose one of the definitions: we choose the one in the
917 // namespace if the fileScope imports namespaces and the definition
918 // found was in a namespace while the best match so far isn't.
919 // Just a non-perfect heuristic but it could help in some situations
920 // (kdecore code is an example).
921 AUTO_TRACE_ADD("found symbol={} at distance={} minDistance={}",d->name(),distance,minDistance);
922 minDistance=distance;
923 bestMatch = d;
924 bestTypedef = nullptr;
925 bestTemplSpec.clear();
926 bestResolvedType = cd->qualifiedName();
927 }
928 }
929 else
930 {
931 AUTO_TRACE_ADD("class with template arguments");
932 }
933 }
935 {
936 const MemberDef *md = toMemberDef(d);
937
938 bool match = true;
939 AUTO_TRACE_ADD("member={} args={} isCallable()={}",md->name(),argListToString(md->argumentList()),md->isCallable());
940 if (md->isCallable() && !args.empty())
941 {
942 DString actArgs;
943 if (md->isArtificial() && md->formalTemplateArguments()) // for members of an instantiated template we need to replace
944 // the formal arguments by the actual ones before matching
945 // See issue #10640
946 {
948 }
949 else
950 {
951 actArgs = args;
952 }
953 std::unique_ptr<ArgumentList> argList = stringToArgumentList(md->getLanguage(),actArgs);
954 const ArgumentList &mdAl = md->argumentList();
955 match = matchArguments2(md->getOuterScope(),md->getFileDef(),md->typeString(),&mdAl,
956 scope, md->getFileDef(),md->typeString(),argList.get(),
957 checkCV,md->getLanguage());
958 AUTO_TRACE_ADD("match={}",match);
959 }
960
961 if (match && distance<minDistance)
962 {
963 AUTO_TRACE_ADD("found symbol={} at distance={} minDistance={}",md->name(),distance,minDistance);
964 minDistance=distance;
965 bestMatch = md;
966 bestTypedef = md;
967 bestTemplSpec = "";
968 bestResolvedType = md->qualifiedName();
969 }
970 }
974 {
975 if (distance<minDistance) // found a definition that is "closer"
976 {
977 AUTO_TRACE_ADD("found symbol={} at distance={} minDistance={}",d->name(),distance,minDistance);
978 minDistance=distance;
979 bestMatch = d;
980 bestTypedef = nullptr;
981 bestTemplSpec.clear();
982 bestResolvedType.clear();
983 }
984 }
985 } // if definition accessible
986 else
987 {
988 AUTO_TRACE_ADD("not accessible");
989 }
990 AUTO_TRACE_EXIT("bestMatch sym={} distance={}",
991 bestMatch?bestMatch->name():DString("<none>"),bestResolvedType);
992}
993
994
996 LookupCache &cache, // inout
997 VisitedKeys &visitedKeys, // in
998 const Definition * /* scope */, // in
999 const MemberDef *md, // in
1000 const MemberDef **pMemType, // out
1001 DString *pTemplSpec, // out
1002 DString *pResolvedType, // out
1003 const ArgumentList *actTemplParams) // in
1004{
1005 AUTO_TRACE("md={}",md->qualifiedName());
1006 std::lock_guard lock(g_cacheTypedefMutex);
1007 bool isCached = md->isTypedefValCached(); // value already cached
1008 if (isCached)
1009 {
1010 AUTO_TRACE_EXIT("cached typedef={} resolvedTypedef={} templSpec={}",
1014
1015 if (pTemplSpec) *pTemplSpec = md->getCachedTypedefTemplSpec();
1016 if (pResolvedType) *pResolvedType = md->getCachedResolvedTypedef();
1017 return md->getCachedTypedefVal();
1018 }
1019
1020 DString qname = md->qualifiedName();
1021 if (m_resolvedTypedefs.find(qname.str())!=m_resolvedTypedefs.end())
1022 {
1023 AUTO_TRACE_EXIT("already being processed");
1024 return nullptr; // typedef already done
1025 }
1026
1027 auto typedef_it = m_resolvedTypedefs.emplace(qname.str(),md).first; // put on the trace list
1028
1029 const ClassDef *typeClass = md->getClassDef();
1030 DString type = md->typeString(); // get the "value" of the typedef
1031 if (typeClass && typeClass->isTemplate() &&
1032 actTemplParams && !actTemplParams->empty())
1033 {
1035 typeClass->templateArguments(),actTemplParams);
1036 }
1037 DString typedefValue = type;
1038 int tl=static_cast<int>(type.length());
1039 int ip=tl-1; // remove * and & at the end
1040 while (ip>=0 && (type.at(ip)=='*' || type.at(ip)=='&' || type.at(ip)==' '))
1041 {
1042 ip--;
1043 }
1044 type=type.left(ip+1);
1045 type.stripPrefix("const "); // strip leading "const"
1046 type.stripPrefix("volatile "); // strip leading "volatile"
1047 type.stripPrefix("struct "); // strip leading "struct"
1048 type.stripPrefix("record "); // strip leading "record"
1049 type.stripPrefix("union "); // strip leading "union"
1050 int sp=0;
1051 tl=static_cast<int>(type.length()); // length may have been changed
1052 while (sp<tl && type.at(sp)==' ') sp++;
1053 const MemberDef *memTypeDef = nullptr;
1054 const ClassDef *result = getResolvedTypeRec(cache,visitedKeys,md->getOuterScope(),type,
1055 &memTypeDef,nullptr,pResolvedType);
1056 // if type is a typedef then return what it resolves to.
1057 if (memTypeDef && memTypeDef->isTypedef())
1058 {
1059 AUTO_TRACE_ADD("resolving typedef");
1060 result=newResolveTypedef(cache,visitedKeys,m_fileScope,memTypeDef,pMemType,pTemplSpec,nullptr);
1061 goto done;
1062 }
1063 else if (memTypeDef && memTypeDef->isEnumerate() && pMemType)
1064 {
1065 *pMemType = memTypeDef;
1066 }
1067
1068 if (result==nullptr)
1069 {
1070 // try unspecialized version if type is template
1071 size_t si = type.rfind("::");
1072 size_t i = type.find('<');
1073 if (si==DString::npos && i!=DString::npos) // typedef of a template => try the unspecialized version
1074 {
1075 if (pTemplSpec) *pTemplSpec = type.mid(i);
1076 result = getResolvedTypeRec(cache,visitedKeys,md->getOuterScope(),type.left(i),nullptr,nullptr,pResolvedType);
1077 }
1078 else if (si!=DString::npos) // A::B
1079 {
1080 i=type.find('<',si);
1081 if (i==DString::npos) // Something like A<T>::B => lookup A::B
1082 {
1083 i=type.length();
1084 }
1085 else // Something like A<T>::B<S> => lookup A::B, spec=<S>
1086 {
1087 if (pTemplSpec) *pTemplSpec = type.mid(i);
1088 }
1089 result = getResolvedTypeRec(cache,visitedKeys,md->getOuterScope(),
1090 stripTemplateSpecifiersFromScope(type.left(i),false),nullptr,nullptr,pResolvedType);
1091 }
1092 }
1093
1094done:
1095 if (pResolvedType)
1096 {
1097 if (result && result->definitionType()==Definition::TypeClass)
1098 {
1099 *pResolvedType = result->qualifiedName();
1100 if (sp>0) pResolvedType->prepend(typedefValue.left(sp));
1101 if (ip<tl-1) pResolvedType->append(typedefValue.right(tl-ip-1));
1102 }
1103 else
1104 {
1105 *pResolvedType = typedefValue;
1106 }
1107 }
1108
1109 // remember computed value for next time
1110 if (result && result->getDefFileName()!="<code>")
1111 // this check is needed to prevent that temporary classes that are
1112 // introduced while parsing code fragments are being cached here.
1113 {
1114 AUTO_TRACE_ADD("caching typedef relation {}->{}",md->name(),result->name());
1115 MemberDefMutable *mdm = toMemberDefMutable(const_cast<MemberDef*>(md));
1116 if (mdm)
1117 {
1118 mdm->cacheTypedefVal(result,
1119 pTemplSpec ? *pTemplSpec : DString(),
1120 pResolvedType ? *pResolvedType : DString()
1121 );
1122 }
1123 }
1124
1125 m_resolvedTypedefs.erase(typedef_it); // remove from the trace list
1126
1127 AUTO_TRACE_EXIT("result={} pTemplSpec={} pResolvedType={}",
1128 result ? result->name() : DString(),
1129 pTemplSpec ? *pTemplSpec : "<nullptr>",
1130 pResolvedType ? *pResolvedType : "<nullptr>"
1131 );
1132 return result;
1133}
1134
1136 VisitedKeys &visitedKeys,
1137 VisitedNamespaces &visitedNamespaces,
1138 AccessStack &accessStack,
1139 const Definition *scope,
1140 const Definition *item,
1141 const DString &explicitScopePart)
1142{
1143 int result=0; // assume we found it
1144 AUTO_TRACE("scope={} item={} explictScopePart={}",
1145 scope?scope->name():DString(), item?item->name():DString(), explicitScopePart);
1146 if (explicitScopePart.empty())
1147 {
1148 // handle degenerate case where there is no explicit scope.
1149 result = isAccessibleFrom(visitedKeys,accessStack,scope,item);
1150 AUTO_TRACE_EXIT("result={}",result);
1151 return result;
1152 }
1153
1154 if (accessStack.find(scope,m_fileScope,item,explicitScopePart))
1155 {
1156 AUTO_TRACE_EXIT("already found");
1157 return -1;
1158 }
1159 accessStack.push(scope,m_fileScope,item,explicitScopePart);
1160
1161 const Definition *newScope = followPath(visitedKeys,scope,explicitScopePart);
1162 if (newScope) // explicitScope is inside scope => newScope is the result
1163 {
1164 Definition *itemScope = item->getOuterScope();
1165
1166 AUTO_TRACE_ADD("scope traversal successful newScope={}",newScope->name());
1167
1168 bool nestedClassInsideBaseClass =
1169 itemScope &&
1170 itemScope->definitionType()==Definition::TypeClass &&
1172 (toClassDef(newScope))->isBaseClass(toClassDef(itemScope),true);
1173
1174 bool enumValueWithinEnum =
1176 toMemberDef(item)->isEnumValue() &&
1177 toMemberDef(item)->getEnumScope()==newScope;
1178
1179 if (itemScope==newScope) // exact match of scopes => distance==0
1180 {
1181 AUTO_TRACE_ADD("found scope match");
1182 }
1183 else if (nestedClassInsideBaseClass)
1184 {
1185 // inheritance is also ok. Example: looking for B::I, where
1186 // class A { public: class I {} };
1187 // class B : public A {}
1188 // but looking for B::I, where
1189 // class A { public: class I {} };
1190 // class B { public: class I {} };
1191 // will find A::I, so we still prefer a direct match and give this one a distance of 1
1192 result=1;
1193
1194 AUTO_TRACE_ADD("{} is a bass class of {}",scope->name(),newScope->name());
1195 }
1196 else if (enumValueWithinEnum)
1197 {
1198 AUTO_TRACE_ADD("found enum value inside enum");
1199 result=1;
1200 }
1201 else
1202 {
1203 int i=-1;
1205 {
1206 visitedNamespaces.emplace(newScope->name().str(),newScope);
1207 // this part deals with the case where item is a class
1208 // A::B::C but is explicit referenced as A::C, where B is imported
1209 // in A via a using directive.
1210 //printf("newScope is a namespace: %s!\n",qPrint(newScope->name()));
1211 const NamespaceDef *nscope = toNamespaceDef(newScope);
1212 for (const auto &ud : nscope->getUsedDefinitions())
1213 {
1214 if (ud==item)
1215 {
1216 AUTO_TRACE_ADD("found in used definition {}",ud->name());
1217 goto done;
1218 }
1219 }
1220 for (const auto &nd : nscope->getUsedNamespaces())
1221 {
1222 if (visitedNamespaces.find(nd->name().str())==visitedNamespaces.end())
1223 {
1224 i = isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope,item,nd->name());
1225 if (i!=-1)
1226 {
1227 AUTO_TRACE_ADD("found in used namespace {}",nd->name());
1228 goto done;
1229 }
1230 }
1231 }
1232 }
1233#if 0 // this caused problems resolving A::f() in the docs when there was a A::f(int) but also a
1234 // global function f() that exactly matched the argument list.
1235 else if (isParentScope(scope,newScope) && newScope->definitionType()==Definition::TypeClass)
1236 {
1237 // if we a look for a type B and have explicit scope A, then it is also fine if B
1238 // is found at the global scope.
1239 result = 1;
1240 goto done;
1241 }
1242#endif
1243 // repeat for the parent scope
1244 if (scope!=Doxygen::globalScope)
1245 {
1246 i = isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope->getOuterScope(),item,explicitScopePart);
1247 }
1248 result = (i==-1) ? -1 : i+2;
1249 }
1250 }
1251 else // failed to resolve explicitScope
1252 {
1253 AUTO_TRACE_ADD("failed to resolve explicitScope");
1255 {
1256 const NamespaceDef *nscope = toNamespaceDef(scope);
1257 VisitedNamespaceKeys locVisitedNamespaceKeys;
1258 if (accessibleViaUsingNamespace(visitedKeys,locVisitedNamespaceKeys,nscope->getUsedNamespaces(),item,explicitScopePart))
1259 {
1260 AUTO_TRACE_ADD("found in used class");
1261 goto done;
1262 }
1263 }
1264 if (scope==Doxygen::globalScope)
1265 {
1266 if (m_fileScope)
1267 {
1268 VisitedNamespaceKeys locVisitedNamespaceKeys;
1269 if (accessibleViaUsingNamespace(visitedKeys,locVisitedNamespaceKeys,m_fileScope->getUsedNamespaces(),item,explicitScopePart))
1270 {
1271 AUTO_TRACE_ADD("found in used namespace");
1272 goto done;
1273 }
1274 }
1275 AUTO_TRACE_ADD("not found in this scope");
1276 result=-1;
1277 }
1278 else // continue by looking into the parent scope
1279 {
1280 int i=isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope->getOuterScope(),item,explicitScopePart);
1281 result= (i==-1) ? -1 : i+2;
1282 }
1283 }
1284
1285done:
1286 AUTO_TRACE_EXIT("result={}",result);
1287 accessStack.pop();
1288 return result;
1289}
1290
1292 const Definition *start,const DString &path)
1293{
1294 AUTO_TRACE("start={},path={}",start?start->name():DString(), path);
1295 int is=0,ps=0,l=0;
1296
1297 const Definition *current=start;
1298 // for each part of the explicit scope
1299 while ((is=getScopeFragment(path,ps,&l))!=-1)
1300 {
1301 // try to resolve the part if it is a typedef
1302 const MemberDef *memTypeDef=nullptr;
1303 DString qualScopePart = substTypedef(visitedKeys,current,path.mid(is,l),&memTypeDef);
1304 AUTO_TRACE_ADD("qualScopePart={} memTypeDef={}",qualScopePart,memTypeDef?memTypeDef->name():"");
1305 const Definition *next = nullptr;
1306 if (memTypeDef)
1307 {
1308 const ClassDef *type = newResolveTypedef(getTypeLookupCache(),visitedKeys,m_fileScope,memTypeDef,nullptr,nullptr,nullptr);
1309 if (type)
1310 {
1311 AUTO_TRACE_EXIT("type={}",type->name());
1312 return type;
1313 }
1314 }
1315 else if (m_fileScope)
1316 {
1317 next = endOfPathIsUsedClass(m_fileScope->getUsedDefinitions(),qualScopePart);
1318 }
1319 if (next==nullptr)
1320 {
1321 next = current->findInnerCompound(qualScopePart);
1322 }
1323 AUTO_TRACE_ADD("Looking for {} inside {} result={}",
1324 qualScopePart, current->name(), next?next->name():DString());
1325 if (next==nullptr)
1326 {
1327 next = current->findInnerCompound(qualScopePart+"-p");
1328 }
1329 if (current->definitionType()==Definition::TypeClass)
1330 {
1331 const MemberDef *classMember = toClassDef(current)->getMemberByName(qualScopePart);
1332 if (classMember && classMember->isEnumerate())
1333 {
1334 next = classMember;
1335 }
1336 }
1337 else if (current!=Doxygen::globalScope && current->definitionType()==Definition::TypeNamespace)
1338 {
1339 const MemberDef *namespaceMember = toNamespaceDef(current)->getMemberByName(qualScopePart);
1340 if (namespaceMember && namespaceMember->isEnumerate())
1341 {
1342 next = namespaceMember;
1343 }
1344 }
1345 else if (current==Doxygen::globalScope || current->definitionType()==Definition::TypeFile)
1346 {
1347 auto &range = Doxygen::symbolMap->find(qualScopePart);
1348 for (Definition *def : range)
1349 {
1350 const Definition *outerScope = def->getOuterScope();
1351 if (
1352 (outerScope==Doxygen::globalScope || // global scope or
1353 (outerScope && // anonymous namespace in the global scope
1354 outerScope->name().startsWith("anonymous_namespace{") &&
1355 outerScope->getOuterScope()==Doxygen::globalScope
1356 )
1357 ) &&
1358 (def->definitionType()==Definition::TypeClass ||
1359 def->definitionType()==Definition::TypeMember ||
1360 def->definitionType()==Definition::TypeNamespace
1361 )
1362 )
1363 {
1364 next=def;
1365 break;
1366 }
1367 }
1368 }
1369 if (next==nullptr) // failed to follow the path
1370 {
1372 {
1373 next = endOfPathIsUsedClass(
1374 (toNamespaceDef(current))->getUsedDefinitions(),qualScopePart);
1375 }
1376 else if (current->definitionType()==Definition::TypeFile)
1377 {
1378 next = endOfPathIsUsedClass(
1379 (toFileDef(current))->getUsedDefinitions(),qualScopePart);
1380 }
1381 current = next;
1382 if (current==nullptr) break;
1383 }
1384 else // continue to follow scope
1385 {
1386 current = next;
1387 AUTO_TRACE_ADD("current={}",current->name());
1388 }
1389 ps=is+l;
1390 }
1391
1392 AUTO_TRACE_EXIT("result={}",current?current->name():DString());
1393 return current; // path could be followed
1394}
1395
1397{
1398 for (const auto &d : dl)
1399 {
1400 if (d->localName()==localName)
1401 {
1402 return d;
1403 }
1404 }
1405 return nullptr;
1406}
1407
1409 VisitedKeys &visitedKeys,
1410 VisitedNamespaceKeys &visitedNamespaces,
1412 const Definition *item,
1413 const DString &explicitScopePart,
1414 int level)
1415{
1416 AUTO_TRACE("item={} explicitScopePart={} level={}",item?item->name():DString(), explicitScopePart, level);
1417 for (const auto &und : nl) // check used namespaces for the class
1418 {
1419 AUTO_TRACE_ADD("trying via used namespace '{}'",und->name());
1420 const Definition *sc = explicitScopePart.empty() ? und : followPath(visitedKeys,und,explicitScopePart);
1421 if (sc && item->getOuterScope()==sc)
1422 {
1423 AUTO_TRACE_EXIT("true");
1424 return true;
1425 }
1426 if (item->getLanguage()==SrcLangExt::Cpp)
1427 {
1428 DString key=und->qualifiedName();
1429 if (!und->getUsedNamespaces().empty() && std::find(visitedNamespaces.begin(),visitedNamespaces.end(),key.str())==std::end(visitedNamespaces))
1430 {
1431 visitedNamespaces.push_back(key.str());
1432 if (accessibleViaUsingNamespace(visitedKeys,visitedNamespaces,und->getUsedNamespaces(),item,explicitScopePart,level+1))
1433 {
1434 AUTO_TRACE_EXIT("true");
1435 return true;
1436 }
1437
1438 }
1439 }
1440 }
1441 AUTO_TRACE_EXIT("false");
1442 return false;
1443}
1444
1445
1448 const Definition *item,
1449 const DString &explicitScopePart)
1450{
1451 AUTO_TRACE("item={} explicitScopePart={}",item?item->name():DString(), explicitScopePart);
1452 for (const auto &ud : dl)
1453 {
1454 AUTO_TRACE_ADD("trying via used definition '{}'",ud->name());
1455 const Definition *sc = explicitScopePart.empty() ? ud : followPath(visitedKeys,ud,explicitScopePart);
1456 if (sc && sc==item)
1457 {
1458 AUTO_TRACE_EXIT("true");
1459 return true;
1460 }
1461 }
1462 AUTO_TRACE_EXIT("false");
1463 return false;
1464}
1465
1467 AccessStack &accessStack,
1468 const Definition *scope,
1469 const Definition *item)
1470{
1471 AUTO_TRACE("scope={} item={} item.definitionType={}",
1472 scope?scope->name():DString(), item?item->name():DString(),
1473 item?(int)item->definitionType():-1);
1474
1475 if (accessStack.find(scope,m_fileScope,item))
1476 {
1477 AUTO_TRACE_EXIT("already processed!");
1478 return -1;
1479 }
1480 accessStack.push(scope,m_fileScope,item);
1481
1482 int result=0; // assume we found it
1483 int i=0;
1484
1485 const Definition *itemScope=item->getOuterScope();
1486 bool itemIsMember = item->definitionType()==Definition::TypeMember;
1487 bool itemIsClass = item->definitionType()==Definition::TypeClass;
1488
1489 // if item is a global member and scope points to a specific file
1490 // we adjust the scope so the file gets preference over members with the same name in
1491 // other files.
1492 if ((itemIsMember || itemIsClass) &&
1493 (itemScope==Doxygen::globalScope || // global
1494 (itemScope && itemScope->name().startsWith("anonymous_namespace{")) // member of an anonymous namespace
1495 ) &&
1497 {
1498 if (itemIsMember)
1499 {
1500 itemScope = toMemberDef(item)->getFileDef();
1501 }
1502 else if (itemIsClass)
1503 {
1504 itemScope = toClassDef(item)->getFileDef();
1505 }
1506 AUTO_TRACE_ADD("adjusting scope to {}",itemScope?itemScope->name():DString());
1507 }
1508
1509 const ClassDef *classScope = scope->definitionType()==Definition::TypeClass ? toClassDef(scope) : nullptr;
1510
1511 bool memberAccessibleFromScope =
1512 (itemIsMember && // a member
1513 itemScope && itemScope->definitionType()==Definition::TypeClass && // of a class
1514 classScope && classScope->isAccessibleMember(toMemberDef(item)) // accessible from scope
1515 );
1516 bool nestedClassInsideBaseClass =
1517 (itemIsClass && // a nested class
1518 itemScope && itemScope->definitionType()==Definition::TypeClass && // inside a base
1519 classScope && classScope->isBaseClass(toClassDef(itemScope),true) // class of scope
1520 );
1521 int distanceToBaseClass=0;
1522 bool baseClassOfScope =
1523 (itemIsClass && item!=scope && // a base class of scope
1524 item->getLanguage()==SrcLangExt::Cpp && // can be named in C++
1525 classScope && // without its own scope,
1526 bareName(item)!=bareName(classScope) && // unless scope has the same name
1527 (distanceToBaseClass=classScope->isBaseClass(toClassDef(item),true))>0
1528 );
1529 bool enumValueOfStrongEnum =
1530 (itemIsMember &&
1531 toMemberDef(item)->isStrongEnumValue() &&
1533 toMemberDef(scope)->isEnumerate() &&
1534 scope==toMemberDef(item)->getEnumScope()
1535 );
1536
1537 if (itemScope==scope || memberAccessibleFromScope || nestedClassInsideBaseClass || baseClassOfScope || enumValueOfStrongEnum)
1538 {
1539 AUTO_TRACE_ADD("memberAccessibleFromScope={} nestedClassInsideBaseClass={} baseClassOfScope={} enumValueOfStrongEnum={}",
1540 memberAccessibleFromScope, nestedClassInsideBaseClass, baseClassOfScope, enumValueOfStrongEnum);
1541 int distanceToBase=0;
1542 if (nestedClassInsideBaseClass)
1543 {
1544 result++; // penalty for base class to prevent
1545 // this is preferred over nested class in this class
1546 // see bug 686956
1547 }
1548 else if (memberAccessibleFromScope &&
1549 itemScope &&
1550 itemScope->definitionType()==Definition::TypeClass &&
1552 (distanceToBase=toClassDef(scope)->isBaseClass(toClassDef(itemScope),true))>0
1553 )
1554 {
1555 result+=distanceToBase; // penalty if member is accessible via a base class
1556 }
1557 else if (baseClassOfScope)
1558 {
1559 result+=distanceToBaseClass; // penalty if class is accessible as a base class of scope
1560 }
1561 }
1562 else if (scope==Doxygen::globalScope)
1563 {
1564 if (itemScope &&
1566 toNamespaceDef(itemScope)->isAnonymous() &&
1567 itemScope->getOuterScope()==Doxygen::globalScope)
1568 { // item is in an anonymous namespace in the global scope and we are
1569 // looking in the global scope
1570 AUTO_TRACE_ADD("found in anonymous namespace");
1571 result++;
1572 goto done;
1573 }
1574 if (m_fileScope)
1575 {
1576 if (accessibleViaUsingDefinition(visitedKeys,m_fileScope->getUsedDefinitions(),item))
1577 {
1578 AUTO_TRACE_ADD("found via used class");
1579 goto done;
1580 }
1581 VisitedNamespaceKeys visitedNamespaceKeys;
1582 if (accessibleViaUsingNamespace(visitedKeys,visitedNamespaceKeys,m_fileScope->getUsedNamespaces(),item))
1583 {
1584 AUTO_TRACE_ADD("found via used namespace");
1585 goto done;
1586 }
1587 }
1588 AUTO_TRACE_ADD("reached global scope");
1589 result=-1; // not found in path to globalScope
1590 }
1591 else // keep searching
1592 {
1593 // check if scope is a namespace, which is using other classes and namespaces
1595 {
1596 const NamespaceDef *nscope = toNamespaceDef(scope);
1597 if (accessibleViaUsingDefinition(visitedKeys,nscope->getUsedDefinitions(),item))
1598 {
1599 AUTO_TRACE_ADD("found via used class");
1600 goto done;
1601 }
1602 VisitedNamespaceKeys visitedNamespaceKeys;
1603 if (accessibleViaUsingNamespace(visitedKeys,visitedNamespaceKeys,nscope->getUsedNamespaces(),item,DString()))
1604 {
1605 AUTO_TRACE_ADD("found via used namespace");
1606 goto done;
1607 }
1608 }
1609 else if (scope->definitionType()==Definition::TypeFile)
1610 {
1611 const FileDef *nfile = toFileDef(scope);
1612 if (accessibleViaUsingDefinition(visitedKeys,nfile->getUsedDefinitions(),item))
1613 {
1614 AUTO_TRACE_ADD("found via used class");
1615 goto done;
1616 }
1617 VisitedNamespaceKeys visitedNamespaceKeys;
1618 if (accessibleViaUsingNamespace(visitedKeys,visitedNamespaceKeys,nfile->getUsedNamespaces(),item,DString()))
1619 {
1620 AUTO_TRACE_ADD("found via used namespace");
1621 goto done;
1622 }
1623 }
1624 // repeat for the parent scope
1625 const Definition *parentScope = scope->getOuterScope();
1626 if (parentScope==Doxygen::globalScope)
1627 {
1629 {
1630 const FileDef *fd = toClassDef(scope)->getFileDef();
1631 if (fd)
1632 {
1633 parentScope = fd;
1634 }
1635 }
1636 }
1637 i=isAccessibleFrom(visitedKeys,accessStack,parentScope,item);
1638 result= (i==-1) ? -1 : i+2;
1639 }
1640done:
1641 AUTO_TRACE_EXIT("result={}",result);
1642 accessStack.pop();
1643 return result;
1644}
1645
1647 VisitedKeys &visitedKeys,
1648 const Definition *scope,const DString &name,
1649 const MemberDef **pTypeDef)
1650{
1651 AUTO_TRACE("scope={} name={}",scope?scope->name():DString(), name);
1652 DString result=name;
1653 if (name.empty()) return result;
1654
1655 auto &range = Doxygen::symbolMap->find(name);
1656 if (range.empty())
1657 return result; // no matches
1658
1659 MemberDef *bestMatch=nullptr;
1660 int minDistance=10000; // init at "infinite"
1661
1662 std::string key;
1663 const int maxAddrSize = 20;
1664 char ptr_str[maxAddrSize];
1665 int num = snprintf(ptr_str,maxAddrSize,"%p:",(void *)scope);
1666 ASSERT(num>0);
1667 key.reserve(num+name.length()+1);
1668 key+=ptr_str;
1669 key+=name.str();
1670 {
1671 auto it = g_substMap.find(key);
1672 if (it!=g_substMap.end())
1673 {
1674 if (pTypeDef) *pTypeDef = it->second.second;
1675 return it->second.first;
1676 }
1677 }
1678
1679 for (Definition *d : range)
1680 {
1681 // only look at members
1682 if (d->definitionType()==Definition::TypeMember)
1683 {
1684 // that are also typedefs
1685 MemberDef *md = toMemberDef(d);
1686 if (md->isTypedef()) // d is a typedef
1687 {
1688 VisitedNamespaces visitedNamespaces;
1689 AccessStack accessStack;
1690 // test accessibility of typedef within scope.
1691 int distance = isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope,d,"");
1692 if (distance!=-1 && distance<minDistance)
1693 // definition is accessible and a better match
1694 {
1695 minDistance=distance;
1696 bestMatch = md;
1697 }
1698 }
1699 }
1700 }
1701
1702 if (bestMatch)
1703 {
1704 result = bestMatch->typeString();
1705 if (pTypeDef) *pTypeDef=bestMatch;
1706 }
1707
1708 // cache the result of the computation to give a faster answers next time, especially relevant
1709 // if `range` has many arguments (i.e. there are many symbols with the same name in different contexts)
1710 {
1711 g_substMap.emplace(key,std::make_pair(result,bestMatch));
1712 }
1713
1714 AUTO_TRACE_EXIT("result={}",result);
1715 return result;
1716}
1717
1718//----------------------------------------------------------------------------------------------
1719
1720
1722 : p(std::make_unique<Private>(fileScope))
1723{
1724}
1725
1729
1730
1732 const DString &name,
1733 bool mayBeUnlinkable,
1734 bool mayBeHidden)
1735{
1736 AUTO_TRACE("scope={} name={} mayBeUnlinkable={} mayBeHidden={}",
1737 scope?scope->name():DString(), name, mayBeUnlinkable, mayBeHidden);
1738 p->reset();
1739
1740 auto lang = scope ? scope->getLanguage() :
1741 p->fileScope() ? p->fileScope()->getLanguage() :
1742 SrcLangExt::Cpp; // fallback to C++
1743
1744 if (scope==nullptr ||
1747 ) ||
1748 (name.stripWhiteSpace().startsWith("::")) ||
1749 ((lang==SrcLangExt::Java || lang==SrcLangExt::CSharp) && DString(name).find("::")!=DString::npos)
1750 )
1751 {
1753 }
1754 const ClassDef *result=nullptr;
1755 if (Config_getBool(OPTIMIZE_OUTPUT_VHDL))
1756 {
1757 result = getClass(name);
1758 }
1759 else
1760 {
1761 VisitedKeys visitedKeys;
1762 DString lookupName = lang==SrcLangExt::CSharp ? mangleCSharpGenericName(name) : name;
1763 AUTO_TRACE_ADD("lookup={}",lookupName);
1764 result = p->getResolvedTypeRec(getTypeLookupCache(),visitedKeys,scope,lookupName,&p->typeDef,&p->templateSpec,&p->resolvedType);
1765 if (result==nullptr) // for nested classes imported via tag files, the scope may not
1766 // present, so we check the class name directly as well.
1767 // See also bug701314
1768 {
1769 result = getClass(lookupName);
1770 }
1771 }
1772 if (!mayBeUnlinkable && result && !result->isLinkable())
1773 {
1774 if (!mayBeHidden || !result->isHidden())
1775 {
1776 AUTO_TRACE_ADD("hiding symbol {}",result->name());
1777 result=nullptr; // don't link to artificial/hidden classes unless explicitly allowed
1778 }
1779 }
1780 AUTO_TRACE_EXIT("result={}",result?result->name():DString());
1781 return result;
1782}
1783
1785 const DString &name,
1786 const DString &args,
1787 bool checkCV,
1788 bool insideCode,
1789 bool onlyLinkable)
1790{
1791 AUTO_TRACE("scope={} name={} args={} checkCV={} insideCode={}",
1792 scope?scope->name():DString(), name, args, checkCV, insideCode);
1793 p->reset();
1794 if (scope==nullptr) scope=Doxygen::globalScope;
1795 VisitedKeys visitedKeys;
1796 const Definition *result = p->getResolvedSymbolRec(getSymbolLookupCache(),visitedKeys,scope,name,args,checkCV,insideCode,onlyLinkable,&p->typeDef,&p->templateSpec,&p->resolvedType);
1797 AUTO_TRACE_EXIT("result={}{}", qPrint(result?result->qualifiedName():DString()),
1798 qPrint(result && result->definitionType()==Definition::TypeMember ? toMemberDef(result)->argsString() : DString()));
1799 return result;
1800}
1801
1803{
1804 AUTO_TRACE("scope={} item={}",
1805 scope?scope->name():DString(), item?item->name():DString());
1806 p->reset();
1807 VisitedKeys visitedKeys;
1808 AccessStack accessStack;
1809 int result = p->isAccessibleFrom(visitedKeys,accessStack,scope,item);
1810 AUTO_TRACE_EXIT("result={}",result);
1811 return result;
1812}
1813
1815 const DString &explicitScopePart)
1816{
1817 AUTO_TRACE("scope={} item={} explicitScopePart={}",
1818 scope?scope->name():DString(), item?item->name():DString(), explicitScopePart);
1819 p->reset();
1820 VisitedKeys visitedKeys;
1821 VisitedNamespaces visitedNamespaces;
1822 AccessStack accessStack;
1823 int result = p->isAccessibleFromWithExpScope(visitedKeys,visitedNamespaces,accessStack,scope,item,explicitScopePart);
1824 AUTO_TRACE_EXIT("result={}",result);
1825 return result;
1826}
1827
1829{
1830 p->setFileScope(fileScope);
1831}
1832
1834{
1835 return p->typeDef;
1836}
1837
1839{
1840 return p->templateSpec;
1841}
1842
1844{
1845 return p->resolvedType;
1846}
1847
1849{
1850 auto &cache = getTypeLookupCache();
1851 switch (scope)
1852 {
1853 case ClearScope::All:
1854 cache.clear();
1855 break;
1857 {
1858 StringVector elementsToRemove;
1859 for (const auto &ci : cache)
1860 {
1861 const LookupInfo &li = ci.second;
1862 if (li.definition==nullptr && li.typeDef==nullptr)
1863 {
1864 elementsToRemove.push_back(ci.first);
1865 }
1866 }
1867 for (const auto &k : elementsToRemove)
1868 {
1869 cache.remove(k);
1870 }
1871 }
1872 break;
1874 {
1875 StringVector elementsToRemove;
1876 for (const auto &ci : cache)
1877 {
1878 const LookupInfo &li = ci.second;
1879 if (li.definition)
1880 {
1881 elementsToRemove.push_back(ci.first);
1882 }
1883 }
1884 for (const auto &k : elementsToRemove)
1885 {
1886 cache.remove(k);
1887 }
1888 }
1889 break;
1890 }
1891}
1892
1893static int computeIdealCacheParam(size_t v)
1894{
1895 //printf("computeIdealCacheParam(v=%u)\n",v);
1896
1897 int r=0;
1898 while (v!=0)
1899 {
1900 v >>= 1;
1901 r++;
1902 }
1903 // r = log2(v)
1904
1905 // convert to a valid cache size value
1906 return std::max(0,std::min(r-16,9));
1907}
1908
1910{
1911 // merge the stats of the main thread
1914
1915 std::lock_guard lock1(g_typeCacheStatistics.mutex);
1916 std::lock_guard lock2(g_symbolCacheStatistics.mutex);
1917
1918 msg("type lookup cache used {}/{} hits={} misses={}\n",
1923 msg("symbol lookup cache used {}/{} hits={} misses={}\n",
1928 int typeCacheParam = computeIdealCacheParam(static_cast<size_t>(g_typeCacheStatistics.misses*2/3)); // part of the cache is flushed, hence the 2/3 correction factor
1929 int symbolCacheParam = computeIdealCacheParam(static_cast<size_t>(g_symbolCacheStatistics.misses*2/3)); // part of the cache is flushed, hence the 2/3 correction factor
1930 int cacheParam = std::max(typeCacheParam,symbolCacheParam);
1931 if (cacheParam>Config_getInt(LOOKUP_CACHE_SIZE))
1932 {
1933 msg("Note: based on cache misses the ideal setting for LOOKUP_CACHE_SIZE is {} at the cost of higher memory usage.\n",cacheParam);
1934 }
1935}
1936
Helper class representing the stack of items considered while resolving the scope.
void push(const Definition *scope, const FileDef *fileScope, const Definition *item, const DString &expScope)
bool find(const Definition *scope, const FileDef *fileScope, const Definition *item, const DString &expScope)
std::vector< AccessElem > m_elements
bool find(const Definition *scope, const FileDef *fileScope, const Definition *item)
void push(const Definition *scope, const FileDef *fileScope, const Definition *item)
This class represents an function or template argument list.
Definition arguments.h:66
bool empty() const
Definition arguments.h:100
Definition cache.h:32
V * insert(const K &key, V &&value)
Inserts value under key in the cache.
Definition cache.h:44
V * find(const K &key)
Definition cache.h:105
size_t capacity() const
Returns the maximum number of values that can be stored in the cache.
Definition cache.h:132
size_t size() const
Returns the number of values stored in the cache.
Definition cache.h:126
uint64_t misses() const
Returns how many of the find() calls did not found a value in the cache.
Definition cache.h:144
uint64_t hits() const
Returns how many of the find() calls did find a value in the cache.
Definition cache.h:138
A abstract class representing of a compound symbol.
Definition classdef.h:100
virtual const MemberDef * getMemberByName(const DString &) const =0
Returns the member with the given name.
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 int isBaseClass(const ClassDef *bcd, bool followInstances, const DString &templSpec=DString()) const =0
Returns true iff bcd is a direct or indirect base class of this class.
virtual bool isTemplateArgument() const =0
virtual bool isAccessibleMember(const MemberDef *md) const =0
returns true iff md is a member of this class or of the the public/protected members of a base class
virtual FileDef * getFileDef() const =0
Returns the file in which this compound's definition can be found.
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
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
bool empty() const
Returns true iff the string is empty (std::string compatible alias for isEmpty()).
Definition dstring.h:148
char * rawData()
Returns a writable pointer to the data.
Definition dstring.h:166
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 & append(char c)
Definition dstring.h:489
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
@ ExplicitSize
Definition dstring.h:131
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
size_t length() const
Returns the length of the string, not counting the 0-terminator.
Definition dstring.h:151
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 DString getDefFileName() const =0
virtual bool isLinkable() const =0
virtual DefType definitionType() const =0
virtual const DString & name() const =0
virtual const DString & localName() const =0
virtual DString qualifiedName() const =0
virtual bool isHidden() const =0
virtual bool isArtificial() const =0
virtual Definition * getOuterScope() const =0
virtual bool isReference() const =0
virtual const Definition * findInnerCompound(const DString &name) const =0
static NamespaceDefMutable * globalScope
Definition doxygen.h:114
static SymbolMap< Definition > * symbolMap
Definition doxygen.h:118
A model of a file symbol.
Definition filedef.h:97
virtual DString absFilePath() const =0
virtual const LinkedRefMap< NamespaceDef > & getUsedNamespaces() const =0
virtual const LinkedRefMap< const Definition > & getUsedDefinitions() const =0
Container class representing a vector of objects with keys.
Definition linkedmap.h:232
bool empty() const
Definition linkedmap.h:374
A model of a class/file/namespace member symbol.
Definition memberdef.h:45
virtual DString argsString() const =0
virtual const ClassDef * getCachedTypedefVal() const =0
virtual const ClassDef * getClassDef() const =0
virtual DString getCachedResolvedTypedef() const =0
virtual bool isTypedef() const =0
virtual const FileDef * getFileDef() const =0
virtual const ArgumentList & argumentList() const =0
virtual bool isStrongEnumValue() const =0
virtual bool isStatic() const =0
virtual bool isTypedefValCached() const =0
virtual std::optional< ArgumentList > formalTemplateArguments() const =0
virtual DString getCachedTypedefTemplSpec() const =0
virtual bool isEnumerate() const =0
virtual bool isStrong() const =0
virtual DString typeString() const =0
virtual bool isCallable() const =0
virtual const MemberDef * getEnumScope() const =0
virtual bool isEnumValue() const =0
virtual void cacheTypedefVal(const ClassDef *val, const DString &templSpec, const DString &resolvedType)=0
An abstract interface of a namespace symbol.
virtual const MemberDef * getMemberByName(const DString &) const =0
virtual const LinkedRefMap< NamespaceDef > & getUsedNamespaces() const =0
virtual const LinkedRefMap< const Definition > & getUsedDefinitions() const =0
const VectorPtr & find(const DString &name)
Definition symbolmap.h:74
static void showCacheUsage()
Show usage of the type lookup cache.
ClearScope
Clear the type lookup cache for the current thread.
int isAccessibleFrom(const Definition *scope, const Definition *item)
Checks if symbol item is accessible from within scope.
static void clearTypeLookupCache(ClearScope 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.
std::unique_ptr< Private > p
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.
SymbolResolver(const FileDef *fileScope=nullptr)
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.
ClassDef * getClass(const DString &n)
ClassDef * toClassDef(Definition *d)
#define Config_getInt(name)
Definition config.h:34
#define Config_getBool(name)
Definition config.h:33
std::vector< std::string > StringVector
Definition containers.h:33
std::unique_ptr< ArgumentList > stringToArgumentList(SrcLangExt lang, const DString &argsString, DString *extraTypeChars=nullptr)
Definition defargs.l:822
#define AUTO_TRACE_ADD(...)
Definition docnode.cpp:54
#define AUTO_TRACE(...)
Definition docnode.cpp:53
#define AUTO_TRACE_EXIT(...)
Definition docnode.cpp:55
#define THREAD_LOCAL
Definition doxygen.h:29
char * dstrcpy(char *dst, const char *src)
Definition dstring.h:42
const char * qPrint(const char *s)
Definition dstring.h:783
FileDef * toFileDef(Definition *d)
Definition filedef.cpp:2054
MemberDefMutable * toMemberDefMutable(Definition *d)
MemberDef * toMemberDef(Definition *d)
#define msg(fmt,...)
Definition message.h:94
#define ASSERT(x)
Definition message.h:142
void replaceNamespaceAliases(DString &name)
NamespaceDef * toNamespaceDef(Definition *d)
Definition dstring.h:913
Element in the stack.
const Definition * scope
const Definition * item
AccessElem(const Definition *d, const FileDef *f, const Definition *i)
AccessElem(const Definition *d, const FileDef *f, const Definition *i, const DString &e)
CacheStatistics & m_statistics
Cache< std::string, LookupInfo > m_cache
CacheStatsWrapper(CacheStatistics &stats, size_t capacity)
LookupCache & cache()
DString resolvedType
Definition doxygen.h:55
const Definition * definition
Definition doxygen.h:52
const MemberDef * typeDef
Definition doxygen.h:53
DString templSpec
Definition doxygen.h:54
const MemberDef * typeDef
const ClassDef * newResolveTypedef(LookupCache &cache, VisitedKeys &visitedKeys, const Definition *scope, const MemberDef *md, const MemberDef **pMemType, DString *pTemplSpec, DString *pResolvedType, const ArgumentList *actTemplParams=nullptr)
int isAccessibleFrom(VisitedKeys &visitedKeys, AccessStack &accessStack, const Definition *scope, const Definition *item)
Private(const FileDef *f)
const ClassDef * getResolvedTypeRec(LookupCache &cache, VisitedKeys &visitedKeys, const Definition *scope, const DString &n, const MemberDef **pTypeDef, DString *pTemplSpec, DString *pResolvedType)
bool accessibleViaUsingNamespace(VisitedKeys &visitedKeys, VisitedNamespaceKeys &visitedNamespaces, const LinkedRefMap< NamespaceDef > &nl, const Definition *item, const DString &explicitScopePart="", int level=0)
bool accessibleViaUsingDefinition(VisitedKeys &visitedKeys, const LinkedRefMap< const Definition > &dl, const Definition *item, const DString &explicitScopePart="")
const FileDef * fileScope() const
void setFileScope(const FileDef *fileScope)
const Definition * endOfPathIsUsedClass(const LinkedRefMap< const Definition > &dl, const DString &localName)
void getResolvedType(LookupCache &cache, VisitedKeys &visitedKeys, const Definition *scope, const Definition *d, const DString &explicitScopePart, const ArgumentList *actTemplParams, int &minDistance, const ClassDef *&bestMatch, const MemberDef *&bestTypedef, DString &bestTemplSpec, DString &bestResolvedType)
const Definition * followPath(VisitedKeys &visitedKeys, const Definition *start, const DString &path)
void getResolvedSymbol(VisitedKeys &visitedKeys, const Definition *scope, const Definition *d, const DString &args, bool checkCV, bool insideCode, const DString &explicitScopePart, const DString &strippedTemplateParams, bool forceCallable, int &minDistance, const Definition *&bestMatch, const MemberDef *&bestTypedef, DString &bestTemplSpec, DString &bestResolvedType)
int isAccessibleFromWithExpScope(VisitedKeys &visitedKeys, VisitedNamespaces &visitedNamespaces, AccessStack &accessStack, const Definition *scope, const Definition *item, const DString &explicitScopePart)
DString substTypedef(VisitedKeys &visitedKeys, const Definition *scope, const DString &name, const MemberDef **pTypeDef=nullptr)
std::unordered_map< std::string, const MemberDef * > m_resolvedTypedefs
const Definition * getResolvedSymbolRec(LookupCache &cache, VisitedKeys &visitedKeys, const Definition *scope, const DString &n, const DString &args, bool checkCV, bool insideCode, bool onlyLinkable, const MemberDef **pTypeDef, DString *pTemplSpec, DString *pResolvedType)
StringVector VisitedNamespaceKeys
static bool isCodeSymbol(Definition::DefType defType)
static bool isFileLocalStatic(const Definition *d)
Returns true for a static function or variable that is not a class member, so it is only visible with...
static DString bareName(const Definition *d)
Returns the name of a class as it is used inside the class itself, so Widget for Widget<int>.
static std::recursive_mutex g_cacheTypedefMutex
static void mergeStatistics(CacheStatistics &stats, LookupCache &cache)
std::unordered_map< std::string, const Definition * > VisitedNamespaces
static LookupCache & getTypeLookupCache()
StringVector VisitedKeys
static int computeIdealCacheParam(size_t v)
static LookupCache & getSymbolLookupCache()
static size_t getCacheSize()
THREAD_LOCAL std::unordered_map< std::string, std::pair< DString, const MemberDef * > > g_substMap
static CacheStatistics g_symbolCacheStatistics
static CacheStatistics g_typeCacheStatistics
Cache< std::string, LookupInfo > LookupCache
DString substituteTemplateArgumentsInString(const DString &nm, const ArgumentList &formalArgs, const ArgumentList *actualArgs)
Definition util.cpp:3656
int computeQualifiedIndex(const DString &name)
Return the index of the last :: in the string name that is still before the first <.
Definition util.cpp:5435
DString stripTemplateSpecifiersFromScope(const DString &fullName, bool parentOnly, DString *pLastScopeStripped, DString scopeName, bool allowArtificial)
Definition util.cpp:3818
DString argListToString(const ArgumentList &al, bool useCanonicalType, bool showDefVals)
Definition util.cpp:864
bool matchArguments2(const Definition *srcScope, const FileDef *srcFileScope, const DString &srcReturnType, const ArgumentList *srcAl, const Definition *dstScope, const FileDef *dstFileScope, const DString &dstReturnType, const ArgumentList *dstAl, bool checkCV, SrcLangExt lang, bool allowUnresolved)
Definition util.cpp:1649
DString mangleCSharpGenericName(const DString &name)
Definition util.cpp:5477
int getScopeFragment(const DString &s, int p, int *l)
Definition util.cpp:3930
A bunch of utility functions.