diff options
author | Thomas Young <wenzhang5800@gmail.com> | 2021-07-01 15:34:38 +0800 |
---|---|---|
committer | Thomas Young <wenzhang5800@gmail.com> | 2021-07-02 12:37:54 +0800 |
commit | 6d7b87f9dd9223da0f3994be5bef5ea9458ebdff (patch) | |
tree | 2948f81be055a6ef61090fa1b409e42d26810390 | |
parent | 458f7a5459a8907fa55a84248ba137281ac675c4 (diff) | |
download | gcc-6d7b87f9dd9223da0f3994be5bef5ea9458ebdff.zip gcc-6d7b87f9dd9223da0f3994be5bef5ea9458ebdff.tar.gz gcc-6d7b87f9dd9223da0f3994be5bef5ea9458ebdff.tar.bz2 |
make struct field carry the location info
-rw-r--r-- | gcc/rust/ast/rust-item.h | 16 | ||||
-rw-r--r-- | gcc/rust/hir/rust-ast-lower-item.h | 6 | ||||
-rw-r--r-- | gcc/rust/hir/tree/rust-hir-item.h | 2 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 4 |
4 files changed, 15 insertions, 13 deletions
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h index 7865a44..37d087c 100644 --- a/gcc/rust/ast/rust-item.h +++ b/gcc/rust/ast/rust-item.h @@ -1841,10 +1841,10 @@ private: Identifier field_name; std::unique_ptr<Type> field_type; - // should this store location info? - NodeId node_id; + Location locus; + public: // Returns whether struct field has any outer attributes. bool has_outer_attributes () const { return !outer_attrs.empty (); } @@ -1853,17 +1853,18 @@ public: bool has_visibility () const { return !visibility.is_error (); } StructField (Identifier field_name, std::unique_ptr<Type> field_type, - Visibility vis, + Visibility vis, Location locus, std::vector<Attribute> outer_attrs = std::vector<Attribute> ()) : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)), field_name (std::move (field_name)), field_type (std::move (field_type)), - node_id (Analysis::Mappings::get ()->get_next_node_id ()) + node_id (Analysis::Mappings::get ()->get_next_node_id ()), locus (locus) {} // Copy constructor StructField (StructField const &other) : outer_attrs (other.outer_attrs), visibility (other.visibility), - field_name (other.field_name), node_id (other.node_id) + field_name (other.field_name), node_id (other.node_id), + locus (other.locus) { // guard to prevent null dereference if (other.field_type != nullptr) @@ -1903,7 +1904,8 @@ public: // Creates an error state struct field. static StructField create_error () { - return StructField (std::string (""), nullptr, Visibility::create_error ()); + return StructField (std::string (""), nullptr, Visibility::create_error (), + Location ()); } std::string as_string () const; @@ -1914,6 +1916,8 @@ public: Identifier get_field_name () const { return field_name; } + Location get_locus () const { return locus; } + // TODO: is this better? Or is a "vis_block" better? std::unique_ptr<Type> &get_field_type () { diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-lower-item.h index b2a4d5f..7985faa 100644 --- a/gcc/rust/hir/rust-ast-lower-item.h +++ b/gcc/rust/hir/rust-ast-lower-item.h @@ -165,12 +165,10 @@ public: mappings->get_next_localdef_id ( crate_num)); - // FIXME - // AST::StructField is missing Location info - Location field_locus; HIR::StructField translated_field (mapping, field.get_field_name (), std::unique_ptr<HIR::Type> (type), vis, - field_locus, field.get_outer_attrs ()); + field.get_locus (), + field.get_outer_attrs ()); fields.push_back (std::move (translated_field)); return true; }); diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h index a5069b7..10b1f61 100644 --- a/gcc/rust/hir/tree/rust-hir-item.h +++ b/gcc/rust/hir/tree/rust-hir-item.h @@ -1448,8 +1448,6 @@ public: Location locus; - // should this store location info? - // Returns whether struct field has any outer attributes. bool has_outer_attributes () const { return !outer_attrs.empty (); } diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 23e6234..9f8282b 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -4150,6 +4150,8 @@ Parser<ManagedTokenSource>::parse_struct_field () // parse visibility, if it exists AST::Visibility vis = parse_visibility (); + Location locus = lexer.peek_token ()->get_locus (); + // parse field name const_TokenPtr field_name_tok = lexer.peek_token (); if (field_name_tok->get_id () != IDENTIFIER) @@ -4180,7 +4182,7 @@ Parser<ManagedTokenSource>::parse_struct_field () } return AST::StructField (std::move (field_name), std::move (field_type), - std::move (vis), std::move (outer_attrs)); + std::move (vis), locus, std::move (outer_attrs)); } // Parses tuple fields in tuple/tuple struct declarations. |