LLVM: lib/DWARFLinker/Classic/DWARFLinkerDeclContext.cpp Source File (original) (raw)
35 if (LastSeenCompileUnitID == U.getUniqueID()) {
36 DWARFUnit &OrigUnit = U.getOrigUnit();
38 U.getInfo(FirstIdx).Ctxt = nullptr;
39 return false;
40 }
41
42 LastSeenCompileUnitID = U.getUniqueID();
43 LastSeenDIE = Die;
44 return true;
45}
51
52
53
54
55
56 switch (Tag) {
57 default:
58
60 case dwarf::DW_TAG_module:
61 break;
62 case dwarf::DW_TAG_compile_unit:
64 case dwarf::DW_TAG_subprogram:
65
66 if ((Context.getTag() == dwarf::DW_TAG_namespace ||
67 Context.getTag() == dwarf::DW_TAG_compile_unit) &&
70 [[fallthrough]];
71 case dwarf::DW_TAG_member:
72 case dwarf::DW_TAG_namespace:
73 case dwarf::DW_TAG_structure_type:
74 case dwarf::DW_TAG_class_type:
75 case dwarf::DW_TAG_union_type:
76 case dwarf::DW_TAG_enumeration_type:
77 case dwarf::DW_TAG_typedef:
78
79
80
81
84 break;
85 }
86
90
92 NameForUniquing = StringPool.internString(LinkageName);
93 else if (!Name.empty())
94 NameForUniquing = StringPool.internString(Name);
95
96 bool IsAnonymousNamespace =
97 NameForUniquing.empty() && Tag == dwarf::DW_TAG_namespace;
98 if (IsAnonymousNamespace) {
99
100
101 NameForUniquing = "(anonymous namespace)";
102 }
103
104 if (Tag != dwarf::DW_TAG_class_type && Tag != dwarf::DW_TAG_structure_type &&
105 Tag != dwarf::DW_TAG_union_type &&
106 Tag != dwarf::DW_TAG_enumeration_type && NameForUniquing.empty())
108
109 unsigned Line = 0;
110 unsigned ByteSize = std::numeric_limits<uint32_t>::max();
111
112 if (!InClangModule) {
113
114
115
116
117
118
119
120
122 std::numeric_limits<uint64_t>::max());
123 if (Tag != dwarf::DW_TAG_namespace || IsAnonymousNamespace) {
124 if (unsigned FileNum =
126 if (const auto *LT = U.getOrigUnit().getContext().getLineTableForUnit(
127 &U.getOrigUnit())) {
128
129
130
131 if (IsAnonymousNamespace)
132 FileNum = 1;
133
134 if (LT->hasFileAtIndex(FileNum)) {
136
137
138 FileRef = getResolvedPath(U, FileNum, *LT);
139 }
140 }
141 }
142 }
143 }
144
145 if (!Line && NameForUniquing.empty())
147
148
149
150
151
152
153
154
155
156
157
158 unsigned Hash =
159 hash_combine(Context.getQualifiedNameHash(), Tag, NameForUniquing);
160
161
162
163 if (IsAnonymousNamespace)
165
166
167 DeclContext Key(Hash, Line, ByteSize, Tag, Name, NameForUniquing, FileRef,
168 Context);
169 auto ContextIter = Contexts.find(&Key);
170
171 if (ContextIter == Contexts.end()) {
172
173 bool Inserted;
174 DeclContext *NewContext = new (Allocator)
175 DeclContext(Hash, Line, ByteSize, Tag, Name, NameForUniquing, FileRef,
176 Context, DIE, U.getUniqueID());
177 std::tie(ContextIter, Inserted) = Contexts.insert(NewContext);
178 assert(Inserted && "Failed to insert DeclContext");
179 (void)Inserted;
180 } else if (Tag != dwarf::DW_TAG_namespace &&
181 !(*ContextIter)->setLastSeenDIE(U, DIE)) {
182
183
185 }
186
187 assert(ContextIter != Contexts.end());
188
189
190 if ((Tag == dwarf::DW_TAG_subprogram &&
191 Context.getTag() != dwarf::DW_TAG_structure_type &&
192 Context.getTag() != dwarf::DW_TAG_class_type) ||
193 (Tag == dwarf::DW_TAG_union_type))
195
197}
PointerIntPair< DeclContext *, 1 > getChildDeclContext(DeclContext &Context, const DWARFDie &DIE, CompileUnit &Unit, bool InClangModule)
Get the child of Context described by DIE in Unit.
Definition DWARFLinkerDeclContext.cpp:48
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.
Definition DWARFLinkerDeclContext.cpp:34