]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: nr2.0: Add new ImmutableNameResolutionCtx class.
authorArthur Cohen <arthur.cohen@embecosm.com>
Thu, 24 Aug 2023 15:49:42 +0000 (17:49 +0200)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 1 Aug 2024 11:12:17 +0000 (13:12 +0200)
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
gcc/rust/resolve/rust-immutable-name-resolution-context.cc [new file with mode: 0644]
gcc/rust/resolve/rust-immutable-name-resolution-context.h [new file with mode: 0644]

index 10af0814372e133e36435ddde87d649fc07670cb..24229c02770dfdd2a5c4cc88e0a0b214f47905fd 100644 (file)
@@ -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 (file)
index 0000000..3894e27
--- /dev/null
@@ -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 (file)
index 0000000..9f9e776
--- /dev/null
@@ -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