aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-06-28 10:38:09 +0100
committerPhilip Herron <philip.herron@embecosm.com>2022-06-28 10:38:09 +0100
commitd5ffe1cdb023f502c09fbc64744f4cf9ad2be90d (patch)
treee74a42c6d48e74ab286d674779aa9030ebe7b583 /gcc
parentda2dda70637ecd42a9ba3fba976a5f280e880852 (diff)
downloadgcc-d5ffe1cdb023f502c09fbc64744f4cf9ad2be90d.zip
gcc-d5ffe1cdb023f502c09fbc64744f4cf9ad2be90d.tar.gz
gcc-d5ffe1cdb023f502c09fbc64744f4cf9ad2be90d.tar.bz2
refactor name resolution of generic arguments into ResolveType class
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-expr.cc2
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-path.cc18
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-type.cc16
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-type.h46
4 files changed, 25 insertions, 57 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.cc b/gcc/rust/resolve/rust-ast-resolve-expr.cc
index e9127e6..f0ad567 100644
--- a/gcc/rust/resolve/rust-ast-resolve-expr.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-expr.cc
@@ -87,7 +87,7 @@ ResolveExpr::visit (AST::MethodCallExpr &expr)
if (expr.get_method_name ().has_generic_args ())
{
AST::GenericArgs &args = expr.get_method_name ().get_generic_args ();
- ResolveTypeToCanonicalPath::type_resolve_generic_args (args);
+ ResolveType::type_resolve_generic_args (args);
}
auto const &in_params = expr.get_params ();
diff --git a/gcc/rust/resolve/rust-ast-resolve-path.cc b/gcc/rust/resolve/rust-ast-resolve-path.cc
index 8135d4d..a6940d4 100644
--- a/gcc/rust/resolve/rust-ast-resolve-path.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-path.cc
@@ -88,14 +88,7 @@ ResolvePath::resolve_path (AST::PathInExpression *expr)
// resolve any generic args
if (segment.has_generic_args ())
{
- bool ok = ResolveTypeToCanonicalPath::type_resolve_generic_args (
- segment.get_generic_args ());
- if (!ok)
- {
- rust_error_at (segment.get_locus (),
- "failed to resolve generic arguments");
- return;
- }
+ ResolveType::type_resolve_generic_args (segment.get_generic_args ());
}
// logic is awkward here there are a few cases
@@ -235,14 +228,7 @@ ResolvePath::resolve_path (AST::QualifiedPathInExpression *expr)
// generic arguments used
if (segment.has_generic_args ())
{
- bool ok = ResolveTypeToCanonicalPath::type_resolve_generic_args (
- segment.get_generic_args ());
- if (!ok)
- {
- rust_error_at (segment.get_locus (),
- "failed to resolve generic arguments");
- return;
- }
+ ResolveType::type_resolve_generic_args (segment.get_generic_args ());
}
}
}
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.cc b/gcc/rust/resolve/rust-ast-resolve-type.cc
index 050f3b9..553008d 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.cc
+++ b/gcc/rust/resolve/rust-ast-resolve-type.cc
@@ -44,19 +44,6 @@ ResolveTypeToCanonicalPath::canonicalize_generic_args (AST::GenericArgs &args)
return "<" + buf + ">";
}
-bool
-ResolveTypeToCanonicalPath::type_resolve_generic_args (AST::GenericArgs &args)
-{
- for (auto &gt : args.get_type_args ())
- {
- ResolveType::go (gt.get (), UNKNOWN_NODEID);
- // FIXME error handling here for inference variable since they do not have
- // a node to resolve to
- // if (resolved == UNKNOWN_NODEID) return false;
- }
- return true;
-}
-
void
ResolveTypeToCanonicalPath::visit (AST::TypePathSegmentGeneric &seg)
{
@@ -79,8 +66,7 @@ ResolveTypeToCanonicalPath::visit (AST::TypePathSegmentGeneric &seg)
if (type_resolve_generic_args_flag)
{
- bool ok = type_resolve_generic_args (seg.get_generic_args ());
- failure_flag = !ok;
+ ResolveType::type_resolve_generic_args (seg.get_generic_args ());
}
if (include_generic_args_flag)
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h
index b8ad6d1..b16799f 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -64,8 +64,6 @@ public:
static std::string canonicalize_generic_args (AST::GenericArgs &args);
- static bool type_resolve_generic_args (AST::GenericArgs &args);
-
protected:
ResolveTypeToCanonicalPath (bool include_generic_args,
bool type_resolve_generic_args)
@@ -81,29 +79,6 @@ protected:
bool failure_flag;
};
-class ResolvePathSegmentToCanonicalPath
-{
-public:
- static CanonicalPath resolve (AST::PathExprSegment &seg)
- {
- if (!seg.has_generic_args ())
- return CanonicalPath::new_seg (seg.get_node_id (),
- seg.get_ident_segment ().as_string ());
-
- bool ok = ResolveTypeToCanonicalPath::type_resolve_generic_args (
- seg.get_generic_args ());
- if (!ok)
- {
- rust_error_at (seg.get_locus (),
- "failed to resolve all generic arguments");
- return CanonicalPath::create_empty ();
- }
-
- return CanonicalPath::new_seg (seg.get_node_id (),
- seg.get_ident_segment ().as_string ());
- }
-};
-
class TraitImplProjection
{
public:
@@ -143,6 +118,12 @@ public:
return resolver.resolved_node;
}
+ static void type_resolve_generic_args (AST::GenericArgs &args)
+ {
+ for (auto &gt : args.get_type_args ())
+ ResolveType::go (gt.get ());
+ }
+
void visit (AST::BareFunctionType &fntype) override
{
for (auto &param : fntype.get_function_params ())
@@ -213,6 +194,21 @@ private:
CanonicalPath *canonical_path;
};
+class ResolvePathSegmentToCanonicalPath
+{
+public:
+ static CanonicalPath resolve (AST::PathExprSegment &seg)
+ {
+ if (!seg.has_generic_args ())
+ return CanonicalPath::new_seg (seg.get_node_id (),
+ seg.get_ident_segment ().as_string ());
+
+ ResolveType::type_resolve_generic_args (seg.get_generic_args ());
+ return CanonicalPath::new_seg (seg.get_node_id (),
+ seg.get_ident_segment ().as_string ());
+ }
+};
+
class ResolveTypeBound : public ResolverBase
{
using Rust::Resolver::ResolverBase::visit;