aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/ast/rust-ast.h26
-rw-r--r--gcc/rust/ast/rust-item.h35
-rw-r--r--gcc/rust/hir/rust-ast-lower-extern.h121
-rw-r--r--gcc/rust/hir/rust-ast-lower-item.h32
-rw-r--r--gcc/rust/hir/tree/rust-hir-full-test.cc5
-rw-r--r--gcc/rust/hir/tree/rust-hir-item.h68
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-implitem.h53
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-item.h49
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-toplevel.h8
-rw-r--r--gcc/rust/resolve/rust-ast-resolve.cc4
10 files changed, 345 insertions, 56 deletions
diff --git a/gcc/rust/ast/rust-ast.h b/gcc/rust/ast/rust-ast.h
index 3e3e185b..067e2f5b 100644
--- a/gcc/rust/ast/rust-ast.h
+++ b/gcc/rust/ast/rust-ast.h
@@ -1364,6 +1364,8 @@ public:
class ExternalItem
{
public:
+ ExternalItem () : node_id (Analysis::Mappings::get ()->get_next_node_id ()) {}
+
virtual ~ExternalItem () {}
// Unique pointer custom clone function
@@ -1379,9 +1381,13 @@ public:
virtual void mark_for_strip () = 0;
virtual bool is_marked_for_strip () const = 0;
+ NodeId get_node_id () const { return node_id; }
+
protected:
// Clone function implementation as pure virtual method
virtual ExternalItem *clone_external_item_impl () const = 0;
+
+ NodeId node_id;
};
/* Data structure to store the data used in macro invocations and macro
@@ -1513,36 +1519,36 @@ protected:
return new MacroInvocationSemi (*this);
}
- /* Use covariance to implement clone function as returning this object rather
- * than base */
+ /* Use covariance to implement clone function as returning this object
+ * rather than base */
MacroInvocationSemi *clone_item_impl () const final override
{
return clone_macro_invocation_semi_impl ();
}
- /* Use covariance to implement clone function as returning this object rather
- * than base */
+ /* Use covariance to implement clone function as returning this object
+ * rather than base */
MacroInvocationSemi *clone_inherent_impl_item_impl () const final override
{
return clone_macro_invocation_semi_impl ();
}
- /* Use covariance to implement clone function as returning this object rather
- * than base */
+ /* Use covariance to implement clone function as returning this object
+ * rather than base */
MacroInvocationSemi *clone_trait_impl_item_impl () const final override
{
return clone_macro_invocation_semi_impl ();
}
- /* Use covariance to implement clone function as returning this object rather
- * than base */
+ /* Use covariance to implement clone function as returning this object
+ * rather than base */
MacroInvocationSemi *clone_trait_item_impl () const final override
{
return clone_macro_invocation_semi_impl ();
}
- /* Use covariance to implement clone function as returning this object rather
- * than base */
+ /* Use covariance to implement clone function as returning this object
+ * rather than base */
MacroInvocationSemi *clone_external_item_impl () const final override
{
return clone_macro_invocation_semi_impl ();
diff --git a/gcc/rust/ast/rust-item.h b/gcc/rust/ast/rust-item.h
index 30cab0e..6d29c5b 100644
--- a/gcc/rust/ast/rust-item.h
+++ b/gcc/rust/ast/rust-item.h
@@ -3910,9 +3910,9 @@ public:
ExternalStaticItem (Identifier item_name, std::unique_ptr<Type> item_type,
bool is_mut, Visibility vis,
std::vector<Attribute> outer_attrs, Location locus)
- : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)),
- item_name (std::move (item_name)), locus (locus), has_mut (is_mut),
- item_type (std::move (item_type))
+ : ExternalItem (), outer_attrs (std::move (outer_attrs)),
+ visibility (std::move (vis)), item_name (std::move (item_name)),
+ locus (locus), has_mut (is_mut), item_type (std::move (item_type))
{}
// Copy constructor
@@ -3920,6 +3920,7 @@ public:
: outer_attrs (other.outer_attrs), visibility (other.visibility),
item_name (other.item_name), locus (other.locus), has_mut (other.has_mut)
{
+ node_id = other.node_id;
// guard to prevent null dereference (only required if error state)
if (other.item_type != nullptr)
item_type = other.item_type->clone_type ();
@@ -3928,6 +3929,7 @@ public:
// Overloaded assignment operator to clone
ExternalStaticItem &operator= (ExternalStaticItem const &other)
{
+ node_id = other.node_id;
outer_attrs = other.outer_attrs;
visibility = other.visibility;
item_name = other.item_name;
@@ -3974,6 +3976,10 @@ public:
return item_type;
}
+ Identifier get_identifier () const { return item_name; }
+
+ bool is_mut () const { return has_mut; }
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -3997,6 +4003,8 @@ private:
// seemingly new since writing this node
std::vector<Attribute> outer_attrs;
+ NodeId node_id;
+
public:
/* Returns whether the named function parameter has a name (i.e. name is not
* '_'). */
@@ -4011,6 +4019,8 @@ public:
return param_type == nullptr;
}
+ std::string get_name () const { return name; }
+
// Creates an error state named function parameter.
static NamedFunctionParam create_error ()
{
@@ -4020,13 +4030,15 @@ public:
NamedFunctionParam (std::string name, std::unique_ptr<Type> param_type,
std::vector<Attribute> outer_attrs)
: name (std::move (name)), param_type (std::move (param_type)),
- outer_attrs (std::move (outer_attrs))
+ outer_attrs (std::move (outer_attrs)),
+ node_id (Analysis::Mappings::get ()->get_next_node_id ())
{}
// Copy constructor
NamedFunctionParam (NamedFunctionParam const &other)
: name (other.name), outer_attrs (other.outer_attrs)
{
+ node_id = other.node_id;
// guard to prevent null dereference (only required if error state)
if (other.param_type != nullptr)
param_type = other.param_type->clone_type ();
@@ -4037,6 +4049,7 @@ public:
// Overloaded assignment operator to clone
NamedFunctionParam &operator= (NamedFunctionParam const &other)
{
+ node_id = other.node_id;
name = other.name;
// has_name = other.has_name;
outer_attrs = other.outer_attrs;
@@ -4070,6 +4083,8 @@ public:
rust_assert (param_type != nullptr);
return param_type;
}
+
+ NodeId get_node_id () const { return node_id; }
};
// A function item used in an extern block
@@ -4133,9 +4148,9 @@ public:
std::vector<NamedFunctionParam> function_params, bool has_variadics,
std::vector<Attribute> variadic_outer_attrs, Visibility vis,
std::vector<Attribute> outer_attrs, Location locus)
- : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)),
- item_name (std::move (item_name)), locus (locus),
- generic_params (std::move (generic_params)),
+ : ExternalItem (), outer_attrs (std::move (outer_attrs)),
+ visibility (std::move (vis)), item_name (std::move (item_name)),
+ locus (locus), generic_params (std::move (generic_params)),
return_type (std::move (return_type)),
where_clause (std::move (where_clause)),
function_params (std::move (function_params)),
@@ -4155,6 +4170,7 @@ public:
has_variadics (other.has_variadics),
variadic_outer_attrs (other.variadic_outer_attrs)
{
+ node_id = other.node_id;
// guard to prevent null pointer dereference
if (other.return_type != nullptr)
return_type = other.return_type->clone_type ();
@@ -4175,6 +4191,7 @@ public:
function_params = other.function_params;
has_variadics = other.has_variadics;
variadic_outer_attrs = other.variadic_outer_attrs;
+ node_id = other.node_id;
// guard to prevent null pointer dereference
if (other.return_type != nullptr)
@@ -4237,6 +4254,8 @@ public:
return return_type;
}
+ Identifier get_identifier () const { return item_name; };
+
protected:
/* Use covariance to implement clone function as returning this object
* rather than base */
@@ -4275,6 +4294,8 @@ public:
// Returns whether extern block has ABI name.
bool has_abi () const { return !abi.empty (); }
+ std::string get_abi () const { return abi; }
+
ExternBlock (std::string abi,
std::vector<std::unique_ptr<ExternalItem> > extern_items,
Visibility vis, std::vector<Attribute> inner_attrs,
diff --git a/gcc/rust/hir/rust-ast-lower-extern.h b/gcc/rust/hir/rust-ast-lower-extern.h
new file mode 100644
index 0000000..1cc0c8e
--- /dev/null
+++ b/gcc/rust/hir/rust-ast-lower-extern.h
@@ -0,0 +1,121 @@
+// Copyright (C) 2020 Free Software Foundation, Inc.
+
+// This file is part of GCC.
+
+// GCC is free software; you can redistribute it and/or modify it under
+// the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3, or (at your option) any later
+// version.
+
+// GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+// WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+// for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with GCC; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#ifndef RUST_AST_LOWER_EXTERN_ITEM
+#define RUST_AST_LOWER_EXTERN_ITEM
+
+#include "rust-ast-lower-base.h"
+#include "rust-ast-lower-type.h"
+
+namespace Rust {
+namespace HIR {
+
+class ASTLoweringExternItem : public ASTLoweringBase
+{
+ using Rust::HIR::ASTLoweringBase::visit;
+
+public:
+ static HIR::ExternalItem *translate (AST::ExternalItem *item)
+ {
+ ASTLoweringExternItem resolver;
+ item->accept_vis (resolver);
+ return resolver.translated;
+ }
+
+ void visit (AST::ExternalStaticItem &item) override
+ {
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+ HIR::Type *static_type
+ = ASTLoweringType::translate (item.get_type ().get ());
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, item.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (crate_num));
+ mappings->insert_location (crate_num, mapping.get_hirid (),
+ item.get_locus ());
+
+ HIR::ExternalStaticItem *static_item
+ = new HIR::ExternalStaticItem (mapping, item.get_identifier (),
+ std::unique_ptr<HIR::Type> (static_type),
+ item.is_mut (), std::move (vis),
+ item.get_outer_attrs (),
+ item.get_locus ());
+
+ translated = static_item;
+ }
+
+ void visit (AST::ExternalFunctionItem &function) override
+ {
+ std::vector<std::unique_ptr<HIR::WhereClauseItem> > where_clause_items;
+ HIR::WhereClause where_clause (std::move (where_clause_items));
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+
+ std::vector<std::unique_ptr<HIR::GenericParam> > generic_params;
+ if (function.has_generics ())
+ generic_params = lower_generic_params (function.get_generic_params ());
+
+ HIR::Type *return_type
+ = function.has_return_type ()
+ ? ASTLoweringType::translate (function.get_return_type ().get ())
+ : nullptr;
+
+ std::vector<HIR::NamedFunctionParam> function_params;
+ for (auto &param : function.get_function_params ())
+ {
+ HIR::Type *param_type
+ = ASTLoweringType::translate (param.get_type ().get ());
+ Identifier param_name = param.get_name ();
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, param.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (
+ crate_num));
+
+ function_params.push_back (
+ HIR::NamedFunctionParam (mapping, param_name,
+ std::unique_ptr<HIR::Type> (param_type)));
+ }
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, function.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (crate_num));
+ mappings->insert_location (crate_num, mapping.get_hirid (),
+ function.get_locus ());
+
+ HIR::ExternalFunctionItem *function_item = new HIR::ExternalFunctionItem (
+ mapping, function.get_identifier (), std::move (generic_params),
+ std::unique_ptr<HIR::Type> (return_type), std::move (where_clause),
+ std::move (function_params), function.is_variadic (), std::move (vis),
+ function.get_outer_attrs (), function.get_locus ());
+
+ translated = function_item;
+ }
+
+private:
+ ASTLoweringExternItem () : translated (nullptr) {}
+
+ HIR::ExternalItem *translated;
+};
+
+} // namespace HIR
+} // namespace Rust
+
+#endif // RUST_AST_LOWER_ITEM
diff --git a/gcc/rust/hir/rust-ast-lower-item.h b/gcc/rust/hir/rust-ast-lower-item.h
index 5ba5918..e53b739 100644
--- a/gcc/rust/hir/rust-ast-lower-item.h
+++ b/gcc/rust/hir/rust-ast-lower-item.h
@@ -28,6 +28,7 @@
#include "rust-ast-lower-expr.h"
#include "rust-ast-lower-pattern.h"
#include "rust-ast-lower-block.h"
+#include "rust-ast-lower-extern.h"
namespace Rust {
namespace HIR {
@@ -553,6 +554,37 @@ public:
}
}
+ void visit (AST::ExternBlock &extern_block) override
+ {
+ HIR::Visibility vis = HIR::Visibility::create_public ();
+
+ std::vector<std::unique_ptr<HIR::ExternalItem> > extern_items;
+ for (auto &item : extern_block.get_extern_items ())
+ {
+ HIR::ExternalItem *lowered
+ = ASTLoweringExternItem::translate (item.get ());
+ extern_items.push_back (std::unique_ptr<HIR::ExternalItem> (lowered));
+ }
+
+ auto crate_num = mappings->get_current_crate ();
+ Analysis::NodeMapping mapping (crate_num, extern_block.get_node_id (),
+ mappings->get_next_hir_id (crate_num),
+ mappings->get_next_localdef_id (crate_num));
+
+ mappings->insert_defid_mapping (mapping.get_defid (), translated);
+ mappings->insert_location (crate_num, mapping.get_hirid (),
+ extern_block.get_locus ());
+
+ HIR::ExternBlock *hir_extern_block
+ = new HIR::ExternBlock (mapping, extern_block.get_abi (),
+ std::move (extern_items), std::move (vis),
+ extern_block.get_inner_attrs (),
+ extern_block.get_outer_attrs (),
+ extern_block.get_locus ());
+
+ translated = hir_extern_block;
+ }
+
private:
ASTLoweringItem () : translated (nullptr) {}
diff --git a/gcc/rust/hir/tree/rust-hir-full-test.cc b/gcc/rust/hir/tree/rust-hir-full-test.cc
index 86664d3..d61d060 100644
--- a/gcc/rust/hir/tree/rust-hir-full-test.cc
+++ b/gcc/rust/hir/tree/rust-hir-full-test.cc
@@ -3399,8 +3399,9 @@ ExternalFunctionItem::as_string () const
}
}
- // add type on new line
- str += "\n (return) Type: " + return_type->as_string ();
+ // add type on new line)
+ str += "\n (return) Type: "
+ + (has_return_type () ? return_type->as_string () : "()");
// where clause
str += "\n Where clause: ";
diff --git a/gcc/rust/hir/tree/rust-hir-item.h b/gcc/rust/hir/tree/rust-hir-item.h
index e7e110f..6d53711 100644
--- a/gcc/rust/hir/tree/rust-hir-item.h
+++ b/gcc/rust/hir/tree/rust-hir-item.h
@@ -2684,6 +2684,7 @@ protected:
// Abstract base class for an item used inside an extern block
class ExternalItem
{
+ Analysis::NodeMapping mappings;
AST::AttrVec outer_attrs;
Visibility visibility;
Identifier item_name;
@@ -2710,22 +2711,27 @@ public:
virtual void accept_vis (HIRVisitor &vis) = 0;
+ Analysis::NodeMapping get_mappings () const { return mappings; }
+
protected:
- ExternalItem (Identifier item_name, Visibility vis, AST::AttrVec outer_attrs,
- Location locus)
- : outer_attrs (std::move (outer_attrs)), visibility (std::move (vis)),
- item_name (std::move (item_name)), locus (locus)
+ ExternalItem (Analysis::NodeMapping mappings, Identifier item_name,
+ Visibility vis, AST::AttrVec outer_attrs, Location locus)
+ : mappings (mappings), outer_attrs (std::move (outer_attrs)),
+ visibility (std::move (vis)), item_name (std::move (item_name)),
+ locus (locus)
{}
// Copy constructor
ExternalItem (ExternalItem const &other)
- : outer_attrs (other.outer_attrs), visibility (other.visibility),
- item_name (other.item_name), locus (other.locus)
+ : mappings (other.mappings), outer_attrs (other.outer_attrs),
+ visibility (other.visibility), item_name (other.item_name),
+ locus (other.locus)
{}
// Overloaded assignment operator to clone
ExternalItem &operator= (ExternalItem const &other)
{
+ mappings = other.mappings;
item_name = other.item_name;
visibility = other.visibility;
outer_attrs = other.outer_attrs;
@@ -2752,11 +2758,11 @@ class ExternalStaticItem : public ExternalItem
std::unique_ptr<Type> item_type;
public:
- ExternalStaticItem (Identifier item_name, std::unique_ptr<Type> item_type,
- bool is_mut, Visibility vis, AST::AttrVec outer_attrs,
- Location locus)
- : ExternalItem (std::move (item_name), std::move (vis),
- std::move (outer_attrs), locus),
+ ExternalStaticItem (Analysis::NodeMapping mappings, Identifier item_name,
+ std::unique_ptr<Type> item_type, bool is_mut,
+ Visibility vis, AST::AttrVec outer_attrs, Location locus)
+ : ExternalItem (std::move (mappings), std::move (item_name),
+ std::move (vis), std::move (outer_attrs), locus),
has_mut (is_mut), item_type (std::move (item_type))
{}
@@ -2797,38 +2803,23 @@ protected:
struct NamedFunctionParam
{
private:
- // bool has_name; // otherwise is _
- Identifier name; // TODO: handle wildcard in identifier?
-
+ Identifier name;
std::unique_ptr<Type> param_type;
-
- // TODO: should this store location data?
+ Analysis::NodeMapping mappings;
public:
- // Returns whether the named function parameter has a name (i.e. name is not
- // '_').
bool has_name () const { return name != "_"; }
- // Returns whether the named function parameter is in an error state.
- bool is_error () const
- {
- // also if identifier is "" but that is probably more costly to compute
- return param_type == nullptr;
- }
-
- // Creates an error state named function parameter.
- static NamedFunctionParam create_error ()
- {
- return NamedFunctionParam ("", nullptr);
- }
-
- NamedFunctionParam (Identifier name, std::unique_ptr<Type> param_type)
- : name (std::move (name)), param_type (std::move (param_type))
+ NamedFunctionParam (Analysis::NodeMapping mappings, Identifier name,
+ std::unique_ptr<Type> param_type)
+ : name (std::move (name)), param_type (std::move (param_type)),
+ mappings (std::move (mappings))
{}
// Copy constructor
NamedFunctionParam (NamedFunctionParam const &other)
- : name (other.name), param_type (other.param_type->clone_type ())
+ : name (other.name), param_type (other.param_type->clone_type ()),
+ mappings (other.mappings)
{}
~NamedFunctionParam () = default;
@@ -2836,6 +2827,7 @@ public:
// Overloaded assignment operator to clone
NamedFunctionParam &operator= (NamedFunctionParam const &other)
{
+ mappings = other.mappings;
name = other.name;
param_type = other.param_type->clone_type ();
// has_name = other.has_name;
@@ -2878,13 +2870,13 @@ public:
bool has_where_clause () const { return !where_clause.is_empty (); }
ExternalFunctionItem (
- Identifier item_name,
+ Analysis::NodeMapping mappings, Identifier item_name,
std::vector<std::unique_ptr<GenericParam> > generic_params,
std::unique_ptr<Type> return_type, WhereClause where_clause,
std::vector<NamedFunctionParam> function_params, bool has_variadics,
Visibility vis, AST::AttrVec outer_attrs, Location locus)
- : ExternalItem (std::move (item_name), std::move (vis),
- std::move (outer_attrs), locus),
+ : ExternalItem (std::move (mappings), std::move (item_name),
+ std::move (vis), std::move (outer_attrs), locus),
generic_params (std::move (generic_params)),
return_type (std::move (return_type)),
where_clause (std::move (where_clause)),
@@ -2963,6 +2955,8 @@ public:
// Returns whether extern block has ABI name.
bool has_abi () const { return !abi.empty (); }
+ std::string get_abi () const { return abi; }
+
ExternBlock (Analysis::NodeMapping mappings, std::string abi,
std::vector<std::unique_ptr<ExternalItem> > extern_items,
Visibility vis, AST::AttrVec inner_attrs,
diff --git a/gcc/rust/resolve/rust-ast-resolve-implitem.h b/gcc/rust/resolve/rust-ast-resolve-implitem.h
index 2b3a09a..6437be2 100644
--- a/gcc/rust/resolve/rust-ast-resolve-implitem.h
+++ b/gcc/rust/resolve/rust-ast-resolve-implitem.h
@@ -201,6 +201,59 @@ private:
const CanonicalPath &prefix;
};
+class ResolveToplevelExternItem : public ResolverBase
+{
+ using Rust::Resolver::ResolverBase::visit;
+
+public:
+ static void go (AST::ExternalItem *item,
+ const CanonicalPath &prefix = CanonicalPath::create_empty ())
+ {
+ ResolveToplevelExternItem resolver (prefix);
+ item->accept_vis (resolver);
+ };
+
+ void visit (AST::ExternalFunctionItem &function) override
+ {
+ auto path
+ = prefix.append (CanonicalPath::new_seg (function.get_node_id (),
+ function.get_identifier ()));
+ resolver->get_name_scope ().insert (
+ path, function.get_node_id (), function.get_locus (), false,
+ [&] (const CanonicalPath &, NodeId, Location locus) -> void {
+ RichLocation r (function.get_locus ());
+ r.add_range (locus);
+ rust_error_at (r, "redefined multiple times");
+ });
+ resolver->insert_new_definition (function.get_node_id (),
+ Definition{function.get_node_id (),
+ function.get_node_id ()});
+ }
+
+ void visit (AST::ExternalStaticItem &item) override
+ {
+ auto path = prefix.append (
+ CanonicalPath::new_seg (item.get_node_id (), item.get_identifier ()));
+ resolver->get_name_scope ().insert (
+ path, item.get_node_id (), item.get_locus (), false,
+ [&] (const CanonicalPath &, NodeId, Location locus) -> void {
+ RichLocation r (item.get_locus ());
+ r.add_range (locus);
+ rust_error_at (r, "redefined multiple times");
+ });
+ resolver->insert_new_definition (item.get_node_id (),
+ Definition{item.get_node_id (),
+ item.get_node_id ()});
+ }
+
+private:
+ ResolveToplevelExternItem (const CanonicalPath &prefix)
+ : ResolverBase (UNKNOWN_NODEID), prefix (prefix)
+ {}
+
+ const CanonicalPath &prefix;
+};
+
} // namespace Resolver
} // namespace Rust
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h
index 0714f5d..ccf3872 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.h
+++ b/gcc/rust/resolve/rust-ast-resolve-item.h
@@ -521,10 +521,19 @@ public:
resolver->get_name_scope ().pop ();
}
+ void visit (AST::ExternBlock &extern_block) override
+ {
+ for (auto &item : extern_block.get_extern_items ())
+ {
+ resolve_extern_item (item.get ());
+ }
+ }
+
protected:
void resolve_impl_item (AST::TraitImplItem *item, const CanonicalPath &self);
void resolve_impl_item (AST::InherentImplItem *item,
const CanonicalPath &self);
+ void resolve_extern_item (AST::ExternalItem *item);
ResolveItem () : ResolverBase (UNKNOWN_NODEID) {}
};
@@ -572,6 +581,46 @@ private:
const CanonicalPath &self;
};
+class ResolveExternItem : public ResolverBase
+{
+ using Rust::Resolver::ResolverBase::visit;
+
+public:
+ static void go (AST::ExternalItem *item)
+ {
+ ResolveExternItem resolver;
+ item->accept_vis (resolver);
+ };
+
+ void visit (AST::ExternalFunctionItem &function) override
+ {
+ if (function.has_generics ())
+ {
+ for (auto &generic : function.get_generic_params ())
+ ResolveGenericParam::go (generic.get (), function.get_node_id ());
+ }
+
+ if (function.has_return_type ())
+ ResolveType::go (function.get_return_type ().get (),
+ function.get_node_id ());
+
+ // we make a new scope so the names of parameters are resolved and shadowed
+ // correctly
+ for (auto &param : function.get_function_params ())
+ {
+ ResolveType::go (param.get_type ().get (), param.get_node_id ());
+ }
+ }
+
+ void visit (AST::ExternalStaticItem &item) override
+ {
+ ResolveType::go (item.get_type ().get (), item.get_node_id ());
+ }
+
+private:
+ ResolveExternItem () : ResolverBase (UNKNOWN_NODEID) {}
+}; // namespace Resolver
+
} // namespace Resolver
} // namespace Rust
diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
index 9abbb18..a042f5c 100644
--- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h
+++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
@@ -191,6 +191,14 @@ public:
ResolveTopLevelTraitItems::go (item.get (), path);
}
+ void visit (AST::ExternBlock &extern_block) override
+ {
+ for (auto &item : extern_block.get_extern_items ())
+ {
+ ResolveToplevelExternItem::go (item.get (), prefix);
+ }
+ }
+
private:
ResolveTopLevel (const CanonicalPath &prefix)
: ResolverBase (UNKNOWN_NODEID), prefix (prefix)
diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc
index 18047db..9cc833f 100644
--- a/gcc/rust/resolve/rust-ast-resolve.cc
+++ b/gcc/rust/resolve/rust-ast-resolve.cc
@@ -635,5 +635,9 @@ ResolveItem::resolve_impl_item (AST::InherentImplItem *item,
ResolveImplItems::go (item, self);
}
+void
+ResolveItem::resolve_extern_item (AST::ExternalItem *item)
+{}
+
} // namespace Resolver
} // namespace Rust