diff options
| author | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-02-07 16:40:07 -0800 |
|---|---|---|
| committer | Tim Chevalier <chevalier@alum.wellesley.edu> | 2012-02-08 15:21:45 -0800 |
| commit | 48769b57e0f184ff42f5226641447e41cf3053a7 (patch) | |
| tree | d6434a733e8d66e0754d46f5b8e5c5b8b23d3cff /src/comp/syntax | |
| parent | 6e680e36a70e94f307928fee1c99b29a28eeba6e (diff) | |
| download | rust-48769b57e0f184ff42f5226641447e41cf3053a7.tar.gz rust-48769b57e0f184ff42f5226641447e41cf3053a7.zip | |
A bit more WIP on classes, and some cleanup in resolve
Diffstat (limited to 'src/comp/syntax')
| -rw-r--r-- | src/comp/syntax/ast_util.rs | 11 | ||||
| -rw-r--r-- | src/comp/syntax/fold.rs | 2 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 19 |
3 files changed, 19 insertions, 13 deletions
diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs index 3046ba02907..d0cfb5ee848 100644 --- a/src/comp/syntax/ast_util.rs +++ b/src/comp/syntax/ast_util.rs @@ -30,9 +30,9 @@ fn def_id_of_def(d: def) -> def_id { def_fn(id, _) | def_self(id) | def_mod(id) | def_native_mod(id) | def_const(id) | def_arg(id, _) | def_local(id, _) | def_variant(_, id) | def_ty(id) | def_ty_param(id, _) | - def_binding(id) | def_use(id) | def_upvar(id, _, _) { id } + def_binding(id) | def_use(id) | def_upvar(id, _, _) | + def_class(id) | def_class_field(_, id) | def_class_method(_, id) { id } def_prim_ty(_) { fail; } - _ { fail "Dead"; } } } @@ -374,6 +374,13 @@ pure fn unguarded_pat(a: arm) -> option<[@pat]> { // for reserving this id. fn op_expr_callee_id(e: @expr) -> node_id { e.id - 1 } +pure fn class_item_ident(ci: @class_item) -> ident { + alt ci.node.decl { + instance_var(i,_,_,_) { i } + class_method(it) { it.ident } + } +} + // Local Variables: // mode: rust // fill-column: 78; diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs index 723a70741ab..09c9a46e73f 100644 --- a/src/comp/syntax/fold.rs +++ b/src/comp/syntax/fold.rs @@ -618,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 dab6be43e2f..d15c333c5fe 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -1580,7 +1580,7 @@ fn parse_let(p: parser) -> @ast::decl { ret @spanned(lo, p.last_span.hi, ast::decl_local(locals)); } -fn parse_instance_var(p:parser) -> @ast::class_member { +fn parse_instance_var(p:parser) -> ast::class_member { let is_mut = ast::class_immutable; expect_word(p, "let"); if eat_word(p, "mutable") { @@ -1592,7 +1592,7 @@ fn parse_instance_var(p:parser) -> @ast::class_member { let name = parse_ident(p); expect(p, token::COLON); let ty = parse_ty(p, false); - ret @ast::instance_var(name, ty, is_mut, p.get_id()); + ret ast::instance_var(name, ty, is_mut, p.get_id()); } fn parse_stmt(p: parser, first_item_attrs: [ast::attribute]) -> @ast::stmt { @@ -1973,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}}); } } @@ -1986,8 +1986,7 @@ 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, ctor_id, - 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? */ @@ -2000,11 +1999,11 @@ fn parse_item_class(p: parser, attrs: [ast::attribute]) -> @ast::item { // we don't really want just the fn_decl... enum class_contents { ctor_decl(ast::fn_decl, ast::blk), // assumed to be public - plain_decl(@ast::class_member), + plain_decl(ast::class_member), // contents of a priv section -- // parse_class_item ensures that // none of these are a ctor decl - priv_decls([@ast::class_member])} + priv_decls([ast::class_member])} fn parse_class_item(p:parser) -> class_contents { if eat_word(p, "new") { @@ -2020,7 +2019,7 @@ fn parse_class_item(p:parser) -> class_contents { while p.token != token::RBRACE { alt parse_item(p, []) { some(i) { - results += [@ast::class_method(i)]; + results += [ast::class_method(i)]; } _ { let a_var = parse_instance_var(p); @@ -2036,7 +2035,7 @@ fn parse_class_item(p:parser) -> class_contents { // Probably need to parse attrs alt parse_item(p, []) { some(i) { - ret plain_decl(@ast::class_method(i)); + ret plain_decl(ast::class_method(i)); } _ { let a_var = parse_instance_var(p); |
