[flang] GetBaseObject()

Original-commit: flang-compiler/f18@38eced54de
Reviewed-on: https://github.com/flang-compiler/f18/pull/531
Tree-same-pre-rewrite: false
This commit is contained in:
peter klausler 2019-06-21 14:10:19 -07:00
parent f01537b146
commit c2b743122a

View file

@ -644,6 +644,26 @@ template<typename A> semantics::Attrs GetAttrs(const A &x) {
}
}
// GetBaseObject()
template<typename A> std::optional<BaseObject> GetBaseObject(const A &) {
return std::nullopt;
}
template<typename T>
std::optional<BaseObject> GetBaseObject(const Designator<T> &x) {
return x.GetBaseObject();
}
template<typename T> std::optional<BaseObject> GetBaseObject(const Expr<T> &x) {
return std::visit([](const auto &y) { return GetBaseObject(y); }, x.u);
}
template<typename A>
std::optional<BaseObject> GetBaseObject(const std::optional<A> &x) {
if (x.has_value()) {
return GetBaseObject(*x);
} else {
return std::nullopt;
}
}
// Predicate: IsAllocatableOrPointer()
template<typename A> bool IsAllocatableOrPointer(const A &x) {
return GetAttrs(x).HasAny(