about summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2013-03-15 15:24:24 -0400
committerNiko Matsakis <niko@alum.mit.edu>2013-04-30 06:59:32 -0400
commita896440ca1b93cc5dc6edd827ea2ae89602bfa9e (patch)
treec6945d51bf84faeb9be6ac32247c8ffa2cd39226 /src/libsyntax/ext
parentb5a7e8b35322869b1cf51bd1b35a86e9e721da54 (diff)
downloadrust-a896440ca1b93cc5dc6edd827ea2ae89602bfa9e.tar.gz
rust-a896440ca1b93cc5dc6edd827ea2ae89602bfa9e.zip
new borrow checker (mass squash)
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/base.rs108
-rw-r--r--src/libsyntax/ext/expand.rs3
-rw-r--r--src/libsyntax/ext/pipes/liveness.rs4
-rw-r--r--src/libsyntax/ext/pipes/proto.rs18
4 files changed, 71 insertions, 62 deletions
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index 5bad9ecae3e..7d058f22e4c 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -210,29 +210,29 @@ pub fn syntax_expander_table() -> SyntaxEnv {
 // when a macro expansion occurs, the resulting nodes have the backtrace()
 // -> expn_info of their expansion context stored into their span.
 pub trait ext_ctxt {
-    fn codemap(@mut self) -> @CodeMap;
-    fn parse_sess(@mut self) -> @mut parse::ParseSess;
-    fn cfg(@mut self) -> ast::crate_cfg;
-    fn call_site(@mut self) -> span;
-    fn print_backtrace(@mut self);
-    fn backtrace(@mut self) -> Option<@ExpnInfo>;
-    fn mod_push(@mut self, mod_name: ast::ident);
-    fn mod_pop(@mut self);
-    fn mod_path(@mut self) -> ~[ast::ident];
-    fn bt_push(@mut self, ei: codemap::ExpnInfo);
-    fn bt_pop(@mut self);
-    fn span_fatal(@mut self, sp: span, msg: &str) -> !;
-    fn span_err(@mut self, sp: span, msg: &str);
-    fn span_warn(@mut self, sp: span, msg: &str);
-    fn span_unimpl(@mut self, sp: span, msg: &str) -> !;
-    fn span_bug(@mut self, sp: span, msg: &str) -> !;
-    fn bug(@mut self, msg: &str) -> !;
-    fn next_id(@mut self) -> ast::node_id;
-    fn trace_macros(@mut self) -> bool;
-    fn set_trace_macros(@mut self, x: bool);
+    fn codemap(&self) -> @CodeMap;
+    fn parse_sess(&self) -> @mut parse::ParseSess;
+    fn cfg(&self) -> ast::crate_cfg;
+    fn call_site(&self) -> span;
+    fn print_backtrace(&self);
+    fn backtrace(&self) -> Option<@ExpnInfo>;
+    fn mod_push(&self, mod_name: ast::ident);
+    fn mod_pop(&self);
+    fn mod_path(&self) -> ~[ast::ident];
+    fn bt_push(&self, ei: codemap::ExpnInfo);
+    fn bt_pop(&self);
+    fn span_fatal(&self, sp: span, msg: &str) -> !;
+    fn span_err(&self, sp: span, msg: &str);
+    fn span_warn(&self, sp: span, msg: &str);
+    fn span_unimpl(&self, sp: span, msg: &str) -> !;
+    fn span_bug(&self, sp: span, msg: &str) -> !;
+    fn bug(&self, msg: &str) -> !;
+    fn next_id(&self) -> ast::node_id;
+    fn trace_macros(&self) -> bool;
+    fn set_trace_macros(&self, x: bool);
     /* for unhygienic identifier transformation */
-    fn str_of(@mut self, id: ast::ident) -> ~str;
-    fn ident_of(@mut self, st: ~str) -> ast::ident;
+    fn str_of(&self, id: ast::ident) -> ~str;
+    fn ident_of(&self, st: ~str) -> ast::ident;
 }
 
 pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg)
@@ -241,25 +241,31 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg)
         parse_sess: @mut parse::ParseSess,
         cfg: ast::crate_cfg,
         backtrace: @mut Option<@ExpnInfo>,
-        mod_path: ~[ast::ident],
-        trace_mac: bool
+
+        // These two @mut's should really not be here,
+        // but the self types for CtxtRepr are all wrong
+        // and there are bugs in the code for object
+        // types that make this hard to get right at the
+        // moment. - nmatsakis
+        mod_path: @mut ~[ast::ident],
+        trace_mac: @mut bool
     }
     impl ext_ctxt for CtxtRepr {
-        fn codemap(@mut self) -> @CodeMap { self.parse_sess.cm }
-        fn parse_sess(@mut self) -> @mut parse::ParseSess { self.parse_sess }
-        fn cfg(@mut self) -> ast::crate_cfg { copy self.cfg }
-        fn call_site(@mut self) -> span {
+        fn codemap(&self) -> @CodeMap { self.parse_sess.cm }
+        fn parse_sess(&self) -> @mut parse::ParseSess { self.parse_sess }
+        fn cfg(&self) -> ast::crate_cfg { copy self.cfg }
+        fn call_site(&self) -> span {
             match *self.backtrace {
                 Some(@ExpandedFrom(CallInfo {call_site: cs, _})) => cs,
                 None => self.bug(~"missing top span")
             }
         }
-        fn print_backtrace(@mut self) { }
-        fn backtrace(@mut self) -> Option<@ExpnInfo> { *self.backtrace }
-        fn mod_push(@mut self, i: ast::ident) { self.mod_path.push(i); }
-        fn mod_pop(@mut self) { self.mod_path.pop(); }
-        fn mod_path(@mut self) -> ~[ast::ident] { copy self.mod_path }
-        fn bt_push(@mut self, ei: codemap::ExpnInfo) {
+        fn print_backtrace(&self) { }
+        fn backtrace(&self) -> Option<@ExpnInfo> { *self.backtrace }
+        fn mod_push(&self, i: ast::ident) { self.mod_path.push(i); }
+        fn mod_pop(&self) { self.mod_path.pop(); }
+        fn mod_path(&self) -> ~[ast::ident] { copy *self.mod_path }
+        fn bt_push(&self, ei: codemap::ExpnInfo) {
             match ei {
               ExpandedFrom(CallInfo {call_site: cs, callee: ref callee}) => {
                 *self.backtrace =
@@ -270,7 +276,7 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg)
               }
             }
         }
-        fn bt_pop(@mut self) {
+        fn bt_pop(&self) {
             match *self.backtrace {
               Some(@ExpandedFrom(CallInfo {
                   call_site: span {expn_info: prev, _}, _
@@ -280,52 +286,52 @@ pub fn mk_ctxt(parse_sess: @mut parse::ParseSess, cfg: ast::crate_cfg)
               _ => self.bug(~"tried to pop without a push")
             }
         }
-        fn span_fatal(@mut self, sp: span, msg: &str) -> ! {
+        fn span_fatal(&self, sp: span, msg: &str) -> ! {
             self.print_backtrace();
             self.parse_sess.span_diagnostic.span_fatal(sp, msg);
         }
-        fn span_err(@mut self, sp: span, msg: &str) {
+        fn span_err(&self, sp: span, msg: &str) {
             self.print_backtrace();
             self.parse_sess.span_diagnostic.span_err(sp, msg);
         }
-        fn span_warn(@mut self, sp: span, msg: &str) {
+        fn span_warn(&self, sp: span, msg: &str) {
             self.print_backtrace();
             self.parse_sess.span_diagnostic.span_warn(sp, msg);
         }
-        fn span_unimpl(@mut self, sp: span, msg: &str) -> ! {
+        fn span_unimpl(&self, sp: span, msg: &str) -> ! {
             self.print_backtrace();
             self.parse_sess.span_diagnostic.span_unimpl(sp, msg);
         }
-        fn span_bug(@mut self, sp: span, msg: &str) -> ! {
+        fn span_bug(&self, sp: span, msg: &str) -> ! {
             self.print_backtrace();
             self.parse_sess.span_diagnostic.span_bug(sp, msg);
         }
-        fn bug(@mut self, msg: &str) -> ! {
+        fn bug(&self, msg: &str) -> ! {
             self.print_backtrace();
             self.parse_sess.span_diagnostic.handler().bug(msg);
         }
-        fn next_id(@mut self) -> ast::node_id {
+        fn next_id(&self) -> ast::node_id {
             return parse::next_node_id(self.parse_sess);
         }
-        fn trace_macros(@mut self) -> bool {
-            self.trace_mac
+        fn trace_macros(&self) -> bool {
+            *self.trace_mac
         }
-        fn set_trace_macros(@mut self, x: bool) {
-            self.trace_mac = x
+        fn set_trace_macros(&self, x: bool) {
+            *self.trace_mac = x
         }
-        fn str_of(@mut self, id: ast::ident) -> ~str {
+        fn str_of(&self, id: ast::ident) -> ~str {
             copy *self.parse_sess.interner.get(id)
         }
-        fn ident_of(@mut self, st: ~str) -> ast::ident {
+        fn ident_of(&self, st: ~str) -> ast::ident {
             self.parse_sess.interner.intern(@/*bad*/ copy st)
         }
     }
-    let imp: @mut CtxtRepr = @mut CtxtRepr {
+    let imp: @CtxtRepr = @CtxtRepr {
         parse_sess: parse_sess,
         cfg: cfg,
         backtrace: @mut None,
-        mod_path: ~[],
-        trace_mac: false
+        mod_path: @mut ~[],
+        trace_mac: @mut false
     };
     ((imp) as @ext_ctxt)
 }
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index fde5a259422..841f64e0b05 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -27,6 +27,7 @@ pub fn expand_expr(extsbox: @mut SyntaxEnv,
                    fld: @ast_fold,
                    orig: @fn(&expr_, span, @ast_fold) -> (expr_, span))
                 -> (expr_, span) {
+    let mut cx = cx;
     match *e {
         // expr_mac should really be expr_ext or something; it's the
         // entry-point for all syntax extensions.
@@ -112,6 +113,8 @@ pub fn expand_mod_items(extsbox: @mut SyntaxEnv,
                         fld: @ast_fold,
                         orig: @fn(&ast::_mod, @ast_fold) -> ast::_mod)
                      -> ast::_mod {
+    let mut cx = cx;
+
     // Fold the contents first:
     let module_ = orig(module_, fld);
 
diff --git a/src/libsyntax/ext/pipes/liveness.rs b/src/libsyntax/ext/pipes/liveness.rs
index 4597dab89cb..7843db55789 100644
--- a/src/libsyntax/ext/pipes/liveness.rs
+++ b/src/libsyntax/ext/pipes/liveness.rs
@@ -38,11 +38,11 @@ updating the states using rule (2) until there are no changes.
 */
 
 use ext::base::ext_ctxt;
-use ext::pipes::proto::protocol;
+use ext::pipes::proto::{protocol_};
 
 use std::bitv::Bitv;
 
-pub fn analyze(proto: protocol, _cx: @ext_ctxt) {
+pub fn analyze(proto: &mut protocol_, _cx: @ext_ctxt) {
     debug!("initializing colive analysis");
     let num_states = proto.num_states();
     let mut colive = do (copy proto.states).map_to_vec |state| {
diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs
index 79072a2f577..ffb55ee50d9 100644
--- a/src/libsyntax/ext/pipes/proto.rs
+++ b/src/libsyntax/ext/pipes/proto.rs
@@ -138,26 +138,26 @@ pub struct protocol_ {
 
 pub impl protocol_ {
     /// Get a state.
-    fn get_state(&mut self, name: ~str) -> state {
+    fn get_state(&self, name: ~str) -> state {
         self.states.find(|i| i.name == name).get()
     }
 
-    fn get_state_by_id(&mut self, id: uint) -> state { self.states[id] }
+    fn get_state_by_id(&self, id: uint) -> state { self.states[id] }
 
-    fn has_state(&mut self, name: ~str) -> bool {
+    fn has_state(&self, name: ~str) -> bool {
         self.states.find(|i| i.name == name).is_some()
     }
 
-    fn filename(&mut self) -> ~str {
+    fn filename(&self) -> ~str {
         ~"proto://" + self.name
     }
 
-    fn num_states(&mut self) -> uint {
+    fn num_states(&self) -> uint {
         let states = &mut *self.states;
         states.len()
     }
 
-    fn has_ty_params(&mut self) -> bool {
+    fn has_ty_params(&self) -> bool {
         for self.states.each |s| {
             if s.generics.ty_params.len() > 0 {
                 return true;
@@ -165,7 +165,7 @@ pub impl protocol_ {
         }
         false
     }
-    fn is_bounded(&mut self) -> bool {
+    fn is_bounded(&self) -> bool {
         let bounded = self.bounded.get();
         bounded
     }
@@ -179,7 +179,7 @@ pub impl protocol_ {
                       generics: ast::Generics)
                    -> state {
         let messages = @mut ~[];
-        let states = &*self.states;
+        let states = &mut *self.states;
 
         let state = @state_ {
             id: states.len(),
@@ -192,7 +192,7 @@ pub impl protocol_ {
             proto: self
         };
 
-        self.states.push(state);
+        states.push(state);
         state
     }
 }