about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2011-08-05 13:58:33 -0700
committerPatrick Walton <pcwalton@mimiga.net>2011-08-05 13:59:27 -0700
commitb079e1adbbfdd98b41d3c45e6f83941a7a3c106f (patch)
tree1e8fd8f5b2ff012649c7a3d5ecc6ac648ba90829 /src
parentc6bb04aba60649b7e126fd35474fab50359eb130 (diff)
downloadrust-b079e1adbbfdd98b41d3c45e6f83941a7a3c106f.tar.gz
rust-b079e1adbbfdd98b41d3c45e6f83941a7a3c106f.zip
rustc: Parse "inline". Also write it into metadata.
Diffstat (limited to 'src')
-rw-r--r--src/comp/metadata/common.rs2
-rw-r--r--src/comp/metadata/encoder.rs11
-rw-r--r--src/comp/syntax/parse/parser.rs33
3 files changed, 33 insertions, 13 deletions
diff --git a/src/comp/metadata/common.rs b/src/comp/metadata/common.rs
index 065f4dc66bc..128ebea3f28 100644
--- a/src/comp/metadata/common.rs
+++ b/src/comp/metadata/common.rs
@@ -62,6 +62,8 @@ const tag_crate_deps: uint = 0x25u;
 // A single crate dependency
 const tag_crate_dep: uint = 0x26u;
 
+const tag_items_data_item_inlineness: uint = 0x27u;
+
 // djb's cdb hashes.
 fn hash_node_id(node_id: &int) -> uint { ret 177573u ^ (node_id as uint); }
 
diff --git a/src/comp/metadata/encoder.rs b/src/comp/metadata/encoder.rs
index b9a1fa3886a..6649cca29a3 100644
--- a/src/comp/metadata/encoder.rs
+++ b/src/comp/metadata/encoder.rs
@@ -166,6 +166,12 @@ fn encode_family(ebml_w: &ebmlivec::writer, c: u8) {
     ebmlivec::end_tag(ebml_w);
 }
 
+fn encode_inlineness(ebml_w: &ebmlivec::writer, c: u8) {
+    ebmlivec::start_tag(ebml_w, tag_items_data_item_inlineness);
+    ebml_w.writer.write(~[c]);
+    ebmlivec::end_tag(ebml_w);
+}
+
 fn def_to_str(did: &def_id) -> str { ret #fmt("%d:%d", did.crate, did.node); }
 
 fn encode_type_param_kinds(ebml_w: &ebmlivec::writer, tps: &ty_param[]) {
@@ -256,6 +262,11 @@ fn encode_info_for_item(ecx: @encode_ctxt, ebml_w: &ebmlivec::writer,
         encode_family(ebml_w,
                     alt fd.decl.purity { pure_fn. { 'p' } impure_fn. { 'f' } }
                         as u8);
+        encode_inlineness(ebml_w,
+                          alt fd.decl.il {
+                            il_normal. { 'n' }
+                            il_inline. { 'i' }
+                          } as u8);
         encode_type_param_kinds(ebml_w, tps);
         encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
         encode_symbol(ecx, ebml_w, item.id);
diff --git a/src/comp/syntax/parse/parser.rs b/src/comp/syntax/parse/parser.rs
index 125c6f04852..f0b25eb9a53 100644
--- a/src/comp/syntax/parse/parser.rs
+++ b/src/comp/syntax/parse/parser.rs
@@ -1285,7 +1285,7 @@ fn parse_if_expr(p: &parser) -> @ast::expr {
 
 fn parse_fn_expr(p: &parser, proto: ast::proto) -> @ast::expr {
     let lo = p.get_last_lo_pos();
-    let decl = parse_fn_decl(p, ast::impure_fn);
+    let decl = parse_fn_decl(p, ast::impure_fn, ast::il_normal);
     let body = parse_block(p);
     let _fn = {decl: decl, proto: proto, body: body};
     ret mk_expr(p, lo, body.span.hi, ast::expr_fn(_fn));
@@ -1706,7 +1706,8 @@ fn parse_ty_params(p: &parser) -> ast::ty_param[] {
     ret ty_params;
 }
 
-fn parse_fn_decl(p: &parser, purity: ast::purity) -> ast::fn_decl {
+fn parse_fn_decl(p: &parser, purity: ast::purity, il: ast::inlineness)
+        -> ast::fn_decl {
     let inputs: ast::spanned[ast::arg[]] =
         parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_arg,
                   p);
@@ -1730,7 +1731,7 @@ fn parse_fn_decl(p: &parser, purity: ast::purity) -> ast::fn_decl {
         ret {inputs: inputs.node,
              output: t,
              purity: purity,
-             il: ast::il_normal,
+             il: il,
              cf: ast::return,
              constraints: constrs};
       }
@@ -1738,15 +1739,16 @@ fn parse_fn_decl(p: &parser, purity: ast::purity) -> ast::fn_decl {
         ret {inputs: inputs.node,
              output: @spanned(p.get_lo_pos(), p.get_hi_pos(), ast::ty_bot),
              purity: purity,
-             il: ast::il_normal,
+             il: il,
              cf: ast::noreturn,
              constraints: constrs};
       }
     }
 }
 
-fn parse_fn(p: &parser, proto: ast::proto, purity: ast::purity) -> ast::_fn {
-    let decl = parse_fn_decl(p, purity);
+fn parse_fn(p: &parser, proto: ast::proto, purity: ast::purity,
+            il: ast::inlineness) -> ast::_fn {
+    let decl = parse_fn_decl(p, purity, il);
     let body = parse_block(p);
     ret {decl: decl, proto: proto, body: body};
 }
@@ -1767,10 +1769,11 @@ fn mk_item(p: &parser, lo: uint, hi: uint, ident: &ast::ident,
 }
 
 fn parse_item_fn_or_iter(p: &parser, purity: ast::purity, proto: ast::proto,
-                         attrs: &ast::attribute[]) -> @ast::item {
+                         attrs: &ast::attribute[], il: ast::inlineness)
+        -> @ast::item {
     let lo = p.get_last_lo_pos();
     let t = parse_fn_header(p);
-    let f = parse_fn(p, proto, purity);
+    let f = parse_fn(p, proto, purity, il);
     ret mk_item(p, lo, f.body.span.hi, t.ident, ast::item_fn(f, t.tps),
                 attrs);
 }
@@ -1797,7 +1800,7 @@ fn parse_method(p: &parser) -> @ast::method {
     let lo = p.get_lo_pos();
     let proto = parse_proto(p);
     let ident = parse_value_ident(p);
-    let f = parse_fn(p, proto, ast::impure_fn);
+    let f = parse_fn(p, proto, ast::impure_fn, ast::il_normal);
     let meth = {ident: ident, meth: f, id: p.get_id()};
     ret @spanned(lo, f.body.span.hi, meth);
 }
@@ -1910,7 +1913,7 @@ fn parse_item_native_fn(p: &parser, attrs: &ast::attribute[]) ->
    @ast::native_item {
     let lo = p.get_last_lo_pos();
     let t = parse_fn_header(p);
-    let decl = parse_fn_decl(p, ast::impure_fn);
+    let decl = parse_fn_decl(p, ast::impure_fn, ast::il_normal);
     let link_name = none;
     if p.peek() == token::EQ { p.bump(); link_name = some(parse_str(p)); }
     let hi = p.get_hi_pos();
@@ -2071,16 +2074,20 @@ fn parse_auth(p: &parser) -> ast::_auth {
 fn parse_item(p: &parser, attrs: &ast::attribute[]) -> option::t[@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_or_iter(p, ast::impure_fn, ast::proto_fn,
+                                       attrs, ast::il_inline));
     } else if (is_word(p, "fn") && p.look_ahead(1u) != token::LPAREN) {
         p.bump();
         ret some(parse_item_fn_or_iter(p, ast::impure_fn, ast::proto_fn,
-                                           attrs));
+                                       attrs, ast::il_normal));
     } else if (eat_word(p, "pred")) {
         ret some(parse_item_fn_or_iter(p, ast::pure_fn, ast::proto_fn,
-                                           attrs));
+                                       attrs, ast::il_normal));
     } else if (eat_word(p, "iter")) {
         ret some(parse_item_fn_or_iter(p, ast::impure_fn, ast::proto_iter,
-                                           attrs));
+                                       attrs, ast::il_normal));
     } else if (eat_word(p, "mod")) {
         ret some(parse_item_mod(p, attrs));
     } else if (eat_word(p, "native")) {