Skip to content

Commit b079e1a

Browse files
committed
rustc: Parse "inline". Also write it into metadata.
1 parent c6bb04a commit b079e1a

File tree

3 files changed

+33
-13
lines changed

3 files changed

+33
-13
lines changed

src/comp/metadata/common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ const tag_crate_deps: uint = 0x25u;
6262
// A single crate dependency
6363
const tag_crate_dep: uint = 0x26u;
6464

65+
const tag_items_data_item_inlineness: uint = 0x27u;
66+
6567
// djb's cdb hashes.
6668
fn hash_node_id(node_id: &int) -> uint { ret 177573u ^ (node_id as uint); }
6769

src/comp/metadata/encoder.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,12 @@ fn encode_family(ebml_w: &ebmlivec::writer, c: u8) {
166166
ebmlivec::end_tag(ebml_w);
167167
}
168168

169+
fn encode_inlineness(ebml_w: &ebmlivec::writer, c: u8) {
170+
ebmlivec::start_tag(ebml_w, tag_items_data_item_inlineness);
171+
ebml_w.writer.write(~[c]);
172+
ebmlivec::end_tag(ebml_w);
173+
}
174+
169175
fn def_to_str(did: &def_id) -> str { ret #fmt("%d:%d", did.crate, did.node); }
170176

171177
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,
256262
encode_family(ebml_w,
257263
alt fd.decl.purity { pure_fn. { 'p' } impure_fn. { 'f' } }
258264
as u8);
265+
encode_inlineness(ebml_w,
266+
alt fd.decl.il {
267+
il_normal. { 'n' }
268+
il_inline. { 'i' }
269+
} as u8);
259270
encode_type_param_kinds(ebml_w, tps);
260271
encode_type(ecx, ebml_w, node_id_to_monotype(ecx.ccx.tcx, item.id));
261272
encode_symbol(ecx, ebml_w, item.id);

src/comp/syntax/parse/parser.rs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,7 +1285,7 @@ fn parse_if_expr(p: &parser) -> @ast::expr {
12851285

12861286
fn parse_fn_expr(p: &parser, proto: ast::proto) -> @ast::expr {
12871287
let lo = p.get_last_lo_pos();
1288-
let decl = parse_fn_decl(p, ast::impure_fn);
1288+
let decl = parse_fn_decl(p, ast::impure_fn, ast::il_normal);
12891289
let body = parse_block(p);
12901290
let _fn = {decl: decl, proto: proto, body: body};
12911291
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[] {
17061706
ret ty_params;
17071707
}
17081708

1709-
fn parse_fn_decl(p: &parser, purity: ast::purity) -> ast::fn_decl {
1709+
fn parse_fn_decl(p: &parser, purity: ast::purity, il: ast::inlineness)
1710+
-> ast::fn_decl {
17101711
let inputs: ast::spanned[ast::arg[]] =
17111712
parse_seq(token::LPAREN, token::RPAREN, some(token::COMMA), parse_arg,
17121713
p);
@@ -1730,23 +1731,24 @@ fn parse_fn_decl(p: &parser, purity: ast::purity) -> ast::fn_decl {
17301731
ret {inputs: inputs.node,
17311732
output: t,
17321733
purity: purity,
1733-
il: ast::il_normal,
1734+
il: il,
17341735
cf: ast::return,
17351736
constraints: constrs};
17361737
}
17371738
a_bang. {
17381739
ret {inputs: inputs.node,
17391740
output: @spanned(p.get_lo_pos(), p.get_hi_pos(), ast::ty_bot),
17401741
purity: purity,
1741-
il: ast::il_normal,
1742+
il: il,
17421743
cf: ast::noreturn,
17431744
constraints: constrs};
17441745
}
17451746
}
17461747
}
17471748

1748-
fn parse_fn(p: &parser, proto: ast::proto, purity: ast::purity) -> ast::_fn {
1749-
let decl = parse_fn_decl(p, purity);
1749+
fn parse_fn(p: &parser, proto: ast::proto, purity: ast::purity,
1750+
il: ast::inlineness) -> ast::_fn {
1751+
let decl = parse_fn_decl(p, purity, il);
17501752
let body = parse_block(p);
17511753
ret {decl: decl, proto: proto, body: body};
17521754
}
@@ -1767,10 +1769,11 @@ fn mk_item(p: &parser, lo: uint, hi: uint, ident: &ast::ident,
17671769
}
17681770

17691771
fn parse_item_fn_or_iter(p: &parser, purity: ast::purity, proto: ast::proto,
1770-
attrs: &ast::attribute[]) -> @ast::item {
1772+
attrs: &ast::attribute[], il: ast::inlineness)
1773+
-> @ast::item {
17711774
let lo = p.get_last_lo_pos();
17721775
let t = parse_fn_header(p);
1773-
let f = parse_fn(p, proto, purity);
1776+
let f = parse_fn(p, proto, purity, il);
17741777
ret mk_item(p, lo, f.body.span.hi, t.ident, ast::item_fn(f, t.tps),
17751778
attrs);
17761779
}
@@ -1797,7 +1800,7 @@ fn parse_method(p: &parser) -> @ast::method {
17971800
let lo = p.get_lo_pos();
17981801
let proto = parse_proto(p);
17991802
let ident = parse_value_ident(p);
1800-
let f = parse_fn(p, proto, ast::impure_fn);
1803+
let f = parse_fn(p, proto, ast::impure_fn, ast::il_normal);
18011804
let meth = {ident: ident, meth: f, id: p.get_id()};
18021805
ret @spanned(lo, f.body.span.hi, meth);
18031806
}
@@ -1910,7 +1913,7 @@ fn parse_item_native_fn(p: &parser, attrs: &ast::attribute[]) ->
19101913
@ast::native_item {
19111914
let lo = p.get_last_lo_pos();
19121915
let t = parse_fn_header(p);
1913-
let decl = parse_fn_decl(p, ast::impure_fn);
1916+
let decl = parse_fn_decl(p, ast::impure_fn, ast::il_normal);
19141917
let link_name = none;
19151918
if p.peek() == token::EQ { p.bump(); link_name = some(parse_str(p)); }
19161919
let hi = p.get_hi_pos();
@@ -2071,16 +2074,20 @@ fn parse_auth(p: &parser) -> ast::_auth {
20712074
fn parse_item(p: &parser, attrs: &ast::attribute[]) -> option::t[@ast::item] {
20722075
if eat_word(p, "const") {
20732076
ret some(parse_item_const(p, attrs));
2077+
} else if (eat_word(p, "inline")) {
2078+
expect_word(p, "fn");
2079+
ret some(parse_item_fn_or_iter(p, ast::impure_fn, ast::proto_fn,
2080+
attrs, ast::il_inline));
20742081
} else if (is_word(p, "fn") && p.look_ahead(1u) != token::LPAREN) {
20752082
p.bump();
20762083
ret some(parse_item_fn_or_iter(p, ast::impure_fn, ast::proto_fn,
2077-
attrs));
2084+
attrs, ast::il_normal));
20782085
} else if (eat_word(p, "pred")) {
20792086
ret some(parse_item_fn_or_iter(p, ast::pure_fn, ast::proto_fn,
2080-
attrs));
2087+
attrs, ast::il_normal));
20812088
} else if (eat_word(p, "iter")) {
20822089
ret some(parse_item_fn_or_iter(p, ast::impure_fn, ast::proto_iter,
2083-
attrs));
2090+
attrs, ast::il_normal));
20842091
} else if (eat_word(p, "mod")) {
20852092
ret some(parse_item_mod(p, attrs));
20862093
} else if (eat_word(p, "native")) {

0 commit comments

Comments
 (0)