[flang] Address comments; allow "real,parameter::x=tiny(x)"

Original-commit: flang-compiler/f18@e865358871
Reviewed-on: https://github.com/flang-compiler/f18/pull/602
This commit is contained in:
peter klausler 2019-07-25 10:16:28 -07:00
parent 9b079deed5
commit 4aa659f795
4 changed files with 17 additions and 11 deletions

View File

@ -445,14 +445,7 @@ Expr<Type<TypeCategory::Integer, KIND>> FoldIntrinsicFunction(
return j.value;
}));
} else if (name == "bit_size") {
if (auto *sx{UnwrapExpr<Expr<SomeInteger>>(args[0])}) {
return std::visit(
[](const auto &x) {
using TR = typename std::decay_t<decltype(x)>::Result;
return Expr<T>{Scalar<TR>::bits};
},
sx->u);
}
return Expr<T>{Scalar<T>::bits};
} else if (name == "dim") {
return FoldElementalIntrinsic<T, T, T>(
context, std::move(funcRef), &Scalar<T>::DIM);

View File

@ -296,7 +296,7 @@ static const IntrinsicInterface genericIntrinsicFunction[]{
{{"i", AnyInt, Rank::elementalOrBOZ},
{"j", AnyInt, Rank::elementalOrBOZ}},
DefaultLogical},
{"bit_size", {{"i", AnyInt, Rank::anyOrAssumedRank}}, DefaultInt,
{"bit_size", {{"i", SameInt, Rank::anyOrAssumedRank}}, SameInt,
Rank::scalar},
{"ble",
{{"i", AnyInt, Rank::elementalOrBOZ},

View File

@ -56,7 +56,8 @@ std::optional<ConstantSubscripts> AsConstantExtents(const Shape &);
inline int GetRank(const Shape &s) { return static_cast<int>(s.size()); }
// The dimension here is zero-based, unlike DIM= arguments to many intrinsics.
// The dimension argument to these inquiries is zero-based,
// unlike the DIM= arguments to many intrinsics.
MaybeExtentExpr GetLowerBound(
FoldingContext &, const NamedEntity &, int dimension);
Shape GetLowerBounds(FoldingContext &, const NamedEntity &);

View File

@ -658,6 +658,7 @@ public:
using ScopeHandler::Post;
using ScopeHandler::Pre;
bool Pre(const parser::Initialization &);
void Post(const parser::EntityDecl &);
void Post(const parser::ObjectDecl &);
void Post(const parser::PointerDecl &);
@ -2636,6 +2637,13 @@ void DeclarationVisitor::Post(const parser::CodimensionDecl &x) {
DeclareObjectEntity(name, Attrs{});
}
bool DeclarationVisitor::Pre(const parser::Initialization &) {
// Defer inspection of initializers to Initialization() so that the
// symbol being initialized will be available within the initialization
// expression.
return false;
}
void DeclarationVisitor::Post(const parser::EntityDecl &x) {
// TODO: may be under StructureStmt
const auto &name{std::get<parser::ObjectName>(x.t)};
@ -2677,8 +2685,8 @@ bool DeclarationVisitor::Pre(const parser::NamedConstantDef &x) {
return false;
}
const auto &expr{std::get<parser::ConstantExpr>(x.t)};
Walk(expr);
ApplyImplicitRules(symbol);
Walk(expr);
if (auto converted{
EvaluateConvertedExpr(symbol, expr, expr.thing.value().source)}) {
symbol.get<ObjectEntityDetails>().set_init(std::move(*converted));
@ -4773,6 +4781,10 @@ void DeclarationVisitor::Initialization(const parser::Name &name,
if (name.symbol == nullptr) {
return;
}
// Traversal of the initializer was deferred to here so that the
// symbol being declared can be available for e.g.
// real, parameter :: x = tiny(x)
Walk(init.u);
Symbol &ultimate{name.symbol->GetUltimate()};
if (auto *details{ultimate.detailsIf<ObjectEntityDetails>()}) {
// TODO: check C762 - all bounds and type parameters of component