1998-06-25 06:14:07 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
2011-07-27 07:17:02 -07:00
|
|
|
(* OCaml *)
|
1998-06-25 06:14:07 -07:00
|
|
|
(* *)
|
|
|
|
(* Jerome Vouillon, projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1997 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. *)
|
1998-06-25 06:14:07 -07:00
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
(* Inclusion checks for the class language *)
|
|
|
|
|
|
|
|
open Types
|
|
|
|
|
|
|
|
let class_types env cty1 cty2 =
|
|
|
|
Ctype.match_class_types env cty1 cty2
|
|
|
|
|
|
|
|
let class_type_declarations env cty1 cty2 =
|
|
|
|
Ctype.match_class_declarations env
|
|
|
|
cty1.clty_params cty1.clty_type
|
|
|
|
cty2.clty_params cty2.clty_type
|
|
|
|
|
|
|
|
let class_declarations env cty1 cty2 =
|
|
|
|
match cty1.cty_new, cty2.cty_new with
|
|
|
|
None, Some _ ->
|
|
|
|
[Ctype.CM_Virtual_class]
|
|
|
|
| _ ->
|
|
|
|
Ctype.match_class_declarations env
|
|
|
|
cty1.cty_params cty1.cty_type
|
|
|
|
cty2.cty_params cty2.cty_type
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
open Format
|
1998-06-25 06:14:07 -07:00
|
|
|
open Ctype
|
|
|
|
|
2010-08-02 07:37:22 -07:00
|
|
|
(*
|
|
|
|
let rec hide_params = function
|
|
|
|
Tcty_fun ("*", _, cty) -> hide_params cty
|
|
|
|
| cty -> cty
|
|
|
|
*)
|
|
|
|
|
2000-03-06 14:12:09 -08:00
|
|
|
let include_err ppf =
|
1998-06-25 06:14:07 -07:00
|
|
|
function
|
2000-03-06 14:12:09 -08:00
|
|
|
| CM_Virtual_class ->
|
|
|
|
fprintf ppf "A class cannot be changed from virtual to concrete"
|
1998-06-25 06:14:07 -07:00
|
|
|
| CM_Parameter_arity_mismatch (ls, lp) ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf
|
2010-01-22 04:48:24 -08:00
|
|
|
"The classes do not have the same number of type parameters"
|
2012-01-22 23:59:45 -08:00
|
|
|
| CM_Type_parameter_mismatch (env, trace) ->
|
2013-01-29 06:21:12 -08:00
|
|
|
Printtyp.report_unification_error ppf env ~unif:false trace
|
2000-03-06 14:12:09 -08:00
|
|
|
(function ppf ->
|
2012-01-22 23:59:45 -08:00
|
|
|
fprintf ppf "A type parameter has type")
|
2000-03-06 14:12:09 -08:00
|
|
|
(function ppf ->
|
|
|
|
fprintf ppf "but is expected to have type")
|
2012-01-22 23:59:45 -08:00
|
|
|
| CM_Class_type_mismatch (env, cty1, cty2) ->
|
|
|
|
Printtyp.wrap_printing_env env (fun () ->
|
|
|
|
fprintf ppf
|
|
|
|
"@[The class type@;<1 2>%a@ %s@;<1 2>%a@]"
|
|
|
|
Printtyp.class_type cty1
|
|
|
|
"is not matched by the class type"
|
|
|
|
Printtyp.class_type cty2)
|
|
|
|
| CM_Parameter_mismatch (env, trace) ->
|
2013-01-29 06:21:12 -08:00
|
|
|
Printtyp.report_unification_error ppf env ~unif:false trace
|
2000-03-06 14:12:09 -08:00
|
|
|
(function ppf ->
|
2012-01-22 23:59:45 -08:00
|
|
|
fprintf ppf "A parameter has type")
|
2000-03-06 14:12:09 -08:00
|
|
|
(function ppf ->
|
|
|
|
fprintf ppf "but is expected to have type")
|
2012-01-22 23:59:45 -08:00
|
|
|
| CM_Val_type_mismatch (lab, env, trace) ->
|
2013-01-29 06:21:12 -08:00
|
|
|
Printtyp.report_unification_error ppf env ~unif:false trace
|
2000-03-06 14:12:09 -08:00
|
|
|
(function ppf ->
|
2012-01-22 23:59:45 -08:00
|
|
|
fprintf ppf "The instance variable %s@ has type" lab)
|
2000-03-06 14:12:09 -08:00
|
|
|
(function ppf ->
|
|
|
|
fprintf ppf "but is expected to have type")
|
2012-01-22 23:59:45 -08:00
|
|
|
| CM_Meth_type_mismatch (lab, env, trace) ->
|
2013-01-29 06:21:12 -08:00
|
|
|
Printtyp.report_unification_error ppf env ~unif:false trace
|
2000-03-06 14:12:09 -08:00
|
|
|
(function ppf ->
|
2012-01-22 23:59:45 -08:00
|
|
|
fprintf ppf "The method %s@ has type" lab)
|
2000-03-06 14:12:09 -08:00
|
|
|
(function ppf ->
|
|
|
|
fprintf ppf "but is expected to have type")
|
1998-06-25 06:14:07 -07:00
|
|
|
| CM_Non_mutable_value lab ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf
|
|
|
|
"@[The non-mutable instance variable %s cannot become mutable@]" lab
|
2006-04-04 19:28:13 -07:00
|
|
|
| CM_Non_concrete_value lab ->
|
|
|
|
fprintf ppf
|
|
|
|
"@[The virtual instance variable %s cannot become concrete@]" lab
|
1998-06-25 06:14:07 -07:00
|
|
|
| CM_Missing_value lab ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "@[The first class type has no instance variable %s@]" lab
|
1998-06-25 06:14:07 -07:00
|
|
|
| CM_Missing_method lab ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "@[The first class type has no method %s@]" lab
|
1998-06-25 06:14:07 -07:00
|
|
|
| CM_Hide_public lab ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "@[The public method %s cannot be hidden@]" lab
|
2006-04-04 19:28:13 -07:00
|
|
|
| CM_Hide_virtual (k, lab) ->
|
|
|
|
fprintf ppf "@[The virtual %s %s cannot be hidden@]" k lab
|
1998-06-25 06:14:07 -07:00
|
|
|
| CM_Public_method lab ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "@[The public method %s cannot become private" lab
|
1998-06-25 06:14:07 -07:00
|
|
|
| CM_Virtual_method lab ->
|
2009-05-20 04:52:42 -07:00
|
|
|
fprintf ppf "@[The virtual method %s cannot become concrete" lab
|
1998-06-25 10:15:29 -07:00
|
|
|
| CM_Private_method lab ->
|
2000-03-06 14:12:09 -08:00
|
|
|
fprintf ppf "The private method %s cannot become public" lab
|
|
|
|
|
|
|
|
let report_error ppf = function
|
|
|
|
| [] -> ()
|
|
|
|
| err :: errs ->
|
|
|
|
let print_errs ppf errs =
|
|
|
|
List.iter (fun err -> fprintf ppf "@ %a" include_err err) errs in
|
|
|
|
fprintf ppf "@[<v>%a%a@]" include_err err print_errs errs
|