@@ -633,8 +633,7 @@ private:
public:
// Creates a Visibility - TODO make constructor protected or private?
- Visibility (VisType vis_type, SimplePath in_path,
- Location locus = Location ())
+ Visibility (VisType vis_type, SimplePath in_path, Location locus)
: vis_type (vis_type), in_path (std::move (in_path)), locus (locus)
{}
@@ -654,10 +653,11 @@ public:
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
@@ -669,45 +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),
- 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),
- 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),
- 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), in_path.get_locus ());
+ return Visibility (PUB_IN_PATH, std::move (in_path), in_path_vis_location);
}
std::string as_string () const;
@@ -2137,12 +2137,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
}
@@ -2158,19 +2159,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 ();
@@ -2188,7 +2189,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",