Skip to content
This repository has been archived by the owner on Jun 4, 2019. It is now read-only.

Commit

Permalink
* lang_ml/analyze/graph_code_cmt.ml: support for 4.00 and 4.01 via cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
pad committed Oct 6, 2013
1 parent 6b1277d commit 81fbf8c
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 9 deletions.
4 changes: 2 additions & 2 deletions configure
Expand Up @@ -173,8 +173,8 @@ my $arch = `uname`;
#---------------------------------------------------------------------
# We need 3.12 because I use the forall 'a. new typing feature
# as well as the '_' pattern in records (in my code but also in lib-sexp/)
# We need 4.00 because of codegraph for ocaml code using the .cmt
# We need 4.01 because of changes in the .cmt format
# We need 4.00 for codegraph for ocaml code using the .cmt
# We need 4.01 for changes in the .cmt format
$error +=
check_config("echo \"1;;\\n\" | ocaml |",
"(Objective|OCaml)(.*) (4\.01\.*)",
Expand Down
14 changes: 14 additions & 0 deletions lang_ml/analyze/Makefile
Expand Up @@ -91,6 +91,20 @@ clean::
rm -f $(TARGET).top


CPP=-pp 'cpp -DOCAML_VERSION=4000'

meta_ast_cmt.cmo: meta_ast_cmt.ml
$(OCAMLC) $(CPP) -c $<

meta_ast_cmt.cmx: meta_ast_cmt.ml
$(OCAMLOPT) $(CPP) -c $<

graph_code_cmt.cmo: graph_code_cmt.ml
$(OCAMLC) $(CPP) -c $<

graph_code_cmt.cmx: graph_code_cmt.ml
$(OCAMLOPT) $(CPP) $<

##############################################################################
# Literate Programming rules
##############################################################################
56 changes: 49 additions & 7 deletions lang_ml/analyze/graph_code_cmt.ml
Expand Up @@ -651,8 +651,13 @@ and structure_item_desc env loc = function
in ()

(* opened names are resolved, no need to handle that I think *)
#if OCAML_VERSION >= 4010
| Tstr_open ((_override, v1, _loc)) ->
path_t env v1
#else
| Tstr_open ((v1, _loc)) ->
path_t env v1
#endif
| Tstr_include ((v1, v2)) ->
let _ = module_expr env v1 and _ = List.iter (Ident.t env) v2 in ()

Expand Down Expand Up @@ -722,7 +727,12 @@ and pattern_desc t env = function
constant env v1
| Tpat_tuple xs ->
List.iter (pattern env) xs
| Tpat_construct ((lid, v3, v4, v5)) ->
#if OCAML_VERSION >= 4010
| Tpat_construct (lid, v3, v4, v5)
#else
| Tpat_construct (_path, lid, v3, v4, v5)
#endif
->
add_use_edge_lid env lid t E.Constructor;
let _ = constructor_description env v3
and _ = List.iter (pattern env) v4
Expand All @@ -733,7 +743,13 @@ and pattern_desc t env = function
and _ = v_ref (row_desc env) v3
in ()
| Tpat_record ((xs, _closed_flag)) ->
List.iter (fun (lid, v2, v3) ->
List.iter (fun
#if OCAML_VERSION >= 4010
(lid, v2, v3)
#else
(_path, lid, v2, v3)
#endif
->
add_use_edge_lid env lid t E.Field;
let _ = label_description env v3
and _ = pattern env v3
Expand Down Expand Up @@ -816,7 +832,12 @@ and expression_desc t env =
v2
in ()
| Texp_tuple v1 -> let _ = List.iter (expression env) v1 in ()
| Texp_construct (lid, v2, v3, _bool) ->
#if OCAML_VERSION >= 4010
| Texp_construct (lid, v2, v3, _bool)
#else
| Texp_construct (_path, lid, v2, v3, _bool)
#endif
->
add_use_edge_lid env lid t E.Constructor;
constructor_description env v2;
List.iter (expression env) v3;
Expand All @@ -825,19 +846,35 @@ and expression_desc t env =
let _ = label env v1 and _ = v_option (expression env) v2 in ()
(* ?? *)
| Texp_record ((v1, v2)) ->
List.iter (fun (lid, v2, v3) ->
List.iter (fun
#if OCAML_VERSION >= 4010
(lid, v2, v3)
#else
(_path, lid, v2, v3)
#endif
->
path_t env lid;
let _ = label_description env v2
and _ = expression env v3
in ()
) v1;
v_option (expression env) v2
| Texp_field ((v1, lid, v2)) ->
#if OCAML_VERSION >= 4010
| Texp_field ((v1, lid, v2))
#else
| Texp_field ((v1, _path, lid, v2))
#endif
->
expression env v1;
add_use_edge_lid env lid v1.exp_type E.Field;
label_description env v2

| Texp_setfield ((v1, lid, v3, v4)) ->
#if OCAML_VERSION >= 4010
| Texp_setfield ((v1, lid, v3, v4))
#else
| Texp_setfield ((v1, _path, lid, v3, v4))
#endif
->
expression env v1;
add_use_edge_lid env lid v1.exp_type E.Field;
label_description env v3;
Expand Down Expand Up @@ -908,7 +945,12 @@ and exp_extra env = function
let _ = v_option (core_type env) v1
and _ = v_option (core_type env) v2
in ()
| Texp_open (_override, path, lid, _env) ->
#if OCAML_VERSION >= 4010
| Texp_open (_override, path, lid, _env)
#else
| Texp_open (path, lid, _env)
#endif
->
path_t env path
| Texp_poly v1 -> let _ = v_option (core_type env) v1 in ()
| Texp_newtype v1 -> let _ = v_string v1 in ()
Expand Down
101 changes: 101 additions & 0 deletions lang_ml/analyze/meta_ast_cmt.ml
Expand Up @@ -273,17 +273,28 @@ and vof_pattern_desc =
| Tpat_tuple v1 ->
let v1 = Ocaml.vof_list vof_pattern v1
in Ocaml.VSum (("Tpat_tuple", [ v1 ]))
#if OCAML_VERSION >= 4010
| Tpat_construct ((v1, v2, v3, v4)) ->
let v1 = vof_loc Longident.vof_t v1
and v2 = vof_constructor_description v2
and v3 = Ocaml.vof_list vof_pattern v3
and v4 = Ocaml.vof_bool v4
in Ocaml.VSum (("Tpat_construct", [ v1; v2; v3; v4 ]))
#else
| Tpat_construct ((v1, v2, v3, v4, v5)) ->
let v1 = Path.vof_t v1
and v2 = vof_loc Longident.vof_t v2
and v3 = vof_constructor_description v3
and v4 = Ocaml.vof_list vof_pattern v4
and v5 = Ocaml.vof_bool v5
in Ocaml.VSum (("Tpat_construct", [ v1; v2; v3; v4; v5 ]))
#endif
| Tpat_variant ((v1, v2, v3)) ->
let v1 = vof_label v1
and v2 = Ocaml.vof_option vof_pattern v2
and v3 = Ocaml.vof_ref vof_row_desc v3
in Ocaml.VSum (("Tpat_variant", [ v1; v2; v3 ]))
#if OCAML_VERSION >= 4010
| Tpat_record ((v1, v2)) ->
let v1 =
Ocaml.vof_list
Expand All @@ -295,6 +306,20 @@ and vof_pattern_desc =
v1
and v2 = vof_closed_flag v2
in Ocaml.VSum (("Tpat_record", [ v1; v2 ]))
#else
| Tpat_record ((v1, v2)) ->
let v1 =
Ocaml.vof_list
(fun (v1, v2, v3, v4) ->
let v1 = Path.vof_t v1
and v2 = vof_loc Longident.vof_t v2
and v3 = vof_label_description v3
and v4 = vof_pattern v4
in Ocaml.VTuple [ v1; v2; v3; v4 ])
v1
and v2 = vof_closed_flag v2
in Ocaml.VSum (("Tpat_record", [ v1; v2 ]))
#endif
| Tpat_array v1 ->
let v1 = Ocaml.vof_list vof_pattern v1
in Ocaml.VSum (("Tpat_array", [ v1 ]))
Expand Down Expand Up @@ -344,12 +369,21 @@ and vof_exp_extra =
let v1 = Ocaml.vof_option vof_core_type v1
and v2 = Ocaml.vof_option vof_core_type v2
in Ocaml.VSum (("Texp_constraint", [ v1; v2 ]))
#if OCAML_VERSION >= 4010
| Texp_open ((v1, v2, v3, v4)) ->
let v1 = vof_override_flag v1
and v2 = Path.vof_t v2
and v3 = vof_loc Longident.vof_t v3
and v4 = Env.vof_t v4
in Ocaml.VSum (("Texp_open", [ v1; v2; v3; v4 ]))
#else
| Texp_open ((v1, v2, v3)) ->
let v1 = Path.vof_t v1
and v2 = vof_loc Longident.vof_t v2
and v3 = Env.vof_t v3
in Ocaml.VSum (("Texp_open", [ v1; v2; v3 ]))
#endif

| Texp_poly v1 ->
let v1 = Ocaml.vof_option vof_core_type v1
in Ocaml.VSum (("Texp_poly", [ v1 ]))
Expand Down Expand Up @@ -421,16 +455,30 @@ and vof_expression_desc =
| Texp_tuple v1 ->
let v1 = Ocaml.vof_list vof_expression v1
in Ocaml.VSum (("Texp_tuple", [ v1 ]))

#if OCAML_VERSION >= 4010
| Texp_construct ((v1, v2, v3, v4)) ->
let v1 = vof_loc Longident.vof_t v1
and v2 = vof_constructor_description v2
and v3 = Ocaml.vof_list vof_expression v3
and v4 = Ocaml.vof_bool v4
in Ocaml.VSum (("Texp_construct", [ v1; v2; v3; v4 ]))
#else
| Texp_construct ((v1, v2, v3, v4, v5)) ->
let v1 = Path.vof_t v1
and v2 = vof_loc Longident.vof_t v2
and v3 = vof_constructor_description v3
and v4 = Ocaml.vof_list vof_expression v4
and v5 = Ocaml.vof_bool v5
in Ocaml.VSum (("Texp_construct", [ v1; v2; v3; v4; v5 ]))
#endif

| Texp_variant ((v1, v2)) ->
let v1 = vof_label v1
and v2 = Ocaml.vof_option vof_expression v2
in Ocaml.VSum (("Texp_variant", [ v1; v2 ]))

#if OCAML_VERSION >= 4010
| Texp_record ((v1, v2)) ->
let v1 =
Ocaml.vof_list
Expand All @@ -453,6 +501,34 @@ and vof_expression_desc =
and v3 = vof_label_description v3
and v4 = vof_expression v4
in Ocaml.VSum (("Texp_setfield", [ v1; v2; v3; v4 ]))
#else
| Texp_record ((v1, v2)) ->
let v1 =
Ocaml.vof_list
(fun (v1, v2, v3, v4) ->
let v1 = Path.vof_t v1
and v2 = vof_loc Longident.vof_t v2
and v3 = vof_label_description v3
and v4 = vof_expression v4
in Ocaml.VTuple [ v1; v2; v3; v4 ])
v1
and v2 = Ocaml.vof_option vof_expression v2
in Ocaml.VSum (("Texp_record", [ v1; v2 ]))
| Texp_field ((v1, v2, v3, v4)) ->
let v1 = vof_expression v1
and v2 = Path.vof_t v2
and v3 = vof_loc Longident.vof_t v3
and v4 = vof_label_description v4
in Ocaml.VSum (("Texp_field", [ v1; v2; v3; v4 ]))
| Texp_setfield ((v1, v2, v3, v4, v5)) ->
let v1 = vof_expression v1
and v2 = Path.vof_t v2
and v3 = vof_loc Longident.vof_t v3
and v4 = vof_label_description v4
and v5 = vof_expression v5
in Ocaml.VSum (("Texp_setfield", [ v1; v2; v3; v4; v5 ]))
#endif

| Texp_array v1 ->
let v1 = Ocaml.vof_list vof_expression v1
in Ocaml.VSum (("Texp_array", [ v1 ]))
Expand Down Expand Up @@ -854,11 +930,18 @@ and vof_structure_item_desc =
and v2 = vof_loc Ocaml.vof_string v2
and v3 = vof_module_type v3
in Ocaml.VSum (("Tstr_modtype", [ v1; v2; v3 ]))
#if OCAML_VERSION >= 4010
| Tstr_open ((v1, v2, v3)) ->
let v1 = vof_override_flag v1
and v2 = Path.vof_t v2
and v3 = vof_loc Longident.vof_t v3
in Ocaml.VSum (("Tstr_open", [ v1; v2; v3 ]))
#else
| Tstr_open ((v1, v2)) ->
let v1 = Path.vof_t v1
and v2 = vof_loc Longident.vof_t v2
in Ocaml.VSum (("Tstr_open", [ v1; v2 ]))
#endif
| Tstr_class v1 ->
let v1 =
Ocaml.vof_list
Expand All @@ -879,10 +962,19 @@ and vof_structure_item_desc =
in Ocaml.VTuple [ v1; v2; v3 ])
v1
in Ocaml.VSum (("Tstr_class_type", [ v1 ]))

#if OCAML_VERSION >= 4010
| Tstr_include ((v1, v2)) ->
let v1 = vof_module_expr v1
and v2 = Types.vof_signature v2
in Ocaml.VSum (("Tstr_include", [ v1; v2 ]))
#else
| Tstr_include ((v1, v2)) ->
let v1 = vof_module_expr v1
and v2 = Ocaml.vof_list Ident.vof_t v2
in Ocaml.VSum (("Tstr_include", [ v1; v2 ]))
#endif

and vof_module_coercion =
function
| Tcoerce_none -> Ocaml.VSum (("Tcoerce_none", []))
Expand Down Expand Up @@ -1028,11 +1120,20 @@ and vof_signature_item_desc =
and v2 = vof_loc Ocaml.vof_string v2
and v3 = vof_modtype_declaration v3
in Ocaml.VSum (("Tsig_modtype", [ v1; v2; v3 ]))

#if OCAML_VERSION >= 4010
| Tsig_open ((v1, v2, v3)) ->
let v1 = vof_override_flag v1
and v2 = Path.vof_t v2
and v3 = vof_loc Longident.vof_t v3
in Ocaml.VSum (("Tsig_open", [ v1; v2; v3 ]))
#else
| Tsig_open ((v1, v2)) ->
let v1 = Path.vof_t v1
and v2 = vof_loc Longident.vof_t v2
in Ocaml.VSum (("Tsig_open", [ v1; v2 ]))
#endif

| Tsig_include ((v1, v2)) ->
let v1 = vof_module_type v1
and v2 = Types.vof_signature v2
Expand Down

0 comments on commit 81fbf8c

Please sign in to comment.