73 case dwarf::DW_TAG_module:
75 case dwarf::DW_TAG_compile_unit:
77 case dwarf::DW_TAG_subprogram:
79 if ((Context.getTag() == dwarf::DW_TAG_namespace ||
80 Context.getTag() == dwarf::DW_TAG_compile_unit) &&
84 case dwarf::DW_TAG_member:
85 case dwarf::DW_TAG_namespace:
86 case dwarf::DW_TAG_structure_type:
87 case dwarf::DW_TAG_class_type:
88 case dwarf::DW_TAG_union_type:
89 case dwarf::DW_TAG_enumeration_type:
90 case dwarf::DW_TAG_typedef:
105 NameForUniquing = StringPool.internString(
LinkageName);
106 }
else if (!Name.empty()) {
111 bool HasTemplateParamsInName =
112 Name.ends_with(
">") && !Name.ends_with(
"<=>") && Name.contains(
'<');
113 std::optional<std::string> FullName;
114 if (!HasTemplateParamsInName)
116 NameForUniquing = StringPool.internString(FullName ? *FullName : Name);
126 if (
Tag == dwarf::DW_TAG_typedef && !NameForUniquing.
empty()) {
142 StringRef RefName = RefDie.getShortName();
143 if (!RefName.
empty()) {
150 if (Combined.
size() != NameForUniquing.
size())
151 NameForUniquing = StringPool.internString(Combined);
154 bool IsAnonymousNamespace =
155 NameForUniquing.
empty() &&
Tag == dwarf::DW_TAG_namespace;
156 if (IsAnonymousNamespace) {
159 NameForUniquing =
"(anonymous namespace)";
162 if (
Tag != dwarf::DW_TAG_class_type &&
Tag != dwarf::DW_TAG_structure_type &&
163 Tag != dwarf::DW_TAG_union_type &&
164 Tag != dwarf::DW_TAG_enumeration_type && NameForUniquing.
empty())
168 unsigned ByteSize = std::numeric_limits<uint32_t>::max();
170 if (!InClangModule) {
180 std::numeric_limits<uint64_t>::max());
181 if (
Tag != dwarf::DW_TAG_namespace || IsAnonymousNamespace) {
182 if (
unsigned FileNum =
184 if (
const auto *LT = U.getOrigUnit().getContext().getLineTableForUnit(
189 if (IsAnonymousNamespace)
192 if (LT->hasFileAtIndex(FileNum)) {
196 FileRef = getResolvedPath(U, FileNum, *LT);
203 if (!Line && NameForUniquing.
empty())
221 if (IsAnonymousNamespace)
227 auto ContextIter = Contexts.find(&
Key);
229 if (ContextIter == Contexts.end()) {
233 DeclContext(Hash, Line, ByteSize,
Tag, Name, NameForUniquing, FileRef,
234 Context,
DIE, U.getUniqueID());
235 std::tie(ContextIter, Inserted) = Contexts.insert(NewContext);
236 assert(Inserted &&
"Failed to insert DeclContext");
238 }
else if (
Tag != dwarf::DW_TAG_namespace &&
239 !(*ContextIter)->setLastSeenDIE(U,
DIE)) {
245 assert(ContextIter != Contexts.end());
248 if ((
Tag == dwarf::DW_TAG_subprogram &&
249 Context.getTag() != dwarf::DW_TAG_structure_type &&
250 Context.getTag() != dwarf::DW_TAG_class_type) ||
251 (
Tag == dwarf::DW_TAG_union_type))
PointerIntPair< DeclContext *, 1 > getChildDeclContext(DeclContext &Context, const DWARFDie &DIE, CompileUnit &Unit, bool InClangModule)
Get the child of Context described by DIE in Unit.
A DeclContext is a named program scope that is used for ODR uniquing of types.
bool setLastSeenDIE(CompileUnit &U, const DWARFDie &Die)
Set the last DIE/CU a context was seen in and, possibly invalidate the context if it is ambiguous.