aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2024-01-29 22:06:39 +0100
committerCohenArthur <arthur.cohen@embecosm.com>2024-02-26 17:32:38 +0000
commitb49f87f6931fa1f42b9a49e7dccd38b0afe3442d (patch)
treeec75ce4e5354cd8a18884d3c3c7550c60153b335 /gcc
parente3fca6ffc75a131edef613c9eca1d96df1aad2d3 (diff)
downloadgcc-b49f87f6931fa1f42b9a49e7dccd38b0afe3442d.zip
gcc-b49f87f6931fa1f42b9a49e7dccd38b0afe3442d.tar.gz
gcc-b49f87f6931fa1f42b9a49e7dccd38b0afe3442d.tar.bz2
libformat_parser: Update header and remove old interface
gcc/rust/ChangeLog: * ast/rust-fmt.cc (Pieces::collect): Use new Pieces API. * ast/rust-fmt.h: Update interface with new FFI bindings. libgrust/ChangeLog: * libformat_parser/src/lib.rs: Add IntoFFI trait. * libformat_parser/libformat-parser.h: Removed.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-fmt.cc10
-rw-r--r--gcc/rust/ast/rust-fmt.h199
2 files changed, 157 insertions, 52 deletions
diff --git a/gcc/rust/ast/rust-fmt.cc b/gcc/rust/ast/rust-fmt.cc
index 559b1c8..a7c4341 100644
--- a/gcc/rust/ast/rust-fmt.cc
+++ b/gcc/rust/ast/rust-fmt.cc
@@ -17,6 +17,7 @@
// <http://www.gnu.org/licenses/>.
#include "rust-fmt.h"
+#include "rust-diagnostics.h"
namespace Rust {
namespace Fmt {
@@ -26,13 +27,12 @@ Pieces::collect (const std::string &to_parse)
{
auto piece_slice = collect_pieces (to_parse.c_str ());
- rust_debug ("[ARTHUR] %p, %lu", (void *) piece_slice.ptr, piece_slice.len);
+ rust_debug ("[ARTHUR] %p, %lu", (const void *) piece_slice.base_ptr,
+ piece_slice.len);
// this performs multiple copies, can we avoid them maybe?
- auto pieces
- = std::vector (piece_slice.ptr, piece_slice.ptr + piece_slice.len);
-
- rust_debug ("[ARTHUR] %p, %lu", (void *) pieces.data (), pieces.size ());
+ // auto pieces = std::vector<Piece> (piece_slice.base_ptr,
+ // piece_slice.base_ptr + piece_slice.len);
return Pieces{};
}
diff --git a/gcc/rust/ast/rust-fmt.h b/gcc/rust/ast/rust-fmt.h
index 27c1c36..7ec9a2a 100644
--- a/gcc/rust/ast/rust-fmt.h
+++ b/gcc/rust/ast/rust-fmt.h
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2023 Free Software Foundation, Inc.
+// Copyright (C) 2023-2024 Free Software Foundation, Inc.
// This file is part of GCC.
@@ -19,9 +19,10 @@
#ifndef RUST_FMT_H
#define RUST_FMT_H
-#include "rust-diagnostics.h"
#include "rust-system.h"
+// FIXME: How to encode Option?
+
namespace Rust {
namespace Fmt {
@@ -30,116 +31,220 @@ struct RustHamster
// hehe
};
-struct InnerSpan
+/// Enum of alignments which are supported.
+enum class Alignment
{
+ /// The value will be aligned to the left.
+ AlignLeft,
+ /// The value will be aligned to the right.
+ AlignRight,
+ /// The value will be aligned in the center.
+ AlignCenter,
+ /// The value will take on a default alignment.
+ AlignUnknown,
};
-struct Count
+/// Enum for the debug hex flags.
+enum class DebugHex
{
- enum class Kind
- {
- Is,
- IsName,
- IsParam,
- IsStar,
- Implied
- } kind;
-
- union
- {
- size_t is;
- std::pair<RustHamster, InnerSpan> is_name;
- size_t is_param;
- size_t is_star;
- } data;
+ /// The `x` flag in `{:x?}`.
+ Lower,
+ /// The `X` flag in `{:X?}`.
+ Upper,
};
-struct DebugHex
+/// Enum for the sign flags.
+enum class Sign
{
+ /// The `+` flag.
+ Plus,
+ /// The `-` flag.
+ Minus,
};
-struct Sign
+/// Enum describing where an argument for a format can be located.
+struct Position
{
-};
+ enum class Tag
+ {
+ /// The argument is implied to be located at an index
+ ArgumentImplicitlyIs,
+ /// The argument is located at a specific index given in the format,
+ ArgumentIs,
+ /// The argument has a name.
+ ArgumentNamed,
+ };
-struct Alignment
-{
+ struct ArgumentImplicitlyIs_Body
+ {
+ size_t _0;
+ };
+
+ struct ArgumentIs_Body
+ {
+ size_t _0;
+ };
+
+ struct ArgumentNamed_Body
+ {
+ RustHamster _0;
+ };
+
+ Tag tag;
+ union
+ {
+ ArgumentImplicitlyIs_Body argument_implicitly_is;
+ ArgumentIs_Body argument_is;
+ ArgumentNamed_Body argument_named;
+ };
};
-struct RustString
+/// Range inside of a `Span` used for diagnostics when we only have access to
+/// relative positions.
+struct InnerSpan
{
- // hehe
+ size_t start;
+ size_t end;
};
-struct Position
+/// A count is used for the precision and width parameters of an integer, and
+/// can reference either an argument or a literal integer.
+struct Count
{
+ enum class Tag
+ {
+ /// The count is specified explicitly.
+ CountIs,
+ /// The count is specified by the argument with the given name.
+ CountIsName,
+ /// The count is specified by the argument at the given index.
+ CountIsParam,
+ /// The count is specified by a star (like in `{:.*}`) that refers to the
+ /// argument at the given index.
+ CountIsStar,
+ /// The count is implied and cannot be explicitly specified.
+ CountImplied,
+ };
+
+ struct CountIs_Body
+ {
+ size_t _0;
+ };
+
+ struct CountIsName_Body
+ {
+ RustHamster _0;
+ InnerSpan _1;
+ };
+
+ struct CountIsParam_Body
+ {
+ size_t _0;
+ };
+
+ struct CountIsStar_Body
+ {
+ size_t _0;
+ };
+
+ Tag tag;
+ union
+ {
+ CountIs_Body count_is;
+ CountIsName_Body count_is_name;
+ CountIsParam_Body count_is_param;
+ CountIsStar_Body count_is_star;
+ };
};
+/// Specification for the formatting of an argument in the format string.
struct FormatSpec
{
/// Optionally specified character to fill alignment with.
- tl::optional<char /* FIXME: This is a Rust char, not a C++ char - use an uint32_t instead? */> fill;
+ const uint32_t *fill;
/// Span of the optionally specified fill character.
- tl::optional<InnerSpan> fill_span;
+ const InnerSpan *fill_span;
/// Optionally specified alignment.
Alignment align;
/// The `+` or `-` flag.
- tl::optional<Sign> sign;
+ const Sign *sign;
/// The `#` flag.
bool alternate;
/// The `0` flag.
bool zero_pad;
/// The `x` or `X` flag. (Only for `Debug`.)
- tl::optional<DebugHex> debug_hex;
+ const DebugHex *debug_hex;
/// The integer precision to use.
Count precision;
/// The span of the precision formatting flag (for diagnostics).
- tl::optional<InnerSpan> precision_span;
+ const InnerSpan *precision_span;
/// The string width requested for the resulting format.
Count width;
/// The span of the width formatting flag (for diagnostics).
- tl::optional<InnerSpan> width_span;
+ const InnerSpan *width_span;
/// The descriptor string representing the name of the format desired for
/// this argument, this can be empty or any number of characters, although
/// it is required to be one word.
RustHamster ty;
- // &'a str ty;
/// The span of the descriptor string (for diagnostics).
- tl::optional<InnerSpan> ty_span;
+ const InnerSpan *ty_span;
};
+/// Representation of an argument specification.
struct Argument
{
+ /// Where to find this argument
Position position;
- InnerSpan inner_span;
+ /// The span of the position indicator. Includes any whitespace in implicit
+ /// positions (`{ }`).
+ InnerSpan position_span;
+ /// How to format the argument
FormatSpec format;
};
+/// A piece is a portion of the format string which represents the next part
+/// to emit. These are emitted as a stream by the `Parser` class.
struct Piece
{
- enum class Kind
+ enum class Tag
{
+ /// A literal string which should directly be emitted
String,
- NextArgument
- } kind;
+ /// This describes that formatting should process the next argument (as
+ /// specified inside) for emission.
+ NextArgument,
+ };
+
+ struct String_Body
+ {
+ RustHamster _0;
+ };
+
+ struct NextArgument_Body
+ {
+ const Argument *_0;
+ };
+ Tag tag;
union
{
- RustString string;
- Argument *next_argument;
- } data;
+ String_Body string;
+ NextArgument_Body next_argument;
+ };
};
struct PieceSlice
{
- Piece *ptr;
+ const Piece *base_ptr;
size_t len;
};
extern "C" {
+
PieceSlice
-collect_pieces (const char *);
-}
+collect_pieces (const char *input);
+
+} // extern "C"
struct Pieces
{
@@ -149,4 +254,4 @@ struct Pieces
} // namespace Fmt
} // namespace Rust
-#endif // ! RUST_FMT_H
+#endif // !RUST_FMT_H