Skip to content

Commit 471cff2

Browse files
committed
ast: Add location info to remaining meta items
1 parent ffb38df commit 471cff2

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

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

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

4121-
auto &identifier = peek_token ();
4121+
auto ident = peek_token ()->as_string ();
4122+
auto ident_locus = peek_token ()->get_locus ();
4123+
41224124
if (is_end_meta_item_tok (peek_token (1)->get_id ()))
41234125
{
41244126
// meta word syntax
41254127
skip_token ();
4126-
// FIXME: We probably need a Location here as well
4127-
return std::unique_ptr<MetaWord> (
4128-
new MetaWord (identifier->as_string (), identifier->get_locus ()));
4128+
return std::unique_ptr<MetaWord> (new MetaWord (ident, ident_locus));
41294129
}
41304130

41314131
if (peek_token (1)->get_id () == EQUAL)
@@ -4145,9 +4145,8 @@ AttributeParser::parse_meta_item_inner ()
41454145
std::string raw_value = unquote_string (std::move (value));
41464146

41474147
return std::unique_ptr<MetaNameValueStr> (
4148-
new MetaNameValueStr (identifier->as_string (),
4149-
identifier->get_locus (),
4150-
std::move (raw_value), locus));
4148+
new MetaNameValueStr (ident, ident_locus, std::move (raw_value),
4149+
locus));
41514150
}
41524151
else
41534152
{
@@ -4189,7 +4188,7 @@ AttributeParser::parse_meta_item_inner ()
41894188
if (!meta_name_value_str_items.empty ())
41904189
{
41914190
return std::unique_ptr<MetaListNameValueStr> (
4192-
new MetaListNameValueStr (identifier->as_string (),
4191+
new MetaListNameValueStr (ident, ident_locus,
41934192
std::move (meta_name_value_str_items)));
41944193
}
41954194

@@ -4228,7 +4227,7 @@ AttributeParser::parse_meta_item_inner ()
42284227
if (!path_items.empty ())
42294228
{
42304229
return std::unique_ptr<MetaListPaths> (
4231-
new MetaListPaths (identifier->as_string (), std::move (path_items)));
4230+
new MetaListPaths (ident, ident_locus, std::move (path_items)));
42324231
}
42334232

42344233
rust_error_at (Linemap::unknown_location (),
@@ -4749,8 +4748,7 @@ MetaListPaths::to_attribute () const
47494748

47504749
std::unique_ptr<AttrInputMetaItemContainer> new_seq_container (
47514750
new AttrInputMetaItemContainer (std::move (new_seq)));
4752-
// FIXME: How do we get a location here?
4753-
return Attribute (SimplePath::from_str (ident, Location ()),
4751+
return Attribute (SimplePath::from_str (ident, ident_locus),
47544752
std::move (new_seq_container));
47554753
}
47564754

@@ -4765,8 +4763,7 @@ MetaListNameValueStr::to_attribute () const
47654763

47664764
std::unique_ptr<AttrInputMetaItemContainer> new_seq_container (
47674765
new AttrInputMetaItemContainer (std::move (new_seq)));
4768-
// FIXME: How do we get a location here?
4769-
return Attribute (SimplePath::from_str (ident, Location ()),
4766+
return Attribute (SimplePath::from_str (ident, ident_locus),
47704767
std::move (new_seq_container));
47714768
}
47724769

gcc/rust/ast/rust-macro.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -829,11 +829,14 @@ class MetaNameValueStr : public MetaItem
829829
class MetaListPaths : public MetaItem
830830
{
831831
Identifier ident;
832+
Location ident_locus;
832833
std::vector<SimplePath> paths;
833834

834835
public:
835-
MetaListPaths (Identifier ident, std::vector<SimplePath> paths)
836-
: ident (std::move (ident)), paths (std::move (paths))
836+
MetaListPaths (Identifier ident, Location ident_locus,
837+
std::vector<SimplePath> paths)
838+
: ident (std::move (ident)), ident_locus (ident_locus),
839+
paths (std::move (paths))
837840
{}
838841

839842
std::string as_string () const override;
@@ -860,13 +863,14 @@ class MetaListPaths : public MetaItem
860863
class MetaListNameValueStr : public MetaItem
861864
{
862865
Identifier ident;
866+
Location ident_locus;
863867
std::vector<MetaNameValueStr> strs;
864868

865-
// FIXME add location info
866-
867869
public:
868-
MetaListNameValueStr (Identifier ident, std::vector<MetaNameValueStr> strs)
869-
: ident (std::move (ident)), strs (std::move (strs))
870+
MetaListNameValueStr (Identifier ident, Location ident_locus,
871+
std::vector<MetaNameValueStr> strs)
872+
: ident (std::move (ident)), ident_locus (ident_locus),
873+
strs (std::move (strs))
870874
{}
871875

872876
std::string as_string () const override;

0 commit comments

Comments
 (0)