1 //===-- DWARFASTParserClang.h -----------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef SymbolFileDWARF_DWARFASTParserClang_h_
11 #define SymbolFileDWARF_DWARFASTParserClang_h_
12 
13 // C Includes
14 // C++ Includes
15 // Other libraries and framework includes
16 #include "clang/AST/CharUnits.h"
17 #include "llvm/ADT/DenseMap.h"
18 #include "llvm/ADT/SmallPtrSet.h"
19 #include "llvm/ADT/SmallVector.h"
20 
21 // Project includes
22 #include "DWARFASTParser.h"
23 #include "DWARFDefines.h"
24 #include "lldb/Core/ClangForward.h"
25 #include "lldb/Core/PluginInterface.h"
26 #include "lldb/Symbol/ClangASTContext.h"
27 #include "lldb/Symbol/ClangASTImporter.h"
28 
29 class DWARFDebugInfoEntry;
30 class DWARFDIECollection;
31 
32 class DWARFASTParserClang : public DWARFASTParser {
33 public:
34   DWARFASTParserClang(lldb_private::ClangASTContext &ast);
35 
36   ~DWARFASTParserClang() override;
37 
38   // DWARFASTParser interface.
39   lldb::TypeSP ParseTypeFromDWARF(const lldb_private::SymbolContext &sc,
40                                   const DWARFDIE &die, lldb_private::Log *log,
41                                   bool *type_is_new_ptr) override;
42 
43   lldb_private::Function *
44   ParseFunctionFromDWARF(const lldb_private::SymbolContext &sc,
45                          const DWARFDIE &die) override;
46 
47   bool
48   CompleteTypeFromDWARF(const DWARFDIE &die, lldb_private::Type *type,
49                         lldb_private::CompilerType &compiler_type) override;
50 
51   lldb_private::CompilerDecl
52   GetDeclForUIDFromDWARF(const DWARFDIE &die) override;
53 
54   std::vector<DWARFDIE>
55   GetDIEForDeclContext(lldb_private::CompilerDeclContext decl_context) override;
56 
57   lldb_private::CompilerDeclContext
58   GetDeclContextForUIDFromDWARF(const DWARFDIE &die) override;
59 
60   lldb_private::CompilerDeclContext
61   GetDeclContextContainingUIDFromDWARF(const DWARFDIE &die) override;
62 
63   lldb_private::ClangASTImporter &GetClangASTImporter();
64 
65 protected:
66   class DelayedAddObjCClassProperty;
67   typedef std::vector<DelayedAddObjCClassProperty> DelayedPropertyList;
68 
69   clang::BlockDecl *ResolveBlockDIE(const DWARFDIE &die);
70 
71   clang::NamespaceDecl *ResolveNamespaceDIE(const DWARFDIE &die);
72 
73   bool ParseTemplateDIE(const DWARFDIE &die,
74                         lldb_private::ClangASTContext::TemplateParameterInfos
75                             &template_param_infos);
76   bool ParseTemplateParameterInfos(
77       const DWARFDIE &parent_die,
78       lldb_private::ClangASTContext::TemplateParameterInfos
79           &template_param_infos);
80 
81   bool
82   ParseChildMembers(const lldb_private::SymbolContext &sc, const DWARFDIE &die,
83                     lldb_private::CompilerType &class_compiler_type,
84                     const lldb::LanguageType class_language,
85                     std::vector<clang::CXXBaseSpecifier *> &base_classes,
86                     std::vector<int> &member_accessibilities,
87                     DWARFDIECollection &member_function_dies,
88                     DelayedPropertyList &delayed_properties,
89                     lldb::AccessType &default_accessibility, bool &is_a_class,
90                     lldb_private::ClangASTImporter::LayoutInfo &layout_info);
91 
92   size_t
93   ParseChildParameters(const lldb_private::SymbolContext &sc,
94                        clang::DeclContext *containing_decl_ctx,
95                        const DWARFDIE &parent_die, bool skip_artificial,
96                        bool &is_static, bool &is_variadic,
97                        bool &has_template_params,
98                        std::vector<lldb_private::CompilerType> &function_args,
99                        std::vector<clang::ParmVarDecl *> &function_param_decls,
100                        unsigned &type_quals);
101 
102   void ParseChildArrayInfo(const lldb_private::SymbolContext &sc,
103                            const DWARFDIE &parent_die, int64_t &first_index,
104                            std::vector<uint64_t> &element_orders,
105                            uint32_t &byte_stride, uint32_t &bit_stride);
106 
107   size_t ParseChildEnumerators(const lldb_private::SymbolContext &sc,
108                                lldb_private::CompilerType &compiler_type,
109                                bool is_signed, uint32_t enumerator_byte_size,
110                                const DWARFDIE &parent_die);
111 
112   lldb_private::Type *GetTypeForDIE(const DWARFDIE &die);
113 
114   clang::Decl *GetClangDeclForDIE(const DWARFDIE &die);
115 
116   clang::DeclContext *GetClangDeclContextForDIE(const DWARFDIE &die);
117 
118   clang::DeclContext *GetClangDeclContextContainingDIE(const DWARFDIE &die,
119                                                        DWARFDIE *decl_ctx_die);
120 
121   bool CopyUniqueClassMethodTypes(const DWARFDIE &src_class_die,
122                                   const DWARFDIE &dst_class_die,
123                                   lldb_private::Type *class_type,
124                                   DWARFDIECollection &failures);
125 
126   clang::DeclContext *GetCachedClangDeclContextForDIE(const DWARFDIE &die);
127 
128   void LinkDeclContextToDIE(clang::DeclContext *decl_ctx, const DWARFDIE &die);
129 
130   void LinkDeclToDIE(clang::Decl *decl, const DWARFDIE &die);
131 
132   lldb::TypeSP ParseTypeFromDWO(const DWARFDIE &die, lldb_private::Log *log);
133 
134   //----------------------------------------------------------------------
135   // Return true if this type is a declaration to a type in an external
136   // module.
137   //----------------------------------------------------------------------
138   lldb::ModuleSP GetModuleForType(const DWARFDIE &die);
139 
140   typedef llvm::SmallPtrSet<const DWARFDebugInfoEntry *, 4> DIEPointerSet;
141   typedef llvm::DenseMap<const DWARFDebugInfoEntry *, clang::DeclContext *>
142       DIEToDeclContextMap;
143   // typedef llvm::DenseMap<const clang::DeclContext *, DIEPointerSet>
144   // DeclContextToDIEMap;
145   typedef std::multimap<const clang::DeclContext *, const DWARFDIE>
146       DeclContextToDIEMap;
147   typedef llvm::DenseMap<const DWARFDebugInfoEntry *, clang::Decl *>
148       DIEToDeclMap;
149   typedef llvm::DenseMap<const clang::Decl *, DIEPointerSet> DeclToDIEMap;
150 
151   lldb_private::ClangASTContext &m_ast;
152   DIEToDeclMap m_die_to_decl;
153   DeclToDIEMap m_decl_to_die;
154   DIEToDeclContextMap m_die_to_decl_ctx;
155   DeclContextToDIEMap m_decl_ctx_to_die;
156   std::unique_ptr<lldb_private::ClangASTImporter> m_clang_ast_importer_ap;
157 };
158 
159 #endif // SymbolFileDWARF_DWARFASTParserClang_h_
160