[flang] Rearrange some facilities into a new lib/common.
authorpeter klausler <pklausler@nvidia.com>
Mon, 18 Jun 2018 18:03:43 +0000 (11:03 -0700)
committerpeter klausler <pklausler@nvidia.com>
Mon, 18 Jun 2018 18:05:17 +0000 (11:05 -0700)
Original-commit: flang-compiler/f18@279af1e817b1266dd57689e462272f8e29496798
Reviewed-on: https://github.com/flang-compiler/f18/pull/106

41 files changed:
flang/CMakeLists.txt
flang/include/flang/ISO_Fortran_binding.h
flang/lib/CMakeLists.txt
flang/lib/common/CMakeLists.txt [new file with mode: 0644]
flang/lib/common/enum-set.h
flang/lib/common/idioms.cc [moved from flang/lib/parser/idioms.cc with 95% similarity]
flang/lib/common/idioms.h [moved from flang/lib/parser/idioms.h with 87% similarity]
flang/lib/common/indirection.h [moved from flang/lib/parser/indirection.h with 90% similarity]
flang/lib/common/interval.h [moved from flang/lib/parser/interval.h with 94% similarity]
flang/lib/common/reference-counted.h [moved from flang/lib/parser/reference-counted.h with 87% similarity]
flang/lib/evaluate/real.h
flang/lib/evaluate/type.h
flang/lib/parser/CMakeLists.txt
flang/lib/parser/basic-parsers.h
flang/lib/parser/char-block.h
flang/lib/parser/char-buffer.cc
flang/lib/parser/message.cc
flang/lib/parser/message.h
flang/lib/parser/parse-state.h
flang/lib/parser/parse-tree-visitor.h
flang/lib/parser/parse-tree.cc
flang/lib/parser/parse-tree.h
flang/lib/parser/preprocessor.cc
flang/lib/parser/prescan.cc
flang/lib/parser/provenance.cc
flang/lib/parser/provenance.h
flang/lib/parser/source.cc
flang/lib/parser/token-parsers.h
flang/lib/parser/unparse.cc
flang/lib/parser/user-state.h
flang/lib/semantics/CMakeLists.txt
flang/lib/semantics/attr.cc
flang/lib/semantics/attr.h
flang/lib/semantics/dump-parse-tree.h
flang/lib/semantics/resolve-names.cc
flang/lib/semantics/rewrite-parse-tree.cc
flang/lib/semantics/scope.h
flang/lib/semantics/symbol.cc
flang/lib/semantics/symbol.h
flang/lib/semantics/type.h
flang/runtime/descriptor.h

index 284583a..a59a3f3 100644 (file)
@@ -64,7 +64,7 @@ message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
 include_directories(${LLVM_INCLUDE_DIRS})
 add_definitions(${LLVM_DEFINITIONS})
 
-llvm_map_components_to_libnames(LLVM_COMMON_LIBS support target option) 
+llvm_map_components_to_libnames(LLVM_COMMON_LIBS support target option)
 
 if(CMAKE_COMPILER_IS_GNUCXX OR (CMAKE_CXX_COMPILER_ID MATCHES "Clang"))
    if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
index 8420c75..409951d 100644 (file)
@@ -58,8 +58,9 @@ typedef unsigned short CFI_attribute_t;
 
 typedef signed char CFI_type_t;
 /* These codes are required to be macros (i.e., #ifdef will work).
- * They are not required to be either distinct nor to have had their
- * synonyms combined.
+ * They are not required to be distinct, but neither are they required
+ * to have had their synonyms combined.
+ * Extension: 128-bit integers are anticipated
  */
 #define CFI_type_signed_char 1
 #define CFI_type_short 2
@@ -71,31 +72,34 @@ typedef signed char CFI_type_t;
 #define CFI_type_int16_t 8
 #define CFI_type_int32_t 9
 #define CFI_type_int64_t 10
-#define CFI_type_int_least8_t 11
-#define CFI_type_int_least16_t 12
-#define CFI_type_int_least32_t 13
-#define CFI_type_int_least64_t 14
-#define CFI_type_int_fast8_t 15
-#define CFI_type_int_fast16_t 16
-#define CFI_type_int_fast32_t 17
-#define CFI_type_int_fast64_t 18
-#define CFI_type_intmax_t 19
-#define CFI_type_intptr_t 20
-#define CFI_type_ptrdiff_t 21
-#define CFI_type_float 22
-#define CFI_type_double 23
-#define CFI_type_long_double 24
-#define CFI_type_float_Complex 25
-#define CFI_type_double_Complex 26
-#define CFI_type_long_double_Complex 27
-#define CFI_type_Bool 28
-#define CFI_type_char 29
-#define CFI_type_cptr 30
-#define CFI_type_struct 31
-#define CFI_type_other (-1) /* must be negative */
+#define CFI_type_int128_t 11
+#define CFI_type_int_least8_t 12
+#define CFI_type_int_least16_t 13
+#define CFI_type_int_least32_t 14
+#define CFI_type_int_least64_t 15
+#define CFI_type_int_least128_t 16
+#define CFI_type_int_fast8_t 17
+#define CFI_type_int_fast16_t 18
+#define CFI_type_int_fast32_t 19
+#define CFI_type_int_fast64_t 20
+#define CFI_type_int_fast128_t 21
+#define CFI_type_intmax_t 22
+#define CFI_type_intptr_t 23
+#define CFI_type_ptrdiff_t 24
+#define CFI_type_float 25
+#define CFI_type_double 26
+#define CFI_type_long_double 27
+#define CFI_type_float_Complex 28
+#define CFI_type_double_Complex 29
+#define CFI_type_long_double_Complex 30
+#define CFI_type_Bool 31
+#define CFI_type_char 32
+#define CFI_type_cptr 33
+#define CFI_type_struct 34
+#define CFI_type_other (-1)  // must be negative
 
 /* Error code macros */
-#define CFI_SUCCESS 0
+#define CFI_SUCCESS 0  /* must be zero */
 #define CFI_ERROR_BASE_ADDR_NULL 1
 #define CFI_ERROR_BASE_ADDR_NOT_NULL 2
 #define CFI_INVALID_ELEM_LEN 3
index 65bdcd5..2c77e79 100644 (file)
@@ -12,7 +12,7 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-
+add_subdirectory(common)
 add_subdirectory(evaluate)
 add_subdirectory(parser)
 add_subdirectory(semantics)
diff --git a/flang/lib/common/CMakeLists.txt b/flang/lib/common/CMakeLists.txt
new file mode 100644 (file)
index 0000000..da12c5b
--- /dev/null
@@ -0,0 +1,18 @@
+# Copyright (c) 2018, NVIDIA CORPORATION.  All rights reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+add_library(FortranCommon
+  idioms.cc
+)
+
index f4ffd56..5e200bb 100644 (file)
@@ -17,6 +17,8 @@
 
 // Implements a set of enums as a std::bitset<>.  APIs from bitset<> and set<>
 // can be used on these sets, whichever might be more clear to the user.
+// This class template facilitates the use of the more type-safe C++ "enum
+// class" feature without loss of convenience.
 
 #include <bitset>
 #include <cstddef>
@@ -171,7 +173,6 @@ public:
 private:
   bitsetType bitset_;
 };
-
 }  // namespace Fortran::common
 
 template<typename ENUM, std::size_t values>
similarity index 95%
rename from flang/lib/parser/idioms.cc
rename to flang/lib/common/idioms.cc
index 772eb89..6027b1d 100644 (file)
@@ -17,7 +17,7 @@
 #include <cstdio>
 #include <cstdlib>
 
-namespace Fortran::parser {
+namespace Fortran::common {
 
 [[noreturn]] void die(const char *msg, ...) {
   va_list ap;
@@ -46,5 +46,4 @@ std::string EnumIndexToString(int index, const char *enumNames) {
   }
   return std::string(p, q - p);
 }
-
-}  // namespace Fortran::parser
+}  // namespace Fortran::common
similarity index 87%
rename from flang/lib/parser/idioms.h
rename to flang/lib/common/idioms.h
index 7f58f3c..340cb15 100644 (file)
@@ -12,9 +12,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-// TODO: move to lib/common
-#ifndef FORTRAN_PARSER_IDIOMS_H_
-#define FORTRAN_PARSER_IDIOMS_H_
+#ifndef FORTRAN_COMMON_IDIOMS_H_
+#define FORTRAN_COMMON_IDIOMS_H_
 
 // Defines anything that might ever be useful in more than one source file
 // or that is too weird or too specific to the host C++ compiler to be
@@ -49,7 +48,7 @@ struct is_trivially_copy_constructible<optional<list<A>>> : false_type {};
 // enable "this is a std::string"s with the 's' suffix
 using namespace std::literals::string_literals;
 
-namespace Fortran::parser {
+namespace Fortran::common {
 
 // Helper templates for combining a list of lambdas into an anonymous
 // struct for use with std::visit() on a std::variant<> sum type.
@@ -68,22 +67,16 @@ template<typename... LAMBDAS> visitors(LAMBDAS... x)->visitors<LAMBDAS...>;
 // Calls std::fprintf(stderr, ...), then abort().
 [[noreturn]] void die(const char *, ...);
 
-// Treat operator! as if it were a Boolean context, i.e. like if() and ? :,
-// when its operand is std::optional<>.
-template<typename A> bool operator!(const std::optional<A> &x) {
-  return !x.has_value();
-}
-
 // For switch statements without default: labels.
 #define CRASH_NO_CASE \
-  Fortran::parser::die("no case at " __FILE__ "(%d)", __LINE__)
+  Fortran::common::die("no case at " __FILE__ "(%d)", __LINE__)
 
 // For cheap assertions that should be applied in production.
 // To disable, compile with '-DCHECK=(void)'
 #ifndef CHECK
 #define CHECK(x) \
   ((x) || \
-      (Fortran::parser::die( \
+      (Fortran::common::die( \
            "CHECK(" #x ") failed at " __FILE__ "(%d)", __LINE__), \
           false))
 #endif
@@ -130,12 +123,12 @@ template<typename A> struct ListItemCount {
   enum class NAME { __VA_ARGS__ }; \
   static constexpr std::size_t NAME##_enumSize{[] { \
     enum { __VA_ARGS__ }; \
-    return Fortran::parser::ListItemCount{__VA_ARGS__}.value; \
+    return Fortran::common::ListItemCount{__VA_ARGS__}.value; \
   }()}; \
   static inline std::string EnumToString(NAME e) { \
-    return Fortran::parser::EnumIndexToString( \
+    return Fortran::common::EnumIndexToString( \
         static_cast<int>(e), #__VA_ARGS__); \
   }
 
-}  // namespace Fortran::parser
-#endif  // FORTRAN_PARSER_IDIOMS_H_
+}  // namespace Fortran::common
+#endif  // FORTRAN_COMMON_IDIOMS_H_
similarity index 90%
rename from flang/lib/parser/indirection.h
rename to flang/lib/common/indirection.h
index 7d356d5..72b3967 100644 (file)
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#ifndef FORTRAN_PARSER_INDIRECTION_H_
-#define FORTRAN_PARSER_INDIRECTION_H_
+#ifndef FORTRAN_COMMON_INDIRECTION_H_
+#define FORTRAN_COMMON_INDIRECTION_H_
 
 // Defines a smart pointer class template that's rather like std::unique_ptr<>
 // but further restricted, like a C++ reference, to be non-null when constructed
 // or assigned.  Users need not check whether these pointers are null.
 // Intended to be as invisible as possible.
 
-#include "idioms.h"
+#include "../common/idioms.h"
 #include <utility>
 
-namespace Fortran::parser {
+namespace Fortran::common {
 
 template<typename A> class Indirection {
 public:
@@ -60,6 +60,5 @@ public:
 private:
   A *p_{nullptr};
 };
-
-}  // namespace Fortran::parser
-#endif  // FORTRAN_PARSER_INDIRECTION_H_
+}  // namespace Fortran::common
+#endif  // FORTRAN_COMMON_INDIRECTION_H_
similarity index 94%
rename from flang/lib/parser/interval.h
rename to flang/lib/common/interval.h
index e836516..0f90100 100644 (file)
@@ -12,8 +12,8 @@
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#ifndef FORTRAN_PARSER_INTERVAL_H_
-#define FORTRAN_PARSER_INTERVAL_H_
+#ifndef FORTRAN_COMMON_INTERVAL_H_
+#define FORTRAN_COMMON_INTERVAL_H_
 
 // Defines a generalized template class Interval<A> to represent
 // the half-open interval [x .. x+n).
@@ -22,7 +22,7 @@
 #include <cstddef>
 #include <utility>
 
-namespace Fortran::parser {
+namespace Fortran::common {
 
 template<typename A> class Interval {
 public:
@@ -91,5 +91,5 @@ private:
   std::size_t size_{0};
 };
 
-}  // namespace Fortran::parser
-#endif  // FORTRAN_PARSER_INTERVAL_H_
+}  // namespace Fortran::common
+#endif  // FORTRAN_COMMON_INTERVAL_H_
similarity index 87%
rename from flang/lib/parser/reference-counted.h
rename to flang/lib/common/reference-counted.h
index c4b7c61..f44f0a5 100644 (file)
 // See the License for the specific language governing permissions and
 // limitations under the License.
 
-#ifndef FORTRAN_PARSER_REFERENCE_COUNTED_H_
-#define FORTRAN_PARSER_REFERENCE_COUNTED_H_
+#ifndef FORTRAN_COMMON_REFERENCE_COUNTED_H_
+#define FORTRAN_COMMON_REFERENCE_COUNTED_H_
 
 // A class template of smart pointers to objects with their own
 // reference counting object lifetimes that's lighter weight
 // than std::shared_ptr<>.  Not thread-safe.
 
-namespace Fortran::parser {
+namespace Fortran::common {
 
+// A base class for reference-counted objects.
 template<typename A> class ReferenceCounted {
 public:
   ReferenceCounted() {}
@@ -35,6 +36,7 @@ private:
   int references_{0};
 };
 
+// A reference to a reference-counted object.
 template<typename A> class CountedReference {
 public:
   using type = A;
@@ -77,5 +79,5 @@ private:
   type *p_{nullptr};
 };
 
-}  // namespace Fortran::parser
-#endif  // FORTRAN_PARSER_REFERENCE_COUNTED_H_
+}  // namespace Fortran::common
+#endif  // FORTRAN_COMMON_REFERENCE_COUNTED_H_
index d0515ce..e276bd7 100644 (file)
@@ -80,9 +80,7 @@ public:
     return {word_.IBCLR(bits - 1)};
   }
 
-  constexpr Real Negate() const {
-    return {word_.IEOR(word_.MASKL(1))};
-  }
+  constexpr Real Negate() const { return {word_.IEOR(word_.MASKL(1))}; }
 
   Relation Compare(const Real &) const;
   ValueWithRealFlags<Real> Add(
index 1880a65..926c5ec 100644 (file)
@@ -24,6 +24,7 @@
 #include "integer.h"
 #include "logical.h"
 #include "real.h"
+#include <string>
 
 namespace Fortran::evaluate::type {
 
@@ -87,7 +88,7 @@ template<int KIND> struct Character {
   static constexpr Classification classification{Classification::Character};
   static constexpr int kind{KIND};
   static constexpr bool hasLen{true};
-  using ValueType = std::uint8_t[kind];  // TODO: ?
+  using ValueType = std::string;
 };
 
 // Default REAL just simply has to be IEEE-754 single precision today.
index 257ed21..cd439f7 100644 (file)
@@ -17,7 +17,6 @@ add_library(FortranParser
   char-set.cc
   characters.cc
   debug-parser.cc
-  idioms.cc
   instrumented-parser.cc
   message.cc
   parse-tree.cc
@@ -30,3 +29,7 @@ add_library(FortranParser
   unparse.cc
   user-state.cc
 )
+
+target_link_libraries(FortranParser
+  FortranCommon
+)
index b60b92a..3a9a260 100644 (file)
 // template functions.  See parser-combinators.txt for documentation.
 
 #include "char-block.h"
-#include "idioms.h"
-#include "indirection.h"
 #include "message.h"
 #include "parse-state.h"
 #include "provenance.h"
+#include "../common/idioms.h"
+#include "../common/indirection.h"
 #include <cstring>
 #include <functional>
 #include <list>
@@ -1157,7 +1157,7 @@ constexpr Construct6<T, PA, PB, PC, PD, PE, PF> construct(const PA &pa,
 // For a parser p, indirect(p) returns a parser that builds an indirect
 // reference to p's return type.
 template<typename PA> inline constexpr auto indirect(const PA &p) {
-  return construct<Indirection<typename PA::resultType>>(p);
+  return construct<common::Indirection<typename PA::resultType>>(p);
 }
 
 // If a and b are parsers, then nonemptySeparated(a, b) returns a parser
index 2a52639..c49e4c6 100644 (file)
@@ -17,7 +17,7 @@
 
 // Describes a contiguous block of characters; does not own their storage.
 
-#include "interval.h"
+#include "../common/interval.h"
 #include <algorithm>
 #include <cstddef>
 #include <cstring>
@@ -85,7 +85,7 @@ private:
     return size() < that.size() ? -1 : size() > that.size();
   }
 
-  Interval<const char *> interval_{nullptr, 0};
+  common::Interval<const char *> interval_{nullptr, 0};
 };
 
 }  // namespace Fortran::parser
index e77f46a..e890cb8 100644 (file)
@@ -13,7 +13,7 @@
 // limitations under the License.
 
 #include "char-buffer.h"
-#include "idioms.h"
+#include "../common/idioms.h"
 #include <algorithm>
 #include <cstddef>
 #include <cstring>
index 0391f60..6a009a7 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "message.h"
 #include "char-set.h"
-#include "idioms.h"
+#include "../common/idioms.h"
 #include <algorithm>
 #include <cstdarg>
 #include <cstddef>
@@ -52,11 +52,11 @@ MessageFormattedText::MessageFormattedText(MessageFixedText text, ...)
 
 std::string MessageExpectedText::ToString() const {
   return std::visit(
-      visitors{[](const CharBlock &cb) {
-                 return MessageFormattedText("expected '%s'"_err_en_US,
-                     cb.NULTerminatedToString().data())
-                     .MoveString();
-               },
+      common::visitors{[](const CharBlock &cb) {
+                         return MessageFormattedText("expected '%s'"_err_en_US,
+                             cb.NULTerminatedToString().data())
+                             .MoveString();
+                       },
           [](const SetOfChars &set) {
             SetOfChars expect{set};
             if (expect.Has('\n')) {
@@ -90,9 +90,10 @@ std::string MessageExpectedText::ToString() const {
 }
 
 void MessageExpectedText::Incorporate(const MessageExpectedText &that) {
-  std::visit(
-      visitors{[&](SetOfChars &s1, const SetOfChars &s2) { s1 = s1.Union(s2); },
-          [](const auto &, const auto &) {}},
+  std::visit(common::visitors{[&](SetOfChars &s1, const SetOfChars &s2) {
+                                s1 = s1.Union(s2);
+                              },
+                 [](const auto &, const auto &) {}},
       u_, that.u_);
 }
 
@@ -104,9 +105,9 @@ bool Message::SortBefore(const Message &that) const {
   // are speculative.  Messages with ProvenanceRange locations are ordered
   // before others for sorting.
   return std::visit(
-      visitors{[](const CharBlock &cb1, const CharBlock &cb2) {
-                 return cb1.begin() < cb2.begin();
-               },
+      common::visitors{[](const CharBlock &cb1, const CharBlock &cb2) {
+                         return cb1.begin() < cb2.begin();
+                       },
           [](const CharBlock &, const ProvenanceRange &) { return false; },
           [](const ProvenanceRange &pr1, const ProvenanceRange &pr2) {
             return pr1.start() < pr2.start();
@@ -117,7 +118,7 @@ bool Message::SortBefore(const Message &that) const {
 
 bool Message::IsFatal() const {
   return std::visit(
-      visitors{[](const MessageExpectedText &) { return true; },
+      common::visitors{[](const MessageExpectedText &) { return true; },
           [](const MessageFixedText &x) { return x.isFatal(); },
           [](const MessageFormattedText &x) { return x.isFatal(); }},
       text_);
@@ -125,18 +126,18 @@ bool Message::IsFatal() const {
 
 std::string Message::ToString() const {
   return std::visit(
-      visitors{[](const MessageFixedText &t) {
-                 return t.text().NULTerminatedToString();
-               },
+      common::visitors{[](const MessageFixedText &t) {
+                         return t.text().NULTerminatedToString();
+                       },
           [](const MessageFormattedText &t) { return t.string(); },
           [](const MessageExpectedText &e) { return e.ToString(); }},
       text_);
 }
 
 ProvenanceRange Message::GetProvenanceRange(const CookedSource &cooked) const {
-  return std::visit(visitors{[&](const CharBlock &cb) {
-                               return cooked.GetProvenanceRange(cb);
-                             },
+  return std::visit(common::visitors{[&](const CharBlock &cb) {
+                                       return cooked.GetProvenanceRange(cb);
+                                     },
                         [](const ProvenanceRange &pr) { return pr; }},
       location_);
 }
@@ -173,11 +174,11 @@ void Message::Emit(
 }
 
 void Message::Incorporate(Message &that) {
-  std::visit(
-      visitors{[&](MessageExpectedText &e1, const MessageExpectedText &e2) {
-                 e1.Incorporate(e2);
-               },
-          [](const auto &, const auto &) {}},
+  std::visit(common::visitors{[&](MessageExpectedText &e1,
+                                  const MessageExpectedText &e2) {
+                                e1.Incorporate(e2);
+                              },
+                 [](const auto &, const auto &) {}},
       text_, that.text_);
 }
 
@@ -191,9 +192,9 @@ void Message::Attach(Message *m) {
 
 bool Message::AtSameLocation(const Message &that) const {
   return std::visit(
-      visitors{[](const CharBlock &cb1, const CharBlock &cb2) {
-                 return cb1.begin() == cb2.begin();
-               },
+      common::visitors{[](const CharBlock &cb1, const CharBlock &cb2) {
+                         return cb1.begin() == cb2.begin();
+                       },
           [](const ProvenanceRange &pr1, const ProvenanceRange &pr2) {
             return pr1.start() == pr2.start();
           },
index 6714f34..a31d8af 100644 (file)
@@ -20,9 +20,9 @@
 
 #include "char-block.h"
 #include "char-set.h"
-#include "idioms.h"
 #include "provenance.h"
-#include "reference-counted.h"
+#include "../common/idioms.h"
+#include "../common/reference-counted.h"
 #include <cstddef>
 #include <cstring>
 #include <forward_list>
@@ -102,9 +102,9 @@ private:
   std::variant<CharBlock, SetOfChars> u_;
 };
 
-class Message : public ReferenceCounted<Message> {
+class Message : public common::ReferenceCounted<Message> {
 public:
-  using Reference = CountedReference<Message>;
+  using Reference = common::CountedReference<Message>;
 
   Message(const Message &) = default;
   Message(Message &&) = default;
index 12f80a0..2d5d5aa 100644 (file)
@@ -22,9 +22,9 @@
 // and recovery during parsing!
 
 #include "characters.h"
-#include "idioms.h"
 #include "message.h"
 #include "provenance.h"
+#include "../common/idioms.h"
 #include <cstddef>
 #include <cstring>
 #include <list>
index c846359..39442f8 100644 (file)
@@ -200,10 +200,11 @@ typename std::enable_if<WrapperTrait<A>>::type Walk(A &x, M &mutator) {
 }
 
 template<typename T, typename V>
-void Walk(const Indirection<T> &x, V &visitor) {
+void Walk(const common::Indirection<T> &x, V &visitor) {
   Walk(*x, visitor);
 }
-template<typename T, typename M> void Walk(Indirection<T> &x, M &mutator) {
+template<typename T, typename M>
+void Walk(common::Indirection<T> &x, M &mutator) {
   Walk(*x, mutator);
 }
 
index 9db7fd2..2e1665f 100644 (file)
@@ -13,9 +13,9 @@
 // limitations under the License.
 
 #include "parse-tree.h"
-#include "idioms.h"
-#include "indirection.h"
 #include "user-state.h"
+#include "../common/idioms.h"
+#include "../common/indirection.h"
 #include <algorithm>
 
 namespace Fortran::parser {
@@ -29,10 +29,11 @@ ImportStmt::ImportStmt(Kind &&k, std::list<Name> &&n)
 // R901 designator
 bool Designator::EndsInBareName() const {
   return std::visit(
-      visitors{[](const ObjectName &) { return true; },
+      common::visitors{[](const ObjectName &) { return true; },
           [](const DataRef &dr) {
             return std::holds_alternative<Name>(dr.u) ||
-                std::holds_alternative<Indirection<StructureComponent>>(dr.u);
+                std::holds_alternative<common::Indirection<StructureComponent>>(
+                    dr.u);
           },
           [](const Substring &) { return false; }},
       u);
@@ -43,30 +44,32 @@ DataRef::DataRef(std::list<PartRef> &&prl) : u{std::move(prl.front().name)} {
   for (bool first{true}; !prl.empty(); first = false, prl.pop_front()) {
     PartRef &pr{prl.front()};
     if (!first) {
-      u = Indirection<StructureComponent>{std::move(*this), std::move(pr.name)};
+      u = common::Indirection<StructureComponent>{
+          std::move(*this), std::move(pr.name)};
     }
     if (!pr.subscripts.empty()) {
-      u = Indirection<ArrayElement>{std::move(*this), std::move(pr.subscripts)};
+      u = common::Indirection<ArrayElement>{
+          std::move(*this), std::move(pr.subscripts)};
     }
     if (pr.imageSelector.has_value()) {
-      u = Indirection<CoindexedNamedObject>{
+      u = common::Indirection<CoindexedNamedObject>{
           std::move(*this), std::move(*pr.imageSelector)};
     }
   }
 }
 
 // R1001 - R1022 expression
-Expr::Expr(Designator &&x) : u{Indirection<Designator>(std::move(x))} {}
+Expr::Expr(Designator &&x) : u{common::Indirection<Designator>(std::move(x))} {}
 Expr::Expr(FunctionReference &&x)
-  : u{Indirection<FunctionReference>(std::move(x))} {}
+  : u{common::Indirection<FunctionReference>(std::move(x))} {}
 
 static Designator MakeArrayElementRef(Name &name, std::list<Expr> &subscripts) {
   ArrayElement arrayElement{name, std::list<SectionSubscript>{}};
   for (Expr &expr : subscripts) {
-    arrayElement.subscripts.push_back(
-        SectionSubscript{Scalar{Integer{Indirection{std::move(expr)}}}});
+    arrayElement.subscripts.push_back(SectionSubscript{
+        Scalar{Integer{common::Indirection{std::move(expr)}}}});
   }
-  return Designator{DataRef{Indirection{std::move(arrayElement)}}};
+  return Designator{DataRef{common::Indirection{std::move(arrayElement)}}};
 }
 
 Designator FunctionReference::ConvertToArrayElementRef() {
@@ -74,15 +77,17 @@ Designator FunctionReference::ConvertToArrayElementRef() {
   std::list<Expr> args;
   for (auto &arg : std::get<std::list<ActualArgSpec>>(v.t)) {
     std::visit(
-        visitors{
-            [&](Indirection<Expr> &y) { args.push_back(std::move(*y)); },
-            [&](Indirection<Variable> &y) {
+        common::visitors{
+            [&](common::Indirection<Expr> &y) {
+              args.push_back(std::move(*y));
+            },
+            [&](common::Indirection<Variable> &y) {
               args.push_back(std::visit(
-                  visitors{
-                      [&](Indirection<Designator> &z) {
+                  common::visitors{
+                      [&](common::Indirection<Designator> &z) {
                         return Expr{std::move(*z)};
                       },
-                      [&](Indirection<FunctionReference> &z) {
+                      [&](common::Indirection<FunctionReference> &z) {
                         return Expr{std::move(*z)};
                       },
                   },
@@ -103,12 +108,12 @@ Statement<ActionStmt> StmtFunctionStmt::ConvertToAssignment() {
   auto &funcExpr = std::get<Scalar<Expr>>(t).thing;
   std::list<Expr> subscripts;
   for (Name &arg : funcArgs) {
-    subscripts.push_back(Expr{Indirection{Designator{arg}}});
+    subscripts.push_back(Expr{common::Indirection{Designator{arg}}});
   }
   auto &&variable =
-      Variable{Indirection{MakeArrayElementRef(funcName, subscripts)}};
+      Variable{common::Indirection{MakeArrayElementRef(funcName, subscripts)}};
   return Statement{std::nullopt,
-      ActionStmt{Indirection{
+      ActionStmt{common::Indirection{
           AssignmentStmt{std::move(variable), std::move(funcExpr)}}}};
 }
 
index e466fbc..ef29a2e 100644 (file)
 #include "char-block.h"
 #include "characters.h"
 #include "format-specification.h"
-#include "idioms.h"
-#include "indirection.h"
 #include "message.h"
 #include "provenance.h"
+#include "../common/idioms.h"
+#include "../common/indirection.h"
 #include <cinttypes>
 #include <list>
 #include <optional>
@@ -298,10 +298,10 @@ template<typename A> struct DefaultChar {
   A thing;
 };
 
-using LogicalExpr = Logical<Indirection<Expr>>;  // R1024
-using DefaultCharExpr = DefaultChar<Indirection<Expr>>;  // R1025
-using IntExpr = Integer<Indirection<Expr>>;  // R1026
-using ConstantExpr = Constant<Indirection<Expr>>;  // R1029
+using LogicalExpr = Logical<common::Indirection<Expr>>;  // R1024
+using DefaultCharExpr = DefaultChar<common::Indirection<Expr>>;  // R1025
+using IntExpr = Integer<common::Indirection<Expr>>;  // R1026
+using ConstantExpr = Constant<common::Indirection<Expr>>;  // R1029
 using IntConstantExpr = Integer<ConstantExpr>;  // R1031
 using ScalarLogicalExpr = Scalar<LogicalExpr>;
 using ScalarIntExpr = Scalar<IntExpr>;
@@ -336,16 +336,18 @@ EMPTY_CLASS(ErrorRecovery);
 // Extension: (Cray) based POINTER statement
 struct OtherSpecificationStmt {
   UNION_CLASS_BOILERPLATE(OtherSpecificationStmt);
-  std::variant<Indirection<AccessStmt>, Indirection<AllocatableStmt>,
-      Indirection<AsynchronousStmt>, Indirection<BindStmt>,
-      Indirection<CodimensionStmt>, Indirection<ContiguousStmt>,
-      Indirection<DimensionStmt>, Indirection<ExternalStmt>,
-      Indirection<IntentStmt>, Indirection<IntrinsicStmt>,
-      Indirection<NamelistStmt>, Indirection<OptionalStmt>,
-      Indirection<PointerStmt>, Indirection<ProtectedStmt>,
-      Indirection<SaveStmt>, Indirection<TargetStmt>, Indirection<ValueStmt>,
-      Indirection<VolatileStmt>, Indirection<CommonStmt>,
-      Indirection<EquivalenceStmt>, Indirection<BasedPointerStmt>>
+  std::variant<common::Indirection<AccessStmt>,
+      common::Indirection<AllocatableStmt>,
+      common::Indirection<AsynchronousStmt>, common::Indirection<BindStmt>,
+      common::Indirection<CodimensionStmt>, common::Indirection<ContiguousStmt>,
+      common::Indirection<DimensionStmt>, common::Indirection<ExternalStmt>,
+      common::Indirection<IntentStmt>, common::Indirection<IntrinsicStmt>,
+      common::Indirection<NamelistStmt>, common::Indirection<OptionalStmt>,
+      common::Indirection<PointerStmt>, common::Indirection<ProtectedStmt>,
+      common::Indirection<SaveStmt>, common::Indirection<TargetStmt>,
+      common::Indirection<ValueStmt>, common::Indirection<VolatileStmt>,
+      common::Indirection<CommonStmt>, common::Indirection<EquivalenceStmt>,
+      common::Indirection<BasedPointerStmt>>
       u;
 };
 
@@ -355,14 +357,16 @@ struct OtherSpecificationStmt {
 //        other-specification-stmt | type-declaration-stmt
 struct SpecificationConstruct {
   UNION_CLASS_BOILERPLATE(SpecificationConstruct);
-  std::variant<Indirection<DerivedTypeDef>, Indirection<EnumDef>,
-      Statement<Indirection<GenericStmt>>, Indirection<InterfaceBlock>,
-      Statement<Indirection<ParameterStmt>>,
-      Statement<Indirection<OldParameterStmt>>,
-      Statement<Indirection<ProcedureDeclarationStmt>>,
+  std::variant<common::Indirection<DerivedTypeDef>,
+      common::Indirection<EnumDef>, Statement<common::Indirection<GenericStmt>>,
+      common::Indirection<InterfaceBlock>,
+      Statement<common::Indirection<ParameterStmt>>,
+      Statement<common::Indirection<OldParameterStmt>>,
+      Statement<common::Indirection<ProcedureDeclarationStmt>>,
       Statement<OtherSpecificationStmt>,
-      Statement<Indirection<TypeDeclarationStmt>>, Indirection<StructureDef>,
-      Indirection<OpenMPConstruct>, Indirection<CompilerDirective>>
+      Statement<common::Indirection<TypeDeclarationStmt>>,
+      common::Indirection<StructureDef>, common::Indirection<OpenMPConstruct>,
+      common::Indirection<CompilerDirective>>
       u;
 };
 
@@ -370,10 +374,11 @@ struct SpecificationConstruct {
 //         implicit-stmt | parameter-stmt | format-stmt | entry-stmt
 struct ImplicitPartStmt {
   UNION_CLASS_BOILERPLATE(ImplicitPartStmt);
-  std::variant<Statement<Indirection<ImplicitStmt>>,
-      Statement<Indirection<ParameterStmt>>,
-      Statement<Indirection<OldParameterStmt>>,
-      Statement<Indirection<FormatStmt>>, Statement<Indirection<EntryStmt>>>
+  std::variant<Statement<common::Indirection<ImplicitStmt>>,
+      Statement<common::Indirection<ParameterStmt>>,
+      Statement<common::Indirection<OldParameterStmt>>,
+      Statement<common::Indirection<FormatStmt>>,
+      Statement<common::Indirection<EntryStmt>>>
       u;
 };
 
@@ -385,9 +390,10 @@ WRAPPER_CLASS(ImplicitPart, std::list<ImplicitPartStmt>);
 //        entry-stmt | stmt-function-stmt
 struct DeclarationConstruct {
   UNION_CLASS_BOILERPLATE(DeclarationConstruct);
-  std::variant<SpecificationConstruct, Statement<Indirection<DataStmt>>,
-      Statement<Indirection<FormatStmt>>, Statement<Indirection<EntryStmt>>,
-      Statement<Indirection<StmtFunctionStmt>>, ErrorRecovery>
+  std::variant<SpecificationConstruct, Statement<common::Indirection<DataStmt>>,
+      Statement<common::Indirection<FormatStmt>>,
+      Statement<common::Indirection<EntryStmt>>,
+      Statement<common::Indirection<StmtFunctionStmt>>, ErrorRecovery>
       u;
 };
 
@@ -397,8 +403,8 @@ struct DeclarationConstruct {
 // from the implicit part to the declaration constructs
 struct SpecificationPart {
   TUPLE_CLASS_BOILERPLATE(SpecificationPart);
-  std::tuple<std::list<Statement<Indirection<UseStmt>>>,
-      std::list<Statement<Indirection<ImportStmt>>>, ImplicitPart,
+  std::tuple<std::list<Statement<common::Indirection<UseStmt>>>,
+      std::list<Statement<common::Indirection<ImportStmt>>>, ImplicitPart,
       std::list<DeclarationConstruct>>
       t;
 };
@@ -406,8 +412,8 @@ struct SpecificationPart {
 // R512 internal-subprogram -> function-subprogram | subroutine-subprogram
 struct InternalSubprogram {
   UNION_CLASS_BOILERPLATE(InternalSubprogram);
-  std::variant<Indirection<FunctionSubprogram>,
-      Indirection<SubroutineSubprogram>>
+  std::variant<common::Indirection<FunctionSubprogram>,
+      common::Indirection<SubroutineSubprogram>>
       u;
 };
 
@@ -438,23 +444,28 @@ EMPTY_CLASS(FailImageStmt);
 //        wait-stmt | where-stmt | write-stmt | computed-goto-stmt | forall-stmt
 struct ActionStmt {
   UNION_CLASS_BOILERPLATE(ActionStmt);
-  std::variant<Indirection<AllocateStmt>, Indirection<AssignmentStmt>,
-      Indirection<BackspaceStmt>, Indirection<CallStmt>, Indirection<CloseStmt>,
-      ContinueStmt, Indirection<CycleStmt>, Indirection<DeallocateStmt>,
-      Indirection<EndfileStmt>, Indirection<EventPostStmt>,
-      Indirection<EventWaitStmt>, Indirection<ExitStmt>, FailImageStmt,
-      Indirection<FlushStmt>, Indirection<FormTeamStmt>, Indirection<GotoStmt>,
-      Indirection<IfStmt>, Indirection<InquireStmt>, Indirection<LockStmt>,
-      Indirection<NullifyStmt>, Indirection<OpenStmt>,
-      Indirection<PointerAssignmentStmt>, Indirection<PrintStmt>,
-      Indirection<ReadStmt>, Indirection<ReturnStmt>, Indirection<RewindStmt>,
-      Indirection<StopStmt>, Indirection<SyncAllStmt>,
-      Indirection<SyncImagesStmt>, Indirection<SyncMemoryStmt>,
-      Indirection<SyncTeamStmt>, Indirection<UnlockStmt>, Indirection<WaitStmt>,
-      Indirection<WhereStmt>, Indirection<WriteStmt>,
-      Indirection<ComputedGotoStmt>, Indirection<ForallStmt>,
-      Indirection<ArithmeticIfStmt>, Indirection<AssignStmt>,
-      Indirection<AssignedGotoStmt>, Indirection<PauseStmt>>
+  std::variant<common::Indirection<AllocateStmt>,
+      common::Indirection<AssignmentStmt>, common::Indirection<BackspaceStmt>,
+      common::Indirection<CallStmt>, common::Indirection<CloseStmt>,
+      ContinueStmt, common::Indirection<CycleStmt>,
+      common::Indirection<DeallocateStmt>, common::Indirection<EndfileStmt>,
+      common::Indirection<EventPostStmt>, common::Indirection<EventWaitStmt>,
+      common::Indirection<ExitStmt>, FailImageStmt,
+      common::Indirection<FlushStmt>, common::Indirection<FormTeamStmt>,
+      common::Indirection<GotoStmt>, common::Indirection<IfStmt>,
+      common::Indirection<InquireStmt>, common::Indirection<LockStmt>,
+      common::Indirection<NullifyStmt>, common::Indirection<OpenStmt>,
+      common::Indirection<PointerAssignmentStmt>,
+      common::Indirection<PrintStmt>, common::Indirection<ReadStmt>,
+      common::Indirection<ReturnStmt>, common::Indirection<RewindStmt>,
+      common::Indirection<StopStmt>, common::Indirection<SyncAllStmt>,
+      common::Indirection<SyncImagesStmt>, common::Indirection<SyncMemoryStmt>,
+      common::Indirection<SyncTeamStmt>, common::Indirection<UnlockStmt>,
+      common::Indirection<WaitStmt>, common::Indirection<WhereStmt>,
+      common::Indirection<WriteStmt>, common::Indirection<ComputedGotoStmt>,
+      common::Indirection<ForallStmt>, common::Indirection<ArithmeticIfStmt>,
+      common::Indirection<AssignStmt>, common::Indirection<AssignedGotoStmt>,
+      common::Indirection<PauseStmt>>
       u;
 };
 
@@ -465,14 +476,18 @@ struct ActionStmt {
 //        select-type-construct | where-construct | forall-construct
 struct ExecutableConstruct {
   UNION_CLASS_BOILERPLATE(ExecutableConstruct);
-  std::variant<Statement<ActionStmt>, Indirection<AssociateConstruct>,
-      Indirection<BlockConstruct>, Indirection<CaseConstruct>,
-      Indirection<ChangeTeamConstruct>, Indirection<CriticalConstruct>,
-      Statement<Indirection<LabelDoStmt>>, Statement<Indirection<EndDoStmt>>,
-      Indirection<DoConstruct>, Indirection<IfConstruct>,
-      Indirection<SelectRankConstruct>, Indirection<SelectTypeConstruct>,
-      Indirection<WhereConstruct>, Indirection<ForallConstruct>,
-      Indirection<CompilerDirective>, Indirection<OpenMPConstruct>>
+  std::variant<Statement<ActionStmt>, common::Indirection<AssociateConstruct>,
+      common::Indirection<BlockConstruct>, common::Indirection<CaseConstruct>,
+      common::Indirection<ChangeTeamConstruct>,
+      common::Indirection<CriticalConstruct>,
+      Statement<common::Indirection<LabelDoStmt>>,
+      Statement<common::Indirection<EndDoStmt>>,
+      common::Indirection<DoConstruct>, common::Indirection<IfConstruct>,
+      common::Indirection<SelectRankConstruct>,
+      common::Indirection<SelectTypeConstruct>,
+      common::Indirection<WhereConstruct>, common::Indirection<ForallConstruct>,
+      common::Indirection<CompilerDirective>,
+      common::Indirection<OpenMPConstruct>>
       u;
 };
 
@@ -481,9 +496,10 @@ struct ExecutableConstruct {
 // Extension (PGI/Intel): also accept NAMELIST in execution part
 struct ExecutionPartConstruct {
   UNION_CLASS_BOILERPLATE(ExecutionPartConstruct);
-  std::variant<ExecutableConstruct, Statement<Indirection<FormatStmt>>,
-      Statement<Indirection<EntryStmt>>, Statement<Indirection<DataStmt>>,
-      Statement<Indirection<NamelistStmt>>, ErrorRecovery>
+  std::variant<ExecutableConstruct, Statement<common::Indirection<FormatStmt>>,
+      Statement<common::Indirection<EntryStmt>>,
+      Statement<common::Indirection<DataStmt>>,
+      Statement<common::Indirection<NamelistStmt>>, ErrorRecovery>
       u;
 };
 
@@ -495,9 +511,10 @@ WRAPPER_CLASS(ExecutionPart, std::list<ExecutionPartConstruct>);
 // R503 external-subprogram -> function-subprogram | subroutine-subprogram
 struct ProgramUnit {
   UNION_CLASS_BOILERPLATE(ProgramUnit);
-  std::variant<Indirection<MainProgram>, Indirection<FunctionSubprogram>,
-      Indirection<SubroutineSubprogram>, Indirection<Module>,
-      Indirection<Submodule>, Indirection<BlockData>>
+  std::variant<common::Indirection<MainProgram>,
+      common::Indirection<FunctionSubprogram>,
+      common::Indirection<SubroutineSubprogram>, common::Indirection<Module>,
+      common::Indirection<Submodule>, common::Indirection<BlockData>>
       u;
 };
 
@@ -929,7 +946,7 @@ struct ComponentAttrSpec {
 EMPTY_CLASS(NullInit);
 
 // R744 initial-data-target -> designator
-using InitialDataTarget = Indirection<Designator>;
+using InitialDataTarget = common::Indirection<Designator>;
 
 // R743 component-initialization ->
 //        = constant-expr | => null-init | => initial-data-target
@@ -939,7 +956,7 @@ using InitialDataTarget = Indirection<Designator>;
 struct Initialization {
   UNION_CLASS_BOILERPLATE(Initialization);
   std::variant<ConstantExpr, NullInit, InitialDataTarget,
-      std::list<Indirection<DataStmtValue>>>
+      std::list<common::Indirection<DataStmtValue>>>
       u;
 };
 
@@ -1057,7 +1074,7 @@ struct TypeBoundProcedureStmt {
 //        GENERIC [, access-spec] :: generic-spec => binding-name-list
 struct TypeBoundGenericStmt {
   TUPLE_CLASS_BOILERPLATE(TypeBoundGenericStmt);
-  std::tuple<std::optional<AccessSpec>, Indirection<GenericSpec>,
+  std::tuple<std::optional<AccessSpec>, common::Indirection<GenericSpec>,
       std::list<Name>>
       t;
 };
@@ -1103,7 +1120,7 @@ struct DerivedTypeDef {
 // R758 component-data-source -> expr | data-target | proc-target
 // R1037 data-target -> expr
 // R1040 proc-target -> expr | procedure-name | proc-component-ref
-WRAPPER_CLASS(ComponentDataSource, Indirection<Expr>);
+WRAPPER_CLASS(ComponentDataSource, common::Indirection<Expr>);
 
 // R757 component-spec -> [keyword =] component-data-source
 struct ComponentSpec {
@@ -1149,7 +1166,9 @@ struct AcValue {
     std::tuple<ScalarIntExpr, ScalarIntExpr, std::optional<ScalarIntExpr>> t;
   };
   UNION_CLASS_BOILERPLATE(AcValue);
-  std::variant<Triplet, Indirection<Expr>, Indirection<AcImpliedDo>> u;
+  std::variant<Triplet, common::Indirection<Expr>,
+      common::Indirection<AcImpliedDo>>
+      u;
 };
 
 // R770 ac-spec -> type-spec :: | [type-spec ::] ac-value-list
@@ -1292,7 +1311,7 @@ struct TypeDeclarationStmt {
 // R828 access-id -> access-name | generic-spec
 struct AccessId {
   UNION_CLASS_BOILERPLATE(AccessId);
-  std::variant<Name, Indirection<GenericSpec>> u;
+  std::variant<Name, common::Indirection<GenericSpec>> u;
 };
 
 // R827 access-stmt -> access-spec [[::] access-id-list]
@@ -1344,7 +1363,7 @@ WRAPPER_CLASS(ContiguousStmt, std::list<ObjectName>);
 
 // R847 constant-subobject -> designator
 // R846 int-constant-subobject -> constant-subobject
-using ConstantSubobject = Constant<Indirection<Designator>>;
+using ConstantSubobject = Constant<common::Indirection<Designator>>;
 
 // R845 data-stmt-constant ->
 //        scalar-constant | scalar-constant-subobject |
@@ -1380,7 +1399,9 @@ struct DataStmtValue {
 //        array-element | scalar-structure-component | data-implied-do
 struct DataIDoObject {
   UNION_CLASS_BOILERPLATE(DataIDoObject);
-  std::variant<Scalar<Indirection<Designator>>, Indirection<DataImpliedDo>> u;
+  std::variant<Scalar<common::Indirection<Designator>>,
+      common::Indirection<DataImpliedDo>>
+      u;
 };
 
 // R840 data-implied-do ->
@@ -1398,7 +1419,7 @@ struct DataImpliedDo {
 // R839 data-stmt-object -> variable | data-implied-do
 struct DataStmtObject {
   UNION_CLASS_BOILERPLATE(DataStmtObject);
-  std::variant<Indirection<Variable>, DataImpliedDo> u;
+  std::variant<common::Indirection<Variable>, DataImpliedDo> u;
 };
 
 // R838 data-stmt-set -> data-stmt-object-list / data-stmt-value-list /
@@ -1506,7 +1527,7 @@ struct CommonStmt {
 };
 
 // R872 equivalence-object -> variable-name | array-element | substring
-WRAPPER_CLASS(EquivalenceObject, Indirection<Designator>);
+WRAPPER_CLASS(EquivalenceObject, common::Indirection<Designator>);
 
 // R870 equivalence-stmt -> EQUIVALENCE equivalence-set-list
 // R871 equivalence-set -> ( equivalence-object , equivalence-object-list )
@@ -1542,13 +1563,13 @@ struct SectionSubscript {
 using Cosubscript = ScalarIntExpr;
 
 // R1115 team-variable -> scalar-variable
-using TeamVariable = Scalar<Indirection<Variable>>;
+using TeamVariable = Scalar<common::Indirection<Variable>>;
 
 // R926 image-selector-spec ->
 //        STAT = stat-variable | TEAM = team-variable |
 //        TEAM_NUMBER = scalar-int-expr
 struct ImageSelectorSpec {
-  WRAPPER_CLASS(Stat, Scalar<Integer<Indirection<Variable>>>);
+  WRAPPER_CLASS(Stat, Scalar<Integer<common::Indirection<Variable>>>);
   WRAPPER_CLASS(Team, TeamVariable);
   WRAPPER_CLASS(Team_Number, ScalarIntExpr);
   UNION_CLASS_BOILERPLATE(ImageSelectorSpec);
@@ -1566,7 +1587,7 @@ struct ImageSelector {
 struct Expr {
   UNION_CLASS_BOILERPLATE(Expr);
 
-  WRAPPER_CLASS(IntrinsicUnary, Indirection<Expr>);
+  WRAPPER_CLASS(IntrinsicUnary, common::Indirection<Expr>);
   struct Parentheses : public IntrinsicUnary {
     using IntrinsicUnary::IntrinsicUnary;
   };
@@ -1580,16 +1601,17 @@ struct Expr {
     using IntrinsicUnary::IntrinsicUnary;
   };
 
-  WRAPPER_CLASS(PercentLoc, Indirection<Variable>);  // %LOC(v) extension
+  WRAPPER_CLASS(
+      PercentLoc, common::Indirection<Variable>);  // %LOC(v) extension
 
   struct DefinedUnary {
     TUPLE_CLASS_BOILERPLATE(DefinedUnary);
-    std::tuple<DefinedOpName, Indirection<Expr>> t;
+    std::tuple<DefinedOpName, common::Indirection<Expr>> t;
   };
 
   struct IntrinsicBinary {
     TUPLE_CLASS_BOILERPLATE(IntrinsicBinary);
-    std::tuple<Indirection<Expr>, Indirection<Expr>> t;
+    std::tuple<common::Indirection<Expr>, common::Indirection<Expr>> t;
   };
   struct Power : public IntrinsicBinary {
     using IntrinsicBinary::IntrinsicBinary;
@@ -1627,6 +1649,7 @@ struct Expr {
   struct GT : public IntrinsicBinary {
     using IntrinsicBinary::IntrinsicBinary;
   };
+  // TODO: .UN. unordered comparisons?
   struct AND : public IntrinsicBinary {
     using IntrinsicBinary::IntrinsicBinary;
   };
@@ -1650,18 +1673,21 @@ struct Expr {
 
   struct DefinedBinary {
     TUPLE_CLASS_BOILERPLATE(DefinedBinary);
-    std::tuple<DefinedOpName, Indirection<Expr>, Indirection<Expr>> t;
+    std::tuple<DefinedOpName, common::Indirection<Expr>,
+        common::Indirection<Expr>>
+        t;
   };
 
   explicit Expr(Designator &&);
   explicit Expr(FunctionReference &&);
 
-  std::variant<Indirection<CharLiteralConstantSubstring>, LiteralConstant,
-      Indirection<Designator>, ArrayConstructor, StructureConstructor,
-      Indirection<TypeParamInquiry>, Indirection<FunctionReference>,
-      Parentheses, UnaryPlus, Negate, NOT, PercentLoc, DefinedUnary, Power,
-      Multiply, Divide, Add, Subtract, Concat, LT, LE, EQ, NE, GE, GT, AND, OR,
-      EQV, NEQV, XOR, DefinedBinary, ComplexConstructor>
+  std::variant<common::Indirection<CharLiteralConstantSubstring>,
+      LiteralConstant, common::Indirection<Designator>, ArrayConstructor,
+      StructureConstructor, common::Indirection<TypeParamInquiry>,
+      common::Indirection<FunctionReference>, Parentheses, UnaryPlus, Negate,
+      NOT, PercentLoc, DefinedUnary, Power, Multiply, Divide, Add, Subtract,
+      Concat, LT, LE, EQ, NE, GE, GT, AND, OR, EQV, NEQV, XOR, DefinedBinary,
+      ComplexConstructor>
       u;
 };
 
@@ -1681,8 +1707,9 @@ struct PartRef {
 struct DataRef {
   UNION_CLASS_BOILERPLATE(DataRef);
   explicit DataRef(std::list<PartRef> &&);
-  std::variant<Name, Indirection<StructureComponent>, Indirection<ArrayElement>,
-      Indirection<CoindexedNamedObject>>
+  std::variant<Name, common::Indirection<StructureComponent>,
+      common::Indirection<ArrayElement>,
+      common::Indirection<CoindexedNamedObject>>
       u;
 };
 
@@ -1716,7 +1743,9 @@ struct Designator {
 // R902 variable -> designator | function-reference
 struct Variable {
   UNION_CLASS_BOILERPLATE(Variable);
-  std::variant<Indirection<Designator>, Indirection<FunctionReference>> u;
+  std::variant<common::Indirection<Designator>,
+      common::Indirection<FunctionReference>>
+      u;
 };
 
 // R904 logical-variable -> variable
@@ -1840,8 +1869,8 @@ struct StatOrErrmsg {
 // R931 source-expr -> expr
 struct AllocOpt {
   UNION_CLASS_BOILERPLATE(AllocOpt);
-  WRAPPER_CLASS(Mold, Indirection<Expr>);
-  WRAPPER_CLASS(Source, Indirection<Expr>);
+  WRAPPER_CLASS(Mold, common::Indirection<Expr>);
+  WRAPPER_CLASS(Source, common::Indirection<Expr>);
   std::variant<Mold, Source, StatOrErrmsg> u;
 };
 
@@ -1921,7 +1950,7 @@ struct WhereConstructStmt {
 struct WhereBodyConstruct {
   UNION_CLASS_BOILERPLATE(WhereBodyConstruct);
   std::variant<Statement<AssignmentStmt>, Statement<WhereStmt>,
-      Indirection<WhereConstruct>>
+      common::Indirection<WhereConstruct>>
       u;
 };
 
@@ -1962,7 +1991,7 @@ struct WhereConstruct {
 //         [forall-construct-name :] FORALL concurrent-header
 struct ForallConstructStmt {
   TUPLE_CLASS_BOILERPLATE(ForallConstructStmt);
-  std::tuple<std::optional<Name>, Indirection<ConcurrentHeader>> t;
+  std::tuple<std::optional<Name>, common::Indirection<ConcurrentHeader>> t;
 };
 
 // R1053 forall-assignment-stmt -> assignment-stmt | pointer-assignment-stmt
@@ -1974,7 +2003,7 @@ struct ForallAssignmentStmt {
 // R1055 forall-stmt -> FORALL concurrent-header forall-assignment-stmt
 struct ForallStmt {
   TUPLE_CLASS_BOILERPLATE(ForallStmt);
-  std::tuple<Indirection<ConcurrentHeader>, ForallAssignmentStmt> t;
+  std::tuple<common::Indirection<ConcurrentHeader>, ForallAssignmentStmt> t;
 };
 
 // R1052 forall-body-construct ->
@@ -1983,7 +2012,8 @@ struct ForallStmt {
 struct ForallBodyConstruct {
   UNION_CLASS_BOILERPLATE(ForallBodyConstruct);
   std::variant<Statement<ForallAssignmentStmt>, Statement<WhereStmt>,
-      WhereConstruct, Indirection<ForallConstruct>, Statement<ForallStmt>>
+      WhereConstruct, common::Indirection<ForallConstruct>,
+      Statement<ForallStmt>>
       u;
 };
 
@@ -2552,7 +2582,7 @@ struct IoControlSpec {
 // R1216 input-item -> variable | io-implied-do
 struct InputItem {
   UNION_CLASS_BOILERPLATE(InputItem);
-  std::variant<Variable, Indirection<InputImpliedDo>> u;
+  std::variant<Variable, common::Indirection<InputImpliedDo>> u;
 };
 
 // R1210 read-stmt ->
@@ -2575,7 +2605,7 @@ struct ReadStmt {
 // R1217 output-item -> expr | io-implied-do
 struct OutputItem {
   UNION_CLASS_BOILERPLATE(OutputItem);
-  std::variant<Expr, Indirection<OutputImpliedDo>> u;
+  std::variant<Expr, common::Indirection<OutputImpliedDo>> u;
 };
 
 // R1211 write-stmt -> WRITE ( io-control-spec-list ) [output-item-list]
@@ -2750,8 +2780,9 @@ WRAPPER_CLASS(ModuleStmt, Name);
 //         separate-module-subprogram
 struct ModuleSubprogram {
   UNION_CLASS_BOILERPLATE(ModuleSubprogram);
-  std::variant<Indirection<FunctionSubprogram>,
-      Indirection<SubroutineSubprogram>, Indirection<SeparateModuleSubprogram>>
+  std::variant<common::Indirection<FunctionSubprogram>,
+      common::Indirection<SubroutineSubprogram>,
+      common::Indirection<SeparateModuleSubprogram>>
       u;
 };
 
@@ -2865,7 +2896,7 @@ struct InterfaceStmt {
 // R1413 only-use-name -> use-name
 struct Only {
   UNION_CLASS_BOILERPLATE(Only);
-  std::variant<Indirection<GenericSpec>, Name, Rename> u;
+  std::variant<common::Indirection<GenericSpec>, Name, Rename> u;
 };
 
 // R1409 use-stmt ->
@@ -2972,14 +3003,14 @@ struct InterfaceBody {
   UNION_CLASS_BOILERPLATE(InterfaceBody);
   struct Function {
     TUPLE_CLASS_BOILERPLATE(Function);
-    std::tuple<Statement<FunctionStmt>, Indirection<SpecificationPart>,
+    std::tuple<Statement<FunctionStmt>, common::Indirection<SpecificationPart>,
         Statement<EndFunctionStmt>>
         t;
   };
   struct Subroutine {
     TUPLE_CLASS_BOILERPLATE(Subroutine);
-    std::tuple<Statement<SubroutineStmt>, Indirection<SpecificationPart>,
-        Statement<EndSubroutineStmt>>
+    std::tuple<Statement<SubroutineStmt>,
+        common::Indirection<SpecificationPart>, Statement<EndSubroutineStmt>>
         t;
   };
   std::variant<Function, Subroutine> u;
@@ -3033,10 +3064,10 @@ struct ActualArg {
   WRAPPER_CLASS(PercentRef, Variable);  // %REF(v) extension
   WRAPPER_CLASS(PercentVal, Expr);  // %VAL(x) extension
   UNION_CLASS_BOILERPLATE(ActualArg);
-  ActualArg(Expr &&x) : u{Indirection<Expr>(std::move(x))} {}
-  ActualArg(Variable &&x) : u{Indirection<Variable>(std::move(x))} {}
-  std::variant<Indirection<Expr>, Indirection<Variable>, Name, ProcComponentRef,
-      AltReturnSpec, PercentRef, PercentVal>
+  ActualArg(Expr &&x) : u{common::Indirection<Expr>(std::move(x))} {}
+  ActualArg(Variable &&x) : u{common::Indirection<Variable>(std::move(x))} {}
+  std::variant<common::Indirection<Expr>, common::Indirection<Variable>, Name,
+      ProcComponentRef, AltReturnSpec, PercentRef, PercentVal>
       u;
 };
 
@@ -3138,8 +3169,8 @@ struct StructureDef;
 
 struct StructureField {
   UNION_CLASS_BOILERPLATE(StructureField);
-  std::variant<Statement<DataComponentDefStmt>, Indirection<StructureDef>,
-      Indirection<Union>>
+  std::variant<Statement<DataComponentDefStmt>,
+      common::Indirection<StructureDef>, common::Indirection<Union>>
       u;
 };
 
@@ -3308,7 +3339,7 @@ struct OmpReductionClause {
 
 struct OmpDependSinkVecLength {
   TUPLE_CLASS_BOILERPLATE(OmpDependSinkVecLength);
-  std::tuple<Indirection<DefinedOperator>, ScalarIntConstantExpr> t;
+  std::tuple<common::Indirection<DefinedOperator>, ScalarIntConstantExpr> t;
 };
 
 struct OmpDependSinkVec {
@@ -3442,8 +3473,8 @@ WRAPPER_CLASS(OpenMPStandaloneConstruct, Statement<OmpStandaloneDirective>);
 
 struct OpenMPConstruct {
   UNION_CLASS_BOILERPLATE(OpenMPConstruct);
-  std::variant<Indirection<OpenMPStandaloneConstruct>,
-      Indirection<OpenMPLoopConstruct>>
+  std::variant<common::Indirection<OpenMPStandaloneConstruct>,
+      common::Indirection<OpenMPLoopConstruct>>
       u;
 };
 
index 8b95489..17c0cf1 100644 (file)
@@ -14,9 +14,9 @@
 
 #include "preprocessor.h"
 #include "characters.h"
-#include "idioms.h"
 #include "message.h"
 #include "prescan.h"
+#include "../common/idioms.h"
 #include <algorithm>
 #include <cinttypes>
 #include <cstddef>
index 9b67157..b47bcef 100644 (file)
 
 #include "prescan.h"
 #include "characters.h"
-#include "idioms.h"
 #include "message.h"
 #include "preprocessor.h"
 #include "source.h"
 #include "token-sequence.h"
+#include "../common/idioms.h"
 #include <cstddef>
 #include <cstring>
 #include <sstream>
index 5bcf695..77d0197 100644 (file)
@@ -13,7 +13,7 @@
 // limitations under the License.
 
 #include "provenance.h"
-#include "idioms.h"
+#include "../common/idioms.h"
 #include <utility>
 
 namespace Fortran::parser {
@@ -150,7 +150,7 @@ void AllSources::EmitMessage(std::ostream &o, ProvenanceRange range,
   CHECK(IsValid(range));
   const Origin &origin{MapToOrigin(range.start())};
   std::visit(
-      visitors{
+      common::visitors{
           [&](const Inclusion &inc) {
             o << inc.source.path();
             std::size_t offset{origin.covers.MemberOffset(range.start())};
@@ -210,12 +210,13 @@ void AllSources::EmitMessage(std::ostream &o, ProvenanceRange range,
 const SourceFile *AllSources::GetSourceFile(
     Provenance at, std::size_t *offset) const {
   const Origin &origin{MapToOrigin(at)};
-  return std::visit(visitors{[&](const Inclusion &inc) {
-                               if (offset != nullptr) {
-                                 *offset = origin.covers.MemberOffset(at);
-                               }
-                               return &inc.source;
-                             },
+  return std::visit(common::visitors{[&](const Inclusion &inc) {
+                                       if (offset != nullptr) {
+                                         *offset =
+                                             origin.covers.MemberOffset(at);
+                                       }
+                                       return &inc.source;
+                                     },
                         [&](const Macro &mac) {
                           return GetSourceFile(origin.replaces.start(), offset);
                         },
@@ -271,9 +272,9 @@ AllSources::Origin::Origin(ProvenanceRange r, const std::string &text)
 
 const char &AllSources::Origin::operator[](std::size_t n) const {
   return std::visit(
-      visitors{[n](const Inclusion &inc) -> const char & {
-                 return inc.source.content()[n];
-               },
+      common::visitors{[n](const Inclusion &inc) -> const char & {
+                         return inc.source.content()[n];
+                       },
           [n](const Macro &mac) -> const char & { return mac.expansion[n]; },
           [n](const CompilerInsertion &ins) -> const char & {
             return ins.text[n];
@@ -339,12 +340,12 @@ void AllSources::Dump(std::ostream &o) const {
     o << "   ";
     DumpRange(o, m.covers);
     o << " -> ";
-    std::visit(visitors{[&](const Inclusion &inc) {
-                          if (inc.isModule) {
-                            o << "module ";
-                          }
-                          o << "file " << inc.source.path();
-                        },
+    std::visit(common::visitors{[&](const Inclusion &inc) {
+                                  if (inc.isModule) {
+                                    o << "module ";
+                                  }
+                                  o << "file " << inc.source.path();
+                                },
                    [&](const Macro &mac) { o << "macro " << mac.expansion; },
                    [&](const CompilerInsertion &ins) {
                      o << "compiler '" << ins.text << '\'';
index 0c6f176..8f0e6ea 100644 (file)
@@ -17,9 +17,9 @@
 
 #include "char-block.h"
 #include "char-buffer.h"
-#include "idioms.h"
-#include "interval.h"
 #include "source.h"
+#include "../common/idioms.h"
+#include "../common/interval.h"
 #include <cstddef>
 #include <map>
 #include <memory>
@@ -79,7 +79,7 @@ private:
   std::size_t offset_{0};
 };
 
-using ProvenanceRange = Interval<Provenance>;
+using ProvenanceRange = common::Interval<Provenance>;
 
 // Maps 0-based local offsets in some contiguous range (e.g., a token
 // sequence) to their provenances.  Lookup time is on the order of
index aef7253..2497722 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "source.h"
 #include "char-buffer.h"
-#include "idioms.h"
+#include "../common/idioms.h"
 #include <algorithm>
 #include <cerrno>
 #include <cstddef>
index cb35a4d..9544f82 100644 (file)
 #include "basic-parsers.h"
 #include "char-set.h"
 #include "characters.h"
-#include "idioms.h"
 #include "instrumented-parser.h"
 #include "provenance.h"
 #include "type-parsers.h"
+#include "../common/idioms.h"
 #include <cstddef>
 #include <cstring>
 #include <functional>
@@ -364,10 +364,10 @@ struct BOZLiteral {
       content += **at;
     }
 
-    if (!shift) {
+    if (!shift.has_value()) {
       // extension: base allowed to appear as suffix, too
-      if (!IsNonstandardUsageOk(state) || !(at = nextCh.Parse(state)) ||
-          !baseChar(**at)) {
+      if (!IsNonstandardUsageOk(state) ||
+          !(at = nextCh.Parse(state)).has_value() || !baseChar(**at)) {
         return {};
       }
       spaceCheck.Parse(state);
@@ -478,7 +478,7 @@ struct SignedIntLiteralConstantWithoutKind {
     bool negate{false};
     if (minus.Parse(state)) {
       negate = true;
-    } else if (!plus.Parse(state)) {
+    } else if (!plus.Parse(state).has_value()) {
       return {};
     }
     return SignedInteger(digitString.Parse(state), at, negate, state);
@@ -565,7 +565,7 @@ struct HollerithLiteral {
     const char *start{state.GetLocation()};
     std::optional<std::uint64_t> charCount{
         DigitStringIgnoreSpaces{}.Parse(state)};
-    if (!charCount || *charCount < 1) {
+    if (!charCount.has_value() || *charCount < 1) {
       return {};
     }
     static constexpr auto letterH = "h"_ch;
index 9481e7d..935392b 100644 (file)
 
 #include "unparse.h"
 #include "characters.h"
-#include "idioms.h"
-#include "indirection.h"
 #include "parse-tree-visitor.h"
 #include "parse-tree.h"
+#include "../common/idioms.h"
+#include "../common/indirection.h"
 #include <algorithm>
 #include <cinttypes>
 #include <cstddef>
@@ -129,9 +129,9 @@ public:
   }
   void Unparse(const KindSelector &x) {  // R706
     std::visit(
-        visitors{[&](const ScalarIntConstantExpr &y) {
-                   Put('('), Word("KIND="), Walk(y), Put(')');
-                 },
+        common::visitors{[&](const ScalarIntConstantExpr &y) {
+                           Put('('), Word("KIND="), Walk(y), Put(')');
+                         },
             [&](const KindSelector::StarSize &y) { Put('*'), Walk(y.v); }},
         x.u);
   }
@@ -157,16 +157,17 @@ public:
     Walk(", LEN=", x.length), Put(')');
   }
   void Unparse(const LengthSelector &x) {  // R722
-    std::visit(visitors{[&](const TypeParamValue &y) {
-                          Put('('), Word("LEN="), Walk(y), Put(')');
-                        },
+    std::visit(common::visitors{[&](const TypeParamValue &y) {
+                                  Put('('), Word("LEN="), Walk(y), Put(')');
+                                },
                    [&](const CharLength &y) { Put('*'), Walk(y); }},
         x.u);
   }
   void Unparse(const CharLength &x) {  // R723
-    std::visit(
-        visitors{[&](const TypeParamValue &y) { Put('('), Walk(y), Put(')'); },
-            [&](const std::int64_t &y) { Walk(y); }},
+    std::visit(common::visitors{[&](const TypeParamValue &y) {
+                                  Put('('), Walk(y), Put(')');
+                                },
+                   [&](const std::int64_t &y) { Walk(y); }},
         x.u);
   }
   void Unparse(const CharLiteralConstant &x) {  // R724
@@ -235,7 +236,8 @@ public:
                       std::get<std::optional<Initialization>>(d.t);
                   return init.has_value() &&
                       std::holds_alternative<
-                          std::list<Indirection<DataStmtValue>>>(init->u);
+                          std::list<common::Indirection<DataStmtValue>>>(
+                          init->u);
                 }))) {
       Put(" ::");
     }
@@ -247,14 +249,15 @@ public:
   void Unparse(const Pointer &x) { Word("POINTER"); }
   void Unparse(const Contiguous &x) { Word("CONTIGUOUS"); }
   void Before(const ComponentAttrSpec &x) {
-    std::visit(visitors{[&](const CoarraySpec &) { Word("CODIMENSION["); },
-                   [&](const ComponentArraySpec &) { Word("DIMENSION("); },
-                   [](const auto &) {}},
+    std::visit(
+        common::visitors{[&](const CoarraySpec &) { Word("CODIMENSION["); },
+            [&](const ComponentArraySpec &) { Word("DIMENSION("); },
+            [](const auto &) {}},
         x.u);
   }
   void Post(const ComponentAttrSpec &x) {
     std::visit(
-        visitors{[&](const CoarraySpec &) { Put(']'); },
+        common::visitors{[&](const CoarraySpec &) { Put(']'); },
             [&](const ComponentArraySpec &) { Put(')'); }, [](const auto &) {}},
         x.u);
   }
@@ -266,9 +269,10 @@ public:
     Walk(std::get<std::optional<Initialization>>(x.t));
   }
   void Unparse(const ComponentArraySpec &x) {  // R740
-    std::visit(
-        visitors{[&](const std::list<ExplicitShapeSpec> &y) { Walk(y, ","); },
-            [&](const DeferredShapeSpecList &y) { Walk(y); }},
+    std::visit(common::visitors{[&](const std::list<ExplicitShapeSpec> &y) {
+                                  Walk(y, ",");
+                                },
+                   [&](const DeferredShapeSpecList &y) { Walk(y); }},
         x.u);
   }
   void Unparse(const ProcComponentDefStmt &x) {  // R741
@@ -282,12 +286,13 @@ public:
   }
   void Unparse(const Pass &x) { Word("PASS"), Walk("(", x.v, ")"); }
   void Unparse(const Initialization &x) {  // R743 & R805
-    std::visit(visitors{[&](const ConstantExpr &y) { Put(" = "), Walk(y); },
-                   [&](const NullInit &y) { Put(" => "), Walk(y); },
-                   [&](const InitialDataTarget &y) { Put(" => "), Walk(y); },
-                   [&](const std::list<Indirection<DataStmtValue>> &y) {
-                     Walk("/", y, ", ", "/");
-                   }},
+    std::visit(
+        common::visitors{[&](const ConstantExpr &y) { Put(" = "), Walk(y); },
+            [&](const NullInit &y) { Put(" => "), Walk(y); },
+            [&](const InitialDataTarget &y) { Put(" => "), Walk(y); },
+            [&](const std::list<common::Indirection<DataStmtValue>> &y) {
+              Walk("/", y, ", ", "/");
+            }},
         x.u);
   }
   void Unparse(const PrivateStmt &x) {  // R745
@@ -308,7 +313,7 @@ public:
   }
   void Unparse(const TypeBoundGenericStmt &x) {  // R751
     Word("GENERIC"), Walk(", ", std::get<std::optional<AccessSpec>>(x.t));
-    Put(" :: "), Walk(std::get<Indirection<GenericSpec>>(x.t));
+    Put(" :: "), Walk(std::get<common::Indirection<GenericSpec>>(x.t));
     Put(" => "), Walk(std::get<std::list<Name>>(x.t), ", ");
   }
   void Post(const BindAttr::Deferred &) { Word("DEFERRED"); }  // R752
@@ -387,7 +392,8 @@ public:
     Walk(dts), Walk(", ", attrs, ", ");
 
     static const auto isInitializerOldStyle = [](const Initialization &i) {
-      return std::holds_alternative<std::list<Indirection<DataStmtValue>>>(i.u);
+      return std::holds_alternative<
+          std::list<common::Indirection<DataStmtValue>>>(i.u);
     };
     static const auto hasAssignmentInitializer = [](const EntityDecl &d) {
       // Does a declaration have a new-style =x initializer?
@@ -435,13 +441,14 @@ public:
     Put(' '), Walk(std::get<std::list<EntityDecl>>(x.t), ", ");
   }
   void Before(const AttrSpec &x) {  // R802
-    std::visit(visitors{[&](const CoarraySpec &y) { Word("CODIMENSION["); },
-                   [&](const ArraySpec &y) { Word("DIMENSION("); },
-                   [](const auto &) {}},
+    std::visit(
+        common::visitors{[&](const CoarraySpec &y) { Word("CODIMENSION["); },
+            [&](const ArraySpec &y) { Word("DIMENSION("); },
+            [](const auto &) {}},
         x.u);
   }
   void Post(const AttrSpec &x) {
-    std::visit(visitors{[&](const CoarraySpec &y) { Put(']'); },
+    std::visit(common::visitors{[&](const CoarraySpec &y) { Put(']'); },
                    [&](const ArraySpec &y) { Put(')'); }, [](const auto &) {}},
         x.u);
   }
@@ -459,8 +466,9 @@ public:
     Word("BIND(C"), Walk(", NAME=", x.v), Put(')');
   }
   void Unparse(const CoarraySpec &x) {  // R809
-    std::visit(visitors{[&](const DeferredCoshapeSpecList &y) { Walk(y); },
-                   [&](const ExplicitCoshapeSpec &y) { Walk(y); }},
+    std::visit(
+        common::visitors{[&](const DeferredCoshapeSpecList &y) { Walk(y); },
+            [&](const ExplicitCoshapeSpec &y) { Walk(y); }},
         x.u);
   }
   void Unparse(const DeferredCoshapeSpecList &x) {  // R810
@@ -480,13 +488,14 @@ public:
     Walk(std::get<SpecificationExpr>(x.t));
   }
   void Unparse(const ArraySpec &x) {  // R815
-    std::visit(
-        visitors{[&](const std::list<ExplicitShapeSpec> &y) { Walk(y, ","); },
-            [&](const std::list<AssumedShapeSpec> &y) { Walk(y, ","); },
-            [&](const DeferredShapeSpecList &y) { Walk(y); },
-            [&](const AssumedSizeSpec &y) { Walk(y); },
-            [&](const ImpliedShapeSpec &y) { Walk(y); },
-            [&](const AssumedRankSpec &y) { Walk(y); }},
+    std::visit(common::visitors{[&](const std::list<ExplicitShapeSpec> &y) {
+                                  Walk(y, ",");
+                                },
+                   [&](const std::list<AssumedShapeSpec> &y) { Walk(y, ","); },
+                   [&](const DeferredShapeSpecList &y) { Walk(y); },
+                   [&](const AssumedSizeSpec &y) { Walk(y); },
+                   [&](const ImpliedShapeSpec &y) { Walk(y); },
+                   [&](const AssumedRankSpec &y) { Walk(y); }},
         x.u);
   }
   void Post(const AssumedShapeSpec &) { Put(':'); }  // R819
@@ -621,11 +630,12 @@ public:
   }
   void Unparse(const ImplicitStmt &x) {  // R863
     Word("IMPLICIT ");
-    std::visit(
-        visitors{[&](const std::list<ImplicitSpec> &y) { Walk(y, ", "); },
-            [&](const std::list<ImplicitStmt::ImplicitNoneNameSpec> &y) {
-              Word("NONE"), Walk(" (", y, ", ", ")");
-            }},
+    std::visit(common::visitors{[&](const std::list<ImplicitSpec> &y) {
+                                  Walk(y, ", ");
+                                },
+                   [&](const std::list<ImplicitStmt::ImplicitNoneNameSpec> &y) {
+                     Word("NONE"), Walk(" (", y, ", ", ")");
+                   }},
         x.u);
   }
   void Unparse(const ImplicitSpec &x) {  // R864
@@ -732,7 +742,7 @@ public:
     Walk(", ", std::get<std::list<AllocOpt>>(x.t), ", "), Put(')');
   }
   void Before(const AllocOpt &x) {  // R928, R931
-    std::visit(visitors{[&](const AllocOpt::Mold &) { Word("MOLD="); },
+    std::visit(common::visitors{[&](const AllocOpt::Mold &) { Word("MOLD="); },
                    [&](const AllocOpt::Source &) { Word("SOURCE="); },
                    [](const StatOrErrmsg &) {}},
         x.u);
@@ -759,7 +769,7 @@ public:
     Walk(", ", std::get<std::list<StatOrErrmsg>>(x.t), ", "), Put(')');
   }
   void Before(const StatOrErrmsg &x) {  // R942 & R1165
-    std::visit(visitors{[&](const StatVariable &) { Word("STAT="); },
+    std::visit(common::visitors{[&](const StatVariable &) { Word("STAT="); },
                    [&](const MsgVariable &) { Word("ERRMSG="); }},
         x.u);
   }
@@ -806,9 +816,9 @@ public:
   void Unparse(const PointerAssignmentStmt &x) {  // R1033, R1034, R1038
     Walk(std::get<DataRef>(x.t));
     std::visit(
-        visitors{[&](const std::list<BoundsRemapping> &y) {
-                   Put('('), Walk(y), Put(')');
-                 },
+        common::visitors{[&](const std::list<BoundsRemapping> &y) {
+                           Put('('), Walk(y), Put(')');
+                         },
             [&](const std::list<BoundsSpec> &y) { Walk("(", y, ", ", ")"); }},
         std::get<PointerAssignmentStmt::Bounds>(x.t).u);
     Put(" => "), Walk(std::get<Expr>(x.t));
@@ -841,7 +851,7 @@ public:
   }
   void Unparse(const ForallConstructStmt &x) {  // R1051
     Walk(std::get<std::optional<Name>>(x.t), ": ");
-    Word("FORALL"), Walk(std::get<Indirection<ConcurrentHeader>>(x.t));
+    Word("FORALL"), Walk(std::get<common::Indirection<ConcurrentHeader>>(x.t));
     Indent();
   }
   void Unparse(const EndForallStmt &x) {  // R1054
@@ -906,9 +916,9 @@ public:
     Word("DO "), Walk(std::get<std::optional<LoopControl>>(x.t));
   }
   void Unparse(const LoopControl &x) {  // R1123
-    std::visit(visitors{[&](const ScalarLogicalExpr &y) {
-                          Word("WHILE ("), Walk(y), Put(')');
-                        },
+    std::visit(common::visitors{[&](const ScalarLogicalExpr &y) {
+                                  Word("WHILE ("), Walk(y), Put(')');
+                                },
                    [&](const auto &y) { Walk(y); }},
         x.u);
   }
@@ -973,9 +983,9 @@ public:
     Outdent(), Word("END SELECT"), Walk(" ", x.v);
   }
   void Unparse(const CaseSelector &x) {  // R1145
-    std::visit(visitors{[&](const std::list<CaseValueRange> &y) {
-                          Put('('), Walk(y), Put(')');
-                        },
+    std::visit(common::visitors{[&](const std::list<CaseValueRange> &y) {
+                                  Put('('), Walk(y), Put(')');
+                                },
                    [&](const Default &) { Word("DEFAULT"); }},
         x.u);
   }
@@ -989,9 +999,9 @@ public:
   }
   void Unparse(const SelectRankCaseStmt &x) {  // R1150
     Outdent(), Word("RANK ");
-    std::visit(visitors{[&](const ScalarIntConstantExpr &y) {
-                          Put('('), Walk(y), Put(')');
-                        },
+    std::visit(common::visitors{[&](const ScalarIntConstantExpr &y) {
+                                  Put('('), Walk(y), Put(')');
+                                },
                    [&](const Star &) { Put("(*)"); },
                    [&](const Default &) { Word("DEFAULT"); }},
         std::get<SelectRankCaseStmt::Rank>(x.t).u);
@@ -1007,9 +1017,9 @@ public:
     Walk(" ", std::get<std::optional<Name>>(x.t)), Indent();
   }
   void Unparse(const TypeGuardStmt::Guard &x) {
-    std::visit(visitors{[&](const TypeSpec &y) {
-                          Word("TYPE IS ("), Walk(y), Put(')');
-                        },
+    std::visit(common::visitors{[&](const TypeSpec &y) {
+                                  Word("TYPE IS ("), Walk(y), Put(')');
+                                },
                    [&](const DerivedTypeSpec &y) {
                      Word("CLASS IS ("), Walk(y), Put(')');
                    },
@@ -1058,8 +1068,9 @@ public:
     Walk(", ", std::get<std::list<StatOrErrmsg>>(x.t), ", "), Put(')');
   }
   void Before(const EventWaitStmt::EventWaitSpec &x) {  // R1173, R1174
-    std::visit(visitors{[&](const ScalarIntExpr &x) { Word("UNTIL_COUNT="); },
-                   [](const StatOrErrmsg &) {}},
+    std::visit(
+        common::visitors{[&](const ScalarIntExpr &x) { Word("UNTIL_COUNT="); },
+            [](const StatOrErrmsg &) {}},
         x.u);
   }
   void Unparse(const EventWaitStmt &x) {  // R1170
@@ -1074,8 +1085,9 @@ public:
     Put(')');
   }
   void Before(const FormTeamStmt::FormTeamSpec &x) {  // R1176, R1177
-    std::visit(visitors{[&](const ScalarIntExpr &x) { Word("NEW_INDEX="); },
-                   [](const StatOrErrmsg &) {}},
+    std::visit(
+        common::visitors{[&](const ScalarIntExpr &x) { Word("NEW_INDEX="); },
+            [](const StatOrErrmsg &) {}},
         x.u);
   }
   void Unparse(const LockStmt &x) {  // R1178
@@ -1084,9 +1096,10 @@ public:
     Put(')');
   }
   void Before(const LockStmt::LockStat &x) {  // R1179
-    std::visit(
-        visitors{[&](const ScalarLogicalVariable &) { Word("ACQUIRED_LOCK="); },
-            [](const StatOrErrmsg &y) {}},
+    std::visit(common::visitors{[&](const ScalarLogicalVariable &) {
+                                  Word("ACQUIRED_LOCK=");
+                                },
+                   [](const StatOrErrmsg &y) {}},
         x.u);
   }
   void Unparse(const UnlockStmt &x) {  // R1180
@@ -1099,10 +1112,10 @@ public:
     Word("OPEN ("), Walk(x.v, ", "), Put(')');
   }
   bool Pre(const ConnectSpec &x) {  // R1205
-    return std::visit(visitors{[&](const FileUnitNumber &) {
-                                 Word("UNIT=");
-                                 return true;
-                               },
+    return std::visit(common::visitors{[&](const FileUnitNumber &) {
+                                         Word("UNIT=");
+                                         return true;
+                                       },
                           [&](const FileNameExpr &) {
                             Word("FILE=");
                             return true;
@@ -1141,7 +1154,7 @@ public:
     Word("CLOSE ("), Walk(x.v, ", "), Put(')');
   }
   void Before(const CloseStmt::CloseSpec &x) {  // R1209
-    std::visit(visitors{[&](const FileUnitNumber &) { Word("UNIT="); },
+    std::visit(common::visitors{[&](const FileUnitNumber &) { Word("UNIT="); },
                    [&](const StatVariable &) { Word("IOSTAT="); },
                    [&](const MsgVariable &) { Word("IOMSG="); },
                    [&](const ErrLabel &) { Word("ERR="); },
@@ -1185,10 +1198,10 @@ public:
     Walk(", ", std::get<std::list<OutputItem>>(x.t), ", ");
   }
   bool Pre(const IoControlSpec &x) {  // R1213
-    return std::visit(visitors{[&](const IoUnit &) {
-                                 Word("UNIT=");
-                                 return true;
-                               },
+    return std::visit(common::visitors{[&](const IoUnit &) {
+                                         Word("UNIT=");
+                                         return true;
+                                       },
                           [&](const Format &) {
                             Word("FMT=");
                             return true;
@@ -1255,7 +1268,7 @@ public:
     Word("WAIT ("), Walk(x.v, ", "), Put(')');
   }
   void Before(const WaitSpec &x) {  // R1223
-    std::visit(visitors{[&](const FileUnitNumber &) { Word("UNIT="); },
+    std::visit(common::visitors{[&](const FileUnitNumber &) { Word("UNIT="); },
                    [&](const EndLabel &) { Word("END="); },
                    [&](const EorLabel &) { Word("EOR="); },
                    [&](const ErrLabel &) { Word("ERR="); },
@@ -1274,7 +1287,7 @@ public:
     Word("REWIND ("), Walk(x.v, ", "), Put(')');
   }
   void Before(const PositionOrFlushSpec &x) {  // R1227 & R1229
-    std::visit(visitors{[&](const FileUnitNumber &) { Word("UNIT="); },
+    std::visit(common::visitors{[&](const FileUnitNumber &) { Word("UNIT="); },
                    [&](const MsgVariable &) { Word("IOMSG="); },
                    [&](const StatVariable &) { Word("IOSTAT="); },
                    [&](const ErrLabel &) { Word("ERR="); }},
@@ -1286,17 +1299,17 @@ public:
   void Unparse(const InquireStmt &x) {  // R1230
     Word("INQUIRE (");
     std::visit(
-        visitors{[&](const InquireStmt::Iolength &y) {
-                   Word("IOLENGTH="), Walk(y.t, ") ");
-                 },
+        common::visitors{[&](const InquireStmt::Iolength &y) {
+                           Word("IOLENGTH="), Walk(y.t, ") ");
+                         },
             [&](const std::list<InquireSpec> &y) { Walk(y, ", "), Put(')'); }},
         x.u);
   }
   bool Pre(const InquireSpec &x) {  // R1231
-    return std::visit(visitors{[&](const FileUnitNumber &) {
-                                 Word("UNIT=");
-                                 return true;
-                               },
+    return std::visit(common::visitors{[&](const FileUnitNumber &) {
+                                         Word("UNIT=");
+                                         return true;
+                                       },
                           [&](const FileNameExpr &) {
                             Word("FILE=");
                             return true;
@@ -1335,7 +1348,7 @@ public:
     if (x.repeatCount.has_value()) {
       Walk(*x.repeatCount);
     }
-    std::visit(visitors{[&](const std::string &y) { PutQuoted(y); },
+    std::visit(common::visitors{[&](const std::string &y) { PutQuoted(y); },
                    [&](const std::list<format::FormatItem> &y) {
                      Walk("(", y, ",", ")");
                    },
@@ -1443,15 +1456,17 @@ public:
   void Unparse(const UseStmt &x) {  // R1409
     Word("USE"), Walk(", ", x.nature), Put(" :: "), Walk(x.moduleName);
     std::visit(
-        visitors{[&](const std::list<Rename> &y) { Walk(", ", y, ", "); },
+        common::visitors{
+            [&](const std::list<Rename> &y) { Walk(", ", y, ", "); },
             [&](const std::list<Only> &y) { Walk(", ONLY: ", y, ", "); }},
         x.u);
   }
   void Unparse(const Rename &x) {  // R1411
-    std::visit(visitors{[&](const Rename::Names &y) { Walk(y.t, " => "); },
-                   [&](const Rename::Operators &y) {
-                     Word("OPERATOR("), Walk(y.t, ") => OPERATOR("), Put(")");
-                   }},
+    std::visit(
+        common::visitors{[&](const Rename::Names &y) { Walk(y.t, " => "); },
+            [&](const Rename::Operators &y) {
+              Word("OPERATOR("), Walk(y.t, ") => OPERATOR("), Put(")");
+            }},
         x.u);
   }
   void Before(const SubmoduleStmt &x) {  // R1417
@@ -1471,9 +1486,9 @@ public:
   }
 
   void Unparse(const InterfaceStmt &x) {  // R1503
-    std::visit(visitors{[&](const std::optional<GenericSpec> &y) {
-                          Word("INTERFACE"), Walk(" ", y);
-                        },
+    std::visit(common::visitors{[&](const std::optional<GenericSpec> &y) {
+                                  Word("INTERFACE"), Walk(" ", y);
+                                },
                    [&](const Abstract &) { Word("ABSTRACT INTERFACE"); }},
         x.u);
     Indent();
@@ -1491,7 +1506,7 @@ public:
   }
   void Before(const GenericSpec &x) {  // R1508, R1509
     std::visit(
-        visitors{[&](const DefinedOperator &x) { Word("OPERATOR("); },
+        common::visitors{[&](const DefinedOperator &x) { Word("OPERATOR("); },
             [&](const GenericSpec::Assignment &) { Word("ASSIGNMENT(=)"); },
             [&](const GenericSpec::ReadFormatted &) {
               Word("READ(FORMATTED)");
@@ -1509,7 +1524,7 @@ public:
         x.u);
   }
   void Post(const GenericSpec &x) {
-    std::visit(visitors{[&](const DefinedOperator &x) { Put(')'); },
+    std::visit(common::visitors{[&](const DefinedOperator &x) { Put(')'); },
                    [](const auto &) {}},
         x.u);
   }
@@ -1629,10 +1644,11 @@ public:
   // Directives, extensions, and deprecated constructs
   void Unparse(const CompilerDirective &x) {
     std::visit(
-        visitors{[&](const std::list<CompilerDirective::IgnoreTKR> &tkr) {
-                   Word("!DIR$ IGNORE_TKR");
-                   Walk(" ", tkr, ", ");
-                 },
+        common::visitors{
+            [&](const std::list<CompilerDirective::IgnoreTKR> &tkr) {
+              Word("!DIR$ IGNORE_TKR");
+              Walk(" ", tkr, ", ");
+            },
             [&](const CompilerDirective::IVDEP &) { Word("!DIR$ IVDEP\n"); }},
         x.u);
     Put('\n');
@@ -1713,7 +1729,7 @@ public:
     Put(")");
   }
   void Unparse(const OmpDependSinkVecLength &x) {
-    Walk(std::get<Indirection<DefinedOperator>>(x.t));
+    Walk(std::get<common::Indirection<DefinedOperator>>(x.t));
     Walk(std::get<ScalarIntConstantExpr>(x.t));
   }
   void Unparse(const OmpDependSinkVec &x) {
@@ -1726,9 +1742,9 @@ public:
     Walk(std::get<std::list<Designator>>(x.t), ",");
   }
   void Unparse(const OmpDependClause &x) {
-    std::visit(visitors{[&](const OmpDependClause::Source &y) {
-                          Word("DEPEND(SOURCE)");
-                        },
+    std::visit(common::visitors{[&](const OmpDependClause::Source &y) {
+                                  Word("DEPEND(SOURCE)");
+                                },
                    [&](const OmpDependClause::Sink &y) {
                      Word("DEPEND(SINK:");
                      Walk(y.v);
@@ -1871,10 +1887,11 @@ public:
   }
   void Unparse(const OmpLoopDirective &x) {
     std::visit(
-        visitors{[&](const OmpLoopDirective::DistributeParallelDoSimd &y) {
-                   Word("DISTRIBUTE PARALLEL DO SIMD ");
-                   Walk(y.v, " ");
-                 },
+        common::visitors{
+            [&](const OmpLoopDirective::DistributeParallelDoSimd &y) {
+              Word("DISTRIBUTE PARALLEL DO SIMD ");
+              Walk(y.v, " ");
+            },
             [&](const OmpLoopDirective::DistributeParallelDo &y) {
               Word("DISTRIBUTE PARALLEL DO ");
               Walk(y.v, " ");
@@ -1965,10 +1982,10 @@ public:
     Indent();
   }
   void Unparse(const OmpStandaloneDirective &x) {
-    std::visit(visitors{[&](const OmpStandaloneDirective::Barrier &y) {
-                          Word("BARRIER ");
-                          Walk(y.v, " ");
-                        },
+    std::visit(common::visitors{[&](const OmpStandaloneDirective::Barrier &y) {
+                                  Word("BARRIER ");
+                                  Walk(y.v, " ");
+                                },
                    [&](const OmpStandaloneDirective::CancellationPoint &y) {
                      Word("CANCELLATION POINT ");
                      Walk(y.v, " ");
@@ -2007,7 +2024,7 @@ public:
   }
   void Unparse(const OmpEndDirective &x) {
     Outdent();
-    std::visit(visitors{[&](const OmpLoopDirective &y) {
+    std::visit(common::visitors{[&](const OmpLoopDirective &y) {
       Word("!$OMP END ");
       Walk(y);
     }},
index 1ca879c..fe6b274 100644 (file)
@@ -109,12 +109,12 @@ struct StartNewSubprogram {
 };
 
 struct CapturedLabelDoStmt {
-  using resultType = Statement<Indirection<LabelDoStmt>>;
+  using resultType = Statement<common::Indirection<LabelDoStmt>>;
   static std::optional<resultType> Parse(ParseState &);
 };
 
 struct EndDoStmtForCapturedLabelDoStmt {
-  using resultType = Statement<Indirection<EndDoStmt>>;
+  using resultType = Statement<common::Indirection<EndDoStmt>>;
   static std::optional<resultType> Parse(ParseState &);
 };
 
index 9a6f6a1..1d7a1af 100644 (file)
@@ -22,6 +22,7 @@ add_library(FlangSemantics
   type.cc
 )
 
-target_link_libraries( FlangSemantics
-  clangBasic                    
+target_link_libraries(FlangSemantics
+  FortranCommon
+  clangBasic
 )
index 0d65d4d..4d7f3ca 100644 (file)
 // limitations under the License.
 
 #include "attr.h"
-#include "../parser/idioms.h"
+#include "../common/idioms.h"
 #include <stddef.h>
 
 namespace Fortran::semantics {
 
 void Attrs::CheckValid(const Attrs &allowed) const {
   if (!allowed.HasAll(*this)) {
-    parser::die("invalid attribute");
+    common::die("invalid attribute");
   }
 }
 
index 50dc532..b948ee6 100644 (file)
@@ -16,7 +16,7 @@
 #define FORTRAN_SEMANTICS_ATTR_H_
 
 #include "../common/enum-set.h"
-#include "../parser/idioms.h"
+#include "../common/idioms.h"
 #include <cinttypes>
 #include <iostream>
 #include <string>
index 7bf6159..00c95e2 100644 (file)
@@ -15,9 +15,9 @@
 #define FORTRAN_SEMANTICS_DUMP_PARSE_TREE_H_
 
 #include "symbol.h"
+#include "../common/idioms.h"
+#include "../common/indirection.h"
 #include "../parser/format-specification.h"
-#include "../parser/idioms.h"
-#include "../parser/indirection.h"
 #include "../parser/parse-tree-visitor.h"
 #include "../parser/parse-tree.h"
 #include <ostream>
@@ -716,9 +716,9 @@ public:
 
   template<typename T> void Post(const parser::Statement<T> &) {}
 
-  template<typename T> bool Pre(const parser::Indirection<T> &) { return true; }
+  template<typename T> bool Pre(const common::Indirection<T> &) { return true; }
 
-  template<typename T> void Post(const parser::Indirection<T> &) {}
+  template<typename T> void Post(const common::Indirection<T> &) {}
 
   template<typename T> bool Pre(const parser::Integer<T> &) { return true; }
 
index e2c4eca..06cbdeb 100644 (file)
@@ -18,7 +18,7 @@
 #include "scope.h"
 #include "symbol.h"
 #include "type.h"
-#include "../parser/indirection.h"
+#include "../common/indirection.h"
 #include "../parser/parse-tree-visitor.h"
 #include "../parser/parse-tree.h"
 #include <list>
@@ -115,7 +115,7 @@ protected:
     case parser::AccessSpec::Kind::Private: return Attr::PRIVATE;
     }
     // unnecessary but g++ warns "control reaches end of non-void function"
-    parser::die("unreachable");
+    common::die("unreachable");
   }
 };
 
@@ -735,7 +735,7 @@ void DeclTypeSpecVisitor::Post(const parser::TypeParamSpec &x) {
 }
 bool DeclTypeSpecVisitor::Pre(const parser::TypeParamValue &x) {
   typeParamValue_ = std::make_unique<ParamValue>(std::visit(
-      parser::visitors{
+      common::visitors{
           // TODO: create IntExpr from ScalarIntExpr
           [&](const parser::ScalarIntExpr &x) { return Bound{IntExpr{}}; },
           [&](const parser::Star &x) { return Bound::ASSUMED; },
@@ -881,7 +881,7 @@ void ImplicitRulesVisitor::Post(const parser::ParameterStmt &x) {
 
 bool ImplicitRulesVisitor::Pre(const parser::ImplicitStmt &x) {
   bool res = std::visit(
-      parser::visitors{
+      common::visitors{
           [&](const std::list<ImplicitNoneNameSpec> &x) {
             return HandleImplicitNone(x);
           },
@@ -1107,22 +1107,22 @@ void ScopeHandler::ApplyImplicitRules() {
 
 bool ModuleVisitor::Pre(const parser::Only &x) {
   std::visit(
-      parser::visitors{
-          [&](const parser::Indirection<parser::GenericSpec> &generic) {
+      common::visitors{
+          [&](const common::Indirection<parser::GenericSpec> &generic) {
             std::visit(
-                parser::visitors{
+                common::visitors{
                     [&](const parser::Name &name) { AddUse(name); },
-                    [](const auto &) { parser::die("TODO: GenericSpec"); },
+                    [](const auto &) { common::die("TODO: GenericSpec"); },
                 },
                 generic->u);
           },
           [&](const parser::Name &name) { AddUse(name); },
           [&](const parser::Rename &rename) {
             std::visit(
-                parser::visitors{
+                common::visitors{
                     [&](const parser::Rename::Names &names) { AddUse(names); },
                     [&](const parser::Rename::Operators &ops) {
-                      parser::die("TODO: Rename::Operators");
+                      common::die("TODO: Rename::Operators");
                     },
                 },
                 rename.u);
@@ -1161,7 +1161,7 @@ void ModuleVisitor::Post(const parser::UseStmt &x) {
     std::set<SourceName> useNames;
     for (const auto &rename : *list) {
       std::visit(
-          parser::visitors{
+          common::visitors{
               [&](const parser::Rename::Names &names) {
                 useNames.insert(std::get<1>(names.t).source);
               },
@@ -2003,15 +2003,15 @@ bool ModuleVisitor::Pre(const parser::AccessStmt &x) {
   } else {
     for (const auto &accessId : accessIds) {
       std::visit(
-          parser::visitors{
+          common::visitors{
               [=](const parser::Name &y) { SetAccess(y, accessAttr); },
-              [=](const parser::Indirection<parser::GenericSpec> &y) {
+              [=](const common::Indirection<parser::GenericSpec> &y) {
                 std::visit(
-                    parser::visitors{
+                    common::visitors{
                         [=](const parser::Name &z) {
                           SetAccess(z, accessAttr);
                         },
-                        [](const auto &) { parser::die("TODO: GenericSpec"); },
+                        [](const auto &) { common::die("TODO: GenericSpec"); },
                     },
                     y->u);
               },
@@ -2088,7 +2088,7 @@ const parser::Name *ResolveNamesVisitor::GetVariableName(
 const parser::Name *ResolveNamesVisitor::GetVariableName(
     const parser::Designator &x) {
   return std::visit(
-      parser::visitors{
+      common::visitors{
           [&](const parser::ObjectName &x) { return &x; },
           [&](const parser::DataRef &x) { return GetVariableName(x); },
           [&](const auto &) {
@@ -2100,7 +2100,7 @@ const parser::Name *ResolveNamesVisitor::GetVariableName(
 const parser::Name *ResolveNamesVisitor::GetVariableName(
     const parser::Expr &x) {
   if (const auto *designator =
-          std::get_if<parser::Indirection<parser::Designator>>(&x.u)) {
+          std::get_if<common::Indirection<parser::Designator>>(&x.u)) {
     return GetVariableName(**designator);
   } else {
     return nullptr;
@@ -2109,7 +2109,7 @@ const parser::Name *ResolveNamesVisitor::GetVariableName(
 const parser::Name *ResolveNamesVisitor::GetVariableName(
     const parser::Variable &x) {
   if (const auto *designator =
-          std::get_if<parser::Indirection<parser::Designator>>(&x.u)) {
+          std::get_if<common::Indirection<parser::Designator>>(&x.u)) {
     return GetVariableName(**designator);
   } else {
     return nullptr;
@@ -2198,13 +2198,13 @@ static GenericSpec::Kind MapIntrinsicOperator(
 // Map a parser::GenericSpec to a semantics::GenericSpec
 static GenericSpec MapGenericSpec(const parser::GenericSpec &genericSpec) {
   return std::visit(
-      parser::visitors{
+      common::visitors{
           [](const parser::Name &x) {
             return GenericSpec::GenericName(x.source);
           },
           [](const parser::DefinedOperator &x) {
             return std::visit(
-                parser::visitors{
+                common::visitors{
                     [](const parser::DefinedOpName &name) {
                       return GenericSpec::DefinedOp(name.v.source);
                     },
index c2fb6ff..d3cc1be 100644 (file)
@@ -15,7 +15,7 @@
 #include "rewrite-parse-tree.h"
 #include "scope.h"
 #include "symbol.h"
-#include "../parser/indirection.h"
+#include "../common/indirection.h"
 #include "../parser/parse-tree-visitor.h"
 #include "../parser/parse-tree.h"
 #include <list>
@@ -44,7 +44,7 @@ public:
   }
 
   using stmtFuncType =
-      parser::Statement<parser::Indirection<parser::StmtFunctionStmt>>;
+      parser::Statement<common::Indirection<parser::StmtFunctionStmt>>;
 
   // Find mis-parsed statement functions and move to stmtFuncsToConvert list.
   void Post(parser::SpecificationPart &x) {
@@ -89,7 +89,7 @@ private:
   // entity declaration, convert it.
   template<typename T> void ConvertFunctionRef(T &x) {
     auto *funcRef =
-        std::get_if<parser::Indirection<parser::FunctionReference>>(&x.u);
+        std::get_if<common::Indirection<parser::FunctionReference>>(&x.u);
     if (!funcRef) {
       return;
     }
@@ -98,7 +98,7 @@ private:
     if (!name || !name->symbol || !name->symbol->has<EntityDetails>()) {
       return;
     }
-    x.u = parser::Indirection{(*funcRef)->ConvertToArrayElementRef()};
+    x.u = common::Indirection{(*funcRef)->ConvertToArrayElementRef()};
   }
 };
 
index bb62933..40311a1 100644 (file)
@@ -17,7 +17,7 @@
 
 #include "attr.h"
 #include "symbol.h"
-#include "../parser/idioms.h"
+#include "../common/idioms.h"
 #include "../parser/parse-tree.h"
 #include <list>
 #include <map>
index 83dfaa0..c79d2b8 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "symbol.h"
 #include "scope.h"
-#include "../parser/idioms.h"
+#include "../common/idioms.h"
 #include <memory>
 
 namespace Fortran::semantics {
@@ -83,7 +83,7 @@ const Symbol *GenericDetails::CheckSpecific() const {
 // This is primarily for debugging.
 static std::string DetailsToString(const Details &details) {
   return std::visit(
-      parser::visitors{
+      common::visitors{
           [](const UnknownDetails &) { return "Unknown"; },
           [](const MainProgramDetails &) { return "MainProgram"; },
           [](const ModuleDetails &) { return "Module"; },
@@ -114,7 +114,7 @@ bool Symbol::CanReplaceDetails(const Details &details) const {
     return true;  // can always replace UnknownDetails
   } else {
     return std::visit(
-        parser::visitors{
+        common::visitors{
             [](const UseErrorDetails &) { return true; },
             [=](const ObjectEntityDetails &) { return has<EntityDetails>(); },
             [=](const ProcEntityDetails &) { return has<EntityDetails>(); },
@@ -140,7 +140,7 @@ const Symbol &Symbol::GetUltimate() const {
 
 bool Symbol::isSubprogram() const {
   return std::visit(
-      parser::visitors{
+      common::visitors{
           [](const SubprogramDetails &) { return true; },
           [](const SubprogramNameDetails &) { return true; },
           [](const GenericDetails &) { return true; },
@@ -152,7 +152,7 @@ bool Symbol::isSubprogram() const {
 
 bool Symbol::HasExplicitInterface() const {
   return std::visit(
-      parser::visitors{
+      common::visitors{
           [](const SubprogramDetails &) { return true; },
           [](const SubprogramNameDetails &) { return true; },
           [](const ProcEntityDetails &x) { return x.HasExplicitInterface(); },
@@ -217,7 +217,7 @@ static std::ostream &DumpType(std::ostream &os, const Symbol &symbol) {
 std::ostream &operator<<(std::ostream &os, const Details &details) {
   os << DetailsToString(details);
   std::visit(
-      parser::visitors{
+      common::visitors{
           [&](const UnknownDetails &x) {},
           [&](const MainProgramDetails &x) {},
           [&](const ModuleDetails &x) {},
index c3f6065..4af6135 100644 (file)
@@ -247,8 +247,8 @@ public:
     if (const auto p = detailsIf<D>()) {
       return *p;
     } else {
-      Fortran::parser::die("unexpected %s details at %s(%d)",
-          GetDetailsName().c_str(), __FILE__, __LINE__);
+      common::die("unexpected %s details at %s(%d)", GetDetailsName().c_str(),
+          __FILE__, __LINE__);
     }
   }
 
index b2039c0..c71eda4 100644 (file)
@@ -16,8 +16,8 @@
 #define FORTRAN_SEMANTICS_TYPE_H_
 
 #include "attr.h"
+#include "../common/idioms.h"
 #include "../parser/char-block.h"
-#include "../parser/idioms.h"
 #include <list>
 #include <map>
 #include <memory>
@@ -503,7 +503,7 @@ public:
       const SourceName &binding)
     : TypeBoundProc(interface, attrs, binding, binding) {
     if (!attrs_.test(Attr::DEFERRED)) {
-      parser::die(
+      common::die(
           "DEFERRED attribute is required if interface name is specified");
     }
   }
@@ -511,7 +511,7 @@ public:
       const std::optional<SourceName> &procedure)
     : TypeBoundProc({}, attrs, binding, procedure ? *procedure : binding) {
     if (attrs_.test(Attr::DEFERRED)) {
-      parser::die("DEFERRED attribute is only allowed with interface name");
+      common::die("DEFERRED attribute is only allowed with interface name");
     }
   }
 
index d5f0429..8e341a2 100644 (file)
 
 namespace Fortran::runtime {
 
-// Fortran requires that default INTEGER values occupy a single numeric
-// storage unit, just like default REAL.  Since there's no reasonable way
-// that default REAL can be anything but 32-bit IEEE-754 today, the default
-// INTEGER type is also forced; and default INTEGER is required to be the
-// type of the kind type parameters of the intrinsic types.
-using DefaultKindInteger = std::int32_t;
-
-class DerivedType;
 class DerivedTypeSpecialization;
 class DescriptorAddendum;
 
-// This next section implements a C++ view of the sole interoperable
-// descriptor (ISO_cdesc_t) and its type and per-dimension information.
+// A C++ view of the sole interoperable standard descriptor (ISO_cdesc_t)
+// and its type and per-dimension information.
 
 class TypeCode {
 public:
-  enum class Form { Integer, Real, Complex, Logical, Character, DerivedType };
+  enum class Form { Integer, Real, Complex, Logical, Character, Derived };
 
   TypeCode() {}
   explicit TypeCode(ISO::CFI_type_t t) : raw_{t} {}
@@ -67,10 +59,10 @@ public:
   }
   constexpr bool IsLogical() const { return raw_ == CFI_type_Bool; }
   constexpr bool IsCharacter() const { return raw_ == CFI_type_cptr; }
-  constexpr bool IsDerivedType() const { return raw_ == CFI_type_struct; }
+  constexpr bool IsDerived() const { return raw_ == CFI_type_struct; }
 
   constexpr bool IsIntrinsic() const {
-    return raw_ >= CFI_type_signed_char && raw_ <= CFI_type_cptr;
+    return IsValid() && !IsDerived();
   }
 
   constexpr Form GetForm() const {
@@ -89,7 +81,7 @@ public:
     if (IsCharacter()) {
       return Form::Character;
     }
-    return Form::DerivedType;
+    return Form::Derived;
   }
 
 private: