public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] ast: Add location info to MetaValueStr
@ 2022-06-08 12:39 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:39 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:34c73a75cf0043d3b9bb222c1c506aae18f27195
commit 34c73a75cf0043d3b9bb222c1c506aae18f27195
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Thu Apr 28 10:02:16 2022 +0200
ast: Add location info to MetaValueStr
Diff:
---
gcc/rust/ast/rust-ast-full-test.cc | 22 ++++++++++++++--------
gcc/rust/ast/rust-macro.h | 9 +++++++--
2 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc
index 71cbb372d92..5c8e04fcbbc 100644
--- a/gcc/rust/ast/rust-ast-full-test.cc
+++ b/gcc/rust/ast/rust-ast-full-test.cc
@@ -4118,12 +4118,14 @@ AttributeParser::parse_meta_item_inner ()
return parse_path_meta_item ();
}
- Identifier ident = peek_token ()->as_string ();
+ auto &identifier = peek_token ();
if (is_end_meta_item_tok (peek_token (1)->get_id ()))
{
// meta word syntax
skip_token ();
- return std::unique_ptr<MetaWord> (new MetaWord (std::move (ident)));
+ // FIXME: We probably need a Location here as well
+ return std::unique_ptr<MetaWord> (
+ new MetaWord (identifier->as_string ()));
}
if (peek_token (1)->get_id () == EQUAL)
@@ -4133,7 +4135,9 @@ AttributeParser::parse_meta_item_inner ()
&& is_end_meta_item_tok (peek_token (3)->get_id ()))
{
// meta name value str syntax
- std::string value = peek_token (2)->as_string ();
+ auto &value_tok = peek_token (2);
+ auto value = value_tok->as_string ();
+ auto locus = value_tok->get_locus ();
skip_token (2);
@@ -4141,7 +4145,9 @@ AttributeParser::parse_meta_item_inner ()
std::string raw_value = unquote_string (std::move (value));
return std::unique_ptr<MetaNameValueStr> (
- new MetaNameValueStr (std::move (ident), std::move (raw_value)));
+ new MetaNameValueStr (identifier->as_string (),
+ identifier->get_locus (),
+ std::move (raw_value), locus));
}
else
{
@@ -4183,7 +4189,7 @@ AttributeParser::parse_meta_item_inner ()
if (!meta_name_value_str_items.empty ())
{
return std::unique_ptr<MetaListNameValueStr> (
- new MetaListNameValueStr (std::move (ident),
+ new MetaListNameValueStr (identifier->as_string (),
std::move (meta_name_value_str_items)));
}
@@ -4222,7 +4228,7 @@ AttributeParser::parse_meta_item_inner ()
if (!path_items.empty ())
{
return std::unique_ptr<MetaListPaths> (
- new MetaListPaths (std::move (ident), std::move (path_items)));
+ new MetaListPaths (identifier->as_string (), std::move (path_items)));
}
rust_error_at (Linemap::unknown_location (),
@@ -4694,11 +4700,11 @@ Attribute
MetaNameValueStr::to_attribute () const
{
LiteralExpr lit_expr (str, Literal::LitType::STRING,
- PrimitiveCoreType::CORETYPE_UNKNOWN, {}, Location ());
+ PrimitiveCoreType::CORETYPE_UNKNOWN, {}, str_locus);
// FIXME: What location do we put here? Is the literal above supposed to have
// an empty location as well?
// Should MetaNameValueStr keep a location?
- return Attribute (SimplePath::from_str (ident, Location ()),
+ return Attribute (SimplePath::from_str (ident, ident_locus),
std::unique_ptr<AttrInputLiteral> (
new AttrInputLiteral (std::move (lit_expr))));
}
diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h
index 5ab82c4df7d..4b0a41217a0 100644
--- a/gcc/rust/ast/rust-macro.h
+++ b/gcc/rust/ast/rust-macro.h
@@ -783,12 +783,17 @@ protected:
class MetaNameValueStr : public MetaItem
{
Identifier ident;
+ Location ident_locus;
+
// NOTE: str stored without quotes
std::string str;
+ Location str_locus;
public:
- MetaNameValueStr (Identifier ident, std::string str)
- : ident (std::move (ident)), str (std::move (str))
+ MetaNameValueStr (Identifier ident, Location ident_locus, std::string str,
+ Location str_locus)
+ : ident (std::move (ident)), ident_locus (ident_locus),
+ str (std::move (str)), str_locus (str_locus)
{}
std::string as_string () const override
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:39 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:39 [gcc/devel/rust/master] ast: Add location info to MetaValueStr 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).