Sys.Signals module for a Variant type of signals (and a set_signal function that...
[ocaml.git] / typing / path.ml
blob88f9aa5748b4e100dc880b4317271897369220fd
1 (***********************************************************************)
2 (* *)
3 (* Objective Caml *)
4 (* *)
5 (* Xavier Leroy, projet Cristal, INRIA Rocquencourt *)
6 (* *)
7 (* Copyright 1996 Institut National de Recherche en Informatique et *)
8 (* en Automatique. All rights reserved. This file is distributed *)
9 (* under the terms of the Q Public License version 1.0. *)
10 (* *)
11 (***********************************************************************)
13 (* $Id$ *)
15 type t =
16 Pident of Ident.t
17 | Pdot of t * string * int
18 | Papply of t * t
20 let nopos = -1
22 let rec same p1 p2 =
23 match (p1, p2) with
24 (Pident id1, Pident id2) -> Ident.same id1 id2
25 | (Pdot(p1, s1, pos1), Pdot(p2, s2, pos2)) -> s1 = s2 && same p1 p2
26 | (Papply(fun1, arg1), Papply(fun2, arg2)) ->
27 same fun1 fun2 && same arg1 arg2
28 | (_, _) -> false
30 let rec isfree id = function
31 Pident id' -> Ident.same id id'
32 | Pdot(p, s, pos) -> isfree id p
33 | Papply(p1, p2) -> isfree id p1 || isfree id p2
35 let rec binding_time = function
36 Pident id -> Ident.binding_time id
37 | Pdot(p, s, pos) -> binding_time p
38 | Papply(p1, p2) -> max (binding_time p1) (binding_time p2)
40 let rec name = function
41 Pident id -> Ident.name id
42 | Pdot(p, s, pos) -> name p ^ "." ^ s
43 | Papply(p1, p2) -> name p1 ^ "(" ^ name p2 ^ ")"
45 let rec head = function
46 Pident id -> id
47 | Pdot(p, s, pos) -> head p
48 | Papply(p1, p2) -> assert false