Doxygen
Loading...
Searching...
No Matches
symbolresolver.cpp File Reference
#include "symbolresolver.h"
#include <algorithm>
#include <mutex>
#include <string>
#include <unordered_map>
#include <vector>
#include "cache.h"
#include "config.h"
#include "defargs.h"
#include "doxygen.h"
#include "filedef.h"
#include "namespacedef.h"
#include "trace.h"
#include "util.h"
Include dependency graph for symbolresolver.cpp:

Go to the source code of this file.

Classes

struct  CacheStatistics
struct  CacheStatsWrapper
class  AccessStack
 Helper class representing the stack of items considered while resolving the scope. More...
struct  AccessStack::AccessElem
 Element in the stack. More...
struct  SymbolResolver::Private

Macros

#define AUTO_TRACE(...)
#define AUTO_TRACE_ADD(...)
#define AUTO_TRACE_EXIT(...)

Typedefs

using LookupCache = Cache<std::string,LookupInfo>
using VisitedKeys = StringVector
using VisitedNamespaceKeys = StringVector
using VisitedNamespaces = std::unordered_map<std::string,const Definition *>

Functions

static void mergeStatistics (CacheStatistics &stats, LookupCache &cache)
static size_t getCacheSize ()
static LookupCache & getTypeLookupCache ()
static LookupCache & getSymbolLookupCache ()
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 within the file that defines it.
static int computeIdealCacheParam (size_t v)

Variables

static std::recursive_mutex g_cacheTypedefMutex
static CacheStatistics g_typeCacheStatistics
static CacheStatistics g_symbolCacheStatistics
THREAD_LOCAL std::unordered_map< std::string, std::pair< DString, const MemberDef * > > g_substMap

Macro Definition Documentation

◆ AUTO_TRACE

#define AUTO_TRACE ( ...)
Value:
(void)0

Definition at line 40 of file symbolresolver.cpp.

◆ AUTO_TRACE_ADD

#define AUTO_TRACE_ADD ( ...)
Value:
(void)0

Definition at line 41 of file symbolresolver.cpp.

◆ AUTO_TRACE_EXIT

#define AUTO_TRACE_EXIT ( ...)
Value:
(void)0

Definition at line 42 of file symbolresolver.cpp.

Typedef Documentation

◆ LookupCache

using LookupCache = Cache<std::string,LookupInfo>

Definition at line 59 of file symbolresolver.cpp.

◆ VisitedKeys

Definition at line 178 of file symbolresolver.cpp.

◆ VisitedNamespaceKeys

Definition at line 179 of file symbolresolver.cpp.

◆ VisitedNamespaces

using VisitedNamespaces = std::unordered_map<std::string,const Definition *>

Definition at line 180 of file symbolresolver.cpp.

Function Documentation

◆ computeIdealCacheParam()

int computeIdealCacheParam ( size_t v)
static

Definition at line 1870 of file symbolresolver.cpp.

1871{
1872 //printf("computeIdealCacheParam(v=%u)\n",v);
1873
1874 int r=0;
1875 while (v!=0)
1876 {
1877 v >>= 1;
1878 r++;
1879 }
1880 // r = log2(v)
1881
1882 // convert to a valid cache size value
1883 return std::max(0,std::min(r-16,9));
1884}

Referenced by SymbolResolver::showCacheUsage().

◆ getCacheSize()

size_t getCacheSize ( )
static

Definition at line 85 of file symbolresolver.cpp.

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}
#define Config_getInt(name)
Definition config.h:34

References Config_getInt.

Referenced by getSymbolLookupCache(), and getTypeLookupCache().

◆ getSymbolLookupCache()

LookupCache & getSymbolLookupCache ( )
static

Definition at line 99 of file symbolresolver.cpp.

100{
102 return wrapper.cache();
103}
#define THREAD_LOCAL
Definition doxygen.h:29
static size_t getCacheSize()
static CacheStatistics g_symbolCacheStatistics

References g_symbolCacheStatistics, getCacheSize(), and THREAD_LOCAL.

Referenced by SymbolResolver::resolveSymbol(), and SymbolResolver::showCacheUsage().

◆ getTypeLookupCache()

LookupCache & getTypeLookupCache ( )
static

◆ isCodeSymbol()

◆ isFileLocalStatic()

bool isFileLocalStatic ( const Definition * d)
static

Returns true for a static function or variable that is not a class member, so it is only visible within the file that defines it.

Definition at line 119 of file symbolresolver.cpp.

120{
121 const MemberDef *md = toMemberDef(d);
122 return md && md->isStatic() && md->getClassDef()==nullptr;
123}
A model of a class/file/namespace member symbol.
Definition memberdef.h:45
virtual const ClassDef * getClassDef() const =0
virtual bool isStatic() const =0
MemberDef * toMemberDef(Definition *d)

References MemberDef::getClassDef(), MemberDef::isStatic(), and toMemberDef().

Referenced by SymbolResolver::Private::getResolvedSymbolRec().

◆ mergeStatistics()

void mergeStatistics ( CacheStatistics & stats,
LookupCache & cache )
static

Definition at line 61 of file symbolresolver.cpp.

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}
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

References Cache< K, V >::capacity(), CacheStatistics::capacity, Cache< K, V >::hits(), CacheStatistics::hits, Cache< K, V >::misses(), CacheStatistics::misses, CacheStatistics::mutex, Cache< K, V >::size(), and CacheStatistics::size.

Referenced by SymbolResolver::showCacheUsage(), and CacheStatsWrapper::~CacheStatsWrapper().

Variable Documentation

◆ g_cacheTypedefMutex

std::recursive_mutex g_cacheTypedefMutex
static

Definition at line 45 of file symbolresolver.cpp.

Referenced by SymbolResolver::Private::newResolveTypedef().

◆ g_substMap

THREAD_LOCAL std::unordered_map<std::string, std::pair<DString,const MemberDef *> > g_substMap

Definition at line 105 of file symbolresolver.cpp.

Referenced by SymbolResolver::Private::substTypedef().

◆ g_symbolCacheStatistics

CacheStatistics g_symbolCacheStatistics
static

Definition at line 57 of file symbolresolver.cpp.

Referenced by getSymbolLookupCache(), and SymbolResolver::showCacheUsage().

◆ g_typeCacheStatistics

CacheStatistics g_typeCacheStatistics
static

Definition at line 56 of file symbolresolver.cpp.

Referenced by getTypeLookupCache(), and SymbolResolver::showCacheUsage().