]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Plugins/SymbolFile/DWARF/UniqueDWARFASTType.cpp
MFV: r313101
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Plugins / SymbolFile / DWARF / UniqueDWARFASTType.cpp
1 //===-- UniqueDWARFASTType.cpp ----------------------------------*- 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 #include "UniqueDWARFASTType.h"
11
12 // C Includes
13 // C++ Includes
14 // Other libraries and framework includes
15 // Project includes
16 #include "lldb/Symbol/Declaration.h"
17
18 bool
19 UniqueDWARFASTTypeList::Find (const DWARFDIE &die,
20                               const lldb_private::Declaration &decl,
21                               const int32_t byte_size,
22                               UniqueDWARFASTType &entry) const
23 {
24     for (const UniqueDWARFASTType &udt : m_collection)
25     {
26         // Make sure the tags match
27         if (udt.m_die.Tag() == die.Tag())
28         {
29             // Validate byte sizes of both types only if both are valid.
30             if (udt.m_byte_size < 0 || byte_size < 0 || udt.m_byte_size == byte_size)
31             {
32                 // Make sure the file and line match
33                 if (udt.m_declaration == decl)
34                 {
35                     // The type has the same name, and was defined on the same
36                     // file and line. Now verify all of the parent DIEs match.
37                     DWARFDIE parent_arg_die = die.GetParent();
38                     DWARFDIE parent_pos_die = udt.m_die.GetParent();
39                     bool match = true;
40                     bool done = false;
41                     while (!done && match && parent_arg_die && parent_pos_die)
42                     {
43                         const dw_tag_t parent_arg_tag = parent_arg_die.Tag();
44                         const dw_tag_t parent_pos_tag = parent_pos_die.Tag();
45                         if (parent_arg_tag == parent_pos_tag)
46                         {
47                             switch (parent_arg_tag)
48                             {
49                             case DW_TAG_class_type:
50                             case DW_TAG_structure_type:
51                             case DW_TAG_union_type:
52                             case DW_TAG_namespace:
53                                 {
54                                     const char *parent_arg_die_name = parent_arg_die.GetName();
55                                     if (parent_arg_die_name == NULL)  // Anonymous (i.e. no-name) struct
56                                     {
57                                         match = false;
58                                     }
59                                     else
60                                     {
61                                         const char *parent_pos_die_name = parent_pos_die.GetName();
62                                         if (parent_pos_die_name == NULL || ((parent_arg_die_name != parent_pos_die_name) && strcmp (parent_arg_die_name, parent_pos_die_name)))
63                                             match = false;
64                                     }
65                                 }
66                                 break;
67                             
68                             case DW_TAG_compile_unit:
69                                 done = true;
70                                 break;
71                             }
72                         }
73                         parent_arg_die = parent_arg_die.GetParent();
74                         parent_pos_die = parent_pos_die.GetParent();
75                     }
76
77                     if (match)
78                     {
79                         entry = udt;
80                         return true;
81                     }
82                 }
83             }
84         }
85     }
86     return false;
87 }