[backend] eliminate phantom spaces in printing of types

Summary: These are dangerous if you are trying to compare a type to a string, and they're also unsightly.

Reviewed By: jvillard

Differential Revision: D4189956

fbshipit-source-id: 14ce127
master
Sam Blackshear 9 years ago committed by Facebook Github Bot
parent b34e8fe192
commit 708c0bf1f8

@ -239,39 +239,28 @@ let array_sensitive_compare t1 t2 =>
};
/** Pretty print a type declaration.
pp_base prints the variable for a declaration, or can be skip to print only the type */
let rec pp_decl pe pp_base f =>
/** Pretty print a type with all the details, using the C syntax. */
let rec pp_full pe f =>
fun
| Tstruct tname => F.fprintf f "%s %a" (Typename.to_string tname) pp_base ()
| Tint ik => F.fprintf f "%s %a" (ikind_to_string ik) pp_base ()
| Tfloat fk => F.fprintf f "%s %a" (fkind_to_string fk) pp_base ()
| Tvoid => F.fprintf f "void %a" pp_base ()
| Tfun false => F.fprintf f "_fn_ %a" pp_base ()
| Tfun true => F.fprintf f "_fn_noreturn_ %a" pp_base ()
| Tptr ((Tarray _ | Tfun _) as typ) pk => {
let pp_base' fmt () => F.fprintf fmt "(%s%a)" (ptr_kind_string pk) pp_base ();
pp_decl pe pp_base' f typ
}
| Tptr typ pk => {
let pp_base' fmt () => F.fprintf fmt "%s%a" (ptr_kind_string pk) pp_base ();
pp_decl pe pp_base' f typ
}
| Tstruct tname => F.fprintf f "%s" (Typename.to_string tname)
| Tint ik => F.fprintf f "%s" (ikind_to_string ik)
| Tfloat fk => F.fprintf f "%s" (fkind_to_string fk)
| Tvoid => F.fprintf f "void"
| Tfun false => F.fprintf f "_fn_"
| Tfun true => F.fprintf f "_fn_noreturn_"
| Tptr ((Tarray _ | Tfun _) as typ) pk =>
F.fprintf f "%a(%s)" (pp_full pe) typ (ptr_kind_string pk)
| Tptr typ pk => F.fprintf f "%a%s" (pp_full pe) typ (ptr_kind_string pk)
| Tarray typ static_len => {
let pp_array_static_len fmt => (
fun
| Some static_len => IntLit.pp fmt static_len
| None => F.fprintf fmt "_"
);
let pp_base' fmt () => F.fprintf fmt "%a[%a]" pp_base () pp_array_static_len static_len;
pp_decl pe pp_base' f typ
F.fprintf f "%a[%a]" (pp_full pe) typ pp_array_static_len static_len
};
/** Pretty print a type with all the details, using the C syntax. */
let pp_full pe => pp_decl pe (fun _ () => ());
/** Pretty print a type. Do nothing by default. */
let pp pe f te =>
if Config.print_types {

@ -95,11 +95,6 @@ let array_sensitive_compare: t => t => int;
let equal: t => t => bool;
/** [pp_decl pe pp_base f typ] pretty prints a type declaration.
pp_base prints the variable for a declaration, or can be skip to print only the type */
let pp_decl: printenv => (F.formatter => unit => unit) => F.formatter => t => unit;
/** Pretty print a type with all the details. */
let pp_full: printenv => F.formatter => t => unit;

@ -424,15 +424,17 @@ let get_signature summary =
let s = ref "" in
IList.iter
(fun (p, typ) ->
let pp_name f () = F.fprintf f "%a" Mangled.pp p in
let pp f () = Typ.pp_decl pe_text pp_name f typ in
let pp f () = F.fprintf f "%a %a" (Typ.pp_full pe_text) typ Mangled.pp p in
let decl = pp_to_string pp () in
s := if !s = "" then decl else !s ^ ", " ^ decl)
summary.attributes.ProcAttributes.formals;
let pp_procname f () = F.fprintf f "%a"
Procname.pp summary.attributes.ProcAttributes.proc_name in
let pp f () =
Typ.pp_decl pe_text pp_procname f summary.attributes.ProcAttributes.ret_type in
F.fprintf
f
"%a %a"
(Typ.pp_full pe_text)
summary.attributes.ProcAttributes.ret_type
Procname.pp summary.attributes.ProcAttributes.proc_name in
let decl = pp_to_string pp () in
decl ^ "(" ^ !s ^ ")"

@ -7,7 +7,7 @@ digraph iCFG {
"main.fad58de7366495db4650cfefac2fcd61_2" [label="2: Exit main \n " color=yellow style=filled]
"main.fad58de7366495db4650cfefac2fcd61_1" [label="1: Start main\nFormals: \nLocals: a:int [2][3] z:int \n DECLARE_LOCALS(&return,&a,&z); [line 10]\n " color=yellow style=filled]
"main.fad58de7366495db4650cfefac2fcd61_1" [label="1: Start main\nFormals: \nLocals: a:int[3][2] z:int \n DECLARE_LOCALS(&return,&a,&z); [line 10]\n " color=yellow style=filled]
"main.fad58de7366495db4650cfefac2fcd61_1" -> "main.fad58de7366495db4650cfefac2fcd61_3" ;

@ -7,7 +7,7 @@ digraph iCFG {
"main.fad58de7366495db4650cfefac2fcd61_2" [label="2: Exit main \n " color=yellow style=filled]
"main.fad58de7366495db4650cfefac2fcd61_1" [label="1: Start main\nFormals: \nLocals: a:int [2][3] z:int \n DECLARE_LOCALS(&return,&a,&z); [line 12]\n " color=yellow style=filled]
"main.fad58de7366495db4650cfefac2fcd61_1" [label="1: Start main\nFormals: \nLocals: a:int[3][2] z:int \n DECLARE_LOCALS(&return,&a,&z); [line 12]\n " color=yellow style=filled]
"main.fad58de7366495db4650cfefac2fcd61_1" -> "main.fad58de7366495db4650cfefac2fcd61_3" ;

Loading…
Cancel
Save