diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-02-07 11:31:15 -0800 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-02-07 12:15:59 -0800 |
| commit | a63780afcee53489e2f1640245d3b7c496dbe071 (patch) | |
| tree | 528c39b713494ffdd24ceae75f27188658f5dee7 /src | |
| parent | 47143ee24a135ee2a82864c9ff892fafe5cd262d (diff) | |
Minor class-related tweaks to the AST
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp/metadata/encoder.rs | 4 | ||||
| -rw-r--r-- | src/comp/middle/resolve.rs | 3 | ||||
| -rw-r--r-- | src/comp/middle/tstate/pre_post_conditions.rs | 2 | ||||
| -rw-r--r-- | src/comp/middle/typeck.rs | 6 | ||||
| -rw-r--r-- | src/comp/syntax/ast.rs | 14 | ||||
| -rw-r--r-- | src/comp/syntax/ast_util.rs | 1 | ||||
| -rw-r--r-- | src/comp/syntax/fold.rs | 7 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 8 | ||||
| -rw-r--r-- | src/comp/syntax/print/pprust.rs | 4 | ||||
| -rw-r--r-- | src/comp/syntax/visit.rs | 16 |
10 files changed, 40 insertions, 25 deletions
diff --git a/src/comp/metadata/encoder.rs b/src/comp/metadata/encoder.rs index fda3ab14cbe..d57bc0ab36e 100644 --- a/src/comp/metadata/encoder.rs +++ b/src/comp/metadata/encoder.rs @@ -119,7 +119,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, module: _mod, path: [str], encode_def_id(ebml_w, local_def(it.id)); ebml::end_tag(ebml_w); } - item_class(_,_,_,_) { + item_class(_,_,_,_,_) { fail "encode: implement item_class"; } item_enum(variants, tps) { @@ -343,7 +343,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item, ebml::end_tag(ebml_w); encode_enum_variant_info(ecx, ebml_w, item.id, variants, index, tps); } - item_class(_,_,_,_) { + item_class(_,_,_,_,_) { fail "encode: implement item_class"; } item_res(_, tps, _, _, ctor_id) { diff --git a/src/comp/middle/resolve.rs b/src/comp/middle/resolve.rs index 7fbc2ad0c05..47b0c71e112 100644 --- a/src/comp/middle/resolve.rs +++ b/src/comp/middle/resolve.rs @@ -1452,7 +1452,7 @@ fn index_mod(md: ast::_mod) -> mod_index { variant_idx += 1u; } } - ast::item_class(_, items, ctor_decl, _) { + ast::item_class(_, items, _, ctor_decl, _) { fail "resolve::index_mod: item_class"; } } @@ -1498,6 +1498,7 @@ fn ns_for_def(d: def) -> namespace { ast::def_mod(_) | ast::def_native_mod(_) { ns_module } ast::def_ty(_) | ast::def_binding(_) | ast::def_use(_) | ast::def_ty_param(_, _) | ast::def_prim_ty(_) { ns_type } + _ { fail "Dead"; } } } diff --git a/src/comp/middle/tstate/pre_post_conditions.rs b/src/comp/middle/tstate/pre_post_conditions.rs index 0ca3a6ee294..f9a3740c049 100644 --- a/src/comp/middle/tstate/pre_post_conditions.rs +++ b/src/comp/middle/tstate/pre_post_conditions.rs @@ -60,7 +60,7 @@ fn find_pre_post_item(ccx: crate_ctxt, i: item) { ccx: ccx}; find_pre_post_fn(fcx, body); } - item_class(_,_,_,_) { + item_class(_,_,_,_,_) { fail "find_pre_post_item: implement item_class"; } item_impl(_, _, _, ms) { for m in ms { find_pre_post_method(ccx, m); } } diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 08f67f5f5b8..7eb9380d3f8 100644 --- a/src/comp/middle/typeck.rs +++ b/src/comp/middle/typeck.rs @@ -424,7 +424,7 @@ fn ty_of_item(tcx: ty::ctxt, mode: mode, it: @ast::item) tcx.tcache.insert(local_def(it.id), tpt); ret tpt; } - ast::item_class(_,_,_,_) { + ast::item_class(_,_,_,_,_) { fail "ty_of_item: implement item_class"; } ast::item_impl(_, _, _, _) | ast::item_mod(_) | @@ -2006,7 +2006,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier, let variants = ty::enum_variants(tcx, id); if vec::len(*variants) != 1u || vec::len(variants[0].args) != 1u { - tcx.sess.span_fatal(expr.span, + tcx.sess.span_err(expr.span, "can only dereference enums " + "with a single variant which has a " + "single argument"); @@ -2019,7 +2019,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier, require_unsafe(tcx.sess, fcx.purity, expr.span); } _ { - tcx.sess.span_fatal(expr.span, + tcx.sess.span_err(expr.span, "dereferencing non-" + "dereferenceable type: " + ty_to_str(tcx, oper_t)); diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index fd70d642501..c1b3b4e1636 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -47,6 +47,12 @@ enum def { def_binding(def_id), def_use(def_id), def_upvar(def_id, @def, node_id), // node_id == expr_fn or expr_fn_block + def_class(def_id), + // first def_id is for parent class + def_class_field(def_id, def_id), + // No purity allowed for now, I guess + // (simpler this way, b/c presumably methods read mutable state) + def_class_method(def_id, def_id) } // The set of meta_items that define the compilation environment of the crate, @@ -483,6 +489,7 @@ enum item_ { item_class([ty_param], /* ty params for class */ [@class_item], /* methods, etc. */ /* (not including ctor) */ + node_id, fn_decl, /* ctor decl */ blk /* ctor body */ ), @@ -491,12 +498,15 @@ enum item_ { @ty /* self */, [@method]), } -type class_item_ = {privacy: privacy, decl: @class_member}; +type class_item_ = {privacy: privacy, decl: class_member}; type class_item = spanned<class_item_>; enum class_member { instance_var(ident, @ty, class_mutability, node_id), - class_method(@item) + class_method(@item) // FIXME: methods aren't allowed to be + // type-parametric. + // without constrained types, have to duplicate some stuff. or factor out + // item to separate out things with type params? } enum class_mutability { class_mutable, class_immutable } diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs index 6e44b56d0a0..3046ba02907 100644 --- a/src/comp/syntax/ast_util.rs +++ b/src/comp/syntax/ast_util.rs @@ -32,6 +32,7 @@ fn def_id_of_def(d: def) -> def_id { def_variant(_, id) | def_ty(id) | def_ty_param(id, _) | def_binding(id) | def_use(id) | def_upvar(id, _, _) { id } def_prim_ty(_) { fail; } + _ { fail "Dead"; } } } diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs index f7151e7e838..723a70741ab 100644 --- a/src/comp/syntax/fold.rs +++ b/src/comp/syntax/fold.rs @@ -227,7 +227,7 @@ fn noop_fold_class_item(&&ci: @class_item, fld: ast_fold) @{node: { privacy:ci.node.privacy, decl: - @alt *ci.node.decl { + alt ci.node.decl { instance_var(ident, t, cm, id) { instance_var(ident, fld.fold_ty(t), cm, id) } @@ -249,9 +249,10 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ { item_enum(variants, typms) { item_enum(vec::map(variants, fld.fold_variant), typms) } - item_class(typms, items, ctor_decl, ctor_body) { + item_class(typms, items, id, ctor_decl, ctor_body) { item_class(typms, vec::map(items, fld.fold_class_item), + id, fold_fn_decl(ctor_decl, fld), fld.fold_block(ctor_body)) } @@ -617,7 +618,7 @@ fn make_fold(afp: ast_fold_precursor) -> ast_fold { @{node: {privacy:ci.node.privacy, decl: - @alt *ci.node.decl { + alt ci.node.decl { instance_var(nm, t, mt, id) { instance_var(nm, f_ty(afp, f, t), mt, id) diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 33b6432a09c..dab6be43e2f 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -1965,6 +1965,7 @@ fn parse_item_class(p: parser, attrs: [ast::attribute]) -> @ast::item { let ty_params = parse_ty_params(p); expect(p, token::LBRACE); let items: [@ast::class_item] = []; + let ctor_id = p.get_id(); let the_ctor : option<(ast::fn_decl, ast::blk)> = none; while p.token != token::RBRACE { alt parse_class_item(p) { @@ -1972,12 +1973,12 @@ fn parse_item_class(p: parser, attrs: [ast::attribute]) -> @ast::item { the_ctor = some((a_fn_decl, blk)); } plain_decl(a_decl) { - items += [@{node: {privacy: ast::pub, decl: a_decl}, + items += [@{node: {privacy: ast::pub, decl: *a_decl}, span: p.last_span}]; } priv_decls(some_decls) { items += vec::map(some_decls, {|d| - @{node: {privacy: ast::priv, decl: d}, + @{node: {privacy: ast::priv, decl: *d}, span: p.last_span}}); } } @@ -1985,7 +1986,8 @@ fn parse_item_class(p: parser, attrs: [ast::attribute]) -> @ast::item { p.bump(); alt the_ctor { some((ct_d, ct_b)) { ret mk_item(p, lo, p.last_span.hi, class_name, - ast::item_class(ty_params, items, ct_d, ct_b), attrs); } + ast::item_class(ty_params, items, ctor_id, + ct_d, ct_b), attrs); } /* Is it strange for the parser to check this? */ diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index 121a57b24f7..a60e68b335d 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -470,7 +470,7 @@ fn print_item(s: ps, &&item: @ast::item) { bclose(s, item.span); } } - ast::item_class(tps,items,ctor_decl,ctor_body) { + ast::item_class(tps,items,_,ctor_decl,ctor_body) { head(s, "class"); word_nbsp(s, item.ident); print_type_params(s, tps); @@ -494,7 +494,7 @@ fn print_item(s: ps, &&item: @ast::item) { } _ {} } - alt *ci.node.decl { + alt ci.node.decl { ast::instance_var(nm, t, mt, _) { word_nbsp(s, "let"); alt mt { diff --git a/src/comp/syntax/visit.rs b/src/comp/syntax/visit.rs index 1bea675b8a0..571deb576c4 100644 --- a/src/comp/syntax/visit.rs +++ b/src/comp/syntax/visit.rs @@ -55,7 +55,7 @@ type visitor<E> = visit_ty_params: fn@([ty_param], E, vt<E>), visit_constr: fn@(@path, span, node_id, E, vt<E>), visit_fn: fn@(fn_kind, fn_decl, blk, span, node_id, E, vt<E>), - visit_class_item: fn@(span, privacy, @class_member, E, vt<E>)}; + visit_class_item: fn@(span, privacy, class_member, E, vt<E>)}; fn default_visitor<E>() -> visitor<E> { ret @{visit_mod: bind visit_mod::<E>(_, _, _, _, _), @@ -137,7 +137,7 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) { m.id, e, v); } } - item_class(tps, members, ctor_decl, ctor_blk) { + item_class(tps, members, _, ctor_decl, ctor_blk) { v.visit_ty_params(tps, e, v); for m in members { v.visit_class_item(m.span, m.node.privacy, m.node.decl, e, v); @@ -155,9 +155,9 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) { } } -fn visit_class_item<E>(_s: span, _p: privacy, cm: @class_member, +fn visit_class_item<E>(_s: span, _p: privacy, cm: class_member, e:E, v:vt<E>) { - alt *cm { + alt cm { instance_var(ident, t, mt, id) { v.visit_ty(t, e, v); } @@ -409,7 +409,7 @@ type simple_visitor = visit_ty_params: fn@([ty_param]), visit_constr: fn@(@path, span, node_id), visit_fn: fn@(fn_kind, fn_decl, blk, span, node_id), - visit_class_item: fn@(span, privacy, @class_member)}; + visit_class_item: fn@(span, privacy, class_member)}; fn simple_ignore_ty(_t: @ty) {} @@ -430,7 +430,7 @@ fn default_simple_visitor() -> simple_visitor { visit_constr: fn@(_p: @path, _sp: span, _id: node_id) { }, visit_fn: fn@(_fk: fn_kind, _d: fn_decl, _b: blk, _sp: span, _id: node_id) { }, - visit_class_item: fn@(_s: span, _p: privacy, _c: @class_member) {} + visit_class_item: fn@(_s: span, _p: privacy, _c: class_member) {} }; } @@ -505,8 +505,8 @@ fn mk_simple_visitor(v: simple_visitor) -> vt<()> { } else { bind v_ty(v.visit_ty, _, _, _) }; - fn v_class_item(f: fn@(span, privacy, @class_member), - s:span, p:privacy, cm: @class_member, &&e: (), + fn v_class_item(f: fn@(span, privacy, class_member), + s:span, p:privacy, cm: class_member, &&e: (), v: vt<()>) { f(s, p, cm); visit_class_item(s, p, cm, e, v); |
