aboutsummaryrefslogtreecommitdiff
path: root/boot/result.cc
blob: 5f3c516a359bebcd1ad53ad798702c1178a1d4d5 (plain)
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/* Miscellaneous types used across stage boundaries.
   Copyright (C) 2025 Free Software Foundation, Inc.

GCC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3, or (at your option)
any later version.

GCC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3.  If not see
<http://www.gnu.org/licenses/>.  */

#include "elna/boot/result.h"

namespace elna::boot
{
    location::location(const std::size_t line, const std::size_t column)
        : m_line(line), m_column(column)
    {
    }

    std::size_t location::line() const
    {
        return this->m_line;
    }

    std::size_t location::column() const
    {
        return this->m_column;
    }

    bool location::available() const
    {
        return this->m_line != 0 || this->m_column != 0;
    }

    bool location::operator==(const location& that) const
    {
        return this->m_line == that.m_line && this->m_column == that.m_column;
    }

    bool location::operator!=(const location& that) const
    {
        return !(*this == that);
    }

    source_position::source_position(location start, location end)
        : m_start(start), m_end(end)
    {
    }

    const location& source_position::start() const
    {
        return this->m_start;
    }

    const location& source_position::end() const
    {
        return this->m_end;
    }

    bool source_position::is_span() const
    {
        return this->m_start != this->m_end;
    }

    error::error(const source_position position)
        : position(position)
    {
    }

    std::deque<std::unique_ptr<error>>& error_container::errors()
    {
        return m_errors;
    }

    bool error_container::has_errors() const
    {
        return !m_errors.empty();
    }

    identifier::identifier(const std::string& name, const source_position& position)
        : m_name(name), m_position(position)
    {
    }

    const std::string& identifier::name() const
    {
        return this->m_name;
    }

    const source_position& identifier::position() const
    {
        return this->m_position;
    }

    bool identifier::operator==(const identifier& that) const
    {
        return this->m_name == that.m_name;
    }

    bool identifier::operator!=(const identifier& that) const
    {
        return !(*this == that);
    }

    bool identifier::operator==(const std::string& that) const
    {
        return this->m_name == that;
    }

    bool identifier::operator!=(const std::string& that) const
    {
        return !(*this == that);
    }

    identifier_definition::identifier_definition(const std::string& name,
            const source_position& position, const bool exported)
        : m_identifier(name, position), m_exported(exported)
    {
    }

    const std::string& identifier_definition::name() const
    {
        return this->m_identifier.name();
    }

    const identifier& identifier_definition::id() const
    {
        return this->m_identifier;
    }

    bool identifier_definition::exported() const
    {
        return this->m_exported;
    }
}

std::size_t std::hash<elna::boot::identifier>::operator()(
        const elna::boot::identifier& key) const
{
    return std::hash<std::string>{}(key.name());
}