const Scope *FindContainingSubprogram(const Scope &start) {
const Scope *scope{&start};
- while (scope->kind() != Scope::Kind::Global) {
+ while (!scope->IsGlobal()) {
switch (scope->kind()) {
case Scope::Kind::MainProgram:
case Scope::Kind::Subprogram: return scope;
PutSymbol(typeBindings, symbol);
}
if (auto str{typeBindings.str()}; !str.empty()) {
- CHECK(scope.kind() == Scope::Kind::DerivedType);
+ CHECK(scope.IsDerivedType());
decls_ << "contains\n" << str;
}
}
// Do symbols this one depends on; then add to need_
void SubprogramSymbolCollector::DoSymbol(const Symbol &symbol) {
const auto &scope{symbol.owner()};
- if (scope != scope_ && scope.kind() != Scope::Kind::DerivedType) {
+ if (scope != scope_ && !scope.IsDerivedType()) {
if (scope != scope_.parent()) {
useSet_.insert(&symbol);
} else if (isInterface_) {
if (!symbol.has<UseDetails>()) {
DoType(symbol.GetType());
}
- if (scope.kind() != Scope::Kind::DerivedType) {
+ if (!scope.IsDerivedType()) {
need_.push_back(&symbol);
}
}
currObject_.symbol = name.symbol;
parser::MessageFixedText msg{"", 0};
const Symbol &symbol{*name.symbol};
- if (symbol.owner().kind() == Scope::Kind::DerivedType) { // C8107
+ if (symbol.owner().IsDerivedType()) { // C8107
msg = "Derived type component '%s'"
" is not allowed in an equivalence set"_err_en_US;
} else if (symbol.IsDummy()) { // C8106
Scope &ScopeHandler::InclusiveScope() {
for (auto *scope{&currScope()};; scope = &scope->parent()) {
- if (scope->kind() != Scope::Kind::Block &&
- scope->kind() != Scope::Kind::DerivedType) {
+ if (scope->kind() != Scope::Kind::Block && !scope->IsDerivedType()) {
return *scope;
}
}
}
Scope &ScopeHandler::GlobalScope() {
for (auto *scope = currScope_; scope; scope = &scope->parent()) {
- if (scope->kind() == Scope::Kind::Global) {
+ if (scope->IsGlobal()) {
return *scope;
}
}
if (kind != Scope::Kind::Block) {
ImplicitRulesVisitor::BeginScope(scope);
}
- if (kind != Scope::Kind::DerivedType) {
+ if (!currScope_->IsDerivedType()) {
if (auto *symbol{scope.symbol()}) {
// Create a dummy symbol so we can't create another one with the same
// name. It might already be there if we previously pushed the scope.
// Find a component or type parameter by name in a derived type or its parents.
Symbol *ScopeHandler::FindInTypeOrParents(const Scope &scope, SourceName name) {
- if (scope.kind() == Scope::Kind::DerivedType) {
+ if (scope.IsDerivedType()) {
if (Symbol * symbol{FindInScope(scope, name)}) {
return symbol;
}
}
// component must be in a module/submodule because of PRIVATE:
const Scope *moduleScope{&symbol.owner()};
- CHECK(moduleScope->kind() == Scope::Kind::DerivedType);
- while (moduleScope->kind() != Scope::Kind::Module &&
- moduleScope->kind() != Scope::Kind::Global) {
+ CHECK(moduleScope->IsDerivedType());
+ while (
+ moduleScope->kind() != Scope::Kind::Module && !moduleScope->IsGlobal()) {
moduleScope = &moduleScope->parent();
}
if (moduleScope->kind() == Scope::Kind::Module) {
- for (auto *scope{&currScope()}; scope->kind() != Scope::Kind::Global;
+ for (auto *scope{&currScope()}; !scope->IsGlobal();
scope = &scope->parent()) {
if (scope == moduleScope) {
return true;
Symbol *DeclarationVisitor::MakeTypeSymbol(
const SourceName &name, Details &&details) {
Scope &derivedType{currScope()};
- CHECK(derivedType.kind() == Scope::Kind::DerivedType);
+ CHECK(derivedType.IsDerivedType());
if (auto *symbol{FindInScope(derivedType, name)}) {
Say2(name,
"Type parameter, component, or procedure binding '%s'"
bool DeclarationVisitor::OkToAddComponent(
const parser::Name &name, const Symbol *extends) {
for (const Scope *scope{&currScope()}; scope != nullptr;) {
- CHECK(scope->kind() == Scope::Kind::DerivedType);
+ CHECK(scope->IsDerivedType());
if (auto *prev{FindInScope(*scope, name)}) {
auto msg{""_en_US};
if (extends != nullptr) {
Say("IMPORT is not allowed in a main program scoping unit"_err_en_US);
return false;
case Scope::Kind::Subprogram:
- if (scope.parent().kind() == Scope::Kind::Global) {
+ if (scope.parent().IsGlobal()) {
Say("IMPORT is not allowed in an external subprogram scoping unit"_err_en_US);
return false;
}
}
}
for (Scope &childScope : currScope().children()) {
- if (childScope.kind() == Scope::Kind::DerivedType && childScope.symbol()) {
+ if (childScope.IsDerivedType() && childScope.symbol()) {
FinishDerivedType(childScope);
}
}
// Perform checks on procedure bindings of this type
void ResolveNamesVisitor::FinishDerivedType(Scope &scope) {
- CHECK(scope.kind() == Scope::Kind::DerivedType);
+ CHECK(scope.IsDerivedType());
for (auto &pair : scope) {
Symbol &comp{*pair.second};
std::visit(
}
}
Symbol *Scope::FindSymbol(const SourceName &name) const {
- if (kind() == Kind::DerivedType) {
+ if (IsDerivedType()) {
return parent_.FindSymbol(name);
}
auto it{find(name)};
void Scope::set_chars(parser::CookedSource &cooked) {
CHECK(kind_ == Kind::Module);
- CHECK(parent_.kind_ == Kind::Global || parent_.IsModuleFile());
+ CHECK(parent_.IsGlobal() || parent_.IsModuleFile());
CHECK(symbol_ != nullptr);
CHECK(symbol_->test(Symbol::Flag::ModFile));
// TODO: Preserve the CookedSource rather than acquiring its string.
// true if name can be imported or host-associated from parent scope.
bool Scope::CanImport(const SourceName &name) const {
- if (kind_ == Kind::Global) {
+ if (IsGlobal()) {
return false;
}
switch (GetImportKind()) {
Scope *Scope::FindScope(parser::CharBlock source) {
bool isContained{sourceRange_.Contains(source)};
- if (!isContained && kind_ != Kind::Global && !IsModuleFile()) {
+ if (!isContained && !IsGlobal() && !IsModuleFile()) {
return nullptr;
}
for (auto &child : children_) {
}
bool Scope::IsParameterizedDerivedType() const {
- if (kind_ != Kind::DerivedType) {
+ if (!IsDerivedType()) {
return false;
}
if (const Scope * parent{GetDerivedTypeParent()}) {
DeclTypeSpec type{category, spec};
if (const auto *result{FindType(type)}) {
return result;
- } else if (kind() == Kind::Global) {
+ } else if (IsGlobal()) {
return nullptr;
} else {
return parent().FindInstantiatedDerivedType(spec, category);
return parent_;
}
Kind kind() const { return kind_; }
+ bool IsGlobal() const { return kind_ == Kind::Global; }
bool IsModule() const; // only module, not submodule
+ bool IsDerivedType() const { return kind_ == Kind::DerivedType; }
bool IsParameterizedDerivedType() const;
Symbol *symbol() { return symbol_; }
const Symbol *symbol() const { return symbol_; }
bool Symbol::IsFromModFile() const {
return test(Flag::ModFile) ||
- (owner_->kind() != Scope::Kind::Global &&
- owner_->symbol()->IsFromModFile());
+ (!owner_->IsGlobal() && owner_->symbol()->IsFromModFile());
}
ObjectEntityDetails::ObjectEntityDetails(EntityDetails &&d)
// parent scopes. For scopes without corresponding symbols, use the kind
// with an index (e.g. Block1, Block2, etc.).
static void DumpUniqueName(std::ostream &os, const Scope &scope) {
- if (scope.kind() != Scope::Kind::Global) {
+ if (!scope.IsGlobal()) {
DumpUniqueName(os, scope.parent());
os << '/';
if (auto *scopeSymbol{scope.symbol()};
}
const Symbol *FindCommonBlockContaining(const Symbol &object) {
- for (const Scope *scope{&object.owner()};
- scope->kind() != Scope::Kind::Global; scope = &scope->parent()) {
+ for (const Scope *scope{&object.owner()}; !scope->IsGlobal();
+ scope = &scope->parent()) {
if (const Symbol * block{FindCommonBlockInScope(*scope, object)}) {
return block;
}
const Scope *maybeAncestor, const Scope &maybeDescendent) {
if (maybeAncestor != nullptr) {
const Scope *scope{&maybeDescendent};
- while (scope->kind() != Scope::Kind::Global) {
+ while (!scope->IsGlobal()) {
scope = &scope->parent();
if (scope == maybeAncestor) {
return true;
static const Symbol *FindPointerComponent(
const Scope &scope, std::set<const Scope *> &visited) {
- if (scope.kind() != Scope::Kind::DerivedType) {
+ if (!scope.IsDerivedType()) {
return nullptr;
}
if (!visited.insert(&scope).second) {
DeclTypeSpec type{category, spec};
if (const auto *found{scope.FindType(type)}) {
return found;
- } else if (scope.kind() == Scope::Kind::Global) {
+ } else if (scope.IsGlobal()) {
return nullptr;
} else {
return FindInstantiatedDerivedType(scope.parent(), spec, category);
ReplaceScope(scope);
}
void DerivedTypeSpec::ReplaceScope(const Scope &scope) {
- CHECK(scope.kind() == Scope::Kind::DerivedType);
+ CHECK(scope.IsDerivedType());
scope_ = &scope;
}