Mercurial > projects > ddmd
annotate dmd/TypeArray.d @ 161:584dc990e12f
type fixed
author | korDen |
---|---|
date | Mon, 20 Sep 2010 01:19:36 +0400 |
parents | 60bb0fe4563e |
children | af724d3510d7 |
rev | line source |
---|---|
0 | 1 module dmd.TypeArray; |
2 | |
114 | 3 import dmd.common; |
0 | 4 import dmd.Type; |
5 import dmd.TypeNext; | |
6 import dmd.Id; | |
7 import dmd.Loc; | |
8 import dmd.ArrayTypes; | |
9 import dmd.CallExp; | |
10 import dmd.FuncDeclaration; | |
11 import dmd.VarExp; | |
12 import dmd.Expression; | |
13 import dmd.MATCH; | |
14 import dmd.Scope; | |
15 import dmd.Identifier; | |
16 import dmd.TY; | |
17 import dmd.IntegerExp; | |
18 import dmd.Global; | |
19 | |
20 // Allow implicit conversion of T[] to T* | |
21 bool IMPLICIT_ARRAY_TO_PTR() | |
22 { | |
23 return global.params.useDeprecated; | |
24 } | |
25 | |
26 class TypeArray : TypeNext | |
27 { | |
28 this(TY ty, Type next) | |
29 { | |
30 super(ty, next); | |
31 } | |
32 | |
72 | 33 override Expression dotExp(Scope sc, Expression e, Identifier ident) |
0 | 34 { |
35 Type n = this.next.toBasetype(); // uncover any typedef's | |
36 | |
37 version (LOGDOTEXP) { | |
38 printf("TypeArray.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars()); | |
39 } | |
40 if (ident == Id.reverse && (n.ty == Tchar || n.ty == Twchar)) | |
41 { | |
42 Expression ec; | |
43 FuncDeclaration fd; | |
44 Expressions arguments; | |
45 string nm; | |
46 static string name[2] = [ "_adReverseChar", "_adReverseWchar" ]; | |
47 | |
48 nm = name[n.ty == Twchar]; | |
49 fd = FuncDeclaration.genCfunc(Type.tindex, nm); | |
50 ec = new VarExp(Loc(0), fd); | |
51 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
52 arguments = new Expressions(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
53 arguments.push(e); |
0 | 54 e = new CallExp(e.loc, ec, arguments); |
55 e.type = next.arrayOf(); | |
56 } | |
57 else if (ident == Id.sort && (n.ty == Tchar || n.ty == Twchar)) | |
58 { | |
59 Expression ec; | |
60 FuncDeclaration fd; | |
61 Expressions arguments; | |
62 string nm; | |
63 static string name2[2] = [ "_adSortChar", "_adSortWchar" ]; | |
64 | |
65 nm = name2[n.ty == Twchar]; | |
66 fd = FuncDeclaration.genCfunc(Type.tindex, nm); | |
67 ec = new VarExp(Loc(0), fd); | |
68 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
69 arguments = new Expressions(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
70 arguments.push(e); |
0 | 71 e = new CallExp(e.loc, ec, arguments); |
72 e.type = next.arrayOf(); | |
73 } | |
74 else if (ident == Id.reverse || ident == Id.dup || ident == Id.idup) | |
75 { | |
76 Expression ec; | |
77 FuncDeclaration fd; | |
78 Expressions arguments; | |
79 int size = cast(int)next.size(e.loc); | |
80 int dup; | |
81 | |
82 assert(size); | |
83 dup = (ident == Id.dup || ident == Id.idup); | |
84 fd = FuncDeclaration.genCfunc(Type.tindex, dup ? Id.adDup : Id.adReverse); | |
85 ec = new VarExp(Loc(0), fd); | |
86 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
87 arguments = new Expressions(); | |
88 if (dup) | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
89 arguments.push(getTypeInfo(sc)); |
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
90 arguments.push(e); |
0 | 91 if (!dup) |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
92 arguments.push(new IntegerExp(Loc(0), size, Type.tsize_t)); |
0 | 93 e = new CallExp(e.loc, ec, arguments); |
94 if (ident == Id.idup) | |
95 { | |
96 Type einv = next.invariantOf(); | |
97 if (next.implicitConvTo(einv) < MATCHconst) | |
98 error(e.loc, "cannot implicitly convert element type %s to immutable", next.toChars()); | |
99 e.type = einv.arrayOf(); | |
100 } | |
101 else | |
102 e.type = next.mutableOf().arrayOf(); | |
103 } | |
104 else if (ident == Id.sort) | |
105 { | |
106 Expression ec; | |
107 FuncDeclaration fd; | |
108 Expressions arguments; | |
109 | |
110 fd = FuncDeclaration.genCfunc(tint32.arrayOf(), "_adSort"); | |
111 ec = new VarExp(Loc(0), fd); | |
112 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
113 arguments = new Expressions(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
114 arguments.push(e); |
0 | 115 arguments.push(n.ty == Tsarray |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
116 ? n.getTypeInfo(sc) // don't convert to dynamic array |
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
117 : n.getInternalTypeInfo(sc)); |
0 | 118 e = new CallExp(e.loc, ec, arguments); |
119 e.type = next.arrayOf(); | |
120 } | |
121 else | |
122 { | |
123 e = Type.dotExp(sc, e, ident); | |
124 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
125 e = e.semantic(sc); |
0 | 126 return e; |
127 } | |
128 | |
129 version (DumbClone) { | |
130 } else { | |
131 Type clone() | |
132 { | |
133 assert(false); | |
134 } | |
135 } | |
72 | 136 } |