aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-implitem.h82
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-item.h6
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-toplevel.h15
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-type.h14
4 files changed, 113 insertions, 4 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-implitem.h b/gcc/rust/resolve/rust-ast-resolve-implitem.h
new file mode 100644
index 0000000..74f2cdc
--- /dev/null
+++ b/gcc/rust/resolve/rust-ast-resolve-implitem.h
@@ -0,0 +1,82 @@
+// 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_RESOLVE_IMPLITEM_H
+#define RUST_AST_RESOLVE_IMPLITEM_H
+
+#include "rust-ast-resolve-base.h"
+#include "rust-ast-resolve-type.h"
+#include "rust-ast-full.h"
+
+namespace Rust {
+namespace Resolver {
+
+class ResolveToplevelImplItem : public ResolverBase
+{
+public:
+ static void go (AST::InherentImplItem *item, AST::Type *base)
+ {
+ ResolveToplevelImplItem resolver (base);
+ item->accept_vis (resolver);
+ };
+
+ void visit (AST::ConstantItem &constant)
+ {
+ std::string identifier
+ = base->as_string () + "::" + constant.get_identifier ();
+ resolver->get_name_scope ().insert (identifier, constant.get_node_id (),
+ constant.get_locus ());
+ resolver->insert_new_definition (constant.get_node_id (),
+ Definition{constant.get_node_id (),
+ constant.get_node_id ()});
+ }
+
+ void visit (AST::Function &function)
+ {
+ std::string identifier
+ = base->as_string () + "::" + function.get_function_name ();
+ resolver->get_name_scope ().insert (identifier, function.get_node_id (),
+ function.get_locus ());
+ resolver->insert_new_definition (function.get_node_id (),
+ Definition{function.get_node_id (),
+ function.get_node_id ()});
+ }
+
+ void visit (AST::Method &method)
+ {
+ std::string identifier
+ = base->as_string () + "::" + method.get_method_name ();
+ resolver->get_name_scope ().insert (identifier, method.get_node_id (),
+ method.get_locus ());
+ resolver->insert_new_definition (method.get_node_id (),
+ Definition{method.get_node_id (),
+ method.get_node_id ()});
+ }
+
+private:
+ ResolveToplevelImplItem (AST::Type *base)
+ : ResolverBase (UNKNOWN_NODEID), base (base)
+ {}
+
+ AST::Type *base;
+};
+
+} // namespace Resolver
+} // namespace Rust
+
+#endif // RUST_AST_RESOLVE_IMPLITEM_H
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h
index 0f45ba0..74b5f8d 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.h
+++ b/gcc/rust/resolve/rust-ast-resolve-item.h
@@ -117,6 +117,12 @@ public:
resolver->get_type_scope ().pop ();
}
+ void visit (AST::InherentImpl &impl_block)
+ {
+ for (auto &impl_item : impl_block.get_impl_items ())
+ impl_item->accept_vis (*this);
+ }
+
private:
ResolveItem () : ResolverBase (UNKNOWN_NODEID) {}
};
diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
index c3f5e4c..7ca8275 100644
--- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h
+++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
@@ -20,6 +20,8 @@
#define RUST_AST_RESOLVE_TOPLEVEL_H
#include "rust-ast-resolve-base.h"
+#include "rust-ast-resolve-type.h"
+#include "rust-ast-resolve-implitem.h"
#include "rust-ast-full.h"
namespace Rust {
@@ -34,8 +36,6 @@ public:
item->accept_vis (resolver);
};
- ~ResolveTopLevel () {}
-
void visit (AST::TupleStruct &struct_decl)
{
resolver->get_type_scope ().insert (struct_decl.get_identifier (),
@@ -88,6 +88,17 @@ public:
}
}
+ void visit (AST::InherentImpl &impl_block)
+ {
+ if (!ResolveType::go (impl_block.get_type ().get (),
+ impl_block.get_node_id ()))
+ return;
+
+ for (auto &impl_item : impl_block.get_impl_items ())
+ ResolveToplevelImplItem::go (impl_item.get (),
+ impl_block.get_type ().get ());
+ }
+
private:
ResolveTopLevel () : ResolverBase (UNKNOWN_NODEID) {}
};
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h
index b303ee9..258524b 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -28,14 +28,19 @@ namespace Resolver {
class ResolveType : public ResolverBase
{
public:
- static void go (AST::Type *type, NodeId parent)
+ static bool go (AST::Type *type, NodeId parent)
{
ResolveType resolver (parent);
type->accept_vis (resolver);
+ if (!resolver.ok)
+ rust_error_at (type->get_locus_slow (), "unresolved type");
+
+ return resolver.ok;
};
void visit (AST::BareFunctionType &fntype)
{
+ ok = true;
for (auto &param : fntype.get_function_params ())
ResolveType::go (param.get_type ().get (), fntype.get_node_id ());
@@ -45,6 +50,7 @@ public:
void visit (AST::TupleType &tuple)
{
+ ok = true;
if (tuple.is_unit_type ())
{
resolved_node = resolver->get_unit_type_node_id ();
@@ -65,6 +71,8 @@ public:
path.as_string ().c_str ());
return;
}
+
+ ok = true;
resolver->insert_resolved_type (path.get_node_id (), resolved_node);
resolver->insert_new_definition (path.get_node_id (),
Definition{path.get_node_id (), parent});
@@ -76,7 +84,9 @@ public:
}
private:
- ResolveType (NodeId parent) : ResolverBase (parent) {}
+ ResolveType (NodeId parent) : ResolverBase (parent), ok (false) {}
+
+ bool ok;
};
} // namespace Resolver