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 ...@@ -576,6 +576,9 @@ module Production = struct
let map f = let map f =
Misc.mapi n f Misc.mapi n f
let amap f =
Array.init n f
let iterx f = let iterx f =
for prod = start to n - 1 do for prod = start to n - 1 do
f prod f prod
......
...@@ -294,6 +294,7 @@ module Production : sig ...@@ -294,6 +294,7 @@ module Production : sig
val iter: (index -> unit) -> unit val iter: (index -> unit) -> unit
val fold: (index -> 'a -> 'a) -> 'a -> 'a val fold: (index -> 'a -> 'a) -> 'a -> 'a
val map: (index -> 'a) -> 'a list val map: (index -> 'a) -> 'a list
val amap: (index -> 'a) -> 'a array
(* Iteration over all productions, except the start productions. *) (* Iteration over all productions, except the start productions. *)
......
...@@ -415,6 +415,13 @@ let marshal11 (table : int array) = ...@@ -415,6 +415,13 @@ let marshal11 (table : int array) =
assert (bits = 1); assert (bits = 1);
EStringConst text 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. *) (* [marshal2] marshals a two-dimensional table. *)
let marshal2 name m n (matrix : int list list) = let marshal2 name m n (matrix : int list list) =
...@@ -875,43 +882,24 @@ let incoming_symbol_def () = ...@@ -875,43 +882,24 @@ let incoming_symbol_def () =
(* ------------------------------------------------------------------------ *) (* ------------------------------------------------------------------------ *)
(* A table that maps a production (i.e., an integer index) to its definition (* A table that maps a production (i.e., an integer index) to the production's
(i.e., its right-hand side). In principle, we use this table only for right-hand side. In principle, we use this table for ordinary productions
ordinary productions, as opposed to the start productions, whose existence only, as opposed to the start productions, whose existence is not exposed
is not exposed to the user. However, it is simpler (and not costly) to to the user. However, it is simpler (and not really costly) to include all
include all productions in this table. *) 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))
)
let production_defs () = let rhs () =
assert Settings.inspection; 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 = let productions : int array array =
Array.of_list (List.map Array.of_list productions) Production.amap (fun prod ->
in Array.map encode_symbol (Production.rhs prod)
let productions : int MenhirLib.LinearizedArray.t = )
MenhirLib.LinearizedArray.make productions
in in
let (data, entry) = productions in
define_and_measure ( define_and_measure (
"production_defs2", "rhs",
ETuple [ marshal1 (Array.to_list data); marshal1 (Array.to_list entry) ] linearize_and_marshal1 productions
) )
(* ------------------------------------------------------------------------ *) (* ------------------------------------------------------------------------ *)
(* A table that maps an LR(1) state to its LR(0) core. *) (* A table that maps an LR(1) state to its LR(0) core. *)
...@@ -1048,8 +1036,7 @@ let program = ...@@ -1048,8 +1036,7 @@ let program =
) :: ) ::
SIValDefs (false, SIValDefs (false,
incoming_symbol_def() :: incoming_symbol_def() ::
production_defs() :: rhs() ::
production_defs2() ::
lr0_core() :: lr0_core() ::
lr0_items() :: lr0_items() ::
[] []
......
...@@ -136,12 +136,12 @@ module type INSPECTION_TABLES = sig ...@@ -136,12 +136,12 @@ module type INSPECTION_TABLES = sig
val symbol: 'a lr1state -> 'a symbol val symbol: 'a lr1state -> 'a symbol
(* The definition (i.e. left-hand side and right-hand side) of every (* The right-hand side of every production. This a linearized array
(non-start) production. *) 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 rhs: PackedIntArray.t * PackedIntArray.t
val production_defs2: PackedIntArray.t * PackedIntArray.t
(* packed linearized array *)
(* A mapping of every (non-initial) state to its LR(0) core. *) (* A mapping of every (non-initial) state to its LR(0) core. *)
......
...@@ -182,8 +182,8 @@ module MakeInspection (T : TableFormat.INSPECTION_TABLES) = struct ...@@ -182,8 +182,8 @@ module MakeInspection (T : TableFormat.INSPECTION_TABLES) = struct
let kind = symbol land 1 in let kind = symbol land 1 in
(if kind = 0 then T.terminal else T.nonterminal) (symbol lsr 1) (if kind = 0 then T.terminal else T.nonterminal) (symbol lsr 1)
let rhs2 prod = let rhs prod =
let (data, entry) = T.production_defs2 in let (data, entry) = T.rhs in
let rhs : int list = let rhs : int list =
LinearizedArray.read_row_via LinearizedArray.read_row_via
(PackedIntArray.get data) (PackedIntArray.get data)
...@@ -192,12 +192,6 @@ module MakeInspection (T : TableFormat.INSPECTION_TABLES) = struct ...@@ -192,12 +192,6 @@ module MakeInspection (T : TableFormat.INSPECTION_TABLES) = struct
in in
List.map decode_symbol rhs 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]. *) (* This is a copy of [Item.export]. *)
let export t = 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