Browse Source

add `-D dump_ignore_var_ids`

Simon Krajewski 10 years ago
parent
commit
691a59701a
3 changed files with 8 additions and 5 deletions
  1. 1 1
      codegen.ml
  2. 2 0
      common.ml
  3. 5 4
      type.ml

+ 1 - 1
codegen.ml

@@ -1347,7 +1347,7 @@ let dump_types com =
 	let params = function [] -> "" | l -> Printf.sprintf "<%s>" (String.concat "," (List.map (fun (n,t) -> n ^ " : " ^ s_type t) l)) in
 	let s_expr = match Common.defined_value_safe com Define.Dump with
 		| "pretty" -> Type.s_expr_pretty "\t"
-		| "ast" -> Type.s_expr_ast "\t"
+		| "ast" -> Type.s_expr_ast (not (Common.defined com Define.DumpIgnoreVarIds)) "\t"
 		| _ -> Type.s_expr
 	in
 	List.iter (fun mt ->

+ 2 - 0
common.ml

@@ -180,6 +180,7 @@ module Define = struct
 		| DocGen
 		| Dump
 		| DumpDependencies
+		| DumpIgnoreVarIds
 		| Fdb
 		| FlashStrict
 		| FlashUseStage
@@ -258,6 +259,7 @@ module Define = struct
 		| DocGen -> ("doc_gen","Do not perform any removal/change in order to correctly generate documentation")
 		| Dump -> ("dump","Dump the complete typed AST for internal debugging")
 		| DumpDependencies -> ("dump_dependencies","Dump the classes dependencies")
+		| DumpIgnoreVarIds -> ("dump_ignore_var_ids","Dump files do not contain variable IDs (helps with diff)")
 		| Fdb -> ("fdb","Enable full flash debug infos for FDB interactive debugging")
 		| FlashStrict -> ("flash_strict","More strict typing for flash target")
 		| FlashUseStage -> ("flash_use_stage","Keep the SWF library initial stage")

+ 5 - 4
type.ml

@@ -1042,9 +1042,9 @@ let rec s_expr_pretty tabs s_type e =
 	| TMeta ((n,el,_),e) ->
 		sprintf "@%s%s %s" (Meta.to_string n) (match el with [] -> "" | _ -> "(" ^ (String.concat ", " (List.map Ast.s_expr el)) ^ ")") (loop e)
 
-let rec s_expr_ast tabs s_type e =
+let rec s_expr_ast print_var_ids tabs s_type e =
 	let sprintf = Printf.sprintf in
-	let loop ?(extra_tabs="") = s_expr_ast (tabs ^ "\t" ^ extra_tabs) s_type in
+	let loop ?(extra_tabs="") = s_expr_ast print_var_ids (tabs ^ "\t" ^ extra_tabs) s_type in
 	let tag_args tabs sl = match sl with
 		| [] -> ""
 		| [s] when not (String.contains s '\n') -> " " ^ s
@@ -1059,9 +1059,10 @@ let rec s_expr_ast tabs s_type e =
 		in
 		sprintf "[%s:%s]%s" s st (tag_args (tabs ^ extra_tabs) sl)
 	in
+	let var_id v = if print_var_ids then v.v_id else 0 in
 	let const c = sprintf "[Const %s:%s]" (s_const c) (s_type e.etype) in
-	let local v = sprintf "[Local %s(%i):%s]" v.v_name v.v_id (s_type v.v_type) in
-	let var v sl = sprintf "[Var %s(%i):%s]%s" v.v_name v.v_id (s_type v.v_type) (tag_args tabs sl) in
+	let local v = sprintf "[Local %s(%i):%s]" v.v_name (var_id v) (s_type v.v_type) in
+	let var v sl = sprintf "[Var %s(%i):%s]%s" v.v_name (var_id v) (s_type v.v_type) (tag_args tabs sl) in
 	let module_type mt = sprintf "[TypeExpr %s:%s]" (s_type_path (t_path mt)) (s_type e.etype) in
 	match e.eexpr with
 	| TConst c -> const c