1995-08-09 08:06:35 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
1996-04-30 07:53:58 -07: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. *)
|
1995-08-09 08:06:35 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
1995-05-04 03:15:53 -07:00
|
|
|
type t =
|
|
|
|
Pident of Ident.t
|
|
|
|
| Pdot of t * string * int
|
1995-08-23 04:55:54 -07:00
|
|
|
| Papply of t * t
|
1995-05-04 03:15:53 -07:00
|
|
|
|
|
|
|
let nopos = -1
|
|
|
|
|
|
|
|
let rec same p1 p2 =
|
|
|
|
match (p1, p2) with
|
|
|
|
(Pident id1, Pident id2) -> Ident.same id1 id2
|
2000-12-28 05:07:42 -08:00
|
|
|
| (Pdot(p1, s1, pos1), Pdot(p2, s2, pos2)) -> s1 = s2 && same p1 p2
|
|
|
|
| (Papply(fun1, arg1), Papply(fun2, arg2)) ->
|
|
|
|
same fun1 fun2 && same arg1 arg2
|
1995-05-04 03:15:53 -07:00
|
|
|
| (_, _) -> false
|
|
|
|
|
1995-08-23 04:55:54 -07:00
|
|
|
let rec isfree id = function
|
|
|
|
Pident id' -> Ident.same id id'
|
|
|
|
| Pdot(p, s, pos) -> isfree id p
|
2000-12-28 05:07:42 -08:00
|
|
|
| Papply(p1, p2) -> isfree id p1 || isfree id p2
|
1996-07-15 09:35:35 -07:00
|
|
|
|
|
|
|
let rec binding_time = function
|
|
|
|
Pident id -> Ident.binding_time id
|
|
|
|
| Pdot(p, s, pos) -> binding_time p
|
|
|
|
| Papply(p1, p2) -> max (binding_time p1) (binding_time p2)
|
1998-06-23 03:06:50 -07:00
|
|
|
|
2010-11-11 19:09:11 -08:00
|
|
|
let kfalse x = false
|
|
|
|
|
|
|
|
let rec name ?(paren=kfalse) = function
|
1998-06-23 03:06:50 -07:00
|
|
|
Pident id -> Ident.name id
|
2010-11-14 20:32:21 -08:00
|
|
|
| Pdot(p, s, pos) ->
|
|
|
|
name ~paren p ^ if paren s then ".( " ^ s ^ " )" else "." ^ s
|
2010-11-11 19:09:11 -08:00
|
|
|
| Papply(p1, p2) -> name ~paren p1 ^ "(" ^ name ~paren p2 ^ ")"
|
2003-07-01 06:05:43 -07:00
|
|
|
|
|
|
|
let rec head = function
|
|
|
|
Pident id -> id
|
|
|
|
| Pdot(p, s, pos) -> head p
|
|
|
|
| Papply(p1, p2) -> assert false
|
2012-01-12 01:16:26 -08:00
|
|
|
|
|
|
|
let rec last = function
|
|
|
|
| Pident id -> Ident.name id
|
|
|
|
| Pdot(_, s, _) -> s
|
|
|
|
| Papply(_, p) -> last p
|
2014-10-14 08:51:30 -07:00
|
|
|
|
|
|
|
let is_uident s =
|
|
|
|
assert (s <> "");
|
|
|
|
match s.[0] with
|
|
|
|
| 'A'..'Z' -> true
|
|
|
|
| _ -> false
|
|
|
|
|
|
|
|
type typath =
|
|
|
|
| Regular of t
|
|
|
|
| Ext of t * string
|
|
|
|
| LocalExt of Ident.t
|
|
|
|
| Cstr of t * string
|
|
|
|
|
|
|
|
let constructor_typath = function
|
|
|
|
| Pident id when is_uident (Ident.name id) -> LocalExt id
|
|
|
|
| Pdot(ty_path, s, _) when is_uident s ->
|
|
|
|
if is_uident (last ty_path) then Ext (ty_path, s)
|
|
|
|
else Cstr (ty_path, s)
|
|
|
|
| p -> Regular p
|
|
|
|
|
|
|
|
let is_constructor_typath p =
|
|
|
|
match constructor_typath p with
|
|
|
|
| Regular _ -> false
|
|
|
|
| _ -> true
|