Mercurial > projects > ddmd
annotate dmd/TypeArray.d @ 174:af724d3510d7
lot os toCBuffer methods implemented
moved shared Type.* stuff into Global
author | korDen |
---|---|
date | Sun, 10 Oct 2010 03:47:23 +0400 |
parents | 60bb0fe4563e |
children | e3afd1303184 |
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; | |
174 | 46 |
47 enum string name[2] = [ "_adReverseChar", "_adReverseWchar" ]; | |
0 | 48 |
49 nm = name[n.ty == Twchar]; | |
50 fd = FuncDeclaration.genCfunc(Type.tindex, nm); | |
51 ec = new VarExp(Loc(0), fd); | |
52 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
53 arguments = new Expressions(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
54 arguments.push(e); |
0 | 55 e = new CallExp(e.loc, ec, arguments); |
56 e.type = next.arrayOf(); | |
57 } | |
58 else if (ident == Id.sort && (n.ty == Tchar || n.ty == Twchar)) | |
59 { | |
60 Expression ec; | |
61 FuncDeclaration fd; | |
62 Expressions arguments; | |
63 string nm; | |
174 | 64 |
65 enum string name2[2] = [ "_adSortChar", "_adSortWchar" ]; | |
0 | 66 |
67 nm = name2[n.ty == Twchar]; | |
68 fd = FuncDeclaration.genCfunc(Type.tindex, nm); | |
69 ec = new VarExp(Loc(0), fd); | |
70 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
71 arguments = new Expressions(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
72 arguments.push(e); |
0 | 73 e = new CallExp(e.loc, ec, arguments); |
74 e.type = next.arrayOf(); | |
75 } | |
76 else if (ident == Id.reverse || ident == Id.dup || ident == Id.idup) | |
77 { | |
78 Expression ec; | |
79 FuncDeclaration fd; | |
80 Expressions arguments; | |
81 int size = cast(int)next.size(e.loc); | |
82 int dup; | |
83 | |
84 assert(size); | |
85 dup = (ident == Id.dup || ident == Id.idup); | |
86 fd = FuncDeclaration.genCfunc(Type.tindex, dup ? Id.adDup : Id.adReverse); | |
87 ec = new VarExp(Loc(0), fd); | |
88 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
89 arguments = new Expressions(); | |
90 if (dup) | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
91 arguments.push(getTypeInfo(sc)); |
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
92 arguments.push(e); |
0 | 93 if (!dup) |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
94 arguments.push(new IntegerExp(Loc(0), size, Type.tsize_t)); |
0 | 95 e = new CallExp(e.loc, ec, arguments); |
96 if (ident == Id.idup) | |
97 { | |
98 Type einv = next.invariantOf(); | |
99 if (next.implicitConvTo(einv) < MATCHconst) | |
100 error(e.loc, "cannot implicitly convert element type %s to immutable", next.toChars()); | |
101 e.type = einv.arrayOf(); | |
102 } | |
103 else | |
104 e.type = next.mutableOf().arrayOf(); | |
105 } | |
106 else if (ident == Id.sort) | |
107 { | |
108 Expression ec; | |
109 FuncDeclaration fd; | |
110 Expressions arguments; | |
111 | |
112 fd = FuncDeclaration.genCfunc(tint32.arrayOf(), "_adSort"); | |
113 ec = new VarExp(Loc(0), fd); | |
114 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
115 arguments = new Expressions(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
116 arguments.push(e); |
0 | 117 arguments.push(n.ty == Tsarray |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
118 ? n.getTypeInfo(sc) // don't convert to dynamic array |
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
119 : n.getInternalTypeInfo(sc)); |
0 | 120 e = new CallExp(e.loc, ec, arguments); |
121 e.type = next.arrayOf(); | |
122 } | |
123 else | |
124 { | |
125 e = Type.dotExp(sc, e, ident); | |
126 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
127 e = e.semantic(sc); |
0 | 128 return e; |
129 } | |
130 | |
131 version (DumbClone) { | |
132 } else { | |
133 Type clone() | |
134 { | |
135 assert(false); | |
136 } | |
137 } | |
72 | 138 } |