Skip to content

Commit e2fa6f0

Browse files
committed
Translate simple classes
Programs using classes with fields only (no methods) compile and run, as long as nothing refers to a class in a different crate (todo). Also changed the AST representation of classes to have a separate record for constructor info (instead of inlining the fields in the item_class node), and fixed up spans and pretty-printing for classes.
1 parent 1d826b7 commit e2fa6f0

File tree

18 files changed

+493
-232
lines changed

18 files changed

+493
-232
lines changed

src/rustc/metadata/astencode_gen.rs

Lines changed: 179 additions & 125 deletions
Large diffs are not rendered by default.

src/rustc/metadata/encoder.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ fn encode_module_item_paths(ebml_w: ebml::writer, module: _mod, path: [str],
127127
encode_def_id(ebml_w, local_def(it.id));
128128
ebml_w.end_tag();
129129
}
130-
item_class(_,_,_,_,_) {
130+
item_class(_,_,_) {
131131
fail "encode: implement item_class";
132132
}
133133
item_enum(variants, tps) {
@@ -384,7 +384,7 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: ebml::writer, item: @item,
384384
encode_enum_variant_info(ecx, ebml_w, item.id, variants,
385385
path, index, tps);
386386
}
387-
item_class(_,_,_,_,_) {
387+
item_class(_,_,_) {
388388
fail "encode: implement item_class";
389389
}
390390
item_res(_, tps, _, _, ctor_id) {

src/rustc/middle/resolve.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -541,12 +541,12 @@ fn visit_item_with_scope(e: @env, i: @ast::item, sc: scopes, v: vt<scopes>) {
541541
v.visit_ty(m.decl.output, msc, v);
542542
}
543543
}
544-
ast::item_class(tps, members, ctor_id, ctor_decl, ctor_block) {
544+
ast::item_class(tps, members, ctor) {
545545
visit::visit_ty_params(tps, sc, v);
546546
let class_scope = cons(scope_item(i), @sc);
547547
/* visit the constructor... */
548-
visit_fn_with_scope(e, visit::fk_item_fn(i.ident, tps), ctor_decl,
549-
ctor_block, ctor_block.span, ctor_id,
548+
visit_fn_with_scope(e, visit::fk_item_fn(i.ident, tps), ctor.node.dec,
549+
ctor.node.body, ctor.span, ctor.node.id,
550550
class_scope, v);
551551
/* visit the items */
552552
for cm in members {
@@ -1029,12 +1029,12 @@ fn lookup_in_scope(e: env, sc: scopes, sp: span, name: ident, ns: namespace)
10291029
ast::item_native_mod(m) {
10301030
ret lookup_in_local_native_mod(e, it.id, sp, name, ns);
10311031
}
1032-
ast::item_class(tps, members, ctor_id, _, _) {
1032+
ast::item_class(tps, members, ctor) {
10331033
if ns == ns_type {
10341034
ret lookup_in_ty_params(e, name, tps);
10351035
}
10361036
if ns == ns_val(value_or_enum) && name == it.ident {
1037-
ret some(ast::def_fn(local_def(ctor_id),
1037+
ret some(ast::def_fn(local_def(ctor.node.id),
10381038
ast::impure_fn));
10391039
}
10401040
if ns == ns_val(value_or_enum) {
@@ -1359,7 +1359,7 @@ fn found_def_item(i: @ast::item, ns: namespace) -> option<def> {
13591359
_ { }
13601360
}
13611361
}
1362-
ast::item_class(_, _, _, _, _) {
1362+
ast::item_class(_, _, _) {
13631363
if ns == ns_type {
13641364
ret some(ast::def_class(local_def(i.id)));
13651365
}
@@ -1664,16 +1664,16 @@ fn index_mod(md: ast::_mod) -> mod_index {
16641664
variant_idx += 1u;
16651665
}
16661666
}
1667-
ast::item_class(tps, items, ctor_id, ctor_decl, ctor_body) {
1667+
ast::item_class(tps, items, ctor) {
16681668
// add the class name itself
16691669
add_to_index(index, it.ident, mie_item(it));
16701670
// add the constructor decl
16711671
add_to_index(index, it.ident,
16721672
mie_item(@{ident: it.ident, attrs: [],
1673-
id: ctor_id,
1674-
node:
1675-
item_fn(ctor_decl, tps, ctor_body),
1676-
span: ctor_body.span}));
1673+
id: ctor.node.id,
1674+
node:
1675+
item_fn(ctor.node.dec, tps, ctor.node.body),
1676+
span: ctor.node.body.span}));
16771677
// add the members
16781678
for ci in items {
16791679
add_to_index(index, class_item_ident(ci),

0 commit comments

Comments
 (0)