Mercurial > projects > dang
view misc/Error.d @ 29:41d23f2762c3 new_gen
Merge, and updated Error class
Usage is something like:
---
auto e = new Error("No conversion between %0 and %1);
e.arg(t1).arg(t2);
e.loc(exp.location);
---
Multiple locations can be given, to do clang like errors in the future
author | Anders Halager <halager@gmail.com> |
---|---|
date | Sun, 20 Apr 2008 11:47:34 +0200 |
parents | 2d28b21faad6 |
children | 084c2c147c4f |
line wrap: on
line source
module misc.Error; import tango.core.Exception, tango.text.Util : layout; import llvm.type; import misc.Location, sema.Symbol; class Error : Exception { this(char[] message) { super(message); args ~= message; } char[] toString() { char[256] tmp = void; char[] msg = layout(tmp, args); if (locs.length > 0) msg = locs[0].toString ~ ": " ~ msg; else msg = msg.dup; return msg; } Error arg(char[] s) { if (args.length == 11) throw new Exception("Sorry, errors only support up to 10 args"); args ~= s; return this; } Error arg(char c) { return arg([c]); } Error arg(DType type) { return arg(type.name()); } Error arg(Symbol sym) { return arg(sym.type.name ~ " " ~ sym.id.get); } Error loc(Location loc) { locs ~= loc; return this; } private: char[][] args; Location[] locs; }