diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-05-17 10:11:04 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-17 10:11:04 +0000 |
commit | 8cad07cfd2244ad9a40027a4306b81b4553a4797 (patch) | |
tree | ce267318444308626518420adf10b563c2bad96c /gcc/rust/resolve | |
parent | e4213b9568ae8cb8a4e31326e0e78c79db0a99cc (diff) | |
parent | 48fc2df91b07709f41ab80499a661ac9f12f3be3 (diff) | |
download | gcc-8cad07cfd2244ad9a40027a4306b81b4553a4797.zip gcc-8cad07cfd2244ad9a40027a4306b81b4553a4797.tar.gz gcc-8cad07cfd2244ad9a40027a4306b81b4553a4797.tar.bz2 |
Merge #1246
1246: Report simple privacy violations r=CohenArthur a=CohenArthur
This adds a base visitor for reporting basic privacy violations. For now, only function calls are implemented.
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-base.h | 6 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-item.cc | 5 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-toplevel.h | 14 | ||||
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve.cc | 2 |
4 files changed, 17 insertions, 10 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-base.h b/gcc/rust/resolve/rust-ast-resolve-base.h index 17d05c3..9c1f0a1 100644 --- a/gcc/rust/resolve/rust-ast-resolve-base.h +++ b/gcc/rust/resolve/rust-ast-resolve-base.h @@ -199,9 +199,10 @@ public: void visit (AST::BareFunctionType &); protected: - ResolverBase (NodeId parent) + ResolverBase (NodeId parent, NodeId current_module = UNKNOWN_NODEID) : resolver (Resolver::get ()), mappings (Analysis::Mappings::get ()), - resolved_node (UNKNOWN_NODEID), parent (parent), locus (Location ()) + resolved_node (UNKNOWN_NODEID), parent (parent), + current_module (current_module), locus (Location ()) {} bool resolved () const { return resolved_node != UNKNOWN_NODEID; } @@ -215,6 +216,7 @@ protected: Analysis::Mappings *mappings; NodeId resolved_node; NodeId parent; + NodeId current_module; Location locus; }; diff --git a/gcc/rust/resolve/rust-ast-resolve-item.cc b/gcc/rust/resolve/rust-ast-resolve-item.cc index 93eca1b..38e7713 100644 --- a/gcc/rust/resolve/rust-ast-resolve-item.cc +++ b/gcc/rust/resolve/rust-ast-resolve-item.cc @@ -250,8 +250,11 @@ ResolveItem::visit (AST::Module &module) resolver->push_new_type_rib (resolver->get_type_scope ().peek ()); resolver->push_new_label_rib (resolver->get_type_scope ().peek ()); + // FIXME: Should we reinsert a child here? Any reason we ResolveTopLevel::go + // in ResolveTopLevel::visit (AST::Module) as well as here? for (auto &item : module.get_items ()) - ResolveTopLevel::go (item.get (), CanonicalPath::create_empty (), cpath); + ResolveTopLevel::go (item.get (), CanonicalPath::create_empty (), cpath, + module.get_node_id ()); for (auto &item : module.get_items ()) ResolveItem::go (item.get (), path, cpath); diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h index 7aba67f..7cfaa72 100644 --- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h +++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h @@ -34,12 +34,12 @@ class ResolveTopLevel : public ResolverBase public: static void go (AST::Item *item, const CanonicalPath &prefix, - const CanonicalPath &canonical_prefix) + const CanonicalPath &canonical_prefix, NodeId current_module) { if (item->is_marked_for_strip ()) return; - ResolveTopLevel resolver (prefix, canonical_prefix); + ResolveTopLevel resolver (prefix, canonical_prefix, current_module); item->accept_vis (resolver); }; @@ -62,8 +62,10 @@ public: Definition{module.get_node_id (), module.get_node_id ()}); + mappings->insert_module_child (current_module, module.get_node_id ()); + for (auto &item : module.get_items ()) - ResolveTopLevel::go (item.get (), path, cpath); + ResolveTopLevel::go (item.get (), path, cpath, module.get_node_id ()); mappings->insert_canonical_path (mappings->get_current_crate (), module.get_node_id (), cpath); @@ -123,7 +125,7 @@ public: }); for (auto &variant : enum_decl.get_variants ()) - ResolveTopLevel::go (variant.get (), path, cpath); + ResolveTopLevel::go (variant.get (), path, cpath, current_module); mappings->insert_canonical_path (mappings->get_current_crate (), enum_decl.get_node_id (), cpath); @@ -403,8 +405,8 @@ public: private: ResolveTopLevel (const CanonicalPath &prefix, - const CanonicalPath &canonical_prefix) - : ResolverBase (UNKNOWN_NODEID), prefix (prefix), + const CanonicalPath &canonical_prefix, NodeId current_module) + : ResolverBase (UNKNOWN_NODEID, current_module), prefix (prefix), canonical_prefix (canonical_prefix) {} diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc index 6da5609..945ff28 100644 --- a/gcc/rust/resolve/rust-ast-resolve.cc +++ b/gcc/rust/resolve/rust-ast-resolve.cc @@ -86,7 +86,7 @@ NameResolution::go (AST::Crate &crate) // a Self type Foo which is defined after the impl block for example. for (auto it = crate.items.begin (); it != crate.items.end (); it++) ResolveTopLevel::go (it->get (), CanonicalPath::create_empty (), - crate_prefix); + crate_prefix, scope_node_id); // FIXME remove this if (saw_errors ()) |