From 1b50885a3f1758cf25ea7a9bd1b1ee510da01760 Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Tue, 4 Sep 2018 10:26:31 -0700 Subject: [PATCH] [flang] Move KindOrLen enum to common/fortran.h This is so that it can more easily be used in semantics in the representation of type parameters. Original-commit: flang-compiler/f18@f734d754e49b45c8bcaf246f577b030e77413aa7 Reviewed-on: https://github.com/flang-compiler/f18/pull/173 Tree-same-pre-rewrite: false --- flang/lib/common/fortran.h | 3 +++ flang/lib/parser/grammar.h | 4 ++-- flang/lib/parser/parse-tree.h | 5 +++-- flang/lib/parser/unparse.cc | 4 ++-- flang/lib/semantics/dump-parse-tree.h | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/flang/lib/common/fortran.h b/flang/lib/common/fortran.h index a413248..443732e 100644 --- a/flang/lib/common/fortran.h +++ b/flang/lib/common/fortran.h @@ -28,5 +28,8 @@ 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) +// Type parameters can be kind or len. +ENUM_CLASS(TypeParamKindOrLen, Kind, Len) + } // namespace Fortran::common #endif // FORTRAN_COMMON_FORTRAN_H_ diff --git a/flang/lib/parser/grammar.h b/flang/lib/parser/grammar.h index a29354f..359c4b9 100644 --- a/flang/lib/parser/grammar.h +++ b/flang/lib/parser/grammar.h @@ -740,8 +740,8 @@ TYPE_PARSER(construct("SEQUENCE"_tok)) // integer-type-spec , type-param-attr-spec :: type-param-decl-list // R734 type-param-attr-spec -> KIND | LEN TYPE_PARSER(construct(integerTypeSpec / ",", - "KIND" >> pure(TypeParamDefStmt::KindOrLen::Kind) || - "LEN" >> pure(TypeParamDefStmt::KindOrLen::Len), + "KIND" >> pure(common::TypeParamKindOrLen::Kind) || + "LEN" >> pure(common::TypeParamKindOrLen::Len), "::" >> nonemptyList(Parser{}))) // R733 type-param-decl -> type-param-name [= scalar-int-constant-expr] diff --git a/flang/lib/parser/parse-tree.h b/flang/lib/parser/parse-tree.h index cd131e7..0604d0d 100644 --- a/flang/lib/parser/parse-tree.h +++ b/flang/lib/parser/parse-tree.h @@ -889,9 +889,10 @@ struct TypeParamDecl { // integer-type-spec , type-param-attr-spec :: type-param-decl-list // R734 type-param-attr-spec -> KIND | LEN struct TypeParamDefStmt { - ENUM_CLASS(KindOrLen, Kind, Len) // R734 TUPLE_CLASS_BOILERPLATE(TypeParamDefStmt); - std::tuple> t; + std::tuple> + t; }; // R1028 specification-expr -> scalar-int-expr diff --git a/flang/lib/parser/unparse.cc b/flang/lib/parser/unparse.cc index 3b237a3..ce3e938 100644 --- a/flang/lib/parser/unparse.cc +++ b/flang/lib/parser/unparse.cc @@ -222,7 +222,7 @@ public: } void Unparse(const TypeParamDefStmt &x) { // R732 Walk(std::get(x.t)); - Put(", "), Walk(std::get(x.t)); + Put(", "), Walk(std::get(x.t)); Put(" :: "), Walk(std::get>(x.t), ", "); } void Unparse(const TypeParamDecl &x) { // R733 @@ -2333,7 +2333,7 @@ public: #define WALK_NESTED_ENUM(CLASS, ENUM) \ void Unparse(const CLASS::ENUM &x) { Word(CLASS::EnumToString(x)); } WALK_NESTED_ENUM(AccessSpec, Kind) // R807 - WALK_NESTED_ENUM(TypeParamDefStmt, KindOrLen) // R734 + WALK_NESTED_ENUM(common, TypeParamKindOrLen) // R734 WALK_NESTED_ENUM(IntentSpec, Intent) // R826 WALK_NESTED_ENUM(ImplicitStmt, ImplicitNoneNameSpec) // R866 WALK_NESTED_ENUM(ConnectSpec::CharExpr, Kind) // R1205 diff --git a/flang/lib/semantics/dump-parse-tree.h b/flang/lib/semantics/dump-parse-tree.h index e0014e3..97b592f 100644 --- a/flang/lib/semantics/dump-parse-tree.h +++ b/flang/lib/semantics/dump-parse-tree.h @@ -680,7 +680,7 @@ public: NODE(parser::TypeGuardStmt, Guard) NODE(parser, TypeParamDecl) NODE(parser, TypeParamDefStmt) - NODE(parser::TypeParamDefStmt, KindOrLen) + NODE(common, TypeParamKindOrLen) NODE(parser, TypeParamInquiry) NODE(parser, TypeParamSpec) NODE(parser, TypeParamValue) -- 2.7.4