2016-09-08 21:13:10 +04:00
|
|
|
(**************************************************************************)
|
|
|
|
(* *)
|
2017-11-14 03:36:14 +04:00
|
|
|
(* Copyright (c) 2014 - 2017. *)
|
2016-09-08 21:13:10 +04:00
|
|
|
(* Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)
|
|
|
|
(* *)
|
|
|
|
(* All rights reserved. No warranty, explicit or implicit, provided. *)
|
|
|
|
(* *)
|
|
|
|
(**************************************************************************)
|
|
|
|
|
2017-11-27 09:13:12 +04:00
|
|
|
open Tezos_micheline
|
|
|
|
|
2017-11-02 21:57:17 +04:00
|
|
|
type point = Micheline_parser.point =
|
2017-06-15 01:35:24 +04:00
|
|
|
{ point : int ;
|
|
|
|
byte : int ;
|
|
|
|
line : int ;
|
|
|
|
column : int }
|
|
|
|
|
2017-11-02 21:57:17 +04:00
|
|
|
let point_zero = Micheline_parser.point_zero
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-11-02 21:57:17 +04:00
|
|
|
type location = Micheline_parser.location =
|
2017-06-15 01:35:24 +04:00
|
|
|
{ start : point ;
|
|
|
|
stop : point }
|
2016-09-08 21:13:10 +04:00
|
|
|
|
2017-07-22 02:37:33 +04:00
|
|
|
let location_encoding =
|
|
|
|
let open Data_encoding in
|
|
|
|
let point_encoding =
|
|
|
|
conv
|
2017-06-15 01:35:24 +04:00
|
|
|
(fun { line ; column ; point ; byte } -> (line, column, point, byte))
|
|
|
|
(fun (line, column, point, byte) -> { line ; column ; point ; byte })
|
|
|
|
(obj4
|
2017-07-22 02:37:33 +04:00
|
|
|
(req "line" uint16)
|
|
|
|
(req "column" uint16)
|
2017-06-15 01:35:24 +04:00
|
|
|
(req "point" uint16)
|
|
|
|
(req "byte" uint16)) in
|
|
|
|
conv
|
|
|
|
(fun { start ; stop } -> (start, stop))
|
|
|
|
(fun (start, stop) -> { start ; stop })
|
|
|
|
(obj2
|
|
|
|
(req "start" point_encoding)
|
|
|
|
(req "stop" point_encoding))
|
2017-07-22 02:37:33 +04:00
|
|
|
|
2017-11-02 21:57:17 +04:00
|
|
|
type node = (location, string) Micheline.node
|
|
|
|
|
|
|
|
open Micheline
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let node_location = function
|
|
|
|
| Int (loc, _)
|
|
|
|
| String (loc, _)
|
2017-06-15 01:35:24 +04:00
|
|
|
| Prim (loc, _, _, _)
|
|
|
|
| Seq (loc, _, _) -> loc
|
2016-09-08 21:13:10 +04:00
|
|
|
|
|
|
|
let strip_locations root =
|
2017-06-15 01:35:24 +04:00
|
|
|
let id = let id = ref (-1) in fun () -> incr id ; !id in
|
2017-07-22 02:37:33 +04:00
|
|
|
let loc_table = ref [] in
|
2016-09-08 21:13:10 +04:00
|
|
|
let rec strip_locations l =
|
|
|
|
let id = id () in
|
|
|
|
match l with
|
2017-07-22 02:37:33 +04:00
|
|
|
| Int (loc, v) ->
|
|
|
|
loc_table := (id, loc) :: !loc_table ;
|
2017-11-02 21:57:17 +04:00
|
|
|
Int (id, v)
|
2017-07-22 02:37:33 +04:00
|
|
|
| String (loc, v) ->
|
|
|
|
loc_table := (id, loc) :: !loc_table ;
|
2017-11-02 21:57:17 +04:00
|
|
|
String (id, v)
|
2017-06-15 01:35:24 +04:00
|
|
|
| Seq (loc, seq, annot) ->
|
2017-07-22 02:37:33 +04:00
|
|
|
loc_table := (id, loc) :: !loc_table ;
|
2017-11-02 21:57:17 +04:00
|
|
|
Seq (id, List.map strip_locations seq, annot)
|
2017-06-15 01:35:24 +04:00
|
|
|
| Prim (loc, name, seq, annot) ->
|
2017-07-22 02:37:33 +04:00
|
|
|
loc_table := (id, loc) :: !loc_table ;
|
2017-11-02 21:57:17 +04:00
|
|
|
Prim (id, name, List.map strip_locations seq, annot) in
|
2017-07-22 02:37:33 +04:00
|
|
|
let stripped = strip_locations root in
|
|
|
|
stripped, List.rev !loc_table
|
2017-06-15 01:35:24 +04:00
|
|
|
|
|
|
|
exception Missing_program_field of string
|