mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Track a resolved Member on each member access expression. (#1333)
Type checking now stores information on a member access identifying the member that was accessed, not only its name. This parallels what we do for other similar constructs whose meaning is resolved by name lookup or type-checking, and will allow us to avoid redoing lookups in some cases during interpretation.
This commit is contained in:
@@ -0,0 +1,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
|
||||
Reference in New Issue
Block a user