@@ -553,91 +553,46 @@ struct FunctionParam
553
553
struct Visibility
554
554
{
555
555
public:
556
- enum PublicVisType
556
+ enum VisType
557
557
{
558
- NONE,
559
- CRATE,
560
- SELF,
561
- SUPER,
562
- IN_PATH
558
+ PRIVATE,
559
+ PUBLIC,
560
+ ERROR,
563
561
};
564
562
565
563
private:
566
- // if vis is public, one of these
567
- PublicVisType public_vis_type;
568
- // Only assigned if public_vis_type is IN_PATH
569
- AST::SimplePath in_path;
564
+ VisType vis_type;
565
+ AST::SimplePath path;
570
566
571
567
// should this store location info?
572
568
573
569
public:
574
570
// Creates a Visibility - TODO make constructor protected or private?
575
- Visibility (PublicVisType public_vis_type, AST::SimplePath in_path)
576
- : public_vis_type (public_vis_type), in_path (std::move (in_path))
571
+ Visibility (VisType vis_type,
572
+ AST::SimplePath path = AST::SimplePath::create_empty ())
573
+ : vis_type (vis_type), path (std::move (path))
577
574
{}
578
575
579
576
// Returns whether visibility is in an error state.
580
- bool is_error () const
581
- {
582
- return public_vis_type == IN_PATH && in_path.is_empty ();
583
- }
577
+ bool is_error () const { return vis_type == ERROR; }
584
578
585
579
// Creates an error visibility.
586
580
static Visibility create_error ()
587
581
{
588
- return Visibility (IN_PATH , AST::SimplePath::create_empty ());
582
+ return Visibility (ERROR , AST::SimplePath::create_empty ());
589
583
}
590
584
591
- // Unique pointer custom clone function
592
- /* std::unique_ptr<Visibility> clone_visibility() const {
593
- return std::unique_ptr<Visibility>(clone_visibility_impl());
594
- }*/
595
-
596
- /* TODO: think of a way to only allow valid Visibility states - polymorphism
597
- * is one idea but may be too resource-intensive. */
598
-
599
- // Creates a public visibility with no further features/arguments.
585
+ // Creates a public visibility.
586
+ // FIXME: Remove this function: We should not be calling it anymore and
587
+ // instead we should be using `translate_visibility`
600
588
static Visibility create_public ()
601
589
{
602
- return Visibility (NONE, AST::SimplePath::create_empty ());
603
- }
604
-
605
- // Creates a public visibility with crate-relative paths or whatever.
606
- static Visibility create_crate ()
607
- {
608
- return Visibility (CRATE, AST::SimplePath::create_empty ());
609
- }
610
-
611
- // Creates a public visibility with self-relative paths or whatever.
612
- static Visibility create_self ()
613
- {
614
- return Visibility (SELF, AST::SimplePath::create_empty ());
615
- }
616
-
617
- // Creates a public visibility with parent module-relative paths or
618
- // whatever.
619
- static Visibility create_super ()
620
- {
621
- return Visibility (SUPER, AST::SimplePath::create_empty ());
622
- }
623
-
624
- // Creates a public visibility with a given path or whatever.
625
- static Visibility create_in_path (AST::SimplePath in_path)
626
- {
627
- return Visibility (IN_PATH, std::move (in_path));
590
+ return Visibility (ERROR, AST::SimplePath::create_empty ());
628
591
}
629
592
630
- PublicVisType get_vis_type () const { return public_vis_type ; }
593
+ VisType get_vis_type () const { return vis_type ; }
631
594
632
595
std::string as_string () const ;
633
-
634
- protected:
635
- // Clone function implementation - not currently virtual but may be if
636
- // polymorphism used
637
- /* virtual*/ Visibility *clone_visibility_impl () const
638
- {
639
- return new Visibility (*this );
640
- }
641
596
};
642
597
643
598
// Item that supports visibility - abstract base class
0 commit comments