Mercurial > projects > ddmd
annotate dmd/TypeArray.d @ 178:e3afd1303184
Many small bugs fixed
Made all classes derive from TObject to detect memory leaks (functionality is disabled for now)
Began work on overriding backend memory allocations (to avoid memory leaks)
author | korDen |
---|---|
date | Sun, 17 Oct 2010 07:42:00 +0400 |
parents | af724d3510d7 |
children | b0d41ff5e0df |
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 { | |
178 | 30 register(); |
0 | 31 super(ty, next); |
32 } | |
33 | |
72 | 34 override Expression dotExp(Scope sc, Expression e, Identifier ident) |
0 | 35 { |
36 Type n = this.next.toBasetype(); // uncover any typedef's | |
37 | |
38 version (LOGDOTEXP) { | |
39 printf("TypeArray.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars()); | |
40 } | |
41 if (ident == Id.reverse && (n.ty == Tchar || n.ty == Twchar)) | |
42 { | |
43 Expression ec; | |
44 FuncDeclaration fd; | |
45 Expressions arguments; | |
46 string nm; | |
174 | 47 |
48 enum string name[2] = [ "_adReverseChar", "_adReverseWchar" ]; | |
0 | 49 |
50 nm = name[n.ty == Twchar]; | |
51 fd = FuncDeclaration.genCfunc(Type.tindex, nm); | |
52 ec = new VarExp(Loc(0), fd); | |
53 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
54 arguments = new Expressions(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
55 arguments.push(e); |
0 | 56 e = new CallExp(e.loc, ec, arguments); |
57 e.type = next.arrayOf(); | |
58 } | |
59 else if (ident == Id.sort && (n.ty == Tchar || n.ty == Twchar)) | |
60 { | |
61 Expression ec; | |
62 FuncDeclaration fd; | |
63 Expressions arguments; | |
64 string nm; | |
174 | 65 |
66 enum string name2[2] = [ "_adSortChar", "_adSortWchar" ]; | |
0 | 67 |
68 nm = name2[n.ty == Twchar]; | |
69 fd = FuncDeclaration.genCfunc(Type.tindex, nm); | |
70 ec = new VarExp(Loc(0), fd); | |
71 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
72 arguments = new Expressions(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
73 arguments.push(e); |
0 | 74 e = new CallExp(e.loc, ec, arguments); |
75 e.type = next.arrayOf(); | |
76 } | |
77 else if (ident == Id.reverse || ident == Id.dup || ident == Id.idup) | |
78 { | |
79 Expression ec; | |
80 FuncDeclaration fd; | |
81 Expressions arguments; | |
82 int size = cast(int)next.size(e.loc); | |
83 int dup; | |
84 | |
85 assert(size); | |
86 dup = (ident == Id.dup || ident == Id.idup); | |
87 fd = FuncDeclaration.genCfunc(Type.tindex, dup ? Id.adDup : Id.adReverse); | |
88 ec = new VarExp(Loc(0), fd); | |
89 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
90 arguments = new Expressions(); | |
91 if (dup) | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
92 arguments.push(getTypeInfo(sc)); |
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
93 arguments.push(e); |
0 | 94 if (!dup) |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
95 arguments.push(new IntegerExp(Loc(0), size, Type.tsize_t)); |
0 | 96 e = new CallExp(e.loc, ec, arguments); |
97 if (ident == Id.idup) | |
98 { | |
99 Type einv = next.invariantOf(); | |
100 if (next.implicitConvTo(einv) < MATCHconst) | |
101 error(e.loc, "cannot implicitly convert element type %s to immutable", next.toChars()); | |
102 e.type = einv.arrayOf(); | |
103 } | |
104 else | |
105 e.type = next.mutableOf().arrayOf(); | |
106 } | |
107 else if (ident == Id.sort) | |
108 { | |
109 Expression ec; | |
110 FuncDeclaration fd; | |
111 Expressions arguments; | |
112 | |
113 fd = FuncDeclaration.genCfunc(tint32.arrayOf(), "_adSort"); | |
114 ec = new VarExp(Loc(0), fd); | |
115 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array | |
116 arguments = new Expressions(); | |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
117 arguments.push(e); |
0 | 118 arguments.push(n.ty == Tsarray |
84
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
119 ? n.getTypeInfo(sc) // don't convert to dynamic array |
be2ab491772e
Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
72
diff
changeset
|
120 : n.getInternalTypeInfo(sc)); |
0 | 121 e = new CallExp(e.loc, ec, arguments); |
122 e.type = next.arrayOf(); | |
123 } | |
124 else | |
125 { | |
126 e = Type.dotExp(sc, e, ident); | |
127 } | |
130
60bb0fe4563e
dmdfe 2.037 first main iteration
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents:
114
diff
changeset
|
128 e = e.semantic(sc); |
0 | 129 return e; |
130 } | |
131 } |