From: badumbatish <tanghocle...@gmail.com> 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 | 6 ++++-- gcc/rust/ast/rust-fmt.h | 11 +++++++++-- gcc/rust/expand/rust-macro-builtins-format-args.cc | 6 ++++-- .../libformat_parser/generic_format_parser/src/lib.rs | 1 + libgrust/libformat_parser/src/bin.rs | 3 ++- libgrust/libformat_parser/src/lib.rs | 7 +++++-- 6 files changed, 25 insertions(+), 9 deletions(-) diff --git a/gcc/rust/ast/rust-fmt.cc b/gcc/rust/ast/rust-fmt.cc index cc48c2e3576..a29c8203ae8 100644 --- a/gcc/rust/ast/rust-fmt.cc +++ b/gcc/rust/ast/rust-fmt.cc @@ -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 diff --git a/gcc/rust/ast/rust-fmt.h b/gcc/rust/ast/rust-fmt.h index 31100ea8f84..1db391bafe7 100644 --- a/gcc/rust/ast/rust-fmt.h +++ b/gcc/rust/ast/rust-fmt.h @@ -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); diff --git a/gcc/rust/expand/rust-macro-builtins-format-args.cc b/gcc/rust/expand/rust-macro-builtins-format-args.cc index 031007b418b..8eb32d5f1b3 100644 --- a/gcc/rust/expand/rust-macro-builtins-format-args.cc +++ b/gcc/rust/expand/rust-macro-builtins-format-args.cc @@ -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 diff --git a/libgrust/libformat_parser/generic_format_parser/src/lib.rs b/libgrust/libformat_parser/generic_format_parser/src/lib.rs index 25f6b0ead17..ad4d3d9a546 100644 --- a/libgrust/libformat_parser/generic_format_parser/src/lib.rs +++ b/libgrust/libformat_parser/generic_format_parser/src/lib.rs @@ -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!`. diff --git a/libgrust/libformat_parser/src/bin.rs b/libgrust/libformat_parser/src/bin.rs index 5f46497c946..a7947afb11c 100644 --- a/libgrust/libformat_parser/src/bin.rs +++ b/libgrust/libformat_parser/src/bin.rs @@ -5,6 +5,7 @@ fn main() { std::env::args().nth(1).unwrap().as_str(), None, None, - false + false, + generic_format_parser::ParseMode::Format )); } diff --git a/libgrust/libformat_parser/src/lib.rs b/libgrust/libformat_parser/src/lib.rs index f4670bf9b1f..42ad62892bd 100644 --- a/libgrust/libformat_parser/src/lib.rs +++ b/libgrust/libformat_parser/src/lib.rs @@ -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(); -- 2.45.2