Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 204 lines (158 sloc) 6.147 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 Manage all messages of compiler.
21
22 The way of enhancing outputs with colors is as follows:
23 [OManager.printf "\@{<blue>blabla\@}"] which will print "blabla" in blue
24 The available tags are
25 - black, red, green, yellow, blue, magenta, cyan, white, default to set the foreground color
26 - the same list but capitalized to set the background color
27 - reset: to disable any colors
28 - reverse: to switch foreground and background colors
29 - cross: to cross the output
30 - underline: to underline the output
31 - dim, bright, normal: to set the brightness of the foreground
32
33 All these tags can be nested arbitrarily (though nesting cross or underline tags is useless).
34
35 You can set severals tags in one go by separating them with commas:
36 [OManager.printf "\@{<blue,Red, bright}stuff\@}"] will set the foreground color
37 to bright blue, and the background color to red.
38 *)
39
40 (** {6 Options} *)
41 (** Provides a specification list for parsing line command. *)
42 module Arg : sig
43 (**
44 Concatenation of all specs in interaction with this module.
45 + [--no-color] to disable any color from the outputs
46 + [--force-color] to enable colored output
47 + [--verbose]
48 + [--quiet]
49 *)
50 val options : (Base.Arg.key * Base.Arg.spec * Base.Arg.doc) list
51
52 (**
53 Given a tool name, it will return the triplet which print
54 the name and the version of the tool.
55 *)
56 val version : string -> (Base.Arg.key * Base.Arg.spec * Base.Arg.doc)
57 end
58
59 (** Format of a compiler message.*)
60 type ('params,'output) oformat = ('params, Format.formatter, unit, 'output) format4
61
62 (** {6 Properties getter & setter}*)
63
64 (** Activate/Unactivate colors *)
65 val set_color : bool -> unit
66
67 (** Activate/Unactivate verbose mode.*)
68 val set_verbose : bool -> unit
69
70 (** Return the status of verbose mode. *)
71 val is_verbose : unit -> bool
72
73 (** Activate/Unactivate quiet mode.*)
74 val set_quiet : bool -> unit
75
76 (** Return the status of quiet mode. *)
77 val is_quiet : unit -> bool
78
79 (** {6 Standard output} *)
80 (**
81 If you need to use the same formatter as OManager (stderr)
82 <!> Not for casual user (e.g kfprintf, etc...)
83 *)
84 val oformatter : Format.formatter ref
85
86 (** Already print on OManager formatter. *)
87 val printf : ('a,unit) oformat -> 'a
88
89 (** Already print on OManager formatter. *)
90 val ifprintf : ('a,unit) oformat -> 'a
91
92 (** Print on OManager formatter only when verbose is activated. *)
93 val verbose : ('a,unit) oformat -> 'a
94
95 (** Print on OManager formatter unless quiet is activated. *)
96 val unquiet : ('a,unit) oformat -> 'a
97
98 (** {6 Errors} *)
99 (**
100 Print an error and exit.
101 See in NonFatal module for ide or interpreter.
102 <!> You should rather try to use directly a module Error
103 corresonding to the language your are manipulating.
104 cf [QmlError], [OpaError]
105 *)
106 val error : ('a,'exit) oformat -> 'a
107
108 (**
109 Add an error on OManager but doesn't exit immediatly.
110 Exit when [flush_errors] is called.
111 *)
112 val serror : ('a,unit) oformat -> 'a
113
114 (**
115 Like [error] but for internal.
116 The message is prefixed with [Internal error. ]
117 *)
118 val i_error : ('a,'exit) oformat -> 'a
119
120 (**
121 Like [serror] but for internal.
122 *)
123 val i_serror : ('a,unit) oformat -> 'a
124
125 (** Flush all errors and exit if OManager contains errors. *)
126 val flush_errors : unit -> unit
127
128 (** {6 Warning} *)
129 (** Print a warning, and it's behavior it's defined by [WarningClass]
130 options. By default warning is [WarningClass.default]. *)
131 val warning : wclass:WarningClass.wclass -> ('a,unit) oformat -> 'a
132
133 (** At some point after a check for a cond, the [PassHandler] needs to know if a warn-error was produced by the checker.
134
135 This function returns the list of all wclass which have
136 already been produced in warn-error mode at this point.
137 *)
138 val warn_error_status : unit -> WarningClass.wclass list
139
140 (** {6 Using opa as a lib} *)
141
142 (**
143 The function at_exit should have a specific type,
144 like an exception, or an sys exit.
145 *)
146 type at_exit = { at_exit : 'a. int -> 'a }
147
148 (**
149 To be used instead of Pervasives.exit, for users of the compiler
150 as a lib
151 *)
152 val exit : int -> 'a
153
154 module CompilerAsLib :
155 sig
156 (** {6 Cannal redirection} *)
157 (**
158 You can change the cannal used by the compiler.
159 For wild code which does not respect guidelines, there is not guaranty.
160 *)
161
162 val set_stderr : Format.formatter -> unit
163
164 (** TODO: stdout is not used by OManager *)
165 val set_stdout : Format.formatter -> unit
166
167 (**
168 You can replace the function called in case of an fatal error.
169 A typicall exemple is to define a exception in the ide to catch
170 all errors of the compiler.
171
172 Usability : the error messages have already been printed by the responsable
173 of the error, you can just continue your jobs without taking care of
174 reporting more messages about the error. :
175
176 "Each module is responsable of the coherence and the clarty of its own errors"
177
178 However, modules can take help from [LangError] modules.
179 *)
180 val at_exit : at_exit -> unit
181 end
182
183 (** {6 Tool welcome} *)
184
185 (**
186 Given a tool name (e.g bslregister, qmlflat, etc...)
187 this will produce on the oformatter :
188 {[
189 This is $tool version ... (c) MLstate 2010
190 ]}
191
192 [force] means if you want to print it, even if
193 verbose is not set to [true].
194 by default, the message is printed only if the
195 verbose parameter of OManager is activated.
196 *)
197 val this_is_tool : ?force:bool -> string -> unit
198
199
200 (**
201 Our apologize, internal error, invitation to bug report
202 *)
203 val apologies : unit -> unit
Something went wrong with that request. Please try again.