Mercurial > projects > ddmd
comparison dmd/expression/util/arrayTypeCompatible.d @ 0:10317f0c89a5
Initial commit
author | korDen |
---|---|
date | Sat, 24 Oct 2009 08:42:06 +0400 |
parents | |
children | e28b18c23469 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:10317f0c89a5 |
---|---|
1 module dmd.expression.util.arrayTypeCompatible; | |
2 | |
3 import dmd.Loc; | |
4 import dmd.Type; | |
5 import dmd.TY; | |
6 import dmd.MATCH; | |
7 import dmd.Util; | |
8 | |
9 /*********************************** | |
10 * See if both types are arrays that can be compared | |
11 * for equality. Return !=0 if so. | |
12 * If they are arrays, but incompatible, issue error. | |
13 * This is to enable comparing things like an immutable | |
14 * array with a mutable one. | |
15 */ | |
16 bool arrayTypeCompatible(Loc loc, Type t1, Type t2) | |
17 { | |
18 t1 = t1.toBasetype(); | |
19 t2 = t2.toBasetype(); | |
20 | |
21 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)) | |
22 { | |
23 if (t1.nextOf().implicitConvTo(t2.nextOf()) < MATCH.MATCHconst && | |
24 t2.nextOf().implicitConvTo(t1.nextOf()) < MATCH.MATCHconst && | |
25 (t1.nextOf().ty != TY.Tvoid && t2.nextOf().ty != TY.Tvoid)) | |
26 { | |
27 error(loc, "array equality comparison type mismatch, %s vs %s", t1.toChars(), t2.toChars()); | |
28 } | |
29 | |
30 return true; | |
31 } | |
32 | |
33 return false; | |
34 } |