Diff
Not logged in

Differences From Artifact [701f5b1b899607f2]:

To Artifact [1bc945d1d318d417]:


17 17 { 18 18 immutable string filename; /// name of the source file 19 19 immutable int lineno; /// 1-origin 20 20 immutable int column; /// 1-origin 21 21 22 22 mixin SimpleClass; 23 23 override string toString() const 24 - { 25 - return sprintf!("%s:%d:%d")(filename, lineno, column); 26 - } 27 - 24 + { return sprintf!("%s:%d:%d")(filename, lineno, column); } 28 25 static LexPosition dummy; 29 26 static this(){ dummy = new LexPosition("<unnamed>",0,0); } 30 27 } 31 28 32 29 unittest 33 30 { 34 31 auto p = new LexPosition("hello.cpp", 123, 45); ................................................................................ 50 47 51 48 /*mixin*/ 52 49 template ExceptionWithPosition() 53 50 { 54 51 LexPosition pos; 55 52 this( LexPosition pos, string msg, string file=null, size_t line=0, Throwable next=null ) 56 53 { 57 - if(pos is null) 58 - super(sprintf!("[??] %s")(msg), file, line, next); 59 - else 60 - super(sprintf!("[%s] %s")(pos, msg), file, line, next); 54 + string fullmsg = pos is null ? sprintf!("\n[??] %s")(msg) 55 + : sprintf!("\n[%s] %s")(pos, msg); 56 + for(int i=0; i<callstack_pos.length || i<callstack_msg.length; ++i) 57 + { 58 + LexPosition p = (i<callstack_pos.length ? callstack_pos[i] : null); 59 + string m = (i<callstack_msg.length ? callstack_msg[i] : null); 60 + fullmsg ~= p is null ? sprintf!("\n[??] %s")(m) 61 + : sprintf!("\n[%s] %s")(p, m); 62 + } 63 + super(fullmsg, file, line, next); 61 64 this.pos = pos; 65 + } 66 + this( string msg, string file=null, size_t line=0, Throwable next=null ) 67 + { 68 + this(null, msg, file, line, next); 62 69 } 63 70 } 64 71 65 -class UnexpectedEOF : Exception { mixin ExceptionWithPosition; } /// EOF during lexing/parsing 66 -class LexException : Exception { mixin ExceptionWithPosition; } /// Lexer errors 67 -class ParseException : Exception { mixin ExceptionWithPosition; } /// Parser errors 72 +class UnexpectedEOF : Exception { mixin ExceptionWithPosition; } /// EOF during lexing/parsing 73 +class LexException : Exception { mixin ExceptionWithPosition; } /// Lexer errors 74 +class ParseException : Exception { mixin ExceptionWithPosition; } /// Parser errors 68 75 class RuntimeException : Exception { mixin ExceptionWithPosition; } /// Evaluator errors 76 + 77 +/// Per-thread call stack management. 78 +/// This scoped class's ctor&dtor maintain the callstack. 79 +/// TODO: make it "per-evaluator" !!!!!!!!!!! 80 + 81 +scope class PushCallStack 82 +{ 83 + this(LexPosition pos, string msg) { callstackEnterFunction(pos,msg); } 84 + ~this() { callstackLeaveFunction(); } 85 +} 86 + 87 +LexPosition[] callstack_pos; 88 +string[] callstack_msg; 89 + 90 +private void callstackEnterFunction(LexPosition pos, string msg) 91 +{ 92 + callstack_pos ~= pos; 93 + callstack_msg ~= msg; 94 +} 95 + 96 +private void callstackLeaveFunction() 97 +{ 98 + callstack_pos.length -= 1; 99 + callstack_msg.length -= 1; 100 +}