Skip to content
This repository
tag: v1853
Fetching contributors…

Cannot retrieve contributors at this time

file 97 lines (76 sloc) 3.03 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
(*
Copyright © 2011 MLstate

This file is part of OPA.

OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.

OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.

You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
(**
Error management constructor for a Language treated by a compiler.

@author Mathieu Barbin
@author Quentin Bourgerie
*)

(* This module has no mli because it would duplicate the module type sig LangContext *)

(** {6 Design note} *)

(**
This module is meant to factorize code to create located error messages, for a
public or an internal audience for any language Lang following the design.

This module uses internally the [passlib] which offers the opportunity to passes
and checkers to be more verbose and outputting a detailed context in the
track system, which can be analyzed after the compilation (or after the last error),
using [opatrack]
*)

module type LangContext =
sig
  (** {6 Context} *)

  (**
The type of the context of the error.

The type context will not be private after the functor application,
we use a context constructor
*)
  type context

  (**
The printer of your context. Print everything possible from the context.
Example: the expr, the toplevel expr in which the expr is, etc...
*)
  val full : context PassHandler.printer

  (**
The reduced printer for the console. Example: only filename, line
*)
  val console : context PassHandler.printer
end


module LangError (C : LangContext) =
struct

  (**
The documentation of theses function is in PassHandler
They have the same names, there are just partially applied
to the context printer.
*)

  (** Checkers *)
  (** *)
  let check_fail c =
    PassHandler.check_fail ~full:C.full ~console:C.console c
  let scheck_fail c =
    PassHandler.scheck_fail ~full:C.full ~console:C.console c

  (* TODO: finish and clarify the role of full/console in public errors *)
  (* Make sure every errors in qml/opa use the corresponding LangError *)

  (** Passes *)
  (** Internal errors *)
  (** *)
  (* overlaying for passes. eta-expanded for ocaml type generalization *)
  let scond_violation c = PassHandler.scond_violation C.full c
  let cond_violation c = PassHandler.cond_violation C.full c
  let i_error c = PassHandler.i_error C.full c
  let i_serror c = PassHandler.i_serror C.full c

  (** Public errors *)
  (** *)
  let error c fmt = OManager.error ("%a"^^fmt) C.console c
  let serror c fmt = OManager.serror ("%a"^^fmt) C.console c
  let warning ~wclass c fmt = OManager.warning ~wclass ("%a"^^fmt) C.console c
end
Something went wrong with that request. Please try again.