diff options
author | Philip Herron <philip.herron@embecosm.com> | 2021-06-05 16:52:44 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2021-06-05 16:52:44 +0100 |
commit | 7222dcb2bb831b92c71e2a4db3d490525e78a4dd (patch) | |
tree | e887c933abe0d2793b501c4e5ab61811b7a0398b /gcc | |
parent | 1f1d9ed87d3e870f8e64ea28ba3e6bc898502255 (diff) | |
download | gcc-7222dcb2bb831b92c71e2a4db3d490525e78a4dd.zip gcc-7222dcb2bb831b92c71e2a4db3d490525e78a4dd.tar.gz gcc-7222dcb2bb831b92c71e2a4db3d490525e78a4dd.tar.bz2 |
All toplevel items must respect the prefix for their path
Name resolution is split into two parts, one for the toplevel canonical
paths and then a second to actually drill down into new scopes for blocks
for example.
Consider a rust program:
```rust
fn foo() -> bar { ... }
struct bar(..);
```
In that example the function foo references bar which is declared later on.
The compiler is partly query based in that we use ids to get away from
looking up things via strings as quickly as possible.
The toplevel scan follows the rust documentation over on:
This assigns canonical names for all toplevel items but ignore the details
like return types, or body.
So the name resolver ends up with:
::foo
::bar
Then we can drill down into foo and check the return type and see that
::bar is already defined.
The prefix is important for the case of modules for example. This should
be a toplevel scan within the same scope.
Addresses: #432
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/rust/resolve/rust-ast-resolve-toplevel.h | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h index fa3f8a5..6dbc8c9 100644 --- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h +++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h @@ -41,9 +41,9 @@ public: void visit (AST::TypeAlias &alias) override { + auto path = prefix.append (CanonicalPath (alias.get_new_type_name ())); resolver->get_type_scope ().insert ( - CanonicalPath (alias.get_new_type_name ()), alias.get_node_id (), - alias.get_locus (), false, + path, alias.get_node_id (), alias.get_locus (), false, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (alias.get_locus ()); r.add_range (locus); @@ -53,9 +53,9 @@ public: void visit (AST::TupleStruct &struct_decl) override { + auto path = prefix.append (CanonicalPath (struct_decl.get_identifier ())); resolver->get_type_scope ().insert ( - CanonicalPath (struct_decl.get_identifier ()), struct_decl.get_node_id (), - struct_decl.get_locus (), false, + path, struct_decl.get_node_id (), struct_decl.get_locus (), false, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (struct_decl.get_locus ()); r.add_range (locus); @@ -65,9 +65,9 @@ public: void visit (AST::StructStruct &struct_decl) override { + auto path = prefix.append (CanonicalPath (struct_decl.get_identifier ())); resolver->get_type_scope ().insert ( - CanonicalPath (struct_decl.get_identifier ()), struct_decl.get_node_id (), - struct_decl.get_locus (), false, + path, struct_decl.get_node_id (), struct_decl.get_locus (), false, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (struct_decl.get_locus ()); r.add_range (locus); @@ -77,9 +77,9 @@ public: void visit (AST::StaticItem &var) override { + auto path = prefix.append (CanonicalPath (var.get_identifier ())); resolver->get_name_scope ().insert ( - CanonicalPath (var.get_identifier ()), var.get_node_id (), - var.get_locus (), false, + path, var.get_node_id (), var.get_locus (), false, [&] (const CanonicalPath &, NodeId, Location locus) -> void { RichLocation r (var.get_locus ()); r.add_range (locus); |