[flang] Add Symbol::IsArray()

Add and use IsArray for symbols, meaning: it is an object entity
with shape.

Original-commit: flang-compiler/f18@31c1a37f03
Reviewed-on: https://github.com/flang-compiler/f18/pull/277
Tree-same-pre-rewrite: false
This commit is contained in:
Tim Keith 2019-02-06 10:28:31 -08:00
parent da46e49a01
commit 7c4e86b7e2
3 changed files with 13 additions and 11 deletions

View File

@ -2358,11 +2358,9 @@ void DeclarationVisitor::CheckAccessibility(
void DeclarationVisitor::CheckScalarIntegerType(const parser::Name &name) {
if (name.symbol != nullptr) {
const Symbol &symbol{*name.symbol};
if (const auto *details{symbol.detailsIf<ObjectEntityDetails>()}) {
if (details->IsArray()) {
Say(name, "Variable '%s' is not scalar"_err_en_US);
return;
}
if (symbol.IsArray()) {
Say(name, "Variable '%s' is not scalar"_err_en_US);
return;
}
if (auto *type{symbol.GetType()}) {
if (!type->IsNumeric(TypeCategory::Integer)) {
@ -2536,7 +2534,7 @@ Symbol &DeclarationVisitor::DeclareObjectEntity(
SetType(name, *type);
}
if (!arraySpec().empty()) {
if (!details->shape().empty()) {
if (details->IsArray()) {
Say(name,
"The dimensions of '%s' have already been declared"_err_en_US);
} else {
@ -3372,11 +3370,9 @@ void ConstructVisitor::Post(const parser::ConcurrentControl &x) {
if (auto *type{prev->GetType()}) {
symbol.SetType(*type);
}
if (const auto *details{prev->detailsIf<ObjectEntityDetails>()}) {
if (details->IsArray()) {
SayWithDecl(name, *prev, "Index variable '%s' is not scalar"_err_en_US);
return;
}
if (prev->IsArray()) {
SayWithDecl(name, *prev, "Index variable '%s' is not scalar"_err_en_US);
return;
}
}
CheckScalarIntegerType(name);

View File

@ -214,6 +214,11 @@ void Symbol::SetType(const DeclTypeSpec &type) {
details_);
}
bool Symbol::IsArray() const {
const auto *details{std::get_if<ObjectEntityDetails>(&details_)};
return details && details->IsArray();
}
bool Symbol::IsSubprogram() const {
return std::visit(
common::visitors{

View File

@ -452,6 +452,7 @@ public:
void SetType(const DeclTypeSpec &);
bool IsArray() const;
bool IsSubprogram() const;
bool IsSeparateModuleProc() const;
bool HasExplicitInterface() const {