diff options
Diffstat (limited to 'gcc/rust/resolve/rust-rib.h')
-rw-r--r-- | gcc/rust/resolve/rust-rib.h | 82 |
1 files changed, 75 insertions, 7 deletions
diff --git a/gcc/rust/resolve/rust-rib.h b/gcc/rust/resolve/rust-rib.h index 3db17b4..be7c217 100644 --- a/gcc/rust/resolve/rust-rib.h +++ b/gcc/rust/resolve/rust-rib.h @@ -111,29 +111,61 @@ public: class Definition { public: - static Definition NonShadowable (NodeId id); + static Definition NonShadowable (NodeId id, bool enum_variant = false); static Definition Shadowable (NodeId id); - - std::vector<NodeId> ids; - bool shadowable; + static Definition Globbed (NodeId id); + + // checked shadowable -> non_shadowable -> globbed + // we have shadowable *and* globbed in order to control + // resolution priority + // we *could* use a single vector with 2 indices here + // but it's probably not worth it for now + std::vector<NodeId> ids_shadowable; + std::vector<NodeId> ids_non_shadowable; + std::vector<NodeId> ids_globbed; + + // Enum variant should be skipped when dealing with inner definition. + // struct E2; + // + // enum MyEnum<T> /* <-- Should be kept */{ + // E2 /* <-- Should be skipped */ (E2); + // } + bool enum_variant; Definition () = default; Definition &operator= (const Definition &) = default; Definition (Definition const &) = default; + bool is_variant () const; + bool is_ambiguous () const; - NodeId get_node_id () + NodeId get_node_id () const { + if (!ids_shadowable.empty ()) + return ids_shadowable.back (); + rust_assert (!is_ambiguous ()); - return ids[0]; + + if (!ids_non_shadowable.empty ()) + return ids_non_shadowable.back (); + + rust_assert (!ids_globbed.empty ()); + return ids_globbed.back (); } std::string to_string () const; private: - Definition (NodeId id, bool shadowable); + enum class Mode + { + SHADOWABLE, + NON_SHADOWABLE, + GLOBBED + }; + + Definition (NodeId id, Mode mode, bool enum_variant); }; enum class Kind @@ -151,8 +183,44 @@ public: ForwardTypeParamBan, /* Const generic, as in the following example: fn foo<T, const X: T>() {} */ ConstParamType, + /* Prelude rib, used for both the language prelude (i32,usize,etc) and the + * (future) {std,core}::prelude::* import. A regular rib with the + * restriction that you cannot `use` items from the Prelude + */ + Prelude, + /* Generic rib, used to store generics */ + Generics, } kind; + static std::string kind_to_string (Rib::Kind kind) + { + switch (kind) + { + case Rib::Kind::Normal: + return "Normal"; + case Rib::Kind::Module: + return "Module"; + case Rib::Kind::Function: + return "Function"; + case Rib::Kind::ConstantItem: + return "ConstantItem"; + case Rib::Kind::TraitOrImpl: + return "TraitOrImpl"; + case Rib::Kind::Item: + return "Item"; + case Rib::Kind::Closure: + return "Closure"; + case Rib::Kind::MacroDefinition: + return "Macro definition"; + case Rib::Kind::ForwardTypeParamBan: + return "Forward type param ban"; + case Rib::Kind::ConstParamType: + return "Const Param Type"; + default: + rust_unreachable (); + } + } + Rib (Kind kind); Rib (Kind kind, std::string identifier, NodeId id); Rib (Kind kind, std::unordered_map<std::string, NodeId> values); |