12using namespace llvm::itanium_demangle;
16std::optional<DemangledNameInfo>
22 bool cache_enabled =
false;
24 auto state =
m_state.LockShared();
25 cache_enabled = state->max_entries != 0;
26 auto it = state->infos.find(mangled_name);
27 if (it != state->infos.end())
42 if (state->infos.contains(mangled_name))
46 if (state->infos.size() >= state->max_entries)
47 state->EvictRandomEntry();
49 state->infos.insert({mangled_name, info});
50 state->mangled_names.push_back(mangled_name);
55 assert(!
mangled_names.empty() &&
"evicting from an empty cache");
56 std::uniform_int_distribution<size_t> dist(0,
mangled_names.size() - 1);
57 size_t index = dist(
rng);
66 state->mangled_names.clear();
70 return m_state.LockShared()->max_entries;
74 return m_state.LockShared()->infos.size();
84 state->max_entries = max_entries;
85 if (state->infos.size() > state->max_entries) {
87 state->mangled_names.clear();
95 if (isInsideTemplateArgs())
98 if (
NameInfo.ArgumentsRange.first > 0)
108 if (isInsideTemplateArgs())
111 if (
NameInfo.ArgumentsRange.first == 0)
121 NameInfo.BasenameRange.second = getCurrentPosition();
128 NameInfo.ScopeRange.first = getCurrentPosition();
135 NameInfo.ScopeRange.second = getCurrentPosition();
142 NameInfo.ArgumentsRange.second = getCurrentPosition();
149 NameInfo.QualifiersRange.first = getCurrentPosition();
156 NameInfo.QualifiersRange.second = getCurrentPosition();
163 NameInfo.ArgumentsRange.first = getCurrentPosition();
168 if (
NameInfo.BasenameRange.second == 0)
169 NameInfo.BasenameRange.second = getCurrentPosition();
194 NameInfo.SuffixRange.first = getCurrentPosition();
206 switch (N.getKind()) {
207 case Node::KFunctionType:
210 case Node::KFunctionEncoding:
213 case Node::KNestedName:
216 case Node::KNameWithTemplateArgs:
220 OutputBuffer::printLeft(N);
224 NameInfo.SuffixRange.second = getCurrentPosition();
228 switch (N.getKind()) {
229 case Node::KFunctionType:
232 case Node::KFunctionEncoding:
236 OutputBuffer::printRight(N);
240 NameInfo.SuffixRange.second = getCurrentPosition();
244 auto Scoped = enterFunctionTypePrinting();
245 OutputBuffer::printLeft(N);
249 auto Scoped = enterFunctionTypePrinting();
250 OutputBuffer::printRight(N);
254 auto Scoped = enterFunctionTypePrinting();
256 const Node *Ret = N.getReturnType();
259 if (!Ret->hasRHSComponent(*
this))
265 N.getName()->print(*
this);
269 auto Scoped = enterFunctionTypePrinting();
273 N.getParams().printWithComma(*
this);
276 finalizeArgumentEnd();
278 const Node *Ret = N.getReturnType();
283 finalizeQualifiersStart();
285 auto CVQuals = N.getCVQuals();
286 auto RefQual = N.getRefQual();
287 auto *Attrs = N.getAttrs();
288 auto *Requires = N.getRequires();
290 if (CVQuals & QualConst)
292 if (CVQuals & QualVolatile)
293 *
this +=
" volatile";
294 if (CVQuals & QualRestrict)
295 *
this +=
" restrict";
296 if (RefQual == FrefQualLValue)
298 else if (RefQual == FrefQualRValue)
300 if (Attrs !=
nullptr)
302 if (Requires !=
nullptr) {
303 *
this +=
" requires ";
304 Requires->print(*
this);
307 finalizeQualifiersEnd();
312 N.Qual->print(*
this);
315 N.Name->print(*
this);
320 N.Name->print(*
this);
322 N.TemplateArgs->print(*
this);
A uniqued constant string class.
size_t GetMaxEntries() const
void SetMaxEntries(size_t max_entries)
Changes the maximum number of entries. A limit of 0 disables the cache.
size_t GetNumEntries() const
std::optional< DemangledNameInfo > Get(const Mangled &mangled)
Calculates the DemangledNameInfo and caches the result.
A class that handles mangled names.
std::optional< DemangledNameInfo > ComputeDemangledInfo() const
Compute the DemangledNameInfo of the demangled name.
ConstString GetMangledName() const
Mangled name get accessor.
A class that represents a running process on the host machine.
std::vector< ConstString > mangled_names
The mangled names.
llvm::DenseMap< ConstString, std::optional< DemangledNameInfo > > infos
Maps a ConstString to its DemangledNameInfo.
void EvictRandomEntry()
Drops a random entry from the cache.
void updateScopeStart()
If this object shouldTrack, then update the beginning of the scope range to the current OB position.
bool canFinalize() const
Helper used in the finalize APIs.
void printRightImpl(const llvm::itanium_demangle::FunctionType &N)
void printLeftImpl(const llvm::itanium_demangle::FunctionType &N)
bool isPrintingTopLevelFunctionType() const
Returns true if we're not printing any nested function types, just a FunctionEncoding in the Itanium ...
llvm::itanium_demangle::ScopedOverride< unsigned > enterFunctionTypePrinting()
Called whenever we start printing a function type in the Itanium mangling scheme.
void updateBasenameEnd()
If this object shouldTrack, then update the end of the basename range to the current OB position.
unsigned FunctionPrintingDepth
Incremented each time we start printing a function type node in the Itanium mangling scheme (e....
void finalizeQualifiersEnd()
void printLeft(const llvm::itanium_demangle::Node &N) override
void finalizeArgumentEnd()
Helpers called to track beginning and end of the function arguments.
void updateScopeEnd()
If this object shouldTrack, then update the end of the scope range to the current OB position.
void printRight(const llvm::itanium_demangle::Node &N) override
bool shouldTrack() const
Returns true if the members of this object can be updated.
void finalizeQualifiersStart()
DemangledNameInfo NameInfo
Holds information about the demangled name that is being printed into this buffer.