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