Skip to content

Commit 34c73a7

Browse files
committed
ast: Add location info to MetaValueStr
1 parent b4fa674 commit 34c73a7

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

gcc/rust/ast/rust-ast-full-test.cc

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4118,12 +4118,14 @@ AttributeParser::parse_meta_item_inner ()
41184118
return parse_path_meta_item ();
41194119
}
41204120

4121-
Identifier ident = peek_token ()->as_string ();
4121+
auto &identifier = peek_token ();
41224122
if (is_end_meta_item_tok (peek_token (1)->get_id ()))
41234123
{
41244124
// meta word syntax
41254125
skip_token ();
4126-
return std::unique_ptr<MetaWord> (new MetaWord (std::move (ident)));
4126+
// FIXME: We probably need a Location here as well
4127+
return std::unique_ptr<MetaWord> (
4128+
new MetaWord (identifier->as_string ()));
41274129
}
41284130

41294131
if (peek_token (1)->get_id () == EQUAL)
@@ -4133,15 +4135,19 @@ AttributeParser::parse_meta_item_inner ()
41334135
&& is_end_meta_item_tok (peek_token (3)->get_id ()))
41344136
{
41354137
// meta name value str syntax
4136-
std::string value = peek_token (2)->as_string ();
4138+
auto &value_tok = peek_token (2);
4139+
auto value = value_tok->as_string ();
4140+
auto locus = value_tok->get_locus ();
41374141

41384142
skip_token (2);
41394143

41404144
// remove the quotes from the string value
41414145
std::string raw_value = unquote_string (std::move (value));
41424146

41434147
return std::unique_ptr<MetaNameValueStr> (
4144-
new MetaNameValueStr (std::move (ident), std::move (raw_value)));
4148+
new MetaNameValueStr (identifier->as_string (),
4149+
identifier->get_locus (),
4150+
std::move (raw_value), locus));
41454151
}
41464152
else
41474153
{
@@ -4183,7 +4189,7 @@ AttributeParser::parse_meta_item_inner ()
41834189
if (!meta_name_value_str_items.empty ())
41844190
{
41854191
return std::unique_ptr<MetaListNameValueStr> (
4186-
new MetaListNameValueStr (std::move (ident),
4192+
new MetaListNameValueStr (identifier->as_string (),
41874193
std::move (meta_name_value_str_items)));
41884194
}
41894195

@@ -4222,7 +4228,7 @@ AttributeParser::parse_meta_item_inner ()
42224228
if (!path_items.empty ())
42234229
{
42244230
return std::unique_ptr<MetaListPaths> (
4225-
new MetaListPaths (std::move (ident), std::move (path_items)));
4231+
new MetaListPaths (identifier->as_string (), std::move (path_items)));
42264232
}
42274233

42284234
rust_error_at (Linemap::unknown_location (),
@@ -4694,11 +4700,11 @@ Attribute
46944700
MetaNameValueStr::to_attribute () const
46954701
{
46964702
LiteralExpr lit_expr (str, Literal::LitType::STRING,
4697-
PrimitiveCoreType::CORETYPE_UNKNOWN, {}, Location ());
4703+
PrimitiveCoreType::CORETYPE_UNKNOWN, {}, str_locus);
46984704
// FIXME: What location do we put here? Is the literal above supposed to have
46994705
// an empty location as well?
47004706
// Should MetaNameValueStr keep a location?
4701-
return Attribute (SimplePath::from_str (ident, Location ()),
4707+
return Attribute (SimplePath::from_str (ident, ident_locus),
47024708
std::unique_ptr<AttrInputLiteral> (
47034709
new AttrInputLiteral (std::move (lit_expr))));
47044710
}

gcc/rust/ast/rust-macro.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -783,12 +783,17 @@ class MetaWord : public MetaItem
783783
class MetaNameValueStr : public MetaItem
784784
{
785785
Identifier ident;
786+
Location ident_locus;
787+
786788
// NOTE: str stored without quotes
787789
std::string str;
790+
Location str_locus;
788791

789792
public:
790-
MetaNameValueStr (Identifier ident, std::string str)
791-
: ident (std::move (ident)), str (std::move (str))
793+
MetaNameValueStr (Identifier ident, Location ident_locus, std::string str,
794+
Location str_locus)
795+
: ident (std::move (ident)), ident_locus (ident_locus),
796+
str (std::move (str)), str_locus (str_locus)
792797
{}
793798

794799
std::string as_string () const override

0 commit comments

Comments
 (0)