class Semantics {
public:
explicit Semantics(SemanticsContext &context, parser::Program &program,
- parser::CharBlock charBlock, bool debugModuleWriter = false)
+ bool debugModuleWriter = false)
: context_{context}, program_{program} {
context.set_debugModuleWriter(debugModuleWriter);
- context.globalScope().AddSourceRange(charBlock);
}
SemanticsContext &context() const { return context_; }
// Prepare semantics
setSemantics(std::make_unique<Fortran::semantics::Semantics>(
ci.invocation().semanticsContext(), parseTree,
- ci.parsing().cooked().AsCharBlock(), ci.invocation().debugModuleDir()));
+ ci.invocation().debugModuleDir()));
auto &semantics = this->semantics();
// Run semantic checks
void IoChecker::CheckForPureSubprogram() const { // C1597
CHECK(context_.location());
- if (FindPureProcedureContaining(context_.FindScope(*context_.location()))) {
- context_.Say("External I/O is not allowed in a pure subprogram"_err_en_US);
+ if (const Scope *
+ scope{context_.globalScope().FindScope(*context_.location())}) {
+ if (FindPureProcedureContaining(*scope)) {
+ context_.Say(
+ "External I/O is not allowed in a pure subprogram"_err_en_US);
+ }
}
}
}
void Scope::AddSourceRange(const parser::CharBlock &source) {
- for (auto *scope = this; !scope->IsGlobal(); scope = &scope->parent()) {
+ for (auto *scope{this}; !scope->IsGlobal(); scope = &scope->parent()) {
scope->sourceRange_.ExtendToCover(source);
}
}
// N.B. We only need to examine the innermost containing program unit
// because an internal subprogram of a pure subprogram must also
// be pure (C1592).
- const Scope &scope{GetProgramUnitContaining(start)};
- return IsPureProcedure(scope) ? &scope : nullptr;
+ if (start.IsGlobal()) {
+ return nullptr;
+ } else {
+ const Scope &scope{GetProgramUnitContaining(start)};
+ return IsPureProcedure(scope) ? &scope : nullptr;
+ }
}
static bool MightHaveCompatibleDerivedtypes(
if (!driver.debugNoSemantics || driver.dumpSymbols ||
driver.dumpUnparseWithSymbols || driver.getDefinition ||
driver.getSymbolsSources) {
- Fortran::semantics::Semantics semantics{semanticsContext, parseTree,
- parsing.cooked().AsCharBlock(), driver.debugModuleWriter};
+ Fortran::semantics::Semantics semantics{
+ semanticsContext, parseTree, driver.debugModuleWriter};
semantics.Perform();
Fortran::semantics::RuntimeDerivedTypeTables tables;
if (!semantics.AnyFatalError()) {