// forward decl for Attribute
class AttrInput;
+// Visibility of item - if the item has it, then it is some form of public
+struct Visibility
+{
+public:
+ enum VisType
+ {
+ PRIV,
+ PUB,
+ PUB_CRATE,
+ PUB_SELF,
+ PUB_SUPER,
+ PUB_IN_PATH
+ };
+
+private:
+ VisType vis_type;
+ // Only assigned if vis_type is IN_PATH
+ SimplePath in_path;
+ location_t locus;
+
+ // should this store location info?
+
+public:
+ // Creates a Visibility - TODO make constructor protected or private?
+ Visibility (VisType vis_type, SimplePath in_path, location_t locus)
+ : vis_type (vis_type), in_path (std::move (in_path)), locus (locus)
+ {}
+
+ VisType get_vis_type () const { return vis_type; }
+
+ // Returns whether visibility is in an error state.
+ bool is_error () const
+ {
+ return vis_type == PUB_IN_PATH && in_path.is_empty ();
+ }
+
+ // Returns whether a visibility has a path
+ bool has_path () const { return !is_error () && vis_type >= PUB_CRATE; }
+
+ // Returns whether visibility is public or not.
+ bool is_public () const { return vis_type != PRIV && !is_error (); }
+
+ location_t get_locus () const { return locus; }
+
+ // empty?
+ // Creates an error visibility.
+ static Visibility create_error ()
+ {
+ return Visibility (PUB_IN_PATH, SimplePath::create_empty (),
+ UNDEF_LOCATION);
+ }
+
+ // Unique pointer custom clone function
+ /*std::unique_ptr<Visibility> clone_visibility() const {
+ return std::unique_ptr<Visibility>(clone_visibility_impl());
+ }*/
+
+ /* TODO: think of a way to only allow valid Visibility states - polymorphism
+ * is one idea but may be too resource-intensive. */
+
+ // Creates a public visibility with no further features/arguments.
+ // empty?
+ static Visibility create_public (location_t pub_vis_location)
+ {
+ return Visibility (PUB, SimplePath::create_empty (), pub_vis_location);
+ }
+
+ // Creates a public visibility with crate-relative paths
+ static Visibility create_crate (location_t crate_tok_location,
+ location_t crate_vis_location)
+ {
+ return Visibility (PUB_CRATE,
+ SimplePath::from_str ("crate", crate_tok_location),
+ crate_vis_location);
+ }
+
+ // Creates a public visibility with self-relative paths
+ static Visibility create_self (location_t self_tok_location,
+ location_t self_vis_location)
+ {
+ return Visibility (PUB_SELF,
+ SimplePath::from_str ("self", self_tok_location),
+ self_vis_location);
+ }
+
+ // Creates a public visibility with parent module-relative paths
+ static Visibility create_super (location_t super_tok_location,
+ location_t super_vis_location)
+ {
+ return Visibility (PUB_SUPER,
+ SimplePath::from_str ("super", super_tok_location),
+ super_vis_location);
+ }
+
+ // Creates a private visibility
+ static Visibility create_private ()
+ {
+ return Visibility (PRIV, SimplePath::create_empty (), UNDEF_LOCATION);
+ }
+
+ // Creates a public visibility with a given path or whatever.
+ static Visibility create_in_path (SimplePath in_path,
+ location_t in_path_vis_location)
+ {
+ return Visibility (PUB_IN_PATH, std::move (in_path), in_path_vis_location);
+ }
+
+ std::string as_string () const;
+ const SimplePath &get_path () const { return in_path; }
+ SimplePath &get_path () { return in_path; }
+
+protected:
+ // Clone function implementation - not currently virtual but may be if
+ // polymorphism used
+ /*virtual*/ Visibility *clone_visibility_impl () const
+ {
+ return new Visibility (*this);
+ }
+};
+
// aka Attr
// Attribute AST representation
struct Attribute
Item *clone_stmt_impl () const final override { return clone_item_impl (); }
};
-// Visibility of item - if the item has it, then it is some form of public
-struct Visibility
-{
-public:
- enum VisType
- {
- PRIV,
- PUB,
- PUB_CRATE,
- PUB_SELF,
- PUB_SUPER,
- PUB_IN_PATH
- };
-
-private:
- VisType vis_type;
- // Only assigned if vis_type is IN_PATH
- SimplePath in_path;
- location_t locus;
-
- // should this store location info?
-
-public:
- // Creates a Visibility - TODO make constructor protected or private?
- Visibility (VisType vis_type, SimplePath in_path, location_t locus)
- : vis_type (vis_type), in_path (std::move (in_path)), locus (locus)
- {}
-
- VisType get_vis_type () const { return vis_type; }
-
- // Returns whether visibility is in an error state.
- bool is_error () const
- {
- return vis_type == PUB_IN_PATH && in_path.is_empty ();
- }
-
- // Returns whether a visibility has a path
- bool has_path () const { return !is_error () && vis_type >= PUB_CRATE; }
-
- // Returns whether visibility is public or not.
- bool is_public () const { return vis_type != PRIV && !is_error (); }
-
- location_t get_locus () const { return locus; }
-
- // empty?
- // Creates an error visibility.
- static Visibility create_error ()
- {
- return Visibility (PUB_IN_PATH, SimplePath::create_empty (),
- UNDEF_LOCATION);
- }
-
- // Unique pointer custom clone function
- /*std::unique_ptr<Visibility> clone_visibility() const {
- return std::unique_ptr<Visibility>(clone_visibility_impl());
- }*/
-
- /* TODO: think of a way to only allow valid Visibility states - polymorphism
- * is one idea but may be too resource-intensive. */
-
- // Creates a public visibility with no further features/arguments.
- // empty?
- static Visibility create_public (location_t pub_vis_location)
- {
- return Visibility (PUB, SimplePath::create_empty (), pub_vis_location);
- }
-
- // Creates a public visibility with crate-relative paths
- static Visibility create_crate (location_t crate_tok_location,
- location_t crate_vis_location)
- {
- return Visibility (PUB_CRATE,
- SimplePath::from_str ("crate", crate_tok_location),
- crate_vis_location);
- }
-
- // Creates a public visibility with self-relative paths
- static Visibility create_self (location_t self_tok_location,
- location_t self_vis_location)
- {
- return Visibility (PUB_SELF,
- SimplePath::from_str ("self", self_tok_location),
- self_vis_location);
- }
-
- // Creates a public visibility with parent module-relative paths
- static Visibility create_super (location_t super_tok_location,
- location_t super_vis_location)
- {
- return Visibility (PUB_SUPER,
- SimplePath::from_str ("super", super_tok_location),
- super_vis_location);
- }
-
- // Creates a private visibility
- static Visibility create_private ()
- {
- return Visibility (PRIV, SimplePath::create_empty (), UNDEF_LOCATION);
- }
-
- // Creates a public visibility with a given path or whatever.
- static Visibility create_in_path (SimplePath in_path,
- location_t in_path_vis_location)
- {
- return Visibility (PUB_IN_PATH, std::move (in_path), in_path_vis_location);
- }
-
- std::string as_string () const;
- const SimplePath &get_path () const { return in_path; }
- SimplePath &get_path () { return in_path; }
-
-protected:
- // Clone function implementation - not currently virtual but may be if
- // polymorphism used
- /*virtual*/ Visibility *clone_visibility_impl () const
- {
- return new Visibility (*this);
- }
-};
// Item that supports visibility - abstract base class
class VisItem : public Item
{
{
protected:
TraitItem (location_t locus)
- : node_id (Analysis::Mappings::get ()->get_next_node_id ()), locus (locus)
+ : node_id (Analysis::Mappings::get ()->get_next_node_id ()),
+ vis (Visibility::create_private ()), locus (locus)
+ {}
+
+ TraitItem (Visibility vis, location_t locus)
+ : node_id (Analysis::Mappings::get ()->get_next_node_id ()), vis (vis),
+ locus (locus)
{}
// Clone function implementation as pure virtual method
virtual TraitItem *clone_associated_item_impl () const override = 0;
NodeId node_id;
+ Visibility vis;
location_t locus;
public: