about summary refs log tree commit diff
path: root/src/comp/syntax
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-02-14 15:21:53 -0800
committerNiko Matsakis <niko@alum.mit.edu>2012-02-24 20:46:27 -0800
commitf3ca50c9ca4fd2084cfbc85030ff5ea21e589635 (patch)
tree026a63d77c1657e897e33adc6de3fedb7b36a341 /src/comp/syntax
parentbe9914625b0cbf5f305c5af3adbc6bc337ae760e (diff)
downloadrust-f3ca50c9ca4fd2084cfbc85030ff5ea21e589635.tar.gz
rust-f3ca50c9ca4fd2084cfbc85030ff5ea21e589635.zip
Encode/decode AST into metadata, re-instantiate inlined items
Diffstat (limited to 'src/comp/syntax')
-rw-r--r--src/comp/syntax/ast_util.rs8
-rw-r--r--src/comp/syntax/fold.rs79
-rw-r--r--src/comp/syntax/parse/parser.rs3
-rw-r--r--src/comp/syntax/print/pprust.rs2
4 files changed, 64 insertions, 28 deletions
diff --git a/src/comp/syntax/ast_util.rs b/src/comp/syntax/ast_util.rs
index 446f74c8680..d5b33971f8d 100644
--- a/src/comp/syntax/ast_util.rs
+++ b/src/comp/syntax/ast_util.rs
@@ -19,6 +19,14 @@ fn path_name_i(idents: [ident]) -> str { str::connect(idents, "::") }
 
 fn local_def(id: node_id) -> def_id { ret {crate: local_crate, node: id}; }
 
+fn stmt_id(s: stmt) -> node_id {
+    alt s.node {
+      stmt_decl(_, id) { id }
+      stmt_expr(_, id) { id }
+      stmt_semi(_, id) { id }
+    }
+}
+
 fn variant_def_ids(d: def) -> {enm: def_id, var: def_id} {
     alt d { def_variant(enum_id, var_id) {
             ret {enm: enum_id, var: var_id}; }
diff --git a/src/comp/syntax/fold.rs b/src/comp/syntax/fold.rs
index d161d27c020..00624bdf270 100644
--- a/src/comp/syntax/fold.rs
+++ b/src/comp/syntax/fold.rs
@@ -125,9 +125,10 @@ fn fold_attribute_(at: attribute, fmi: fn@(&&@meta_item) -> @meta_item) ->
 }
 //used in noop_fold_native_item and noop_fold_fn_decl
 fn fold_arg_(a: arg, fld: ast_fold) -> arg {
-    ret {ty: fld.fold_ty(a.ty),
-         ident: fld.fold_ident(a.ident)
-         with a};
+    ret {mode: a.mode,
+         ty: fld.fold_ty(a.ty),
+         ident: fld.fold_ident(a.ident),
+         id: fld.new_id(a.id)};
 }
 //used in noop_fold_expr, and possibly elsewhere in the future
 fn fold_mac_(m: mac, fld: ast_fold) -> mac {
@@ -156,6 +157,23 @@ fn fold_fn_decl(decl: ast::fn_decl, fld: ast_fold) -> ast::fn_decl {
          constraints: vec::map(decl.constraints, fld.fold_constr)}
 }
 
+fn fold_ty_param_bound(tpb: ty_param_bound, fld: ast_fold) -> ty_param_bound {
+    alt tpb {
+      bound_copy | bound_send { tpb }
+      bound_iface(ty) { bound_iface(fld.fold_ty(ty)) }
+    }
+}
+
+fn fold_ty_param(tp: ty_param, fld: ast_fold) -> ty_param {
+    {ident: tp.ident,
+     id: fld.new_id(tp.id),
+     bounds: @vec::map(*tp.bounds, fold_ty_param_bound(_, fld))}
+}
+
+fn fold_ty_params(tps: [ty_param], fld: ast_fold) -> [ty_param] {
+    vec::map(tps, fold_ty_param(_, fld))
+}
+
 fn noop_fold_crate(c: crate_, fld: ast_fold) -> crate_ {
     let fold_meta_item = bind fold_meta_item_(_, fld);
     let fold_attribute = bind fold_attribute_(_, fold_meta_item);
@@ -202,11 +220,12 @@ fn noop_fold_native_item(&&ni: @native_item, fld: ast_fold) -> @native_item {
                                   cf: fdec.cf,
                                   constraints:
                                       vec::map(fdec.constraints,
-                                               fld.fold_constr)}, typms)
+                                               fld.fold_constr)},
+                                 fold_ty_params(typms, fld))
                 }
               },
-          id: ni.id,
-          span: ni.span};
+          id: fld.new_id(ni.id),
+          span: fld.new_span(ni.span)};
 }
 
 fn noop_fold_item(&&i: @item, fld: ast_fold) -> @item {
@@ -215,9 +234,9 @@ fn noop_fold_item(&&i: @item, fld: ast_fold) -> @item {
 
     ret @{ident: fld.fold_ident(i.ident),
           attrs: vec::map(i.attrs, fold_attribute),
-          id: i.id,
+          id: fld.new_id(i.id),
           node: fld.fold_item_underscore(i.node),
-          span: i.span};
+          span: fld.new_span(i.span)};
 }
 
 fn noop_fold_class_item(&&ci: @class_item, fld: ast_fold)
@@ -238,17 +257,20 @@ 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(decl, typms, body) {
-              let body = fld.fold_block(body);
-              item_fn(fold_fn_decl(decl, fld), typms, body)
+              item_fn(fold_fn_decl(decl, fld),
+                      fold_ty_params(typms, fld),
+                      fld.fold_block(body))
           }
           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) }
+          item_ty(t, typms) { item_ty(fld.fold_ty(t),
+                                      fold_ty_params(typms, fld)) }
           item_enum(variants, typms) {
-            item_enum(vec::map(variants, fld.fold_variant), typms)
+            item_enum(vec::map(variants, fld.fold_variant),
+                      fold_ty_params(typms, fld))
           }
           item_class(typms, items, id, ctor_decl, ctor_body) {
-              item_class(typms,
+              item_class(fold_ty_params(typms, fld),
                          vec::map(items, fld.fold_class_item),
                          id,
                          fold_fn_decl(ctor_decl, fld),
@@ -260,16 +282,23 @@ fn noop_fold_item_underscore(i: item_, fld: ast_fold) -> item_ {
           }
           item_iface(tps, methods) { item_iface(tps, methods) }
           item_res(decl, typms, body, did, cid) {
-            item_res(fold_fn_decl(decl, fld), typms, fld.fold_block(body),
-                     did, cid)
+            item_res(fold_fn_decl(decl, fld),
+                     fold_ty_params(typms, fld),
+                     fld.fold_block(body),
+                     did,
+                     cid)
           }
         };
 }
 
 fn noop_fold_method(&&m: @method, fld: ast_fold) -> @method {
     ret @{ident: fld.fold_ident(m.ident),
+          attrs: m.attrs,
+          tps: fold_ty_params(m.tps, fld),
           decl: fold_fn_decl(m.decl, fld),
-          body: fld.fold_block(m.body) with *m};
+          body: fld.fold_block(m.body),
+          id: fld.new_id(m.id),
+          span: fld.new_span(m.span)};
 }
 
 
@@ -277,15 +306,15 @@ fn noop_fold_block(b: blk_, fld: ast_fold) -> blk_ {
     ret {view_items: vec::map(b.view_items, fld.fold_view_item),
          stmts: vec::map(b.stmts, fld.fold_stmt),
          expr: option::map(b.expr, fld.fold_expr),
-         id: b.id,
+         id: fld.new_id(b.id),
          rules: b.rules};
 }
 
 fn noop_fold_stmt(s: stmt_, fld: ast_fold) -> stmt_ {
     ret alt s {
-      stmt_decl(d, nid) { stmt_decl(fld.fold_decl(d), nid) }
-      stmt_expr(e, nid) { stmt_expr(fld.fold_expr(e), nid) }
-      stmt_semi(e, nid) { stmt_semi(fld.fold_expr(e), nid) }
+      stmt_decl(d, nid) { stmt_decl(fld.fold_decl(d), fld.new_id(nid)) }
+      stmt_expr(e, nid) { stmt_expr(fld.fold_expr(e), fld.new_id(nid)) }
+      stmt_semi(e, nid) { stmt_semi(fld.fold_expr(e), fld.new_id(nid)) }
     };
 }
 
@@ -459,7 +488,7 @@ fn noop_fold_ty(t: ty_, fld: ast_fold) -> ty_ {
 }
 
 fn noop_fold_constr(c: constr_, fld: ast_fold) -> constr_ {
-    {path: fld.fold_path(c.path), args: c.args, id: c.id}
+    {path: fld.fold_path(c.path), args: c.args, id: fld.new_id(c.id)}
 }
 
 // ...nor do modules
@@ -475,7 +504,7 @@ fn noop_fold_native_mod(nm: native_mod, fld: ast_fold) -> native_mod {
 
 fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
     fn fold_variant_arg_(va: variant_arg, fld: ast_fold) -> variant_arg {
-        ret {ty: fld.fold_ty(va.ty), id: va.id};
+        ret {ty: fld.fold_ty(va.ty), id: fld.new_id(va.id)};
     }
     let fold_variant_arg = bind fold_variant_arg_(_, fld);
     let args = vec::map(v.args, fold_variant_arg);
@@ -490,7 +519,7 @@ fn noop_fold_variant(v: variant_, fld: ast_fold) -> variant_ {
     };
     ret {name: v.name,
          attrs: attrs,
-         args: args, id: v.id,
+         args: args, id: fld.new_id(v.id),
          disr_expr: de};
 }
 
@@ -513,7 +542,7 @@ fn noop_fold_local(l: local_, fld: ast_fold) -> local_ {
                                               expr: fld.fold_expr(init.expr)})
                }
              },
-         id: l.id};
+         id: fld.new_id(l.id)};
 }
 
 /* temporarily eta-expand because of a compiler bug with using `fn<T>` as a
@@ -621,7 +650,7 @@ fn make_fold(afp: ast_fold_precursor) -> ast_fold {
            class_method(i) {
                class_method(afp.fold_item(i, f))
            }
-            }}, span: ci.span}
+            }}, span: afp.new_span(ci.span)}
     }
     fn f_item_underscore(afp: ast_fold_precursor, f: ast_fold, i: item_) ->
        item_ {
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 1a8fbdd917a..0de75d88422 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -2280,9 +2280,6 @@ fn fn_expr_lookahead(tok: token::token) -> bool {
 fn parse_item(p: parser, attrs: [ast::attribute]) -> option<@ast::item> {
     if eat_word(p, "const") {
         ret some(parse_item_const(p, attrs));
-    } else if eat_word(p, "inline") {
-        expect_word(p, "fn");
-        ret some(parse_item_fn(p, ast::impure_fn, attrs));
     } else if is_word(p, "fn") && !fn_expr_lookahead(p.look_ahead(1u)) {
         p.bump();
         ret some(parse_item_fn(p, ast::impure_fn, attrs));
diff --git a/src/comp/syntax/print/pprust.rs b/src/comp/syntax/print/pprust.rs
index 76ab2b4ecb5..5f92b5d5beb 100644
--- a/src/comp/syntax/print/pprust.rs
+++ b/src/comp/syntax/print/pprust.rs
@@ -89,6 +89,8 @@ fn stmt_to_str(s: ast::stmt) -> str { be to_str(s, print_stmt); }
 
 fn item_to_str(i: @ast::item) -> str { be to_str(i, print_item); }
 
+fn attr_to_str(i: ast::attribute) -> str { be to_str(i, print_attribute); }
+
 fn typarams_to_str(tps: [ast::ty_param]) -> str {
     be to_str(tps, print_type_params)
 }