package mlpost

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file duplicate.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
(**************************************************************************)
(*                                                                        *)
(*  Copyright (C) Johannes Kanig, Stephane Lescuyer                       *)
(*  Jean-Christophe Filliatre, Romain Bardou and Francois Bobot           *)
(*                                                                        *)
(*  This software is free software; you can redistribute it and/or        *)
(*  modify it under the terms of the GNU Library General Public           *)
(*  License version 2.1, with the special exception on linking            *)
(*  described in file LICENSE.                                            *)
(*                                                                        *)
(*  This software is distributed in the hope that it will be useful,      *)
(*  but WITHOUT ANY WARRANTY; without even the implied warranty of        *)
(*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.                  *)
(*                                                                        *)
(**************************************************************************)

open Types
open Hashcons

(* A duplicate analysis - find out the number of times a node is used *)

module MetaPath = struct
  type t = metapath_node hash_consed

  let equal = ( == )

  let hash x = x.hkey
end

module Path = struct
  type t = path_node hash_consed

  let equal = ( == )

  let hash x = x.hkey
end

module Picture = struct
  type t = picture_node hash_consed

  let equal = ( == )

  let hash x = x.hkey
end

module MPthM = Hashtbl.Make (MetaPath)
module PthM = Hashtbl.Make (Path)
module PicM = Hashtbl.Make (Picture)

let path_map = PthM.create 257

let picture_map = PicM.create 257

let test_and_incr_path n =
  try
    incr (PthM.find path_map n);
    true
  with Not_found ->
    PthM.add path_map n (ref 1);
    false

let test_and_incr_pic n =
  try
    incr (PicM.find picture_map n);
    true
  with Not_found ->
    PicM.add picture_map n (ref 1);
    false

let option_count f = function None -> () | Some x -> f x

let rec metapath p =
  match p.Hashcons.node with
  | MPAConcat (_, _, p) -> metapath p
  | MPAAppend (p1, _, p2) ->
      metapath p1;
      metapath p2
  | MPAKnot _ -> ()
  | MPAofPA p -> path p

and path' = function
  | PAofMPA p -> metapath p
  | MPACycle (_, _, p) -> metapath p
  | PATransformed (p, _) -> path p
  | PACutAfter (p1, p2) | PACutBefore (p1, p2) ->
      path p1;
      path p2
  | PABuildCycle pl -> List.iter path pl
  | PASub (_, _, p) -> path p
  | PABBox p -> commandpic p
  | PAUnitSquare | PAQuarterCircle | PAHalfCircle | PAFullCircle -> ()

and path p =
  (*   Format.printf "%a@." Print.path p; *)
  if test_and_incr_path p then () else path' p.node

and picture' = function
  | PITransformed (p, _) -> commandpic p
  | PITex _ -> ()
  | PIClip (pic, pth) ->
      commandpic pic;
      path pth

and picture p = if test_and_incr_pic p then () else picture' p.node

and command c =
  match c.node with
  | CDraw (p, b) ->
      path p;
      brush b
  | CFill (p, _) -> path p
  | CDotLabel (pic, _, _) -> commandpic pic
  | CLabel (pic, _, _) -> commandpic pic
  | CExternalImage _ -> ()

and brush b =
  let b = b.Hashcons.node in
  option_count pen b.pen;
  option_count dash b.dash

and pen p =
  match p.Hashcons.node with
  | PenCircle | PenSquare -> ()
  | PenFromPath p -> path p
  | PenTransformed (p, _) -> pen p

and dash d =
  match d.Hashcons.node with
  | DEvenly | DWithdots -> ()
  | DScaled (_, d) -> dash d
  | DShifted (_, d) -> dash d
  | DPattern l -> List.iter dash_pattern l

and dash_pattern _ = ()

and commandpic p =
  match p.node with
  | Picture p -> picture p
  | Command c -> command c
  | Seq l -> List.iter commandpic l
OCaml

Innovation. Community. Security.