From 3bdae798f2d3c73d67d27590b37bca5dcdfb03f1 Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Wed, 7 Feb 2018 13:57:58 -0800 Subject: [PATCH] [flang] Address some of the review comments. Original-commit: flang-compiler/f18@ecdffa374590f5d36c9c3ab22d6108c1c128e596 Reviewed-on: https://github.com/flang-compiler/f18/pull/3 Tree-same-pre-rewrite: false --- flang/attr.cc | 3 ++- flang/attr.h | 3 +-- flang/type.cc | 23 ++++++++++++----------- flang/type.h | 51 ++++++++++++++++++++++++++------------------------- 4 files changed, 41 insertions(+), 39 deletions(-) diff --git a/flang/attr.cc b/flang/attr.cc index cc9564c..859642d 100644 --- a/flang/attr.cc +++ b/flang/attr.cc @@ -1,4 +1,5 @@ #include "attr.h" + #include #include @@ -32,7 +33,7 @@ std::ostream &operator<<(std::ostream &o, Attr attr) { std::ostream &operator<<(std::ostream &o, const Attrs &attrs) { int n = 0; for (auto attr : attrs) { - if (n++) o << ", "; + if (n++) { o << ", "; } o << attr; } return o; diff --git a/flang/attr.h b/flang/attr.h index e1d7aca..f510974 100644 --- a/flang/attr.h +++ b/flang/attr.h @@ -1,12 +1,11 @@ #ifndef FORTRAN_ATTR_H_ #define FORTRAN_ATTR_H_ +#include "idioms.h" #include #include #include -#include "idioms.h" - namespace Fortran { // All available attributes. diff --git a/flang/type.cc b/flang/type.cc index 6904be5..3b5812a 100644 --- a/flang/type.cc +++ b/flang/type.cc @@ -1,7 +1,8 @@ -#include - #include "type.h" +#include "attr.h" +#include + namespace Fortran { // Check that values specified for param defs are valid: they must match the @@ -11,7 +12,7 @@ template static void checkParams( std::string kindOrLen, TypeParamDefs defs, std::map values) { std::set 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()) { @@ -105,11 +106,11 @@ std::ostream &operator<<(std::ostream &o, const DerivedTypeDef &x) { 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 << ')'; @@ -121,8 +122,8 @@ std::ostream &operator<<(std::ostream &o, const DerivedTypeDef &x) { 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"; } @@ -141,11 +142,11 @@ std::ostream &operator<<(std::ostream &o, const DerivedTypeSpec &x) { 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 << ')'; @@ -173,9 +174,9 @@ std::ostream &operator<<(std::ostream &o, const ShapeSpec &x) { 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; } diff --git a/flang/type.h b/flang/type.h index 1553c73..0a198f7 100644 --- a/flang/type.h +++ b/flang/type.h @@ -1,6 +1,8 @@ #ifndef FORTRAN_TYPE_H_ #define FORTRAN_TYPE_H_ +#include "attr.h" +#include "idioms.h" #include #include #include @@ -11,9 +13,6 @@ #include #include -#include "attr.h" -#include "idioms.h" - /* Type specs are represented by a class hierarchy rooted at TypeSpec. Only the @@ -110,7 +109,7 @@ TypeSpec::~TypeSpec() {} class IntrinsicTypeSpec : public TypeSpec { public: - const KindParamValue &kind() { return kind_; } + const KindParamValue &kind() const { return kind_; } protected: IntrinsicTypeSpec(KindParamValue kind) : kind_{kind} {} @@ -219,7 +218,7 @@ class CharacterTypeSpec : public IntrinsicTypeSpec { public: static const int DefaultKind = 0; CharacterTypeSpec(LenParamValue len, KindParamValue kind = DefaultKind) - : IntrinsicTypeSpec(kind), len_{len} {} + : IntrinsicTypeSpec{kind}, len_{len} {} private: const LenParamValue len_; @@ -232,9 +231,9 @@ public: TypeParamDef(const Name &name, const IntegerTypeSpec &type, const std::optional &defaultValue = {}) : name_{name}, type_{type}, defaultValue_{defaultValue} {}; - const Name &name() { return name_; } - const IntegerTypeSpec &type() { return type_; } - const std::optional &defaultValue() { return defaultValue_; } + const Name &name() const { return name_; } + const IntegerTypeSpec &type() const { return type_; } + const std::optional &defaultValue() const { return defaultValue_; } private: const Name name_; @@ -268,8 +267,8 @@ using LenParamValues = std::map; // 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_; @@ -281,26 +280,26 @@ private: 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_; @@ -308,8 +307,9 @@ public: 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_; @@ -317,11 +317,12 @@ private: 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, -- 2.7.4