Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 123 lines (98 sloc) 4.383 kB
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18
19 (**
20 This file contains all the possible cases of Exception possibly returned by
21 any Typer.
22 If you want to add an exception, do it here, and provide the to_string which
23 goes together.
24 Remember that this file is the interface between the typer - guys and the
25 user.
26
27 This module has no mli because it would duplicate the definition of the
28 type t.
29 *)
30
31
32 (* TODO: this almost the same as QmlError.location; use QmlError and refactor*)
33 type location =
34 [`Expr_loc of QmlAst.expr
35 |`Pat_loc of QmlAst.pat
36 |`Ty_loc of QmlAst.ty
37 |`No_loc]
38
39 module LocSet : (BaseSetSig.S with type elt = location)
40 = BaseSet.Make (
41 struct
42 type t = location
43 let compare l1 l2 =
44 match l1, l2 with
45 |`Expr_loc e1, `Expr_loc e2 -> Annot.compare (QmlAst.QAnnot.expr e1) (QmlAst.QAnnot.expr e2)
46 |`Pat_loc e1, `Pat_loc e2 -> Annot.compare (QmlAst.QAnnot.pat e1) (QmlAst.QAnnot.pat e2)
47 |`Ty_loc e1, `Ty_loc e2 -> Pervasives.compare e1(*.annot*) e2(*.annot*)
48 |_ -> Pervasives.compare l1 l2
49 end)
50
51 type loc_set = LocSet.t
52
53 let loc_set_empty = LocSet.empty
54 let loc_set_add = LocSet.add
55 let loc_set_union = LocSet.union
56
57 type error_loc =
978b7c4 @akoprow [fix] typo: occurence->occurrence, occured->occurred
akoprow authored
58 (* the main location, of the subexpression being typed when error occurred *)
fccc685 Initial open-source release
MLstate authored
59 location *
60 (* any extra related locations, e.g., an application in another let rec
61 branch, which makes the currently typed application incorrect *)
62 loc_set
63
64 let loc_empty = (`No_loc, LocSet.empty)
65
66 let loc_make main set =
67 let set = LocSet.remove main set in
68 (main, set)
69
70 let loc_add_main main (old_main, set) =
71 (* [`No_loc] can enter the set, but there'll always be at most one copy *)
72 let set = LocSet.add old_main set in
73 loc_make main set
74
75 let loc_add_set set (main, old_set) =
76 let set = LocSet.union old_set set in
77 loc_make main set
78
79
80 type 'ty t =
81 | InvalidType of
82 'ty * [`duplicate_field | `duplicate_field_with_diff_ty_in_sum_cases |
83 `not_a_record | `record_not_closed | `abstract_in_ty_annotation |
84 `other]
85 (* Invalid type
86 detected while typing:
87 - coerce failure
88 - record with several fields with the same name
89 - several sum cases with a same field having different types
90 - coerce to "external", i.e. into the constructor [QmlAst.TypeAbstract]
91 - ... ? *)
92 | InvalidTypeDefinition of 'ty * 'ty (* Corresponds to the restrictions which
93 are specific to type definitions e.g. type 'a t = ... 'b t ...,
94 if a <> b gives InvalidTypeDefinition (['a], t, ... 'b t ...) *)
95 | InvalidTypeUsage of QmlAst.typeident * QmlAst.typevar list * 'ty list (* The
96 use of a typename does not agree with its definition (e.g. number of type
97 parameters). *)
98 | IdentifierNotFound of Ident.t * Ident.t list
99 (* [IdentifierNotFound (missing, list_of_identifiers_at_this_point)].
100 [list_of_identifiers_at_this_point] may be empty if we are in a context
101 where the list of identifiers is unclear*)
102 | TypeIdentNotFound of QmlAst.typeident
103 | DuplicateTypeDefinitions of string (* An exception for QmlBlender and OPA,
104 not thrown in the normal QML world. *)
aeb2974 @fpessaux [fix] OPA-555: Missing source location in error message for escaping …
fpessaux authored
105
106
fccc685 Initial open-source release
MLstate authored
107
108 type exn_t = error_loc * (QmlAst.ty t)
109 exception Exception of exn_t
110
111
112
113 (* val map : ('a -> 'b) -> 'a QmlTyperException.t -> 'b QmlTyperException.t *)
114 let map f_ty = function
115 | InvalidType (t,k) -> InvalidType (f_ty t, k)
116 | InvalidTypeDefinition (ty1, ty2) ->
117 InvalidTypeDefinition (f_ty ty1, f_ty ty2)
118 | InvalidTypeUsage (tid, tvl, tyl) ->
119 InvalidTypeUsage (tid, tvl, List.map f_ty tyl)
120 | IdentifierNotFound _ as x -> x
121 | TypeIdentNotFound x -> TypeIdentNotFound x
122 | DuplicateTypeDefinitions s -> DuplicateTypeDefinitions s
Something went wrong with that request. Please try again.