comparison runtime/internal/genobj.d @ 1125:8208374e5bed

Apply fawzi's patch from #235. This has some issues which are addressed in my next commit.
author Frits van Bommel <fvbommel wxs.nl>
date Wed, 18 Mar 2009 15:20:07 +0100
parents f466f475b654
children 899a2d90645b
comparison
equal deleted inserted replaced
1124:e7f0c2b48047 1125:8208374e5bed
903 //////////////////////////////////////////////////////////////////////////////// 903 ////////////////////////////////////////////////////////////////////////////////
904 904
905 905
906 class Exception : Object 906 class Exception : Object
907 { 907 {
908 struct FrameInfo{
909 long line;
910 ptrdiff_t offset;
911 size_t address;
912 char[] file;
913 char[] func;
914 char[256] charBuf;
915 void writeOut(void delegate(char[])sink){
916 char[25] buf;
917 sink(func);
918 sprintf(buf.ptr,"@%zx ",address);
919 sink(buf[0..strlen(buf.ptr)]);
920 sprintf(buf.ptr," %+td ",address);
921 sink(buf[0..strlen(buf.ptr)]);
922 sink(file);
923 sprintf(buf.ptr,":%ld",line);
924 sink(buf[0..strlen(buf.ptr)]);
925 }
926 }
908 interface TraceInfo 927 interface TraceInfo
909 { 928 {
910 int opApply( int delegate( inout char[] ) ); 929 int opApply( int delegate( ref FrameInfo fInfo ) );
911 } 930 }
912 931
913 char[] msg; 932 char[] msg;
914 char[] file; 933 char[] file;
915 size_t line; 934 size_t line;
916 TraceInfo info; 935 TraceInfo info;
917 Exception next; 936 Exception next;
918 937
919 this( char[] msg, Exception next = null ) 938 this( char[] msg, char[] file, long line, Exception next, TraceInfo info )
920 { 939 {
940 // main constructor, breakpoint this if you want...
921 this.msg = msg; 941 this.msg = msg;
922 this.next = next; 942 this.next = next;
923 this.info = traceContext();
924 }
925
926 this( char[] msg, char[] file, size_t line, Exception next = null )
927 {
928 this(msg, next);
929 this.file = file; 943 this.file = file;
930 this.line = line; 944 this.line = cast(size_t)line;
931 this.info = traceContext(); 945 this.info = info;
946 }
947
948 this( char[] msg, Exception next=null )
949 {
950 this(msg,"",0,next,rt_createTraceContext(null));
951 }
952
953 this( char[] msg, char[] file, long line, Exception next=null )
954 {
955 this(msg,file,line,next,rt_createTraceContext(null));
932 } 956 }
933 957
934 char[] toString() 958 char[] toString()
935 { 959 {
936 return msg; 960 return msg;
961 }
962
963 void writeOut(void delegate(char[])sink){
964 if (file)
965 {
966 char[25]buf;
967 sink(this.classinfo.name);
968 sink("@");
969 sink(file);
970 sink("(");
971 sprintf(buf.ptr,"%ld",line);
972 sink(buf[0..strlen(buf.ptr)]);
973 sink("): ");
974 sink(toString());
975 sink("\n");
976 }
977 else
978 {
979 sink(this.classinfo.name);
980 sink(": ");
981 sink(toString);
982 sink("\n");
983 }
984 if (info)
985 {
986 sink("----------------\n");
987 foreach (ref t; info){
988 t.writeOut(sink);
989 sink("\n");
990 }
991 }
992 if (next){
993 sink("\n");
994 next.writeOut(sink);
995 }
937 } 996 }
938 } 997 }
939 998
940 999
941 alias Exception.TraceInfo function( void* ptr = null ) TraceHandler; 1000 alias Exception.TraceInfo function( void* ptr = null ) TraceHandler;
966 * 1025 *
967 * Returns: 1026 * Returns:
968 * An object describing the current calling context or null if no handler is 1027 * An object describing the current calling context or null if no handler is
969 * supplied. 1028 * supplied.
970 */ 1029 */
971 Exception.TraceInfo traceContext( void* ptr = null ) 1030 extern(C) Exception.TraceInfo rt_createTraceContext( void* ptr ){
972 { 1031 {
973 if( traceHandler is null ) 1032 if( traceHandler is null )
974 return null; 1033 return null;
975 return traceHandler( ptr ); 1034 return traceHandler( ptr );
976 } 1035 }