Commit 25b1f37d authored by POTTIER Francois's avatar POTTIER Francois

Cleanup.

Removed the old [production_defs].
Renamed [production_defs2] to [rhs].
parent 3d3c7d9f
......@@ -576,6 +576,9 @@ module Production = struct
let map f =
Misc.mapi n f
let amap f =
Array.init n f
let iterx f =
for prod = start to n - 1 do
f prod
......
......@@ -294,6 +294,7 @@ module Production : sig
val iter: (index -> unit) -> unit
val fold: (index -> 'a -> 'a) -> 'a -> 'a
val map: (index -> 'a) -> 'a list
val amap: (index -> 'a) -> 'a array
(* Iteration over all productions, except the start productions. *)
......
......@@ -415,6 +415,13 @@ let marshal11 (table : int array) =
assert (bits = 1);
EStringConst text
(* [linearize_and_marshal1] marshals an array of integer arrays (of possibly
different lengths). *)
let linearize_and_marshal1 (table : int array array) =
let data, entry = MenhirLib.LinearizedArray.make table in
ETuple [ marshal1 data; marshal1 entry ]
(* [marshal2] marshals a two-dimensional table. *)
let marshal2 name m n (matrix : int list list) =
......@@ -875,43 +882,24 @@ let incoming_symbol_def () =
(* ------------------------------------------------------------------------ *)
(* A table that maps a production (i.e., an integer index) to its definition
(i.e., its right-hand side). In principle, we use this table only for
ordinary productions, as opposed to the start productions, whose existence
is not exposed to the user. However, it is simpler (and not costly) to
include all productions in this table. *)
let production_def prod =
elist (
(* The production's right-hand side. This is a list of symbols. *)
List.map xsymbol (Array.to_list (Production.rhs prod))
)
(* A table that maps a production (i.e., an integer index) to the production's
right-hand side. In principle, we use this table for ordinary productions
only, as opposed to the start productions, whose existence is not exposed
to the user. However, it is simpler (and not really costly) to include all
productions in this table. *)
let production_defs () =
let rhs () =
assert Settings.inspection;
define_and_measure (
"production_defs",
EArray (Production.map production_def)
)
let production_defs2 () =
assert Settings.inspection;
let productions : int list list = Production.map (fun prod ->
List.map encode_symbol (Array.to_list (Production.rhs prod))
) in
let productions : int array array =
Array.of_list (List.map Array.of_list productions)
in
let productions : int MenhirLib.LinearizedArray.t =
MenhirLib.LinearizedArray.make productions
Production.amap (fun prod ->
Array.map encode_symbol (Production.rhs prod)
)
in
let (data, entry) = productions in
define_and_measure (
"production_defs2",
ETuple [ marshal1 (Array.to_list data); marshal1 (Array.to_list entry) ]
"rhs",
linearize_and_marshal1 productions
)
(* ------------------------------------------------------------------------ *)
(* A table that maps an LR(1) state to its LR(0) core. *)
......@@ -1048,8 +1036,7 @@ let program =
) ::
SIValDefs (false,
incoming_symbol_def() ::
production_defs() ::
production_defs2() ::
rhs() ::
lr0_core() ::
lr0_items() ::
[]
......
......@@ -136,12 +136,12 @@ module type INSPECTION_TABLES = sig
val symbol: 'a lr1state -> 'a symbol
(* The definition (i.e. left-hand side and right-hand side) of every
(non-start) production. *)
(* The right-hand side of every production. This a linearized array
of arrays of integers, whose [data] and [entry] components have
been packed. The encoding of symbols as integers in described in
[TableBackend]. *)
val production_defs: xsymbol list array
val production_defs2: PackedIntArray.t * PackedIntArray.t
(* packed linearized array *)
val rhs: PackedIntArray.t * PackedIntArray.t
(* A mapping of every (non-initial) state to its LR(0) core. *)
......
......@@ -182,8 +182,8 @@ module MakeInspection (T : TableFormat.INSPECTION_TABLES) = struct
let kind = symbol land 1 in
(if kind = 0 then T.terminal else T.nonterminal) (symbol lsr 1)
let rhs2 prod =
let (data, entry) = T.production_defs2 in
let rhs prod =
let (data, entry) = T.rhs in
let rhs : int list =
LinearizedArray.read_row_via
(PackedIntArray.get data)
......@@ -192,12 +192,6 @@ module MakeInspection (T : TableFormat.INSPECTION_TABLES) = struct
in
List.map decode_symbol rhs
let rhs prod =
let answer1 : T.xsymbol list = rhs2 prod in
let answer2 : T.xsymbol list = T.production_defs.(prod) in
assert (Printf.fprintf stderr "I AM HERE\n%!"; answer1 = answer2);
answer2
(* This is a copy of [Item.export]. *)
let export t =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment