提交 6cb5c098 编写于 作者: M Marijn Haverbeke

box patterns, expect for the trans part

上级 6914d32a
......@@ -312,6 +312,7 @@ fn walk_pat(&mutable vec[node_id] found, &@ast::pat p) {
case (ast::pat_rec(?fields, _)) {
for (ast::field_pat f in fields) { walk_pat(found, f.pat); }
}
case (ast::pat_box(?inner)) { walk_pat(found, inner); }
case (_) { }
}
}
......
......@@ -311,6 +311,7 @@ fn walk_pat(&env e, &scopes sc, &@ast::pat pat) {
case (ast::pat_rec(?fields, _)) {
for (ast::field_pat f in fields) { walk_pat(e, sc, f.pat); }
}
case (ast::pat_box(?inner)) { walk_pat(e, sc, inner); }
case (_) { }
}
}
......@@ -727,6 +728,7 @@ fn lookup_in_pat(&ident name, &ast::pat pat) -> option::t[def] {
if (!option::is_none(found)) { ret found; }
}
}
case (ast::pat_box(?inner)) { ret lookup_in_pat(name, *inner); }
}
ret none[def];
}
......@@ -1268,6 +1270,7 @@ fn walk_pat(checker ch, &@ast::pat p) {
case (ast::pat_rec(?fields, _)) {
for (ast::field_pat f in fields) { walk_pat(ch, f.pat); }
}
case (ast::pat_box(?inner)) { walk_pat(ch, inner); }
case (_) { }
}
}
......
......@@ -1435,6 +1435,20 @@ fn matches(&str name, &ty::field f) -> bool {
}
write::ty_only_fixup(fcx, pat.id, expected);
}
case (ast::pat_box(?inner)) {
alt (structure_of(fcx, pat.span, expected)) {
case (ty::ty_box(?e_inner)) {
check_pat(fcx, map, inner, e_inner.ty);
write::ty_only_fixup(fcx, pat.id, expected);
}
case (_) {
fcx.ccx.tcx.sess.span_fatal
(pat.span, "mismatched types: expected " +
ty_to_str(fcx.ccx.tcx, expected) +
" found box");
}
}
}
}
}
......
......@@ -126,6 +126,7 @@ fn def_id_of_def(def d) -> def_id {
pat_lit(@lit);
pat_tag(path, (@pat)[]);
pat_rec(field_pat[], bool);
pat_box(@pat);
}
type pat_id_map = std::map::hashmap[str, ast::node_id];
......@@ -143,6 +144,7 @@ fn walk(&pat_id_map map, &@pat pat) {
pat_rec(?fields, _) {
for (field_pat f in fields) { walk(map, f.pat); }
}
pat_box(?inner) { walk(map, inner); }
_ {}
}
}
......
......@@ -292,6 +292,7 @@ fn noop_fold_pat(&pat_ p, ast_fold fld) -> pat_ {
}
pat_rec(fs, etc)
}
case (pat_box(?inner)) { pat_box(fld.fold_pat(inner)) }
};
}
......
......@@ -1459,6 +1459,12 @@ fn parse_pat(&parser p) -> @ast::pat {
}
}
}
case (token::AT) {
p.bump();
auto sub = parse_pat(p);
pat = ast::pat_box(sub);
hi = sub.span.hi;
}
case (token::LBRACE) {
p.bump();
auto fields = ~[];
......@@ -2313,9 +2319,8 @@ fn parse_rest_import_name(&parser p, ast::ident first,
}
alt (p.peek()) {
case (token::IDENT(_, _)) { identifiers += ~[parse_ident(p)]; }
case (
//the lexer can't tell the different kinds of stars apart ) :
token::BINOP(token::STAR)) {
//the lexer can't tell the different kinds of stars apart ) :
case (token::BINOP(token::STAR)) {
glob = true;
p.bump();
}
......
......@@ -1136,6 +1136,10 @@ fn get_span(&ast::field_pat f) -> codemap::span {
}
word(s.s, "}");
}
case (ast::pat_box(?inner)) {
word(s.s, "@");
print_pat(s, inner);
}
}
s.ann.post(ann_node);
}
......
......@@ -200,6 +200,7 @@ fn visit_pat[E](&@pat p, &E e, &vt[E] v) {
case (pat_rec(?fields, _)) {
for (field_pat f in fields) { v.visit_pat(f.pat, e, v); }
}
case (pat_box(?inner)) { v.visit_pat(inner, e, v); }
case (_) { }
}
}
......
......@@ -192,6 +192,7 @@ fn walk_pat(&ast_visitor v, &@ast::pat p) {
case (ast::pat_rec(?fields, _)) {
for (ast::field_pat f in fields) { walk_pat(v, f.pat); }
}
case (ast::pat_box(?inner)) { walk_pat(v, inner); }
case (_) { }
}
v.visit_pat_post(p);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册