diff sema/TypeCheck.d @ 114:3a0cd42de9cc

Removed misc/Error.d and is now using the error system all way through.
author Anders Johnsen <skabet@gmail.com>
date Sun, 25 May 2008 16:40:38 +0200
parents 189c049cbfcc
children c3b24e7e8cf8
line wrap: on
line diff
--- a/sema/TypeCheck.d	Sun May 25 15:48:13 2008 +0200
+++ b/sema/TypeCheck.d	Sun May 25 16:40:38 2008 +0200
@@ -5,14 +5,14 @@
 
 import tango.io.Stdout;
 
-import misc.Error,
-       basic.SourceLocation;
+import basic.SourceLocation,
+       basic.Message;
 
 class TypeCheck : Visitor!(void)
 {
-    private Error error(uint line, char[] msg)
+    this(MessageHandler messages)
     {
-        return new Error(msg);
+        this.messages = messages;
     }
 
     override void visitBinaryExp(BinaryExp exp)
@@ -22,7 +22,9 @@
         if(exp.left.type.byteSize > exp.right.type.byteSize)
         {
             if(!exp.right.type.hasImplicitConversionTo(exp.left.type))
-                throw error(__LINE__, "Cannot make implicit cast");
+                messages.report(InvalidImplicitCast, exp.loc)
+                    .arg(exp.right.type.toString)
+                    .arg(exp.left.type.toString);
 
             auto castExp = new CastExp(
                     SLoc.Invalid,
@@ -35,7 +37,9 @@
         if(exp.left.type.byteSize < exp.right.type.byteSize)
         {
             if(!exp.left.type.hasImplicitConversionTo(exp.right.type))
-                throw error(__LINE__, "Cannot make implicit cast");
+                messages.report(InvalidImplicitCast, exp.loc)
+                    .arg(exp.right.type.toString)
+                    .arg(exp.left.type.toString);
 
             auto castExp = new CastExp(
                     SLoc.Invalid,
@@ -60,7 +64,9 @@
             if(argType.byteSize != expType.byteSize)
             {
                 if(!expType.hasImplicitConversionTo(argType))
-                    throw error(__LINE__, "Cannot make implicit cast");
+                   messages.report(InvalidImplicitCast, exp.loc)
+                        .arg(expType.toString)
+                        .arg(argType.toString);
 
                 auto castExp = new CastExp(
                         SLoc.Invalid,
@@ -86,7 +92,9 @@
         if(identifierType != expType)
         {
             if(!expType.hasImplicitConversionTo(identifierType))
-                throw error(__LINE__, "Cannot make implicit cast between");
+                messages.report(InvalidImplicitCast, exp.loc)
+                    .arg(expType.toString)
+                    .arg(identifierType.toString);
 
             auto castExp = new CastExp(
                     SLoc.Invalid,
@@ -108,7 +116,9 @@
             if(returnType != expType)
             {
                 if(!expType.hasImplicitConversionTo(returnType))
-                    throw error(__LINE__, "Cannot make implicit cast");
+                   messages.report(InvalidImplicitCast, stmt.exp.loc)
+                        .arg(expType.toString)
+                        .arg(returnType.toString);
 
                 auto castExp = new CastExp(
                         SLoc.Invalid,
@@ -131,7 +141,9 @@
             if(varType.byteSize != expType.byteSize)
             {
                 if(!expType.hasImplicitConversionTo(varType))
-                    throw error(__LINE__, "Cannot make implicit cast");
+                   messages.report(InvalidImplicitCast, decl.init.loc)
+                        .arg(expType.toString)
+                        .arg(varType.toString);
 
                 auto castExp = new CastExp(
                         SLoc.Invalid,
@@ -142,5 +154,7 @@
             }
         }
     }
+
+    MessageHandler messages;
 }