From e724ed399d4505ccd8ef7cd24185d3caff083027 Mon Sep 17 00:00:00 2001 From: pad Date: Tue, 25 Feb 2014 17:49:59 -0800 Subject: [PATCH] * tests/ml/visual/ref.ml: better display of globals vs constants --- lang_ml/analyze/visual/highlight_ml.ml | 34 ++++++++++++-------------- tests/ml/visual/ref.ml | 8 ++++++ 2 files changed, 23 insertions(+), 19 deletions(-) create mode 100644 tests/ml/visual/ref.ml diff --git a/lang_ml/analyze/visual/highlight_ml.ml b/lang_ml/analyze/visual/highlight_ml.ml index 54848ad42..49de3622e 100644 --- a/lang_ml/analyze/visual/highlight_ml.ml +++ b/lang_ml/analyze/visual/highlight_ml.ml @@ -71,10 +71,12 @@ let disable_token_phase2 = false (* val is_function_body: Ast_ml.seq_expr -> bool *) -let is_function_body x = +let kind_of_body x = + let def2 = Def2 fake_no_def2 in match Ast.uncomma x with - | (Ast.Fun _ | Ast.Function _)::_xs -> true - | _ -> false + | (Ast.Fun _ | Ast.Function _)::_xs -> Function def2 + | Ast.FunCallSimple (([], Name("ref", _)), _)::_xs -> Global def2 + | _ -> Constant def2 (*****************************************************************************) @@ -163,14 +165,13 @@ let visit_program let name = let_def.l_name in let info = Ast.info_of_name name in - if not !in_let then begin - if List.length let_def.l_params > 0 || - is_function_body let_def.l_body - then tag info (Function (Def2 NoUse)) - else tag info (Global (Def2 NoUse)) - end else begin - tag info (Local (Def)) - end; + (if not !in_let + then + if List.length let_def.l_params > 0 + then tag info (Function (Def2 NoUse)) + else tag info (kind_of_body let_def.l_body) + else tag info (Local (Def)) + ); Common.save_excursion in_let true (fun () -> k x ) @@ -178,14 +179,9 @@ let visit_program (match pat with | PatTyped (_, PatVar name, _, _ty, _) -> let info = Ast.info_of_name name in - - if not !in_let then begin - if is_function_body body - then tag info (Function (Def2 NoUse)) - else tag info (Global (Def2 NoUse)) - end else begin - tag info (Local (Def)) - end; + if not !in_let + then tag info (kind_of_body body) + else tag info (Local (Def)) | _ -> () ); Common.save_excursion in_let true (fun () -> diff --git a/tests/ml/visual/ref.ml b/tests/ml/visual/ref.ml new file mode 100644 index 000000000..d8c9d6315 --- /dev/null +++ b/tests/ml/visual/ref.ml @@ -0,0 +1,8 @@ + +let x = 1 + + +let y = ref 1 + + +let z = Hashtbl.create 101