diff options
author | Alex AUVOLAT <alex.auvolat@ens.fr> | 2013-11-25 15:06:21 +0100 |
---|---|---|
committer | Alex AUVOLAT <alex.auvolat@ens.fr> | 2013-11-25 15:06:21 +0100 |
commit | f9ac80d948ecedcf9e04b94b5b529a31f23589a9 (patch) | |
tree | ac566d8756c19367a7eecc39363bd979c61bf8c5 /src/pretty.ml | |
parent | 415f94f0978fbf3104f93033fe21ec88f2ec454f (diff) | |
download | LPC-Projet-f9ac80d948ecedcf9e04b94b5b529a31f23589a9.tar.gz LPC-Projet-f9ac80d948ecedcf9e04b94b5b529a31f23589a9.zip |
Added localisation for expressions and statements.
Diffstat (limited to 'src/pretty.ml')
-rw-r--r-- | src/pretty.ml | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/pretty.ml b/src/pretty.ml index 1307bdf..e618bfa 100644 --- a/src/pretty.ml +++ b/src/pretty.ml @@ -84,7 +84,7 @@ let rec var_type_str = function | TVoid -> "void" | TInt -> "int" | TIdent(i) -> i | TPtr(k) -> "*" ^ (var_type_str k) | TRef(k) -> "&" ^ (var_type_str k) -let rec expr_string = function +let rec expr_string e = match e.e_desc with | EInt(i) -> string_of_int i | EBool(b) -> (if b then "true" else "false") | ENull -> "NULL" @@ -99,7 +99,7 @@ let rec expr_string = function let rec print_stmt l x = for i = 1 to l do print_string " " done; - match x with + match x.s_desc with | SEmpty -> print_string ";\n" | SExpr(e) -> print_string ((expr_string e) ^ "\n") | SIf(e, a, b) -> print_string ("if " ^ (expr_string e) ^ "\n"); @@ -124,8 +124,9 @@ let rec print_stmt l x = (i ^ " : " ^ (var_type_str t) ^ " = " ^ c ^ "(" ^ (csl expr_string a) ^ ")\n") | SWriteCout(k) -> print_string ("std::cout" ^ - (List.fold_left (fun x k -> x ^ " << " ^ (match k with - | SEExpr(k) -> expr_string k | SEStr("\n") -> "std::endl" | SEStr(s) -> "`" ^ s ^ "`")) "" k) ^ "\n") + (List.fold_left (fun x k -> x ^ " << " ^ (match k.se_desc with + | SEExpr(e) -> expr_string {e_loc = k.se_loc; e_desc = e} + | SEStr("\n") -> "std::endl" | SEStr(s) -> "`" ^ s ^ "`")) "" k) ^ "\n") and print_block n b = let prefix = String.make n ' ' in print_string (prefix ^ "{\n"); |