From 0624f9db4aeaa5681941750c3a1a17ca5fbb7e72 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Fri, 4 Mar 2011 07:22:43 +0100 Subject: Add a pretty-printer Adds a -pp option to the compiler which will cause it to simply pretty-print the given file. --- src/comp/front/ast.rs | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'src/comp/front/ast.rs') diff --git a/src/comp/front/ast.rs b/src/comp/front/ast.rs index ed1e2114..d45260f3 100644 --- a/src/comp/front/ast.rs +++ b/src/comp/front/ast.rs @@ -122,6 +122,31 @@ tag binop { gt; } +fn binop_to_str(binop op) -> str { + alt (op) { + case (add) {ret "+";} + case (sub) {ret "-";} + case (mul) {ret "*";} + case (div) {ret "/";} + case (rem) {ret "%";} + case (and) {ret "&&";} + case (or) {ret "||";} + case (bitxor) {ret "^";} + case (bitand) {ret "&";} + case (bitor) {ret "|";} + case (lsl) {ret "<<";} + case (lsr) {ret ">>";} + case (asr) {ret ">>>";} + case (eq) {ret "==";} + case (lt) {ret "<";} + case (le) {ret "<=";} + case (ne) {ret "!=";} + case (ge) {ret ">=";} + case (gt) {ret ">";} + } +} + + tag unop { box; deref; @@ -131,6 +156,17 @@ tag unop { _mutable; } +fn unop_to_str(unop op) -> str { + alt (op) { + case (box) {ret "@";} + case (deref) {ret "*";} + case (bitnot) {ret "~";} + case (not) {ret "!";} + case (neg) {ret "-";} + case (_mutable) {ret "mutable";} + } +} + tag mode { val; alias; -- cgit v1.2.3