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 {
55*0b57cec5SDimitry Andric   const char *language = Language::GetNameForLanguageType(m_language);
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 
100*0b57cec5SDimitry Andric // Dump the current contents of this object. No functions that cause on demand
101*0b57cec5SDimitry Andric // parsing of functions, globals, statics are called, so this is a good
102*0b57cec5SDimitry Andric // function to call to get an idea of the current contents of the CompileUnit
103*0b57cec5SDimitry Andric // object.
104*0b57cec5SDimitry Andric void CompileUnit::Dump(Stream *s, bool show_context) const {
105*0b57cec5SDimitry Andric   const char *language = Language::GetNameForLanguageType(m_language);
106*0b57cec5SDimitry Andric 
107*0b57cec5SDimitry Andric   s->Printf("%p: ", static_cast<const void *>(this));
108*0b57cec5SDimitry Andric   s->Indent();
109*0b57cec5SDimitry Andric   *s << "CompileUnit" << static_cast<const UserID &>(*this) << ", language = \""
110480093f4SDimitry Andric      << language << "\", file = '" << GetPrimaryFile() << "'\n";
111*0b57cec5SDimitry Andric 
112*0b57cec5SDimitry Andric   //  m_types.Dump(s);
113*0b57cec5SDimitry Andric 
114*0b57cec5SDimitry Andric   if (m_variables.get()) {
115*0b57cec5SDimitry Andric     s->IndentMore();
116*0b57cec5SDimitry Andric     m_variables->Dump(s, show_context);
117*0b57cec5SDimitry Andric     s->IndentLess();
118*0b57cec5SDimitry Andric   }
119*0b57cec5SDimitry Andric 
120*0b57cec5SDimitry Andric   if (!m_functions_by_uid.empty()) {
121*0b57cec5SDimitry Andric     s->IndentMore();
122*0b57cec5SDimitry Andric     ForeachFunction([&s, show_context](const FunctionSP &f) {
123*0b57cec5SDimitry Andric       f->Dump(s, show_context);
124*0b57cec5SDimitry Andric       return false;
125*0b57cec5SDimitry Andric     });
126*0b57cec5SDimitry Andric 
127*0b57cec5SDimitry Andric     s->IndentLess();
128*0b57cec5SDimitry Andric     s->EOL();
129*0b57cec5SDimitry Andric   }
130*0b57cec5SDimitry Andric }
131*0b57cec5SDimitry Andric 
132*0b57cec5SDimitry Andric // Add a function to this compile unit
133*0b57cec5SDimitry Andric void CompileUnit::AddFunction(FunctionSP &funcSP) {
134*0b57cec5SDimitry Andric   m_functions_by_uid[funcSP->GetID()] = funcSP;
135*0b57cec5SDimitry Andric }
136*0b57cec5SDimitry Andric 
137*0b57cec5SDimitry Andric FunctionSP CompileUnit::FindFunctionByUID(lldb::user_id_t func_uid) {
138*0b57cec5SDimitry Andric   auto it = m_functions_by_uid.find(func_uid);
139*0b57cec5SDimitry Andric   if (it == m_functions_by_uid.end())
140*0b57cec5SDimitry Andric     return FunctionSP();
141*0b57cec5SDimitry Andric   return it->second;
142*0b57cec5SDimitry Andric }
143*0b57cec5SDimitry Andric 
144*0b57cec5SDimitry Andric lldb::LanguageType CompileUnit::GetLanguage() {
145*0b57cec5SDimitry Andric   if (m_language == eLanguageTypeUnknown) {
146*0b57cec5SDimitry Andric     if (m_flags.IsClear(flagsParsedLanguage)) {
147*0b57cec5SDimitry Andric       m_flags.Set(flagsParsedLanguage);
1489dba64beSDimitry Andric       if (SymbolFile *symfile = GetModule()->GetSymbolFile())
1499dba64beSDimitry Andric         m_language = symfile->ParseLanguage(*this);
150*0b57cec5SDimitry Andric     }
151*0b57cec5SDimitry Andric   }
152*0b57cec5SDimitry Andric   return m_language;
153*0b57cec5SDimitry Andric }
154*0b57cec5SDimitry Andric 
155*0b57cec5SDimitry Andric LineTable *CompileUnit::GetLineTable() {
156*0b57cec5SDimitry Andric   if (m_line_table_up == nullptr) {
157*0b57cec5SDimitry Andric     if (m_flags.IsClear(flagsParsedLineTable)) {
158*0b57cec5SDimitry Andric       m_flags.Set(flagsParsedLineTable);
1599dba64beSDimitry Andric       if (SymbolFile *symfile = GetModule()->GetSymbolFile())
1609dba64beSDimitry Andric         symfile->ParseLineTable(*this);
161*0b57cec5SDimitry Andric     }
162*0b57cec5SDimitry Andric   }
163*0b57cec5SDimitry Andric   return m_line_table_up.get();
164*0b57cec5SDimitry Andric }
165*0b57cec5SDimitry Andric 
166*0b57cec5SDimitry Andric void CompileUnit::SetLineTable(LineTable *line_table) {
167*0b57cec5SDimitry Andric   if (line_table == nullptr)
168*0b57cec5SDimitry Andric     m_flags.Clear(flagsParsedLineTable);
169*0b57cec5SDimitry Andric   else
170*0b57cec5SDimitry Andric     m_flags.Set(flagsParsedLineTable);
171*0b57cec5SDimitry Andric   m_line_table_up.reset(line_table);
172*0b57cec5SDimitry Andric }
173*0b57cec5SDimitry Andric 
1749dba64beSDimitry Andric void CompileUnit::SetSupportFiles(const FileSpecList &support_files) {
1759dba64beSDimitry Andric   m_support_files = support_files;
1769dba64beSDimitry Andric }
1779dba64beSDimitry Andric 
178*0b57cec5SDimitry Andric DebugMacros *CompileUnit::GetDebugMacros() {
179*0b57cec5SDimitry Andric   if (m_debug_macros_sp.get() == nullptr) {
180*0b57cec5SDimitry Andric     if (m_flags.IsClear(flagsParsedDebugMacros)) {
181*0b57cec5SDimitry Andric       m_flags.Set(flagsParsedDebugMacros);
1829dba64beSDimitry Andric       if (SymbolFile *symfile = GetModule()->GetSymbolFile())
1839dba64beSDimitry Andric         symfile->ParseDebugMacros(*this);
184*0b57cec5SDimitry Andric     }
185*0b57cec5SDimitry Andric   }
186*0b57cec5SDimitry Andric 
187*0b57cec5SDimitry Andric   return m_debug_macros_sp.get();
188*0b57cec5SDimitry Andric }
189*0b57cec5SDimitry Andric 
190*0b57cec5SDimitry Andric void CompileUnit::SetDebugMacros(const DebugMacrosSP &debug_macros_sp) {
191*0b57cec5SDimitry Andric   if (debug_macros_sp.get() == nullptr)
192*0b57cec5SDimitry Andric     m_flags.Clear(flagsParsedDebugMacros);
193*0b57cec5SDimitry Andric   else
194*0b57cec5SDimitry Andric     m_flags.Set(flagsParsedDebugMacros);
195*0b57cec5SDimitry Andric   m_debug_macros_sp = debug_macros_sp;
196*0b57cec5SDimitry Andric }
197*0b57cec5SDimitry Andric 
198*0b57cec5SDimitry Andric VariableListSP CompileUnit::GetVariableList(bool can_create) {
199*0b57cec5SDimitry Andric   if (m_variables.get() == nullptr && can_create) {
200*0b57cec5SDimitry Andric     SymbolContext sc;
201*0b57cec5SDimitry Andric     CalculateSymbolContext(&sc);
202*0b57cec5SDimitry Andric     assert(sc.module_sp);
2039dba64beSDimitry Andric     sc.module_sp->GetSymbolFile()->ParseVariablesForContext(sc);
204*0b57cec5SDimitry Andric   }
205*0b57cec5SDimitry Andric 
206*0b57cec5SDimitry Andric   return m_variables;
207*0b57cec5SDimitry Andric }
208*0b57cec5SDimitry Andric 
209480093f4SDimitry Andric std::vector<uint32_t> FindFileIndexes(const FileSpecList &files, const FileSpec &file) {
210480093f4SDimitry Andric   std::vector<uint32_t> result;
211480093f4SDimitry Andric   uint32_t idx = -1;
212480093f4SDimitry Andric   while ((idx = files.FindFileIndex(idx + 1, file, /*full=*/true)) !=
213480093f4SDimitry Andric          UINT32_MAX)
214480093f4SDimitry Andric     result.push_back(idx);
215480093f4SDimitry Andric   return result;
216480093f4SDimitry Andric }
217480093f4SDimitry Andric 
218*0b57cec5SDimitry Andric uint32_t CompileUnit::FindLineEntry(uint32_t start_idx, uint32_t line,
219*0b57cec5SDimitry Andric                                     const FileSpec *file_spec_ptr, bool exact,
220*0b57cec5SDimitry Andric                                     LineEntry *line_entry_ptr) {
221480093f4SDimitry Andric   if (!file_spec_ptr)
222480093f4SDimitry Andric     file_spec_ptr = &GetPrimaryFile();
223480093f4SDimitry Andric   std::vector<uint32_t> file_indexes = FindFileIndexes(GetSupportFiles(), *file_spec_ptr);
224480093f4SDimitry Andric   if (file_indexes.empty())
225*0b57cec5SDimitry Andric     return UINT32_MAX;
226480093f4SDimitry Andric 
227fe6060f1SDimitry Andric   // TODO: Handle SourceLocationSpec column information
228fe6060f1SDimitry Andric   SourceLocationSpec location_spec(*file_spec_ptr, line, /*column=*/llvm::None,
229fe6060f1SDimitry Andric                                    /*check_inlines=*/false, exact);
230fe6060f1SDimitry Andric 
231*0b57cec5SDimitry Andric   LineTable *line_table = GetLineTable();
232*0b57cec5SDimitry Andric   if (line_table)
233480093f4SDimitry Andric     return line_table->FindLineEntryIndexByFileIndex(
234fe6060f1SDimitry Andric         start_idx, file_indexes, location_spec, line_entry_ptr);
235*0b57cec5SDimitry Andric   return UINT32_MAX;
236*0b57cec5SDimitry Andric }
237*0b57cec5SDimitry Andric 
238fe6060f1SDimitry Andric void CompileUnit::ResolveSymbolContext(
239fe6060f1SDimitry Andric     const SourceLocationSpec &src_location_spec,
240fe6060f1SDimitry Andric     SymbolContextItem resolve_scope, SymbolContextList &sc_list) {
241fe6060f1SDimitry Andric   const FileSpec file_spec = src_location_spec.GetFileSpec();
242fe6060f1SDimitry Andric   const uint32_t line = src_location_spec.GetLine().getValueOr(0);
243fe6060f1SDimitry Andric   const bool check_inlines = src_location_spec.GetCheckInlines();
244fe6060f1SDimitry Andric 
245*0b57cec5SDimitry Andric   // First find all of the file indexes that match our "file_spec". If
246*0b57cec5SDimitry Andric   // "file_spec" has an empty directory, then only compare the basenames when
247*0b57cec5SDimitry Andric   // finding file indexes
248*0b57cec5SDimitry Andric   std::vector<uint32_t> file_indexes;
249*0b57cec5SDimitry Andric   bool file_spec_matches_cu_file_spec =
250480093f4SDimitry Andric       FileSpec::Match(file_spec, this->GetPrimaryFile());
251*0b57cec5SDimitry Andric 
252*0b57cec5SDimitry Andric   // If we are not looking for inlined functions and our file spec doesn't
253*0b57cec5SDimitry Andric   // match then we are done...
254*0b57cec5SDimitry Andric   if (!file_spec_matches_cu_file_spec && !check_inlines)
255480093f4SDimitry Andric     return;
256*0b57cec5SDimitry Andric 
257*0b57cec5SDimitry Andric   SymbolContext sc(GetModule());
258*0b57cec5SDimitry Andric   sc.comp_unit = this;
259*0b57cec5SDimitry Andric 
260480093f4SDimitry Andric   if (line == 0) {
261480093f4SDimitry Andric     if (file_spec_matches_cu_file_spec && !check_inlines) {
262480093f4SDimitry Andric       // only append the context if we aren't looking for inline call sites by
263480093f4SDimitry Andric       // file and line and if the file spec matches that of the compile unit
264480093f4SDimitry Andric       sc_list.Append(sc);
265480093f4SDimitry Andric     }
266480093f4SDimitry Andric     return;
267480093f4SDimitry Andric   }
268480093f4SDimitry Andric 
269fe6060f1SDimitry Andric   uint32_t file_idx =
270fe6060f1SDimitry Andric       GetSupportFiles().FindFileIndex(0, file_spec, true);
271fe6060f1SDimitry Andric   while (file_idx != UINT32_MAX) {
272fe6060f1SDimitry Andric     file_indexes.push_back(file_idx);
273fe6060f1SDimitry Andric     file_idx = GetSupportFiles().FindFileIndex(file_idx + 1, file_spec, true);
274fe6060f1SDimitry Andric   }
275fe6060f1SDimitry Andric 
276fe6060f1SDimitry Andric   const size_t num_file_indexes = file_indexes.size();
277fe6060f1SDimitry Andric   if (num_file_indexes == 0)
278fe6060f1SDimitry Andric     return;
279fe6060f1SDimitry Andric 
280*0b57cec5SDimitry Andric   LineTable *line_table = sc.comp_unit->GetLineTable();
281*0b57cec5SDimitry Andric 
282fe6060f1SDimitry Andric   if (line_table == nullptr) {
283fe6060f1SDimitry Andric     if (file_spec_matches_cu_file_spec && !check_inlines) {
284fe6060f1SDimitry Andric       sc_list.Append(sc);
285fe6060f1SDimitry Andric     }
286480093f4SDimitry Andric     return;
287fe6060f1SDimitry Andric   }
288480093f4SDimitry Andric 
289*0b57cec5SDimitry Andric   uint32_t line_idx;
290480093f4SDimitry Andric   LineEntry line_entry;
291*0b57cec5SDimitry Andric 
292*0b57cec5SDimitry Andric   if (num_file_indexes == 1) {
293*0b57cec5SDimitry Andric     // We only have a single support file that matches, so use the line
294*0b57cec5SDimitry Andric     // table function that searches for a line entries that match a single
295*0b57cec5SDimitry Andric     // support file index
296*0b57cec5SDimitry Andric     line_idx = line_table->FindLineEntryIndexByFileIndex(
297fe6060f1SDimitry Andric         0, file_indexes.front(), src_location_spec, &line_entry);
298480093f4SDimitry Andric   } else {
299480093f4SDimitry Andric     // We found multiple support files that match "file_spec" so use the
300480093f4SDimitry Andric     // line table function that searches for a line entries that match a
301480093f4SDimitry Andric     // multiple support file indexes.
302fe6060f1SDimitry Andric     line_idx = line_table->FindLineEntryIndexByFileIndex(
303fe6060f1SDimitry Andric         0, file_indexes, src_location_spec, &line_entry);
304480093f4SDimitry Andric   }
305*0b57cec5SDimitry Andric 
306*0b57cec5SDimitry Andric   // If "exact == true", then "found_line" will be the same as "line". If
307*0b57cec5SDimitry Andric   // "exact == false", the "found_line" will be the closest line entry
308*0b57cec5SDimitry Andric   // with a line number greater than "line" and we will use this for our
309*0b57cec5SDimitry Andric   // subsequent line exact matches below.
310fe6060f1SDimitry Andric   const bool inlines = false;
311fe6060f1SDimitry Andric   const bool exact = true;
312fe6060f1SDimitry Andric   SourceLocationSpec found_entry(line_entry.file, line_entry.line,
313fe6060f1SDimitry Andric                                  line_entry.column, inlines, exact);
314*0b57cec5SDimitry Andric 
315*0b57cec5SDimitry Andric   while (line_idx != UINT32_MAX) {
316*0b57cec5SDimitry Andric     // If they only asked for the line entry, then we're done, we can
317*0b57cec5SDimitry Andric     // just copy that over. But if they wanted more than just the line
318*0b57cec5SDimitry Andric     // number, fill it in.
319*0b57cec5SDimitry Andric     if (resolve_scope == eSymbolContextLineEntry) {
320*0b57cec5SDimitry Andric       sc.line_entry = line_entry;
321*0b57cec5SDimitry Andric     } else {
322480093f4SDimitry Andric       line_entry.range.GetBaseAddress().CalculateSymbolContext(&sc,
323480093f4SDimitry Andric                                                                resolve_scope);
324*0b57cec5SDimitry Andric     }
325*0b57cec5SDimitry Andric 
326*0b57cec5SDimitry Andric     sc_list.Append(sc);
327480093f4SDimitry Andric     if (num_file_indexes == 1)
328*0b57cec5SDimitry Andric       line_idx = line_table->FindLineEntryIndexByFileIndex(
329fe6060f1SDimitry Andric           line_idx + 1, file_indexes.front(), found_entry, &line_entry);
330480093f4SDimitry Andric     else
331*0b57cec5SDimitry Andric       line_idx = line_table->FindLineEntryIndexByFileIndex(
332fe6060f1SDimitry Andric           line_idx + 1, file_indexes, found_entry, &line_entry);
333*0b57cec5SDimitry Andric   }
334*0b57cec5SDimitry Andric }
335*0b57cec5SDimitry Andric 
336*0b57cec5SDimitry Andric bool CompileUnit::GetIsOptimized() {
337*0b57cec5SDimitry Andric   if (m_is_optimized == eLazyBoolCalculate) {
338*0b57cec5SDimitry Andric     m_is_optimized = eLazyBoolNo;
3399dba64beSDimitry Andric     if (SymbolFile *symfile = GetModule()->GetSymbolFile()) {
3409dba64beSDimitry Andric       if (symfile->ParseIsOptimized(*this))
341*0b57cec5SDimitry Andric         m_is_optimized = eLazyBoolYes;
342*0b57cec5SDimitry Andric     }
343*0b57cec5SDimitry Andric   }
344*0b57cec5SDimitry Andric   return m_is_optimized;
345*0b57cec5SDimitry Andric }
346*0b57cec5SDimitry Andric 
347*0b57cec5SDimitry Andric void CompileUnit::SetVariableList(VariableListSP &variables) {
348*0b57cec5SDimitry Andric   m_variables = variables;
349*0b57cec5SDimitry Andric }
350*0b57cec5SDimitry Andric 
351*0b57cec5SDimitry Andric const std::vector<SourceModule> &CompileUnit::GetImportedModules() {
352*0b57cec5SDimitry Andric   if (m_imported_modules.empty() &&
353*0b57cec5SDimitry Andric       m_flags.IsClear(flagsParsedImportedModules)) {
354*0b57cec5SDimitry Andric     m_flags.Set(flagsParsedImportedModules);
3559dba64beSDimitry Andric     if (SymbolFile *symfile = GetModule()->GetSymbolFile()) {
356*0b57cec5SDimitry Andric       SymbolContext sc;
357*0b57cec5SDimitry Andric       CalculateSymbolContext(&sc);
3589dba64beSDimitry Andric       symfile->ParseImportedModules(sc, m_imported_modules);
359*0b57cec5SDimitry Andric     }
360*0b57cec5SDimitry Andric   }
361*0b57cec5SDimitry Andric   return m_imported_modules;
362*0b57cec5SDimitry Andric }
363*0b57cec5SDimitry Andric 
364480093f4SDimitry Andric bool CompileUnit::ForEachExternalModule(
365480093f4SDimitry Andric     llvm::DenseSet<SymbolFile *> &visited_symbol_files,
366480093f4SDimitry Andric     llvm::function_ref<bool(Module &)> lambda) {
3679dba64beSDimitry Andric   if (SymbolFile *symfile = GetModule()->GetSymbolFile())
368480093f4SDimitry Andric     return symfile->ForEachExternalModule(*this, visited_symbol_files, lambda);
369480093f4SDimitry Andric   return false;
3709dba64beSDimitry Andric }
3719dba64beSDimitry Andric 
372*0b57cec5SDimitry Andric const FileSpecList &CompileUnit::GetSupportFiles() {
373*0b57cec5SDimitry Andric   if (m_support_files.GetSize() == 0) {
374*0b57cec5SDimitry Andric     if (m_flags.IsClear(flagsParsedSupportFiles)) {
375*0b57cec5SDimitry Andric       m_flags.Set(flagsParsedSupportFiles);
3769dba64beSDimitry Andric       if (SymbolFile *symfile = GetModule()->GetSymbolFile())
3779dba64beSDimitry Andric         symfile->ParseSupportFiles(*this, m_support_files);
378*0b57cec5SDimitry Andric     }
379*0b57cec5SDimitry Andric   }
380*0b57cec5SDimitry Andric   return m_support_files;
381*0b57cec5SDimitry Andric }
382*0b57cec5SDimitry Andric 
383*0b57cec5SDimitry Andric void *CompileUnit::GetUserData() const { return m_user_data; }
384