[flang] Change WhyNotModifiable to return optional

One overload of WhyNotModifiable returned an optional message while the
other returns a unique_ptr. Change the latter to be consistent with the
former and other message-returning functions in this file.

Also, reorder the if clauses to reduce the level of indentation.

Original-commit: flang-compiler/f18@864e9cfc7e
Reviewed-on: https://github.com/flang-compiler/f18/pull/1050
Tree-same-pre-rewrite: false
This commit is contained in:
Tim Keith 2020-03-05 12:56:30 -08:00
parent 0b130278a0
commit 2cc21cecf2
3 changed files with 17 additions and 24 deletions

View File

@ -167,7 +167,7 @@ bool IsAssumedLengthExternalCharacterFunction(const Symbol &);
// Is the symbol modifiable in this scope
std::optional<parser::MessageFixedText> WhyNotModifiable(
const Symbol &, const Scope &);
std::unique_ptr<parser::Message> WhyNotModifiable(SourceName, const SomeExpr &,
std::optional<parser::Message> WhyNotModifiable(SourceName, const SomeExpr &,
const Scope &, bool vectorSubscriptIsOk = false);
const Symbol *IsExternalInPureContext(const Symbol &, const Scope &);
bool HasCoarray(const parser::Expr &);

View File

@ -329,13 +329,12 @@ static void CheckExplicitDataArg(const characteristics::DummyDataObject &dummy,
}
if (reason && scope) {
bool vectorSubscriptIsOk{isElemental || dummyIsValue}; // 15.5.2.4(21)
std::unique_ptr<parser::Message> why{
WhyNotModifiable(messages.at(), actual, *scope, vectorSubscriptIsOk)};
if (why.get()) {
if (auto why{WhyNotModifiable(
messages.at(), actual, *scope, vectorSubscriptIsOk)}) {
if (auto *msg{messages.Say(
"Actual argument associated with %s %s must be definable"_err_en_US,
reason, dummyName)}) {
msg->Attach(std::move(why));
msg->Attach(*why);
}
}
}

View File

@ -789,29 +789,23 @@ std::optional<parser::MessageFixedText> WhyNotModifiable(
}
}
std::unique_ptr<parser::Message> WhyNotModifiable(parser::CharBlock at,
std::optional<parser::Message> WhyNotModifiable(parser::CharBlock at,
const SomeExpr &expr, const Scope &scope, bool vectorSubscriptIsOk) {
if (evaluate::IsVariable(expr)) {
if (auto dataRef{evaluate::ExtractDataRef(expr)}) {
if (!vectorSubscriptIsOk && evaluate::HasVectorSubscript(expr)) {
return std::make_unique<parser::Message>(
at, "variable has a vector subscript"_en_US);
} else {
const Symbol &symbol{dataRef->GetFirstSymbol()};
if (auto maybeWhy{WhyNotModifiable(symbol, scope)}) {
return std::make_unique<parser::Message>(symbol.name(),
parser::MessageFormattedText{
std::move(*maybeWhy), symbol.name()});
}
}
} else {
// reference to function returning POINTER
if (!evaluate::IsVariable(expr)) {
return parser::Message{at, "Expression is not a variable"_en_US};
} else if (auto dataRef{evaluate::ExtractDataRef(expr)}) {
if (!vectorSubscriptIsOk && evaluate::HasVectorSubscript(expr)) {
return parser::Message{at, "Variable has a vector subscript"_en_US};
}
const Symbol &symbol{dataRef->GetFirstSymbol()};
if (auto maybeWhy{WhyNotModifiable(symbol, scope)}) {
return parser::Message{symbol.name(),
parser::MessageFormattedText{std::move(*maybeWhy), symbol.name()}};
}
} else {
return std::make_unique<parser::Message>(
at, "expression is not a variable"_en_US);
// reference to function returning POINTER
}
return {};
return std::nullopt;
}
class ImageControlStmtHelper {