src/Tools/Code/code_ml.ML
changeset 38928 0e6f54c9d201
parent 38926 24f82786cc57
child 38933 bd77e092f67c
equal deleted inserted replaced
38927:544f4702d621 38928:0e6f54c9d201
   901       end handle Graph.UNDEF _ =>
   901       end handle Graph.UNDEF _ =>
   902         error ("Unknown statement name: " ^ labelled_name name);
   902         error ("Unknown statement name: " ^ labelled_name name);
   903   in (deresolver, nodes) end;
   903   in (deresolver, nodes) end;
   904 
   904 
   905 fun serialize_ml target print_module print_stmt with_signatures { labelled_name,
   905 fun serialize_ml target print_module print_stmt with_signatures { labelled_name,
   906   reserved_syms, includes, single_module, module_alias, class_syntax, tyco_syntax,
   906   reserved_syms, includes, module_alias, class_syntax, tyco_syntax,
   907   const_syntax, program, names, presentation_names } =
   907   const_syntax, program, names, presentation_names } =
   908   let
   908   let
   909     val is_cons = Code_Thingol.is_cons program;
   909     val is_cons = Code_Thingol.is_cons program;
   910     val is_presentation = not (null presentation_names);
   910     val is_presentation = not (null presentation_names);
   911     val (deresolver, nodes) = ml_node_of_program labelled_name
   911     val (deresolver, nodes) = ml_node_of_program labelled_name
   925           in SOME ([], p) end
   925           in SOME ([], p) end
   926     and print_nodes prefix nodes = (map_filter (print_node prefix o Graph.get_node nodes)
   926     and print_nodes prefix nodes = (map_filter (print_node prefix o Graph.get_node nodes)
   927         o rev o flat o Graph.strong_conn) nodes
   927         o rev o flat o Graph.strong_conn) nodes
   928       |> split_list
   928       |> split_list
   929       |> (fn (decls, body) => (flat decls, body))
   929       |> (fn (decls, body) => (flat decls, body))
   930     val names' = map (try (deresolver [])) names
   930     val names' = map (try (deresolver [])) names;
   931       |> single_module ? (map o Option.map) Long_Name.base_name;
       
   932     val p = Pretty.chunks2 (map snd includes @ snd (print_nodes [] nodes));
   931     val p = Pretty.chunks2 (map snd includes @ snd (print_nodes [] nodes));
   933     fun write width NONE = writeln_pretty width
   932     fun write width NONE = writeln_pretty width
   934       | write width (SOME p) = File.write p o string_of_pretty width;
   933       | write width (SOME p) = File.write p o string_of_pretty width;
   935   in
   934   in
   936     Code_Target.serialization write (fn width => (rpair names' o string_of_pretty width)) p
   935     Code_Target.serialization write (fn width => (rpair names' o string_of_pretty width)) p