summary refs log tree commit diff
path: root/src/libsyntax/ext
diff options
context:
space:
mode:
authorMichael Sullivan <sully@msully.net>2012-07-11 23:42:26 -0700
committerMichael Sullivan <sully@msully.net>2012-07-12 16:52:26 -0700
commit2ea9c8df0f7c9ee72913883128b37d0a80d2f4f6 (patch)
treeb3e4acbf2912f804cb45f87e8819a5e4847ec213 /src/libsyntax/ext
parentacb86921a62ba01726fd922f55d0176fa6c1df7c (diff)
downloadrust-2ea9c8df0f7c9ee72913883128b37d0a80d2f4f6.tar.gz
rust-2ea9c8df0f7c9ee72913883128b37d0a80d2f4f6.zip
Accept prefix notation for writing the types of str/~ and friends.
Diffstat (limited to 'src/libsyntax/ext')
-rw-r--r--src/libsyntax/ext/auto_serialize.rs25
-rw-r--r--src/libsyntax/ext/simplext.rs2
-rw-r--r--src/libsyntax/ext/tt/transcribe.rs4
3 files changed, 26 insertions, 5 deletions
diff --git a/src/libsyntax/ext/auto_serialize.rs b/src/libsyntax/ext/auto_serialize.rs
index 0de49367b17..e32ebf4eae5 100644
--- a/src/libsyntax/ext/auto_serialize.rs
+++ b/src/libsyntax/ext/auto_serialize.rs
@@ -218,7 +218,7 @@ impl helpers for ext_ctxt {
                 ast::expr_alt(v, arms, ast::alt_exhaustive)))
     }
 
-    fn lit_str(span: span, s: @str) -> @ast::expr {
+    fn lit_str(span: span, s: @str/~) -> @ast::expr {
         self.expr(
             span,
             ast::expr_lit(
@@ -343,8 +343,19 @@ fn ser_lambda(cx: ext_ctxt, tps: ser_tps_map, ty: @ast::ty,
     cx.lambda(cx.blk(ty.span, ser_ty(cx, tps, ty, s, v)))
 }
 
+fn is_vec_or_str(ty: @ast::ty) -> bool {
+    alt ty.node {
+      ast::ty_vec(_) { true }
+      // This may be wrong if the user has shadowed (!) str
+      ast::ty_path(@{span: _, global: _, idents: ids,
+                             rp: none, types: _}, _)
+      if ids == ~[@"str"] { true }
+      _ { false }
+    }
+}
+
 fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
-                ty: @ast::ty, -s: @ast::expr, -v: @ast::expr)
+          ty: @ast::ty, -s: @ast::expr, -v: @ast::expr)
     -> ~[@ast::stmt] {
 
     let ext_cx = cx; // required for #ast{}
@@ -365,6 +376,11 @@ fn ser_ty(cx: ext_ctxt, tps: ser_tps_map,
         ~[#ast(stmt){$(s).emit_box($(l));}]
       }
 
+      // For unique evecs/estrs, just pass through to underlying vec or str
+      ast::ty_uniq(mt) if is_vec_or_str(mt.ty) {
+        ser_ty(cx, tps, mt.ty, s, v)
+      }
+
       ast::ty_uniq(mt) {
         let l = ser_lambda(cx, tps, mt.ty, cx.clone(s), #ast{ *$(v) });
         ~[#ast(stmt){$(s).emit_uniq($(l));}]
@@ -612,6 +628,11 @@ fn deser_ty(cx: ext_ctxt, tps: deser_tps_map,
         #ast{ @$(d).read_box($(l)) }
       }
 
+      // For unique evecs/estrs, just pass through to underlying vec or str
+      ast::ty_uniq(mt) if is_vec_or_str(mt.ty) {
+        deser_ty(cx, tps, mt.ty, d)
+      }
+
       ast::ty_uniq(mt) {
         let l = deser_lambda(cx, tps, mt.ty, cx.clone(d));
         #ast{ ~$(d).read_uniq($(l)) }
diff --git a/src/libsyntax/ext/simplext.rs b/src/libsyntax/ext/simplext.rs
index c9355f05e38..0d415ccfc43 100644
--- a/src/libsyntax/ext/simplext.rs
+++ b/src/libsyntax/ext/simplext.rs
@@ -679,7 +679,7 @@ fn add_new_extension(cx: ext_ctxt, sp: span, arg: ast::mac_arg,
                      _body: ast::mac_body) -> base::macro_def {
     let args = get_mac_args_no_max(cx, sp, arg, 0u, "macro");
 
-    let mut macro_name: option<@str> = none;
+    let mut macro_name: option<@str/~> = none;
     let mut clauses: ~[@clause] = ~[];
     for args.each |arg| {
         alt arg.node {
diff --git a/src/libsyntax/ext/tt/transcribe.rs b/src/libsyntax/ext/tt/transcribe.rs
index 8924c5820a9..113fdea42e4 100644
--- a/src/libsyntax/ext/tt/transcribe.rs
+++ b/src/libsyntax/ext/tt/transcribe.rs
@@ -24,7 +24,7 @@ type tt_frame = @{
 
 type tt_reader = @{
     sp_diag: span_handler,
-    interner: @interner<@str>,
+    interner: @interner<@str/~>,
     mut cur: tt_frame,
     /* for MBE-style macro transcription */
     interpolations: std::map::hashmap<ident, @arb_depth>,
@@ -38,7 +38,7 @@ type tt_reader = @{
 /** This can do Macro-By-Example transcription. On the other hand, if
  *  `src` contains no `tt_dotdotdot`s and `tt_interpolate`s, `interp` can (and
  *  should) be none. */
-fn new_tt_reader(sp_diag: span_handler, itr: @interner<@str>,
+fn new_tt_reader(sp_diag: span_handler, itr: @interner<@str/~>,
                  interp: option<std::map::hashmap<ident,@arb_depth>>,
                  src: ~[ast::token_tree])
     -> tt_reader {