1 /// Author: Aziz Köksal
2 /// License: GPL3
3 /// $(Maturity average)
4 module dil.Diagnostics;
5
6 import dil.i18n.ResourceBundle,
7 dil.i18n.Messages;
8 import common;
9
10 public import dil.Information;
11
12 /// Collects diagnostic information about the compilation process.
13 class Diagnostics
14 {
15 Information[] info; /// List of info objects.
16 ResourceBundle bundle; /// Used to retrieve messages.
17 Layout!(char) format; /// Used to format messages.
18
19 this()
20 {
21 this.bundle = new ResourceBundle();
22 this.format = new Layout!(char)();
23 }
24
25 /// Returns true if there are info objects.
26 bool hasInfo()
27 {
28 return info.length != 0;
29 }
30
31 /// Appends an info object.
32 void opCatAssign(Information info)
33 {
34 this.info ~= info;
35 }
36
37 /// Appends info objects.
38 void opCatAssign(Information[] info)
39 {
40 this.info ~= info;
41 }
42
43 /// Returns a msg from the resource bundle.
44 cstring msg(MID mid)
45 {
46 return bundle.msg(mid);
47 }
48
49 /// Returns a formatted msg.
50 char[] formatMsg(MID mid, ...)
51 {
52 return formatMsg(mid, _arguments, _argptr);
53 }
54
55 /// ditto
56 char[] formatMsg(MID mid, TypeInfo[] _arguments, va_list _argptr)
57 {
58 auto m = msg(mid);
59 return _arguments.length ? format(_arguments, _argptr, m) : m.dup;
60 }
61 }