Files
carbon-lang/explorer/ast/member.cpp
T
Jon Ross-Perkins 4d522c8e90 Finish making clang-tidy (mostly) work (again) and run -fix (#2312)
This does some more work to the run_clang_tidy.py wrapper script, and runs an example pass.

"again" because it's really the proto fuzzer changes that broke it, it had been working before.

"mostly" because there's still an issue within the proto fuzzer that it can't find "port/protobuf.h", i.e. https://github.com/google/libprotobuf-mutator/tree/master/port, but I'm still hesitant to add an include path there.
2022-10-18 15:48:17 -07:00

41 lines
1.1 KiB
C++

// 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 auto* 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 auto* 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 auto* decl = member_.dyn_cast<const Declaration*>()) {
return decl;
}
return std::nullopt;
}
} // namespace Carbon