aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-02-17 08:44:36 +0000
committerGitHub <noreply@github.com>2022-02-17 08:44:36 +0000
commitd81ba63f4829c12b89e87564c398e95879c89db1 (patch)
tree46c2aa8c0da5a1cfd72b50fb4579ff000c2d46cc
parenta5272f389b02623b8bc4aaeafcf84013dae7c9fb (diff)
parent45ca46018f034e50d37e6fdcd3d0de9c0ce74927 (diff)
downloadgcc-d81ba63f4829c12b89e87564c398e95879c89db1.zip
gcc-d81ba63f4829c12b89e87564c398e95879c89db1.tar.gz
gcc-d81ba63f4829c12b89e87564c398e95879c89db1.tar.bz2
Merge #933
933: macrotranscriber: Add location info r=CohenArthur a=CohenArthur Closes #929 Adds location info to the macro's transcriber. When generating a `MacroRule` error, this PR creates an empty location for the transcriber, since the error function is only called if no fat arrow is present or if there was an error parsing the macro's matcher. Please let me know if this is the expected behavior Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
-rw-r--r--gcc/rust/ast/rust-macro.h12
-rw-r--r--gcc/rust/parse/rust-parse-impl.h3
2 files changed, 9 insertions, 6 deletions
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index 2d59b18..ef50e4a 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -277,15 +277,16 @@ struct MacroTranscriber
{
private:
DelimTokenTree token_tree;
-
- // TODO: should store location information?
+ Location locus;
public:
- MacroTranscriber (DelimTokenTree token_tree)
- : token_tree (std::move (token_tree))
+ MacroTranscriber (DelimTokenTree token_tree, Location locus)
+ : token_tree (std::move (token_tree)), locus (locus)
{}
std::string as_string () const { return token_tree.as_string (); }
+
+ Location get_locus () const { return locus; }
};
// A macro rule? Matcher and transcriber pair?
@@ -310,7 +311,8 @@ public:
{
// FIXME: Once #928 is merged, give location to MacroMatcher
return MacroRule (MacroMatcher::create_error (Location ()),
- MacroTranscriber (DelimTokenTree::create_empty ()));
+ MacroTranscriber (DelimTokenTree::create_empty (),
+ Location ()));
}
std::string as_string () const;
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index b500c87..ef0ad40 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -1691,7 +1691,8 @@ Parser<ManagedTokenSource>::parse_macro_rule ()
}
// parse transcriber (this is just a delim token tree)
- AST::MacroTranscriber transcriber (parse_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));
}