-
-
Notifications
You must be signed in to change notification settings - Fork 647
/
globals.ml
210 lines (178 loc) · 4.72 KB
/
globals.ml
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
type pos = {
pfile : string;
pmin : int;
pmax : int;
}
type path = string list * string
type located =
| Message of string * pos
| Stack of located list
module IntMap = Ptmap
module StringMap = Map.Make(struct type t = string let compare = String.compare end)
module Int32Map = Map.Make(struct type t = Int32.t let compare = Int32.compare end)
type platform =
| Cross
| Js
| Lua
| Neko
| Flash
| Php
| Cpp
| Cs
| Java
| Python
| Hl
| Eval
let version = 4301
let version_major = version / 1000
let version_minor = (version mod 1000) / 100
let version_revision = (version mod 100)
let version_pre = None
let null_pos = { pfile = "?"; pmin = -1; pmax = -1 }
let located msg p = Message (msg,p)
let located_stack stack = Stack stack
let rec extract_located = function
| Message (msg,p) -> [(msg, p)]
| Stack stack -> List.fold_left (fun acc s -> acc @ (extract_located s)) [] stack
let rec relocate msg p = match msg with
| Message (msg,_) -> Message (msg,p)
| Stack [] -> Stack []
| Stack (hd :: tl) -> Stack ((relocate hd p) :: tl)
let rec extract_located_pos = function
| Message (_,p) -> p
| Stack [] -> null_pos
| Stack (hd :: _) -> extract_located_pos hd
let macro_platform = ref Neko
let return_partial_type = ref false
let is_windows = Sys.os_type = "Win32" || Sys.os_type = "Cygwin"
let platforms = [
Js;
Lua;
Neko;
Flash;
Php;
Cpp;
Cs;
Java;
Python;
Hl;
Eval;
]
(** Expected to match `haxe.display.Display.Platform`. *)
let platform_name = function
| Cross -> "cross"
| Js -> "js"
| Lua -> "lua"
| Neko -> "neko"
| Flash -> "flash"
| Php -> "php"
| Cpp -> "cpp"
| Cs -> "cs"
| Java -> "java"
| Python -> "python"
| Hl -> "hl"
| Eval -> "eval"
let parse_platform = function
| "cross" -> Cross
| "js" -> Js
| "lua" -> Lua
| "neko" -> Neko
| "flash" -> Flash
| "php" -> Php
| "cpp" -> Cpp
| "cs" -> Cs
| "java" -> Java
| "python" -> Python
| "hl" -> Hl
| "eval" -> Eval
| p -> raise (failwith ("invalid platform " ^ p))
let platform_list_help = function
| [] -> ""
| [p] -> " (" ^ platform_name p ^ " only)"
| pl -> " (for " ^ String.concat "," (List.map platform_name pl) ^ ")"
let mk_zero_range_pos p = { p with pmax = p.pmin }
let s_type_path (p,s) = match p with [] -> s | _ -> String.concat "." p ^ "." ^ s
let starts_with s c =
String.length s > 0 && s.[0] = c
let get_error_pos_ref : ((string -> int -> string) -> pos -> string) ref = ref (fun printer p ->
Printf.sprintf "%s: characters %d-%d" p.pfile p.pmin p.pmax
)
let s_version =
let pre = Option.map_default (fun pre -> "-" ^ pre) "" version_pre in
Printf.sprintf "%d.%d.%d%s" version_major version_minor version_revision pre
let s_version_full =
match Version.version_extra with
| Some (_,build) -> s_version ^ "+" ^ build
| _ -> s_version
let patch_string_pos p s = { p with pmin = p.pmax - String.length s }
(**
Terminates compiler process and prints user-friendly instructions about filing an issue.
Usage: `die message __LOC__`, where `__LOC__` is a built-in ocaml constant
*)
let die ?p msg ml_loc =
let msg =
let str_pos, expr_msg =
match p with
| None -> "", ""
| Some p -> ((!get_error_pos_ref (Printf.sprintf "%s:%d:") p) ^ " "), "the expression example and "
in
str_pos ^ "Compiler failure" ^ (if msg = "" then "" else ": " ^ msg) ^ "\n"
^ str_pos ^ "Please submit an issue at https://github.com/HaxeFoundation/haxe/issues/new\n"
^ str_pos ^ "Attach " ^ expr_msg ^ "the following information:"
in
let backtrace = Printexc.raw_backtrace_to_string (Printexc.get_callstack 21) in
let backtrace =
try snd (ExtString.String.split backtrace "\n")
with ExtString.Invalid_string -> backtrace
in
let ver = s_version_full
and os_type = if Sys.unix then "unix" else "windows" in
Printf.eprintf "%s\nHaxe: %s; OS type: %s;\n%s\n%s" msg ver os_type ml_loc backtrace;
assert false
module MessageSeverity = struct
type t =
| Error
| Warning
| Information
| Hint
let to_int = function
| Error -> 1
| Warning -> 2
| Information -> 3
| Hint -> 4
end
module MessageKind = struct
type t =
| DKUnusedImport
| DKUnresolvedIdentifier
| DKCompilerMessage
| DKRemovableCode
| DKParserError
| DKDeprecationWarning
| DKInactiveBlock
| DKMissingFields
let to_int = function
| DKUnusedImport -> 0
| DKUnresolvedIdentifier -> 1
| DKCompilerMessage -> 2
| DKRemovableCode -> 3
| DKParserError -> 4
| DKDeprecationWarning -> 5
| DKInactiveBlock -> 6
| DKMissingFields -> 7
end
type compiler_message = {
cm_message : string;
cm_pos : pos;
cm_depth : int;
cm_kind : MessageKind.t;
cm_severity : MessageSeverity.t;
}
let make_compiler_message msg p depth kind sev = {
cm_message = msg;
cm_pos = p;
cm_depth = depth;
cm_kind = kind;
cm_severity = sev;
}
let i32_31 = Int32.of_int 31