diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2011-08-05 11:33:09 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2011-08-05 11:33:48 -0700 |
| commit | 9b9170f9fe2e4701255a5bd0630c203409d8e934 (patch) | |
| tree | ea815ec0056056cc1b98500c3a3e25672401d6cb /src/comp/syntax | |
| parent | ad925955d889c791b81b00e5a0f1516dceb8684a (diff) | |
rustc: Introduce the concept of inline to the AST
Diffstat (limited to 'src/comp/syntax')
| -rw-r--r-- | src/comp/syntax/ast.rs | 4 | ||||
| -rw-r--r-- | src/comp/syntax/fold.rs | 2 | ||||
| -rw-r--r-- | src/comp/syntax/parse/parser.rs | 4 | ||||
| -rw-r--r-- | src/comp/syntax/print/pprust.rs | 2 | ||||
| -rw-r--r-- | src/comp/syntax/visit.rs | 47 |
5 files changed, 34 insertions, 25 deletions
diff --git a/src/comp/syntax/ast.rs b/src/comp/syntax/ast.rs index ff8e6c0893c..e36668d8e96 100644 --- a/src/comp/syntax/ast.rs +++ b/src/comp/syntax/ast.rs @@ -604,9 +604,11 @@ type attribute_ = {style: attr_style, value: meta_item}; type item = // For objs and resources, this is the type def_id {ident: ident, attrs: attribute[], id: node_id, node: item_, span: span}; +tag inlineness { il_normal; il_inline; } + tag item_ { item_const(@ty, @expr); - item_fn(_fn, ty_param[]); + item_fn(_fn, ty_param[], inlineness); item_mod(_mod); item_native_mod(native_mod); item_ty(@ty, ty_param[]); diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs index e2bb0380c04..361c54d87ad 100644 --- a/src/comp/syntax/fold.rs +++ b/src/comp/syntax/fold.rs @@ -223,7 +223,7 @@ fn noop_fold_item_underscore(i: &item_, fld: ast_fold) -> item_ { ret alt i { item_const(t, e) { item_const(fld.fold_ty(t), fld.fold_expr(e)) } - item_fn(f, typms) { item_fn(fld.fold_fn(f), typms) } + item_fn(f, typms, il) { item_fn(fld.fold_fn(f), typms, il) } item_mod(m) { item_mod(fld.fold_mod(m)) } item_native_mod(nm) { item_native_mod(fld.fold_native_mod(nm)) } item_ty(t, typms) { item_ty(fld.fold_ty(t), typms) } diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs index 9e7f693c74b..71a148c5337 100644 --- a/src/comp/syntax/parse/parser.rs +++ b/src/comp/syntax/parse/parser.rs @@ -1769,8 +1769,8 @@ fn parse_item_fn_or_iter(p: &parser, purity: ast::purity, proto: ast::proto, let lo = p.get_last_lo_pos(); let t = parse_fn_header(p); let f = parse_fn(p, proto, purity); - ret mk_item(p, lo, f.body.span.hi, t.ident, ast::item_fn(f, t.tps), - attrs); + ret mk_item(p, lo, f.body.span.hi, t.ident, + ast::item_fn(f, t.tps, ast::il_normal), attrs); } fn parse_obj_field(p: &parser) -> ast::obj_field { diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs index dab764c5baa..f47e3bfb8c8 100644 --- a/src/comp/syntax/print/pprust.rs +++ b/src/comp/syntax/print/pprust.rs @@ -412,7 +412,7 @@ fn print_item(s: &ps, item: &@ast::item) { end(s); // end the outer cbox } - ast::item_fn(_fn, typarams) { + ast::item_fn(_fn, typarams, _) { print_fn(s, _fn.decl, _fn.proto, item.ident, typarams, _fn.decl.constraints); word(s.s, " "); diff --git a/src/comp/syntax/visit.rs b/src/comp/syntax/visit.rs index 673fa46d466..6a63a8c935f 100644 --- a/src/comp/syntax/visit.rs +++ b/src/comp/syntax/visit.rs @@ -33,7 +33,9 @@ type visitor[E] = visit_ty: fn(&@ty, &E, &vt[E]) , visit_constr: fn(&path, &span, node_id, &E, &vt[E]) , visit_fn: - fn(&_fn, &ty_param[], &span, &fn_ident, node_id, &E, &vt[E]) }; + fn(&_fn, &ty_param[], inlineness, &span, &fn_ident, node_id, &E, + &vt[E]) + }; fn default_visitor[E]() -> visitor[E] { ret @{visit_mod: bind visit_mod[E](_, _, _, _), @@ -49,7 +51,7 @@ fn default_visitor[E]() -> visitor[E] { visit_expr: bind visit_expr[E](_, _, _), visit_ty: bind visit_ty[E](_, _, _), visit_constr: bind visit_constr[E](_, _, _, _, _), - visit_fn: bind visit_fn[E](_, _, _, _, _, _, _)}; + visit_fn: bind visit_fn[E](_, _, _, _, _, _, _, _)}; } fn visit_crate[E](c: &crate, e: &E, v: &vt[E]) { @@ -86,7 +88,9 @@ fn visit_local[E](loc: &@local, e: &E, v: &vt[E]) { fn visit_item[E](i: &@item, e: &E, v: &vt[E]) { alt i.node { item_const(t, ex) { v.visit_ty(t, e, v); v.visit_expr(ex, e, v); } - item_fn(f, tp) { v.visit_fn(f, tp, i.span, some(i.ident), i.id, e, v); } + item_fn(f, tp, il) { + v.visit_fn(f, tp, il, i.span, some(i.ident), i.id, e, v); + } item_mod(m) { v.visit_mod(m, i.span, e, v); } item_native_mod(nm) { for vi: @view_item in nm.view_items { v.visit_view_item(vi, e, v); } @@ -94,7 +98,7 @@ fn visit_item[E](i: &@item, e: &E, v: &vt[E]) { } item_ty(t, _) { v.visit_ty(t, e, v); } item_res(f, dtor_id, tps, _) { - v.visit_fn(f, tps, i.span, some(i.ident), dtor_id, e, v); + v.visit_fn(f, tps, il_normal, i.span, some(i.ident), dtor_id, e, v); } item_tag(variants, _) { for vr: variant in variants { @@ -104,8 +108,8 @@ fn visit_item[E](i: &@item, e: &E, v: &vt[E]) { item_obj(ob, _, _) { for f: obj_field in ob.fields { v.visit_ty(f.ty, e, v); } for m: @method in ob.methods { - v.visit_fn(m.node.meth, ~[], m.span, some(m.node.ident), - m.node.id, e, v); + v.visit_fn(m.node.meth, ~[], il_normal, m.span, + some(m.node.ident), m.node.id, e, v); } } } @@ -195,8 +199,8 @@ fn visit_fn_decl[E](fd: &fn_decl, e: &E, v: &vt[E]) { v.visit_ty(fd.output, e, v); } -fn visit_fn[E](f: &_fn, tp: &ty_param[], sp: &span, i: &fn_ident, id: node_id, - e: &E, v: &vt[E]) { +fn visit_fn[E](f: &_fn, tp: &ty_param[], il: inlineness, sp: &span, + i: &fn_ident, id: node_id, e: &E, v: &vt[E]) { visit_fn_decl(f.decl, e, v); v.visit_block(f.body, e, v); } @@ -290,7 +294,9 @@ fn visit_expr[E](ex: &@expr, e: &E, v: &vt[E]) { v.visit_expr(x, e, v); for a: arm in arms { v.visit_arm(a, e, v); } } - expr_fn(f) { v.visit_fn(f, ~[], ex.span, none, ex.id, e, v); } + expr_fn(f) { + v.visit_fn(f, ~[], il_normal, ex.span, none, ex.id, e, v); + } expr_block(b) { v.visit_block(b, e, v); } expr_assign(a, b) { v.visit_expr(b, e, v); v.visit_expr(a, e, v); } expr_move(a, b) { v.visit_expr(b, e, v); v.visit_expr(a, e, v); } @@ -330,8 +336,8 @@ fn visit_expr[E](ex: &@expr, e: &E, v: &vt[E]) { some(ex) { v.visit_expr(ex, e, v); } } for m: @method in anon_obj.methods { - v.visit_fn(m.node.meth, ~[], m.span, some(m.node.ident), - m.node.id, e, v); + v.visit_fn(m.node.meth, ~[], il_normal, m.span, + some(m.node.ident), m.node.id, e, v); } } expr_mac(mac) { visit_mac(mac, e, v); } @@ -362,7 +368,8 @@ type simple_visitor = visit_expr: fn(&@expr) , visit_ty: fn(&@ty) , visit_constr: fn(&path, &span, node_id) , - visit_fn: fn(&_fn, &ty_param[], &span, &fn_ident, node_id) }; + visit_fn: fn(&_fn, &ty_param[], inlineness, &span, &fn_ident, node_id) + }; fn default_simple_visitor() -> simple_visitor { ret @{visit_mod: fn (m: &_mod, sp: &span) { }, @@ -379,8 +386,8 @@ fn default_simple_visitor() -> simple_visitor { visit_ty: fn (t: &@ty) { }, visit_constr: fn (p: &path, sp: &span, id: node_id) { }, visit_fn: - fn (f: &_fn, tps: &ty_param[], sp: &span, ident: &fn_ident, - id: node_id) { + fn (f: &_fn, tps: &ty_param[], il: inlineness, sp: &span, + ident: &fn_ident, id: node_id) { }}; } @@ -439,11 +446,11 @@ fn mk_simple_visitor(v: &simple_visitor) -> vt[()] { f(pt, sp, id); visit_constr(pt, sp, id, e, v); } - fn v_fn(f: fn(&_fn, &ty_param[], &span, &fn_ident, node_id) , ff: &_fn, - tps: &ty_param[], sp: &span, ident: &fn_ident, id: node_id, - e: &(), v: &vt[()]) { - f(ff, tps, sp, ident, id); - visit_fn(ff, tps, sp, ident, id, e, v); + fn v_fn(f: fn(&_fn, &ty_param[], inlineness, &span, &fn_ident, node_id), + ff: &_fn, tps: &ty_param[], il: inlineness, sp: &span, + ident: &fn_ident, id: node_id, e: &(), v: &vt[()]) { + f(ff, tps, il, sp, ident, id); + visit_fn(ff, tps, il, sp, ident, id, e, v); } ret mk_vt(@{visit_mod: bind v_mod(v.visit_mod, _, _, _, _), visit_view_item: bind v_view_item(v.visit_view_item, _, _, _), @@ -459,7 +466,7 @@ fn mk_simple_visitor(v: &simple_visitor) -> vt[()] { visit_expr: bind v_expr(v.visit_expr, _, _, _), visit_ty: bind v_ty(v.visit_ty, _, _, _), visit_constr: bind v_constr(v.visit_constr, _, _, _, _, _), - visit_fn: bind v_fn(v.visit_fn, _, _, _, _, _, _, _)}); + visit_fn: bind v_fn(v.visit_fn, _, _, _, _, _, _, _, _)}); } // Local Variables: |
