diff options
Diffstat (limited to 'gcc/rust/resolve/rust-name-resolver.h')
-rw-r--r-- | gcc/rust/resolve/rust-name-resolver.h | 47 |
1 files changed, 14 insertions, 33 deletions
diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h index 23a9d82..6b611b2 100644 --- a/gcc/rust/resolve/rust-name-resolver.h +++ b/gcc/rust/resolve/rust-name-resolver.h @@ -73,11 +73,13 @@ public: bool lookup (const CanonicalPath &ident, NodeId *id); void iterate (std::function<bool (Rib *)> cb); + void iterate (std::function<bool (const Rib *)> cb) const; Rib *peek (); void push (NodeId id); Rib *pop (); + bool decl_was_declared_here (NodeId def) const; void append_reference_for_def (NodeId refId, NodeId defId); CrateNum get_crate_num () const { return crate_num; } @@ -87,32 +89,6 @@ private: std::vector<Rib *> stack; }; -// This can map simple NodeIds for names to their parent node -// for example: -// -// var x = y + 1; -// -// say y has node id=1 and the plus_expression has id=2 -// then the Definition will have -// Definition { node=1, parent=2 } -// this will be used later to gather the ribs for the type inferences context -// -// if parent is UNKNOWN_NODEID then this is a root declaration -// say the var_decl hasa node_id=4; -// the parent could be a BLOCK_Expr node_id but lets make it UNKNOWN_NODE_ID -// so we know when it terminates -struct Definition -{ - NodeId node; - NodeId parent; - // add kind ? - - bool is_equal (const Definition &other) - { - return node == other.node && parent == other.parent; - } -}; - class Resolver { public: @@ -136,9 +112,6 @@ public: bool find_label_rib (NodeId id, Rib **rib); bool find_macro_rib (NodeId id, Rib **rib); - void insert_new_definition (NodeId id, Definition def); - bool lookup_definition (NodeId id, Definition *def); - void insert_resolved_name (NodeId refId, NodeId defId); bool lookup_resolved_name (NodeId refId, NodeId *defId); @@ -183,6 +156,18 @@ public: return current_module_stack.back (); } + NodeId peek_crate_module_scope () const + { + rust_assert (!current_module_stack.empty ()); + return current_module_stack.front (); + } + + NodeId peek_parent_module_scope () const + { + rust_assert (current_module_stack.size () > 1); + return current_module_stack.at (current_module_stack.size () - 2); + } + private: Resolver (); @@ -207,10 +192,6 @@ private: std::map<NodeId, Rib *> label_ribs; std::map<NodeId, Rib *> macro_ribs; - // map any Node to its Definition - // ie any name or type usage - std::map<NodeId, Definition> name_definitions; - // Rust uses DefIds to namespace these under a crate_num // but then it uses the def_collector to assign local_defids // to each ast node as well. not sure if this is going to fit |