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