]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: format-args: Add base for expanding FormatArgs nodes
authorArthur Cohen <arthur.cohen@embecosm.com>
Thu, 29 Feb 2024 12:01:32 +0000 (13:01 +0100)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 1 Aug 2024 11:12:16 +0000 (13:12 +0200)
gcc/rust/ChangeLog:

* Make-lang.in: Add new object.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Remove calls to
FormatArgsLowering.
* expand/rust-expand-format-args.cc: New file.
* expand/rust-expand-format-args.h: New file.

gcc/rust/Make-lang.in
gcc/rust/expand/rust-expand-format-args.cc [new file with mode: 0644]
gcc/rust/expand/rust-expand-format-args.h [new file with mode: 0644]
gcc/rust/hir/rust-ast-lower-expr.cc

index f166b02340d7c9364b690c7ddbfb56e80e7867fa..cbb9da0fe43b0d0c384f6d79aa540bee624d80a7 100644 (file)
@@ -205,6 +205,7 @@ GRS_OBJS = \
     rust/rust-unicode.o \
     rust/rust-punycode.o \
        rust/rust-lang-item.o \
+       rust/rust-expand-format-args.o \
     $(END)
 # removed object files from here
 
diff --git a/gcc/rust/expand/rust-expand-format-args.cc b/gcc/rust/expand/rust-expand-format-args.cc
new file mode 100644 (file)
index 0000000..52249cb
--- /dev/null
@@ -0,0 +1,43 @@
+// Copyright (C) 2024 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-expand-format-args.h"
+#include "rust-builtin-ast-nodes.h"
+
+namespace Rust {
+
+tl::optional<AST::Fragment>
+expand_format_args (AST::FormatArgs &fmt)
+{
+  for (const auto &node : fmt.get_template ().get_pieces ())
+    {
+      switch (node.tag)
+       {
+       case Fmt::Piece::Tag::String:
+         // rust_debug ("[ARTHUR]: %s", node.string._0.c_str ());
+
+       case Fmt::Piece::Tag::NextArgument:
+         rust_debug ("[ARTHUR]: NextArgument");
+         break;
+       }
+    }
+
+  return tl::nullopt;
+}
+
+} // namespace Rust
diff --git a/gcc/rust/expand/rust-expand-format-args.h b/gcc/rust/expand/rust-expand-format-args.h
new file mode 100644 (file)
index 0000000..1481f36
--- /dev/null
@@ -0,0 +1,32 @@
+// Copyright (C) 2024 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_EXPAND_FORMAT_ARGS_H
+#define RUST_EXPAND_FORMAT_ARGS_H
+
+#include "optional.h"
+#include "rust-ast-fragment.h"
+
+namespace Rust {
+
+tl::optional<AST::Fragment>
+expand_format_args (AST::FormatArgs &fmt);
+
+} // namespace Rust
+
+#endif //! RUST_EXPAND_FORMAT_ARGS_H
index 6944db9b9ccf6e82d729d2609838dd0dc50e1d8e..c414643bb9154c0cc7efde7791c8213cff831e7e 100644 (file)
@@ -19,7 +19,6 @@
 #include "rust-ast-lower-expr.h"
 #include "rust-ast-lower-base.h"
 #include "rust-ast-lower-block.h"
-#include "rust-ast-lower-format-args.h"
 #include "rust-ast-lower-struct-field-expr.h"
 #include "rust-ast-lower-pattern.h"
 #include "rust-ast-lower-type.h"
@@ -824,9 +823,6 @@ ASTLoweringExpr::visit (AST::ClosureExprInnerTyped &expr)
 void
 ASTLoweringExpr::visit (AST::FormatArgs &fmt)
 {
-  // Lowering FormatArgs is complex, and this file is already very long
-  translated = FormatArgsLowering ().go (fmt);
-
   rust_sorry_at (fmt.get_locus (),
                 "FormatArgs lowering is not implemented yet");
 }