@@ -609,41 +609,44 @@ struct FunctionParam
609
609
struct Visibility
610
610
{
611
611
public:
612
- enum PublicVisType
613
- {
614
- NONE,
615
- CRATE,
616
- SELF,
617
- SUPER,
618
- IN_PATH
612
+ enum VisType
613
+ {
614
+ PRIV,
615
+ PUB,
616
+ PUB_CRATE,
617
+ PUB_SELF,
618
+ PUB_SUPER,
619
+ PUB_IN_PATH
619
620
};
620
621
621
622
private:
622
- // if vis is public, one of these
623
- PublicVisType public_vis_type;
624
- // Only assigned if public_vis_type is IN_PATH
623
+ VisType vis_type;
624
+ // Only assigned if vis_type is IN_PATH
625
625
SimplePath in_path;
626
626
627
627
// should this store location info?
628
628
629
629
public:
630
630
// Creates a Visibility - TODO make constructor protected or private?
631
- Visibility (PublicVisType public_vis_type , SimplePath in_path)
632
- : public_vis_type (public_vis_type ), in_path (std::move (in_path))
631
+ Visibility (VisType vis_type , SimplePath in_path)
632
+ : vis_type (vis_type ), in_path (std::move (in_path))
633
633
{}
634
634
635
- PublicVisType get_public_vis_type () const { return public_vis_type ; }
635
+ VisType get_public_vis_type () const { return vis_type ; }
636
636
637
637
// Returns whether visibility is in an error state.
638
638
bool is_error () const
639
639
{
640
- return public_vis_type == IN_PATH && in_path.is_empty ();
640
+ return vis_type == PUB_IN_PATH && in_path.is_empty ();
641
641
}
642
642
643
+ // Returns whether visibility is public or not.
644
+ bool is_public () const { return vis_type != PRIV && !is_error (); }
645
+
643
646
// Creates an error visibility.
644
647
static Visibility create_error ()
645
648
{
646
- return Visibility (IN_PATH , SimplePath::create_empty ());
649
+ return Visibility (PUB_IN_PATH , SimplePath::create_empty ());
647
650
}
648
651
649
652
// Unique pointer custom clone function
@@ -657,32 +660,38 @@ struct Visibility
657
660
// Creates a public visibility with no further features/arguments.
658
661
static Visibility create_public ()
659
662
{
660
- return Visibility (NONE , SimplePath::create_empty ());
663
+ return Visibility (PUB , SimplePath::create_empty ());
661
664
}
662
665
663
666
// Creates a public visibility with crate-relative paths or whatever.
664
667
static Visibility create_crate ()
665
668
{
666
- return Visibility (CRATE , SimplePath::create_empty ());
669
+ return Visibility (PUB_CRATE , SimplePath::create_empty ());
667
670
}
668
671
669
672
// Creates a public visibility with self-relative paths or whatever.
670
673
static Visibility create_self ()
671
674
{
672
- return Visibility (SELF , SimplePath::create_empty ());
675
+ return Visibility (PUB_SELF , SimplePath::create_empty ());
673
676
}
674
677
675
678
// Creates a public visibility with parent module-relative paths or
676
679
// whatever.
677
680
static Visibility create_super ()
678
681
{
679
- return Visibility (SUPER, SimplePath::create_empty ());
682
+ return Visibility (PUB_SUPER, SimplePath::create_empty ());
683
+ }
684
+
685
+ // Creates a private visibility
686
+ static Visibility create_private ()
687
+ {
688
+ return Visibility (PRIV, SimplePath::create_empty ());
680
689
}
681
690
682
691
// Creates a public visibility with a given path or whatever.
683
692
static Visibility create_in_path (SimplePath in_path)
684
693
{
685
- return Visibility (IN_PATH , std::move (in_path));
694
+ return Visibility (PUB_IN_PATH , std::move (in_path));
686
695
}
687
696
688
697
std::string as_string () const ;
@@ -938,7 +947,7 @@ class VisItem : public Item
938
947
public:
939
948
/* Does the item have some kind of public visibility (non-default
940
949
* visibility)? */
941
- bool has_visibility () const { return ! visibility.is_error (); }
950
+ bool has_visibility () const { return visibility.is_public (); }
942
951
943
952
std::string as_string () const override ;
944
953
0 commit comments