# HG changeset patch # User Anders Johnsen # Date 1216941667 -7200 # Node ID 2a1a635bd5312729531f4b7a01a5ad7be8ea7460 # Parent 5f7e2f2344a5e4769e5008779e5e2676e16f5d26 Changes the way messages can be displayed. Also added a toString to DType's for type printing. diff -r 5f7e2f2344a5 -r 2a1a635bd531 ast/Exp.d --- a/ast/Exp.d Thu Jul 24 23:36:38 2008 +0200 +++ b/ast/Exp.d Fri Jul 25 01:21:07 2008 +0200 @@ -637,6 +637,11 @@ this.myType = myType; } + override SourceRange sourceRange() + { + return SourceRange(loc, loc + name.length); + } + char[] name; private DType myType; } diff -r 5f7e2f2344a5 -r 2a1a635bd531 basic/Message.d --- a/basic/Message.d Thu Jul 24 23:36:38 2008 +0200 +++ b/basic/Message.d Fri Jul 25 01:21:07 2008 +0200 @@ -42,9 +42,16 @@ return m; } - Message report(uint opcode, SLoc location1, SLoc location2) + Message report(uint opcode, SourceRange[] ranges, SourceLocation[] locs) { - Message m = new Message(opcode, location1, location2, src_mgr, this); + Message m = new Message(opcode, ranges, locs, src_mgr, this); + messages ~= m; + return m; + } + + Message report(uint opcode, SLoc location1, SLoc location2, SLoc location3 = SLoc.Invalid) + { + Message m = new Message(opcode, [SourceRange(location1, location2)][], [location3][], src_mgr, this); messages ~= m; return m; } @@ -91,17 +98,23 @@ this(int opcode, SLoc location, SourceManager src_mgr, MessageHandler msg_handler) { this.src_mgr = src_mgr; - this.location = location; + this.interests ~= location; args ~= Messages[opcode].message; this.type = Messages[opcode].type; this.msg_handler = msg_handler; } - this(int opcode, SLoc location, SLoc end, SourceManager src_mgr, MessageHandler msg_handler) + this(int opcode, SourceRange[] locs, SLoc[] interests, + SourceManager src_mgr, MessageHandler msg_handler) + in + { + assert(locs.length + interests.length, "Atleast one location is requiret for a mark"); + } + body { this.src_mgr = src_mgr; - this.location = location; - this.end = end; + this.locs = locs; + this.interests = interests; args ~= Messages[opcode].message; this.type = Messages[opcode].type; this.msg_handler = msg_handler; @@ -113,16 +126,22 @@ char[256] tmp = void; char[] msg = layout(tmp, args); + SLoc location; + if (interests.length) + location = interests[0]; + else + location = locs[0].begin; + int len = 0; if(!haveEnd) { - Lexer l = new Lexer(location, src_mgr, new MessageHandler(src_mgr)); + Lexer l = new Lexer(interests[0], src_mgr, new MessageHandler(src_mgr)); Token t = l.next; len = t.length; } - else - len = end - location; +// else + // len = end - location; if (src_mgr.getRawData(location).length > 0) msg = src_mgr.getLocationAsString(location) ~ ": " ~ msg; @@ -133,8 +152,18 @@ char[] line = src_mgr.getLine(location); char[] marks = line.dup; marks[] = ' '; - size_t p = src_mgr.getColumn(location); - marks[p .. p + len] = '^'; + + foreach (s ; locs) + { + size_t p = src_mgr.getColumn(s.begin); + marks[p .. p + (s.end-s.begin)] = '~'; + } + + foreach (interest ; interests) + { + size_t i = src_mgr.getColumn(interest); + marks[i] = '^'; + } msg ~= "\n "; msg ~= line; @@ -191,7 +220,8 @@ MessageType type; private: char[][] args; - SLoc location, end; + SourceRange[] locs; + SLoc[] interests; bool haveEnd; SourceManager src_mgr; MessageHandler msg_handler; diff -r 5f7e2f2344a5 -r 2a1a635bd531 basic/Messages.d --- a/basic/Messages.d Thu Jul 24 23:36:38 2008 +0200 +++ b/basic/Messages.d Fri Jul 25 01:21:07 2008 +0200 @@ -107,7 +107,7 @@ // sema CannotFindModule : E(Err, "Cannot find module '%0'"), - InvalidImplicitCast : E(Err, "Cannot make implicit cast between %0 and %1"), + InvalidImplicitCast : E(Err, "Cannot make implicit cast between '%0' and '%1'"), UndefinedIdentifier : E(Err, "Undefined identifier '%0'"), UndefinedType : E(Err, "Undefined type '%0'"), MissingMember : E(Err, "%0 %1 has no member %2"), diff -r 5f7e2f2344a5 -r 2a1a635bd531 sema/DType.d --- a/sema/DType.d Thu Jul 24 23:36:38 2008 +0200 +++ b/sema/DType.d Fri Jul 25 01:21:07 2008 +0200 @@ -99,12 +99,12 @@ { return cast(hash_t)(cast(void*)this); } -/* + char[] toString() { return id; } -*/ + char[] name() { return id; } SourceLocation getLoc() { return loc; } int byteSize() { return 0; } @@ -548,6 +548,12 @@ return arrayOf.isSame(a.arrayOf); } + char[] toString() + { + return arrayOf.toString~"["~Integer.toString(size)~"]"; + } + + override char[] mangle() { return "G"~Integer.toString(size)~arrayOf.mangle; @@ -617,6 +623,21 @@ return pointerOf.isSame(p.pointerOf); } + char[] toString() + { + if (!pointerOf.isFunction) + return pointerOf.toString~"*"; + + auto f = pointerOf.asFunction; + + char[] res = f.returnType.toString~" function("; + + foreach (i, p ; f.params) + res ~= i ? ", "~p.toString : p.toString; + + return res ~ ")"; + } + override char[] mangle() { return "P"~pointerOf.mangle; @@ -655,6 +676,16 @@ return res; } + char[] toString() + { + char[] res = returnType.toString~" ("; + + foreach (i, p ; params) + res ~= i ? ", "~p.toString : p.toString; + + return res ~ ")"; + } + override bool isSame(DType f) { if (f is this) diff -r 5f7e2f2344a5 -r 2a1a635bd531 sema/TypeCheck.d --- a/sema/TypeCheck.d Thu Jul 24 23:36:38 2008 +0200 +++ b/sema/TypeCheck.d Fri Jul 25 01:21:07 2008 +0200 @@ -308,7 +308,9 @@ if(!identifierType.isSame(expType)) { if(!expType.hasImplicitConversionTo(identifierType)) - messages.report(InvalidImplicitCast, exp.loc) + messages.report(InvalidImplicitCast, + [exp.identifier.sourceRange, exp.exp.sourceRange][], + [exp.loc]) .arg(expType.toString) .arg(identifierType.toString); diff -r 5f7e2f2344a5 -r 2a1a635bd531 tests/parser/function_pointer.d --- a/tests/parser/function_pointer.d Thu Jul 24 23:36:38 2008 +0200 +++ b/tests/parser/function_pointer.d Fri Jul 25 01:21:07 2008 +0200 @@ -1,7 +1,7 @@ int main() { - f = &foo; + f = &&foo; } int foo(int x) @@ -9,4 +9,4 @@ return x; } -int function(int x) f; +int function(int x)* f; diff -r 5f7e2f2344a5 -r 2a1a635bd531 tests/parser/public_1.d --- a/tests/parser/public_1.d Thu Jul 24 23:36:38 2008 +0200 +++ b/tests/parser/public_1.d Fri Jul 25 01:21:07 2008 +0200 @@ -1,4 +1,3 @@ -module tests.parser.public_1; public struct name {