aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorArthur Cohen <arthur.cohen@embecosm.com>2022-04-28 10:02:16 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2022-04-28 10:02:16 +0200
commit34c73a75cf0043d3b9bb222c1c506aae18f27195 (patch)
tree5af2c7e0bf9502328c3e94c0d630501cf0249a18 /gcc
parentb4fa67403f3f5f5579e30e03102ca56c4ed6f049 (diff)
downloadgcc-34c73a75cf0043d3b9bb222c1c506aae18f27195.zip
gcc-34c73a75cf0043d3b9bb222c1c506aae18f27195.tar.gz
gcc-34c73a75cf0043d3b9bb222c1c506aae18f27195.tar.bz2
ast: Add location info to MetaValueStr
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-ast-full-test.cc22
-rw-r--r--gcc/rust/ast/rust-macro.h9
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 71cbb37..5c8e04f 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 5ab82c4..4b0a412 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