forked from ocaml/odoc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Paul-Elliot <[email protected]>
- Loading branch information
Showing
8 changed files
with
147 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
(library | ||
(name odoc_occurrences) | ||
(public_name odoc.occurrences) | ||
(libraries odoc_model)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Table = Table | ||
|
||
let of_impl ~include_hidden unit htbl = | ||
let incr tbl p = | ||
let open Odoc_model.Paths.Path.Resolved in | ||
let p = (p :> t) in | ||
let id = identifier p in | ||
if (not (is_hidden p)) || include_hidden then Table.add tbl id | ||
in | ||
let open Odoc_model.Lang in | ||
List.iter | ||
(function | ||
| Source_info.Module { documentation = Some (`Resolved p); _ }, _ -> | ||
incr htbl p | ||
| Value { documentation = Some (`Resolved p); _ }, _ -> incr htbl p | ||
| ModuleType { documentation = Some (`Resolved p); _ }, _ -> incr htbl p | ||
| Type { documentation = Some (`Resolved p); _ }, _ -> incr htbl p | ||
| _ -> ()) | ||
(match unit.Compilation_unit.source_info with | ||
| None -> [] | ||
| Some i -> i.infos) | ||
|
||
let aggregate ~tbl ~data = | ||
Table.iter | ||
(fun id { Table.direct; _ } -> Table.add ~quantity:direct tbl id) | ||
data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
open Odoc_model.Lang | ||
|
||
module Table = Table | ||
|
||
val of_impl : include_hidden:bool -> Compilation_unit.t -> Table.t -> unit | ||
(** Add all occurrences from implementation of a compilation unit into a table *) | ||
|
||
val aggregate : tbl:Table.t -> data:Table.t -> unit | ||
(** Aggregate [data] into [tbl] *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
module H = Hashtbl.Make (Odoc_model.Paths.Identifier) | ||
|
||
type t = item H.t | ||
and item = { direct : int; indirect : int; sub : item H.t } | ||
type key = Odoc_model.Paths.Identifier.t | ||
|
||
let v_item () = { direct = 0; indirect = 0; sub = H.create 0 } | ||
|
||
let v () = H.create 0 | ||
|
||
let add ?(quantity = 1) tbl id = | ||
let rec add ?(kind = `Indirect) id = | ||
let incr htbl id = | ||
let { direct; indirect; sub } = | ||
try H.find htbl id with Not_found -> v_item () | ||
in | ||
let direct, indirect = | ||
match kind with | ||
| `Direct -> (direct + quantity, indirect) | ||
| `Indirect -> (direct, indirect + quantity) | ||
in | ||
H.replace htbl id { direct; indirect; sub }; | ||
sub | ||
in | ||
let do_ parent = | ||
let htbl = add (parent :> key) in | ||
incr htbl id | ||
in | ||
match id.iv with | ||
| `InstanceVariable (parent, _) -> do_ parent | ||
| `Parameter (parent, _) -> do_ parent | ||
| `Module (parent, _) -> do_ parent | ||
| `ModuleType (parent, _) -> do_ parent | ||
| `Method (parent, _) -> do_ parent | ||
| `Field (parent, _) -> do_ parent | ||
| `Extension (parent, _) -> do_ parent | ||
| `Type (parent, _) -> do_ parent | ||
| `CoreType _ -> incr tbl id | ||
| `Constructor (parent, _) -> do_ parent | ||
| `Exception (parent, _) -> do_ parent | ||
| `ExtensionDecl (parent, _, _) -> do_ parent | ||
| `Class (parent, _) -> do_ parent | ||
| `Value (parent, _) -> do_ parent | ||
| `ClassType (parent, _) -> do_ parent | ||
| `Root _ -> incr tbl id | ||
| `SourcePage _ | `Page _ | `LeafPage _ | `SourceLocation _ | ||
| `CoreException _ | `Label _ | `SourceLocationMod _ | `Result _ | ||
| `AssetFile _ | `SourceDir _ | `SourceLocationInternal _ -> | ||
assert false | ||
in | ||
let _htbl = add ~kind:`Direct id in | ||
() | ||
|
||
let rec get t id = | ||
let do_ parent = | ||
get t (parent :> key) |> function | ||
| None -> None | ||
| Some { sub; _ } -> ( try Some (H.find sub id) with Not_found -> None) | ||
in | ||
match id.iv with | ||
| `InstanceVariable (parent, _) -> do_ parent | ||
| `Parameter (parent, _) -> do_ parent | ||
| `Module (parent, _) -> do_ parent | ||
| `ModuleType (parent, _) -> do_ parent | ||
| `Method (parent, _) -> do_ parent | ||
| `Field (parent, _) -> do_ parent | ||
| `Extension (parent, _) -> do_ parent | ||
| `ExtensionDecl (parent, _, _) -> do_ parent | ||
| `Type (parent, _) -> do_ parent | ||
| `Constructor (parent, _) -> do_ parent | ||
| `Exception (parent, _) -> do_ parent | ||
| `Class (parent, _) -> do_ parent | ||
| `Value (parent, _) -> do_ parent | ||
| `ClassType (parent, _) -> do_ parent | ||
| `Root _ -> ( try Some (H.find t id) with Not_found -> None) | ||
| `SourcePage _ | `Page _ | `LeafPage _ | `CoreType _ | `SourceLocation _ | ||
| `CoreException _ | `Label _ | `SourceLocationMod _ | `Result _ | ||
| `AssetFile _ | `SourceDir _ | `SourceLocationInternal _ -> | ||
assert false | ||
|
||
let rec iter f tbl = | ||
H.iter | ||
(fun id v -> | ||
iter f v.sub; | ||
f id v) | ||
tbl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type t | ||
type item = { direct : int; indirect : int; sub : t } | ||
type key = Odoc_model.Paths.Identifier.t | ||
|
||
val v : unit -> t | ||
|
||
val add : ?quantity:int -> t -> key -> unit | ||
|
||
val iter : (key -> item -> unit) -> t -> unit | ||
|
||
val get : t -> key -> item option |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
odoc_model | ||
odoc_json_index | ||
odoc_xref2 | ||
odoc_occurrences | ||
tyxml | ||
unix) | ||
(instrumentation | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters