// Fortran has five kinds of intrinsic data, and the derived types.
ENUM_CLASS(TypeCategory, Integer, Real, Complex, Character, Logical, Derived)
+// Kinds of IMPORT statements. Default means IMPORT or IMPORT :: names.
+ENUM_CLASS(ImportKind, Default, Only, None, All)
+
} // namespace Fortran::common
#endif // FORTRAN_COMMON_FORTRAN_H_
// IMPORT [[::] import-name-list] |
// IMPORT , ONLY : import-name-list | IMPORT , NONE | IMPORT , ALL
TYPE_CONTEXT_PARSER("IMPORT statement"_en_US,
- construct<ImportStmt>("IMPORT , ONLY :" >> pure(ImportStmt::Kind::Only),
+ construct<ImportStmt>("IMPORT , ONLY :" >> pure(common::ImportKind::Only),
nonemptyList(name)) ||
construct<ImportStmt>(
- "IMPORT , NONE" >> pure(ImportStmt::Kind::None)) ||
- construct<ImportStmt>("IMPORT , ALL" >> pure(ImportStmt::Kind::All)) ||
+ "IMPORT , NONE" >> pure(common::ImportKind::None)) ||
+ construct<ImportStmt>(
+ "IMPORT , ALL" >> pure(common::ImportKind::All)) ||
construct<ImportStmt>(
"IMPORT" >> maybe("::"_tok) >> optionalList(name)))
namespace Fortran::parser {
// R867
-ImportStmt::ImportStmt(Kind &&k, std::list<Name> &&n)
+ImportStmt::ImportStmt(common::ImportKind &&k, std::list<Name> &&n)
: kind{k}, names(std::move(n)) {
- CHECK(kind == Kind::Default || kind == Kind::Only || names.empty());
+ CHECK(kind == common::ImportKind::Default ||
+ kind == common::ImportKind::Only || names.empty());
}
// R901 designator
#include "format-specification.h"
#include "message.h"
#include "provenance.h"
+#include "../common/fortran.h"
#include "../common/idioms.h"
#include "../common/indirection.h"
#include <cinttypes>
// IMPORT , ONLY : import-name-list | IMPORT , NONE | IMPORT , ALL
struct ImportStmt {
BOILERPLATE(ImportStmt);
- ENUM_CLASS(Kind, Default, Only, None, All)
- ImportStmt(Kind &&k) : kind{k} {}
+ ImportStmt(common::ImportKind &&k) : kind{k} {}
ImportStmt(std::list<Name> &&n) : names(std::move(n)) {}
- ImportStmt(Kind &&, std::list<Name> &&);
- Kind kind{Kind::Default};
+ ImportStmt(common::ImportKind &&, std::list<Name> &&);
+ common::ImportKind kind{common::ImportKind::Default};
std::list<Name> names;
};
#include "characters.h"
#include "parse-tree-visitor.h"
#include "parse-tree.h"
+#include "../common/fortran.h"
#include "../common/idioms.h"
#include "../common/indirection.h"
#include <algorithm>
void Unparse(const ImportStmt &x) { // R867
Word("IMPORT");
switch (x.kind) {
- case ImportStmt::Kind::Default: Walk(" :: ", x.names, ", "); break;
- case ImportStmt::Kind::Only:
+ case common::ImportKind::Default: Walk(" :: ", x.names, ", "); break;
+ case common::ImportKind::Only:
Put(", "), Word("ONLY: ");
Walk(x.names, ", ");
break;
- case ImportStmt::Kind::None: Word(", NONE"); break;
- case ImportStmt::Kind::All: Word(", ALL"); break;
+ case common::ImportKind::None: Word(", NONE"); break;
+ case common::ImportKind::All: Word(", ALL"); break;
default: CRASH_NO_CASE;
}
}
class MessageHandler;
static GenericSpec MapGenericSpec(const parser::GenericSpec &);
-static Scope::ImportKind MapImportKind(parser::ImportStmt::Kind);
// ImplicitRules maps initial character of identifier to the DeclTypeSpec*
// representing the implicit type; nullptr if none.
}
bool ResolveNamesVisitor::Pre(const parser::ImportStmt &x) {
- auto kind{MapImportKind(x.kind)};
auto &scope{currScope()};
// Check C896 and C899: where IMPORT statements are allowed
switch (scope.kind()) {
if (!scope.symbol()->get<ModuleDetails>().isSubmodule()) {
Say("IMPORT is not allowed in a module scoping unit"_err_en_US);
return false;
- } else if (kind == Scope::ImportKind::None) {
+ } else if (x.kind == common::ImportKind::None) {
Say("IMPORT,NONE is not allowed in a submodule scoping unit"_err_en_US);
return false;
}
break;
default:;
}
- if (auto error{scope.SetImportKind(kind)}) {
+ if (auto error{scope.SetImportKind(x.kind)}) {
Say(std::move(*error));
}
for (auto &name : x.names) {
void ResolveNamesVisitor::CheckImports() {
auto &scope{currScope()};
- switch (scope.importKind()) {
- case Scope::ImportKind::None: break;
- case Scope::ImportKind::All:
+ switch (scope.GetImportKind()) {
+ case common::ImportKind::None: break;
+ case common::ImportKind::All:
// C8102: all entities in host must not be hidden
for (const auto &pair : scope.parent()) {
auto &name{pair.first};
}
}
break;
- case Scope::ImportKind::Default:
- case Scope::ImportKind::Only:
+ case common::ImportKind::Default:
+ case common::ImportKind::Only:
// C8102: entities named in IMPORT must not be hidden
for (auto &name : scope.importNames()) {
CheckImport(name, name);
genericSpec.u);
}
-static Scope::ImportKind MapImportKind(parser::ImportStmt::Kind kind) {
- switch (kind) {
- case parser::ImportStmt::Kind::Default: return Scope::ImportKind::Default;
- case parser::ImportStmt::Kind::Only: return Scope::ImportKind::Only;
- case parser::ImportStmt::Kind::None: return Scope::ImportKind::None;
- case parser::ImportStmt::Kind::All: return Scope::ImportKind::All;
- default: CRASH_NO_CASE;
- }
-}
-
static void PutIndent(std::ostream &os, int indent) {
for (int i = 0; i < indent; ++i) {
os << " ";
return derivedTypeSpecs_.back();
}
-Scope::ImportKind Scope::importKind() const {
+Scope::ImportKind Scope::GetImportKind() const {
if (importKind_) {
return *importKind_;
}
if (kind_ == Kind::Global) {
return false;
}
- switch (importKind()) {
+ switch (GetImportKind()) {
case ImportKind::None: return false;
case ImportKind::All:
case ImportKind::Default: return true;
#include "attr.h"
#include "symbol.h"
+#include "../common/fortran.h"
#include "../common/idioms.h"
#include "../parser/message.h"
#include <list>
static Scope globalScope; // contains program-units
ENUM_CLASS(Kind, System, Global, Module, MainProgram, Subprogram, DerivedType)
- ENUM_CLASS(ImportKind, Default, Only, None, All);
+ using ImportKind = common::ImportKind;
Scope(Scope &parent, Kind kind, Symbol *symbol)
: parent_{parent}, kind_{kind}, symbol_{symbol} {
// that are referenced by SourceName objects.
void set_chars(std::string &&chars) { chars_ = std::move(chars); }
- ImportKind importKind() const;
+ ImportKind GetImportKind() const;
// Names appearing in IMPORT statements in this scope
std::set<SourceName> importNames() const { return importNames_; }