Mercurial > projects > ddmd
diff dmd/expression/util/arrayTypeCompatible.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | e28b18c23469 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dmd/expression/util/arrayTypeCompatible.d Sat Oct 24 08:42:06 2009 +0400 @@ -0,0 +1,34 @@ +module dmd.expression.util.arrayTypeCompatible; + +import dmd.Loc; +import dmd.Type; +import dmd.TY; +import dmd.MATCH; +import dmd.Util; + +/*********************************** + * See if both types are arrays that can be compared + * for equality. Return !=0 if so. + * If they are arrays, but incompatible, issue error. + * This is to enable comparing things like an immutable + * array with a mutable one. + */ +bool arrayTypeCompatible(Loc loc, Type t1, Type t2) +{ + t1 = t1.toBasetype(); + t2 = t2.toBasetype(); + + if ((t1.ty == TY.Tarray || t1.ty == TY.Tsarray || t1.ty == TY.Tpointer) && (t2.ty == TY.Tarray || t2.ty == TY.Tsarray || t2.ty == TY.Tpointer)) + { + if (t1.nextOf().implicitConvTo(t2.nextOf()) < MATCH.MATCHconst && + t2.nextOf().implicitConvTo(t1.nextOf()) < MATCH.MATCHconst && + (t1.nextOf().ty != TY.Tvoid && t2.nextOf().ty != TY.Tvoid)) + { + error(loc, "array equality comparison type mismatch, %s vs %s", t1.toChars(), t2.toChars()); + } + + return true; + } + + return false; +} \ No newline at end of file