diff options
author | SimplyTheOther <simplytheother@gmail.com> | 2020-12-13 18:18:37 +0800 |
---|---|---|
committer | SimplyTheOther <simplytheother@gmail.com> | 2020-12-13 20:19:37 +0800 |
commit | 6d9b6db945ec25b51bff8b04e151973788149f3d (patch) | |
tree | 3e108b3b8727a01b008191d2eedeab6774b67025 | |
parent | a697962166a9c72e568814e09658a896fc92fef5 (diff) | |
download | gcc-6d9b6db945ec25b51bff8b04e151973788149f3d.zip gcc-6d9b6db945ec25b51bff8b04e151973788149f3d.tar.gz gcc-6d9b6db945ec25b51bff8b04e151973788149f3d.tar.bz2 |
Added location storage for struct expr fields
Fixed typo in an enum expr field class
-rw-r--r-- | gcc/rust/ast/rust-expr.h | 62 | ||||
-rw-r--r-- | gcc/rust/parse/rust-parse-impl.h | 10 |
2 files changed, 44 insertions, 28 deletions
diff --git a/gcc/rust/ast/rust-expr.h b/gcc/rust/ast/rust-expr.h index a3c94aa..cfffb38 100644 --- a/gcc/rust/ast/rust-expr.h +++ b/gcc/rust/ast/rust-expr.h @@ -1566,6 +1566,8 @@ public: virtual void accept_vis (ASTVisitor &vis) = 0; + virtual Location get_locus_slow () const = 0; + protected: // pure virtual clone implementation virtual StructExprField *clone_struct_expr_field_impl () const = 0; @@ -1575,15 +1577,18 @@ protected: class StructExprFieldIdentifier : public StructExprField { Identifier field_name; + Location locus; - // TODO: should this store location data? public: - StructExprFieldIdentifier (Identifier field_identifier) - : field_name (std::move (field_identifier)) + StructExprFieldIdentifier (Identifier field_identifier, Location locus) + : field_name (std::move (field_identifier)), locus (locus) {} std::string as_string () const override { return field_name; } + Location get_locus () const { return locus; } + Location get_locus_slow () const final override { return get_locus (); } + void accept_vis (ASTVisitor &vis) override; protected: @@ -1638,13 +1643,13 @@ public: class StructExprFieldIdentifierValue : public StructExprFieldWithVal { Identifier field_name; + Location locus; - // TODO: should this store location data? public: StructExprFieldIdentifierValue (Identifier field_identifier, - std::unique_ptr<Expr> field_value) + std::unique_ptr<Expr> field_value, Location locus) : StructExprFieldWithVal (std::move (field_value)), - field_name (std::move (field_identifier)) + field_name (std::move (field_identifier)), locus (locus) {} std::string as_string () const override; @@ -1653,6 +1658,9 @@ public: std::string get_field_name () const { return field_name; } + Location get_locus () const { return locus; } + Location get_locus_slow () const final override { return get_locus (); } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -1666,12 +1674,12 @@ protected: class StructExprFieldIndexValue : public StructExprFieldWithVal { TupleIndex index; + Location locus; - // TODO: should this store location data? public: StructExprFieldIndexValue (TupleIndex tuple_index, - std::unique_ptr<Expr> field_value) - : StructExprFieldWithVal (std::move (field_value)), index (tuple_index) + std::unique_ptr<Expr> field_value, Location locus) + : StructExprFieldWithVal (std::move (field_value)), index (tuple_index), locus (locus) {} std::string as_string () const override; @@ -1680,6 +1688,9 @@ public: TupleIndex get_index () const { return index; } + Location get_locus () const { return locus; } + Location get_locus_slow () const final override { return get_locus (); } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -1947,6 +1958,8 @@ public: virtual void accept_vis (ASTVisitor &vis) = 0; + virtual Location get_locus_slow () const = 0; + protected: // Clone function implementation as pure virtual method virtual EnumExprField *clone_enum_expr_field_impl () const = 0; @@ -1956,18 +1969,20 @@ protected: class EnumExprFieldIdentifier : public EnumExprField { Identifier field_name; - - // TODO: should this store location data? + Location locus; public: EnumExprFieldIdentifier (Identifier field_identifier) - : field_name (std::move (field_identifier)) + : field_name (std::move (field_identifier)), locus (locus) {} void accept_vis (ASTVisitor &vis) override; std::string as_string () const override { return field_name; } + Location get_locus () const { return locus; } + Location get_locus_slow () const final override { return get_locus (); } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -1983,8 +1998,6 @@ class EnumExprFieldWithVal : public EnumExprField { std::unique_ptr<Expr> value; - // TODO: should this store location data? - protected: EnumExprFieldWithVal (std::unique_ptr<Expr> field_value) : value (std::move (field_value)) @@ -2022,20 +2035,22 @@ public: class EnumExprFieldIdentifierValue : public EnumExprFieldWithVal { Identifier field_name; - - // TODO: should this store location data? + Location locus; public: EnumExprFieldIdentifierValue (Identifier field_name, - std::unique_ptr<Expr> field_value) + std::unique_ptr<Expr> field_value, Location locus) : EnumExprFieldWithVal (std::move (field_value)), - field_name (std::move (field_name)) + field_name (std::move (field_name)), locus (locus) {} std::string as_string () const override; void accept_vis (ASTVisitor &vis) override; + Location get_locus () const { return locus; } + Location get_locus_slow () const final override { return get_locus (); } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -2051,18 +2066,21 @@ class EnumExprFieldIndexValue : public EnumExprFieldWithVal TupleIndex index; // TODO: implement "with val" as a template with EnumExprField as type param? - // TODO: should this store location data? + Location locus; public: EnumExprFieldIndexValue (TupleIndex field_index, - std::unique_ptr<Expr> field_value) - : EnumExprFieldWithVal (std::move (field_value)), index (field_index) + std::unique_ptr<Expr> field_value, Location locus) + : EnumExprFieldWithVal (std::move (field_value)), index (field_index), locus (locus) {} std::string as_string () const override; void accept_vis (ASTVisitor &vis) override; + Location get_locus () const { return locus; } + Location get_locus_slow () const final override { return get_locus (); } + protected: /* Use covariance to implement clone function as returning this object rather * than base */ @@ -2075,9 +2093,7 @@ protected: // Struct-like syntax enum variant instance creation AST node class EnumExprStruct : public EnumVariantExpr { - // std::vector<EnumExprField> fields; std::vector<std::unique_ptr<EnumExprField> > fields; - Location locus; public: diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h index 74b6510..02c32b2 100644 --- a/gcc/rust/parse/rust-parse-impl.h +++ b/gcc/rust/parse/rust-parse-impl.h @@ -11509,7 +11509,7 @@ Parser<ManagedTokenSource>::parse_struct_expr_field () return std::unique_ptr<AST::StructExprFieldIdentifierValue> ( new AST::StructExprFieldIdentifierValue (std::move (ident), - std::move (expr))); + std::move (expr), t->get_locus ())); } else { @@ -11518,7 +11518,7 @@ Parser<ManagedTokenSource>::parse_struct_expr_field () lexer.skip_token (); return std::unique_ptr<AST::StructExprFieldIdentifier> ( - new AST::StructExprFieldIdentifier (std::move (ident))); + new AST::StructExprFieldIdentifier (std::move (ident), t->get_locus ())); } case INT_LITERAL: { // parse tuple index field @@ -11542,7 +11542,7 @@ Parser<ManagedTokenSource>::parse_struct_expr_field () } return std::unique_ptr<AST::StructExprFieldIndexValue> ( - new AST::StructExprFieldIndexValue (index, std::move (expr))); + new AST::StructExprFieldIndexValue (index, std::move (expr), t->get_locus ())); } case DOT_DOT: /* this is a struct base and can't be parsed here, so just return nothing @@ -11551,8 +11551,8 @@ Parser<ManagedTokenSource>::parse_struct_expr_field () return nullptr; default: rust_error_at (t->get_locus (), - "unrecognised token %qs as first token of struct expr " - "field - expected identifier or int literal", + "unrecognised token %qs as first token of struct expr field - " + "expected identifier or int literal", t->get_token_description ()); return nullptr; } |