about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-08-02 15:42:56 -0700
committerNiko Matsakis <niko@alum.mit.edu>2012-08-02 15:53:28 -0700
commit97452c0ca16238a2de5503aca07db26ff9e8ba63 (patch)
tree47ef430d1671ab297bc192009aa74a23723a42fc /src/libsyntax
parent476ce459bd3b687658e566c75d0fb73281450d67 (diff)
downloadrust-97452c0ca16238a2de5503aca07db26ff9e8ba63.tar.gz
rust-97452c0ca16238a2de5503aca07db26ff9e8ba63.zip
Remove modes from map API and replace with regions.
API is (for now) mostly by value, there are options to use it by
reference if you like.  Hash and equality functions must be pure
and by reference (forward looking to the day when something
like send_map becomes the standard map).
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast_util.rs10
-rw-r--r--src/libsyntax/attr.rs6
-rw-r--r--src/libsyntax/ext/qquote.rs24
-rw-r--r--src/libsyntax/parse/common.rs10
-rw-r--r--src/libsyntax/parse/lexer.rs2
-rw-r--r--src/libsyntax/parse/parser.rs2
-rw-r--r--src/libsyntax/print/pprust.rs13
-rw-r--r--src/libsyntax/util/interner.rs4
8 files changed, 41 insertions, 30 deletions
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index 1ba0beea305..21d2de2d31b 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -230,18 +230,18 @@ pure fn is_call_expr(e: @expr) -> bool {
     alt e.node { expr_call(_, _, _) { true } _ { false } }
 }
 
-fn eq_ty(&&a: @ty, &&b: @ty) -> bool { return box::ptr_eq(a, b); }
+pure fn eq_ty(a: &@ty, b: &@ty) -> bool { box::ptr_eq(*a, *b) }
 
-fn hash_ty(&&t: @ty) -> uint {
+pure fn hash_ty(t: &@ty) -> uint {
     let res = (t.span.lo << 16u) + t.span.hi;
     return res;
 }
 
-fn def_eq(a: ast::def_id, b: ast::def_id) -> bool {
-    return a.crate == b.crate && a.node == b.node;
+pure fn def_eq(a: &ast::def_id, b: &ast::def_id) -> bool {
+    a.crate == b.crate && a.node == b.node
 }
 
-fn hash_def(d: ast::def_id) -> uint {
+pure fn hash_def(d: &ast::def_id) -> uint {
     let mut h = 5381u;
     h = (h << 5u) + h ^ (d.crate as uint);
     h = (h << 5u) + h ^ (d.node as uint);
diff --git a/src/libsyntax/attr.rs b/src/libsyntax/attr.rs
index bfaa7fa3bbd..da0dec061bb 100644
--- a/src/libsyntax/attr.rs
+++ b/src/libsyntax/attr.rs
@@ -289,15 +289,15 @@ fn last_meta_item_list_by_name(
 // FIXME (#607): This needs to sort by meta_item variant in addition to
 // the item name (See [Fixme-sorting])
 fn sort_meta_items(+items: ~[@ast::meta_item]) -> ~[@ast::meta_item] {
-    fn lteq(&&ma: @ast::meta_item, &&mb: @ast::meta_item) -> bool {
-        fn key(m: @ast::meta_item) -> ast::ident {
+    pure fn lteq(ma: &@ast::meta_item, mb: &@ast::meta_item) -> bool {
+        pure fn key(m: &ast::meta_item) -> ast::ident {
             alt m.node {
               ast::meta_word(name) { /* FIXME (#2543) */ copy name }
               ast::meta_name_value(name, _) { /* FIXME (#2543) */ copy name }
               ast::meta_list(name, _) { /* FIXME (#2543) */ copy name }
             }
         }
-        return key(ma) <= key(mb);
+        key(*ma) <= key(*mb)
     }
 
     // This is sort of stupid here, converting to a vec of mutables and back
diff --git a/src/libsyntax/ext/qquote.rs b/src/libsyntax/ext/qquote.rs
index 1c3e0aa5181..ec0b69d652c 100644
--- a/src/libsyntax/ext/qquote.rs
+++ b/src/libsyntax/ext/qquote.rs
@@ -13,10 +13,14 @@ import io::*;
 
 import codemap::span;
 
-type aq_ctxt = @{lo: uint,
-                 gather: dvec<{lo: uint, hi: uint,
-                               e: @ast::expr,
-                               constr: ~str}>};
+struct gather_item {
+    lo: uint;
+    hi: uint;
+    e: @ast::expr;
+    constr: ~str;
+}
+
+type aq_ctxt = @{lo: uint, gather: dvec<gather_item>};
 enum fragment {
     from_expr(@ast::expr),
     from_ty(@ast::ty)
@@ -110,7 +114,10 @@ fn gather_anti_quotes<N: qq_helper>(lo: uint, node: N) -> aq_ctxt
     // FIXME (#2250): Maybe this is an overkill (merge_sort), it might
     // be better to just keep the gather array in sorted order.
     do cx.gather.swap |v| {
-        vec::to_mut(std::sort::merge_sort(|a,b| a.lo < b.lo, v))
+        pure fn by_lo(a: &gather_item, b: &gather_item) -> bool {
+            a.lo < b.lo
+        }
+        vec::to_mut(std::sort::merge_sort(by_lo, v))
     };
     return cx;
 }
@@ -119,8 +126,11 @@ fn visit_aq<T:qq_helper>(node: T, constr: ~str, &&cx: aq_ctxt, v: vt<aq_ctxt>)
 {
     alt (node.extract_mac()) {
       some(mac_aq(sp, e)) {
-        cx.gather.push({lo: sp.lo - cx.lo, hi: sp.hi - cx.lo,
-                        e: e, constr: constr});
+        cx.gather.push(gather_item {
+            lo: sp.lo - cx.lo,
+            hi: sp.hi - cx.lo,
+            e: e,
+            constr: constr});
       }
       _ {node.visit(cx, v);}
     }
diff --git a/src/libsyntax/parse/common.rs b/src/libsyntax/parse/common.rs
index e0b551f0e45..092238e17be 100644
--- a/src/libsyntax/parse/common.rs
+++ b/src/libsyntax/parse/common.rs
@@ -112,14 +112,14 @@ impl parser_common of parser_common for parser {
 
     // A sanity check that the word we are asking for is a known keyword
     fn require_keyword(word: ~str) {
-        if !self.keywords.contains_key(word) {
+        if !self.keywords.contains_key_ref(&word) {
             self.bug(fmt!{"unknown keyword: %s", word});
         }
     }
 
     fn token_is_word(word: ~str, ++tok: token::token) -> bool {
         alt tok {
-          token::IDENT(sid, false) => { str::eq(word, *self.get_str(sid)) }
+          token::IDENT(sid, false) => { word == *self.get_str(sid) }
           _ => { false }
         }
     }
@@ -136,7 +136,7 @@ impl parser_common of parser_common for parser {
     fn is_any_keyword(tok: token::token) -> bool {
         alt tok {
           token::IDENT(sid, false) {
-            self.keywords.contains_key(*self.get_str(sid))
+            self.keywords.contains_key_ref(self.get_str(sid))
           }
           _ { false }
         }
@@ -148,7 +148,7 @@ impl parser_common of parser_common for parser {
         let mut bump = false;
         let val = alt self.token {
           token::IDENT(sid, false) {
-            if str::eq(word, *self.get_str(sid)) {
+            if word == *self.get_str(sid) {
                 bump = true;
                 true
             } else { false }
@@ -169,7 +169,7 @@ impl parser_common of parser_common for parser {
     }
 
     fn is_restricted_keyword(word: ~str) -> bool {
-        self.restricted_keywords.contains_key(word)
+        self.restricted_keywords.contains_key_ref(&word)
     }
 
     fn check_restricted_keywords() {
diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs
index a2d7a04a6bf..9583be3461d 100644
--- a/src/libsyntax/parse/lexer.rs
+++ b/src/libsyntax/parse/lexer.rs
@@ -456,7 +456,7 @@ fn next_token_inner(rdr: string_reader) -> token::token {
             bump(rdr);
             c = rdr.curr;
         }
-        if str::eq(accum_str, ~"_") { return token::UNDERSCORE; }
+        if accum_str == ~"_" { return token::UNDERSCORE; }
         let is_mod_name = c == ':' && nextch(rdr) == ':';
 
         // FIXME: perform NFKC normalization here. (Issue #2253)
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 29fdc884604..7d5a088a04f 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -2066,7 +2066,7 @@ class parser {
 
     fn is_self_ident() -> bool {
         alt self.token {
-            token::IDENT(sid, false) if str::eq(~"self", *self.get_str(sid)) {
+            token::IDENT(sid, false) if ~"self" == *self.get_str(sid) {
                 true
             }
             _ => {
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 6a2b5c787de..02a888e4022 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -467,12 +467,13 @@ fn print_item(s: ps, &&item: @ast::item) {
       ast::item_enum(variants, params) {
         let newtype =
             vec::len(variants) == 1u &&
-                str::eq(*item.ident, *variants[0].node.name) &&
+                str::eq(item.ident, variants[0].node.name) &&
                 vec::len(variants[0].node.args) == 1u;
         if newtype {
             ibox(s, indent_unit);
             word_space(s, ~"enum");
         } else { head(s, ~"enum"); }
+
         word(s.s, *item.ident);
         print_type_params(s, params);
         space(s.s);
@@ -1789,12 +1790,12 @@ fn opt_proto_to_str(opt_p: option<ast::proto>) -> ~str {
     }
 }
 
-fn purity_to_str(p: ast::purity) -> ~str {
+pure fn purity_to_str(p: ast::purity) -> ~str {
     alt p {
-      ast::impure_fn {~"impure"}
-      ast::unsafe_fn {~"unsafe"}
-      ast::pure_fn {~"pure"}
-      ast::extern_fn {~"extern"}
+      ast::impure_fn => ~"impure",
+      ast::unsafe_fn => ~"unsafe",
+      ast::pure_fn => ~"pure",
+      ast::extern_fn => ~"extern"
     }
 }
 
diff --git a/src/libsyntax/util/interner.rs b/src/libsyntax/util/interner.rs
index 5c2f78bce3b..5b959cb648a 100644
--- a/src/libsyntax/util/interner.rs
+++ b/src/libsyntax/util/interner.rs
@@ -11,8 +11,8 @@ type hash_interner<T: const> =
      hasher: hashfn<T>,
      eqer: eqfn<T>};
 
-fn mk<T: const copy>(hasher: hashfn<T>, eqer: eqfn<T>) -> interner<T> {
-    let m = map::hashmap::<T, uint>(hasher, eqer);
+fn mk<T: const copy>(+hasher: hashfn<T>, +eqer: eqfn<T>) -> interner<T> {
+    let m = map::hashmap::<T, uint>(copy hasher, copy eqer);
     let hi: hash_interner<T> =
         {map: m, vect: dvec(), hasher: hasher, eqer: eqer};
     return hi as interner::<T>;