aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2022-11-18 08:48:08 +0000
committerGitHub <noreply@github.com>2022-11-18 08:48:08 +0000
commit9ef8144e3994dea423011c0c248a0ea71c73cf25 (patch)
tree358b50f30b9764fea0735b85a98f7c360eaf36b5 /gcc
parentd8e9850b7f818f56fcf7e945003556db349db536 (diff)
parentbea720bef773efce55391ef005b7be990b9bfc50 (diff)
downloadgcc-9ef8144e3994dea423011c0c248a0ea71c73cf25.zip
gcc-9ef8144e3994dea423011c0c248a0ea71c73cf25.tar.gz
gcc-9ef8144e3994dea423011c0c248a0ea71c73cf25.tar.bz2
Merge #1636
1636: Add location to AST::Visibility r=CohenArthur a=dme2 Hi. I've added location to AST::Visibility, but it's possible I may have missed some steps here. Fixes #1183. Co-authored-by: Dave <dme2223@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-item.h44
-rw-r--r--gcc/rust/hir/rust-ast-lower.cc3
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.h6
-rw-r--r--gcc/rust/parse/rust-parse-impl.h11
4 files changed, 40 insertions, 24 deletions
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 09fad81..b91aec0 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -627,13 +627,14 @@ private:
VisType vis_type;
// Only assigned if vis_type is IN_PATH
SimplePath in_path;
+ Location locus;
// should this store location info?
public:
// Creates a Visibility - TODO make constructor protected or private?
- Visibility (VisType vis_type, SimplePath in_path)
- : vis_type (vis_type), in_path (std::move (in_path))
+ Visibility (VisType vis_type, SimplePath in_path, Location locus)
+ : vis_type (vis_type), in_path (std::move (in_path)), locus (locus)
{}
VisType get_vis_type () const { return vis_type; }
@@ -650,10 +651,13 @@ public:
// Returns whether visibility is public or not.
bool is_public () const { return vis_type != PRIV && !is_error (); }
+ Location get_locus () const { return locus; }
+
+ // empty?
// Creates an error visibility.
static Visibility create_error ()
{
- return Visibility (PUB_IN_PATH, SimplePath::create_empty ());
+ return Visibility (PUB_IN_PATH, SimplePath::create_empty (), Location ());
}
// Unique pointer custom clone function
@@ -665,42 +669,50 @@ public:
* is one idea but may be too resource-intensive. */
// Creates a public visibility with no further features/arguments.
- static Visibility create_public ()
+ // empty?
+ static Visibility create_public (Location pub_vis_location)
{
- return Visibility (PUB, SimplePath::create_empty ());
+ return Visibility (PUB, SimplePath::create_empty (), pub_vis_location);
}
// Creates a public visibility with crate-relative paths
- static Visibility create_crate (Location crate_tok_location)
+ static Visibility create_crate (Location crate_tok_location,
+ Location crate_vis_location)
{
return Visibility (PUB_CRATE,
- SimplePath::from_str ("crate", crate_tok_location));
+ SimplePath::from_str ("crate", crate_tok_location),
+ crate_vis_location);
}
// Creates a public visibility with self-relative paths
- static Visibility create_self (Location self_tok_location)
+ static Visibility create_self (Location self_tok_location,
+ Location self_vis_location)
{
return Visibility (PUB_SELF,
- SimplePath::from_str ("self", self_tok_location));
+ SimplePath::from_str ("self", self_tok_location),
+ self_vis_location);
}
// Creates a public visibility with parent module-relative paths
- static Visibility create_super (Location super_tok_location)
+ static Visibility create_super (Location super_tok_location,
+ Location super_vis_location)
{
return Visibility (PUB_SUPER,
- SimplePath::from_str ("super", super_tok_location));
+ SimplePath::from_str ("super", super_tok_location),
+ super_vis_location);
}
// Creates a private visibility
static Visibility create_private ()
{
- return Visibility (PRIV, SimplePath::create_empty ());
+ return Visibility (PRIV, SimplePath::create_empty (), Location ());
}
// Creates a public visibility with a given path or whatever.
- static Visibility create_in_path (SimplePath in_path)
+ static Visibility create_in_path (SimplePath in_path,
+ Location in_path_vis_location)
{
- return Visibility (PUB_IN_PATH, std::move (in_path));
+ return Visibility (PUB_IN_PATH, std::move (in_path), in_path_vis_location);
}
std::string as_string () const;
@@ -3841,8 +3853,8 @@ class ExternalItem
public:
virtual ~ExternalItem () {}
- /* TODO: spec syntax rules state that "MacroInvocationSemi" can be used as
- * ExternalItem, but text body isn't so clear. Adding MacroInvocationSemi
+ /* TODO: spec syntax rules state that "MacroInvocationSemi" can be used as
+ * ExternalItem, but text body isn't so clear. Adding MacroInvocationSemi
* support would require a lot of refactoring. */
// Returns whether item has outer attributes.
diff --git a/gcc/rust/hir/rust-ast-lower.cc b/gcc/rust/hir/rust-ast-lower.cc
index 52b7003..bffef4c 100644
--- a/gcc/rust/hir/rust-ast-lower.cc
+++ b/gcc/rust/hir/rust-ast-lower.cc
@@ -50,7 +50,8 @@ translate_visibility (const AST::Visibility &vis)
case AST::Visibility::PUB_SUPER:
case AST::Visibility::PUB_IN_PATH:
return Visibility (Visibility::VisType::RESTRICTED,
- ASTLoweringSimplePath::translate (vis.get_path ()));
+ ASTLoweringSimplePath::translate (vis.get_path ()),
+ vis.get_locus ());
break;
}
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index d84e41e..4420a0d 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -571,13 +571,15 @@ public:
private:
VisType vis_type;
HIR::SimplePath path;
+ Location locus;
// should this store location info?
public:
Visibility (VisType vis_type,
- HIR::SimplePath path = HIR::SimplePath::create_empty ())
- : vis_type (vis_type), path (std::move (path))
+ HIR::SimplePath path = HIR::SimplePath::create_empty (),
+ Location locus = Location ())
+ : vis_type (vis_type), path (std::move (path)), locus (locus)
{}
// Returns whether visibility is in an error state.
diff --git a/gcc/rust/parse/rust-parse-impl.h b/gcc/rust/parse/rust-parse-impl.h
index 54f3c5c..5642990 100644
--- a/gcc/rust/parse/rust-parse-impl.h
+++ b/gcc/rust/parse/rust-parse-impl.h
@@ -2128,12 +2128,13 @@ Parser<ManagedTokenSource>::parse_visibility ()
return AST::Visibility::create_private ();
}
+ auto vis_loc = lexer.peek_token ()->get_locus ();
lexer.skip_token ();
// create simple pub visibility if no parentheses
if (lexer.peek_token ()->get_id () != LEFT_PAREN)
{
- return AST::Visibility::create_public ();
+ return AST::Visibility::create_public (vis_loc);
// or whatever
}
@@ -2149,19 +2150,19 @@ Parser<ManagedTokenSource>::parse_visibility ()
skip_token (RIGHT_PAREN);
- return AST::Visibility::create_crate (path_loc);
+ return AST::Visibility::create_crate (path_loc, vis_loc);
case SELF:
lexer.skip_token ();
skip_token (RIGHT_PAREN);
- return AST::Visibility::create_self (path_loc);
+ return AST::Visibility::create_self (path_loc, vis_loc);
case SUPER:
lexer.skip_token ();
skip_token (RIGHT_PAREN);
- return AST::Visibility::create_super (path_loc);
+ return AST::Visibility::create_super (path_loc, vis_loc);
case IN: {
lexer.skip_token ();
@@ -2179,7 +2180,7 @@ Parser<ManagedTokenSource>::parse_visibility ()
skip_token (RIGHT_PAREN);
- return AST::Visibility::create_in_path (std::move (path));
+ return AST::Visibility::create_in_path (std::move (path), vis_loc);
}
default:
add_error (Error (t->get_locus (), "unexpected token %qs in visibility",