]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: Add get_locus function for abstract class MetaItemInner.
authormxlol233 <mxlol233@outlook.com>
Wed, 11 Jan 2023 15:24:07 +0000 (23:24 +0800)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 6 Apr 2023 08:47:17 +0000 (10:47 +0200)
This commit adds virtual function get_locus to base class MetaItemInner,
which is helpful when we need to print  diagnostics on some sub-classes of
MetaItemInner.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add get_locus method.
* ast/rust-expr.h: Likewise.
* ast/rust-macro.h: Likewise.

Signed-off-by: Xiao Ma <mxlol233@outlook.com>
gcc/rust/ast/rust-ast.h
gcc/rust/ast/rust-expr.h
gcc/rust/ast/rust-macro.h

index 5f18233eb0fe69f83dfeaf3f24ad9bb0c40452b1..d30e6d494f2d11fb5b5a19f360bb9ce010b28946 100644 (file)
@@ -630,6 +630,8 @@ public:
 
   virtual ~MetaItemInner ();
 
+  virtual Location get_locus () const = 0;
+
   virtual std::string as_string () const = 0;
 
   virtual void accept_vis (ASTVisitor &vis) = 0;
index c58fae5e564501c1e67c2aeaffeaa5f30f8f7bfa..34bc6993ab646a7ec0aff91641e3165d58795ff6 100644 (file)
@@ -150,6 +150,8 @@ public:
 
   std::string as_string () const override { return lit_expr.as_string (); }
 
+  Location get_locus () const override { return lit_expr.get_locus (); }
+
   void accept_vis (ASTVisitor &vis) override;
 
   bool check_cfg_predicate (const Session &session) const override;
@@ -178,6 +180,12 @@ public:
     return path.as_string () + " = " + lit.as_string ();
   }
 
+  // There are two Locations in MetaItemPathLit (path and lit_expr),
+  //  we have no idea use which of them, just simply return UNKNOWN_LOCATION
+  //  now.
+  // Maybe we will figure out when we really need the location in the future.
+  Location get_locus () const override { return Location (UNKNOWN_LOCATION); }
+
   void accept_vis (ASTVisitor &vis) override;
 
   bool check_cfg_predicate (const Session &session) const override;
index bff8c7ac6fb5cc36ff0343251f6e407069c9393b..4226c6919ff122d7d25b16125b75a15e49346ce6 100644 (file)
@@ -725,6 +725,8 @@ public:
     return path;
   }
 
+  Location get_locus () const override { return path.get_locus (); }
+
   bool check_cfg_predicate (const Session &session) const override;
 
   Attribute to_attribute () const override;
@@ -778,6 +780,8 @@ public:
 
   void accept_vis (ASTVisitor &vis) override;
 
+  Location get_locus () const override { return path.get_locus (); }
+
   bool check_cfg_predicate (const Session &session) const override;
 
   Attribute to_attribute () const override;
@@ -805,6 +809,8 @@ public:
 
   void accept_vis (ASTVisitor &vis) override;
 
+  Location get_locus () const override { return ident_locus; }
+
   bool check_cfg_predicate (const Session &session) const override;
 
   Attribute to_attribute () const override;
@@ -847,6 +853,8 @@ public:
     return std::unique_ptr<MetaNameValueStr> (clone_meta_item_inner_impl ());
   }
 
+  Location get_locus () const override { return ident_locus; }
+
   bool check_cfg_predicate (const Session &session) const override;
 
   Attribute to_attribute () const override;
@@ -885,6 +893,8 @@ public:
 
   void accept_vis (ASTVisitor &vis) override;
 
+  Location get_locus () const override { return ident_locus; }
+
   bool check_cfg_predicate (const Session &session) const override;
 
   Attribute to_attribute () const override;
@@ -919,6 +929,8 @@ public:
 
   void accept_vis (ASTVisitor &vis) override;
 
+  Location get_locus () const override { return ident_locus; }
+
   bool check_cfg_predicate (const Session &session) const override;
 
   Attribute to_attribute () const override;