Add EntryPat and NodePat variants to ast_map.

Add `EntryPat` and `NodePat` variants to ast_map, so that lookups for
id 1 in `let S{val: _x /* pat 2 */} /* pat 1 */ = ...` will actually
resolve to the pattern `S{ ... }`, rather than "unknown node", in a
function like `node_id_to_str`.
This commit is contained in:
Felix S. Klock II 2014-05-08 15:50:54 +02:00 committed by Alex Crichton
parent b9e4fcbf04
commit 39b271f4a3
2 changed files with 12 additions and 1 deletions

View File

@ -309,6 +309,7 @@ pub fn monomorphic_fn(ccx: &CrateContext,
ast_map::NodeStmt(..) |
ast_map::NodeArg(..) |
ast_map::NodeBlock(..) |
ast_map::NodePat(..) |
ast_map::NodeLocal(..) => {
ccx.sess().bug(format!("can't monomorphize a {:?}", map_node))
}

View File

@ -103,6 +103,7 @@ pub enum Node {
NodeStmt(@Stmt),
NodeArg(@Pat),
NodeLocal(@Pat),
NodePat(@Pat),
NodeBlock(P<Block>),
/// NodeStructCtor represents a tuple struct.
@ -127,6 +128,7 @@ enum MapEntry {
EntryStmt(NodeId, @Stmt),
EntryArg(NodeId, @Pat),
EntryLocal(NodeId, @Pat),
EntryPat(NodeId, @Pat),
EntryBlock(NodeId, P<Block>),
EntryStructCtor(NodeId, @StructDef),
EntryLifetime(NodeId, @Lifetime),
@ -154,6 +156,7 @@ impl MapEntry {
EntryStmt(id, _) => id,
EntryArg(id, _) => id,
EntryLocal(id, _) => id,
EntryPat(id, _) => id,
EntryBlock(id, _) => id,
EntryStructCtor(id, _) => id,
EntryLifetime(id, _) => id,
@ -172,6 +175,7 @@ impl MapEntry {
EntryStmt(_, p) => NodeStmt(p),
EntryArg(_, p) => NodeArg(p),
EntryLocal(_, p) => NodeLocal(p),
EntryPat(_, p) => NodePat(p),
EntryBlock(_, p) => NodeBlock(p),
EntryStructCtor(_, p) => NodeStructCtor(p),
EntryLifetime(_, p) => NodeLifetime(p),
@ -399,6 +403,7 @@ impl Map {
Some(NodeExpr(expr)) => expr.span,
Some(NodeStmt(stmt)) => stmt.span,
Some(NodeArg(pat)) | Some(NodeLocal(pat)) => pat.span,
Some(NodePat(pat)) => pat.span,
Some(NodeBlock(block)) => block.span,
Some(NodeStructCtor(_)) => self.expect_item(self.get_parent(id)).span,
_ => fail!("node_span: could not find span for id {}", id),
@ -513,7 +518,9 @@ impl<'a, F: FoldOps> Folder for Ctx<'a, F> {
// Note: this is at least *potentially* a pattern...
self.insert(pat.id, EntryLocal(self.parent, pat));
}
_ => {}
_ => {
self.insert(pat.id, EntryPat(self.parent, pat));
}
}
pat
@ -704,6 +711,9 @@ fn node_id_to_str(map: &Map, id: NodeId) -> StrBuf {
(format!("local {} (id={})",
pprust::pat_to_str(pat), id)).to_strbuf()
}
Some(NodePat(pat)) => {
(format!("pat {} (id={})", pprust::pat_to_str(pat), id)).to_strbuf()
}
Some(NodeBlock(block)) => {
(format!("block {} (id={})",
pprust::block_to_str(block), id)).to_strbuf()