aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2021-07-08 15:44:59 +0100
committerPhilip Herron <philip.herron@embecosm.com>2021-07-10 21:32:44 +0100
commit213bc11225fcbb57e2fa6d949917bd2cf44e2477 (patch)
tree8c28309b0963c5dc9f1a5c8738f3bf4c16de7f31 /gcc/rust/resolve
parent8bfeef998ff340fef37f07e1a7a0366e73296380 (diff)
downloadgcc-213bc11225fcbb57e2fa6d949917bd2cf44e2477.zip
gcc-213bc11225fcbb57e2fa6d949917bd2cf44e2477.tar.gz
gcc-213bc11225fcbb57e2fa6d949917bd2cf44e2477.tar.bz2
canonical path enhancements
This refactors the canonical path to enforce the segment ids.
Diffstat (limited to 'gcc/rust/resolve')
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-expr.h28
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-implitem.h4
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-item.h19
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-pattern.h10
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-stmt.h6
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-toplevel.h19
-rw-r--r--gcc/rust/resolve/rust-ast-resolve-type.h68
-rw-r--r--gcc/rust/resolve/rust-ast-resolve.cc48
-rw-r--r--gcc/rust/resolve/rust-ast-verify-assignee.h3
-rw-r--r--gcc/rust/resolve/rust-name-resolver.h39
10 files changed, 142 insertions, 102 deletions
diff --git a/gcc/rust/resolve/rust-ast-resolve-expr.h b/gcc/rust/resolve/rust-ast-resolve-expr.h
index d6f5fcd..ec89f6c 100644
--- a/gcc/rust/resolve/rust-ast-resolve-expr.h
+++ b/gcc/rust/resolve/rust-ast-resolve-expr.h
@@ -118,7 +118,8 @@ public:
void visit (AST::IdentifierExpr &expr) override
{
if (resolver->get_name_scope ().lookup (
- CanonicalPath::new_seg (expr.as_string ()), &resolved_node))
+ CanonicalPath::new_seg (expr.get_node_id (), expr.as_string ()),
+ &resolved_node))
{
resolver->insert_resolved_name (expr.get_node_id (), resolved_node);
resolver->insert_new_definition (expr.get_node_id (),
@@ -126,7 +127,8 @@ public:
parent});
}
else if (resolver->get_type_scope ().lookup (
- CanonicalPath::new_seg (expr.as_string ()), &resolved_node))
+ CanonicalPath::new_seg (expr.get_node_id (), expr.as_string ()),
+ &resolved_node))
{
resolver->insert_resolved_type (expr.get_node_id (), resolved_node);
resolver->insert_new_definition (expr.get_node_id (),
@@ -272,8 +274,8 @@ public:
auto label_name = label.get_lifetime ().get_lifetime_name ();
auto label_lifetime_node_id = label.get_lifetime ().get_node_id ();
resolver->get_label_scope ().insert (
- CanonicalPath::new_seg (label_name), label_lifetime_node_id,
- label.get_locus (), false,
+ CanonicalPath::new_seg (expr.get_node_id (), label_name),
+ label_lifetime_node_id, label.get_locus (), false,
[&] (const CanonicalPath &, NodeId, Location locus) -> void {
rust_error_at (label.get_locus (),
"label redefined multiple times");
@@ -299,9 +301,10 @@ public:
}
NodeId resolved_node = UNKNOWN_NODEID;
- if (!resolver->get_label_scope ().lookup (CanonicalPath::new_seg (
- label.get_lifetime_name ()),
- &resolved_node))
+ if (!resolver->get_label_scope ().lookup (
+ CanonicalPath::new_seg (label.get_node_id (),
+ label.get_lifetime_name ()),
+ &resolved_node))
{
rust_error_at (expr.get_label ().get_locus (),
"failed to resolve label");
@@ -330,8 +333,8 @@ public:
auto label_name = label.get_lifetime ().get_lifetime_name ();
auto label_lifetime_node_id = label.get_lifetime ().get_node_id ();
resolver->get_label_scope ().insert (
- CanonicalPath::new_seg (label_name), label_lifetime_node_id,
- label.get_locus (), false,
+ CanonicalPath::new_seg (label.get_node_id (), label_name),
+ label_lifetime_node_id, label.get_locus (), false,
[&] (const CanonicalPath &, NodeId, Location locus) -> void {
rust_error_at (label.get_locus (),
"label redefined multiple times");
@@ -358,9 +361,10 @@ public:
}
NodeId resolved_node = UNKNOWN_NODEID;
- if (!resolver->get_label_scope ().lookup (CanonicalPath::new_seg (
- label.get_lifetime_name ()),
- &resolved_node))
+ if (!resolver->get_label_scope ().lookup (
+ CanonicalPath::new_seg (label.get_node_id (),
+ label.get_lifetime_name ()),
+ &resolved_node))
{
rust_error_at (expr.get_label ().get_locus (),
"failed to resolve label");
diff --git a/gcc/rust/resolve/rust-ast-resolve-implitem.h b/gcc/rust/resolve/rust-ast-resolve-implitem.h
index b622dcb..2b3a09a 100644
--- a/gcc/rust/resolve/rust-ast-resolve-implitem.h
+++ b/gcc/rust/resolve/rust-ast-resolve-implitem.h
@@ -45,8 +45,8 @@ public:
void visit (AST::TypeAlias &type) override
{
- auto path
- = prefix.append (CanonicalPath::new_seg (type.get_new_type_name ()));
+ auto path = prefix.append (
+ CanonicalPath::new_seg (type.get_node_id (), type.get_new_type_name ()));
resolver->get_type_scope ().insert (
path, type.get_node_id (), type.get_locus (), false,
[&] (const CanonicalPath &, NodeId, Location locus) -> void {
diff --git a/gcc/rust/resolve/rust-ast-resolve-item.h b/gcc/rust/resolve/rust-ast-resolve-item.h
index 09d6430..ad817dc 100644
--- a/gcc/rust/resolve/rust-ast-resolve-item.h
+++ b/gcc/rust/resolve/rust-ast-resolve-item.h
@@ -184,17 +184,23 @@ public:
impl_block.get_node_id (),
canonicalize_type_with_generics);
if (resolved_node == UNKNOWN_NODEID)
- return;
+ {
+ resolver->get_type_scope ().pop ();
+ return;
+ }
+
+ auto Self
+ = CanonicalPath::get_big_self (impl_block.get_type ()->get_node_id ());
resolver->get_type_scope ().insert (
- CanonicalPath::get_big_self (), impl_block.get_type ()->get_node_id (),
+ Self, impl_block.get_type ()->get_node_id (),
impl_block.get_type ()->get_locus_slow ());
for (auto &impl_item : impl_block.get_impl_items ())
impl_item->accept_vis (*this);
resolver->get_type_scope ().peek ()->clear_name (
- CanonicalPath::get_big_self (), impl_block.get_type ()->get_node_id ());
+ Self, impl_block.get_type ()->get_node_id ());
resolver->get_type_scope ().pop ();
}
@@ -293,15 +299,18 @@ public:
return;
}
+ auto Self
+ = CanonicalPath::get_big_self (impl_block.get_type ()->get_node_id ());
+
resolver->get_type_scope ().insert (
- CanonicalPath::get_big_self (), impl_block.get_type ()->get_node_id (),
+ Self, impl_block.get_type ()->get_node_id (),
impl_block.get_type ()->get_locus_slow ());
for (auto &impl_item : impl_block.get_impl_items ())
impl_item->accept_vis (*this);
resolver->get_type_scope ().peek ()->clear_name (
- CanonicalPath::get_big_self (), impl_block.get_type ()->get_node_id ());
+ Self, impl_block.get_type ()->get_node_id ());
resolver->get_type_scope ().pop ();
}
diff --git a/gcc/rust/resolve/rust-ast-resolve-pattern.h b/gcc/rust/resolve/rust-ast-resolve-pattern.h
index b2d059e..a41764a 100644
--- a/gcc/rust/resolve/rust-ast-resolve-pattern.h
+++ b/gcc/rust/resolve/rust-ast-resolve-pattern.h
@@ -44,7 +44,8 @@ public:
void visit (AST::IdentifierPattern &pattern) override
{
if (resolver->get_name_scope ().lookup (
- CanonicalPath::new_seg (pattern.get_ident ()), &resolved_node))
+ CanonicalPath::new_seg (pattern.get_node_id (), pattern.get_ident ()),
+ &resolved_node))
{
resolver->insert_resolved_name (pattern.get_node_id (), resolved_node);
resolver->insert_new_definition (pattern.get_node_id (),
@@ -72,10 +73,9 @@ public:
{
// if we have a duplicate id this then allows for shadowing correctly
// as new refs to this decl will match back here so it is ok to overwrite
- resolver->get_name_scope ().insert (CanonicalPath::new_seg (
- pattern.get_ident ()),
- pattern.get_node_id (),
- pattern.get_locus ());
+ resolver->get_name_scope ().insert (
+ CanonicalPath::new_seg (pattern.get_node_id (), pattern.get_ident ()),
+ pattern.get_node_id (), pattern.get_locus ());
resolver->insert_new_definition (pattern.get_node_id (),
Definition{pattern.get_node_id (),
parent});
diff --git a/gcc/rust/resolve/rust-ast-resolve-stmt.h b/gcc/rust/resolve/rust-ast-resolve-stmt.h
index b0cdeb2..210a9fc 100644
--- a/gcc/rust/resolve/rust-ast-resolve-stmt.h
+++ b/gcc/rust/resolve/rust-ast-resolve-stmt.h
@@ -67,7 +67,8 @@ public:
void visit (AST::TupleStruct &struct_decl) override
{
- auto path = CanonicalPath::new_seg (struct_decl.get_identifier ());
+ auto path = CanonicalPath::new_seg (struct_decl.get_node_id (),
+ struct_decl.get_identifier ());
resolver->get_type_scope ().insert (
path, struct_decl.get_node_id (), struct_decl.get_locus (), false,
[&] (const CanonicalPath &, NodeId, Location locus) -> void {
@@ -99,7 +100,8 @@ public:
void visit (AST::StructStruct &struct_decl) override
{
- auto path = CanonicalPath::new_seg (struct_decl.get_identifier ());
+ auto path = CanonicalPath::new_seg (struct_decl.get_node_id (),
+ struct_decl.get_identifier ());
resolver->get_type_scope ().insert (
path, struct_decl.get_node_id (), struct_decl.get_locus (), false,
[&] (const CanonicalPath &, NodeId, Location locus) -> void {
diff --git a/gcc/rust/resolve/rust-ast-resolve-toplevel.h b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
index 9f0d816..9abbb18 100644
--- a/gcc/rust/resolve/rust-ast-resolve-toplevel.h
+++ b/gcc/rust/resolve/rust-ast-resolve-toplevel.h
@@ -42,7 +42,8 @@ public:
void visit (AST::TypeAlias &alias) override
{
auto path
- = prefix.append (CanonicalPath::new_seg (alias.get_new_type_name ()));
+ = prefix.append (CanonicalPath::new_seg (alias.get_node_id (),
+ alias.get_new_type_name ()));
resolver->get_type_scope ().insert (
path, alias.get_node_id (), alias.get_locus (), false,
[&] (const CanonicalPath &, NodeId, Location locus) -> void {
@@ -55,7 +56,8 @@ public:
void visit (AST::TupleStruct &struct_decl) override
{
auto path
- = prefix.append (CanonicalPath::new_seg (struct_decl.get_identifier ()));
+ = prefix.append (CanonicalPath::new_seg (struct_decl.get_node_id (),
+ struct_decl.get_identifier ()));
resolver->get_type_scope ().insert (
path, struct_decl.get_node_id (), struct_decl.get_locus (), false,
[&] (const CanonicalPath &, NodeId, Location locus) -> void {
@@ -68,7 +70,8 @@ public:
void visit (AST::StructStruct &struct_decl) override
{
auto path
- = prefix.append (CanonicalPath::new_seg (struct_decl.get_identifier ()));
+ = prefix.append (CanonicalPath::new_seg (struct_decl.get_node_id (),
+ struct_decl.get_identifier ()));
resolver->get_type_scope ().insert (
path, struct_decl.get_node_id (), struct_decl.get_locus (), false,
[&] (const CanonicalPath &, NodeId, Location locus) -> void {
@@ -80,7 +83,8 @@ public:
void visit (AST::StaticItem &var) override
{
- auto path = prefix.append (CanonicalPath::new_seg (var.get_identifier ()));
+ auto path = prefix.append (
+ CanonicalPath::new_seg (var.get_node_id (), var.get_identifier ()));
resolver->get_name_scope ().insert (
path, var.get_node_id (), var.get_locus (), false,
[&] (const CanonicalPath &, NodeId, Location locus) -> void {
@@ -163,7 +167,8 @@ public:
type_resolve_generic_args);
CanonicalPath projection
- = TraitImplProjection::resolve (trait_type_seg, impl_type_seg);
+ = TraitImplProjection::resolve (impl_block.get_node_id (), trait_type_seg,
+ impl_type_seg);
CanonicalPath impl_prefix = prefix.append (projection);
for (auto &impl_item : impl_block.get_impl_items ())
@@ -172,8 +177,8 @@ public:
void visit (AST::Trait &trait) override
{
- CanonicalPath path
- = prefix.append (CanonicalPath::new_seg (trait.get_identifier ()));
+ CanonicalPath path = prefix.append (
+ CanonicalPath::new_seg (trait.get_node_id (), trait.get_identifier ()));
resolver->get_type_scope ().insert (
path, trait.get_node_id (), trait.get_locus (), false,
[&] (const CanonicalPath &, NodeId, Location locus) -> void {
diff --git a/gcc/rust/resolve/rust-ast-resolve-type.h b/gcc/rust/resolve/rust-ast-resolve-type.h
index cf6962b..23419b0 100644
--- a/gcc/rust/resolve/rust-ast-resolve-type.h
+++ b/gcc/rust/resolve/rust-ast-resolve-type.h
@@ -30,7 +30,8 @@ class ResolveConstantItemToCanonicalPath
public:
static CanonicalPath resolve (AST::ConstantItem &constant)
{
- return CanonicalPath::new_seg (constant.get_identifier ());
+ return CanonicalPath::new_seg (constant.get_node_id (),
+ constant.get_identifier ());
}
};
@@ -39,7 +40,8 @@ class ResolveFunctionItemToCanonicalPath
public:
static CanonicalPath resolve (AST::Function &function)
{
- return CanonicalPath::new_seg (function.get_function_name ());
+ return CanonicalPath::new_seg (function.get_node_id (),
+ function.get_function_name ());
}
};
@@ -48,7 +50,8 @@ class ResolveMethodItemToCanonicalPath
public:
static CanonicalPath resolve (AST::Method &method)
{
- return CanonicalPath::new_seg (method.get_method_name ());
+ return CanonicalPath::new_seg (method.get_node_id (),
+ method.get_method_name ());
}
};
@@ -58,6 +61,7 @@ public:
static CanonicalPath resolve (AST::TraitItemFunc &function)
{
return CanonicalPath::new_seg (
+ function.get_node_id (),
function.get_trait_function_decl ().get_identifier ());
}
};
@@ -68,7 +72,7 @@ public:
static CanonicalPath resolve (AST::TraitItemMethod &method)
{
return CanonicalPath::new_seg (
- method.get_trait_method_decl ().get_identifier ());
+ method.get_node_id (), method.get_trait_method_decl ().get_identifier ());
}
};
@@ -77,7 +81,8 @@ class ResolveTraitItemConstToCanonicalPath
public:
static CanonicalPath resolve (AST::TraitItemConst &constant)
{
- return CanonicalPath::new_seg (constant.get_identifier ());
+ return CanonicalPath::new_seg (constant.get_node_id (),
+ constant.get_identifier ());
}
};
@@ -86,7 +91,7 @@ class ResolveTraitItemTypeToCanonicalPath
public:
static CanonicalPath resolve (AST::TraitItemType &type)
{
- return CanonicalPath::new_seg (type.get_identifier ());
+ return CanonicalPath::new_seg (type.get_node_id (), type.get_identifier ());
}
};
@@ -119,7 +124,7 @@ public:
void visit (AST::TypePathSegment &seg) override;
- static CanonicalPath canonicalize_generic_args (AST::GenericArgs &args);
+ static std::string canonicalize_generic_args (AST::GenericArgs &args);
static bool type_resolve_generic_args (AST::GenericArgs &args);
@@ -143,41 +148,40 @@ class ResolvePathSegmentToCanonicalPath
public:
static CanonicalPath resolve (AST::PathExprSegment &seg)
{
- CanonicalPath path
- = CanonicalPath::new_seg (seg.get_ident_segment ().as_string ());
- if (seg.has_generic_args ())
+ 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)
{
- 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 ();
- }
-
- path
- = path.append (ResolveTypeToCanonicalPath::canonicalize_generic_args (
- seg.get_generic_args ()));
+ rust_error_at (seg.get_locus (),
+ "failed to resolve all generic arguments");
+ return CanonicalPath::create_empty ();
}
- return path;
+
+ std::string generics
+ = ResolveTypeToCanonicalPath::canonicalize_generic_args (
+ seg.get_generic_args ());
+
+ return CanonicalPath::new_seg (seg.get_node_id (),
+ seg.get_ident_segment ().as_string ()
+ + "::" + generics);
}
};
class TraitImplProjection
{
public:
- static CanonicalPath resolve (const CanonicalPath &trait_seg,
+ static CanonicalPath resolve (NodeId id, const CanonicalPath &trait_seg,
const CanonicalPath &impl_type_seg)
{
- return CanonicalPath::new_seg ("<" + impl_type_seg.get () + " as "
- + trait_seg.get () + ">");
+ return CanonicalPath::new_seg (id, "<" + impl_type_seg.get () + " as "
+ + trait_seg.get () + ">");
}
};
-// FIXME: as part of imports and visibility we need to be able to keep a context
-// for handling PathInExpressions segments as they can be local to a particular
-// lexical scope requiring a context to be maintained for resolution
class ResolveRelativeTypePath
{
public:
@@ -191,7 +195,8 @@ public:
true);
if (canonical_path.is_error ())
{
- rust_error_at (path.get_locus (), "Failed to resolve canonical path");
+ rust_error_at (path.get_locus (),
+ "Failed to resolve canonical path for TypePath");
return UNKNOWN_NODEID;
}
@@ -318,7 +323,8 @@ public:
// for now lets focus on handling the basics: like struct<T> { a:T, ....}
resolver->get_type_scope ().insert (
- CanonicalPath::new_seg (param.get_type_representation ()),
+ CanonicalPath::new_seg (param.get_node_id (),
+ param.get_type_representation ()),
param.get_node_id (), param.get_locus (), false,
[&] (const CanonicalPath &, NodeId, Location locus) -> void {
rust_error_at (param.get_locus (),
diff --git a/gcc/rust/resolve/rust-ast-resolve.cc b/gcc/rust/resolve/rust-ast-resolve.cc
index d47371c..b568e1c 100644
--- a/gcc/rust/resolve/rust-ast-resolve.cc
+++ b/gcc/rust/resolve/rust-ast-resolve.cc
@@ -122,7 +122,8 @@ Resolver::insert_builtin_types (Rib *r)
for (auto &builtin : builtins)
{
CanonicalPath builtin_path
- = CanonicalPath::new_seg (builtin->as_string ());
+ = CanonicalPath::new_seg (builtin->get_node_id (),
+ builtin->as_string ());
r->insert_name (builtin_path, builtin->get_node_id (),
Linemap::predeclared_location (), false,
[] (const CanonicalPath &, NodeId, Location) -> void {});
@@ -385,7 +386,7 @@ ResolveStructExprField::visit (AST::StructExprFieldIdentifier &field)
// rust-ast-resolve-type.h
-CanonicalPath
+std::string
ResolveTypeToCanonicalPath::canonicalize_generic_args (AST::GenericArgs &args)
{
std::string buf;
@@ -402,7 +403,7 @@ ResolveTypeToCanonicalPath::canonicalize_generic_args (AST::GenericArgs &args)
i++;
}
- return CanonicalPath::new_seg ("<" + buf + ">");
+ return "<" + buf + ">";
}
bool
@@ -429,24 +430,31 @@ ResolveTypeToCanonicalPath::visit (AST::TypePathSegmentGeneric &seg)
return;
}
- // ident seg
- CanonicalPath ident_seg
- = CanonicalPath::new_seg (seg.get_ident_segment ().as_string ());
- result = result.append (ident_seg);
+ if (!seg.has_generic_args ())
+ {
+ result = CanonicalPath::new_seg (seg.get_node_id (),
+ seg.get_ident_segment ().as_string ());
+ return;
+ }
- // generic args
- if (seg.has_generic_args ())
+ if (type_resolve_generic_args_flag)
{
- if (include_generic_args_flag)
- result
- = result.append (canonicalize_generic_args (seg.get_generic_args ()));
+ bool ok = type_resolve_generic_args (seg.get_generic_args ());
+ failure_flag = !ok;
+ }
- if (type_resolve_generic_args_flag)
- {
- bool ok = type_resolve_generic_args (seg.get_generic_args ());
- failure_flag = !ok;
- }
+ if (include_generic_args_flag)
+ {
+ std::string generics
+ = canonicalize_generic_args (seg.get_generic_args ());
+ result = CanonicalPath::new_seg (seg.get_node_id (),
+ seg.get_ident_segment ().as_string ()
+ + "::" + generics);
+ return;
}
+
+ result = CanonicalPath::new_seg (seg.get_node_id (),
+ seg.get_ident_segment ().as_string ());
}
void
@@ -461,7 +469,8 @@ ResolveTypeToCanonicalPath::visit (AST::TypePathSegment &seg)
}
CanonicalPath ident_seg
- = CanonicalPath::new_seg (seg.get_ident_segment ().as_string ());
+ = CanonicalPath::new_seg (seg.get_node_id (),
+ seg.get_ident_segment ().as_string ());
result = result.append (ident_seg);
}
@@ -476,7 +485,8 @@ ResolvePath::resolve_path (AST::PathInExpression *expr)
bool segment_is_type = false;
CanonicalPath root_seg_path
- = CanonicalPath::new_seg (root_ident_seg.as_string ());
+ = CanonicalPath::new_seg (expr->get_node_id (),
+ root_ident_seg.as_string ());
// name scope first
if (resolver->get_name_scope ().lookup (root_seg_path, &resolved_node))
diff --git a/gcc/rust/resolve/rust-ast-verify-assignee.h b/gcc/rust/resolve/rust-ast-verify-assignee.h
index 11a5414..aed0119 100644
--- a/gcc/rust/resolve/rust-ast-verify-assignee.h
+++ b/gcc/rust/resolve/rust-ast-verify-assignee.h
@@ -58,7 +58,8 @@ public:
void visit (AST::IdentifierExpr &expr) override
{
if (!resolver->get_name_scope ().lookup (
- CanonicalPath::new_seg (expr.as_string ()), &resolved_node))
+ CanonicalPath::new_seg (expr.get_node_id (), expr.as_string ()),
+ &resolved_node))
return;
ok = true;
diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h
index d3b22a0..033b891 100644
--- a/gcc/rust/resolve/rust-name-resolver.h
+++ b/gcc/rust/resolve/rust-name-resolver.h
@@ -55,10 +55,10 @@ public:
return *this;
}
- static CanonicalPath new_seg (const std::string &path)
+ static CanonicalPath new_seg (NodeId id, const std::string &path)
{
rust_assert (!path.empty ());
- return CanonicalPath ({path});
+ return CanonicalPath ({std::pair<NodeId, std::string> (id, path)});
}
std::string get () const
@@ -67,20 +67,15 @@ public:
for (size_t i = 0; i < segs.size (); i++)
{
bool have_more = (i + 1) < segs.size ();
- const std::string &seg = segs.at (i);
+ const std::string &seg = segs.at (i).second;
buf += seg + (have_more ? "::" : "");
}
return buf;
}
- static CanonicalPath get_big_self ()
+ static CanonicalPath get_big_self (NodeId id)
{
- return CanonicalPath::new_seg ("Self");
- }
-
- static CanonicalPath get_wee_self ()
- {
- return CanonicalPath::new_seg ("self");
+ return CanonicalPath::new_seg (id, "Self");
}
static CanonicalPath create_empty () { return CanonicalPath ({}); }
@@ -93,7 +88,7 @@ public:
if (is_error ())
return CanonicalPath (other.segs);
- std::vector<std::string> copy (segs);
+ std::vector<std::pair<NodeId, std::string>> copy (segs);
for (auto &s : other.segs)
copy.push_back (s);
@@ -105,9 +100,9 @@ public:
// A
// A::B
// A::B::C
- void iterate_path (std::function<bool (const CanonicalPath &)> cb) const
+ void iterate (std::function<bool (const CanonicalPath &)> cb) const
{
- std::vector<std::string> buf;
+ std::vector<std::pair<NodeId, std::string>> buf;
for (auto &seg : segs)
{
buf.push_back (seg);
@@ -116,6 +111,12 @@ public:
}
}
+ NodeId get_id () const
+ {
+ rust_assert (!segs.empty ());
+ return segs.back ().first;
+ }
+
bool operator== (const CanonicalPath &b) const
{
return get ().compare (b.get ()) == 0;
@@ -124,9 +125,11 @@ public:
bool operator< (const CanonicalPath &b) const { return get () < b.get (); }
private:
- explicit CanonicalPath (std::vector<std::string> path) : segs (path) {}
+ explicit CanonicalPath (std::vector<std::pair<NodeId, std::string>> path)
+ : segs (path)
+ {}
- std::vector<std::string> segs;
+ std::vector<std::pair<NodeId, std::string>> segs;
};
class Rib
@@ -255,8 +258,8 @@ private:
NodeId node_id;
std::map<CanonicalPath, NodeId> mappings;
std::map<NodeId, CanonicalPath> reverse_mappings;
- std::set<std::pair<NodeId, Location> > decls_within_rib;
- std::map<NodeId, std::set<NodeId> > references;
+ std::set<std::pair<NodeId, Location>> decls_within_rib;
+ std::map<NodeId, std::set<NodeId>> references;
};
class Scope
@@ -494,7 +497,7 @@ private:
// map of resolved names mutability flag
std::map<NodeId, bool> decl_mutability;
// map of resolved names and set of assignments to the decl
- std::map<NodeId, std::set<NodeId> > assignment_to_decl;
+ std::map<NodeId, std::set<NodeId>> assignment_to_decl;
};
} // namespace Resolver