Skip to content

Commit

Permalink
fmt: Try and appease the GCC 4.8 C++almost11 gods
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenArthur committed Nov 22, 2023
1 parent 43d188f commit 243e719
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
14 changes: 7 additions & 7 deletions gcc/rust/ast/rust-fmt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,39 +25,39 @@ Fmt::parse_fmt_string (Fmt::Input input)
return Fmt ();
}

Fmt::ParseResult<tl::optional<Fmt::Format>>
tl::expected<Fmt::Result<tl::optional<Fmt::Format>>, Fmt::Error>
Fmt::maybe_format (Fmt::Input input)
{
tl::optional<Fmt::Format> none = tl::nullopt;

return Fmt::Result (input, none);
}

Fmt::ParseResult<Fmt::Format>
tl::expected<Fmt::Result<Fmt::Format>, Fmt::Error>
Fmt::format (Input input)
{
return Fmt::Result (input, Format ());
}

Fmt::ParseResult<Fmt::Argument>
tl::expected<Fmt::Result<Fmt::Argument>, Fmt::Error>
Fmt::argument (Input input)
{
return Fmt::Result (input, Argument ());
}

Fmt::ParseResult<Fmt::FormatSpec>
tl::expected<Fmt::Result<Fmt::FormatSpec>, Fmt::Error>
Fmt::format_spec (Input input)
{
return Fmt::Result (input, FormatSpec ());
}

Fmt::ParseResult<Fmt::Fill>
tl::expected<Fmt::Result<Fmt::Fill>, Fmt::Error>
Fmt::fill (Input input)
{
return Fmt::Result (input, Fill ());
}

Fmt::ParseResult<Fmt::Align>
tl::expected<Fmt::Result<Fmt::Align>, Fmt::Error>
Fmt::align (Input input)
{
switch (input[0])
Expand All @@ -76,7 +76,7 @@ Fmt::align (Input input)
}
}

Fmt::ParseResult<Fmt::Sign>
tl::expected<Fmt::Result<Fmt::Sign>, Fmt::Error>
Fmt::sign (Input input)
{
switch (input[0])
Expand Down
31 changes: 22 additions & 9 deletions gcc/rust/ast/rust-fmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,19 @@ class Fmt
// expected node let's look at nom
// TODO: no string view :( use an owned string for now?

template <typename T> using ParseResult = tl::expected<Result<T>, Error>;
template <typename T> struct ParseResult
{
tl::expected<Result<T>, Error> inner;

ParseResult (tl::expected<Result<T>, Error> inner) : inner (inner) {}
ParseResult operator= (tl::expected<Result<T>, Error> inner)
{
return ParseResult (inner);
}

Input remaining_input () { return inner->remaining_input; }
T value () { return inner->value; }
};

struct Format
{
Expand Down Expand Up @@ -105,14 +117,15 @@ class Fmt
};

// let's do one function per rule in the BNF
static ParseResult<std::string> text (Input input);
static ParseResult<tl::optional<Format>> maybe_format (Input input);
static ParseResult<Format> format (Input input);
static ParseResult<Argument> argument (Input input);
static ParseResult<FormatSpec> format_spec (Input input);
static ParseResult<Fill> fill (Input input);
static ParseResult<Align> align (Input input);
static ParseResult<Sign> sign (Input input);
static tl::expected<Result<std::string>, Error> text (Input input);
static tl::expected<Result<tl::optional<Format>>, Error>
maybe_format (Input input);
static tl::expected<Result<Format>, Error> format (Input input);
static tl::expected<Result<Argument>, Error> argument (Input input);
static tl::expected<Result<FormatSpec>, Error> format_spec (Input input);
static tl::expected<Result<Fill>, Error> fill (Input input);
static tl::expected<Result<Align>, Error> align (Input input);
static tl::expected<Result<Sign>, Error> sign (Input input);
};

} // namespace Rust
Expand Down

0 comments on commit 243e719

Please sign in to comment.