1996-11-29 08:55:09 -08:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1996-11-29 08:55:09 -08:00
|
|
|
(* *)
|
|
|
|
(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml port by John Malecki and Xavier Leroy *)
|
1996-11-29 08:55:09 -08:00
|
|
|
(* *)
|
|
|
|
(* Copyright 1996 Institut National de Recherche en Informatique et *)
|
1999-11-17 10:59:06 -08:00
|
|
|
(* en Automatique. All rights reserved. This file is distributed *)
|
|
|
|
(* under the terms of the Q Public License version 1.0. *)
|
1996-11-29 08:55:09 -08:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
open Misc
|
|
|
|
open Path
|
|
|
|
open Instruct
|
1997-01-05 06:04:06 -08:00
|
|
|
open Types
|
|
|
|
open Parser_aux
|
1996-11-29 08:55:09 -08:00
|
|
|
|
1997-01-05 06:04:06 -08:00
|
|
|
type error =
|
|
|
|
Unbound_identifier of Ident.t
|
|
|
|
| Not_initialized_yet of Path.t
|
|
|
|
| Unbound_long_identifier of Longident.t
|
|
|
|
| Unknown_name of int
|
|
|
|
| Tuple_index of type_expr * int * int
|
|
|
|
| Array_index of int * int
|
|
|
|
| List_index of int * int
|
|
|
|
| String_index of string * int * int
|
|
|
|
| Wrong_item_type of type_expr * int
|
|
|
|
| Wrong_label of type_expr * string
|
|
|
|
| Not_a_record of type_expr
|
|
|
|
| No_result
|
|
|
|
|
|
|
|
exception Error of error
|
|
|
|
|
1997-04-01 12:53:38 -08:00
|
|
|
let abstract_type =
|
1998-07-03 10:40:39 -07:00
|
|
|
Btype.newgenty (Tconstr (Pident (Ident.create "<abstr>"), [], ref Mnil))
|
1997-04-01 12:53:38 -08:00
|
|
|
|
1997-01-05 06:04:06 -08:00
|
|
|
let rec path event = function
|
1996-11-29 08:55:09 -08:00
|
|
|
Pident id ->
|
|
|
|
if Ident.global id then
|
2009-05-20 04:52:42 -07:00
|
|
|
try
|
|
|
|
Debugcom.Remote_value.global (Symtable.get_global_position id)
|
|
|
|
with Symtable.Error _ -> raise(Error(Unbound_identifier id))
|
1997-03-25 07:08:47 -08:00
|
|
|
else
|
|
|
|
begin match event with
|
|
|
|
Some ev ->
|
|
|
|
begin try
|
|
|
|
let pos = Ident.find_same id ev.ev_compenv.ce_stack in
|
|
|
|
Debugcom.Remote_value.local (ev.ev_stacksize - pos)
|
|
|
|
with Not_found ->
|
|
|
|
try
|
|
|
|
let pos = Ident.find_same id ev.ev_compenv.ce_heap in
|
1998-08-03 06:51:08 -07:00
|
|
|
Debugcom.Remote_value.from_environment pos
|
1997-03-25 07:08:47 -08:00
|
|
|
with Not_found ->
|
|
|
|
raise(Error(Unbound_identifier id))
|
|
|
|
end
|
|
|
|
| None ->
|
|
|
|
raise(Error(Unbound_identifier id))
|
|
|
|
end
|
1996-11-29 08:55:09 -08:00
|
|
|
| Pdot(root, fieldname, pos) ->
|
1997-01-05 06:04:06 -08:00
|
|
|
let v = path event root in
|
1997-03-22 12:16:52 -08:00
|
|
|
if not (Debugcom.Remote_value.is_block v) then
|
1997-01-05 06:04:06 -08:00
|
|
|
raise(Error(Not_initialized_yet root));
|
1997-03-22 12:16:52 -08:00
|
|
|
Debugcom.Remote_value.field v pos
|
1996-11-29 08:55:09 -08:00
|
|
|
| Papply(p1, p2) ->
|
|
|
|
fatal_error "Eval.path: Papply"
|
1997-01-05 06:04:06 -08:00
|
|
|
|
|
|
|
let rec expression event env = function
|
|
|
|
E_ident lid ->
|
|
|
|
begin try
|
|
|
|
let (p, valdesc) = Env.lookup_value lid env in
|
1997-12-01 09:48:50 -08:00
|
|
|
(begin match valdesc.val_kind with
|
1999-02-22 07:27:46 -08:00
|
|
|
Val_ivar (_, cl_num) ->
|
|
|
|
let (p0, _) =
|
|
|
|
Env.lookup_value (Longident.Lident ("self-" ^ cl_num)) env
|
|
|
|
in
|
1997-12-01 09:48:50 -08:00
|
|
|
let v = path event p0 in
|
|
|
|
let i = path event p in
|
|
|
|
Debugcom.Remote_value.field v (Debugcom.Remote_value.obj i)
|
|
|
|
| _ ->
|
|
|
|
path event p
|
|
|
|
end,
|
|
|
|
Ctype.correct_levels valdesc.val_type)
|
1997-01-05 06:04:06 -08:00
|
|
|
with Not_found ->
|
|
|
|
raise(Error(Unbound_long_identifier lid))
|
|
|
|
end
|
|
|
|
| E_result ->
|
1997-03-25 07:08:47 -08:00
|
|
|
begin match event with
|
2013-03-22 11:18:26 -07:00
|
|
|
Some {ev_kind = Event_after ty; ev_typsubst = subst}
|
|
|
|
when !Frames.current_frame = 0 ->
|
2009-05-20 04:52:42 -07:00
|
|
|
(Debugcom.Remote_value.accu(), Subst.type_expr subst ty)
|
1997-03-13 14:32:10 -08:00
|
|
|
| _ ->
|
|
|
|
raise(Error(No_result))
|
1997-01-05 06:04:06 -08:00
|
|
|
end
|
|
|
|
| E_name n ->
|
|
|
|
begin try
|
|
|
|
Printval.find_named_value n
|
|
|
|
with Not_found ->
|
|
|
|
raise(Error(Unknown_name n))
|
|
|
|
end
|
|
|
|
| E_item(arg, n) ->
|
|
|
|
let (v, ty) = expression event env arg in
|
2007-11-28 14:32:14 -08:00
|
|
|
begin match (Ctype.repr(Ctype.expand_head_opt env ty)).desc with
|
1997-01-05 06:04:06 -08:00
|
|
|
Ttuple ty_list ->
|
|
|
|
if n < 1 || n > List.length ty_list
|
|
|
|
then raise(Error(Tuple_index(ty, List.length ty_list, n)))
|
1997-03-22 12:16:52 -08:00
|
|
|
else (Debugcom.Remote_value.field v (n-1), List.nth ty_list (n-1))
|
1997-01-05 06:04:06 -08:00
|
|
|
| Tconstr(path, [ty_arg], _) when Path.same path Predef.path_array ->
|
1997-03-22 12:16:52 -08:00
|
|
|
let size = Debugcom.Remote_value.size v in
|
1997-01-05 06:04:06 -08:00
|
|
|
if n >= size
|
|
|
|
then raise(Error(Array_index(size, n)))
|
1997-03-22 12:16:52 -08:00
|
|
|
else (Debugcom.Remote_value.field v n, ty_arg)
|
1997-01-05 06:04:06 -08:00
|
|
|
| Tconstr(path, [ty_arg], _) when Path.same path Predef.path_list ->
|
|
|
|
let rec nth pos v =
|
1997-03-22 12:16:52 -08:00
|
|
|
if not (Debugcom.Remote_value.is_block v) then
|
1997-01-05 06:04:06 -08:00
|
|
|
raise(Error(List_index(pos, n)))
|
|
|
|
else if pos = n then
|
1997-03-22 12:16:52 -08:00
|
|
|
(Debugcom.Remote_value.field v 0, ty_arg)
|
1997-01-05 06:04:06 -08:00
|
|
|
else
|
1997-03-22 12:16:52 -08:00
|
|
|
nth (pos + 1) (Debugcom.Remote_value.field v 1)
|
1997-01-05 06:04:06 -08:00
|
|
|
in nth 0 v
|
|
|
|
| Tconstr(path, [], _) when Path.same path Predef.path_string ->
|
1997-03-22 12:16:52 -08:00
|
|
|
let s = (Debugcom.Remote_value.obj v : string) in
|
1997-01-05 06:04:06 -08:00
|
|
|
if n >= String.length s
|
|
|
|
then raise(Error(String_index(s, String.length s, n)))
|
1997-03-22 12:16:52 -08:00
|
|
|
else (Debugcom.Remote_value.of_int(Char.code s.[n]),
|
|
|
|
Predef.type_char)
|
1997-01-05 06:04:06 -08:00
|
|
|
| _ ->
|
|
|
|
raise(Error(Wrong_item_type(ty, n)))
|
|
|
|
end
|
|
|
|
| E_field(arg, lbl) ->
|
|
|
|
let (v, ty) = expression event env arg in
|
2007-11-28 14:32:14 -08:00
|
|
|
begin match (Ctype.repr(Ctype.expand_head_opt env ty)).desc with
|
1997-01-05 06:04:06 -08:00
|
|
|
Tconstr(path, args, _) ->
|
|
|
|
let tydesc = Env.find_type path env in
|
|
|
|
begin match tydesc.type_kind with
|
2007-10-09 03:29:37 -07:00
|
|
|
Type_record(lbl_list, repr) ->
|
1997-01-05 06:04:06 -08:00
|
|
|
let (pos, ty_res) =
|
|
|
|
find_label lbl env ty path tydesc 0 lbl_list in
|
1997-03-22 12:16:52 -08:00
|
|
|
(Debugcom.Remote_value.field v pos, ty_res)
|
1997-01-05 06:04:06 -08:00
|
|
|
| _ -> raise(Error(Not_a_record ty))
|
|
|
|
end
|
|
|
|
| _ -> raise(Error(Not_a_record ty))
|
|
|
|
end
|
|
|
|
|
|
|
|
and find_label lbl env ty path tydesc pos = function
|
|
|
|
[] ->
|
|
|
|
raise(Error(Wrong_label(ty, lbl)))
|
|
|
|
| (name, mut, ty_arg) :: rem ->
|
2012-05-30 07:52:37 -07:00
|
|
|
if Ident.name name = lbl then begin
|
1997-03-13 13:20:13 -08:00
|
|
|
let ty_res =
|
1998-07-03 10:40:39 -07:00
|
|
|
Btype.newgenty(Tconstr(path, tydesc.type_params, ref Mnil))
|
1997-03-13 13:20:13 -08:00
|
|
|
in
|
1997-04-01 12:53:38 -08:00
|
|
|
(pos,
|
|
|
|
try Ctype.apply env [ty_res] ty_arg [ty] with Ctype.Cannot_apply ->
|
|
|
|
abstract_type)
|
1997-01-05 06:04:06 -08:00
|
|
|
end else
|
1997-03-13 13:20:13 -08:00
|
|
|
find_label lbl env ty path tydesc (pos + 1) rem
|
1997-01-05 06:04:06 -08:00
|
|
|
|
|
|
|
(* Error report *)
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
open Format
|
1997-01-05 06:04:06 -08:00
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let report_error ppf = function
|
|
|
|
| Unbound_identifier id ->
|
|
|
|
fprintf ppf "@[Unbound identifier %s@]@." (Ident.name id)
|
1997-01-05 06:04:06 -08:00
|
|
|
| Not_initialized_yet path ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf
|
|
|
|
"@[The module path %a is not yet initialized.@ \
|
|
|
|
Please run program forward@ \
|
|
|
|
until its initialization code is executed.@]@."
|
|
|
|
Printtyp.path path
|
1997-01-05 06:04:06 -08:00
|
|
|
| Unbound_long_identifier lid ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "@[Unbound identifier %a@]@." Printtyp.longident lid
|
1997-01-05 06:04:06 -08:00
|
|
|
| Unknown_name n ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "@[Unknown value name $%i@]@." n
|
1997-01-05 06:04:06 -08:00
|
|
|
| Tuple_index(ty, len, pos) ->
|
2000-03-06 14:12:09 -08:00
|
|
|
Printtyp.reset_and_mark_loops ty;
|
|
|
|
fprintf ppf
|
2009-05-20 04:52:42 -07:00
|
|
|
"@[Cannot extract field number %i from a %i-tuple of type@ %a@]@."
|
2000-03-06 14:12:09 -08:00
|
|
|
pos len Printtyp.type_expr ty
|
1997-01-05 06:04:06 -08:00
|
|
|
| Array_index(len, pos) ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf
|
2013-03-22 11:18:26 -07:00
|
|
|
"@[Cannot extract element number %i from an array of length %i@]@."
|
|
|
|
pos len
|
1997-01-05 06:04:06 -08:00
|
|
|
| List_index(len, pos) ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf
|
2013-03-22 11:18:26 -07:00
|
|
|
"@[Cannot extract element number %i from a list of length %i@]@."
|
|
|
|
pos len
|
1997-01-05 06:04:06 -08:00
|
|
|
| String_index(s, len, pos) ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf
|
|
|
|
"@[Cannot extract character number %i@ \
|
2002-06-27 10:25:11 -07:00
|
|
|
from the following string of length %i:@ %S@]@."
|
|
|
|
pos len s
|
1997-01-05 06:04:06 -08:00
|
|
|
| Wrong_item_type(ty, pos) ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf
|
|
|
|
"@[Cannot extract item number %i from a value of type@ %a@]@."
|
|
|
|
pos Printtyp.type_expr ty
|
1997-01-05 06:04:06 -08:00
|
|
|
| Wrong_label(ty, lbl) ->
|
2010-01-22 04:48:24 -08:00
|
|
|
fprintf ppf
|
2000-03-06 14:12:09 -08:00
|
|
|
"@[The record type@ %a@ has no label named %s@]@."
|
|
|
|
Printtyp.type_expr ty lbl
|
1997-01-05 06:04:06 -08:00
|
|
|
| Not_a_record ty ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf
|
|
|
|
"@[The type@ %a@ is not a record type@]@." Printtyp.type_expr ty
|
1997-01-05 06:04:06 -08:00
|
|
|
| No_result ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "@[No result available at current program event@]@."
|