15ffd83dbSDimitry Andric //===-- CompileUnit.cpp ---------------------------------------------------===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric 
9*0b57cec5SDimitry Andric #include "lldb/Symbol/CompileUnit.h"
10*0b57cec5SDimitry Andric #include "lldb/Core/Module.h"
11*0b57cec5SDimitry Andric #include "lldb/Symbol/LineTable.h"
129dba64beSDimitry Andric #include "lldb/Symbol/SymbolFile.h"
13*0b57cec5SDimitry Andric #include "lldb/Symbol/VariableList.h"
14*0b57cec5SDimitry Andric #include "lldb/Target/Language.h"
15480093f4SDimitry Andric #include "lldb/Utility/Timer.h"
16*0b57cec5SDimitry Andric 
17*0b57cec5SDimitry Andric using namespace lldb;
18*0b57cec5SDimitry Andric using namespace lldb_private;
19*0b57cec5SDimitry Andric 
20*0b57cec5SDimitry Andric CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data,
21*0b57cec5SDimitry Andric                          const char *pathname, const lldb::user_id_t cu_sym_id,
22*0b57cec5SDimitry Andric                          lldb::LanguageType language,
23*0b57cec5SDimitry Andric                          lldb_private::LazyBool is_optimized)
24480093f4SDimitry Andric     : CompileUnit(module_sp, user_data, FileSpec(pathname), cu_sym_id, language,
25480093f4SDimitry Andric                   is_optimized) {}
26*0b57cec5SDimitry Andric 
27*0b57cec5SDimitry Andric CompileUnit::CompileUnit(const lldb::ModuleSP &module_sp, void *user_data,
28*0b57cec5SDimitry Andric                          const FileSpec &fspec, const lldb::user_id_t cu_sym_id,
29*0b57cec5SDimitry Andric                          lldb::LanguageType language,
30*0b57cec5SDimitry Andric                          lldb_private::LazyBool is_optimized)
31480093f4SDimitry Andric     : ModuleChild(module_sp), UserID(cu_sym_id), m_user_data(user_data),
32480093f4SDimitry Andric       m_language(language), m_flags(0), m_file_spec(fspec),
33*0b57cec5SDimitry Andric       m_is_optimized(is_optimized) {
34*0b57cec5SDimitry Andric   if (language != eLanguageTypeUnknown)
35*0b57cec5SDimitry Andric     m_flags.Set(flagsParsedLanguage);
36*0b57cec5SDimitry Andric   assert(module_sp);
37*0b57cec5SDimitry Andric }
38*0b57cec5SDimitry Andric 
39*0b57cec5SDimitry Andric void CompileUnit::CalculateSymbolContext(SymbolContext *sc) {
40*0b57cec5SDimitry Andric   sc->comp_unit = this;
41*0b57cec5SDimitry Andric   GetModule()->CalculateSymbolContext(sc);
42*0b57cec5SDimitry Andric }
43*0b57cec5SDimitry Andric 
44*0b57cec5SDimitry Andric ModuleSP CompileUnit::CalculateSymbolContextModule() { return GetModule(); }
45*0b57cec5SDimitry Andric 
46*0b57cec5SDimitry Andric CompileUnit *CompileUnit::CalculateSymbolContextCompileUnit() { return this; }
47*0b57cec5SDimitry Andric 
48*0b57cec5SDimitry Andric void CompileUnit::DumpSymbolContext(Stream *s) {
49*0b57cec5SDimitry Andric   GetModule()->DumpSymbolContext(s);
50*0b57cec5SDimitry Andric   s->Printf(", CompileUnit{0x%8.8" PRIx64 "}", GetID());
51*0b57cec5SDimitry Andric }
52*0b57cec5SDimitry Andric 
53*0b57cec5SDimitry Andric void CompileUnit::GetDescription(Stream *s,
54*0b57cec5SDimitry Andric                                  lldb::DescriptionLevel level) const {
55349cc55cSDimitry Andric   const char *language = GetCachedLanguage();
56*0b57cec5SDimitry Andric   *s << "id = " << (const UserID &)*this << ", file = \""
57480093f4SDimitry Andric      << this->GetPrimaryFile() << "\", language = \"" << language << '"';
58*0b57cec5SDimitry Andric }
59*0b57cec5SDimitry Andric 
60*0b57cec5SDimitry Andric void CompileUnit::ForeachFunction(
61*0b57cec5SDimitry Andric     llvm::function_ref<bool(const FunctionSP &)> lambda) const {
62*0b57cec5SDimitry Andric   std::vector<lldb::FunctionSP> sorted_functions;
63*0b57cec5SDimitry Andric   sorted_functions.reserve(m_functions_by_uid.size());
64*0b57cec5SDimitry Andric   for (auto &p : m_functions_by_uid)
65*0b57cec5SDimitry Andric     sorted_functions.push_back(p.second);
66*0b57cec5SDimitry Andric   llvm::sort(sorted_functions.begin(), sorted_functions.end(),
67*0b57cec5SDimitry Andric              [](const lldb::FunctionSP &a, const lldb::FunctionSP &b) {
68*0b57cec5SDimitry Andric                return a->GetID() < b->GetID();
69*0b57cec5SDimitry Andric              });
70*0b57cec5SDimitry Andric 
71*0b57cec5SDimitry Andric   for (auto &f : sorted_functions)
72*0b57cec5SDimitry Andric     if (lambda(f))
73*0b57cec5SDimitry Andric       return;
74*0b57cec5SDimitry Andric }
75*0b57cec5SDimitry Andric 
76480093f4SDimitry Andric lldb::FunctionSP CompileUnit::FindFunction(
77480093f4SDimitry Andric     llvm::function_ref<bool(const FunctionSP &)> matching_lambda) {
78e8d8bef9SDimitry Andric   LLDB_SCOPED_TIMER();
79480093f4SDimitry Andric 
80480093f4SDimitry Andric   lldb::ModuleSP module = CalculateSymbolContextModule();
81480093f4SDimitry Andric 
82480093f4SDimitry Andric   if (!module)
83480093f4SDimitry Andric     return {};
84480093f4SDimitry Andric 
85480093f4SDimitry Andric   SymbolFile *symbol_file = module->GetSymbolFile();
86480093f4SDimitry Andric 
87480093f4SDimitry Andric   if (!symbol_file)
88480093f4SDimitry Andric     return {};
89480093f4SDimitry Andric 
90480093f4SDimitry Andric   // m_functions_by_uid is filled in lazily but we need all the entries.
91480093f4SDimitry Andric   symbol_file->ParseFunctions(*this);
92480093f4SDimitry Andric 
93480093f4SDimitry Andric   for (auto &p : m_functions_by_uid) {
94480093f4SDimitry Andric     if (matching_lambda(p.second))
95480093f4SDimitry Andric       return p.second;
96480093f4SDimitry Andric   }
97480093f4SDimitry Andric   return {};
98480093f4SDimitry Andric }
99480093f4SDimitry Andric 
100349cc55cSDimitry Andric const char *CompileUnit::GetCachedLanguage() const {
101349cc55cSDimitry Andric   if (m_flags.IsClear(flagsParsedLanguage))
102349cc55cSDimitry Andric     return "<not loaded>";
103349cc55cSDimitry Andric   return Language::GetNameForLanguageType(m_language);
104349cc55cSDimitry Andric }
105349cc55cSDimitry Andric 
106*0b57cec5SDimitry Andric // Dump the current contents of this object. No functions that cause on demand
107*0b57cec5SDimitry Andric // parsing of functions, globals, statics are called, so this is a good
108*0b57cec5SDimitry Andric // function to call to get an idea of the current contents of the CompileUnit
109*0b57cec5SDimitry Andric // object.
110*0b57cec5SDimitry Andric void CompileUnit::Dump(Stream *s, bool show_context) const {
111349cc55cSDimitry Andric   const char *language = GetCachedLanguage();
112*0b57cec5SDimitry Andric 
113*0b57cec5SDimitry Andric   s->Printf("%p: ", static_cast<const void *>(this));
114*0b57cec5SDimitry Andric   s->Indent();
115*0b57cec5SDimitry Andric   *s << "CompileUnit" << static_cast<const UserID &>(*this) << ", language = \""
116480093f4SDimitry Andric      << language << "\", file = '" << GetPrimaryFile() << "'\n";
117*0b57cec5SDimitry Andric 
118*0b57cec5SDimitry Andric   //  m_types.Dump(s);
119*0b57cec5SDimitry Andric 
120*0b57cec5SDimitry Andric   if (m_variables.get()) {
121*0b57cec5SDimitry Andric     s->IndentMore();
122*0b57cec5SDimitry Andric     m_variables->Dump(s, show_context);
123*0b57cec5SDimitry Andric     s->IndentLess();
124*0b57cec5SDimitry Andric   }
125*0b57cec5SDimitry Andric 
126*0b57cec5SDimitry Andric   if (!m_functions_by_uid.empty()) {
127*0b57cec5SDimitry Andric     s->IndentMore();
128*0b57cec5SDimitry Andric     ForeachFunction([&s, show_context](const FunctionSP &f) {
129*0b57cec5SDimitry Andric       f->Dump(s, show_context);
130*0b57cec5SDimitry Andric       return false;
131*0b57cec5SDimitry Andric     });
132*0b57cec5SDimitry Andric 
133*0b57cec5SDimitry Andric     s->IndentLess();
134*0b57cec5SDimitry Andric     s->EOL();
135*0b57cec5SDimitry Andric   }
136*0b57cec5SDimitry Andric }
137*0b57cec5SDimitry Andric 
138*0b57cec5SDimitry Andric // Add a function to this compile unit
139*0b57cec5SDimitry Andric void CompileUnit::AddFunction(FunctionSP &funcSP) {
140*0b57cec5SDimitry Andric   m_functions_by_uid[funcSP->GetID()] = funcSP;
141*0b57cec5SDimitry Andric }
142*0b57cec5SDimitry Andric 
143*0b57cec5SDimitry Andric FunctionSP CompileUnit::FindFunctionByUID(lldb::user_id_t func_uid) {
144*0b57cec5SDimitry Andric   auto it = m_functions_by_uid.find(func_uid);
145*0b57cec5SDimitry Andric   if (it == m_functions_by_uid.end())
146*0b57cec5SDimitry Andric     return FunctionSP();
147*0b57cec5SDimitry Andric   return it->second;
148*0b57cec5SDimitry Andric }
149*0b57cec5SDimitry Andric 
150*0b57cec5SDimitry Andric lldb::LanguageType CompileUnit::GetLanguage() {
151*0b57cec5SDimitry Andric   if (m_language == eLanguageTypeUnknown) {
152*0b57cec5SDimitry Andric     if (m_flags.IsClear(flagsParsedLanguage)) {
153*0b57cec5SDimitry Andric       m_flags.Set(flagsParsedLanguage);
1549dba64beSDimitry Andric       if (SymbolFile *symfile = GetModule()->GetSymbolFile())
1559dba64beSDimitry Andric         m_language = symfile->ParseLanguage(*this);
156*0b57cec5SDimitry Andric     }
157*0b57cec5SDimitry Andric   }
158*0b57cec5SDimitry Andric   return m_language;
159*0b57cec5SDimitry Andric }
160*0b57cec5SDimitry Andric 
161*0b57cec5SDimitry Andric LineTable *CompileUnit::GetLineTable() {
162*0b57cec5SDimitry Andric   if (m_line_table_up == nullptr) {
163*0b57cec5SDimitry Andric     if (m_flags.IsClear(flagsParsedLineTable)) {
164*0b57cec5SDimitry Andric       m_flags.Set(flagsParsedLineTable);
1659dba64beSDimitry Andric       if (SymbolFile *symfile = GetModule()->GetSymbolFile())
1669dba64beSDimitry Andric         symfile->ParseLineTable(*this);
167*0b57cec5SDimitry Andric     }
168*0b57cec5SDimitry Andric   }
169*0b57cec5SDimitry Andric   return m_line_table_up.get();
170*0b57cec5SDimitry Andric }
171*0b57cec5SDimitry Andric 
172*0b57cec5SDimitry Andric void CompileUnit::SetLineTable(LineTable *line_table) {
173*0b57cec5SDimitry Andric   if (line_table == nullptr)
174*0b57cec5SDimitry Andric     m_flags.Clear(flagsParsedLineTable);
175*0b57cec5SDimitry Andric   else
176*0b57cec5SDimitry Andric     m_flags.Set(flagsParsedLineTable);
177*0b57cec5SDimitry Andric   m_line_table_up.reset(line_table);
178*0b57cec5SDimitry Andric }
179*0b57cec5SDimitry Andric 
1809dba64beSDimitry Andric void CompileUnit::SetSupportFiles(const FileSpecList &support_files) {
1819dba64beSDimitry Andric   m_support_files = support_files;
1829dba64beSDimitry Andric }
1839dba64beSDimitry Andric 
184349cc55cSDimitry Andric void CompileUnit::SetSupportFiles(FileSpecList &&support_files) {
185349cc55cSDimitry Andric   m_support_files = std::move(support_files);
186349cc55cSDimitry Andric }
187349cc55cSDimitry Andric 
188*0b57cec5SDimitry Andric DebugMacros *CompileUnit::GetDebugMacros() {
189*0b57cec5SDimitry Andric   if (m_debug_macros_sp.get() == nullptr) {
190*0b57cec5SDimitry Andric     if (m_flags.IsClear(flagsParsedDebugMacros)) {
191*0b57cec5SDimitry Andric       m_flags.Set(flagsParsedDebugMacros);
1929dba64beSDimitry Andric       if (SymbolFile *symfile = GetModule()->GetSymbolFile())
1939dba64beSDimitry Andric         symfile->ParseDebugMacros(*this);
194*0b57cec5SDimitry Andric     }
195*0b57cec5SDimitry Andric   }
196*0b57cec5SDimitry Andric 
197*0b57cec5SDimitry Andric   return m_debug_macros_sp.get();
198*0b57cec5SDimitry Andric }
199*0b57cec5SDimitry Andric 
200*0b57cec5SDimitry Andric void CompileUnit::SetDebugMacros(const DebugMacrosSP &debug_macros_sp) {
201*0b57cec5SDimitry Andric   if (debug_macros_sp.get() == nullptr)
202*0b57cec5SDimitry Andric     m_flags.Clear(flagsParsedDebugMacros);
203*0b57cec5SDimitry Andric   else
204*0b57cec5SDimitry Andric     m_flags.Set(flagsParsedDebugMacros);
205*0b57cec5SDimitry Andric   m_debug_macros_sp = debug_macros_sp;
206*0b57cec5SDimitry Andric }
207*0b57cec5SDimitry Andric 
208*0b57cec5SDimitry Andric VariableListSP CompileUnit::GetVariableList(bool can_create) {
209*0b57cec5SDimitry Andric   if (m_variables.get() == nullptr && can_create) {
210*0b57cec5SDimitry Andric     SymbolContext sc;
211*0b57cec5SDimitry Andric     CalculateSymbolContext(&sc);
212*0b57cec5SDimitry Andric     assert(sc.module_sp);
2139dba64beSDimitry Andric     sc.module_sp->GetSymbolFile()->ParseVariablesForContext(sc);
214*0b57cec5SDimitry Andric   }
215*0b57cec5SDimitry Andric 
216*0b57cec5SDimitry Andric   return m_variables;
217*0b57cec5SDimitry Andric }
218*0b57cec5SDimitry Andric 
219480093f4SDimitry Andric std::vector<uint32_t> FindFileIndexes(const FileSpecList &files, const FileSpec &file) {
220480093f4SDimitry Andric   std::vector<uint32_t> result;
221480093f4SDimitry Andric   uint32_t idx = -1;
222480093f4SDimitry Andric   while ((idx = files.FindFileIndex(idx + 1, file, /*full=*/true)) !=
223480093f4SDimitry Andric          UINT32_MAX)
224480093f4SDimitry Andric     result.push_back(idx);
225480093f4SDimitry Andric   return result;
226480093f4SDimitry Andric }
227480093f4SDimitry Andric 
228*0b57cec5SDimitry Andric uint32_t CompileUnit::FindLineEntry(uint32_t start_idx, uint32_t line,
229*0b57cec5SDimitry Andric                                     const FileSpec *file_spec_ptr, bool exact,
230*0b57cec5SDimitry Andric                                     LineEntry *line_entry_ptr) {
231480093f4SDimitry Andric   if (!file_spec_ptr)
232480093f4SDimitry Andric     file_spec_ptr = &GetPrimaryFile();
233480093f4SDimitry Andric   std::vector<uint32_t> file_indexes = FindFileIndexes(GetSupportFiles(), *file_spec_ptr);
234480093f4SDimitry Andric   if (file_indexes.empty())
235*0b57cec5SDimitry Andric     return UINT32_MAX;
236480093f4SDimitry Andric 
237fe6060f1SDimitry Andric   // TODO: Handle SourceLocationSpec column information
238fe6060f1SDimitry Andric   SourceLocationSpec location_spec(*file_spec_ptr, line, /*column=*/llvm::None,
239fe6060f1SDimitry Andric                                    /*check_inlines=*/false, exact);
240fe6060f1SDimitry Andric 
241*0b57cec5SDimitry Andric   LineTable *line_table = GetLineTable();
242*0b57cec5SDimitry Andric   if (line_table)
243480093f4SDimitry Andric     return line_table->FindLineEntryIndexByFileIndex(
244fe6060f1SDimitry Andric         start_idx, file_indexes, location_spec, line_entry_ptr);
245*0b57cec5SDimitry Andric   return UINT32_MAX;
246*0b57cec5SDimitry Andric }
247*0b57cec5SDimitry Andric 
248fe6060f1SDimitry Andric void CompileUnit::ResolveSymbolContext(
249fe6060f1SDimitry Andric     const SourceLocationSpec &src_location_spec,
250fe6060f1SDimitry Andric     SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
251fe6060f1SDimitry Andric   const FileSpec file_spec = src_location_spec.GetFileSpec();
25281ad6265SDimitry Andric   const uint32_t line = src_location_spec.GetLine().value_or(0);
253fe6060f1SDimitry Andric   const bool check_inlines = src_location_spec.GetCheckInlines();
254fe6060f1SDimitry Andric 
255*0b57cec5SDimitry Andric   // First find all of the file indexes that match our "file_spec". If
256*0b57cec5SDimitry Andric   // "file_spec" has an empty directory, then only compare the basenames when
257*0b57cec5SDimitry Andric   // finding file indexes
258*0b57cec5SDimitry Andric   std::vector<uint32_t> file_indexes;
259*0b57cec5SDimitry Andric   bool file_spec_matches_cu_file_spec =
260480093f4SDimitry Andric       FileSpec::Match(file_spec, this->GetPrimaryFile());
261*0b57cec5SDimitry Andric 
262*0b57cec5SDimitry Andric   // If we are not looking for inlined functions and our file spec doesn't
263*0b57cec5SDimitry Andric   // match then we are done...
264*0b57cec5SDimitry Andric   if (!file_spec_matches_cu_file_spec && !check_inlines)
265480093f4SDimitry Andric     return;
266*0b57cec5SDimitry Andric 
267*0b57cec5SDimitry Andric   SymbolContext sc(GetModule());
268*0b57cec5SDimitry Andric   sc.comp_unit = this;
269*0b57cec5SDimitry Andric 
270480093f4SDimitry Andric   if (line == 0) {
271480093f4SDimitry Andric     if (file_spec_matches_cu_file_spec && !check_inlines) {
272480093f4SDimitry Andric       // only append the context if we aren't looking for inline call sites by
273480093f4SDimitry Andric       // file and line and if the file spec matches that of the compile unit
274480093f4SDimitry Andric       sc_list.Append(sc);
275480093f4SDimitry Andric     }
276480093f4SDimitry Andric     return;
277480093f4SDimitry Andric   }
278480093f4SDimitry Andric 
279fe6060f1SDimitry Andric   uint32_t file_idx =
280fe6060f1SDimitry Andric       GetSupportFiles().FindFileIndex(0, file_spec, true);
281fe6060f1SDimitry Andric   while (file_idx != UINT32_MAX) {
282fe6060f1SDimitry Andric     file_indexes.push_back(file_idx);
283fe6060f1SDimitry Andric     file_idx = GetSupportFiles().FindFileIndex(file_idx + 1, file_spec, true);
284fe6060f1SDimitry Andric   }
285fe6060f1SDimitry Andric 
286fe6060f1SDimitry Andric   const size_t num_file_indexes = file_indexes.size();
287fe6060f1SDimitry Andric   if (num_file_indexes == 0)
288fe6060f1SDimitry Andric     return;
289fe6060f1SDimitry Andric 
29081ad6265SDimitry Andric   // Found a matching source file in this compile unit load its debug info.
29181ad6265SDimitry Andric   GetModule()->GetSymbolFile()->SetLoadDebugInfoEnabled();
29281ad6265SDimitry Andric 
293*0b57cec5SDimitry Andric   LineTable *line_table = sc.comp_unit->GetLineTable();
294*0b57cec5SDimitry Andric 
295fe6060f1SDimitry Andric   if (line_table == nullptr) {
296fe6060f1SDimitry Andric     if (file_spec_matches_cu_file_spec && !check_inlines) {
297fe6060f1SDimitry Andric       sc_list.Append(sc);
298fe6060f1SDimitry Andric     }
299480093f4SDimitry Andric     return;
300fe6060f1SDimitry Andric   }
301480093f4SDimitry Andric 
302*0b57cec5SDimitry Andric   uint32_t line_idx;
303480093f4SDimitry Andric   LineEntry line_entry;
304*0b57cec5SDimitry Andric 
305*0b57cec5SDimitry Andric   if (num_file_indexes == 1) {
306*0b57cec5SDimitry Andric     // We only have a single support file that matches, so use the line
307*0b57cec5SDimitry Andric     // table function that searches for a line entries that match a single
308*0b57cec5SDimitry Andric     // support file index
309*0b57cec5SDimitry Andric     line_idx = line_table->FindLineEntryIndexByFileIndex(
310fe6060f1SDimitry Andric         0, file_indexes.front(), src_location_spec, &line_entry);
311480093f4SDimitry Andric   } else {
312480093f4SDimitry Andric     // We found multiple support files that match "file_spec" so use the
313480093f4SDimitry Andric     // line table function that searches for a line entries that match a
314480093f4SDimitry Andric     // multiple support file indexes.
315fe6060f1SDimitry Andric     line_idx = line_table->FindLineEntryIndexByFileIndex(
316fe6060f1SDimitry Andric         0, file_indexes, src_location_spec, &line_entry);
317480093f4SDimitry Andric   }
318*0b57cec5SDimitry Andric 
319*0b57cec5SDimitry Andric   // If "exact == true", then "found_line" will be the same as "line". If
320*0b57cec5SDimitry Andric   // "exact == false", the "found_line" will be the closest line entry
321*0b57cec5SDimitry Andric   // with a line number greater than "line" and we will use this for our
322*0b57cec5SDimitry Andric   // subsequent line exact matches below.
323fe6060f1SDimitry Andric   const bool inlines = false;
324fe6060f1SDimitry Andric   const bool exact = true;
325349cc55cSDimitry Andric   const llvm::Optional<uint16_t> column =
32681ad6265SDimitry Andric       src_location_spec.GetColumn()
327349cc55cSDimitry Andric           ? llvm::Optional<uint16_t>(line_entry.column)
328349cc55cSDimitry Andric           : llvm::None;
329349cc55cSDimitry Andric 
330349cc55cSDimitry Andric   SourceLocationSpec found_entry(line_entry.file, line_entry.line, column,
331349cc55cSDimitry Andric                                  inlines, exact);
332*0b57cec5SDimitry Andric 
333*0b57cec5SDimitry Andric   while (line_idx != UINT32_MAX) {
334*0b57cec5SDimitry Andric     // If they only asked for the line entry, then we're done, we can
335*0b57cec5SDimitry Andric     // just copy that over. But if they wanted more than just the line
336*0b57cec5SDimitry Andric     // number, fill it in.
337*0b57cec5SDimitry Andric     if (resolve_scope == eSymbolContextLineEntry) {
338*0b57cec5SDimitry Andric       sc.line_entry = line_entry;
339*0b57cec5SDimitry Andric     } else {
340480093f4SDimitry Andric       line_entry.range.GetBaseAddress().CalculateSymbolContext(&sc,
341480093f4SDimitry Andric                                                                resolve_scope);
342*0b57cec5SDimitry Andric     }
343*0b57cec5SDimitry Andric 
344*0b57cec5SDimitry Andric     sc_list.Append(sc);
345480093f4SDimitry Andric     if (num_file_indexes == 1)
346*0b57cec5SDimitry Andric       line_idx = line_table->FindLineEntryIndexByFileIndex(
347fe6060f1SDimitry Andric           line_idx + 1, file_indexes.front(), found_entry, &line_entry);
348480093f4SDimitry Andric     else
349*0b57cec5SDimitry Andric       line_idx = line_table->FindLineEntryIndexByFileIndex(
350fe6060f1SDimitry Andric           line_idx + 1, file_indexes, found_entry, &line_entry);
351*0b57cec5SDimitry Andric   }
352*0b57cec5SDimitry Andric }
353*0b57cec5SDimitry Andric 
354*0b57cec5SDimitry Andric bool CompileUnit::GetIsOptimized() {
355*0b57cec5SDimitry Andric   if (m_is_optimized == eLazyBoolCalculate) {
356*0b57cec5SDimitry Andric     m_is_optimized = eLazyBoolNo;
3579dba64beSDimitry Andric     if (SymbolFile *symfile = GetModule()->GetSymbolFile()) {
3589dba64beSDimitry Andric       if (symfile->ParseIsOptimized(*this))
359*0b57cec5SDimitry Andric         m_is_optimized = eLazyBoolYes;
360*0b57cec5SDimitry Andric     }
361*0b57cec5SDimitry Andric   }
362*0b57cec5SDimitry Andric   return m_is_optimized;
363*0b57cec5SDimitry Andric }
364*0b57cec5SDimitry Andric 
365*0b57cec5SDimitry Andric void CompileUnit::SetVariableList(VariableListSP &variables) {
366*0b57cec5SDimitry Andric   m_variables = variables;
367*0b57cec5SDimitry Andric }
368*0b57cec5SDimitry Andric 
369*0b57cec5SDimitry Andric const std::vector<SourceModule> &CompileUnit::GetImportedModules() {
370*0b57cec5SDimitry Andric   if (m_imported_modules.empty() &&
371*0b57cec5SDimitry Andric       m_flags.IsClear(flagsParsedImportedModules)) {
372*0b57cec5SDimitry Andric     m_flags.Set(flagsParsedImportedModules);
3739dba64beSDimitry Andric     if (SymbolFile *symfile = GetModule()->GetSymbolFile()) {
374*0b57cec5SDimitry Andric       SymbolContext sc;
375*0b57cec5SDimitry Andric       CalculateSymbolContext(&sc);
3769dba64beSDimitry Andric       symfile->ParseImportedModules(sc, m_imported_modules);
377*0b57cec5SDimitry Andric     }
378*0b57cec5SDimitry Andric   }
379*0b57cec5SDimitry Andric   return m_imported_modules;
380*0b57cec5SDimitry Andric }
381*0b57cec5SDimitry Andric 
382480093f4SDimitry Andric bool CompileUnit::ForEachExternalModule(
383480093f4SDimitry Andric     llvm::DenseSet<SymbolFile *> &visited_symbol_files,
384480093f4SDimitry Andric     llvm::function_ref<bool(Module &)> lambda) {
3859dba64beSDimitry Andric   if (SymbolFile *symfile = GetModule()->GetSymbolFile())
386480093f4SDimitry Andric     return symfile->ForEachExternalModule(*this, visited_symbol_files, lambda);
387480093f4SDimitry Andric   return false;
3889dba64beSDimitry Andric }
3899dba64beSDimitry Andric 
390*0b57cec5SDimitry Andric const FileSpecList &CompileUnit::GetSupportFiles() {
391*0b57cec5SDimitry Andric   if (m_support_files.GetSize() == 0) {
392*0b57cec5SDimitry Andric     if (m_flags.IsClear(flagsParsedSupportFiles)) {
393*0b57cec5SDimitry Andric       m_flags.Set(flagsParsedSupportFiles);
3949dba64beSDimitry Andric       if (SymbolFile *symfile = GetModule()->GetSymbolFile())
3959dba64beSDimitry Andric         symfile->ParseSupportFiles(*this, m_support_files);
396*0b57cec5SDimitry Andric     }
397*0b57cec5SDimitry Andric   }
398*0b57cec5SDimitry Andric   return m_support_files;
399*0b57cec5SDimitry Andric }
400*0b57cec5SDimitry Andric 
401*0b57cec5SDimitry Andric void *CompileUnit::GetUserData() const { return m_user_data; }
402