Skip to content

Commit a63780a

Browse files
committed
Minor class-related tweaks to the AST
1 parent 47143ee commit a63780a

File tree

10 files changed

+40
-25
lines changed

10 files changed

+40
-25
lines changed

src/comp/metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, module: _mod, path: [str],
119119
encode_def_id(ebml_w, local_def(it.id));
120120
ebml::end_tag(ebml_w);
121121
}
122-
item_class(_,_,_,_) {
122+
item_class(_,_,_,_,_) {
123123
fail "encode: implement item_class";
124124
}
125125
item_enum(variants, tps) {
@@ -343,7 +343,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
343343
ebml::end_tag(ebml_w);
344344
encode_enum_variant_info(ecx, ebml_w, item.id, variants, index, tps);
345345
}
346-
item_class(_,_,_,_) {
346+
item_class(_,_,_,_,_) {
347347
fail "encode: implement item_class";
348348
}
349349
item_res(_, tps, _, _, ctor_id) {

src/comp/middle/resolve.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,7 @@ fn index_mod(md: ast::_mod) -> mod_index {
14521452
variant_idx += 1u;
14531453
}
14541454
}
1455-
ast::item_class(_, items, ctor_decl, _) {
1455+
ast::item_class(_, items, _, ctor_decl, _) {
14561456
fail "resolve::index_mod: item_class";
14571457
}
14581458
}
@@ -1498,6 +1498,7 @@ fn ns_for_def(d: def) -> namespace {
14981498
ast::def_mod(_) | ast::def_native_mod(_) { ns_module }
14991499
ast::def_ty(_) | ast::def_binding(_) | ast::def_use(_) |
15001500
ast::def_ty_param(_, _) | ast::def_prim_ty(_) { ns_type }
1501+
_ { fail "Dead"; }
15011502
}
15021503
}
15031504

src/comp/middle/tstate/pre_post_conditions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ fn find_pre_post_item(ccx: crate_ctxt, i: item) {
6060
ccx: ccx};
6161
find_pre_post_fn(fcx, body);
6262
}
63-
item_class(_,_,_,_) {
63+
item_class(_,_,_,_,_) {
6464
fail "find_pre_post_item: implement item_class";
6565
}
6666
item_impl(_, _, _, ms) { for m in ms { find_pre_post_method(ccx, m); } }

src/comp/middle/typeck.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ fn ty_of_item(tcx: ty::ctxt, mode: mode, it: @ast::item)
424424
tcx.tcache.insert(local_def(it.id), tpt);
425425
ret tpt;
426426
}
427-
ast::item_class(_,_,_,_) {
427+
ast::item_class(_,_,_,_,_) {
428428
fail "ty_of_item: implement item_class";
429429
}
430430
ast::item_impl(_, _, _, _) | ast::item_mod(_) |
@@ -2006,7 +2006,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
20062006
let variants = ty::enum_variants(tcx, id);
20072007
if vec::len(*variants) != 1u ||
20082008
vec::len(variants[0].args) != 1u {
2009-
tcx.sess.span_fatal(expr.span,
2009+
tcx.sess.span_err(expr.span,
20102010
"can only dereference enums " +
20112011
"with a single variant which has a "
20122012
+ "single argument");
@@ -2019,7 +2019,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
20192019
require_unsafe(tcx.sess, fcx.purity, expr.span);
20202020
}
20212021
_ {
2022-
tcx.sess.span_fatal(expr.span,
2022+
tcx.sess.span_err(expr.span,
20232023
"dereferencing non-" +
20242024
"dereferenceable type: " +
20252025
ty_to_str(tcx, oper_t));

src/comp/syntax/ast.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ enum def {
4747
def_binding(def_id),
4848
def_use(def_id),
4949
def_upvar(def_id, @def, node_id), // node_id == expr_fn or expr_fn_block
50+
def_class(def_id),
51+
// first def_id is for parent class
52+
def_class_field(def_id, def_id),
53+
// No purity allowed for now, I guess
54+
// (simpler this way, b/c presumably methods read mutable state)
55+
def_class_method(def_id, def_id)
5056
}
5157

5258
// The set of meta_items that define the compilation environment of the crate,
@@ -483,6 +489,7 @@ enum item_ {
483489
item_class([ty_param], /* ty params for class */
484490
[@class_item], /* methods, etc. */
485491
/* (not including ctor) */
492+
node_id,
486493
fn_decl, /* ctor decl */
487494
blk /* ctor body */
488495
),
@@ -491,12 +498,15 @@ enum item_ {
491498
@ty /* self */, [@method]),
492499
}
493500

494-
type class_item_ = {privacy: privacy, decl: @class_member};
501+
type class_item_ = {privacy: privacy, decl: class_member};
495502
type class_item = spanned<class_item_>;
496503

497504
enum class_member {
498505
instance_var(ident, @ty, class_mutability, node_id),
499-
class_method(@item)
506+
class_method(@item) // FIXME: methods aren't allowed to be
507+
// type-parametric.
508+
// without constrained types, have to duplicate some stuff. or factor out
509+
// item to separate out things with type params?
500510
}
501511

502512
enum class_mutability { class_mutable, class_immutable }

src/comp/syntax/ast_util.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ fn def_id_of_def(d: def) -> def_id {
3232
def_variant(_, id) | def_ty(id) | def_ty_param(id, _) |
3333
def_binding(id) | def_use(id) | def_upvar(id, _, _) { id }
3434
def_prim_ty(_) { fail; }
35+
_ { fail "Dead"; }
3536
}
3637
}
3738

src/comp/syntax/fold.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ fn noop_fold_class_item(&&ci: @class_item, fld: ast_fold)
227227
@{node: {
228228
privacy:ci.node.privacy,
229229
decl:
230-
@alt *ci.node.decl {
230+
alt ci.node.decl {
231231
instance_var(ident, t, cm, id) {
232232
instance_var(ident, fld.fold_ty(t), cm, id)
233233
}
@@ -249,9 +249,10 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
249249
item_enum(variants, typms) {
250250
item_enum(vec::map(variants, fld.fold_variant), typms)
251251
}
252-
item_class(typms, items, ctor_decl, ctor_body) {
252+
item_class(typms, items, id, ctor_decl, ctor_body) {
253253
item_class(typms,
254254
vec::map(items, fld.fold_class_item),
255+
id,
255256
fold_fn_decl(ctor_decl, fld),
256257
fld.fold_block(ctor_body))
257258
}
@@ -617,7 +618,7 @@ fn make_fold(afp: ast_fold_precursor) -> ast_fold {
617618
@{node:
618619
{privacy:ci.node.privacy,
619620
decl:
620-
@alt *ci.node.decl {
621+
alt ci.node.decl {
621622
instance_var(nm, t, mt, id) {
622623
instance_var(nm, f_ty(afp, f, t),
623624
mt, id)

src/comp/syntax/parse/parser.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1965,27 +1965,29 @@ fn parse_item_class(p: parser, attrs: [ast::attribute]) -> @ast::item {
19651965
let ty_params = parse_ty_params(p);
19661966
expect(p, token::LBRACE);
19671967
let items: [@ast::class_item] = [];
1968+
let ctor_id = p.get_id();
19681969
let the_ctor : option<(ast::fn_decl, ast::blk)> = none;
19691970
while p.token != token::RBRACE {
19701971
alt parse_class_item(p) {
19711972
ctor_decl(a_fn_decl, blk) {
19721973
the_ctor = some((a_fn_decl, blk));
19731974
}
19741975
plain_decl(a_decl) {
1975-
items += [@{node: {privacy: ast::pub, decl: a_decl},
1976+
items += [@{node: {privacy: ast::pub, decl: *a_decl},
19761977
span: p.last_span}];
19771978
}
19781979
priv_decls(some_decls) {
19791980
items += vec::map(some_decls, {|d|
1980-
@{node: {privacy: ast::priv, decl: d},
1981+
@{node: {privacy: ast::priv, decl: *d},
19811982
span: p.last_span}});
19821983
}
19831984
}
19841985
}
19851986
p.bump();
19861987
alt the_ctor {
19871988
some((ct_d, ct_b)) { ret mk_item(p, lo, p.last_span.hi, class_name,
1988-
ast::item_class(ty_params, items, ct_d, ct_b), attrs); }
1989+
ast::item_class(ty_params, items, ctor_id,
1990+
ct_d, ct_b), attrs); }
19891991
/*
19901992
Is it strange for the parser to check this?
19911993
*/

src/comp/syntax/print/pprust.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ fn print_item(s: ps, &&item: @ast::item) {
470470
bclose(s, item.span);
471471
}
472472
}
473-
ast::item_class(tps,items,ctor_decl,ctor_body) {
473+
ast::item_class(tps,items,_,ctor_decl,ctor_body) {
474474
head(s, "class");
475475
word_nbsp(s, item.ident);
476476
print_type_params(s, tps);
@@ -494,7 +494,7 @@ fn print_item(s: ps, &&item: @ast::item) {
494494
}
495495
_ {}
496496
}
497-
alt *ci.node.decl {
497+
alt ci.node.decl {
498498
ast::instance_var(nm, t, mt, _) {
499499
word_nbsp(s, "let");
500500
alt mt {

src/comp/syntax/visit.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type visitor<E> =
5555
visit_ty_params: fn@([ty_param], E, vt<E>),
5656
visit_constr: fn@(@path, span, node_id, E, vt<E>),
5757
visit_fn: fn@(fn_kind, fn_decl, blk, span, node_id, E, vt<E>),
58-
visit_class_item: fn@(span, privacy, @class_member, E, vt<E>)};
58+
visit_class_item: fn@(span, privacy, class_member, E, vt<E>)};
5959

6060
fn default_visitor<E>() -> visitor<E> {
6161
ret @{visit_mod: bind visit_mod::<E>(_, _, _, _, _),
@@ -137,7 +137,7 @@ fn visit_item<E>(i: @item, e: E, v: vt<E>) {
137137
m.id, e, v);
138138
}
139139
}
140-
item_class(tps, members, ctor_decl, ctor_blk) {
140+
item_class(tps, members, _, ctor_decl, ctor_blk) {
141141
v.visit_ty_params(tps, e, v);
142142
for m in members {
143143
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>) {
155155
}
156156
}
157157

158-
fn visit_class_item<E>(_s: span, _p: privacy, cm: @class_member,
158+
fn visit_class_item<E>(_s: span, _p: privacy, cm: class_member,
159159
e:E, v:vt<E>) {
160-
alt *cm {
160+
alt cm {
161161
instance_var(ident, t, mt, id) {
162162
v.visit_ty(t, e, v);
163163
}
@@ -409,7 +409,7 @@ type simple_visitor =
409409
visit_ty_params: fn@([ty_param]),
410410
visit_constr: fn@(@path, span, node_id),
411411
visit_fn: fn@(fn_kind, fn_decl, blk, span, node_id),
412-
visit_class_item: fn@(span, privacy, @class_member)};
412+
visit_class_item: fn@(span, privacy, class_member)};
413413

414414
fn simple_ignore_ty(_t: @ty) {}
415415

@@ -430,7 +430,7 @@ fn default_simple_visitor() -> simple_visitor {
430430
visit_constr: fn@(_p: @path, _sp: span, _id: node_id) { },
431431
visit_fn: fn@(_fk: fn_kind, _d: fn_decl, _b: blk, _sp: span,
432432
_id: node_id) { },
433-
visit_class_item: fn@(_s: span, _p: privacy, _c: @class_member) {}
433+
visit_class_item: fn@(_s: span, _p: privacy, _c: class_member) {}
434434
};
435435
}
436436

@@ -505,8 +505,8 @@ fn mk_simple_visitor(v: simple_visitor) -> vt<()> {
505505
} else {
506506
bind v_ty(v.visit_ty, _, _, _)
507507
};
508-
fn v_class_item(f: fn@(span, privacy, @class_member),
509-
s:span, p:privacy, cm: @class_member, &&e: (),
508+
fn v_class_item(f: fn@(span, privacy, class_member),
509+
s:span, p:privacy, cm: class_member, &&e: (),
510510
v: vt<()>) {
511511
f(s, p, cm);
512512
visit_class_item(s, p, cm, e, v);

0 commit comments

Comments
 (0)