librustc: Remove mutable fields from the language.
They're still parsed though, to get through bootstrapping.
This commit is contained in:
parent
c7522417d4
commit
db4573a776
19 changed files with 69 additions and 177 deletions
|
@ -204,18 +204,6 @@ fn each_reexport(d: ebml::Doc, f: &fn(ebml::Doc) -> bool) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn field_mutability(d: ebml::Doc) -> ast::struct_mutability {
|
|
||||||
// Use maybe_get_doc in case it's a method
|
|
||||||
reader::maybe_get_doc(d, tag_struct_mut).map_default(
|
|
||||||
ast::struct_immutable,
|
|
||||||
|d| {
|
|
||||||
match reader::doc_as_u8(*d) as char {
|
|
||||||
'm' => ast::struct_mutable,
|
|
||||||
_ => ast::struct_immutable
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
fn variant_disr_val(d: ebml::Doc) -> Option<int> {
|
fn variant_disr_val(d: ebml::Doc) -> Option<int> {
|
||||||
do reader::maybe_get_doc(d, tag_disr_val).chain |val_doc| {
|
do reader::maybe_get_doc(d, tag_disr_val).chain |val_doc| {
|
||||||
int::parse_bytes(reader::doc_data(val_doc), 10u)
|
int::parse_bytes(reader::doc_data(val_doc), 10u)
|
||||||
|
@ -923,12 +911,10 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
|
||||||
if f == PublicField || f == PrivateField || f == InheritedField {
|
if f == PublicField || f == PrivateField || f == InheritedField {
|
||||||
let name = item_name(intr, an_item);
|
let name = item_name(intr, an_item);
|
||||||
let did = item_def_id(an_item, cdata);
|
let did = item_def_id(an_item, cdata);
|
||||||
let mt = field_mutability(an_item);
|
|
||||||
result.push(ty::field_ty {
|
result.push(ty::field_ty {
|
||||||
ident: name,
|
ident: name,
|
||||||
id: did, vis:
|
id: did, vis:
|
||||||
struct_field_family_to_visibility(f),
|
struct_field_family_to_visibility(f),
|
||||||
mutability: mt,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -938,7 +924,6 @@ pub fn get_struct_fields(intr: @ident_interner, cdata: cmd, id: ast::node_id)
|
||||||
ident: special_idents::unnamed_field,
|
ident: special_idents::unnamed_field,
|
||||||
id: did,
|
id: did,
|
||||||
vis: ast::inherited,
|
vis: ast::inherited,
|
||||||
mutability: ast::struct_immutable,
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
result
|
result
|
||||||
|
|
|
@ -119,16 +119,6 @@ fn encode_region_param(ecx: @EncodeContext,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn encode_mutability(ebml_w: &mut writer::Encoder, mt: struct_mutability) {
|
|
||||||
ebml_w.start_tag(tag_struct_mut);
|
|
||||||
let val = match mt {
|
|
||||||
struct_immutable => 'a',
|
|
||||||
struct_mutable => 'm'
|
|
||||||
};
|
|
||||||
ebml_w.writer.write(&[val as u8]);
|
|
||||||
ebml_w.end_tag();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct entry<T> {
|
struct entry<T> {
|
||||||
val: T,
|
val: T,
|
||||||
pos: uint
|
pos: uint
|
||||||
|
@ -518,13 +508,9 @@ fn encode_info_for_struct(ecx: @EncodeContext,
|
||||||
/* We encode both private and public fields -- need to include
|
/* We encode both private and public fields -- need to include
|
||||||
private fields to get the offsets right */
|
private fields to get the offsets right */
|
||||||
for fields.each |field| {
|
for fields.each |field| {
|
||||||
let (nm, mt, vis) = match field.node.kind {
|
let (nm, vis) = match field.node.kind {
|
||||||
named_field(nm, mt, vis) => (nm, mt, vis),
|
named_field(nm, vis) => (nm, vis),
|
||||||
unnamed_field => (
|
unnamed_field => (special_idents::unnamed_field, inherited)
|
||||||
special_idents::unnamed_field,
|
|
||||||
struct_immutable,
|
|
||||||
inherited
|
|
||||||
)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let id = field.node.id;
|
let id = field.node.id;
|
||||||
|
@ -537,7 +523,6 @@ fn encode_info_for_struct(ecx: @EncodeContext,
|
||||||
encode_name(ecx, ebml_w, nm);
|
encode_name(ecx, ebml_w, nm);
|
||||||
encode_path(ecx, ebml_w, path, ast_map::path_name(nm));
|
encode_path(ecx, ebml_w, path, ast_map::path_name(nm));
|
||||||
encode_type(ecx, ebml_w, node_id_to_type(tcx, id));
|
encode_type(ecx, ebml_w, node_id_to_type(tcx, id));
|
||||||
encode_mutability(ebml_w, mt);
|
|
||||||
encode_def_id(ebml_w, local_def(id));
|
encode_def_id(ebml_w, local_def(id));
|
||||||
ebml_w.end_tag();
|
ebml_w.end_tag();
|
||||||
}
|
}
|
||||||
|
@ -828,7 +813,7 @@ fn encode_info_for_item(ecx: @EncodeContext,
|
||||||
needs to know*/
|
needs to know*/
|
||||||
for struct_def.fields.each |f| {
|
for struct_def.fields.each |f| {
|
||||||
match f.node.kind {
|
match f.node.kind {
|
||||||
named_field(ident, _, vis) => {
|
named_field(ident, vis) => {
|
||||||
ebml_w.start_tag(tag_item_field);
|
ebml_w.start_tag(tag_item_field);
|
||||||
encode_struct_field_family(ebml_w, vis);
|
encode_struct_field_family(ebml_w, vis);
|
||||||
encode_name(ecx, ebml_w, ident);
|
encode_name(ecx, ebml_w, ident);
|
||||||
|
|
|
@ -56,7 +56,6 @@ pub enum lint {
|
||||||
non_camel_case_types,
|
non_camel_case_types,
|
||||||
type_limits,
|
type_limits,
|
||||||
default_methods,
|
default_methods,
|
||||||
deprecated_mutable_fields,
|
|
||||||
unused_unsafe,
|
unused_unsafe,
|
||||||
|
|
||||||
managed_heap_memory,
|
managed_heap_memory,
|
||||||
|
@ -455,7 +454,6 @@ fn check_item(i: @ast::item, cx: ty::ctxt) {
|
||||||
check_item_heap(cx, i);
|
check_item_heap(cx, i);
|
||||||
check_item_type_limits(cx, i);
|
check_item_type_limits(cx, i);
|
||||||
check_item_default_methods(cx, i);
|
check_item_default_methods(cx, i);
|
||||||
check_item_deprecated_mutable_fields(cx, i);
|
|
||||||
check_item_unused_unsafe(cx, i);
|
check_item_unused_unsafe(cx, i);
|
||||||
check_item_unused_mut(cx, i);
|
check_item_unused_mut(cx, i);
|
||||||
}
|
}
|
||||||
|
@ -640,28 +638,7 @@ fn check_item_default_methods(cx: ty::ctxt, item: @ast::item) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_item_deprecated_mutable_fields(cx: ty::ctxt, item: @ast::item) {
|
|
||||||
match item.node {
|
|
||||||
ast::item_struct(struct_def, _) => {
|
|
||||||
for struct_def.fields.each |field| {
|
|
||||||
match field.node.kind {
|
|
||||||
ast::named_field(_, ast::struct_mutable, _) => {
|
|
||||||
cx.sess.span_lint(deprecated_mutable_fields,
|
|
||||||
item.id,
|
|
||||||
item.id,
|
|
||||||
field.span,
|
|
||||||
"mutable fields are deprecated");
|
|
||||||
}
|
|
||||||
ast::named_field(*) | ast::unnamed_field => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
|
fn check_item_ctypes(cx: ty::ctxt, it: @ast::item) {
|
||||||
|
|
||||||
fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,
|
fn check_foreign_fn(cx: ty::ctxt, fn_id: ast::node_id,
|
||||||
decl: &ast::fn_decl) {
|
decl: &ast::fn_decl) {
|
||||||
let tys = vec::map(decl.inputs, |a| a.ty );
|
let tys = vec::map(decl.inputs, |a| a.ty );
|
||||||
|
|
|
@ -581,17 +581,7 @@ pub impl mem_categorization_ctxt {
|
||||||
f_name: ast::ident,
|
f_name: ast::ident,
|
||||||
f_ty: ty::t,
|
f_ty: ty::t,
|
||||||
field_id: ast::node_id) -> cmt {
|
field_id: ast::node_id) -> cmt {
|
||||||
let f_mutbl = match field_mutbl(self.tcx, base_cmt.ty,
|
let f_mutbl = m_imm;
|
||||||
f_name, field_id) {
|
|
||||||
Some(f_mutbl) => f_mutbl,
|
|
||||||
None => {
|
|
||||||
self.tcx.sess.span_bug(
|
|
||||||
node.span(),
|
|
||||||
fmt!("Cannot find field `%s` in type `%s`",
|
|
||||||
*self.tcx.sess.str_of(f_name),
|
|
||||||
ty_to_str(self.tcx, base_cmt.ty)));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let m = self.inherited_mutability(base_cmt.mutbl, f_mutbl);
|
let m = self.inherited_mutability(base_cmt.mutbl, f_mutbl);
|
||||||
let f_interior = interior_field(f_name, f_mutbl);
|
let f_interior = interior_field(f_name, f_mutbl);
|
||||||
@cmt_ {
|
@cmt_ {
|
||||||
|
@ -968,11 +958,7 @@ pub fn field_mutbl(tcx: ty::ctxt,
|
||||||
ty::ty_struct(did, _) => {
|
ty::ty_struct(did, _) => {
|
||||||
for ty::lookup_struct_fields(tcx, did).each |fld| {
|
for ty::lookup_struct_fields(tcx, did).each |fld| {
|
||||||
if fld.ident == f_name {
|
if fld.ident == f_name {
|
||||||
let m = match fld.mutability {
|
return Some(ast::m_imm);
|
||||||
ast::struct_mutable => ast::m_mutbl,
|
|
||||||
ast::struct_immutable => ast::m_imm
|
|
||||||
};
|
|
||||||
return Some(m);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -981,11 +967,7 @@ pub fn field_mutbl(tcx: ty::ctxt,
|
||||||
ast::def_variant(_, variant_id) => {
|
ast::def_variant(_, variant_id) => {
|
||||||
for ty::lookup_struct_fields(tcx, variant_id).each |fld| {
|
for ty::lookup_struct_fields(tcx, variant_id).each |fld| {
|
||||||
if fld.ident == f_name {
|
if fld.ident == f_name {
|
||||||
let m = match fld.mutability {
|
return Some(ast::m_imm);
|
||||||
ast::struct_mutable => ast::m_mutbl,
|
|
||||||
ast::struct_immutable => ast::m_imm
|
|
||||||
};
|
|
||||||
return Some(m);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -894,17 +894,7 @@ pub fn determine_rp_in_struct_field(
|
||||||
cm: @ast::struct_field,
|
cm: @ast::struct_field,
|
||||||
cx: @mut DetermineRpCtxt,
|
cx: @mut DetermineRpCtxt,
|
||||||
visitor: visit::vt<@mut DetermineRpCtxt>) {
|
visitor: visit::vt<@mut DetermineRpCtxt>) {
|
||||||
match cm.node.kind {
|
visit::visit_struct_field(cm, cx, visitor);
|
||||||
ast::named_field(_, ast::struct_mutable, _) => {
|
|
||||||
do cx.with_ambient_variance(rv_invariant) {
|
|
||||||
visit::visit_struct_field(cm, cx, visitor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ast::named_field(_, ast::struct_immutable, _) |
|
|
||||||
ast::unnamed_field => {
|
|
||||||
visit::visit_struct_field(cm, cx, visitor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn determine_rp_in_crate(sess: Session,
|
pub fn determine_rp_in_crate(sess: Session,
|
||||||
|
|
|
@ -4667,7 +4667,7 @@ pub impl Resolver {
|
||||||
for vec::each(class_def.fields) |field| {
|
for vec::each(class_def.fields) |field| {
|
||||||
match field.node.kind {
|
match field.node.kind {
|
||||||
unnamed_field => {},
|
unnamed_field => {},
|
||||||
named_field(ident, _, _) => {
|
named_field(ident, _) => {
|
||||||
if str::eq_slice(*this.session.str_of(ident),
|
if str::eq_slice(*this.session.str_of(ident),
|
||||||
name) {
|
name) {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -120,14 +120,14 @@ lvalues are *never* stored by value.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use back::abi;
|
use back::abi;
|
||||||
use lib;
|
|
||||||
use lib::llvm::{ValueRef, TypeRef, llvm};
|
use lib::llvm::{ValueRef, TypeRef, llvm};
|
||||||
|
use lib;
|
||||||
use metadata::csearch;
|
use metadata::csearch;
|
||||||
use middle::trans::_match;
|
use middle::trans::_match;
|
||||||
use middle::trans::adt;
|
use middle::trans::adt;
|
||||||
use middle::trans::asm;
|
use middle::trans::asm;
|
||||||
use middle::trans::base;
|
|
||||||
use middle::trans::base::*;
|
use middle::trans::base::*;
|
||||||
|
use middle::trans::base;
|
||||||
use middle::trans::build::*;
|
use middle::trans::build::*;
|
||||||
use middle::trans::callee::DoAutorefArg;
|
use middle::trans::callee::DoAutorefArg;
|
||||||
use middle::trans::callee;
|
use middle::trans::callee;
|
||||||
|
@ -142,8 +142,10 @@ use middle::trans::machine;
|
||||||
use middle::trans::meth;
|
use middle::trans::meth;
|
||||||
use middle::trans::tvec;
|
use middle::trans::tvec;
|
||||||
use middle::trans::type_of;
|
use middle::trans::type_of;
|
||||||
|
use middle::ty::struct_fields;
|
||||||
|
use middle::ty::{AutoDerefRef, AutoAddEnv};
|
||||||
|
use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef, AutoBorrowFn};
|
||||||
use middle::ty;
|
use middle::ty;
|
||||||
use middle::ty::struct_mutable_fields;
|
|
||||||
use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef, AutoBorrowFn,
|
use middle::ty::{AutoPtr, AutoBorrowVec, AutoBorrowVecRef, AutoBorrowFn,
|
||||||
AutoDerefRef, AutoAddEnv, AutoUnsafe};
|
AutoDerefRef, AutoAddEnv, AutoUnsafe};
|
||||||
use util::common::indenter;
|
use util::common::indenter;
|
||||||
|
@ -1107,7 +1109,7 @@ pub fn with_field_tys<R>(tcx: ty::ctxt,
|
||||||
op: &fn(int, (&[ty::field])) -> R) -> R {
|
op: &fn(int, (&[ty::field])) -> R) -> R {
|
||||||
match ty::get(ty).sty {
|
match ty::get(ty).sty {
|
||||||
ty::ty_struct(did, ref substs) => {
|
ty::ty_struct(did, ref substs) => {
|
||||||
op(0, struct_mutable_fields(tcx, did, substs))
|
op(0, struct_fields(tcx, did, substs))
|
||||||
}
|
}
|
||||||
|
|
||||||
ty::ty_enum(_, ref substs) => {
|
ty::ty_enum(_, ref substs) => {
|
||||||
|
@ -1124,8 +1126,8 @@ pub fn with_field_tys<R>(tcx: ty::ctxt,
|
||||||
ast::def_variant(enum_id, variant_id) => {
|
ast::def_variant(enum_id, variant_id) => {
|
||||||
let variant_info = ty::enum_variant_with_id(
|
let variant_info = ty::enum_variant_with_id(
|
||||||
tcx, enum_id, variant_id);
|
tcx, enum_id, variant_id);
|
||||||
op(variant_info.disr_val, struct_mutable_fields(
|
op(variant_info.disr_val,
|
||||||
tcx, variant_id, substs))
|
struct_fields(tcx, variant_id, substs))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
tcx.sess.bug(~"resolve didn't map this expr to a \
|
tcx.sess.bug(~"resolve didn't map this expr to a \
|
||||||
|
|
|
@ -496,9 +496,7 @@ pub fn trans_struct_drop(bcx: block,
|
||||||
Call(bcx, dtor_addr, args);
|
Call(bcx, dtor_addr, args);
|
||||||
|
|
||||||
// Drop the fields
|
// Drop the fields
|
||||||
let field_tys =
|
let field_tys = ty::struct_fields(bcx.tcx(), class_did, substs);
|
||||||
ty::struct_mutable_fields(bcx.tcx(), class_did,
|
|
||||||
substs);
|
|
||||||
for vec::eachi(field_tys) |i, fld| {
|
for vec::eachi(field_tys) |i, fld| {
|
||||||
let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i);
|
let llfld_a = adt::trans_field_ptr(bcx, repr, v0, 0, i);
|
||||||
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
|
bcx = drop_ty(bcx, llfld_a, fld.mt.ty);
|
||||||
|
|
|
@ -106,10 +106,9 @@ pub enum SelfMode {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct field_ty {
|
pub struct field_ty {
|
||||||
ident: ident,
|
ident: ident,
|
||||||
id: def_id,
|
id: def_id,
|
||||||
vis: ast::visibility,
|
vis: ast::visibility,
|
||||||
mutability: ast::struct_mutability,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Contains information needed to resolve types and (in the future) look up
|
// Contains information needed to resolve types and (in the future) look up
|
||||||
|
@ -4027,12 +4026,11 @@ pub fn lookup_struct_field(cx: ctxt,
|
||||||
fn struct_field_tys(fields: &[@struct_field]) -> ~[field_ty] {
|
fn struct_field_tys(fields: &[@struct_field]) -> ~[field_ty] {
|
||||||
do fields.map |field| {
|
do fields.map |field| {
|
||||||
match field.node.kind {
|
match field.node.kind {
|
||||||
named_field(ident, mutability, visibility) => {
|
named_field(ident, visibility) => {
|
||||||
field_ty {
|
field_ty {
|
||||||
ident: ident,
|
ident: ident,
|
||||||
id: ast_util::local_def(field.node.id),
|
id: ast_util::local_def(field.node.id),
|
||||||
vis: visibility,
|
vis: visibility,
|
||||||
mutability: mutability,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
unnamed_field => {
|
unnamed_field => {
|
||||||
|
@ -4041,51 +4039,22 @@ fn struct_field_tys(fields: &[@struct_field]) -> ~[field_ty] {
|
||||||
syntax::parse::token::special_idents::unnamed_field,
|
syntax::parse::token::special_idents::unnamed_field,
|
||||||
id: ast_util::local_def(field.node.id),
|
id: ast_util::local_def(field.node.id),
|
||||||
vis: ast::public,
|
vis: ast::public,
|
||||||
mutability: ast::struct_immutable,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return a list of fields corresponding to the struct's items
|
// Returns a list of fields corresponding to the struct's items. trans uses
|
||||||
// (as if the struct was a record). trans uses this
|
// this. Takes a list of substs with which to instantiate field types.
|
||||||
// Takes a list of substs with which to instantiate field types
|
pub fn struct_fields(cx: ctxt, did: ast::def_id, substs: &substs)
|
||||||
// Keep in mind that this function reports that all fields are
|
-> ~[field] {
|
||||||
// mutable, regardless of how they were declared. It's meant to
|
|
||||||
// be used in trans.
|
|
||||||
pub fn struct_mutable_fields(cx: ctxt,
|
|
||||||
did: ast::def_id,
|
|
||||||
substs: &substs)
|
|
||||||
-> ~[field] {
|
|
||||||
struct_item_fields(cx, did, substs, |_mt| m_mutbl)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Same as struct_mutable_fields, but doesn't change
|
|
||||||
// mutability.
|
|
||||||
pub fn struct_fields(cx: ctxt,
|
|
||||||
did: ast::def_id,
|
|
||||||
substs: &substs)
|
|
||||||
-> ~[field] {
|
|
||||||
struct_item_fields(cx, did, substs, |mt| match mt {
|
|
||||||
struct_mutable => m_mutbl,
|
|
||||||
struct_immutable => m_imm })
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fn struct_item_fields(cx:ctxt,
|
|
||||||
did: ast::def_id,
|
|
||||||
substs: &substs,
|
|
||||||
frob_mutability: &fn(struct_mutability) -> mutability)
|
|
||||||
-> ~[field] {
|
|
||||||
do lookup_struct_fields(cx, did).map |f| {
|
do lookup_struct_fields(cx, did).map |f| {
|
||||||
// consider all instance vars mut, because the
|
|
||||||
// constructor may mutate all vars
|
|
||||||
field {
|
field {
|
||||||
ident: f.ident,
|
ident: f.ident,
|
||||||
mt: mt {
|
mt: mt {
|
||||||
ty: lookup_field_type(cx, did, f.id, substs),
|
ty: lookup_field_type(cx, did, f.id, substs),
|
||||||
mutbl: frob_mutability(f.mutability)
|
mutbl: m_imm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -274,7 +274,7 @@ fn structdoc_from_struct(
|
||||||
item: itemdoc,
|
item: itemdoc,
|
||||||
fields: do struct_def.fields.map |field| {
|
fields: do struct_def.fields.map |field| {
|
||||||
match field.node.kind {
|
match field.node.kind {
|
||||||
ast::named_field(ident, _, _) => to_str(ident),
|
ast::named_field(ident, _) => to_str(ident),
|
||||||
ast::unnamed_field => ~"(unnamed)",
|
ast::unnamed_field => ~"(unnamed)",
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -1168,7 +1168,7 @@ pub type struct_field = spanned<struct_field_>;
|
||||||
#[auto_decode]
|
#[auto_decode]
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq)]
|
||||||
pub enum struct_field_kind {
|
pub enum struct_field_kind {
|
||||||
named_field(ident, struct_mutability, visibility),
|
named_field(ident, visibility),
|
||||||
unnamed_field // element of a tuple-like struct
|
unnamed_field // element of a tuple-like struct
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1218,17 +1218,6 @@ pub enum item_ {
|
||||||
item_mac(mac),
|
item_mac(mac),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[auto_encode]
|
|
||||||
#[auto_decode]
|
|
||||||
#[deriving(Eq)]
|
|
||||||
pub enum struct_mutability { struct_mutable, struct_immutable }
|
|
||||||
|
|
||||||
impl to_bytes::IterBytes for struct_mutability {
|
|
||||||
fn iter_bytes(&self, lsb0: bool, f: to_bytes::Cb) {
|
|
||||||
(*self as u8).iter_bytes(lsb0, f)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[auto_encode]
|
#[auto_encode]
|
||||||
#[auto_decode]
|
#[auto_decode]
|
||||||
#[deriving(Eq)]
|
#[deriving(Eq)]
|
||||||
|
@ -1289,6 +1278,21 @@ mod test {
|
||||||
assert_eq! (s,~[14]);
|
assert_eq! (s,~[14]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test] fn test_marksof () {
|
||||||
|
let stopname = uints_to_name(&~[12,14,78]);
|
||||||
|
assert_eq!(s,~[]);
|
||||||
|
xorPush(&mut s,14);
|
||||||
|
assert_eq!(s,~[14]);
|
||||||
|
xorPush(&mut s,15);
|
||||||
|
assert_eq!(s,~[14,15]);
|
||||||
|
xorPush (&mut s,16);
|
||||||
|
assert_eq! (s,~[14,15,16]);
|
||||||
|
xorPush (&mut s,16);
|
||||||
|
assert_eq! (s,~[14,15]);
|
||||||
|
xorPush (&mut s,15);
|
||||||
|
assert_eq! (s,~[14]);
|
||||||
|
}
|
||||||
|
|
||||||
#[test] fn test_marksof () {
|
#[test] fn test_marksof () {
|
||||||
let stopname = uints_to_name(&~[12,14,78]);
|
let stopname = uints_to_name(&~[12,14,78]);
|
||||||
let name1 = uints_to_name(&~[4,9,7]);
|
let name1 = uints_to_name(&~[4,9,7]);
|
||||||
|
@ -1347,3 +1351,12 @@ mod test {
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
//
|
||||||
|
// Local Variables:
|
||||||
|
// mode: rust
|
||||||
|
// fill-column: 78;
|
||||||
|
// indent-tabs-mode: nil
|
||||||
|
// c-basic-offset: 4
|
||||||
|
// buffer-file-coding-system: utf-8-unix
|
||||||
|
// End:
|
||||||
|
//
|
||||||
|
|
|
@ -285,7 +285,7 @@ pub fn split_trait_methods(trait_methods: &[trait_method])
|
||||||
|
|
||||||
pub fn struct_field_visibility(field: ast::struct_field) -> visibility {
|
pub fn struct_field_visibility(field: ast::struct_field) -> visibility {
|
||||||
match field.node.kind {
|
match field.node.kind {
|
||||||
ast::named_field(_, _, visibility) => visibility,
|
ast::named_field(_, visibility) => visibility,
|
||||||
ast::unnamed_field => ast::public
|
ast::unnamed_field => ast::public
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -914,19 +914,15 @@ struct field {
|
||||||
|
|
||||||
fn mk_struct_fields(fields: &[@ast::struct_field]) -> ~[field] {
|
fn mk_struct_fields(fields: &[@ast::struct_field]) -> ~[field] {
|
||||||
do fields.map |field| {
|
do fields.map |field| {
|
||||||
let (ident, mutbl) = match field.node.kind {
|
let ident = match field.node.kind {
|
||||||
ast::named_field(ident, mutbl, _) => (ident, mutbl),
|
ast::named_field(ident, _) => ident,
|
||||||
_ => fail!(~"[auto_encode] does not support \
|
_ => fail!(~"[auto_encode] does not support unnamed fields")
|
||||||
unnamed fields")
|
|
||||||
};
|
};
|
||||||
|
|
||||||
field {
|
field {
|
||||||
span: field.span,
|
span: field.span,
|
||||||
ident: ident,
|
ident: ident,
|
||||||
mutbl: match mutbl {
|
mutbl: ast::m_imm,
|
||||||
ast::struct_mutable => ast::m_mutbl,
|
|
||||||
ast::struct_immutable => ast::m_imm,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,7 +280,7 @@ fn expand_deriving_decodable_struct_method(
|
||||||
let mut fields = ~[];
|
let mut fields = ~[];
|
||||||
for struct_def.fields.each |struct_field| {
|
for struct_def.fields.each |struct_field| {
|
||||||
match struct_field.node.kind {
|
match struct_field.node.kind {
|
||||||
named_field(ident, _, _) => {
|
named_field(ident, _) => {
|
||||||
fields.push(create_read_struct_field(cx, span, i, ident));
|
fields.push(create_read_struct_field(cx, span, i, ident));
|
||||||
}
|
}
|
||||||
unnamed_field => {
|
unnamed_field => {
|
||||||
|
|
|
@ -211,7 +211,7 @@ fn expand_deriving_encodable_struct_method(
|
||||||
let mut statements = ~[];
|
let mut statements = ~[];
|
||||||
for struct_def.fields.each |struct_field| {
|
for struct_def.fields.each |struct_field| {
|
||||||
match struct_field.node.kind {
|
match struct_field.node.kind {
|
||||||
named_field(ident, _, _) => {
|
named_field(ident, _) => {
|
||||||
// Create the accessor for this field.
|
// Create the accessor for this field.
|
||||||
let self_field = build::mk_access(
|
let self_field = build::mk_access(
|
||||||
cx,
|
cx,
|
||||||
|
|
|
@ -90,4 +90,4 @@ fn iter_bytes_substructure(cx: @ext_ctxt, span: span, substr: &Substructure) ->
|
||||||
}
|
}
|
||||||
|
|
||||||
build::mk_block(cx, span, ~[], stmts, None)
|
build::mk_block(cx, span, ~[], stmts, None)
|
||||||
}
|
}
|
||||||
|
|
|
@ -410,10 +410,8 @@ impl gen_init for protocol {
|
||||||
|
|
||||||
@spanned {
|
@spanned {
|
||||||
node: ast::struct_field_ {
|
node: ast::struct_field_ {
|
||||||
kind: ast::named_field(
|
kind: ast::named_field(cx.ident_of(s.name),
|
||||||
cx.ident_of(s.name),
|
ast::inherited),
|
||||||
ast::struct_immutable,
|
|
||||||
ast::inherited),
|
|
||||||
id: cx.next_id(),
|
id: cx.next_id(),
|
||||||
ty: fty,
|
ty: fty,
|
||||||
attrs: ~[],
|
attrs: ~[],
|
||||||
|
|
|
@ -45,7 +45,7 @@ use ast::{pat_tup, pat_uniq, pat_wild, private};
|
||||||
use ast::{rem, required};
|
use ast::{rem, required};
|
||||||
use ast::{ret_style, return_val, self_ty, shl, shr, stmt, stmt_decl};
|
use ast::{ret_style, return_val, self_ty, shl, shr, stmt, stmt_decl};
|
||||||
use ast::{stmt_expr, stmt_semi, stmt_mac, struct_def, struct_field};
|
use ast::{stmt_expr, stmt_semi, stmt_mac, struct_def, struct_field};
|
||||||
use ast::{struct_immutable, struct_mutable, struct_variant_kind, subtract};
|
use ast::{struct_variant_kind, subtract};
|
||||||
use ast::{sty_box, sty_region, sty_static, sty_uniq, sty_value};
|
use ast::{sty_box, sty_region, sty_static, sty_uniq, sty_value};
|
||||||
use ast::{token_tree, trait_method, trait_ref, tt_delim, tt_seq, tt_tok};
|
use ast::{token_tree, trait_method, trait_ref, tt_delim, tt_seq, tt_tok};
|
||||||
use ast::{tt_nonterminal, tuple_variant_kind, Ty, ty_, ty_bot, ty_box};
|
use ast::{tt_nonterminal, tuple_variant_kind, Ty, ty_, ty_bot, ty_box};
|
||||||
|
@ -2528,10 +2528,10 @@ pub impl Parser {
|
||||||
fn parse_name_and_ty(&self,
|
fn parse_name_and_ty(&self,
|
||||||
pr: visibility,
|
pr: visibility,
|
||||||
attrs: ~[attribute]) -> @struct_field {
|
attrs: ~[attribute]) -> @struct_field {
|
||||||
let mut is_mutbl = struct_immutable;
|
|
||||||
let lo = self.span.lo;
|
let lo = self.span.lo;
|
||||||
if self.eat_keyword(&~"mut") {
|
if self.eat_keyword(&~"mut") {
|
||||||
is_mutbl = struct_mutable;
|
// Do nothing, for backwards compatibility.
|
||||||
|
// XXX: Remove after snapshot.
|
||||||
}
|
}
|
||||||
if !is_plain_ident(&*self.token) {
|
if !is_plain_ident(&*self.token) {
|
||||||
self.fatal(~"expected ident");
|
self.fatal(~"expected ident");
|
||||||
|
@ -2540,7 +2540,7 @@ pub impl Parser {
|
||||||
self.expect(&token::COLON);
|
self.expect(&token::COLON);
|
||||||
let ty = self.parse_ty(false);
|
let ty = self.parse_ty(false);
|
||||||
@spanned(lo, self.last_span.hi, ast::struct_field_ {
|
@spanned(lo, self.last_span.hi, ast::struct_field_ {
|
||||||
kind: named_field(name, is_mutbl, pr),
|
kind: named_field(name, pr),
|
||||||
id: self.get_id(),
|
id: self.get_id(),
|
||||||
ty: ty,
|
ty: ty,
|
||||||
attrs: attrs,
|
attrs: attrs,
|
||||||
|
|
|
@ -703,14 +703,11 @@ pub fn print_struct(s: @ps,
|
||||||
for struct_def.fields.each |field| {
|
for struct_def.fields.each |field| {
|
||||||
match field.node.kind {
|
match field.node.kind {
|
||||||
ast::unnamed_field => fail!(~"unexpected unnamed field"),
|
ast::unnamed_field => fail!(~"unexpected unnamed field"),
|
||||||
ast::named_field(ident, mutability, visibility) => {
|
ast::named_field(ident, visibility) => {
|
||||||
hardbreak_if_not_bol(s);
|
hardbreak_if_not_bol(s);
|
||||||
maybe_print_comment(s, field.span.lo);
|
maybe_print_comment(s, field.span.lo);
|
||||||
print_outer_attributes(s, field.node.attrs);
|
print_outer_attributes(s, field.node.attrs);
|
||||||
print_visibility(s, visibility);
|
print_visibility(s, visibility);
|
||||||
if mutability == ast::struct_mutable {
|
|
||||||
word_nbsp(s, ~"mut");
|
|
||||||
}
|
|
||||||
print_ident(s, ident);
|
print_ident(s, ident);
|
||||||
word_nbsp(s, ~":");
|
word_nbsp(s, ~":");
|
||||||
print_type(s, field.node.ty);
|
print_type(s, field.node.ty);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue