1 //===-- DWARFDeclContext.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 "DWARFDeclContext.h"
11 
12 const char *
13 DWARFDeclContext::GetQualifiedName () const
14 {
15     if (m_qualified_name.empty())
16     {
17         // The declaration context array for a class named "foo" in namespace
18         // "a::b::c" will be something like:
19         //  [0] DW_TAG_class_type "foo"
20         //  [1] DW_TAG_namespace "c"
21         //  [2] DW_TAG_namespace "b"
22         //  [3] DW_TAG_namespace "a"
23         if (!m_entries.empty())
24         {
25             if (m_entries.size() == 1)
26             {
27                 if (m_entries[0].name)
28                 {
29                     m_qualified_name.append("::");
30                     m_qualified_name.append(m_entries[0].name);
31                 }
32             }
33             else
34             {
35                 collection::const_reverse_iterator pos;
36                 collection::const_reverse_iterator begin = m_entries.rbegin();
37                 collection::const_reverse_iterator end = m_entries.rend();
38                 for (pos = begin; pos != end; ++pos)
39                 {
40                     if (pos != begin)
41                         m_qualified_name.append("::");
42                     m_qualified_name.append(pos->name);
43                 }
44             }
45         }
46     }
47     if (m_qualified_name.empty())
48         return NULL;
49     return m_qualified_name.c_str();
50 }
51 
52 
53 bool
54 DWARFDeclContext::operator==(const DWARFDeclContext& rhs) const
55 {
56     if (m_entries.size() != rhs.m_entries.size())
57         return false;
58 
59     collection::const_iterator pos;
60     collection::const_iterator begin = m_entries.begin();
61     collection::const_iterator end = m_entries.end();
62 
63     collection::const_iterator rhs_pos;
64     collection::const_iterator rhs_begin = rhs.m_entries.begin();
65     // The two entry arrays have the same size
66 
67     // First compare the tags before we do expensize name compares
68     for (pos = begin, rhs_pos = rhs_begin; pos != end; ++pos, ++rhs_pos)
69     {
70         if (pos->tag != rhs_pos->tag)
71             return false;
72     }
73     // The tags all match, now compare the names
74     for (pos = begin, rhs_pos = rhs_begin; pos != end; ++pos, ++rhs_pos)
75     {
76         if (!pos->NameMatches (*rhs_pos))
77             return false;
78     }
79     // All tags and names match
80     return true;
81 }
82 
83