diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-04-28 09:44:04 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-28 09:44:04 +0000 |
commit | 1ada076b9324982fd6f49aea6456e99613e394a8 (patch) | |
tree | 811ca2f61e351aeda8be3e5f2e94a93993c1881e /gcc | |
parent | af48e2a3a1554f727e83281cc96071d9b8b3ef91 (diff) | |
parent | 471cff253a1c67cf4a85c0a91695e7e6d7803a5e (diff) | |
download | gcc-1ada076b9324982fd6f49aea6456e99613e394a8.zip gcc-1ada076b9324982fd6f49aea6456e99613e394a8.tar.gz gcc-1ada076b9324982fd6f49aea6456e99613e394a8.tar.bz2 |
Merge #1189
1189: Add missing `SimplePath`s location r=CohenArthur a=CohenArthur
Sorry to new contributors but I think I've taken all the good first issues we opened yesterday...
Closes #1179
Closes #1180
Closes #1181
Closes #1182
Necessary for #1172
Addresses #1159
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/ast/rust-ast-full-test.cc | 30 | ||||
-rw-r--r-- | gcc/rust/ast/rust-item.h | 22 | ||||
-rw-r--r-- | gcc/rust/ast/rust-macro.h | 30 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower.cc | 6 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 7 |
5 files changed, 53 insertions, 42 deletions
diff --git a/gcc/rust/ast/rust-ast-full-test.cc b/gcc/rust/ast/rust-ast-full-test.cc index 71cbb37..92325f1 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 ident = peek_token ()->as_string (); + auto ident_locus = peek_token ()->get_locus (); + 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))); + return std::unique_ptr<MetaWord> (new MetaWord (ident, ident_locus)); } 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,8 @@ 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 (ident, ident_locus, std::move (raw_value), + locus)); } else { @@ -4183,7 +4188,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 (ident, ident_locus, std::move (meta_name_value_str_items))); } @@ -4222,7 +4227,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 (ident, ident_locus, std::move (path_items))); } rust_error_at (Linemap::unknown_location (), @@ -4694,11 +4699,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)))); } @@ -4725,8 +4730,7 @@ MetaItemSeq::to_attribute () const Attribute MetaWord::to_attribute () const { - // FIXME: How do we get a location here? - return Attribute (SimplePath::from_str (ident, Location ()), nullptr); + return Attribute (SimplePath::from_str (ident, ident_locus), nullptr); } Attribute @@ -4744,8 +4748,7 @@ MetaListPaths::to_attribute () const std::unique_ptr<AttrInputMetaItemContainer> new_seq_container ( new AttrInputMetaItemContainer (std::move (new_seq))); - // FIXME: How do we get a location here? - return Attribute (SimplePath::from_str (ident, Location ()), + return Attribute (SimplePath::from_str (ident, ident_locus), std::move (new_seq_container)); } @@ -4760,8 +4763,7 @@ MetaListNameValueStr::to_attribute () const std::unique_ptr<AttrInputMetaItemContainer> new_seq_container ( new AttrInputMetaItemContainer (std::move (new_seq))); - // FIXME: How do we get a location here? - return Attribute (SimplePath::from_str (ident, Location ()), + return Attribute (SimplePath::from_str (ident, ident_locus), std::move (new_seq_container)); } diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 5907516..5d1e0d6 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -666,23 +666,25 @@ public: return Visibility (PUB, SimplePath::create_empty ()); } - // Creates a public visibility with crate-relative paths or whatever. - static Visibility create_crate () + // Creates a public visibility with crate-relative paths + static Visibility create_crate (Location crate_tok_location) { - return Visibility (PUB_CRATE, SimplePath::create_empty ()); + return Visibility (PUB_CRATE, + SimplePath::from_str ("crate", crate_tok_location)); } - // Creates a public visibility with self-relative paths or whatever. - static Visibility create_self () + // Creates a public visibility with self-relative paths + static Visibility create_self (Location self_tok_location) { - return Visibility (PUB_SELF, SimplePath::create_empty ()); + return Visibility (PUB_SELF, + SimplePath::from_str ("self", self_tok_location)); } - // Creates a public visibility with parent module-relative paths or - // whatever. - static Visibility create_super () + // Creates a public visibility with parent module-relative paths + static Visibility create_super (Location super_tok_location) { - return Visibility (PUB_SUPER, SimplePath::create_empty ()); + return Visibility (PUB_SUPER, + SimplePath::from_str ("super", super_tok_location)); } // Creates a private visibility diff --git a/gcc/rust/ast/rust-macro.h b/gcc/rust/ast/rust-macro.h index 5ab82c4..1bf8912 100644 --- a/gcc/rust/ast/rust-macro.h +++ b/gcc/rust/ast/rust-macro.h @@ -759,9 +759,12 @@ protected: class MetaWord : public MetaItem { Identifier ident; + Location ident_locus; public: - MetaWord (Identifier ident) : ident (std::move (ident)) {} + MetaWord (Identifier ident, Location ident_locus) + : ident (std::move (ident)), ident_locus (ident_locus) + {} std::string as_string () const override { return ident; } @@ -783,12 +786,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 @@ -821,11 +829,14 @@ protected: class MetaListPaths : public MetaItem { Identifier ident; + Location ident_locus; std::vector<SimplePath> paths; public: - MetaListPaths (Identifier ident, std::vector<SimplePath> paths) - : ident (std::move (ident)), paths (std::move (paths)) + MetaListPaths (Identifier ident, Location ident_locus, + std::vector<SimplePath> paths) + : ident (std::move (ident)), ident_locus (ident_locus), + paths (std::move (paths)) {} std::string as_string () const override; @@ -852,13 +863,14 @@ protected: class MetaListNameValueStr : public MetaItem { Identifier ident; + Location ident_locus; std::vector<MetaNameValueStr> strs; - // FIXME add location info - public: - MetaListNameValueStr (Identifier ident, std::vector<MetaNameValueStr> strs) - : ident (std::move (ident)), strs (std::move (strs)) + MetaListNameValueStr (Identifier ident, Location ident_locus, + std::vector<MetaNameValueStr> strs) + : ident (std::move (ident)), ident_locus (ident_locus), + strs (std::move (strs)) {} std::string as_string () const override; diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc index 630eded..bc613e1 100644 --- a/gcc/rust/hir/rust-ast-lower.cc +++ b/gcc/rust/hir/rust-ast-lower.cc @@ -43,14 +43,8 @@ translate_visibility (const AST::Visibility &vis) case AST::Visibility::PRIV: case AST::Visibility::PUB_SELF: return Visibility (Visibility::VisType::PRIVATE); - // Desugar pub(crate) into pub(in crate) and so on - // FIXME: How do we get a location for the SimplePath here? case AST::Visibility::PUB_CRATE: - return Visibility (Visibility::PUBLIC, - AST::SimplePath::from_str ("crate", Location ())); case AST::Visibility::PUB_SUPER: - return Visibility (Visibility::PUBLIC, - AST::SimplePath::from_str ("super", Location ())); case AST::Visibility::PUB_IN_PATH: return Visibility (Visibility::VisType::PUBLIC, vis.get_path ()); break; diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 6715a77..23ab32c 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -2136,6 +2136,7 @@ Parser<ManagedTokenSource>::parse_visibility () lexer.skip_token (); const_TokenPtr t = lexer.peek_token (); + auto path_loc = t->get_locus (); switch (t->get_id ()) { @@ -2144,19 +2145,19 @@ Parser<ManagedTokenSource>::parse_visibility () skip_token (RIGHT_PAREN); - return AST::Visibility::create_crate (); + return AST::Visibility::create_crate (path_loc); case SELF: lexer.skip_token (); skip_token (RIGHT_PAREN); - return AST::Visibility::create_self (); + return AST::Visibility::create_self (path_loc); case SUPER: lexer.skip_token (); skip_token (RIGHT_PAREN); - return AST::Visibility::create_super (); + return AST::Visibility::create_super (path_loc); case IN: { lexer.skip_token (); |