auto merge of #6224 : erickt/rust/rustc-cleanup, r=erickt

Just a couple minor cleanups and renames of librustc
This commit is contained in:
bors 2013-05-14 22:57:37 -07:00
commit 217f96339a
56 changed files with 604 additions and 587 deletions

View File

@ -100,7 +100,7 @@ pub static tag_mod_impl_trait: uint = 0x47u;
different tags.
*/
pub static tag_item_impl_method: uint = 0x48u;
pub static tag_item_trait_method_self_ty: uint = 0x4b;
pub static tag_item_trait_method_explicit_self: uint = 0x4b;
pub static tag_item_trait_method_self_ty_region: uint = 0x4c;

View File

@ -22,7 +22,7 @@ use syntax::ast_map;
use syntax::diagnostic::expect;
pub struct ProvidedTraitMethodInfo {
ty: ty::method,
ty: ty::Method,
def_id: ast::def_id
}
@ -129,17 +129,18 @@ pub fn get_impls_for_mod(cstore: @mut cstore::CStore, def: ast::def_id,
}
pub fn get_method(tcx: ty::ctxt,
def: ast::def_id) -> ty::method
def: ast::def_id) -> ty::Method
{
let cdata = cstore::get_crate_data(tcx.cstore, def.crate);
decoder::get_method(tcx.cstore.intr, cdata, def.node, tcx)
}
pub fn get_method_name_and_self_ty(cstore: @mut cstore::CStore,
def: ast::def_id) -> (ast::ident, ast::self_ty_)
pub fn get_method_name_and_explicit_self(cstore: @mut cstore::CStore,
def: ast::def_id)
-> (ast::ident, ast::explicit_self_)
{
let cdata = cstore::get_crate_data(cstore, def.crate);
decoder::get_method_name_and_self_ty(cstore.intr, cdata, def.node)
decoder::get_method_name_and_explicit_self(cstore.intr, cdata, def.node)
}
pub fn get_trait_method_def_ids(cstore: @mut cstore::CStore,

View File

@ -653,7 +653,7 @@ pub fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id,
item, tcx, cdata);
let name = item_name(intr, item);
let arg_tys = match ty::get(ctor_ty).sty {
ty::ty_bare_fn(ref f) => f.sig.inputs.map(|a| a.ty),
ty::ty_bare_fn(ref f) => copy f.sig.inputs,
_ => ~[], // Nullary enum variant.
};
match variant_disr_val(item) {
@ -670,7 +670,7 @@ pub fn get_enum_variants(intr: @ident_interner, cdata: cmd, id: ast::node_id,
return infos;
}
fn get_self_ty(item: ebml::Doc) -> ast::self_ty_ {
fn get_explicit_self(item: ebml::Doc) -> ast::explicit_self_ {
fn get_mutability(ch: u8) -> ast::mutability {
match ch as char {
'i' => { ast::m_imm }
@ -682,11 +682,11 @@ fn get_self_ty(item: ebml::Doc) -> ast::self_ty_ {
}
}
let self_type_doc = reader::get_doc(item, tag_item_trait_method_self_ty);
let string = reader::doc_as_str(self_type_doc);
let explicit_self_doc = reader::get_doc(item, tag_item_trait_method_explicit_self);
let string = reader::doc_as_str(explicit_self_doc);
let self_ty_kind = string[0];
match self_ty_kind as char {
let explicit_self_kind = string[0];
match explicit_self_kind as char {
's' => { return ast::sty_static; }
'v' => { return ast::sty_value; }
'@' => { return ast::sty_box(get_mutability(string[1])); }
@ -696,7 +696,7 @@ fn get_self_ty(item: ebml::Doc) -> ast::self_ty_ {
return ast::sty_region(None, get_mutability(string[1]));
}
_ => {
fail!("unknown self type code: `%c`", self_ty_kind as char);
fail!("unknown self type code: `%c`", explicit_self_kind as char);
}
}
}
@ -707,12 +707,12 @@ fn item_impl_methods(intr: @ident_interner, cdata: cmd, item: ebml::Doc,
for reader::tagged_docs(item, tag_item_impl_method) |doc| {
let m_did = reader::with_doc_data(doc, |d| parse_def_id(d));
let mth_item = lookup_item(m_did.node, cdata.data);
let self_ty = get_self_ty(mth_item);
let explicit_self = get_explicit_self(mth_item);
rslt.push(@resolve::MethodInfo {
did: translate_def_id(cdata, m_did),
n_tps: item_ty_param_count(mth_item) - base_tps,
ident: item_name(intr, mth_item),
self_type: self_ty});
explicit_self: explicit_self});
}
rslt
}
@ -748,19 +748,19 @@ pub fn get_impls_for_mod(intr: @ident_interner,
@result
}
pub fn get_method_name_and_self_ty(
pub fn get_method_name_and_explicit_self(
intr: @ident_interner,
cdata: cmd,
id: ast::node_id) -> (ast::ident, ast::self_ty_)
id: ast::node_id) -> (ast::ident, ast::explicit_self_)
{
let method_doc = lookup_item(id, cdata.data);
let name = item_name(intr, method_doc);
let self_ty = get_self_ty(method_doc);
(name, self_ty)
let explicit_self = get_explicit_self(method_doc);
(name, explicit_self)
}
pub fn get_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
tcx: ty::ctxt) -> ty::method
tcx: ty::ctxt) -> ty::Method
{
let method_doc = lookup_item(id, cdata.data);
let def_id = item_def_id(method_doc, cdata);
@ -770,19 +770,20 @@ pub fn get_method(intr: @ident_interner, cdata: cmd, id: ast::node_id,
let transformed_self_ty = doc_transformed_self_ty(method_doc, tcx, cdata);
let fty = doc_method_fty(method_doc, tcx, cdata);
let vis = item_visibility(method_doc);
let self_ty = get_self_ty(method_doc);
ty::method {
ident: name,
generics: ty::Generics {
let explicit_self = get_explicit_self(method_doc);
ty::Method::new(
name,
ty::Generics {
type_param_defs: type_param_defs,
region_param: None
},
transformed_self_ty: transformed_self_ty,
fty: fty,
self_ty: self_ty,
vis: vis,
def_id: def_id
}
transformed_self_ty,
fty,
explicit_self,
vis,
def_id
)
}
pub fn get_trait_method_def_ids(cdata: cmd,
@ -823,19 +824,20 @@ pub fn get_provided_trait_methods(intr: @ident_interner, cdata: cmd,
};
let transformed_self_ty = doc_transformed_self_ty(mth, tcx, cdata);
let self_ty = get_self_ty(mth);
let ty_method = ty::method {
ident: name,
generics: ty::Generics {
let explicit_self = get_explicit_self(mth);
let ty_method = ty::Method::new(
name,
ty::Generics {
type_param_defs: type_param_defs,
region_param: None
},
transformed_self_ty: transformed_self_ty,
fty: fty,
self_ty: self_ty,
vis: ast::public,
def_id: did
};
transformed_self_ty,
fty,
explicit_self,
ast::public,
did
);
let provided_trait_method_info = ProvidedTraitMethodInfo {
ty: ty_method,
def_id: did

View File

@ -366,7 +366,7 @@ fn encode_path(ecx: @EncodeContext,
fn encode_reexported_static_method(ecx: @EncodeContext,
ebml_w: &mut writer::Encoder,
exp: &middle::resolve::Export2,
m: @ty::method) {
m: @ty::Method) {
debug!("(encode static trait method) reexport '%s::%s'",
*exp.name, *ecx.tcx.sess.str_of(m.ident));
ebml_w.start_tag(tag_items_data_item_reexport);
@ -389,7 +389,7 @@ fn encode_reexported_static_methods(ecx: @EncodeContext,
Some(&ast_map::node_item(_, path)) => {
if mod_path != *path {
for methods.each |&m| {
if m.self_ty == ast::sty_static {
if m.explicit_self == ast::sty_static {
encode_reexported_static_method(ecx,
ebml_w,
exp, m);
@ -486,11 +486,11 @@ fn encode_visibility(ebml_w: &mut writer::Encoder, visibility: visibility) {
ebml_w.end_tag();
}
fn encode_self_type(ebml_w: &mut writer::Encoder, self_type: ast::self_ty_) {
ebml_w.start_tag(tag_item_trait_method_self_ty);
fn encode_explicit_self(ebml_w: &mut writer::Encoder, explicit_self: ast::explicit_self_) {
ebml_w.start_tag(tag_item_trait_method_explicit_self);
// Encode the base self type.
match self_type {
match explicit_self {
sty_static => {
ebml_w.writer.write(&[ 's' as u8 ]);
}
@ -625,7 +625,7 @@ fn encode_info_for_struct_ctor(ecx: @EncodeContext,
fn encode_method_ty_fields(ecx: @EncodeContext,
ebml_w: &mut writer::Encoder,
method_ty: &ty::method) {
method_ty: &ty::Method) {
encode_def_id(ebml_w, method_ty.def_id);
encode_name(ecx, ebml_w, method_ty.ident);
encode_ty_type_param_defs(ebml_w, ecx,
@ -634,7 +634,7 @@ fn encode_method_ty_fields(ecx: @EncodeContext,
encode_transformed_self_ty(ecx, ebml_w, method_ty.transformed_self_ty);
encode_method_fty(ecx, ebml_w, &method_ty.fty);
encode_visibility(ebml_w, method_ty.vis);
encode_self_type(ebml_w, method_ty.self_ty);
encode_explicit_self(ebml_w, method_ty.explicit_self);
}
fn encode_info_for_method(ecx: @EncodeContext,
@ -652,10 +652,10 @@ fn encode_info_for_method(ecx: @EncodeContext,
ebml_w.start_tag(tag_items_data_item);
let method_def_id = local_def(m.id);
let method_ty: @ty::method = ty::method(ecx.tcx, method_def_id);
let method_ty = ty::method(ecx.tcx, method_def_id);
encode_method_ty_fields(ecx, ebml_w, method_ty);
match m.self_ty.node {
match m.explicit_self.node {
ast::sty_static => {
encode_family(ebml_w, purity_static_method_family(m.purity));
}
@ -948,7 +948,7 @@ fn encode_info_for_item(ecx: @EncodeContext,
for ty::trait_method_def_ids(tcx, local_def(item.id)).eachi |i, &method_def_id| {
assert!(method_def_id.crate == ast::local_crate);
let method_ty: @ty::method = ty::method(tcx, method_def_id);
let method_ty = ty::method(tcx, method_def_id);
index.push(entry {val: method_def_id.node, pos: ebml_w.writer.tell()});
@ -962,7 +962,7 @@ fn encode_info_for_item(ecx: @EncodeContext,
trait_path.push(ast_map::path_name(item.ident));
encode_path(ecx, ebml_w, trait_path, ast_map::path_name(method_ty.ident));
match method_ty.self_ty {
match method_ty.explicit_self {
sty_static => {
encode_family(ebml_w,
purity_static_method_family(
@ -991,7 +991,7 @@ fn encode_info_for_item(ecx: @EncodeContext,
// This is obviously a bogus assert but I don't think this
// ever worked before anyhow...near as I can tell, before
// we would emit two items.
if method_ty.self_ty == sty_static {
if method_ty.explicit_self == sty_static {
tcx.sess.span_unimpl(
item.span,
fmt!("Method %s is both provided and static",

View File

@ -126,12 +126,6 @@ pub fn parse_trait_ref_data(data: @~[u8], crate_num: int, pos: uint, tcx: ty::ct
parse_trait_ref(st, conv)
}
pub fn parse_arg_data(data: @~[u8], crate_num: int, pos: uint, tcx: ty::ctxt,
conv: conv_did) -> ty::arg {
let st = parse_state_from_data(data, crate_num, pos, tcx);
parse_arg(st, conv)
}
fn parse_path(st: @mut PState) -> @ast::Path {
let mut idents: ~[ast::ident] = ~[];
fn is_last(c: char) -> bool { return c == '(' || c == ':'; }
@ -471,12 +465,6 @@ fn parse_onceness(c: char) -> ast::Onceness {
}
}
fn parse_arg(st: @mut PState, conv: conv_did) -> ty::arg {
ty::arg {
ty: parse_ty(st, conv)
}
}
fn parse_closure_ty(st: @mut PState, conv: conv_did) -> ty::ClosureTy {
let sigil = parse_sigil(st);
let purity = parse_purity(next(st));
@ -505,9 +493,9 @@ fn parse_bare_fn_ty(st: @mut PState, conv: conv_did) -> ty::BareFnTy {
fn parse_sig(st: @mut PState, conv: conv_did) -> ty::FnSig {
assert!((next(st) == '['));
let mut inputs: ~[ty::arg] = ~[];
let mut inputs = ~[];
while peek(st) != ']' {
inputs.push(ty::arg { ty: parse_ty(st, conv) });
inputs.push(parse_ty(st, conv));
}
st.pos += 1u; // eat the ']'
let ret_ty = parse_ty(st, conv);

View File

@ -344,10 +344,6 @@ fn enc_sigil(w: @io::Writer, sigil: Sigil) {
}
}
pub fn enc_arg(w: @io::Writer, cx: @ctxt, arg: ty::arg) {
enc_ty(w, cx, arg.ty);
}
fn enc_purity(w: @io::Writer, p: purity) {
match p {
pure_fn => w.write_char('p'),
@ -389,8 +385,8 @@ fn enc_closure_ty(w: @io::Writer, cx: @ctxt, ft: &ty::ClosureTy) {
fn enc_fn_sig(w: @io::Writer, cx: @ctxt, fsig: &ty::FnSig) {
w.write_char('[');
for fsig.inputs.each |arg| {
enc_arg(w, cx, *arg);
for fsig.inputs.each |ty| {
enc_ty(w, cx, *ty);
}
w.write_char(']');
enc_ty(w, cx, fsig.output);

View File

@ -526,8 +526,8 @@ fn encode_method_map_entry(ecx: @e::EncodeContext,
ebml_w: &mut writer::Encoder,
mme: method_map_entry) {
do ebml_w.emit_struct("method_map_entry", 3) |ebml_w| {
do ebml_w.emit_struct_field("self_arg", 0u) |ebml_w| {
ebml_w.emit_arg(ecx, mme.self_arg);
do ebml_w.emit_struct_field("self_ty", 0u) |ebml_w| {
ebml_w.emit_ty(ecx, mme.self_ty);
}
do ebml_w.emit_struct_field("explicit_self", 2u) |ebml_w| {
mme.explicit_self.encode(ebml_w);
@ -546,14 +546,14 @@ impl read_method_map_entry_helper for reader::Decoder {
-> method_map_entry {
do self.read_struct("method_map_entry", 3) |this| {
method_map_entry {
self_arg: this.read_struct_field("self_arg", 0, |this| {
this.read_arg(xcx)
self_ty: this.read_struct_field("self_ty", 0u, |this| {
this.read_ty(xcx)
}),
explicit_self: this.read_struct_field("explicit_self",
2,
|this| {
let self_type: ast::self_ty_ = Decodable::decode(this);
self_type
let explicit_self: ast::explicit_self_ = Decodable::decode(this);
explicit_self
}),
origin: this.read_struct_field("origin", 1, |this| {
let method_origin: method_origin =
@ -712,7 +712,6 @@ impl get_ty_str_ctxt for e::EncodeContext {
}
trait ebml_writer_helpers {
fn emit_arg(&mut self, ecx: @e::EncodeContext, arg: ty::arg);
fn emit_ty(&mut self, ecx: @e::EncodeContext, ty: ty::t);
fn emit_vstore(&mut self, ecx: @e::EncodeContext, vstore: ty::vstore);
fn emit_tys(&mut self, ecx: @e::EncodeContext, tys: &[ty::t]);
@ -737,12 +736,6 @@ impl ebml_writer_helpers for writer::Encoder {
}
}
fn emit_arg(&mut self, ecx: @e::EncodeContext, arg: ty::arg) {
do self.emit_opaque |this| {
tyencode::enc_arg(this.writer, ecx.ty_str_ctxt(), arg);
}
}
fn emit_tys(&mut self, ecx: @e::EncodeContext, tys: &[ty::t]) {
do self.emit_from_vec(tys) |this, ty| {
this.emit_ty(ecx, *ty)
@ -943,7 +936,6 @@ impl doc_decoder_helpers for ebml::Doc {
}
trait ebml_decoder_decoder_helpers {
fn read_arg(&mut self, xcx: @ExtendedDecodeContext) -> ty::arg;
fn read_ty(&mut self, xcx: @ExtendedDecodeContext) -> ty::t;
fn read_tys(&mut self, xcx: @ExtendedDecodeContext) -> ~[ty::t];
fn read_type_param_def(&mut self, xcx: @ExtendedDecodeContext)
@ -958,17 +950,6 @@ trait ebml_decoder_decoder_helpers {
}
impl ebml_decoder_decoder_helpers for reader::Decoder {
fn read_arg(&mut self, xcx: @ExtendedDecodeContext) -> ty::arg {
do self.read_opaque |this, doc| {
tydecode::parse_arg_data(
doc.data,
xcx.dcx.cdata.cnum,
doc.start,
xcx.dcx.tcx,
|s, a| this.convert_def_id(xcx, s, a))
}
}
fn read_ty(&mut self, xcx: @ExtendedDecodeContext) -> ty::t {
// Note: regions types embed local node ids. In principle, we
// should translate these node ids into the new decode

View File

@ -381,7 +381,7 @@ fn visit_fn(fk: &visit::fn_kind,
// Add `this`, whether explicit or implicit.
match *fk {
fk_method(_, _, method) => {
match method.self_ty.node {
match method.explicit_self.node {
sty_value | sty_region(*) | sty_box(_) | sty_uniq(_) => {
fn_maps.add_variable(Arg(method.self_id,
special_idents::self_));

View File

@ -10,7 +10,7 @@
use driver::session::Session;
use metadata::csearch::{each_path, get_trait_method_def_ids};
use metadata::csearch::get_method_name_and_self_ty;
use metadata::csearch::get_method_name_and_explicit_self;
use metadata::csearch::get_static_methods_if_impl;
use metadata::csearch::get_type_name_if_impl;
use metadata::cstore::find_extern_mod_stmt_cnum;
@ -28,7 +28,7 @@ use syntax::ast::{def_const, def_foreign_mod, def_fn, def_id, def_label};
use syntax::ast::{def_local, def_mod, def_prim_ty, def_region, def_self};
use syntax::ast::{def_self_ty, def_static_method, def_struct, def_ty};
use syntax::ast::{def_ty_param, def_typaram_binder, def_trait};
use syntax::ast::{def_upvar, def_use, def_variant, expr, expr_assign_op};
use syntax::ast::{def_upvar, def_use, def_variant, explicit_self_, expr, expr_assign_op};
use syntax::ast::{expr_binary, expr_break, expr_field};
use syntax::ast::{expr_fn_block, expr_index, expr_method_call, expr_path};
use syntax::ast::{def_prim_ty, def_region, def_self, def_ty, def_ty_param};
@ -45,7 +45,7 @@ use syntax::ast::{local, local_crate, lt, method, mul};
use syntax::ast::{named_field, ne, neg, node_id, pat, pat_enum, pat_ident};
use syntax::ast::{Path, pat_lit, pat_range, pat_struct};
use syntax::ast::{prim_ty, private, provided};
use syntax::ast::{public, required, rem, self_ty_, shl, shr, stmt_decl};
use syntax::ast::{public, required, rem, shl, shr, stmt_decl};
use syntax::ast::{struct_field, struct_variant_kind};
use syntax::ast::{sty_static, subtract, trait_ref, tuple_variant_kind, Ty};
use syntax::ast::{ty_bool, ty_char, ty_f, ty_f32, ty_f64, ty_float, ty_i};
@ -96,7 +96,7 @@ pub struct MethodInfo {
did: def_id,
n_tps: uint,
ident: ident,
self_type: self_ty_
explicit_self: explicit_self_
}
pub struct Impl {
@ -1203,7 +1203,7 @@ pub impl Resolver {
// Bail out early if there are no static methods.
let mut has_static_methods = false;
for methods.each |method| {
match method.self_ty.node {
match method.explicit_self.node {
sty_static => has_static_methods = true,
_ => {}
}
@ -1236,7 +1236,7 @@ pub impl Resolver {
// For each static method...
for methods.each |method| {
match method.self_ty.node {
match method.explicit_self.node {
sty_static => {
// Add the static method to the
// module.
@ -1274,7 +1274,7 @@ pub impl Resolver {
let mut has_static_methods = false;
for (*methods).each |method| {
let ty_m = trait_method_to_ty_method(method);
match ty_m.self_ty.node {
match ty_m.explicit_self.node {
sty_static => {
has_static_methods = true;
break;
@ -1306,7 +1306,7 @@ pub impl Resolver {
let ident = ty_m.ident;
// Add it to the trait info if not static,
// add it as a name in the trait module otherwise.
match ty_m.self_ty.node {
match ty_m.explicit_self.node {
sty_static => {
let def = def_static_method(
local_def(ty_m.id),
@ -1612,9 +1612,9 @@ pub impl Resolver {
def_id);
let mut interned_method_names = HashSet::new();
for method_def_ids.each |&method_def_id| {
let (method_name, self_ty) =
get_method_name_and_self_ty(self.session.cstore,
method_def_id);
let (method_name, explicit_self) =
get_method_name_and_explicit_self(self.session.cstore,
method_def_id);
debug!("(building reduced graph for \
external crate) ... adding \
@ -1622,7 +1622,7 @@ pub impl Resolver {
*self.session.str_of(method_name));
// Add it to the trait info if not static.
if self_ty != sty_static {
if explicit_self != sty_static {
interned_method_names.insert(method_name);
}
}
@ -3774,7 +3774,7 @@ pub impl Resolver {
outer_type_parameter_count,
rib_kind);
// we only have self ty if it is a non static method
let self_binding = match method.self_ty.node {
let self_binding = match method.explicit_self.node {
sty_static => { NoSelfBinding }
_ => { HasSelfBinding(method.self_id, false) }
};

View File

@ -11,7 +11,7 @@
use driver::session;
use driver::session::Session;
use metadata::csearch::{each_path, get_trait_method_def_ids};
use metadata::csearch::get_method_name_and_self_ty;
use metadata::csearch::get_method_name_and_explicit_self;
use metadata::csearch::get_static_methods_if_impl;
use metadata::csearch::get_type_name_if_impl;
use metadata::cstore::find_extern_mod_stmt_cnum;
@ -46,7 +46,7 @@ use syntax::ast::{local, local_crate, lt, method, mul};
use syntax::ast::{named_field, ne, neg, node_id, pat, pat_enum, pat_ident};
use syntax::ast::{Path, pat_lit, pat_range, pat_struct};
use syntax::ast::{prim_ty, private, provided};
use syntax::ast::{public, required, rem, self_ty_, shl, shr, stmt_decl};
use syntax::ast::{public, required, rem, explicit_self_, shl, shr, stmt_decl};
use syntax::ast::{struct_field, struct_variant_kind};
use syntax::ast::{sty_static, subtract, trait_ref, tuple_variant_kind, Ty};
use syntax::ast::{ty_bool, ty_char, ty_f, ty_f32, ty_f64, ty_float, ty_i};
@ -97,7 +97,7 @@ pub struct MethodInfo {
did: def_id,
n_tps: uint,
ident: ident,
self_type: self_ty_
explicit_self: explicit_self_
}
pub struct Impl {
@ -1219,7 +1219,7 @@ pub impl Resolver {
// Bail out early if there are no static methods.
let mut has_static_methods = false;
for methods.each |method| {
match method.self_ty.node {
match method.explicit_self.node {
sty_static => has_static_methods = true,
_ => {}
}
@ -1252,7 +1252,7 @@ pub impl Resolver {
// For each static method...
for methods.each |method| {
match method.self_ty.node {
match method.explicit_self.node {
sty_static => {
// Add the static method to the
// module.
@ -1290,7 +1290,7 @@ pub impl Resolver {
let mut has_static_methods = false;
for (*methods).each |method| {
let ty_m = trait_method_to_ty_method(method);
match ty_m.self_ty.node {
match ty_m.explicit_self.node {
sty_static => {
has_static_methods = true;
break;
@ -1322,7 +1322,7 @@ pub impl Resolver {
let ident = ty_m.ident;
// Add it to the trait info if not static,
// add it as a name in the trait module otherwise.
match ty_m.self_ty.node {
match ty_m.explicit_self.node {
sty_static => {
let def = def_static_method(
local_def(ty_m.id),
@ -1628,9 +1628,9 @@ pub impl Resolver {
def_id);
let mut interned_method_names = HashSet::new();
for method_def_ids.each |&method_def_id| {
let (method_name, self_ty) =
get_method_name_and_self_ty(self.session.cstore,
method_def_id);
let (method_name, explicit_self) =
get_method_name_and_explicit_self(self.session.cstore,
method_def_id);
debug!("(building reduced graph for \
external crate) ... adding \
@ -1638,7 +1638,7 @@ pub impl Resolver {
*self.session.str_of(method_name));
// Add it to the trait info if not static.
if self_ty != sty_static {
if explicit_self != sty_static {
interned_method_names.insert(method_name);
}
}
@ -3800,7 +3800,7 @@ pub impl Resolver {
outer_type_parameter_count,
rib_kind);
// we only have self ty if it is a non static method
let self_binding = match method.self_ty.node {
let self_binding = match method.explicit_self.node {
sty_static => { NoSelfBinding }
_ => { HasSelfBinding(method.self_id, false) }
};

View File

@ -32,12 +32,9 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block {
let outputs = do ia.outputs.map |&(c, out)| {
constraints.push(copy *c);
let aoutty = ty::arg {
ty: expr_ty(bcx, out)
};
aoutputs.push(unpack_result!(bcx, {
callee::trans_arg_expr(bcx,
aoutty,
expr_ty(bcx, out),
ty::ByCopy,
out,
&mut cleanups,
@ -50,13 +47,9 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block {
_ => fail!("Expression must be addr of")
};
let outty = ty::arg {
ty: expr_ty(bcx, e)
};
unpack_result!(bcx, {
callee::trans_arg_expr(bcx,
outty,
expr_ty(bcx, e),
ty::ByCopy,
e,
&mut cleanups,
@ -75,13 +68,9 @@ pub fn trans_inline_asm(bcx: block, ia: &ast::inline_asm) -> block {
let inputs = do ia.inputs.map |&(c, in)| {
constraints.push(copy *c);
let inty = ty::arg {
ty: expr_ty(bcx, in)
};
unpack_result!(bcx, {
callee::trans_arg_expr(bcx,
inty,
expr_ty(bcx, in),
ty::ByCopy,
in,
&mut cleanups,

View File

@ -1664,12 +1664,12 @@ pub fn new_fn_ctxt(ccx: @CrateContext,
// the function's fn_ctxt). create_llargs_for_fn_args populates the llargs
// field of the fn_ctxt with
pub fn create_llargs_for_fn_args(cx: fn_ctxt,
ty_self: self_arg,
self_arg: self_arg,
args: &[ast::arg])
-> ~[ValueRef] {
let _icx = cx.insn_ctxt("create_llargs_for_fn_args");
match ty_self {
match self_arg {
impl_self(tt) => {
cx.llself = Some(ValSelfData {
v: cx.llenv,
@ -1701,7 +1701,7 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt,
bcx: block,
args: &[ast::arg],
raw_llargs: &[ValueRef],
arg_tys: &[ty::arg]) -> block {
arg_tys: &[ty::t]) -> block {
let _icx = fcx.insn_ctxt("copy_args_to_allocas");
let mut bcx = bcx;
@ -1720,7 +1720,7 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt,
}
for uint::range(0, arg_tys.len()) |arg_n| {
let arg_ty = &arg_tys[arg_n];
let arg_ty = arg_tys[arg_n];
let raw_llarg = raw_llargs[arg_n];
let arg_id = args[arg_n].id;
@ -1732,15 +1732,15 @@ pub fn copy_args_to_allocas(fcx: fn_ctxt,
// This alloca should be optimized away by LLVM's mem-to-reg pass in
// the event it's not truly needed.
// only by value if immediate:
let llarg = if datum::appropriate_mode(arg_ty.ty).is_by_value() {
let alloc = alloc_ty(bcx, arg_ty.ty);
let llarg = if datum::appropriate_mode(arg_ty).is_by_value() {
let alloc = alloc_ty(bcx, arg_ty);
Store(bcx, raw_llarg, alloc);
alloc
} else {
raw_llarg
};
add_clean(bcx, llarg, arg_ty.ty);
add_clean(bcx, llarg, arg_ty);
bcx = _match::bind_irrefutable_pat(bcx,
args[arg_n].pat,
@ -1801,7 +1801,7 @@ pub fn trans_closure(ccx: @CrateContext,
decl: &ast::fn_decl,
body: &ast::blk,
llfndecl: ValueRef,
ty_self: self_arg,
self_arg: self_arg,
param_substs: Option<@param_substs>,
id: ast::node_id,
impl_id: Option<ast::def_id>,
@ -1825,7 +1825,7 @@ pub fn trans_closure(ccx: @CrateContext,
impl_id,
param_substs,
Some(body.span));
let raw_llargs = create_llargs_for_fn_args(fcx, ty_self, decl.inputs);
let raw_llargs = create_llargs_for_fn_args(fcx, self_arg, decl.inputs);
// Set the fixed stack segment flag if necessary.
if attr::attrs_contains_name(attributes, "fixed_stack_segment") {
@ -1882,7 +1882,7 @@ pub fn trans_fn(ccx: @CrateContext,
decl: &ast::fn_decl,
body: &ast::blk,
llfndecl: ValueRef,
ty_self: self_arg,
self_arg: self_arg,
param_substs: Option<@param_substs>,
id: ast::node_id,
impl_id: Option<ast::def_id>,
@ -1890,8 +1890,8 @@ pub fn trans_fn(ccx: @CrateContext,
let do_time = ccx.sess.trans_stats();
let start = if do_time { time::get_time() }
else { time::Timespec::new(0, 0) };
debug!("trans_fn(ty_self=%?, param_substs=%s)",
ty_self,
debug!("trans_fn(self_arg=%?, param_substs=%s)",
self_arg,
param_substs.repr(ccx.tcx));
let _icx = ccx.insn_ctxt("trans_fn");
ccx.stats.n_fns += 1;
@ -1902,7 +1902,7 @@ pub fn trans_fn(ccx: @CrateContext,
decl,
body,
llfndecl,
ty_self,
self_arg,
param_substs,
id,
impl_id,
@ -1987,7 +1987,7 @@ pub fn trans_enum_variant(ccx: @CrateContext,
Some(&local_mem(x)) => x,
_ => fail!("trans_enum_variant: how do we know this works?"),
};
let arg_ty = arg_tys[i].ty;
let arg_ty = arg_tys[i];
memcpy_ty(bcx, lldestptr, llarg, arg_ty);
}
build_return(bcx);
@ -2061,7 +2061,7 @@ pub fn trans_tuple_struct(ccx: @CrateContext,
local_mem")
}
};
let arg_ty = arg_tys[i].ty;
let arg_ty = arg_tys[i];
memcpy_ty(bcx, lldestptr, llarg, arg_ty);
}

View File

@ -674,7 +674,7 @@ pub enum AutorefArg {
// temp_cleanups: cleanups that should run only if failure occurs before the
// call takes place:
pub fn trans_arg_expr(bcx: block,
formal_ty: ty::arg,
formal_arg_ty: ty::t,
self_mode: ty::SelfMode,
arg_expr: @ast::expr,
temp_cleanups: &mut ~[ValueRef],
@ -683,9 +683,9 @@ pub fn trans_arg_expr(bcx: block,
let _icx = bcx.insn_ctxt("trans_arg_expr");
let ccx = bcx.ccx();
debug!("trans_arg_expr(formal_ty=(%s), self_mode=%?, arg_expr=%s, \
debug!("trans_arg_expr(formal_arg_ty=(%s), self_mode=%?, arg_expr=%s, \
ret_flag=%?)",
formal_ty.ty.repr(bcx.tcx()),
formal_arg_ty.repr(bcx.tcx()),
self_mode,
arg_expr.repr(bcx.tcx()),
ret_flag.map(|v| bcx.val_str(*v)));
@ -734,9 +734,9 @@ pub fn trans_arg_expr(bcx: block,
// "undef" value, as such a value should never
// be inspected. It's important for the value
// to have type lldestty (the callee's expected type).
let llformal_ty = type_of::type_of(ccx, formal_ty.ty);
let llformal_arg_ty = type_of::type_of(ccx, formal_arg_ty);
unsafe {
val = llvm::LLVMGetUndef(llformal_ty);
val = llvm::LLVMGetUndef(llformal_arg_ty);
}
} else {
// FIXME(#3548) use the adjustments table
@ -784,16 +784,16 @@ pub fn trans_arg_expr(bcx: block,
}
}
if formal_ty.ty != arg_datum.ty {
if formal_arg_ty != arg_datum.ty {
// this could happen due to e.g. subtyping
let llformal_ty = type_of::type_of_explicit_arg(ccx, &formal_ty);
let llformal_ty = match self_mode {
ty::ByRef => T_ptr(llformal_ty),
ty::ByCopy => llformal_ty,
let llformal_arg_ty = type_of::type_of_explicit_arg(ccx, &formal_arg_ty);
let llformal_arg_ty = match self_mode {
ty::ByRef => T_ptr(llformal_arg_ty),
ty::ByCopy => llformal_arg_ty,
};
debug!("casting actual type (%s) to match formal (%s)",
bcx.val_str(val), bcx.llty_str(llformal_ty));
val = PointerCast(bcx, val, llformal_ty);
bcx.val_str(val), bcx.llty_str(llformal_arg_ty));
val = PointerCast(bcx, val, llformal_arg_ty);
}
}

View File

@ -785,7 +785,7 @@ fn create_ty(cx: @CrateContext, t: ty::t, span: span)
cx.sess.span_bug(span, "debuginfo for rptr NYI")
},
ty::ty_bare_fn(ref barefnty) => {
let inputs = do barefnty.sig.inputs.map |a| { a.ty };
let inputs = barefnty.sig.inputs.map(|a| *a);
let output = barefnty.sig.output;
create_fn_ty(cx, t, inputs, output, span)
},

View File

@ -29,7 +29,7 @@ use middle::trans::machine;
use middle::trans::type_of::*;
use middle::trans::type_of;
use middle::ty;
use middle::ty::{FnSig, arg};
use middle::ty::FnSig;
use util::ppaux::ty_to_str;
use syntax::codemap::span;
@ -94,7 +94,7 @@ fn foreign_signature(ccx: @CrateContext, fn_sig: &ty::FnSig)
* values by pointer like we do.
*/
let llarg_tys = fn_sig.inputs.map(|arg| type_of(ccx, arg.ty));
let llarg_tys = fn_sig.inputs.map(|arg_ty| type_of(ccx, *arg_ty));
let llret_ty = type_of::type_of(ccx, fn_sig.output);
LlvmSignature {
llarg_tys: llarg_tys,
@ -820,7 +820,7 @@ pub fn trans_intrinsic(ccx: @CrateContext,
region: ty::re_bound(ty::br_anon(0)),
sig: FnSig {
bound_lifetime_names: opt_vec::Empty,
inputs: ~[ arg { ty: star_u8 } ],
inputs: ~[ star_u8 ],
output: ty::mk_nil()
}
});

View File

@ -99,14 +99,14 @@ pub fn maybe_instantiate_inline(ccx: @CrateContext, fn_id: ast::def_id,
let path = vec::append(
ty::item_path(ccx.tcx, impl_did),
~[path_name(mth.ident)]);
let self_kind = match mth.self_ty.node {
let self_kind = match mth.explicit_self.node {
ast::sty_static => no_self,
_ => {
let self_ty = ty::node_id_to_type(ccx.tcx,
mth.self_id);
debug!("calling inline trans_fn with self_ty %s",
ty_to_str(ccx.tcx, self_ty));
match mth.self_ty.node {
match mth.explicit_self.node {
ast::sty_value => impl_owned_self(self_ty),
_ => impl_self(self_ty),
}

View File

@ -25,7 +25,6 @@ use middle::trans::inline;
use middle::trans::monomorphize;
use middle::trans::type_of::*;
use middle::ty;
use middle::ty::arg;
use middle::typeck;
use util::common::indenter;
use util::ppaux::Repr;
@ -70,7 +69,12 @@ pub fn trans_impl(ccx: @CrateContext, path: path, name: ast::ident,
}
}
trans_method(ccx, path, *method, param_substs_opt, self_ty, llfn,
trans_method(ccx,
path,
*method,
param_substs_opt,
self_ty,
llfn,
ast_util::local_def(id));
}
}
@ -99,18 +103,17 @@ pub fn trans_method(ccx: @CrateContext,
llfn: ValueRef,
impl_id: ast::def_id) {
// figure out how self is being passed
let self_arg = match method.self_ty.node {
let self_arg = match method.explicit_self.node {
ast::sty_static => {
no_self
}
_ => {
// determine the (monomorphized) type that `self` maps to for
// this method
let self_ty;
match base_self_ty {
None => self_ty = ty::node_id_to_type(ccx.tcx, method.self_id),
Some(provided_self_ty) => self_ty = provided_self_ty
}
let self_ty = match base_self_ty {
None => ty::node_id_to_type(ccx.tcx, method.self_id),
Some(provided_self_ty) => provided_self_ty,
};
let self_ty = match param_substs {
None => self_ty,
Some(@param_substs {tys: ref tys, _}) => {
@ -120,7 +123,7 @@ pub fn trans_method(ccx: @CrateContext,
debug!("calling trans_fn with base_self_ty %s, self_ty %s",
base_self_ty.repr(ccx.tcx),
self_ty.repr(ccx.tcx));
match method.self_ty.node {
match method.explicit_self.node {
ast::sty_value => {
impl_owned_self(self_ty)
}
@ -151,12 +154,10 @@ pub fn trans_self_arg(bcx: block,
let mut temp_cleanups = ~[];
// Compute the type of self.
let self_arg = arg {
ty: monomorphize_type(bcx, mentry.self_arg.ty)
};
let self_ty = monomorphize_type(bcx, mentry.self_ty);
let result = trans_arg_expr(bcx,
self_arg,
self_ty,
mentry.self_mode,
base,
&mut temp_cleanups,
@ -589,7 +590,7 @@ pub fn trans_trait_callee(bcx: block,
n_method: uint,
self_expr: @ast::expr,
store: ty::TraitStore,
explicit_self: ast::self_ty_)
explicit_self: ast::explicit_self_)
-> Callee {
//!
//
@ -626,7 +627,7 @@ pub fn trans_trait_callee_from_llval(bcx: block,
n_method: uint,
llpair: ValueRef,
store: ty::TraitStore,
explicit_self: ast::self_ty_)
explicit_self: ast::explicit_self_)
-> Callee {
//!
//

View File

@ -35,7 +35,7 @@ use syntax::parse::token::special_idents;
pub struct Reflector {
visitor_val: ValueRef,
visitor_methods: @~[@ty::method],
visitor_methods: @~[@ty::Method],
final_bcx: block,
tydesc_ty: TypeRef,
bcx: block
@ -284,13 +284,8 @@ pub impl Reflector {
let sym = mangle_internal_name_by_path_and_seq(ccx,
sub_path,
"get_disr");
let args = [
ty::arg {
ty: opaqueptrty
}
];
let llfty = type_of_fn(ccx, args, ty::mk_int());
let llfty = type_of_fn(ccx, [opaqueptrty], ty::mk_int());
let llfdecl = decl_internal_cdecl_fn(ccx.llmod, sym, llfty);
let arg = unsafe {
llvm::LLVMGetParam(llfdecl, first_real_arg as c_uint)
@ -357,7 +352,7 @@ pub impl Reflector {
let modeval = 5u; // "by copy"
let extra = ~[self.c_uint(i),
self.c_uint(modeval),
self.c_tydesc(arg.ty)];
self.c_tydesc(*arg)];
self.visit(~"fn_input", extra);
}
let extra = ~[self.c_uint(retval),

View File

@ -19,21 +19,21 @@ use util::ppaux;
use syntax::ast;
pub fn arg_is_indirect(_: @CrateContext, arg: &ty::arg) -> bool {
!ty::type_is_immediate(arg.ty)
pub fn arg_is_indirect(_: @CrateContext, arg_ty: &ty::t) -> bool {
!ty::type_is_immediate(*arg_ty)
}
pub fn type_of_explicit_arg(ccx: @CrateContext, arg: &ty::arg) -> TypeRef {
let llty = type_of(ccx, arg.ty);
if arg_is_indirect(ccx, arg) {T_ptr(llty)} else {llty}
pub fn type_of_explicit_arg(ccx: @CrateContext, arg_ty: &ty::t) -> TypeRef {
let llty = type_of(ccx, *arg_ty);
if arg_is_indirect(ccx, arg_ty) {T_ptr(llty)} else {llty}
}
pub fn type_of_explicit_args(ccx: @CrateContext,
inputs: &[ty::arg]) -> ~[TypeRef] {
inputs.map(|arg| type_of_explicit_arg(ccx, arg))
inputs: &[ty::t]) -> ~[TypeRef] {
inputs.map(|arg_ty| type_of_explicit_arg(ccx, arg_ty))
}
pub fn type_of_fn(cx: @CrateContext, inputs: &[ty::arg], output: ty::t)
pub fn type_of_fn(cx: @CrateContext, inputs: &[ty::t], output: ty::t)
-> TypeRef {
unsafe {
let mut atys: ~[TypeRef] = ~[];

View File

@ -78,7 +78,7 @@ pub fn type_uses_for(ccx: @CrateContext, fn_id: def_id, n_tps: uint)
ty::ty_bare_fn(ty::BareFnTy {sig: ref sig, _}) |
ty::ty_closure(ty::ClosureTy {sig: ref sig, _}) => {
for sig.inputs.each |arg| {
type_needs(cx, use_repr, arg.ty);
type_needs(cx, use_repr, *arg);
}
}
_ => ()
@ -331,18 +331,16 @@ pub fn mark_for_expr(cx: Context, e: @expr) {
node_type_needs(cx, use_tydesc, val.id);
}
expr_call(f, _, _) => {
for vec::each(ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx,
f.id))) |a| {
type_needs(cx, use_repr, a.ty);
for ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, f.id)).each |a| {
type_needs(cx, use_repr, *a);
}
}
expr_method_call(rcvr, _, _, _, _) => {
let base_ty = ty::node_id_to_type(cx.ccx.tcx, rcvr.id);
type_needs(cx, use_repr, ty::type_autoderef(cx.ccx.tcx, base_ty));
for ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx,
e.callee_id)).each |a| {
type_needs(cx, use_repr, a.ty);
for ty::ty_fn_args(ty::node_id_to_type(cx.ccx.tcx, e.callee_id)).each |a| {
type_needs(cx, use_repr, *a);
}
mark_for_method_call(cx, e.id, e.callee_id);
}

View File

@ -47,27 +47,49 @@ use syntax;
// Data types
#[deriving(Eq, IterBytes)]
pub struct arg {
ty: t
}
#[deriving(Eq)]
pub struct field {
ident: ast::ident,
mt: mt
}
pub struct method {
pub struct Method {
ident: ast::ident,
generics: ty::Generics,
transformed_self_ty: Option<ty::t>,
fty: BareFnTy,
self_ty: ast::self_ty_,
explicit_self: ast::explicit_self_,
vis: ast::visibility,
def_id: ast::def_id
}
pub impl Method {
fn new(ident: ast::ident,
generics: ty::Generics,
transformed_self_ty: Option<ty::t>,
fty: BareFnTy,
explicit_self: ast::explicit_self_,
vis: ast::visibility,
def_id: ast::def_id) -> Method {
// Check the invariants.
if explicit_self == ast::sty_static {
assert!(transformed_self_ty.is_none());
} else {
assert!(transformed_self_ty.is_some());
}
Method {
ident: ident,
generics: generics,
transformed_self_ty: transformed_self_ty,
fty: fty,
explicit_self: explicit_self,
vis: vis,
def_id: def_id
}
}
}
#[deriving(Eq)]
pub struct mt {
ty: t,
@ -259,13 +281,13 @@ struct ctxt_ {
node_type_substs: @mut HashMap<node_id, ~[t]>,
// Maps from a method to the method "descriptor"
methods: @mut HashMap<def_id, @method>,
methods: @mut HashMap<def_id, @Method>,
// Maps from a trait def-id to a list of the def-ids of its methods
trait_method_def_ids: @mut HashMap<def_id, @~[def_id]>,
// A cache for the trait_methods() routine
trait_methods_cache: @mut HashMap<def_id, @~[@method]>,
trait_methods_cache: @mut HashMap<def_id, @~[@Method]>,
trait_refs: @mut HashMap<node_id, @TraitRef>,
trait_defs: @mut HashMap<def_id, @TraitDef>,
@ -392,7 +414,7 @@ pub struct ClosureTy {
#[deriving(Eq)]
pub struct FnSig {
bound_lifetime_names: OptVec<ast::ident>,
inputs: ~[arg],
inputs: ~[t],
output: t
}
@ -1107,14 +1129,14 @@ fn mk_t(cx: ctxt, st: sty) -> t {
}
&ty_tup(ref ts) => for ts.each |tt| { flags |= get(*tt).flags; },
&ty_bare_fn(ref f) => {
for f.sig.inputs.each |a| { flags |= get(a.ty).flags; }
for f.sig.inputs.each |a| { flags |= get(*a).flags; }
flags |= get(f.sig.output).flags;
// T -> _|_ is *not* _|_ !
flags &= !(has_ty_bot as uint);
}
&ty_closure(ref f) => {
flags |= rflags(f.region);
for f.sig.inputs.each |a| { flags |= get(a.ty).flags; }
for f.sig.inputs.each |a| { flags |= get(*a).flags; }
flags |= get(f.sig.output).flags;
// T -> _|_ is *not* _|_ !
flags &= !(has_ty_bot as uint);
@ -1298,7 +1320,7 @@ pub fn mk_bare_fn(cx: ctxt, fty: BareFnTy) -> t {
}
pub fn mk_ctor_fn(cx: ctxt, input_tys: &[ty::t], output: ty::t) -> t {
let input_args = input_tys.map(|t| arg { ty: *t });
let input_args = input_tys.map(|t| *t);
mk_bare_fn(cx,
BareFnTy {
purity: ast::pure_fn,
@ -1372,11 +1394,11 @@ pub fn maybe_walk_ty(ty: t, f: &fn(t) -> bool) {
}
ty_tup(ref ts) => { for ts.each |tt| { maybe_walk_ty(*tt, f); } }
ty_bare_fn(ref ft) => {
for ft.sig.inputs.each |a| { maybe_walk_ty(a.ty, f); }
for ft.sig.inputs.each |a| { maybe_walk_ty(*a, f); }
maybe_walk_ty(ft.sig.output, f);
}
ty_closure(ref ft) => {
for ft.sig.inputs.each |a| { maybe_walk_ty(a.ty, f); }
for ft.sig.inputs.each |a| { maybe_walk_ty(*a, f); }
maybe_walk_ty(ft.sig.output, f);
}
}
@ -1387,11 +1409,7 @@ pub fn fold_sty_to_ty(tcx: ty::ctxt, sty: &sty, foldop: &fn(t) -> t) -> t {
}
pub fn fold_sig(sig: &FnSig, fldop: &fn(t) -> t) -> FnSig {
let args = do sig.inputs.map |arg| {
arg {
ty: fldop(arg.ty)
}
};
let args = sig.inputs.map(|arg| fldop(*arg));
FnSig {
bound_lifetime_names: copy sig.bound_lifetime_names,
@ -2999,7 +3017,7 @@ pub fn ty_fn_sig(fty: t) -> FnSig {
}
// Type accessors for substructures of types
pub fn ty_fn_args(fty: t) -> ~[arg] {
pub fn ty_fn_args(fty: t) -> ~[t] {
match get(fty).sty {
ty_bare_fn(ref f) => copy f.sig.inputs,
ty_closure(ref f) => copy f.sig.inputs,
@ -3103,7 +3121,7 @@ pub fn replace_closure_return_type(tcx: ctxt, fn_type: t, ret_type: t) -> t {
// Returns a vec of all the input and output types of fty.
pub fn tys_in_fn_sig(sig: &FnSig) -> ~[t] {
vec::append_one(sig.inputs.map(|a| a.ty), sig.output)
vec::append_one(sig.inputs.map(|a| *a), sig.output)
}
// Type accessors for AST nodes
@ -3507,7 +3525,7 @@ pub fn field_idx_strict(tcx: ty::ctxt, id: ast::ident, fields: &[field])
fields.map(|f| tcx.sess.str_of(f.ident))));
}
pub fn method_idx(id: ast::ident, meths: &[@method]) -> Option<uint> {
pub fn method_idx(id: ast::ident, meths: &[@Method]) -> Option<uint> {
vec::position(meths, |m| m.ident == id)
}
@ -3831,12 +3849,12 @@ fn lookup_locally_or_in_crate_store<V:Copy>(
return v;
}
pub fn trait_method(cx: ctxt, trait_did: ast::def_id, idx: uint) -> @method {
pub fn trait_method(cx: ctxt, trait_did: ast::def_id, idx: uint) -> @Method {
let method_def_id = ty::trait_method_def_ids(cx, trait_did)[idx];
ty::method(cx, method_def_id)
}
pub fn trait_methods(cx: ctxt, trait_did: ast::def_id) -> @~[@method] {
pub fn trait_methods(cx: ctxt, trait_did: ast::def_id) -> @~[@Method] {
match cx.trait_methods_cache.find(&trait_did) {
Some(&methods) => methods,
None => {
@ -3848,7 +3866,7 @@ pub fn trait_methods(cx: ctxt, trait_did: ast::def_id) -> @~[@method] {
}
}
pub fn method(cx: ctxt, id: ast::def_id) -> @method {
pub fn method(cx: ctxt, id: ast::def_id) -> @Method {
lookup_locally_or_in_crate_store(
"methods", id, cx.methods,
|| @csearch::get_method(cx, id))
@ -4061,7 +4079,7 @@ pub fn enum_variants(cx: ctxt, id: ast::def_id) -> @~[VariantInfo] {
let ctor_ty = node_id_to_type(cx, variant.node.id);
let arg_tys = {
if args.len() > 0u {
ty_fn_args(ctor_ty).map(|a| a.ty)
ty_fn_args(ctor_ty).map(|a| *a)
} else {
~[]
}

View File

@ -53,7 +53,7 @@
*/
use middle::const_eval;
use middle::ty::{arg, substs};
use middle::ty::{substs};
use middle::ty::{ty_param_substs_and_ty};
use middle::ty;
use middle::typeck::rscope::in_binding_rscope;
@ -501,16 +501,12 @@ pub fn ty_of_arg<AC:AstConv,
this: &AC,
rscope: &RS,
a: ast::arg,
expected_ty: Option<ty::arg>)
-> ty::arg {
let ty = match a.ty.node {
ast::ty_infer if expected_ty.is_some() => expected_ty.get().ty,
expected_ty: Option<ty::t>)
-> ty::t {
match a.ty.node {
ast::ty_infer if expected_ty.is_some() => expected_ty.get(),
ast::ty_infer => this.ty_infer(a.ty.span),
_ => ast_ty_to_ty(this, rscope, a.ty),
};
arg {
ty: ty
}
}
@ -546,7 +542,7 @@ pub fn bound_lifetimes<AC:AstConv>(
struct SelfInfo {
untransformed_self_ty: ty::t,
self_transform: ast::self_ty
explicit_self: ast::explicit_self
}
pub fn ty_of_method<AC:AstConv,RS:region_scope + Copy + 'static>(
@ -555,12 +551,12 @@ pub fn ty_of_method<AC:AstConv,RS:region_scope + Copy + 'static>(
purity: ast::purity,
lifetimes: &OptVec<ast::Lifetime>,
untransformed_self_ty: ty::t,
self_transform: ast::self_ty,
explicit_self: ast::explicit_self,
decl: &ast::fn_decl) -> (Option<ty::t>, ty::BareFnTy)
{
let self_info = SelfInfo {
untransformed_self_ty: untransformed_self_ty,
self_transform: self_transform
explicit_self: explicit_self
};
let (a, b) = ty_of_method_or_bare_fn(
this, rscope, purity, AbiSet::Rust(), lifetimes, Some(&self_info), decl);
@ -621,7 +617,7 @@ fn ty_of_method_or_bare_fn<AC:AstConv,RS:region_scope + Copy + 'static>(
rscope: &RS,
self_info: &SelfInfo) -> Option<ty::t>
{
match self_info.self_transform.node {
match self_info.explicit_self.node {
ast::sty_static => None,
ast::sty_value => {
Some(self_info.untransformed_self_ty)
@ -629,7 +625,7 @@ fn ty_of_method_or_bare_fn<AC:AstConv,RS:region_scope + Copy + 'static>(
ast::sty_region(lifetime, mutability) => {
let region =
ast_region_to_region(this, rscope,
self_info.self_transform.span,
self_info.explicit_self.span,
lifetime);
Some(ty::mk_rptr(this.tcx(), region,
ty::mt {ty: self_info.untransformed_self_ty,

View File

@ -170,7 +170,7 @@ pub struct LookupContext<'self> {
pub struct Candidate {
rcvr_ty: ty::t,
rcvr_substs: ty::substs,
method_ty: @ty::method,
method_ty: @ty::Method,
origin: method_origin,
}
@ -381,7 +381,7 @@ pub impl<'self> LookupContext<'self> {
let trait_methods = ty::trait_methods(tcx, bound_trait_ref.def_id);
let pos = {
match trait_methods.position(|m| {
m.self_ty != ast::sty_static &&
m.explicit_self != ast::sty_static &&
m.ident == self.m_name })
{
Some(pos) => pos,
@ -469,7 +469,7 @@ pub impl<'self> LookupContext<'self> {
did: def_id,
substs: &ty::substs) {
struct MethodInfo {
method_ty: @ty::method,
method_ty: @ty::Method,
trait_def_id: ast::def_id,
index: uint
}
@ -830,10 +830,10 @@ pub impl<'self> LookupContext<'self> {
}
fn search_for_method(&self,
self_ty: ty::t)
rcvr_ty: ty::t)
-> Option<method_map_entry>
{
debug!("search_for_method(self_ty=%s)", self.ty_to_str(self_ty));
debug!("search_for_method(rcvr_ty=%s)", self.ty_to_str(rcvr_ty));
let _indenter = indenter();
// I am not sure that inherent methods should have higher
@ -841,7 +841,7 @@ pub impl<'self> LookupContext<'self> {
// existing code.
debug!("searching inherent candidates");
match self.consider_candidates(self_ty, self.inherent_candidates) {
match self.consider_candidates(rcvr_ty, self.inherent_candidates) {
None => {}
Some(mme) => {
return Some(mme);
@ -849,7 +849,7 @@ pub impl<'self> LookupContext<'self> {
}
debug!("searching extension candidates");
match self.consider_candidates(self_ty, self.extension_candidates) {
match self.consider_candidates(rcvr_ty, self.extension_candidates) {
None => {
return None;
}
@ -860,12 +860,12 @@ pub impl<'self> LookupContext<'self> {
}
fn consider_candidates(&self,
self_ty: ty::t,
rcvr_ty: ty::t,
candidates: &mut ~[Candidate])
-> Option<method_map_entry>
{
let relevant_candidates =
candidates.filter_to_vec(|c| self.is_relevant(self_ty, c));
candidates.filter_to_vec(|c| self.is_relevant(rcvr_ty, c));
let relevant_candidates = self.merge_candidates(relevant_candidates);
@ -882,7 +882,7 @@ pub impl<'self> LookupContext<'self> {
}
}
Some(self.confirm_candidate(self_ty, &relevant_candidates[0]))
Some(self.confirm_candidate(rcvr_ty, &relevant_candidates[0]))
}
fn merge_candidates(&self, candidates: &[Candidate]) -> ~[Candidate] {
@ -932,7 +932,7 @@ pub impl<'self> LookupContext<'self> {
}
fn confirm_candidate(&self,
self_ty: ty::t,
rcvr_ty: ty::t,
candidate: &Candidate)
-> method_map_entry
{
@ -948,11 +948,11 @@ pub impl<'self> LookupContext<'self> {
self.enforce_drop_trait_limitations(candidate);
// static methods should never have gotten this far:
assert!(candidate.method_ty.self_ty != sty_static);
assert!(candidate.method_ty.explicit_self != sty_static);
let transformed_self_ty = match candidate.origin {
method_trait(*) => {
match candidate.method_ty.self_ty {
match candidate.method_ty.explicit_self {
sty_region(*) => {
// FIXME(#5762) again, preserving existing
// behavior here which (for &self) desires
@ -1033,7 +1033,7 @@ pub impl<'self> LookupContext<'self> {
let fty = ty::mk_bare_fn(tcx, ty::BareFnTy {sig: fn_sig, ..bare_fn_ty});
debug!("after replacing bound regions, fty=%s", self.ty_to_str(fty));
let self_mode = get_mode_from_self_type(candidate.method_ty.self_ty);
let self_mode = get_mode_from_explicit_self(candidate.method_ty.explicit_self);
// before we only checked whether self_ty could be a subtype
// of rcvr_ty; now we actually make it so (this may cause
@ -1041,11 +1041,11 @@ pub impl<'self> LookupContext<'self> {
// nothing has changed in the meantime, this unification
// should never fail.
match self.fcx.mk_subty(false, self.self_expr.span,
self_ty, transformed_self_ty) {
rcvr_ty, transformed_self_ty) {
result::Ok(_) => (),
result::Err(_) => {
self.bug(fmt!("%s was a subtype of %s but now is not?",
self.ty_to_str(self_ty),
self.ty_to_str(rcvr_ty),
self.ty_to_str(transformed_self_ty)));
}
}
@ -1053,11 +1053,9 @@ pub impl<'self> LookupContext<'self> {
self.fcx.write_ty(self.callee_id, fty);
self.fcx.write_substs(self.callee_id, all_substs);
method_map_entry {
self_arg: arg {
ty: candidate.rcvr_ty,
},
self_ty: candidate.rcvr_ty,
self_mode: self_mode,
explicit_self: candidate.method_ty.self_ty,
explicit_self: candidate.method_ty.explicit_self,
origin: candidate.origin,
}
}
@ -1116,9 +1114,11 @@ pub impl<'self> LookupContext<'self> {
}
}
fn is_relevant(&self, self_ty: ty::t, candidate: &Candidate) -> bool {
debug!("is_relevant(self_ty=%s, candidate=%s)",
self.ty_to_str(self_ty), self.cand_to_str(candidate));
// `rcvr_ty` is the type of the expression. It may be a subtype of a
// candidate method's `self_ty`.
fn is_relevant(&self, rcvr_ty: ty::t, candidate: &Candidate) -> bool {
debug!("is_relevant(rcvr_ty=%s, candidate=%s)",
self.ty_to_str(rcvr_ty), self.cand_to_str(candidate));
// Check for calls to object methods. We resolve these differently.
//
@ -1126,7 +1126,7 @@ pub impl<'self> LookupContext<'self> {
// on an @Trait object here and so forth
match candidate.origin {
method_trait(*) => {
match candidate.method_ty.self_ty {
match candidate.method_ty.explicit_self {
sty_static | sty_value => {
return false;
}
@ -1136,7 +1136,7 @@ pub impl<'self> LookupContext<'self> {
// an &@Trait receiver (wacky)
}
sty_box(*) | sty_uniq(*) => {
return self.fcx.can_mk_subty(self_ty,
return self.fcx.can_mk_subty(rcvr_ty,
candidate.rcvr_ty).is_ok();
}
};
@ -1144,17 +1144,17 @@ pub impl<'self> LookupContext<'self> {
_ => {}
}
return match candidate.method_ty.self_ty {
return match candidate.method_ty.explicit_self {
sty_static => {
false
}
sty_value => {
self.fcx.can_mk_subty(self_ty, candidate.rcvr_ty).is_ok()
self.fcx.can_mk_subty(rcvr_ty, candidate.rcvr_ty).is_ok()
}
sty_region(_, m) => {
match ty::get(self_ty).sty {
match ty::get(rcvr_ty).sty {
ty::ty_rptr(_, mt) => {
mutability_matches(mt.mutbl, m) &&
self.fcx.can_mk_subty(mt.ty, candidate.rcvr_ty).is_ok()
@ -1165,7 +1165,7 @@ pub impl<'self> LookupContext<'self> {
}
sty_box(m) => {
match ty::get(self_ty).sty {
match ty::get(rcvr_ty).sty {
ty::ty_box(mt) => {
mutability_matches(mt.mutbl, m) &&
self.fcx.can_mk_subty(mt.ty, candidate.rcvr_ty).is_ok()
@ -1176,7 +1176,7 @@ pub impl<'self> LookupContext<'self> {
}
sty_uniq(m) => {
match ty::get(self_ty).sty {
match ty::get(rcvr_ty).sty {
ty::ty_uniq(mt) => {
mutability_matches(mt.mutbl, m) &&
self.fcx.can_mk_subty(mt.ty, candidate.rcvr_ty).is_ok()
@ -1301,8 +1301,8 @@ pub impl<'self> LookupContext<'self> {
}
}
pub fn get_mode_from_self_type(self_type: ast::self_ty_) -> SelfMode {
match self_type {
pub fn get_mode_from_explicit_self(explicit_self: ast::explicit_self_) -> SelfMode {
match explicit_self {
sty_value => ty::ByCopy,
_ => ty::ByRef,
}

View File

@ -81,7 +81,7 @@ use middle::pat_util::pat_id_map;
use middle::pat_util;
use middle::ty::{FnSig, VariantInfo_};
use middle::ty::{ty_param_bounds_and_ty, ty_param_substs_and_ty};
use middle::ty::{substs, arg, param_ty};
use middle::ty::{substs, param_ty};
use middle::ty;
use middle::typeck::astconv::AstConv;
use middle::typeck::astconv::{ast_region_to_region, ast_ty_to_ty};
@ -352,7 +352,7 @@ pub fn check_fn(ccx: @mut CrateCtxt,
relate_free_regions(tcx, opt_self_info.map(|s| s.self_ty), &fn_sig);
let arg_tys = fn_sig.inputs.map(|a| a.ty);
let arg_tys = fn_sig.inputs.map(|a| *a);
let ret_ty = fn_sig.output;
debug!("check_fn(arg_tys=%?, ret_ty=%?, opt_self_ty=%?)",
@ -527,7 +527,7 @@ pub fn check_method(ccx: @mut CrateCtxt,
let opt_self_info = method_ty.transformed_self_ty.map(|&ty| {
SelfInfo {self_ty: ty,
self_id: method.self_id,
span: method.self_ty.span}
span: method.explicit_self.span}
});
check_bare_fn(
@ -1192,7 +1192,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
fn check_argument_types(
fcx: @mut FnCtxt,
sp: span,
fn_inputs: &[ty::arg],
fn_inputs: &[ty::t],
callee_expr: @ast::expr,
args: &[@ast::expr],
sugar: ast::CallSugar,
@ -1211,7 +1211,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
let supplied_arg_count = args.len();
let expected_arg_count = fn_inputs.len();
let formal_tys = if expected_arg_count == supplied_arg_count {
fn_inputs.map(|a| a.ty)
fn_inputs.map(|a| *a)
} else {
let suffix = match sugar {
ast::NoSugar => "",
@ -1287,8 +1287,8 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
}
}
fn err_args(len: uint) -> ~[ty::arg] {
vec::from_fn(len, |_| ty::arg { ty: ty::mk_err() })
fn err_args(len: uint) -> ~[ty::t] {
vec::from_fn(len, |_| ty::mk_err())
}
// A generic function for checking assignment expressions
@ -1701,11 +1701,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
let fty = if error_happened {
fty_sig = FnSig {
bound_lifetime_names: opt_vec::Empty,
inputs: fn_ty.sig.inputs.map(|_| {
arg {
ty: ty::mk_err()
}
}),
inputs: fn_ty.sig.inputs.map(|_| ty::mk_err()),
output: ty::mk_err()
};
ty::mk_err()
@ -3132,24 +3128,23 @@ pub fn check_enum_variants(ccx: @mut CrateCtxt,
}
disr_vals.push(*disr_val);
let ctor_ty = ty::node_id_to_type(ccx.tcx, v.node.id);
let arg_tys;
let this_disr_val = *disr_val;
*disr_val += 1;
match v.node.kind {
let arg_tys = match v.node.kind {
ast::tuple_variant_kind(ref args) if args.len() > 0u => {
arg_tys = Some(ty::ty_fn_args(ctor_ty).map(|a| a.ty));
Some(ty::ty_fn_args(ctor_ty).map(|a| *a))
}
ast::tuple_variant_kind(_) => {
arg_tys = Some(~[]);
Some(~[])
}
ast::struct_variant_kind(_) => {
arg_tys = Some(ty::lookup_struct_fields(
Some(ty::lookup_struct_fields(
ccx.tcx, local_def(v.node.id)).map(|cf|
ty::node_id_to_type(ccx.tcx, cf.id.node)));
ty::node_id_to_type(ccx.tcx, cf.id.node)))
}
}
};
match arg_tys {
None => {}
@ -3454,11 +3449,6 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
fn param(ccx: @mut CrateCtxt, n: uint) -> ty::t {
ty::mk_param(ccx.tcx, n, local_def(0))
}
fn arg(ty: ty::t) -> ty::arg {
arg {
ty: ty
}
}
let tcx = ccx.tcx;
let (n_tps, inputs, output) = match *ccx.tcx.sess.str_of(it.ident) {
@ -3466,15 +3456,13 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
~"pref_align_of" | ~"min_align_of" => (1u, ~[], ty::mk_uint()),
~"init" => (1u, ~[], param(ccx, 0u)),
~"uninit" => (1u, ~[], param(ccx, 0u)),
~"forget" => (1u, ~[arg(param(ccx, 0u))], ty::mk_nil()),
~"transmute" => (2, ~[ arg(param(ccx, 0)) ], param(ccx, 1)),
~"forget" => (1u, ~[ param(ccx, 0) ], ty::mk_nil()),
~"transmute" => (2, ~[ param(ccx, 0) ], param(ccx, 1)),
~"move_val" | ~"move_val_init" => {
(1u,
~[
arg(ty::mk_mut_rptr(tcx,
ty::re_bound(ty::br_anon(0)),
param(ccx, 0))),
arg(param(ccx, 0u))
ty::mk_mut_rptr(tcx, ty::re_bound(ty::br_anon(0)), param(ccx, 0)),
param(ccx, 0u)
],
ty::mk_nil())
}
@ -3483,30 +3471,26 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
~"atomic_cxchg" | ~"atomic_cxchg_acq"| ~"atomic_cxchg_rel" => {
(0,
~[
arg(ty::mk_mut_rptr(tcx,
ty::re_bound(ty::br_anon(0)),
ty::mk_int())),
arg(ty::mk_int()),
arg(ty::mk_int())
ty::mk_mut_rptr(tcx,
ty::re_bound(ty::br_anon(0)),
ty::mk_int()),
ty::mk_int(),
ty::mk_int()
],
ty::mk_int())
}
~"atomic_load" | ~"atomic_load_acq" => {
(0,
~[
arg(ty::mk_imm_rptr(tcx,
ty::re_bound(ty::br_anon(0)),
ty::mk_int()))
ty::mk_imm_rptr(tcx, ty::re_bound(ty::br_anon(0)), ty::mk_int())
],
ty::mk_int())
}
~"atomic_store" | ~"atomic_store_rel" => {
(0,
~[
arg(ty::mk_mut_rptr(tcx,
ty::re_bound(ty::br_anon(0)),
ty::mk_int())),
arg(ty::mk_int())
ty::mk_mut_rptr(tcx, ty::re_bound(ty::br_anon(0)), ty::mk_int()),
ty::mk_int()
],
ty::mk_nil())
}
@ -3515,10 +3499,8 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
~"atomic_xchg_rel" | ~"atomic_xadd_rel" | ~"atomic_xsub_rel" => {
(0,
~[
arg(ty::mk_mut_rptr(tcx,
ty::re_bound(ty::br_anon(0)),
ty::mk_int())),
arg(ty::mk_int())
ty::mk_mut_rptr(tcx, ty::re_bound(ty::br_anon(0)), ty::mk_int()),
ty::mk_int()
],
ty::mk_int())
}
@ -3536,7 +3518,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
ty: tydesc_ty,
mutbl: ast::m_imm
});
(0, ~[ arg(td_ptr), arg(visitor_object_ty) ], ty::mk_nil())
(0, ~[ td_ptr, visitor_object_ty ], ty::mk_nil())
}
~"frame_address" => {
let fty = ty::mk_closure(ccx.tcx, ty::ClosureTy {
@ -3546,16 +3528,11 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
region: ty::re_bound(ty::br_anon(0)),
sig: ty::FnSig {
bound_lifetime_names: opt_vec::Empty,
inputs: ~[
arg {
ty: ty::mk_imm_ptr(ccx.tcx,
ty::mk_mach_uint(ast::ty_u8))
}
],
inputs: ~[ty::mk_imm_ptr(ccx.tcx, ty::mk_mach_uint(ast::ty_u8))],
output: ty::mk_nil()
}
});
(0u, ~[ arg(fty) ], ty::mk_nil())
(0u, ~[fty], ty::mk_nil())
}
~"morestack_addr" => {
(0u, ~[], ty::mk_nil_ptr(ccx.tcx))
@ -3563,101 +3540,102 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
~"memmove32" => {
(0,
~[
arg(ty::mk_ptr(tcx, ty::mt {
ty::mk_ptr(tcx, ty::mt {
ty: ty::mk_u8(),
mutbl: ast::m_mutbl
})),
arg(ty::mk_ptr(tcx, ty::mt {
}),
ty::mk_ptr(tcx, ty::mt {
ty: ty::mk_u8(),
mutbl: ast::m_imm
})),
arg(ty::mk_u32())
}),
ty::mk_u32()
],
ty::mk_nil())
}
~"memmove64" => {
(0,
~[arg(ty::mk_ptr(tcx, ty::mt {
ty: ty::mk_u8(),
mutbl: ast::m_mutbl
})),
arg(ty::mk_ptr(tcx, ty::mt {
ty: ty::mk_u8(),
mutbl: ast::m_imm
})),
arg(ty::mk_u64())
~[
ty::mk_ptr(tcx, ty::mt {
ty: ty::mk_u8(),
mutbl: ast::m_mutbl
}),
ty::mk_ptr(tcx, ty::mt {
ty: ty::mk_u8(),
mutbl: ast::m_imm
}),
ty::mk_u64()
],
ty::mk_nil())
}
~"sqrtf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()),
~"sqrtf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()),
~"sqrtf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()),
~"sqrtf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()),
~"powif32" => {
(0,
~[ arg(ty::mk_f32()), arg(ty::mk_i32()) ],
~[ ty::mk_f32(), ty::mk_i32() ],
ty::mk_f32())
}
~"powif64" => {
(0,
~[ arg(ty::mk_f64()), arg(ty::mk_i32()) ],
~[ ty::mk_f64(), ty::mk_i32() ],
ty::mk_f64())
}
~"sinf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()),
~"sinf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()),
~"cosf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()),
~"cosf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()),
~"sinf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()),
~"sinf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()),
~"cosf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()),
~"cosf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()),
~"powf32" => {
(0,
~[ arg(ty::mk_f32()), arg(ty::mk_f32()) ],
~[ ty::mk_f32(), ty::mk_f32() ],
ty::mk_f32())
}
~"powf64" => {
(0,
~[ arg(ty::mk_f64()), arg(ty::mk_f64()) ],
~[ ty::mk_f64(), ty::mk_f64() ],
ty::mk_f64())
}
~"expf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()),
~"expf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()),
~"exp2f32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()),
~"exp2f64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()),
~"logf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()),
~"logf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()),
~"log10f32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()),
~"log10f64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()),
~"log2f32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()),
~"log2f64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()),
~"expf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()),
~"expf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()),
~"exp2f32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()),
~"exp2f64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()),
~"logf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()),
~"logf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()),
~"log10f32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()),
~"log10f64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()),
~"log2f32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()),
~"log2f64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()),
~"fmaf32" => {
(0,
~[ arg(ty::mk_f32()), arg(ty::mk_f32()), arg(ty::mk_f32()) ],
~[ ty::mk_f32(), ty::mk_f32(), ty::mk_f32() ],
ty::mk_f32())
}
~"fmaf64" => {
(0,
~[ arg(ty::mk_f64()), arg(ty::mk_f64()), arg(ty::mk_f64()) ],
~[ ty::mk_f64(), ty::mk_f64(), ty::mk_f64() ],
ty::mk_f64())
}
~"fabsf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()),
~"fabsf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()),
~"floorf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()),
~"floorf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()),
~"ceilf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()),
~"ceilf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()),
~"truncf32" => (0, ~[ arg(ty::mk_f32()) ], ty::mk_f32()),
~"truncf64" => (0, ~[ arg(ty::mk_f64()) ], ty::mk_f64()),
~"ctpop8" => (0, ~[ arg(ty::mk_i8()) ], ty::mk_i8()),
~"ctpop16" => (0, ~[ arg(ty::mk_i16()) ], ty::mk_i16()),
~"ctpop32" => (0, ~[ arg(ty::mk_i32()) ], ty::mk_i32()),
~"ctpop64" => (0, ~[ arg(ty::mk_i64()) ], ty::mk_i64()),
~"ctlz8" => (0, ~[ arg(ty::mk_i8()) ], ty::mk_i8()),
~"ctlz16" => (0, ~[ arg(ty::mk_i16()) ], ty::mk_i16()),
~"ctlz32" => (0, ~[ arg(ty::mk_i32()) ], ty::mk_i32()),
~"ctlz64" => (0, ~[ arg(ty::mk_i64()) ], ty::mk_i64()),
~"cttz8" => (0, ~[ arg(ty::mk_i8()) ], ty::mk_i8()),
~"cttz16" => (0, ~[ arg(ty::mk_i16()) ], ty::mk_i16()),
~"cttz32" => (0, ~[ arg(ty::mk_i32()) ], ty::mk_i32()),
~"cttz64" => (0, ~[ arg(ty::mk_i64()) ], ty::mk_i64()),
~"bswap16" => (0, ~[ arg(ty::mk_i16()) ], ty::mk_i16()),
~"bswap32" => (0, ~[ arg(ty::mk_i32()) ], ty::mk_i32()),
~"bswap64" => (0, ~[ arg(ty::mk_i64()) ], ty::mk_i64()),
~"fabsf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()),
~"fabsf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()),
~"floorf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()),
~"floorf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()),
~"ceilf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()),
~"ceilf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()),
~"truncf32" => (0, ~[ ty::mk_f32() ], ty::mk_f32()),
~"truncf64" => (0, ~[ ty::mk_f64() ], ty::mk_f64()),
~"ctpop8" => (0, ~[ ty::mk_i8() ], ty::mk_i8()),
~"ctpop16" => (0, ~[ ty::mk_i16() ], ty::mk_i16()),
~"ctpop32" => (0, ~[ ty::mk_i32() ], ty::mk_i32()),
~"ctpop64" => (0, ~[ ty::mk_i64() ], ty::mk_i64()),
~"ctlz8" => (0, ~[ ty::mk_i8() ], ty::mk_i8()),
~"ctlz16" => (0, ~[ ty::mk_i16() ], ty::mk_i16()),
~"ctlz32" => (0, ~[ ty::mk_i32() ], ty::mk_i32()),
~"ctlz64" => (0, ~[ ty::mk_i64() ], ty::mk_i64()),
~"cttz8" => (0, ~[ ty::mk_i8() ], ty::mk_i8()),
~"cttz16" => (0, ~[ ty::mk_i16() ], ty::mk_i16()),
~"cttz32" => (0, ~[ ty::mk_i32() ], ty::mk_i32()),
~"cttz64" => (0, ~[ ty::mk_i64() ], ty::mk_i64()),
~"bswap16" => (0, ~[ ty::mk_i16() ], ty::mk_i16()),
~"bswap32" => (0, ~[ ty::mk_i32() ], ty::mk_i32()),
~"bswap64" => (0, ~[ ty::mk_i64() ], ty::mk_i64()),
ref other => {
tcx.sess.span_err(it.span,
~"unrecognized intrinsic function: `" +

View File

@ -258,7 +258,7 @@ pub fn relate_free_regions(
let mut all_tys = ~[];
for fn_sig.inputs.each |arg| {
all_tys.push(arg.ty);
all_tys.push(*arg);
}
for self_ty.each |&t| {
all_tys.push(t);

View File

@ -13,7 +13,6 @@
// substitutions.
use middle::pat_util;
use middle::ty::arg;
use middle::ty;
use middle::typeck::check::{FnCtxt, SelfInfo};
use middle::typeck::infer::{force_all, resolve_all, resolve_region};
@ -63,14 +62,9 @@ fn resolve_method_map_entry(fcx: @mut FnCtxt, sp: span, id: ast::node_id) {
match fcx.inh.method_map.find(&id) {
None => {}
Some(mme) => {
for resolve_type_vars_in_type(fcx, sp, mme.self_arg.ty).each |t| {
for resolve_type_vars_in_type(fcx, sp, mme.self_ty).each |t| {
let method_map = fcx.ccx.method_map;
let new_entry = method_map_entry {
self_arg: arg {
ty: *t
},
..*mme
};
let new_entry = method_map_entry { self_ty: *t, ..*mme };
debug!("writeback::resolve_method_map_entry(id=%?, \
new_entry=%?)",
id, new_entry);

View File

@ -156,7 +156,7 @@ pub fn method_to_MethodInfo(ast_method: @method) -> @MethodInfo {
did: local_def(ast_method.id),
n_tps: ast_method.generics.ty_params.len(),
ident: ast_method.ident,
self_type: ast_method.self_ty.node
explicit_self: ast_method.explicit_self.node
}
}
@ -383,7 +383,7 @@ pub impl CoherenceChecker {
did: new_did,
n_tps: trait_method.generics.type_param_defs.len(),
ident: trait_method.ident,
self_type: trait_method.self_ty
explicit_self: trait_method.explicit_self
},
trait_method_def_id: trait_method.def_id
};
@ -527,7 +527,7 @@ pub impl CoherenceChecker {
#[cfg(stage0)]
fn each_provided_trait_method(&self,
trait_did: ast::def_id,
f: &fn(x: @ty::method) -> bool) {
f: &fn(@ty::Method) -> bool) {
// Make a list of all the names of the provided methods.
// XXX: This is horrible.
let mut provided_method_idents = HashSet::new();
@ -547,7 +547,7 @@ pub impl CoherenceChecker {
#[cfg(not(stage0))]
fn each_provided_trait_method(&self,
trait_did: ast::def_id,
f: &fn(x: @ty::method) -> bool) -> bool {
f: &fn(x: @ty::Method) -> bool) -> bool {
// Make a list of all the names of the provided methods.
// XXX: This is horrible.
let mut provided_method_idents = HashSet::new();
@ -975,7 +975,7 @@ pub impl CoherenceChecker {
did: new_did,
n_tps: trait_method_info.ty.generics.type_param_defs.len(),
ident: trait_method_info.ty.ident,
self_type: trait_method_info.ty.self_ty
explicit_self: trait_method_info.ty.explicit_self
},
trait_method_def_id: trait_method_info.def_id
};
@ -1073,7 +1073,7 @@ fn subst_receiver_types_in_method_ty(
impl_id: ast::node_id,
trait_ref: &ty::TraitRef,
new_def_id: ast::def_id,
method: &ty::method) -> ty::method
method: &ty::Method) -> ty::Method
{
/*!
* Substitutes the values for the receiver's type parameters
@ -1117,19 +1117,22 @@ fn subst_receiver_types_in_method_ty(
tps: combined_tps
};
ty::method {
ident: method.ident,
ty::Method::new(
method.ident,
// method types *can* appear in the generic bounds
method.generics.subst(tcx, &combined_substs),
// method tps cannot appear in the self_ty, so use `substs` from trait ref
transformed_self_ty: method.transformed_self_ty.subst(tcx, &trait_ref.substs),
method.transformed_self_ty.subst(tcx, &trait_ref.substs),
// method types *can* appear in the generic bounds or the fty
generics: method.generics.subst(tcx, &combined_substs),
fty: method.fty.subst(tcx, &combined_substs),
self_ty: method.self_ty,
vis: method.vis,
def_id: new_def_id
}
// method types *can* appear in the fty
method.fty.subst(tcx, &combined_substs),
method.explicit_self,
method.vis,
new_def_id
)
}
pub fn check_coherence(crate_context: @mut CrateCtxt, crate: @crate) {

View File

@ -52,7 +52,7 @@ use syntax::ast_map;
use syntax::ast_util::{local_def, split_trait_methods};
use syntax::codemap::span;
use syntax::codemap;
use syntax::print::pprust::{path_to_str, self_ty_to_str};
use syntax::print::pprust::{path_to_str, explicit_self_to_str};
use syntax::visit;
use syntax::opt_vec::OptVec;
use syntax::opt_vec;
@ -227,26 +227,26 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
}, _) => {
let trait_ty_generics = ty_generics(ccx, region_paramd, generics, 0);
// For each method, construct a suitable ty::method and
// For each method, construct a suitable ty::Method and
// store it into the `tcx.methods` table:
for ms.each |m| {
let ty_method = @match m {
&ast::required(ref m) => {
ty_method_of_trait_method(
ccx, trait_id, region_paramd, generics,
&m.id, &m.ident, &m.self_ty,
&m.id, &m.ident, &m.explicit_self,
&m.generics, &m.purity, &m.decl)
}
&ast::provided(ref m) => {
ty_method_of_trait_method(
ccx, trait_id, region_paramd, generics,
&m.id, &m.ident, &m.self_ty,
&m.id, &m.ident, &m.explicit_self,
&m.generics, &m.purity, &m.decl)
}
};
if ty_method.self_ty == ast::sty_static {
if ty_method.explicit_self == ast::sty_static {
make_static_method_ty(ccx, trait_id, ty_method,
&trait_ty_generics);
}
@ -270,7 +270,7 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
fn make_static_method_ty(ccx: &CrateCtxt,
trait_id: ast::node_id,
m: &ty::method,
m: &ty::Method,
trait_ty_generics: &ty::Generics) {
// If declaration is
//
@ -376,27 +376,27 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt,
trait_generics: &ast::Generics,
m_id: &ast::node_id,
m_ident: &ast::ident,
m_self_ty: &ast::self_ty,
m_explicit_self: &ast::explicit_self,
m_generics: &ast::Generics,
m_purity: &ast::purity,
m_decl: &ast::fn_decl) -> ty::method
m_decl: &ast::fn_decl) -> ty::Method
{
let trait_self_ty = ty::mk_self(this.tcx, local_def(trait_id));
let rscope = MethodRscope::new(m_self_ty.node, trait_rp, trait_generics);
let rscope = MethodRscope::new(m_explicit_self.node, trait_rp, trait_generics);
let (transformed_self_ty, fty) =
astconv::ty_of_method(this, &rscope, *m_purity, &m_generics.lifetimes,
trait_self_ty, *m_self_ty, m_decl);
trait_self_ty, *m_explicit_self, m_decl);
let num_trait_type_params = trait_generics.ty_params.len();
ty::method {
ident: *m_ident,
generics: ty_generics(this, None, m_generics, num_trait_type_params),
transformed_self_ty: transformed_self_ty,
fty: fty,
self_ty: m_self_ty.node,
ty::Method::new(
*m_ident,
ty_generics(this, None, m_generics, num_trait_type_params),
transformed_self_ty,
fty,
m_explicit_self.node,
// assume public, because this is only invoked on trait methods
vis: ast::public,
def_id: local_def(*m_id)
}
ast::public,
local_def(*m_id)
)
}
}
@ -444,7 +444,7 @@ pub fn ensure_supertraits(ccx: &CrateCtxt,
pub fn compare_impl_method(tcx: ty::ctxt,
impl_tps: uint,
cm: &ConvertedMethod,
trait_m: &ty::method,
trait_m: &ty::Method,
trait_substs: &ty::substs,
self_ty: ty::t) {
debug!("compare_impl_method()");
@ -459,7 +459,7 @@ pub fn compare_impl_method(tcx: ty::ctxt,
// that the error messages you get out of this code are a bit more
// inscrutable, particularly for cases where one method has no
// self.
match (&trait_m.self_ty, &impl_m.self_ty) {
match (&trait_m.explicit_self, &impl_m.explicit_self) {
(&ast::sty_static, &ast::sty_static) => {}
(&ast::sty_static, _) => {
tcx.sess.span_err(
@ -467,7 +467,7 @@ pub fn compare_impl_method(tcx: ty::ctxt,
fmt!("method `%s` has a `%s` declaration in the impl, \
but not in the trait",
*tcx.sess.str_of(trait_m.ident),
self_ty_to_str(impl_m.self_ty, tcx.sess.intr())));
explicit_self_to_str(impl_m.explicit_self, tcx.sess.intr())));
return;
}
(_, &ast::sty_static) => {
@ -476,7 +476,7 @@ pub fn compare_impl_method(tcx: ty::ctxt,
fmt!("method `%s` has a `%s` declaration in the trait, \
but not in the impl",
*tcx.sess.str_of(trait_m.ident),
self_ty_to_str(trait_m.self_ty, tcx.sess.intr())));
explicit_self_to_str(trait_m.explicit_self, tcx.sess.intr())));
return;
}
_ => {
@ -576,14 +576,10 @@ pub fn compare_impl_method(tcx: ty::ctxt,
// represent the self argument (unless this is a static method).
// This argument will have the *transformed* self type.
for trait_m.transformed_self_ty.each |&t| {
trait_fn_args.push(ty::arg {
ty: t
});
trait_fn_args.push(t);
}
for impl_m.transformed_self_ty.each |&t| {
impl_fn_args.push(ty::arg {
ty: t
});
impl_fn_args.push(t);
}
// Add in the normal arguments.
@ -727,7 +723,7 @@ pub fn convert_field(ccx: &CrateCtxt,
}
pub struct ConvertedMethod {
mty: @ty::method,
mty: @ty::Method,
id: ast::node_id,
span: span,
body_id: ast::node_id
@ -780,16 +776,16 @@ pub fn convert_methods(ccx: &CrateCtxt,
untransformed_rcvr_ty: ty::t,
rcvr_generics: &ast::Generics,
rcvr_visibility: ast::visibility,
method_generics: &ast::Generics) -> ty::method
method_generics: &ast::Generics) -> ty::Method
{
let rscope = MethodRscope::new(m.self_ty.node,
let rscope = MethodRscope::new(m.explicit_self.node,
rp,
rcvr_generics);
let (transformed_self_ty, fty) =
astconv::ty_of_method(ccx, &rscope, m.purity,
&method_generics.lifetimes,
untransformed_rcvr_ty,
m.self_ty, &m.decl);
m.explicit_self, &m.decl);
// if the method specifies a visibility, use that, otherwise
// inherit the visibility from the impl (so `foo` in `pub impl
@ -798,15 +794,15 @@ pub fn convert_methods(ccx: &CrateCtxt,
let method_vis = m.vis.inherit_from(rcvr_visibility);
let num_rcvr_type_params = rcvr_generics.ty_params.len();
ty::method {
ident: m.ident,
generics: ty_generics(ccx, None, &m.generics, num_rcvr_type_params),
transformed_self_ty: transformed_self_ty,
fty: fty,
self_ty: m.self_ty.node,
vis: method_vis,
def_id: local_def(m.id)
}
ty::Method::new(
m.ident,
ty_generics(ccx, None, &m.generics, num_rcvr_type_params),
transformed_self_ty,
fty,
m.explicit_self.node,
method_vis,
local_def(m.id)
)
}
}

View File

@ -55,7 +55,7 @@
// now.
use middle::ty::{FloatVar, FnSig, IntVar, TyVar};
use middle::ty::{IntType, UintType, arg, substs};
use middle::ty::{IntType, UintType, substs};
use middle::ty;
use middle::typeck::infer::glb::Glb;
use middle::typeck::infer::lub::Lub;
@ -95,7 +95,7 @@ pub trait Combine {
b: &ty::ClosureTy) -> cres<ty::ClosureTy>;
fn fn_sigs(&self, a: &ty::FnSig, b: &ty::FnSig) -> cres<ty::FnSig>;
fn flds(&self, a: ty::field, b: ty::field) -> cres<ty::field>;
fn args(&self, a: ty::arg, b: ty::arg) -> cres<ty::arg>;
fn args(&self, a: ty::t, b: ty::t) -> cres<ty::t>;
fn sigils(&self, p1: ast::Sigil, p2: ast::Sigil) -> cres<ast::Sigil>;
fn purities(&self, a: purity, b: purity) -> cres<purity>;
fn abis(&self, a: AbiSet, b: AbiSet) -> cres<AbiSet>;
@ -311,12 +311,9 @@ pub fn super_flds<C:Combine>(
}
}
pub fn super_args<C:Combine>(this: &C, a: ty::arg, b: ty::arg)
-> cres<ty::arg> {
do this.contratys(a.ty, b.ty).chain |t| {
Ok(arg {
ty: t
})
pub fn super_args<C:Combine>(this: &C, a: ty::t, b: ty::t) -> cres<ty::t> {
do this.contratys(a, b).chain |t| {
Ok(t)
}
}
@ -407,10 +404,7 @@ pub fn super_bare_fn_tys<C:Combine>(
pub fn super_fn_sigs<C:Combine>(
this: &C, a_f: &ty::FnSig, b_f: &ty::FnSig) -> cres<ty::FnSig>
{
fn argvecs<C:Combine>(this: &C,
a_args: &[ty::arg],
b_args: &[ty::arg]) -> cres<~[ty::arg]>
{
fn argvecs<C:Combine>(this: &C, a_args: &[ty::t], b_args: &[ty::t]) -> cres<~[ty::t]> {
if vec::same_length(a_args, b_args) {
map_vec2(a_args, b_args, |a, b| this.args(*a, *b))
} else {

View File

@ -153,7 +153,7 @@ impl Combine for Glb {
super_trait_stores(self, vk, a, b)
}
fn args(&self, a: ty::arg, b: ty::arg) -> cres<ty::arg> {
fn args(&self, a: ty::t, b: ty::t) -> cres<ty::t> {
super_args(self, a, b)
}

View File

@ -236,7 +236,7 @@ impl Combine for Lub {
super_trait_stores(self, vk, a, b)
}
fn args(&self, a: ty::arg, b: ty::arg) -> cres<ty::arg> {
fn args(&self, a: ty::t, b: ty::t) -> cres<ty::t> {
super_args(self, a, b)
}

View File

@ -245,7 +245,7 @@ impl Combine for Sub {
super_trait_stores(self, vk, a, b)
}
fn args(&self, a: ty::arg, b: ty::arg) -> cres<ty::arg> {
fn args(&self, a: ty::t, b: ty::t) -> cres<ty::t> {
super_args(self, a, b)
}

View File

@ -31,7 +31,7 @@ impl InferStr for ty::t {
impl InferStr for FnSig {
fn inf_str(&self, cx: &InferCtxt) -> ~str {
fmt!("(%s) -> %s",
str::connect(self.inputs.map(|a| a.ty.inf_str(cx)), ", "),
str::connect(self.inputs.map(|a| a.inf_str(cx)), ", "),
self.output.inf_str(cx))
}
}

View File

@ -118,13 +118,13 @@ pub struct method_param {
pub struct method_map_entry {
// the type of the self parameter, which is not reflected in the fn type
// (FIXME #3446)
self_arg: ty::arg,
self_ty: ty::t,
// the mode of `self`
self_mode: ty::SelfMode,
// the type of explicit self on the method
explicit_self: ast::self_ty_,
explicit_self: ast::explicit_self_,
// method details being invoked
origin: method_origin,
@ -351,22 +351,15 @@ fn check_start_fn_ty(ccx: @mut CrateCtxt,
_ => ()
}
fn arg(ty: ty::t) -> ty::arg {
ty::arg {
ty: ty
}
}
let se_ty = ty::mk_bare_fn(tcx, ty::BareFnTy {
purity: ast::impure_fn,
abis: abi::AbiSet::Rust(),
sig: ty::FnSig {
bound_lifetime_names: opt_vec::Empty,
inputs: ~[
arg(ty::mk_int()),
arg(ty::mk_imm_ptr(tcx,
ty::mk_imm_ptr(tcx, ty::mk_u8()))),
arg(ty::mk_imm_ptr(tcx, ty::mk_u8()))
ty::mk_int(),
ty::mk_imm_ptr(tcx, ty::mk_imm_ptr(tcx, ty::mk_u8())),
ty::mk_imm_ptr(tcx, ty::mk_u8())
],
output: ty::mk_int()
}

View File

@ -142,7 +142,7 @@ impl RegionParameterization {
}
pub struct MethodRscope {
self_ty: ast::self_ty_,
explicit_self: ast::explicit_self_,
variance: Option<ty::region_variance>,
region_param_names: RegionParamNames,
}
@ -150,14 +150,14 @@ pub struct MethodRscope {
impl MethodRscope {
// `generics` here refers to the generics of the outer item (impl or
// trait).
pub fn new(self_ty: ast::self_ty_,
pub fn new(explicit_self: ast::explicit_self_,
variance: Option<ty::region_variance>,
rcvr_generics: &ast::Generics)
-> MethodRscope {
let region_param_names =
RegionParamNames::from_generics(rcvr_generics);
MethodRscope {
self_ty: self_ty,
explicit_self: explicit_self,
variance: variance,
region_param_names: region_param_names
}

View File

@ -11,7 +11,7 @@
use metadata::encoder;
use middle::ty::{ReSkolemized, ReVar};
use middle::ty::{bound_region, br_anon, br_named, br_self, br_cap_avoid};
use middle::ty::{br_fresh, ctxt, field, method};
use middle::ty::{br_fresh, ctxt, field};
use middle::ty::{mt, t, param_ty};
use middle::ty::{re_bound, re_free, re_scope, re_infer, re_static, Region,
re_empty};
@ -281,7 +281,7 @@ pub fn tys_to_str(cx: ctxt, ts: &[t]) -> ~str {
pub fn fn_sig_to_str(cx: ctxt, typ: &ty::FnSig) -> ~str {
fmt!("fn%s -> %s",
tys_to_str(cx, typ.inputs.map(|a| a.ty)),
tys_to_str(cx, typ.inputs.map(|a| *a)),
ty_to_str(cx, typ.output))
}
@ -290,8 +290,8 @@ pub fn trait_ref_to_str(cx: ctxt, trait_ref: &ty::TraitRef) -> ~str {
}
pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
fn fn_input_to_str(cx: ctxt, input: ty::arg) -> ~str {
ty_to_str(cx, input.ty)
fn fn_input_to_str(cx: ctxt, input: ty::t) -> ~str {
ty_to_str(cx, input)
}
fn bare_fn_to_str(cx: ctxt,
purity: ast::purity,
@ -375,7 +375,7 @@ pub fn ty_to_str(cx: ctxt, typ: t) -> ~str {
}
}
}
fn method_to_str(cx: ctxt, m: method) -> ~str {
fn method_to_str(cx: ctxt, m: ty::Method) -> ~str {
bare_fn_to_str(cx,
m.fty.purity,
m.fty.abis,
@ -633,15 +633,15 @@ impl Repr for ty::Generics {
}
}
impl Repr for ty::method {
impl Repr for ty::Method {
fn repr(&self, tcx: ctxt) -> ~str {
fmt!("method {ident: %s, generics: %s, transformed_self_ty: %s, \
fty: %s, self_ty: %s, vis: %s, def_id: %s}",
fty: %s, explicit_self: %s, vis: %s, def_id: %s}",
self.ident.repr(tcx),
self.generics.repr(tcx),
self.transformed_self_ty.repr(tcx),
self.fty.repr(tcx),
self.self_ty.repr(tcx),
self.explicit_self.repr(tcx),
self.vis.repr(tcx),
self.def_id.repr(tcx))
}
@ -653,7 +653,7 @@ impl Repr for ast::ident {
}
}
impl Repr for ast::self_ty_ {
impl Repr for ast::explicit_self_ {
fn repr(&self, _tcx: ctxt) -> ~str {
fmt!("%?", *self)
}
@ -685,18 +685,12 @@ impl Repr for typeck::method_map_entry {
fmt!("method_map_entry {self_arg: %s, \
explicit_self: %s, \
origin: %s}",
self.self_arg.repr(tcx),
self.self_ty.repr(tcx),
self.explicit_self.repr(tcx),
self.origin.repr(tcx))
}
}
impl Repr for ty::arg {
fn repr(&self, tcx: ctxt) -> ~str {
fmt!("(%s)", self.ty.repr(tcx))
}
}
impl Repr for typeck::method_origin {
fn repr(&self, tcx: ctxt) -> ~str {
match self {

View File

@ -187,7 +187,7 @@ fn get_method_sig(
&ty_m.decl,
ty_m.purity,
ty_m.ident,
Some(ty_m.self_ty.node),
Some(ty_m.explicit_self.node),
&ty_m.generics,
extract::interner()
))
@ -197,7 +197,7 @@ fn get_method_sig(
&m.decl,
m.purity,
m.ident,
Some(m.self_ty.node),
Some(m.explicit_self.node),
&m.generics,
extract::interner()
))
@ -218,7 +218,7 @@ fn get_method_sig(
&method.decl,
method.purity,
method.ident,
Some(method.self_ty.node),
Some(method.explicit_self.node),
&method.generics,
extract::interner()
))

View File

@ -17,6 +17,7 @@ use opt_vec::OptVec;
use core::cast;
use core::option::{None, Option, Some};
use core::to_bytes;
use core::to_bytes::IterBytes;
use core::to_str::ToStr;
use std::serialize::{Encodable, Decodable, Encoder, Decoder};
@ -123,6 +124,20 @@ pub struct Lifetime {
ident: ident
}
#[cfg(stage0)]
impl to_bytes::IterBytes for Lifetime {
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_3(&self.id, &self.span, &self.ident, lsb0, f)
}
}
#[cfg(not(stage0))]
impl to_bytes::IterBytes for Lifetime {
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
to_bytes::iter_bytes_3(&self.id, &self.span, &self.ident, lsb0, f)
}
}
// a "Path" is essentially Rust's notion of a name;
// for instance: core::cmp::Eq . It's represented
// as a sequence of identifiers, along with a bunch
@ -754,7 +769,7 @@ pub struct ty_method {
purity: purity,
decl: fn_decl,
generics: Generics,
self_ty: self_ty,
explicit_self: explicit_self,
id: node_id,
span: span,
}
@ -1051,7 +1066,7 @@ impl to_bytes::IterBytes for ret_style {
#[auto_encode]
#[auto_decode]
#[deriving(Eq)]
pub enum self_ty_ {
pub enum explicit_self_ {
sty_static, // no self
sty_value, // `self`
sty_region(Option<@Lifetime>, mutability), // `&'lt self`
@ -1059,7 +1074,33 @@ pub enum self_ty_ {
sty_uniq(mutability) // `~self`
}
pub type self_ty = spanned<self_ty_>;
#[cfg(stage0)]
impl to_bytes::IterBytes for explicit_self_ {
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
match *self {
sty_static => 0u8.iter_bytes(lsb0, f),
sty_value => 1u8.iter_bytes(lsb0, f),
sty_region(ref lft, ref mutbl) => to_bytes::iter_bytes_3(&2u8, &lft, mutbl, lsb0, f),
sty_box(ref mutbl) => to_bytes::iter_bytes_2(&3u8, mutbl, lsb0, f),
sty_uniq(ref mutbl) => to_bytes::iter_bytes_2(&4u8, mutbl, lsb0, f),
}
}
}
#[cfg(not(stage0))]
impl to_bytes::IterBytes for explicit_self_ {
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
match *self {
sty_static => 0u8.iter_bytes(lsb0, f),
sty_value => 1u8.iter_bytes(lsb0, f),
sty_region(ref lft, ref mutbl) => to_bytes::iter_bytes_3(&2u8, &lft, mutbl, lsb0, f),
sty_box(ref mutbl) => to_bytes::iter_bytes_2(&3u8, mutbl, lsb0, f),
sty_uniq(ref mutbl) => to_bytes::iter_bytes_2(&4u8, mutbl, lsb0, f),
}
}
}
pub type explicit_self = spanned<explicit_self_>;
#[auto_encode]
#[auto_decode]
@ -1068,7 +1109,7 @@ pub struct method {
ident: ident,
attrs: ~[attribute],
generics: Generics,
self_ty: self_ty,
explicit_self: explicit_self,
purity: purity,
decl: fn_decl,
body: blk,

View File

@ -272,7 +272,7 @@ pub fn trait_method_to_ty_method(method: &trait_method) -> ty_method {
purity: m.purity,
decl: copy m.decl,
generics: copy m.generics,
self_ty: m.self_ty,
explicit_self: m.explicit_self,
id: m.id,
span: m.span,
}

View File

@ -152,6 +152,20 @@ impl<D:Decoder> Decodable<D> for span {
}
}
#[cfg(stage0)]
impl to_bytes::IterBytes for span {
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_3(&self.lo, &self.hi, &self.expn_info, lsb0, f);
}
}
#[cfg(not(stage0))]
impl to_bytes::IterBytes for span {
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
to_bytes::iter_bytes_3(&self.lo, &self.hi, &self.expn_info, lsb0, f)
}
}
pub fn spanned<T>(lo: BytePos, hi: BytePos, t: T) -> spanned<T> {
respan(mk_sp(lo, hi), t)
}
@ -199,16 +213,62 @@ pub struct FileMapAndLine {fm: @FileMap, line: uint}
pub struct FileMapAndBytePos {fm: @FileMap, pos: BytePos}
pub struct NameAndSpan {name: ~str, span: Option<span>}
#[cfg(stage0)]
impl to_bytes::IterBytes for NameAndSpan {
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_2(&self.name, &self.span, lsb0, f)
}
}
#[cfg(not(stage0))]
impl to_bytes::IterBytes for NameAndSpan {
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
to_bytes::iter_bytes_2(&self.name, &self.span, lsb0, f)
}
}
pub struct CallInfo {
call_site: span,
callee: NameAndSpan
}
#[cfg(stage0)]
impl to_bytes::IterBytes for CallInfo {
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_2(&self.call_site, &self.callee, lsb0, f)
}
}
#[cfg(not(stage0))]
impl to_bytes::IterBytes for CallInfo {
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
to_bytes::iter_bytes_2(&self.call_site, &self.callee, lsb0, f)
}
}
/// Extra information for tracking macro expansion of spans
pub enum ExpnInfo {
ExpandedFrom(CallInfo)
}
#[cfg(stage0)]
impl to_bytes::IterBytes for ExpnInfo {
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
match *self {
ExpandedFrom(ref call_info) => to_bytes::iter_bytes_2(&0u8, call_info, lsb0, f)
}
}
}
#[cfg(not(stage0))]
impl to_bytes::IterBytes for ExpnInfo {
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) -> bool {
match *self {
ExpandedFrom(ref call_info) => to_bytes::iter_bytes_2(&0u8, call_info, lsb0, f)
}
}
}
pub type FileName = ~str;
pub struct FileLines

View File

@ -713,7 +713,7 @@ fn mk_ser_method(
ident: cx.ident_of("encode"),
attrs: ~[],
generics: ast_util::empty_generics(),
self_ty: codemap::spanned {
explicit_self: codemap::spanned {
node: ast::sty_region(None, ast::m_imm),
span: span
},
@ -772,7 +772,7 @@ fn mk_deser_method(
ident: cx.ident_of("decode"),
attrs: ~[],
generics: ast_util::empty_generics(),
self_ty: codemap::spanned { node: ast::sty_static, span: span },
explicit_self: codemap::spanned { node: ast::sty_static, span: span },
purity: ast::impure_fn,
decl: deser_decl,
body: deser_body,

View File

@ -28,7 +28,7 @@ pub fn expand_deriving_clone(cx: @ext_ctxt,
MethodDef {
name: ~"clone",
generics: LifetimeBounds::empty(),
self_ty: borrowed_explicit_self(),
explicit_self: borrowed_explicit_self(),
args: ~[],
ret_ty: Self,
const_nonmatching: false,

View File

@ -34,7 +34,7 @@ pub fn expand_deriving_eq(cx: @ext_ctxt,
MethodDef {
name: $name,
generics: LifetimeBounds::empty(),
self_ty: borrowed_explicit_self(),
explicit_self: borrowed_explicit_self(),
args: ~[borrowed_self()],
ret_ty: Literal(Path::new(~[~"bool"])),
const_nonmatching: true,

View File

@ -24,7 +24,7 @@ pub fn expand_deriving_ord(cx: @ext_ctxt,
MethodDef {
name: $name,
generics: LifetimeBounds::empty(),
self_ty: borrowed_explicit_self(),
explicit_self: borrowed_explicit_self(),
args: ~[borrowed_self()],
ret_ty: Literal(Path::new(~[~"bool"])),
const_nonmatching: false,

View File

@ -33,7 +33,7 @@ pub fn expand_deriving_totaleq(cx: @ext_ctxt,
MethodDef {
name: ~"equals",
generics: LifetimeBounds::empty(),
self_ty: borrowed_explicit_self(),
explicit_self: borrowed_explicit_self(),
args: ~[borrowed_self()],
ret_ty: Literal(Path::new(~[~"bool"])),
const_nonmatching: true,

View File

@ -27,7 +27,7 @@ pub fn expand_deriving_totalord(cx: @ext_ctxt,
MethodDef {
name: ~"cmp",
generics: LifetimeBounds::empty(),
self_ty: borrowed_explicit_self(),
explicit_self: borrowed_explicit_self(),
args: ~[borrowed_self()],
ret_ty: Literal(Path::new(~[~"core", ~"cmp", ~"Ordering"])),
const_nonmatching: false,

View File

@ -119,13 +119,13 @@ fn create_decode_method(
let body_block = build::mk_simple_block(cx, span, expr);
// Create the method.
let self_ty = spanned { node: sty_static, span: span };
let explicit_self = spanned { node: sty_static, span: span };
let method_ident = cx.ident_of("decode");
@ast::method {
ident: method_ident,
attrs: ~[],
generics: ast_util::empty_generics(),
self_ty: self_ty,
explicit_self: explicit_self,
purity: impure_fn,
decl: fn_decl,
body: body_block,

View File

@ -111,13 +111,13 @@ fn create_encode_method(
let body_block = build::mk_block_(cx, span, statements);
// Create the method.
let self_ty = spanned { node: sty_region(None, m_imm), span: span };
let explicit_self = spanned { node: sty_region(None, m_imm), span: span };
let method_ident = cx.ident_of("encode");
@ast::method {
ident: method_ident,
attrs: ~[],
generics: ast_util::empty_generics(),
self_ty: self_ty,
explicit_self: explicit_self,
purity: impure_fn,
decl: fn_decl,
body: body_block,

View File

@ -216,7 +216,7 @@ pub struct MethodDef<'self> {
/// Whether there is a self argument (outer Option) i.e. whether
/// this is a static function, and whether it is a pointer (inner
/// Option)
self_ty: Option<Option<PtrTy>>,
explicit_self: Option<Option<PtrTy>>,
/// Arguments other than the self argument
args: ~[Ty],
@ -321,7 +321,7 @@ impl<'self> TraitDef<'self> {
type_ident: ident,
generics: &Generics) -> @ast::item {
let methods = do self.methods.map |method_def| {
let (self_ty, self_args, nonself_args, tys) =
let (explicit_self, self_args, nonself_args, tys) =
method_def.split_self_nonself_args(cx, span, type_ident, generics);
let body = if method_def.is_static() {
@ -339,7 +339,7 @@ impl<'self> TraitDef<'self> {
method_def.create_method(cx, span,
type_ident, generics,
self_ty, tys,
explicit_self, tys,
body)
};
@ -352,7 +352,7 @@ impl<'self> TraitDef<'self> {
type_ident: ident,
generics: &Generics) -> @ast::item {
let methods = do self.methods.map |method_def| {
let (self_ty, self_args, nonself_args, tys) =
let (explicit_self, self_args, nonself_args, tys) =
method_def.split_self_nonself_args(cx, span, type_ident, generics);
let body = if method_def.is_static() {
@ -370,7 +370,7 @@ impl<'self> TraitDef<'self> {
method_def.create_method(cx, span,
type_ident, generics,
self_ty, tys,
explicit_self, tys,
body)
};
@ -404,28 +404,27 @@ impl<'self> MethodDef<'self> {
}
fn is_static(&self) -> bool {
self.self_ty.is_none()
self.explicit_self.is_none()
}
fn split_self_nonself_args(&self, cx: @ext_ctxt, span: span,
type_ident: ident, generics: &Generics)
-> (ast::self_ty, ~[@expr], ~[@expr], ~[(ident, @ast::Ty)]) {
-> (ast::explicit_self, ~[@expr], ~[@expr], ~[(ident, @ast::Ty)]) {
let mut self_args = ~[], nonself_args = ~[], arg_tys = ~[];
let mut ast_self_ty = respan(span, ast::sty_static);
let mut nonstatic = false;
match self.self_ty {
let ast_explicit_self = match self.explicit_self {
Some(ref self_ptr) => {
let (self_expr, self_ty) = ty::get_explicit_self(cx, span,
self_ptr);
let (self_expr, explicit_self) = ty::get_explicit_self(cx, span, self_ptr);
ast_self_ty = self_ty;
self_args.push(self_expr);
nonstatic = true;
explicit_self
}
_ => {}
}
None => respan(span, ast::sty_static),
};
for self.args.eachi |i, ty| {
let ast_ty = ty.to_ty(cx, span, type_ident, generics);
@ -449,13 +448,13 @@ impl<'self> MethodDef<'self> {
}
}
(ast_self_ty, self_args, nonself_args, arg_tys)
(ast_explicit_self, self_args, nonself_args, arg_tys)
}
fn create_method(&self, cx: @ext_ctxt, span: span,
type_ident: ident,
generics: &Generics,
self_ty: ast::self_ty,
explicit_self: ast::explicit_self,
arg_types: ~[(ident, @ast::Ty)],
body: @expr) -> @ast::method {
// create the generics that aren't for Self
@ -477,7 +476,7 @@ impl<'self> MethodDef<'self> {
ident: method_ident,
attrs: ~[],
generics: fn_generics,
self_ty: self_ty,
explicit_self: explicit_self,
purity: ast::impure_fn,
decl: fn_decl,
body: body_block,

View File

@ -26,7 +26,7 @@ pub fn expand_deriving_iter_bytes(cx: @ext_ctxt,
MethodDef {
name: ~"iter_bytes",
generics: LifetimeBounds::empty(),
self_ty: borrowed_explicit_self(),
explicit_self: borrowed_explicit_self(),
args: ~[
Literal(Path::new(~[~"bool"])),
Literal(Path::new(~[~"core", ~"to_bytes", ~"Cb"]))

View File

@ -32,7 +32,7 @@ pub fn expand_deriving_rand(cx: @ext_ctxt,
bounds: ~[(~"R",
~[ Path::new(~[~"core", ~"rand", ~"Rng"]) ])]
},
self_ty: None,
explicit_self: None,
args: ~[
Ptr(~Literal(Path::new_local(~"R")),
Borrowed(None, ast::m_mutbl))

View File

@ -27,7 +27,7 @@ pub fn expand_deriving_to_str(cx: @ext_ctxt,
MethodDef {
name: ~"to_str",
generics: LifetimeBounds::empty(),
self_ty: borrowed_explicit_self(),
explicit_self: borrowed_explicit_self(),
args: ~[],
ret_ty: Ptr(~Literal(Path::new_local(~"str")), Owned),
const_nonmatching: false,

View File

@ -217,7 +217,7 @@ pub impl LifetimeBounds {
pub fn get_explicit_self(cx: @ext_ctxt, span: span, self_ptr: &Option<PtrTy>)
-> (@expr, ast::self_ty) {
-> (@expr, ast::explicit_self) {
let self_path = build::make_self(cx, span);
match *self_ptr {
None => {

View File

@ -323,7 +323,7 @@ fn noop_fold_method(m: @method, fld: @ast_fold) -> @method {
ident: fld.fold_ident(m.ident),
attrs: /* FIXME (#2543) */ copy m.attrs,
generics: fold_generics(&m.generics, fld),
self_ty: m.self_ty,
explicit_self: m.explicit_self,
purity: m.purity,
decl: fold_fn_decl(&m.decl, fld),
body: fld.fold_block(&m.body),

View File

@ -19,7 +19,7 @@ use ast::{_mod, add, arg, arm, attribute, bind_by_ref, bind_infer};
use ast::{bind_by_copy, bitand, bitor, bitxor, blk};
use ast::{blk_check_mode, box};
use ast::{crate, crate_cfg, decl, decl_item};
use ast::{decl_local, default_blk, deref, div, enum_def};
use ast::{decl_local, default_blk, deref, div, enum_def, explicit_self};
use ast::{expr, expr_, expr_addr_of, expr_match, expr_again};
use ast::{expr_assign, expr_assign_op, expr_binary, expr_block};
use ast::{expr_break, expr_call, expr_cast, expr_copy, expr_do_body};
@ -43,7 +43,7 @@ use ast::{named_field, neg, node_id, noreturn, not, pat, pat_box, pat_enum};
use ast::{pat_ident, pat_lit, pat_range, pat_region, pat_struct};
use ast::{pat_tup, pat_uniq, pat_wild, private};
use ast::{rem, required};
use ast::{ret_style, return_val, self_ty, shl, shr, stmt, stmt_decl};
use ast::{ret_style, return_val, shl, shr, stmt, stmt_decl};
use ast::{stmt_expr, stmt_semi, stmt_mac, struct_def, struct_field};
use ast::{struct_variant_kind, subtract};
use ast::{sty_box, sty_region, sty_static, sty_uniq, sty_value};
@ -504,7 +504,7 @@ pub impl Parser {
let generics = p.parse_generics();
let (self_ty, d) = do self.parse_fn_decl_with_self() |p| {
let (explicit_self, d) = do self.parse_fn_decl_with_self() |p| {
// This is somewhat dubious; We don't want to allow argument
// names to be left off if there is a definition...
either::Left(p.parse_arg_general(false))
@ -526,7 +526,7 @@ pub impl Parser {
purity: pur,
decl: d,
generics: generics,
self_ty: self_ty,
explicit_self: explicit_self,
id: p.get_id(),
span: mk_sp(lo, hi)
})
@ -540,7 +540,7 @@ pub impl Parser {
ident: ident,
attrs: attrs,
generics: generics,
self_ty: self_ty,
explicit_self: explicit_self,
purity: pur,
decl: d,
body: body,
@ -3002,11 +3002,11 @@ pub impl Parser {
&self,
parse_arg_fn:
&fn(&Parser) -> arg_or_capture_item
) -> (self_ty, fn_decl) {
fn maybe_parse_self_ty(
cnstr: &fn(v: mutability) -> ast::self_ty_,
) -> (explicit_self, fn_decl) {
fn maybe_parse_explicit_self(
cnstr: &fn(v: mutability) -> ast::explicit_self_,
p: &Parser
) -> ast::self_ty_ {
) -> ast::explicit_self_ {
// We need to make sure it isn't a mode or a type
if p.token_is_keyword(&~"self", &p.look_ahead(1)) ||
((p.token_is_keyword(&~"const", &p.look_ahead(1)) ||
@ -3022,7 +3022,7 @@ pub impl Parser {
}
}
fn maybe_parse_borrowed_self_ty(this: &Parser) -> ast::self_ty_ {
fn maybe_parse_borrowed_explicit_self(this: &Parser) -> ast::explicit_self_ {
// The following things are possible to see here:
//
// fn(&self)
@ -3066,15 +3066,15 @@ pub impl Parser {
// A bit of complexity and lookahead is needed here in order to to be
// backwards compatible.
let lo = self.span.lo;
let self_ty = match *self.token {
let explicit_self = match *self.token {
token::BINOP(token::AND) => {
maybe_parse_borrowed_self_ty(self)
maybe_parse_borrowed_explicit_self(self)
}
token::AT => {
maybe_parse_self_ty(sty_box, self)
maybe_parse_explicit_self(sty_box, self)
}
token::TILDE => {
maybe_parse_self_ty(sty_uniq, self)
maybe_parse_explicit_self(sty_uniq, self)
}
token::IDENT(*) if self.is_self_ident() => {
self.bump();
@ -3087,7 +3087,7 @@ pub impl Parser {
// If we parsed a self type, expect a comma before the argument list.
let args_or_capture_items;
if self_ty != sty_static {
if explicit_self != sty_static {
match *self.token {
token::COMMA => {
self.bump();
@ -3132,7 +3132,7 @@ pub impl Parser {
cf: ret_style
};
(spanned(lo, hi, self_ty), fn_decl)
(spanned(lo, hi, explicit_self), fn_decl)
}
// parse the |arg, arg| header on a lambda
@ -3199,7 +3199,7 @@ pub impl Parser {
let pur = self.parse_fn_purity();
let ident = self.parse_ident();
let generics = self.parse_generics();
let (self_ty, decl) = do self.parse_fn_decl_with_self() |p| {
let (explicit_self, decl) = do self.parse_fn_decl_with_self() |p| {
p.parse_arg()
};
@ -3210,7 +3210,7 @@ pub impl Parser {
ident: ident,
attrs: attrs,
generics: generics,
self_ty: self_ty,
explicit_self: explicit_self,
purity: pur,
decl: decl,
body: body,

View File

@ -181,12 +181,12 @@ pub fn path_to_str(p: @ast::Path, intr: @ident_interner) -> ~str {
}
pub fn fun_to_str(decl: &ast::fn_decl, purity: ast::purity, name: ast::ident,
opt_self_ty: Option<ast::self_ty_>,
opt_explicit_self: Option<ast::explicit_self_>,
generics: &ast::Generics, intr: @ident_interner) -> ~str {
do io::with_str_writer |wr| {
let s = rust_printer(wr, intr);
print_fn(s, decl, Some(purity), AbiSet::Rust(),
name, generics, opt_self_ty, ast::inherited);
name, generics, opt_explicit_self, ast::inherited);
end(s); // Close the head box
end(s); // Close the outer box
eof(s.s);
@ -797,7 +797,7 @@ pub fn print_ty_method(s: @ps, m: &ast::ty_method) {
print_outer_attributes(s, m.attrs);
print_ty_fn(s, None, None, None, m.purity, ast::Many,
&m.decl, Some(m.ident), Some(&m.generics),
Some(/*bad*/ copy m.self_ty.node));
Some(/*bad*/ copy m.explicit_self.node));
word(s.s, ~";");
}
@ -813,7 +813,7 @@ pub fn print_method(s: @ps, meth: @ast::method) {
maybe_print_comment(s, meth.span.lo);
print_outer_attributes(s, meth.attrs);
print_fn(s, &meth.decl, Some(meth.purity), AbiSet::Rust(),
meth.ident, &meth.generics, Some(meth.self_ty.node),
meth.ident, &meth.generics, Some(meth.explicit_self.node),
meth.vis);
word(s.s, ~" ");
print_block_with_attrs(s, &meth.body, meth.attrs);
@ -1626,13 +1626,13 @@ pub fn print_pat(s: @ps, pat: @ast::pat, refutable: bool) {
(s.ann.post)(ann_node);
}
pub fn self_ty_to_str(self_ty: ast::self_ty_, intr: @ident_interner) -> ~str {
to_str(self_ty, |a, b| { print_self_ty(a, b); () }, intr)
pub fn explicit_self_to_str(explicit_self: ast::explicit_self_, intr: @ident_interner) -> ~str {
to_str(explicit_self, |a, b| { print_explicit_self(a, b); () }, intr)
}
// Returns whether it printed anything
pub fn print_self_ty(s: @ps, self_ty: ast::self_ty_) -> bool {
match self_ty {
pub fn print_explicit_self(s: @ps, explicit_self: ast::explicit_self_) -> bool {
match explicit_self {
ast::sty_static => { return false; }
ast::sty_value => { word(s.s, ~"self"); }
ast::sty_region(lt, m) => {
@ -1657,24 +1657,24 @@ pub fn print_fn(s: @ps,
abis: AbiSet,
name: ast::ident,
generics: &ast::Generics,
opt_self_ty: Option<ast::self_ty_>,
opt_explicit_self: Option<ast::explicit_self_>,
vis: ast::visibility) {
head(s, ~"");
print_fn_header_info(s, opt_self_ty, purity, abis, ast::Many, None, vis);
print_fn_header_info(s, opt_explicit_self, purity, abis, ast::Many, None, vis);
nbsp(s);
print_ident(s, name);
print_generics(s, generics);
print_fn_args_and_ret(s, decl, opt_self_ty);
print_fn_args_and_ret(s, decl, opt_explicit_self);
}
pub fn print_fn_args(s: @ps, decl: &ast::fn_decl,
opt_self_ty: Option<ast::self_ty_>) {
opt_explicit_self: Option<ast::explicit_self_>) {
// It is unfortunate to duplicate the commasep logic, but we we want the
// self type and the args all in the same box.
box(s, 0u, inconsistent);
let mut first = true;
for opt_self_ty.each |self_ty| {
first = !print_self_ty(s, *self_ty);
for opt_explicit_self.each |explicit_self| {
first = !print_explicit_self(s, *explicit_self);
}
for decl.inputs.each |arg| {
@ -1686,9 +1686,9 @@ pub fn print_fn_args(s: @ps, decl: &ast::fn_decl,
}
pub fn print_fn_args_and_ret(s: @ps, decl: &ast::fn_decl,
opt_self_ty: Option<ast::self_ty_>) {
opt_explicit_self: Option<ast::explicit_self_>) {
popen(s);
print_fn_args(s, decl, opt_self_ty);
print_fn_args(s, decl, opt_explicit_self);
pclose(s);
maybe_print_comment(s, decl.output.span.lo);
@ -1900,7 +1900,7 @@ pub fn print_ty_fn(s: @ps,
decl: &ast::fn_decl,
id: Option<ast::ident>,
generics: Option<&ast::Generics>,
opt_self_ty: Option<ast::self_ty_>) {
opt_explicit_self: Option<ast::explicit_self_>) {
ibox(s, indent_unit);
// Duplicates the logic in `print_fn_header_info()`. This is because that
@ -1920,8 +1920,8 @@ pub fn print_ty_fn(s: @ps,
// self type and the args all in the same box.
box(s, 0u, inconsistent);
let mut first = true;
for opt_self_ty.each |self_ty| {
first = !print_self_ty(s, *self_ty);
for opt_explicit_self.each |explicit_self| {
first = !print_explicit_self(s, *explicit_self);
}
for decl.inputs.each |arg| {
if first { first = false; } else { word_space(s, ~","); }
@ -2163,7 +2163,7 @@ pub fn print_opt_sigil(s: @ps, opt_sigil: Option<ast::Sigil>) {
}
pub fn print_fn_header_info(s: @ps,
_opt_sty: Option<ast::self_ty_>,
_opt_explicit_self: Option<ast::explicit_self_>,
opt_purity: Option<ast::purity>,
abis: AbiSet,
onceness: ast::Onceness,