Mercurial > projects > ddmd
annotate dmd/TypeArray.d @ 187:b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
author | Abscissa |
---|---|
date | Tue, 07 Jun 2011 23:37:34 -0400 |
parents | e3afd1303184 |
children |
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 | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
20 import dmd.DDMDExtensions; |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
21 |
0 | 22 // Allow implicit conversion of T[] to T* |
23 bool IMPLICIT_ARRAY_TO_PTR() | |
24 { | |
25 return global.params.useDeprecated; | |
26 } | |
27 | |
28 class TypeArray : TypeNext | |
29 { | |
187
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
30 mixin insertMemberExtension!(typeof(this)); |
b0d41ff5e0df
Added expandability scheme outlined in http://www.dsource.org/forums/viewtopic.php?t=5659&sid=6f2150ff5b0bffcd47512a6a7608d218
Abscissa
parents:
178
diff
changeset
|
31 |
0 | 32 this(TY ty, Type next) |
33 { | |
178 | 34 register(); |
0 | 35 super(ty, next); |
36 } | |
37 | |
72 | 38 override Expression dotExp(Scope sc, Expression e, Identifier ident) |
0 | 39 { |
40 Type n = this.next.toBasetype(); // uncover any typedef's | |
41 | |
42 version (LOGDOTEXP) { | |
43 printf("TypeArray.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars()); | |
44 } | |
45 if (ident == Id.reverse && (n.ty == Tchar || n.ty == Twchar)) | |
46 { | |
47 Expression ec; | |
48 FuncDeclaration fd; | |
49 Expressions arguments; | |
50 string nm; | |
174 | 51 |
52 enum string name[2] = [ "_adReverseChar", "_adReverseWchar" ]; | |
0 | 53 |
54 nm = name[n.ty == Twchar]; | |
55 fd = FuncDeclaration.genCfunc(Type.tindex, nm); | |
56 ec = new VarExp(Loc(0), fd); | |
57 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
58 arguments = new Expressions(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
59 arguments.push(e); |
0 | 60 e = new CallExp(e.loc, ec, arguments); |
61 e.type = next.arrayOf(); | |
62 } | |
63 else if (ident == Id.sort && (n.ty == Tchar || n.ty == Twchar)) | |
64 { | |
65 Expression ec; | |
66 FuncDeclaration fd; | |
67 Expressions arguments; | |
68 string nm; | |
174 | 69 |
70 enum string name2[2] = [ "_adSortChar", "_adSortWchar" ]; | |
0 | 71 |
72 nm = name2[n.ty == Twchar]; | |
73 fd = FuncDeclaration.genCfunc(Type.tindex, nm); | |
74 ec = new VarExp(Loc(0), fd); | |
75 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
76 arguments = new Expressions(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
77 arguments.push(e); |
0 | 78 e = new CallExp(e.loc, ec, arguments); |
79 e.type = next.arrayOf(); | |
80 } | |
81 else if (ident == Id.reverse || ident == Id.dup || ident == Id.idup) | |
82 { | |
83 Expression ec; | |
84 FuncDeclaration fd; | |
85 Expressions arguments; | |
86 int size = cast(int)next.size(e.loc); | |
87 int dup; | |
88 | |
89 assert(size); | |
90 dup = (ident == Id.dup || ident == Id.idup); | |
91 fd = FuncDeclaration.genCfunc(Type.tindex, dup ? Id.adDup : Id.adReverse); | |
92 ec = new VarExp(Loc(0), fd); | |
93 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
94 arguments = new Expressions(); | |
95 if (dup) | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
96 arguments.push(getTypeInfo(sc)); |
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
97 arguments.push(e); |
0 | 98 if (!dup) |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
99 arguments.push(new IntegerExp(Loc(0), size, Type.tsize_t)); |
0 | 100 e = new CallExp(e.loc, ec, arguments); |
101 if (ident == Id.idup) | |
102 { | |
103 Type einv = next.invariantOf(); | |
104 if (next.implicitConvTo(einv) < MATCHconst) | |
105 error(e.loc, "cannot implicitly convert element type %s to immutable", next.toChars()); | |
106 e.type = einv.arrayOf(); | |
107 } | |
108 else | |
109 e.type = next.mutableOf().arrayOf(); | |
110 } | |
111 else if (ident == Id.sort) | |
112 { | |
113 Expression ec; | |
114 FuncDeclaration fd; | |
115 Expressions arguments; | |
116 | |
117 fd = FuncDeclaration.genCfunc(tint32.arrayOf(), "_adSort"); | |
118 ec = new VarExp(Loc(0), fd); | |
119 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
120 arguments = new Expressions(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
121 arguments.push(e); |
0 | 122 arguments.push(n.ty == Tsarray |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
123 ? n.getTypeInfo(sc) // don't convert to dynamic array |
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
124 : n.getInternalTypeInfo(sc)); |
0 | 125 e = new CallExp(e.loc, ec, arguments); |
126 e.type = next.arrayOf(); | |
127 } | |
128 else | |
129 { | |
130 e = Type.dotExp(sc, e, ident); | |
131 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
132 e = e.semantic(sc); |
0 | 133 return e; |
134 } | |
135 } |