mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-25 11:06:07 +00:00
[flang] Address some of the review comments.
Original-commit: flang-compiler/f18@ecdffa3745 Reviewed-on: https://github.com/flang-compiler/f18/pull/3 Tree-same-pre-rewrite: false
This commit is contained in:
parent
59157ff1a5
commit
3bdae798f2
@ -1,4 +1,5 @@
|
||||
#include "attr.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
@ -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;
|
||||
|
@ -1,12 +1,11 @@
|
||||
#ifndef FORTRAN_ATTR_H_
|
||||
#define FORTRAN_ATTR_H_
|
||||
|
||||
#include "idioms.h"
|
||||
#include <iostream>
|
||||
#include <set>
|
||||
#include <string>
|
||||
|
||||
#include "idioms.h"
|
||||
|
||||
namespace Fortran {
|
||||
|
||||
// All available attributes.
|
||||
|
@ -1,7 +1,8 @@
|
||||
#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
|
||||
@ -11,7 +12,7 @@ template<typename V>
|
||||
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()) {
|
||||
@ -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;
|
||||
}
|
||||
|
51
flang/type.h
51
flang/type.h
@ -1,6 +1,8 @@
|
||||
#ifndef FORTRAN_TYPE_H_
|
||||
#define FORTRAN_TYPE_H_
|
||||
|
||||
#include "attr.h"
|
||||
#include "idioms.h"
|
||||
#include <algorithm>
|
||||
#include <list>
|
||||
#include <map>
|
||||
@ -11,9 +13,6 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#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<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_;
|
||||
@ -268,8 +267,8 @@ using LenParamValues = std::map<Name, LenParamValue>;
|
||||
// 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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user