about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorPatrick Walton <pcwalton@mimiga.net>2012-07-27 19:32:42 -0700
committerPatrick Walton <pcwalton@mimiga.net>2012-07-27 19:35:24 -0700
commit93c2f5e0e43532a2288ed6dec378564264d1a77c (patch)
tree2d8d3f5d4667f7a009fa338bc34076216873b35c /src/libsyntax
parente6d2e49852873c52b872185a0ae5a8ca941ed2f1 (diff)
downloadrust-93c2f5e0e43532a2288ed6dec378564264d1a77c.tar.gz
rust-93c2f5e0e43532a2288ed6dec378564264d1a77c.zip
rustc: Use coherence for operator overloading.
The only use of the old-style impls is now placement new.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs53
-rw-r--r--src/libsyntax/ast_util.rs16
-rw-r--r--src/libsyntax/ext/pipes/ast_builder.rs17
-rw-r--r--src/libsyntax/ext/pipes/pipec.rs2
4 files changed, 70 insertions, 18 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 933e693345d..b7cb85a5610 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -773,6 +773,59 @@ enum inlined_item {
     ii_dtor(class_dtor, ident, ~[ty_param], def_id /* parent id */)
 }
 
+// Convenience functions
+
+pure fn simple_path(id: ident, span: span) -> @path {
+    @{span: span,
+      global: false,
+      idents: ~[id],
+      rp: none,
+      types: ~[]}
+}
+
+pure fn empty_span() -> span {
+    {lo: 0, hi: 0, expn_info: none}
+}
+
+// Convenience implementations
+
+// Remove after snapshot!
+trait path_concat {
+    pure fn +(&&id: ident) -> @path;
+}
+
+// Remove after snapshot!
+impl methods of path_concat for ident {
+    pure fn +(&&id: ident) -> @path {
+        simple_path(self, empty_span()) + id
+    }
+}
+
+impl methods of ops::add<ident,@path> for ident {
+    pure fn add(&&id: ident) -> @path {
+        simple_path(self, empty_span()) + id
+    }
+}
+
+// Remove after snapshot!
+impl methods of path_concat for @path {
+    pure fn +(&&id: ident) -> @path {
+        @{
+            idents: vec::append_one(self.idents, id)
+            with *self
+        }
+    }
+}
+
+impl methods of ops::add<ident,@path> for @path {
+    pure fn add(&&id: ident) -> @path {
+        @{
+            idents: vec::append_one(self.idents, id)
+            with *self
+        }
+    }
+}
+
 //
 // Local Variables:
 // mode: rust
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index 26e0c70442d..98b42ce79ae 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -87,6 +87,22 @@ pure fn binop_to_str(op: binop) -> ~str {
     }
 }
 
+pure fn binop_to_method_name(op: binop) -> option<~str> {
+    alt op {
+      add { ret some(~"add"); }
+      subtract { ret some(~"sub"); }
+      mul { ret some(~"mul"); }
+      div { ret some(~"div"); }
+      rem { ret some(~"modulo"); }
+      bitxor { ret some(~"bitxor"); }
+      bitand { ret some(~"bitand"); }
+      bitor { ret some(~"bitor"); }
+      shl { ret some(~"shl"); }
+      shr { ret some(~"shr"); }
+      and | or | eq | lt | le | ne | ge | gt { ret none; }
+    }
+}
+
 pure fn lazy_binop(b: binop) -> bool {
     alt b { and { true } or { true } _ { false } }
 }
diff --git a/src/libsyntax/ext/pipes/ast_builder.rs b/src/libsyntax/ext/pipes/ast_builder.rs
index f367fb63985..bb5b35233cd 100644
--- a/src/libsyntax/ext/pipes/ast_builder.rs
+++ b/src/libsyntax/ext/pipes/ast_builder.rs
@@ -31,23 +31,6 @@ fn empty_span() -> span {
     {lo: 0, hi: 0, expn_info: none}
 }
 
-trait path_concat {
-    fn +(id: ident) -> @ast::path;
-}
-
-impl methods of path_concat for ident {
-    fn +(id: ident) -> @ast::path {
-        path(self, empty_span()) + id
-    }
-}
-
-impl methods of path_concat for @ast::path {
-    fn +(id: ident) -> @ast::path {
-        @{idents: vec::append_one(self.idents, id)
-          with *self}
-    }
-}
-
 trait append_types {
     fn add_ty(ty: @ast::ty) -> @ast::path;
     fn add_tys(+tys: ~[@ast::ty]) -> @ast::path;
diff --git a/src/libsyntax/ext/pipes/pipec.rs b/src/libsyntax/ext/pipes/pipec.rs
index 392e6ba392a..c1274d12f1d 100644
--- a/src/libsyntax/ext/pipes/pipec.rs
+++ b/src/libsyntax/ext/pipes/pipec.rs
@@ -16,12 +16,12 @@ import ext::base::{mk_ctxt, ext_ctxt};
 import parse;
 import parse::*;
 import proto::*;
+import ast::methods;
 
 import ast_builder::append_types;
 import ast_builder::ast_builder;
 import ast_builder::methods;
 import ast_builder::path;
-import ast_builder::path_concat;
 
 // Transitional reexports so qquote can find the paths it is looking for
 mod syntax {