Skip to content
This repository
branch: norman_faceboo…
Fetching contributors…

Cannot retrieve contributors at this time

file 173 lines (148 sloc) 4.542 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 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
(*
Copyright © 2011, 2012 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/>.
*)
(**
Signatures for [QmlPatternAnalysis]
@author Rudy Sicard
*)

(**
This module contains types and signatures used by [QmlPatternAnalysis].
This module has no mli, to avoid code duplication.
It does not contain any implementation.
*)

(**
A type for indicating if a pattern is complete or not.
{[
| { a ; b }
]}
would be flaged [`closed]
{[
| { a ; b ; ... }
]}
would be flaged [`open_]
*)
type row_flag = [ `open_ | `closed ]

(**
An alias for manipulating record fields
*)
type field = string

(**
The interface of the argument module to the Analysis functor
*)
module type ONIONLANG =
sig
  (** {6 Types} *)

  type ident
  type const
  type ty
  type expr

  (** {6 Mandatory Functions} *)

  (**
Comparison on const type.
Should return -1, 0, or 1
*)
  val compare_const : const -> const -> int

  (**
Generate a new unique ident given a field
and the identifier of the top-level declaration
containing the processed expression

It is possible to return a fresh ident which does not depend on its arguments,
but is could also be interressant to name identifier depending on the context,
for a better debugging.
*)
  val gen_ident : ?ident:ident -> field -> ident

  (**
Take a type, the fields appearing in a non strict record pattern, and returns
all possible set of fields corresponding to possible sum cases,
with a strictness flag ([`closed] means strict which means without [...])
precising if the completed field list is still open.

Some examples:

Example 1)
in this context:
{[
type toto = { a ; b ; c } / { d }
f =
| { a ; b ; ... } : toto ->
| _ ->
]}
a call to:
{[
strictify_record_ty toto [ "a" ; "b" ]
]}
should return:
{[
[ [ "a" ; "b" ; "c" ], `closed ]
]}

Example 2)
in this context:
{[
type toto = { a ; b ; c } / { a ; b ; d }
f =
| { a ; b ; ... } : toto ->
| _ ->
]}
a call to:
{[
strictify_record_ty toto [ "a" ; "b" ]
]}
should return:
{[
[ [ "a" ; "b" ; "c" ], `closed ; [ "a" ; "b" ; "d" ], `closed ]
]}

Example 3)
in this context:
{[
f =
| { a ; b ; ... } ->
]}
a call to:
{[
strictify_record_ty { a ; b ; ... } [ "a" ; "b" ]
]}
should return:
{[
[ [ "a" ; "b" ], `open_ ]
]}

If all flags in the returned list are strict, this will helps pattern to be free
of unstrict sub-patterns.
*)
  val strictify_record_ty : ty -> field list -> ((field list) * row_flag) list

  (**
Indicate if a type is an open disjuntion.
For Qml, this means that the type is a sum type,
with an open column variable.
*)
  val is_open_ty : ty option -> bool

  (**
Given as context a set of field, and a type, return the type of a given field
the set of field is used to select cases for sum types.
This function can assume that the field list used for selecting the case in the sum
leads to an uniq choice in this sum.
*)
  val strict_get_field_type : ty -> field list -> field -> ty

  (**
Get missing constants in a pattern matching, given a list of matched constants.
Hypothesis: the input list in sorted, according the [compare_const] function.
The function is authorized to contain some jokes.
It is used to produce an hint inviting to complete an pattern matching being not exhaustive.
*)
  val get_missing : const list -> const list


  (** {6 Printing} *)
  (**
Used for formulating errors/warnings messages
*)

  val print_id : Format.formatter -> ident -> unit
  val print_ty : Format.formatter -> ty -> unit
  val print_expr : Format.formatter -> expr -> unit
  val print_const : Format.formatter -> const -> unit
end
Something went wrong with that request. Please try again.