aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve/rust-name-resolver.h
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2020-12-18 16:17:47 +0000
committerPhilip Herron <herron.philip@googlemail.com>2020-12-19 19:32:41 +0000
commit3a10d1f15969f94c3d3bc836db1d75dd0f914aa9 (patch)
treeeecfac3b2f5b7b995a249862e16692a3d5e76845 /gcc/rust/resolve/rust-name-resolver.h
parentbc14d9a0cd3c67093a9c11ad368c0d28325b21c6 (diff)
downloadgcc-3a10d1f15969f94c3d3bc836db1d75dd0f914aa9.zip
gcc-3a10d1f15969f94c3d3bc836db1d75dd0f914aa9.tar.gz
gcc-3a10d1f15969f94c3d3bc836db1d75dd0f914aa9.tar.bz2
Add type unification as part of typecheck.
Rust must examine each usage of a name and unify their types. For example: let mut x; x = 1 This means the declaration is determined to be an inference variable then the assignment can be resolved to an Integer TyTy which can be combined as part of the rules to now make the let x decl be an i32.
Diffstat (limited to 'gcc/rust/resolve/rust-name-resolver.h')
-rw-r--r--gcc/rust/resolve/rust-name-resolver.h27
1 files changed, 22 insertions, 5 deletions
diff --git a/gcc/rust/resolve/rust-name-resolver.h b/gcc/rust/resolve/rust-name-resolver.h
index 2aa592c..38206f6 100644
--- a/gcc/rust/resolve/rust-name-resolver.h
+++ b/gcc/rust/resolve/rust-name-resolver.h
@@ -41,6 +41,7 @@ public:
{
mappings[ident] = id;
decls_within_rib.insert (id);
+ references[id] = {};
}
bool lookup_name (std::string ident, NodeId *id)
@@ -65,11 +66,30 @@ public:
}
}
+ void iterate_references_for_def (NodeId def, std::function<bool (NodeId)> cb)
+ {
+ auto it = references.find (def);
+ if (it == references.end ())
+ return;
+
+ for (auto ref : it->second)
+ {
+ if (!cb (ref))
+ return;
+ }
+ }
+
+ void append_reference_for_def (NodeId def, NodeId ref)
+ {
+ references[def].insert (ref);
+ }
+
private:
CrateNum crate_num;
NodeId node_id;
std::map<std::string, NodeId> mappings;
std::set<NodeId> decls_within_rib;
+ std::map<NodeId, std::set<NodeId> > references;
};
class Scope
@@ -135,8 +155,8 @@ private:
//
// if parent is UNKNOWN_NODEID then this is a root declaration
// say the var_decl hasa node_id=4;
-// the parent could be a BLOCK_Expr node_id but lets make it UNKNOWN_NODE_ID so
-// we know when it terminates
+// the parent could be a BLOCK_Expr node_id but lets make it UNKNOWN_NODE_ID
+// so we know when it terminates
struct Definition
{
NodeId node;
@@ -211,9 +231,6 @@ private:
// we need two namespaces one for names and ones for types
std::map<NodeId, NodeId> resolved_names;
std::map<NodeId, NodeId> resolved_types;
-
- std::map<NodeId, std::set<NodeId> > nameDefNodeIdToRibs;
- std::map<NodeId, std::set<NodeId> > typeDefNodeIdToRibs;
};
} // namespace Resolver