]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Added options for ParseMode
authorbadumbatish <tanghocle456@gmail.com>
Sat, 20 Jul 2024 07:44:26 +0000 (00:44 -0700)
committerArthur Cohen <arthur.cohen@embecosm.com>
Mon, 17 Mar 2025 15:35:53 +0000 (16:35 +0100)
gcc/rust/ChangeLog:

* ast/rust-fmt.cc (Pieces::collect):
Added options for ParseMode
* ast/rust-fmt.h (collect_pieces): Likewise.
(struct Pieces): Likewise.
* expand/rust-macro-builtins-format-args.cc (MacroBuiltin::format_args_handler):
Likewise.

libgrust/ChangeLog:

* libformat_parser/generic_format_parser/src/lib.rs: Likewise.
* libformat_parser/src/bin.rs: Likewise.
* libformat_parser/src/lib.rs: Likewise.

gcc/rust/ast/rust-fmt.cc
gcc/rust/ast/rust-fmt.h
gcc/rust/expand/rust-macro-builtins-format-args.cc
libgrust/libformat_parser/generic_format_parser/src/lib.rs
libgrust/libformat_parser/src/bin.rs
libgrust/libformat_parser/src/lib.rs

index cc48c2e35769cae036627a364bc9e8a62f34e80b..a29c8203ae8f10e0ad06bdcc96e3cbe2452c07ba 100644 (file)
@@ -29,9 +29,11 @@ ffi::RustHamster::to_string () const
 }
 
 Pieces
-Pieces::collect (const std::string &to_parse, bool append_newline)
+Pieces::collect (const std::string &to_parse, bool append_newline,
+                ffi::ParseMode parse_mode)
 {
-  auto handle = ffi::collect_pieces (to_parse.c_str (), append_newline);
+  auto handle
+    = ffi::collect_pieces (to_parse.c_str (), append_newline, parse_mode);
 
   // this performs multiple copies, can we avoid them maybe?
   // TODO: Instead of just creating a vec of, basically, `ffi::Piece`s, we
index 31100ea8f8478ce83f3dc158557e3a4d5ab383bb..1db391bafe7a7875b898fac8a8af6417e47b942f 100644 (file)
@@ -258,10 +258,16 @@ struct FormatArgsHandle
   RustString rust_string;
 };
 
+typedef enum
+{
+  Format,
+  InlineAsm,
+} ParseMode;
+
 extern "C" {
 
 FormatArgsHandle
-collect_pieces (const char *input, bool append_newline);
+collect_pieces (const char *input, bool append_newline, ParseMode parse_mode);
 
 FormatArgsHandle
 clone_pieces (const FormatArgsHandle &);
@@ -274,7 +280,8 @@ void destroy_pieces (FormatArgsHandle);
 
 struct Pieces
 {
-  static Pieces collect (const std::string &to_parse, bool append_newline);
+  static Pieces collect (const std::string &to_parse, bool append_newline,
+                        ffi::ParseMode parse_mode);
   ~Pieces ();
 
   Pieces (const Pieces &other);
index 031007b418bf788b72c99e28bd99822cb2a686bd..8eb32d5f1b31512a8191506c9f2238806d93f30b 100644 (file)
@@ -16,6 +16,7 @@
 // along with GCC; see the file COPYING3.  If not see
 // <http://www.gnu.org/licenses/>.
 #include "rust-ast-fragment.h"
+#include "rust-fmt.h"
 #include "rust-macro-builtins-helpers.h"
 #include "rust-expand-format-args.h"
 
@@ -162,7 +163,8 @@ MacroBuiltin::format_args_handler (location_t invoc_locus,
   if (append_newline)
     fmt_str += '\n';
 
-  auto pieces = Fmt::Pieces::collect (fmt_str, append_newline);
+  auto pieces = Fmt::Pieces::collect (fmt_str, append_newline,
+                                     Fmt::ffi::ParseMode::Format);
 
   // TODO:
   // do the transformation into an AST::FormatArgs node
@@ -191,4 +193,4 @@ MacroBuiltin::format_args_handler (location_t invoc_locus,
   //   invoc.get_delim_tok_tree ().to_token_stream ());
 }
 
-} // namespace Rust
\ No newline at end of file
+} // namespace Rust
index 25f6b0ead170d81ae8cf3f5678a5dd2279597ee4..ad4d3d9a546bd0dbd0bd0d6ebec88b030d584491 100644 (file)
@@ -78,6 +78,7 @@ enum InputStringKind {
 }
 
 /// The type of format string that we are parsing.
+#[repr(C)]
 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
 pub enum ParseMode {
     /// A normal format string as per `format_args!`.
index 5f46497c946ad93fcd3f31e85ba4b370da64e593..a7947afb11c0ea88b8eb04b72e8ec78d15928953 100644 (file)
@@ -5,6 +5,7 @@ fn main() {
         std::env::args().nth(1).unwrap().as_str(),
         None,
         None,
-        false
+        false,
+        generic_format_parser::ParseMode::Format
     ));
 }
index f4670bf9b1f76fd766957ae7b7f934674351022b..42ad62892bdf0332a45d3f079eb8d49c2e6a113e 100644 (file)
@@ -334,8 +334,9 @@ pub mod rust {
         style: Option<usize>,
         snippet: Option<String>,
         append_newline: bool,
+        parse_mode: ParseMode
     ) -> Vec<Piece<'_>> {
-        let parser = Parser::new(input, style, snippet, append_newline, ParseMode::Format);
+        let parser = Parser::new(input, style, snippet, append_newline, parse_mode);
 
         parser.into_iter().collect()
     }
@@ -360,10 +361,12 @@ pub struct RustString {
 #[repr(C)]
 pub struct FormatArgsHandle(PieceSlice, RustString);
 
+
 #[no_mangle]
 pub extern "C" fn collect_pieces(
     input: *const libc::c_char,
     append_newline: bool,
+    parse_mode : generic_format_parser::ParseMode 
 ) -> FormatArgsHandle {
     // FIXME: Add comment
     let str = unsafe { CStr::from_ptr(input) };
@@ -376,7 +379,7 @@ pub extern "C" fn collect_pieces(
     let s = unsafe { std::mem::transmute::<&'_ str, &'static str>(s) };
 
     // FIXME: No unwrap
-    let pieces: Vec<ffi::Piece<'_>> = rust::collect_pieces(s, None, None, append_newline)
+    let pieces: Vec<ffi::Piece<'_>> = rust::collect_pieces(s, None, None, append_newline, parse_mode)
         .into_iter()
         .map(Into::into)
         .collect();