about summary refs log tree commit diff
path: root/src/comp/util
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2012-02-10 10:28:35 -0800
committerNiko Matsakis <niko@alum.mit.edu>2012-02-10 20:48:28 -0800
commit0263039ca0350eb67ce11e985bd7e698de48ca0f (patch)
tree97349888cf68f0d3b487ec15f50dcca558e96026 /src/comp/util
parentfdddf8f9e1d6738d42989a6d8a735dd58127e199 (diff)
use absolute names when pretty-printing types
Diffstat (limited to 'src/comp/util')
-rw-r--r--src/comp/util/ppaux.rs44
1 files changed, 25 insertions, 19 deletions
diff --git a/src/comp/util/ppaux.rs b/src/comp/util/ppaux.rs
index 24337878a5c..5af07e1650e 100644
--- a/src/comp/util/ppaux.rs
+++ b/src/comp/util/ppaux.rs
@@ -6,6 +6,7 @@ import syntax::print::pprust::{path_to_str, constr_args_to_str, proto_to_str,
                                mode_to_str};
 import syntax::{ast, ast_util};
 import middle::ast_map;
+import driver::session::session;
 
 fn ty_to_str(cx: ctxt, typ: t) -> str {
     fn fn_input_to_str(cx: ctxt, input: {mode: ast::mode, ty: t}) ->
@@ -60,21 +61,28 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
         }
         ret mstr + ty_to_str(cx, m.ty);
     }
-    alt ty::type_name(typ) {
-      some(cs) {
-        alt ty::get(typ).struct {
-          ty_enum(_, tps) | ty_res(_, _, tps) {
-            if vec::len(tps) > 0u {
-                let strs = vec::map(tps, {|t| ty_to_str(cx, t)});
-                ret cs + "<" + str::connect(strs, ",") + ">";
-            }
-          }
-          _ {}
+    fn parameterized(cx: ctxt, base: str, tps: [ty::t]) -> str {
+        if vec::len(tps) > 0u {
+            let strs = vec::map(tps, {|t| ty_to_str(cx, t)});
+            #fmt["%s<%s>", base, str::connect(strs, ",")]
+        } else {
+            base
         }
-        ret cs;
+    }
+
+    // if there is an id, print that instead of the structural type:
+    alt ty::type_def_id(typ) {
+      some(def_id) {
+        let cs = ast_map::path_to_str(ty::item_path(cx, def_id));
+        ret alt ty::get(typ).struct {
+          ty_enum(_, tps) | ty_res(_, _, tps) { parameterized(cx, cs, tps) }
+          _ { cs }
+        };
       }
-      _ { }
+      none { /* fallthrough */}
     }
+
+    // pretty print the structural type representation:
     ret alt ty::get(typ).struct {
       ty_nil { "()" }
       ty_bot { "_|_" }
@@ -110,15 +118,13 @@ fn ty_to_str(cx: ctxt, typ: t) -> str {
       ty_param(id, _) {
         "'" + str::from_bytes([('a' as u8) + (id as u8)])
       }
-      ty_enum(did, tps) {
+      ty_enum(did, tps) | ty_res(did, _, tps) {
+        // Not sure why, but under some circumstances enum or resource types
+        // do not have an associated id.  I didn't investigate enough to know
+        // if there is a good reason for this. - Niko, 2012-02-10
         let path = ty::item_path(cx, did);
         let base = ast_map::path_to_str(path);
-        if vec::is_empty(tps) {
-            base
-        } else {
-            let tps_strs = vec::map(tps) {|t| ty_to_str(cx, t) };
-            #fmt["%s<%s>", base, str::connect(tps_strs, ",")]
-        }
+        parameterized(cx, base, tps)
       }
       _ { ty_to_short_str(cx, typ) }
     }