aboutsummaryrefslogtreecommitdiff
path: root/src/comp/middle/ty.rs
diff options
context:
space:
mode:
authorMarijn Haverbeke <[email protected]>2011-03-09 11:41:50 +0100
committerunknown <graydon@.(none)>2011-03-09 16:15:55 -0800
commitaed40fbcd8e81cc1ef7a51b40b76b4631cba299e (patch)
treeb9fe1cf0f40a6f54ab8b6522a3ed6677b127bb02 /src/comp/middle/ty.rs
parentAdd stdout_writer and string_writer to std.io (diff)
downloadrust-aed40fbcd8e81cc1ef7a51b40b76b4631cba299e.tar.xz
rust-aed40fbcd8e81cc1ef7a51b40b76b4631cba299e.zip
Have the pretty-printer take a writer stream as argument
It now uses a string writer to also fill in for middle.ty.ast_ty_to_str
Diffstat (limited to 'src/comp/middle/ty.rs')
-rw-r--r--src/comp/middle/ty.rs81
1 files changed, 1 insertions, 80 deletions
diff --git a/src/comp/middle/ty.rs b/src/comp/middle/ty.rs
index 05558da1..958d0b78 100644
--- a/src/comp/middle/ty.rs
+++ b/src/comp/middle/ty.rs
@@ -81,87 +81,10 @@ tag unify_result {
// Stringification
-fn ast_ty_to_str(&@ast.ty ty) -> str {
-
- fn ast_fn_input_to_str(&rec(ast.mode mode, @ast.ty ty) input) -> str {
- auto s;
- if (mode_is_alias(input.mode)) {
- s = "&";
- } else {
- s = "";
- }
-
- ret s + ast_ty_to_str(input.ty);
- }
-
- fn ast_ty_field_to_str(&ast.ty_field f) -> str {
- ret ast_ty_to_str(f.ty) + " " + f.ident;
- }
-
- auto s;
- alt (ty.node) {
- case (ast.ty_nil) { s = "()"; }
- case (ast.ty_bool) { s = "bool"; }
- case (ast.ty_int) { s = "int"; }
- case (ast.ty_uint) { s = "uint"; }
- case (ast.ty_machine(?tm)) { s = common.ty_mach_to_str(tm); }
- case (ast.ty_char) { s = "char"; }
- case (ast.ty_str) { s = "str"; }
- case (ast.ty_box(?t)) { s = "@" + ast_ty_to_str(t); }
- case (ast.ty_vec(?t)) { s = "vec[" + ast_ty_to_str(t) + "]"; }
- case (ast.ty_type) { s = "type"; }
-
- case (ast.ty_tup(?elts)) {
- auto f = ast_ty_to_str;
- s = "tup(";
- s += _str.connect(_vec.map[@ast.ty,str](f, elts), ",");
- s += ")";
- }
-
- case (ast.ty_rec(?fields)) {
- auto f = ast_ty_field_to_str;
- s = "rec(";
- s += _str.connect(_vec.map[ast.ty_field,str](f, fields), ",");
- s += ")";
- }
-
- case (ast.ty_fn(?proto, ?inputs, ?output)) {
- auto f = ast_fn_input_to_str;
- if (proto == ast.proto_fn) {
- s = "fn(";
- } else {
- s = "iter(";
- }
- auto is = _vec.map[rec(ast.mode mode, @ast.ty ty),str](f, inputs);
- s += _str.connect(is, ", ");
- s += ")";
-
- if (output.node != ast.ty_nil) {
- s += " -> " + ast_ty_to_str(output);
- }
- }
-
- case (ast.ty_path(?path, _)) {
- s = path_to_str(path);
- }
-
- case (ast.ty_mutable(?t)) {
- s = "mutable " + ast_ty_to_str(t);
- }
-
-
- case (_) {
- fail; // FIXME: typestate bug
- }
- }
-
- ret s;
-}
-
fn path_to_str(&ast.path pth) -> str {
auto result = _str.connect(pth.node.idents, ".");
if (_vec.len[@ast.ty](pth.node.types) > 0u) {
- auto f = ast_ty_to_str;
+ auto f = pretty.pprust.ty_to_str;
result += "[";
result += _str.connect(_vec.map[@ast.ty,str](f, pth.node.types), ",");
result += "]";
@@ -169,8 +92,6 @@ fn path_to_str(&ast.path pth) -> str {
ret result;
}
-// FIXME use the pretty-printer for this once it has a concept of an
-// abstract stream
fn ty_to_str(&@t typ) -> str {
fn fn_input_to_str(&rec(ast.mode mode, @t ty) input) -> str {