forked from carbon-language/carbon-lang
-
Notifications
You must be signed in to change notification settings - Fork 0
/
member.cpp
40 lines (31 loc) · 1.11 KB
/
member.cpp
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
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
#include "explorer/ast/member.h"
#include "explorer/ast/declaration.h"
namespace Carbon {
Member::Member(Nonnull<const Declaration*> declaration)
: member_(declaration) {}
Member::Member(Nonnull<const NamedValue*> struct_member)
: member_(struct_member) {}
auto Member::name() const -> std::string_view {
if (const Declaration* decl = member_.dyn_cast<const Declaration*>()) {
return GetName(*decl).value();
} else {
return member_.get<const NamedValue*>()->name;
}
}
auto Member::type() const -> const Value& {
if (const Declaration* decl = member_.dyn_cast<const Declaration*>()) {
return decl->static_type();
} else {
return *member_.get<const NamedValue*>()->value;
}
}
auto Member::declaration() const -> std::optional<Nonnull<const Declaration*>> {
if (const Declaration* decl = member_.dyn_cast<const Declaration*>()) {
return decl;
}
return std::nullopt;
}
} // namespace Carbon