Commit | Line | Data |
---|---|---|
c16dd441 | 1 | module Abs = Tiger_absyn |
7c14a966 | 2 | module Pos = Tiger_position |
c16dd441 SK |
3 | module Sym = Tiger_symbol |
4 | module Typ = Tiger_env_type | |
7c14a966 | 5 | |
c16dd441 SK |
6 | type t = |
7 | | Invalid_syntax of Pos.t | |
8 | | Unknown_id of {id : Sym.t; pos : Pos.t} | |
9 | | Unknown_type of {ty_id : Sym.t; pos : Pos.t} | |
10 | | Id_not_a_function of {id : Sym.t; pos : Pos.t} | |
11 | | Wrong_type_of_expression_in_var_dec of | |
12 | { var_id : Sym.t | |
13 | ; expected : Typ.t | |
14 | ; given : Typ.t | |
15 | ; pos : Pos.t | |
16 | } | |
17 | | Wrong_type_used_as_record of | |
18 | { ty_id : Sym.t | |
19 | ; ty : Typ.t | |
20 | ; pos : Pos.t | |
21 | } | |
22 | | Wrong_type_of_field_value of | |
23 | { field_id : Sym.t | |
24 | ; expected : Typ.t | |
25 | ; given : Typ.t | |
26 | ; pos : Pos.t | |
27 | } | |
28 | | Wrong_type_of_arg of | |
29 | { func : Sym.t | |
30 | ; expected : Typ.t | |
31 | ; given : Typ.t | |
32 | ; pos : Pos.t | |
33 | } | |
34 | | Wrong_number_of_args of | |
35 | { func : Sym.t | |
36 | ; expected : int | |
37 | ; given : int | |
38 | ; pos : Pos.t | |
39 | } | |
40 | | Invalid_operand_type of | |
41 | { oper : Abs.oper | |
42 | ; valid : string list | |
43 | ; given : Typ.t | |
44 | ; pos : Pos.t | |
45 | } | |
46 | | Different_operand_types of | |
47 | { oper : Abs.oper | |
48 | ; left : Typ.t | |
49 | ; right : Typ.t | |
50 | ; pos : Pos.t | |
51 | } | |
7c14a966 | 52 | |
c16dd441 SK |
53 | exception T of t |
54 | ||
55 | let raise t = | |
56 | raise (T t) | |
57 | ||
58 | let to_string = | |
59 | let s = Printf.sprintf in | |
60 | function | |
61 | | Invalid_syntax pos -> | |
62 | s "Invalid syntax in %s" (Pos.to_string pos) | |
63 | | Unknown_id {id; pos} -> | |
64 | s "Unknown identifier %S in %s" (Sym.to_string id) (Pos.to_string pos) | |
65 | | Unknown_type {ty_id; pos} -> | |
66 | s "Unknown type %S in %s" (Sym.to_string ty_id) (Pos.to_string pos) | |
67 | | Id_not_a_function {id; pos} -> | |
68 | s "Identifier %S is not a function, it cannot be called in %s" | |
69 | (Sym.to_string id) (Pos.to_string pos) | |
70 | | Wrong_type_of_expression_in_var_dec {var_id; expected; given; pos} -> | |
71 | s ( "Wrong type of expression in declaration of %S. " | |
72 | ^^"Expected: %S, given: %S. In %s") | |
73 | (Sym.to_string var_id) | |
74 | (Typ.to_string expected) | |
75 | (Typ.to_string given) | |
76 | (Pos.to_string pos) | |
77 | | Wrong_type_used_as_record {ty_id; ty; pos} -> | |
78 | s ( "Identifier %S is bound to type %S, not a record. " | |
79 | ^^"It cannot be used in %s") | |
80 | (Sym.to_string ty_id) (Typ.to_string ty) (Pos.to_string pos) | |
81 | | Wrong_type_of_field_value {field_id; expected; given; pos} -> | |
82 | s ( "Field %S is declared to be of type %S, but is bound to expression " | |
83 | ^^"of type %S in %s") | |
84 | (Sym.to_string field_id) | |
85 | (Typ.to_string expected) | |
86 | (Typ.to_string given) | |
87 | (Pos.to_string pos) | |
88 | | Wrong_type_of_arg {func; expected; given; pos} -> | |
89 | s ( "Incorrect type of argument to function %S, expected: %S, given: %S," | |
90 | ^^" in %s") | |
91 | (Sym.to_string func) | |
92 | (Typ.to_string expected) | |
93 | (Typ.to_string given) | |
94 | (Pos.to_string pos) | |
95 | | Wrong_number_of_args {func; expected; given; pos} -> | |
96 | s ( "Incorrect number of arguments to function %S, " | |
97 | ^^"expected: %d, given: %d," | |
98 | ^^" in %s") | |
99 | (Sym.to_string func) expected given (Pos.to_string pos) | |
100 | | Invalid_operand_type {oper; valid; given; pos} -> | |
101 | s ( "Invalid operand type %S for operator %S, which expects only: %s" | |
102 | ^^". In %s") | |
103 | (Typ.to_string given) | |
104 | (Abs.op_show oper) | |
105 | (String.concat ", " valid) | |
106 | (Pos.to_string pos) | |
107 | | Different_operand_types {oper; left; right; pos} -> | |
108 | s "Operands of different types (%S %S %S) given in %s" | |
109 | (Typ.to_string left) | |
110 | (Abs.op_show oper) | |
111 | (Typ.to_string right) | |
112 | (Pos.to_string pos) |