[flang] Add user-state.h.
authorpeter klausler <pklausler@nvidia.com>
Tue, 30 Jan 2018 19:52:12 +0000 (11:52 -0800)
committerpeter klausler <pklausler@nvidia.com>
Tue, 30 Jan 2018 19:52:12 +0000 (11:52 -0800)
Original-commit: flang-compiler/f18@5daf35b05d7b72ef99dfb756ee0123c87ba167e4

flang/user-state.h [new file with mode: 0644]

diff --git a/flang/user-state.h b/flang/user-state.h
new file mode 100644 (file)
index 0000000..626f169
--- /dev/null
@@ -0,0 +1,38 @@
+#ifndef FORTRAN_USER_STATE_H_
+#define FORTRAN_USER_STATE_H_
+
+// Instances of ParseState (parse-state.h) incorporate instances of this
+// UserState class, which encapsulates any semantic information necessary for
+// parse tree construction so as to avoid any need for representing
+// state in static data.
+
+#include <cinttypes>
+#include <unordered_set>
+
+namespace Fortran {
+class UserState {
+ public:
+  using Label = std::uint64_t;
+  bool IsDoLabel(Label label) const {
+    return doLabels_.find(label) != doLabels_.end();
+  }
+  bool InNonlabelDoConstruct() const {
+    return nonlabelDoConstructNestingDepth_ > 0;
+  }
+  void NewDoLabel(Label label) { doLabels_.insert(label); }
+  void NewSubprogram() {
+    doLabels_.clear();
+    nonlabelDoConstructNestingDepth_ = 0;
+  }
+  void EnterNonlabelDoConstruct() { ++nonlabelDoConstructNestingDepth_; }
+  void LeaveDoConstruct() {
+    if (nonlabelDoConstructNestingDepth_ > 0) {
+      --nonlabelDoConstructNestingDepth_;
+    }
+  }
+ private:
+  std::unordered_set<Label> doLabels_;
+  int nonlabelDoConstructNestingDepth_{0};
+};
+};  // namespace Fortran
+#endif  // FORTRAN_USER_STATE_H_