[flang] Address review comments

Change IsModule to a member function of Scope.

Make multiple PRIVATE statements in a derived type be a non-fatal error.

Original-commit: flang-compiler/f18@dd42dcd15a
Reviewed-on: https://github.com/flang-compiler/f18/pull/175
This commit is contained in:
Tim Keith 2018-09-07 09:06:27 -07:00
parent b168cc0b83
commit a1fff9af07
4 changed files with 9 additions and 12 deletions

View File

@ -36,7 +36,6 @@ using namespace parser::literals;
class MessageHandler;
static GenericSpec MapGenericSpec(const parser::GenericSpec &);
static bool IsModule(const Scope &);
// ImplicitRules maps initial character of identifier to the DeclTypeSpec
// representing the implicit type; std::nullopt if none.
@ -2127,7 +2126,7 @@ bool DeclarationVisitor::Pre(const parser::TypeAttrSpec::Extends &x) {
}
bool DeclarationVisitor::Pre(const parser::PrivateStmt &x) {
if (!IsModule(currScope().parent())) {
if (!currScope().parent().IsModule()) {
Say("PRIVATE is only allowed in a derived type that is"
" in a module"_err_en_US); // C766
} else if (derivedTypeInfo_.sawContains) {
@ -2136,7 +2135,7 @@ bool DeclarationVisitor::Pre(const parser::PrivateStmt &x) {
derivedTypeInfo_.privateComps = true;
} else {
Say("PRIVATE may not appear more than once in"
" derived type components"_err_en_US); // C738
" derived type components"_en_US); // C738
}
return false;
}
@ -2362,7 +2361,7 @@ bool ResolveNamesVisitor::Pre(const parser::ImportStmt &x) {
// Check C896 and C899: where IMPORT statements are allowed
switch (scope.kind()) {
case Scope::Kind::Module:
if (IsModule(scope)) {
if (scope.IsModule()) {
Say("IMPORT is not allowed in a module scoping unit"_err_en_US);
return false;
} else if (x.kind == common::ImportKind::None) {
@ -2886,12 +2885,6 @@ static GenericSpec MapGenericSpec(const parser::GenericSpec &genericSpec) {
genericSpec.u);
}
// Is this a scope for a module (and not a submodule)?
static bool IsModule(const Scope &scope) {
return scope.kind() == Scope::Kind::Module &&
!scope.symbol()->get<ModuleDetails>().isSubmodule();
}
static void PutIndent(std::ostream &os, int indent) {
for (int i = 0; i < indent; ++i) {
os << " ";

View File

@ -23,6 +23,10 @@ Scope Scope::globalScope{Scope::systemScope, Scope::Kind::Global, nullptr};
Symbols<1024> Scope::allSymbols;
bool Scope::IsModule() const {
return kind_ == Kind::Module && !symbol_->get<ModuleDetails>().isSubmodule();
}
Scope &Scope::MakeScope(Kind kind, Symbol *symbol) {
children_.emplace_back(*this, kind, symbol);
return children_.back();

View File

@ -60,6 +60,7 @@ public:
return parent_;
}
Kind kind() const { return kind_; }
bool IsModule() const; // only module, not submodule
Symbol *symbol() { return symbol_; }
const Symbol *symbol() const { return symbol_; }

View File

@ -53,8 +53,7 @@ module m4
type :: t1
private
sequence
!ERROR: PRIVATE may not appear more than once in derived type components
private
private ! not a fatal error
end type
!ERROR: A sequence type may not have the EXTENDS attribute
type, extends(t1) :: t2