public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] macrorule: Add location information
@ 2022-06-08 12:07 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:07 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:c1e72db48a0fa36966f2517cbf45fa2b758af268
commit c1e72db48a0fa36966f2517cbf45fa2b758af268
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Wed Feb 16 12:01:28 2022 +0100
macrorule: Add location information
Diff:
---
gcc/rust/ast/rust-macro.h | 19 +++++++++++--------
gcc/rust/parse/rust-parse-impl.h | 8 +++++---
2 files changed, 16 insertions(+), 11 deletions(-)
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index ef50e4a3015..e0524c6c21c 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -20,6 +20,7 @@
#define RUST_AST_MACRO_H
#include "rust-ast.h"
+#include "rust-location.h"
namespace Rust {
namespace AST {
@@ -295,26 +296,28 @@ struct MacroRule
private:
MacroMatcher matcher;
MacroTranscriber transcriber;
-
- // TODO: should store location information?
+ Location locus;
public:
- MacroRule (MacroMatcher matcher, MacroTranscriber transcriber)
- : matcher (std::move (matcher)), transcriber (std::move (transcriber))
+ MacroRule (MacroMatcher matcher, MacroTranscriber transcriber, Location locus)
+ : matcher (std::move (matcher)), transcriber (std::move (transcriber)),
+ locus (locus)
{}
// Returns whether macro rule is in error state.
bool is_error () const { return matcher.is_error (); }
// Creates an error state macro rule.
- static MacroRule create_error ()
+ static MacroRule create_error (Location locus)
{
- // FIXME: Once #928 is merged, give location to MacroMatcher
- return MacroRule (MacroMatcher::create_error (Location ()),
+ return MacroRule (MacroMatcher::create_error (locus),
MacroTranscriber (DelimTokenTree::create_empty (),
- Location ()));
+ Location ()),
+ locus);
}
+ Location get_locus () const { return locus; }
+
std::string as_string () const;
};
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index ef0ad40a781..748381868ad 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -1678,23 +1678,25 @@ template <typename ManagedTokenSource>
AST::MacroRule
Parser<ManagedTokenSource>::parse_macro_rule ()
{
+ Location locus = lexer.peek_token ()->get_locus ();
+
// parse macro matcher
AST::MacroMatcher matcher = parse_macro_matcher ();
if (matcher.is_error ())
- return AST::MacroRule::create_error ();
+ return AST::MacroRule::create_error (locus);
if (!skip_token (MATCH_ARROW))
{
// skip after somewhere?
- return AST::MacroRule::create_error ();
+ return AST::MacroRule::create_error (locus);
}
// parse transcriber (this is just a delim token tree)
Location token_tree_loc = lexer.peek_token ()->get_locus ();
AST::MacroTranscriber transcriber (parse_delim_token_tree (), token_tree_loc);
- return AST::MacroRule (std::move (matcher), std::move (transcriber));
+ return AST::MacroRule (std::move (matcher), std::move (transcriber), locus);
}
// Parses a macro matcher (part of a macro rule definition).
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:07 [gcc/devel/rust/master] macrorule: Add location information Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).