-#include <iostream>
-
#include "type.h"
+#include "attr.h"
+#include <iostream>
+
namespace Fortran {
// Check that values specified for param defs are valid: they must match the
static void checkParams(
std::string kindOrLen, TypeParamDefs defs, std::map<Name, V> values) {
std::set<Name> validNames{};
- for (TypeParamDef def : defs) {
+ for (const TypeParamDef &def : defs) {
Name name = def.name();
validNames.insert(name);
if (!def.defaultValue() && values.find(name) == values.end()) {
o << '(';
int n = 0;
for (auto param : x.lenParams_) {
- if (n++) o << ", ";
+ if (n++) { o << ", "; }
o << param.name();
}
for (auto param : x.kindParams_) {
- if (n++) o << ", ";
+ if (n++) { o << ", "; }
o << param.name();
}
o << ')';
for (auto param : x.kindParams_) {
o << " " << param.type() << ", KIND :: " << param.name() << "\n";
}
- if (x.private_) o << " PRIVATE\n";
- if (x.sequence_) o << " SEQUENCE\n";
+ if (x.private_) { o << " PRIVATE\n"; }
+ if (x.sequence_) { o << " SEQUENCE\n"; }
// components
return o << "END TYPE\n";
}
o << '(';
int n = 0;
for (auto pair : x.kindParamValues_) {
- if (n++) o << ", ";
+ if (n++) { o << ", "; }
o << pair.first << '=' << pair.second;
}
for (auto pair : x.lenParamValues_) {
- if (n++) o << ", ";
+ if (n++) { o << ", "; }
o << pair.first << '=' << pair.second;
}
o << ')';
CHECK(x.ub_.isAssumed());
o << "..";
} else {
- if (!x.lb_.isDeferred()) o << x.lb_;
+ if (!x.lb_.isDeferred()) { o << x.lb_; }
o << ':';
- if (!x.ub_.isDeferred()) o << x.ub_;
+ if (!x.ub_.isDeferred()) { o << x.ub_; }
}
return o;
}
#ifndef FORTRAN_TYPE_H_
#define FORTRAN_TYPE_H_
+#include "attr.h"
+#include "idioms.h"
#include <algorithm>
#include <list>
#include <map>
#include <string>
#include <vector>
-#include "attr.h"
-#include "idioms.h"
-
/*
Type specs are represented by a class hierarchy rooted at TypeSpec. Only the
class IntrinsicTypeSpec : public TypeSpec {
public:
- const KindParamValue &kind() { return kind_; }
+ const KindParamValue &kind() const { return kind_; }
protected:
IntrinsicTypeSpec(KindParamValue kind) : kind_{kind} {}
public:
static const int DefaultKind = 0;
CharacterTypeSpec(LenParamValue len, KindParamValue kind = DefaultKind)
- : IntrinsicTypeSpec(kind), len_{len} {}
+ : IntrinsicTypeSpec{kind}, len_{len} {}
private:
const LenParamValue len_;
TypeParamDef(const Name &name, const IntegerTypeSpec &type,
const std::optional<IntConst> &defaultValue = {})
: name_{name}, type_{type}, defaultValue_{defaultValue} {};
- const Name &name() { return name_; }
- const IntegerTypeSpec &type() { return type_; }
- const std::optional<IntConst> &defaultValue() { return defaultValue_; }
+ const Name &name() const { return name_; }
+ const IntegerTypeSpec &type() const { return type_; }
+ const std::optional<IntConst> &defaultValue() const { return defaultValue_; }
private:
const Name name_;
// Instantiation of a DerivedTypeDef with kind and len parameter values
class DerivedTypeSpec : public TypeSpec {
public:
- DerivedTypeSpec(DerivedTypeDef def, KindParamValues kindParamValues = {},
- LenParamValues lenParamValues = {});
+ DerivedTypeSpec(DerivedTypeDef def, KindParamValues kindParamValues{},
+ LenParamValues lenParamValues{});
private:
const DerivedTypeDef def_;
class DeclTypeSpec {
public:
// intrinsic-type-spec or TYPE(intrinsic-type-spec)
- static const DeclTypeSpec makeIntrinsic(
+ static DeclTypeSpec makeIntrinsic(
const IntrinsicTypeSpec *intrinsicTypeSpec) {
- return DeclTypeSpec(Intrinsic, intrinsicTypeSpec, nullptr);
+ return DeclTypeSpec{Intrinsic, intrinsicTypeSpec};
}
// TYPE(derived-type-spec)
- static const DeclTypeSpec makeTypeDerivedType(
+ static DeclTypeSpec makeTypeDerivedType(
const DerivedTypeSpec *derivedTypeSpec) {
- return DeclTypeSpec(TypeDerived, nullptr, derivedTypeSpec);
+ return DeclTypeSpec{TypeDerived, nullptr, derivedTypeSpec};
}
// CLASS(derived-type-spec)
- static const DeclTypeSpec makeClassDerivedType(
+ static DeclTypeSpec makeClassDerivedType(
const DerivedTypeSpec *derivedTypeSpec) {
- return DeclTypeSpec(ClassDerived, nullptr, derivedTypeSpec);
- }
- // TYPE(*) or CLASS(*)
- static const DeclTypeSpec makeUnlimitedPoly() {
- return DeclTypeSpec(UnlimitedPoly, nullptr, nullptr);
+ return DeclTypeSpec{ClassDerived, nullptr, derivedTypeSpec};
}
+ // TYPE(*)
+ static DeclTypeSpec makeTypeStar() { return DeclTypeSpec{TypeStar}; }
+ // CLASS(*)
+ static DeclTypeSpec makeClassStar() { return DeclTypeSpec{ClassStar}; }
- enum Category { Intrinsic, TypeDerived, ClassDerived, UnlimitedPoly };
+ enum Category { Intrinsic, TypeDerived, ClassDerived, TypeStar, ClassStar };
Category category() const { return category_; }
const IntrinsicTypeSpec &intrinsicTypeSpec() const {
return *intrinsicTypeSpec_;
const DerivedTypeSpec &derivedTypeSpec() const { return *derivedTypeSpec_; }
private:
- DeclTypeSpec(Category category, const IntrinsicTypeSpec *intrinsicTypeSpec,
- const DerivedTypeSpec *derivedTypeSpec)
+ DeclTypeSpec(Category category,
+ const IntrinsicTypeSpec *intrinsicTypeSpec = nullptr,
+ const DerivedTypeSpec *derivedTypeSpec = nullptr)
: category_{category}, intrinsicTypeSpec_{intrinsicTypeSpec},
derivedTypeSpec_{derivedTypeSpec} {}
const Category category_;
const DerivedTypeSpec *const derivedTypeSpec_;
};
-struct DataComponentDef {
+class DataComponentDef {
+public:
// component-array-spec
// coarray-spec
DataComponentDef(
- const DeclTypeSpec type, const Name &name, const Attrs &attrs)
+ const DeclTypeSpec &type, const Name &name, const Attrs &attrs)
: type_{type}, name_{name}, attrs_{attrs} {
checkAttrs("DataComponentDef", attrs,
Attrs{Attr::PUBLIC, Attr::PRIVATE, Attr::ALLOCATABLE, Attr::CONTIGUOUS,