From e065e5b510d46e25315a9d04122c9f8b491b5f01 Mon Sep 17 00:00:00 2001 From: Tim Keith Date: Wed, 7 Feb 2018 15:54:07 -0800 Subject: [PATCH] [flang] Move type.{h,cc} and attr.{h,cc} The are now in new namespace and directory, "semantics", similar to "parser". Original-commit: flang-compiler/f18@115a1341e2f072e19a3a37da85e9f7f91e42c2be Reviewed-on: https://github.com/flang-compiler/f18/pull/5 --- flang/CMakeLists.txt | 2 +- flang/{ => lib/semantics}/attr.cc | 6 ++++- flang/{ => lib/semantics}/attr.h | 4 +++- flang/{ => lib/semantics}/type.cc | 40 ++++++++++++++++++++++--------- flang/{ => lib/semantics}/type.h | 5 +++- 5 files changed, 42 insertions(+), 15 deletions(-) rename flang/{ => lib/semantics}/attr.cc (94%) rename flang/{ => lib/semantics}/attr.h (90%) rename flang/{ => lib/semantics}/type.cc (93%) rename flang/{ => lib/semantics}/type.h (99%) diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt index ac02d18c56be..13fbff49332d 100644 --- a/flang/CMakeLists.txt +++ b/flang/CMakeLists.txt @@ -20,4 +20,4 @@ set(SOURCES lib/parser/source.cc ) add_executable(f18 ${SOURCES}) -add_executable(type-test type.cc attr.cc lib/parser/idioms.cc) +add_executable(type-test lib/semantics/type.cc lib/semantics/attr.cc lib/parser/idioms.cc) diff --git a/flang/attr.cc b/flang/lib/semantics/attr.cc similarity index 94% rename from flang/attr.cc rename to flang/lib/semantics/attr.cc index 9c906e5dc1fd..b75f9abdd9d5 100644 --- a/flang/attr.cc +++ b/flang/lib/semantics/attr.cc @@ -4,6 +4,7 @@ #include namespace Fortran { +namespace semantics { std::ostream &operator<<(std::ostream &o, Attr attr) { switch (attr) { @@ -33,7 +34,9 @@ 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; @@ -50,4 +53,5 @@ void checkAttrs(std::string className, Attrs attrs, Attrs allowed) { } } +} // namespace semantics } // namespace Fortran diff --git a/flang/attr.h b/flang/lib/semantics/attr.h similarity index 90% rename from flang/attr.h rename to flang/lib/semantics/attr.h index 56cc6e8f6c92..162e34cb91bc 100644 --- a/flang/attr.h +++ b/flang/lib/semantics/attr.h @@ -1,12 +1,13 @@ #ifndef FORTRAN_ATTR_H_ #define FORTRAN_ATTR_H_ -#include "lib/parser/idioms.h" +#include "../parser/idioms.h" #include #include #include namespace Fortran { +namespace semantics { // All available attributes. enum class Attr { @@ -39,6 +40,7 @@ std::ostream &operator<<(std::ostream &o, const Attrs &attrs); // Report internal error if attrs is not a subset of allowed. void checkAttrs(std::string className, Attrs attrs, Attrs allowed); +} // namespace semantics } // namespace Fortran #endif diff --git a/flang/type.cc b/flang/lib/semantics/type.cc similarity index 93% rename from flang/type.cc rename to flang/lib/semantics/type.cc index 37cafe6b76e4..55c7050739ae 100644 --- a/flang/type.cc +++ b/flang/lib/semantics/type.cc @@ -4,6 +4,7 @@ #include namespace Fortran { +namespace semantics { // Check that values specified for param defs are valid: they must match the // names of the params and any def that doesn't have a default value must have a @@ -16,8 +17,8 @@ static void checkParams( Name name = def.name(); validNames.insert(name); if (!def.defaultValue() && values.find(name) == values.end()) { - parser::die("no value or default value for %s parameter '%s'", kindOrLen.c_str(), - name.c_str()); + parser::die("no value or default value for %s parameter '%s'", + kindOrLen.c_str(), name.c_str()); } } for (auto pair : values) { @@ -103,11 +104,15 @@ 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 << ')'; @@ -119,8 +124,12 @@ 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"; } @@ -139,11 +148,15 @@ 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 << ')'; @@ -171,16 +184,21 @@ 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; } +} // namespace semantics } // namespace Fortran -using namespace Fortran; +using namespace Fortran::semantics; void testTypeSpec() { LogicalTypeSpec l1 = LogicalTypeSpec::make(); diff --git a/flang/type.h b/flang/lib/semantics/type.h similarity index 99% rename from flang/type.h rename to flang/lib/semantics/type.h index bfbaf9408352..117d30fc6dd2 100644 --- a/flang/type.h +++ b/flang/lib/semantics/type.h @@ -1,8 +1,8 @@ #ifndef FORTRAN_TYPE_H_ #define FORTRAN_TYPE_H_ +#include "../parser/idioms.h" #include "attr.h" -#include "lib/parser/idioms.h" #include #include #include @@ -41,6 +41,7 @@ that supplied attributes are among the allowed ones using checkAttrs(). */ namespace Fortran { +namespace semantics { using Name = std::string; @@ -65,6 +66,7 @@ public: virtual std::ostream &output(std::ostream &o) const { return o << this->value_; } + private: static std::unordered_map cache; IntConst(int value) : value_{value} {} @@ -388,6 +390,7 @@ private: const Bound ub_; }; +} // namespace semantics } // namespace Fortran #endif