aboutsummaryrefslogtreecommitdiff
path: root/source/Symbol/Declaration.cpp
blob: 3943f02c54741eb23a6fb7b3646df02e64d35bad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
//===-- Declaration.cpp -----------------------------------------*- C++ -*-===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

#include "lldb/Symbol/Declaration.h"
#include "lldb/Core/Stream.h"

using namespace lldb_private;

void
Declaration::Dump(Stream *s, bool show_fullpaths) const
{
    if (m_file)
    {
        *s << ", decl = ";
        if (show_fullpaths)
            *s << m_file;
        else
            *s << m_file.GetFilename();
        if (m_line > 0)
            s->Printf(":%u", m_line);
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
        if (m_column > 0)
            s->Printf(":%u", m_column);
#endif
    }
    else
    {
        if (m_line > 0)
        {
            s->Printf(", line = %u", m_line);
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
            if (m_column > 0)
                s->Printf(":%u", m_column);
#endif
        }
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
        else if (m_column > 0)
            s->Printf(", column = %u", m_column);
#endif
    }
}

bool
Declaration::DumpStopContext (Stream *s, bool show_fullpaths) const
{
    if (m_file)
    {
        if (show_fullpaths || s->GetVerbose())
            *s << m_file;
        else
            m_file.GetFilename().Dump(s);

        if (m_line > 0)
            s->Printf(":%u", m_line);
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
        if (m_column > 0)
            s->Printf(":%u", m_column);
#endif
        return true;
    }
    else if (m_line > 0)
    {
        s->Printf(" line %u", m_line);
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
        if (m_column > 0)
            s->Printf(":%u", m_column);
#endif
        return true;
    }
    return false;
}

size_t
Declaration::MemorySize() const
{
    return sizeof(Declaration);
}

int
Declaration::Compare(const Declaration& a, const Declaration& b)
{
    int result = FileSpec::Compare(a.m_file, b.m_file, true);
    if (result)
        return result;
    if (a.m_line < b.m_line)
        return -1;
    else if (a.m_line > b.m_line)
        return 1;
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
    if (a.m_column < b.m_column)
        return -1;
    else if (a.m_column > b.m_column)
        return 1;
#endif
    return 0;
}

bool
lldb_private::operator == (const Declaration &lhs, const Declaration &rhs)
{
#ifdef LLDB_ENABLE_DECLARATION_COLUMNS
    if (lhs.GetColumn () == rhs.GetColumn ())
        if (lhs.GetLine () == rhs.GetLine ())
            return lhs.GetFile() == rhs.GetFile();
#else
    if (lhs.GetLine () == rhs.GetLine ())
        return lhs.GetFile() == rhs.GetFile();
#endif
    return false;
}