about summary refs log tree commit diff
path: root/src/rustc/metadata/decoder.rs
diff options
context:
space:
mode:
authorTim Chevalier <chevalier@alum.wellesley.edu>2012-03-27 22:08:48 -0700
committerTim Chevalier <chevalier@alum.wellesley.edu>2012-03-27 22:11:58 -0700
commitedb747ceedcfec2eb9f698b0e11b7e94d9174f33 (patch)
tree4b534b40c5a3a06a14e929c680c2ca9c28d1898e /src/rustc/metadata/decoder.rs
parentc9102ee7a1e9c01e9befca44a0c0cb474fff89b4 (diff)
downloadrust-edb747ceedcfec2eb9f698b0e11b7e94d9174f33.tar.gz
rust-edb747ceedcfec2eb9f698b0e11b7e94d9174f33.zip
Enforce mutability declarations in classes; correct shapes for classes
1. Enforce mutability declarations on class fields. Don't allow any
mutation of class fields not declared as mutable (except inside the
constructor).

2. Handle classes correctly in shape (treat classes like records).
Diffstat (limited to 'src/rustc/metadata/decoder.rs')
-rw-r--r--src/rustc/metadata/decoder.rs16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/rustc/metadata/decoder.rs b/src/rustc/metadata/decoder.rs
index c4860ebade7..0b67a16c072 100644
--- a/src/rustc/metadata/decoder.rs
+++ b/src/rustc/metadata/decoder.rs
@@ -118,6 +118,18 @@ fn class_member_id(d: ebml::doc, cdata: cmd) -> ast::def_id {
     ret translate_def_id(cdata, parse_def_id(ebml::doc_data(tagdoc)));
 }
 
+fn field_mutability(d: ebml::doc) -> ast::class_mutability {
+    // Use maybe_get_doc in case it's a method
+    option::maybe(ebml::maybe_get_doc(d, tag_class_mut),
+                  ast::class_immutable,
+                  {|d|
+                  alt ebml::doc_as_u8(d) as char {
+                    'm' { ast::class_mutable }
+                    _   { ast::class_immutable }
+                  }
+                  })
+}
+
 fn variant_disr_val(d: ebml::doc) -> option<int> {
     option::chain(ebml::maybe_get_doc(d, tag_disr_val)) {|val_doc|
         int::parse_buf(ebml::doc_data(val_doc), 10u)
@@ -435,9 +447,9 @@ fn get_class_members(cdata: cmd, id: ast::node_id,
        if p(f) {
           let name = item_name(an_item);
           let did = class_member_id(an_item, cdata);
+          let mt = field_mutability(an_item);
           result += [{ident: name, id: did, privacy:
-                  // This won't work for methods, argh
-                  family_to_privacy(f)}];
+                  family_to_privacy(f), mutability: mt}];
        }
     }
     result