diff mbox series

[059/125] gccrs: nr2.0: Add new ImmutableNameResolutionCtx class.

Message ID 20240801145809.366388-61-arthur.cohen@embecosm.com
State New
Headers show
Series [001/125] Rust: Make 'tree'-level 'MAIN_NAME_P' work | expand

Commit Message

Arthur Cohen Aug. 1, 2024, 2:56 p.m. UTC
gcc/rust/ChangeLog:

	* Make-lang.in: Compile it.
	* resolve/rust-immutable-name-resolution-context.cc: New file.
	* resolve/rust-immutable-name-resolution-context.h: New file.
---
 gcc/rust/Make-lang.in                         |  1 +
 .../rust-immutable-name-resolution-context.cc | 56 +++++++++++++++++++
 .../rust-immutable-name-resolution-context.h  | 55 ++++++++++++++++++
 3 files changed, 112 insertions(+)
 create mode 100644 gcc/rust/resolve/rust-immutable-name-resolution-context.cc
 create mode 100644 gcc/rust/resolve/rust-immutable-name-resolution-context.h
diff mbox series

Patch

diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in
index 10af0814372..24229c02770 100644
--- a/gcc/rust/Make-lang.in
+++ b/gcc/rust/Make-lang.in
@@ -134,6 +134,7 @@  GRS_OBJS = \
     rust/rust-toplevel-name-resolver-2.0.o \
     rust/rust-early-name-resolver-2.0.o \
     rust/rust-late-name-resolver-2.0.o \
+	rust/rust-immutable-name-resolution-context.o \
     rust/rust-early-name-resolver.o \
     rust/rust-name-resolver.o \
     rust/rust-ast-resolve.o \
diff --git a/gcc/rust/resolve/rust-immutable-name-resolution-context.cc b/gcc/rust/resolve/rust-immutable-name-resolution-context.cc
new file mode 100644
index 00000000000..3894e27cd20
--- /dev/null
+++ b/gcc/rust/resolve/rust-immutable-name-resolution-context.cc
@@ -0,0 +1,56 @@ 
+// Copyright (C) 2020-2023 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#include "rust-immutable-name-resolution-context.h"
+
+namespace Rust {
+namespace Resolver2_0 {
+
+static ImmutableNameResolutionContext *instance = nullptr;
+
+const ImmutableNameResolutionContext &
+ImmutableNameResolutionContext::init (const NameResolutionContext &ctx)
+{
+  rust_assert (!instance);
+
+  instance = new ImmutableNameResolutionContext (ctx);
+
+  return *instance;
+}
+
+const ImmutableNameResolutionContext &
+ImmutableNameResolutionContext::get ()
+{
+  rust_assert (instance);
+
+  return *instance;
+}
+
+const NameResolutionContext &
+ImmutableNameResolutionContext::resolver () const
+{
+  return ctx;
+}
+
+ImmutableNameResolutionContext::ImmutableNameResolutionContext (
+  const NameResolutionContext &ctx)
+  : ctx (ctx)
+{}
+
+} // namespace Resolver2_0
+} // namespace Rust
diff --git a/gcc/rust/resolve/rust-immutable-name-resolution-context.h b/gcc/rust/resolve/rust-immutable-name-resolution-context.h
new file mode 100644
index 00000000000..9f9e7764cd2
--- /dev/null
+++ b/gcc/rust/resolve/rust-immutable-name-resolution-context.h
@@ -0,0 +1,55 @@ 
+// Copyright (C) 2020-2023 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3.  If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_IMMUTABLE_NRCTX_H
+#define RUST_IMMUTABLE_NRCTX_H
+
+#include "rust-name-resolution-context.h"
+
+namespace Rust {
+namespace Resolver2_0 {
+
+/**
+ * Once the name resolution pass is complete, the typechecker can access it
+ *
+ * FIXME: More documentation
+ */
+class ImmutableNameResolutionContext
+{
+public:
+  /** FIXME: Documentation */
+  static const ImmutableNameResolutionContext &
+  init (const NameResolutionContext &ctx);
+
+  /** FIXME: Documentation */
+  static const ImmutableNameResolutionContext &get ();
+
+  const NameResolutionContext &resolver () const;
+
+private:
+  ImmutableNameResolutionContext (const NameResolutionContext &ctx);
+  ImmutableNameResolutionContext (const ImmutableNameResolutionContext &other)
+    = default;
+
+  const NameResolutionContext &ctx;
+};
+
+} // namespace Resolver2_0
+} // namespace Rust
+
+#endif //! RUST_IMMUTABLE_NRCTX_H