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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
1 module dmd.TypeArray;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
2
114
e28b18c23469 added a module dmd.common for commonly used stuff
Trass3r
parents: 84
diff changeset
3 import dmd.common;
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
4 import dmd.Type;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
5 import dmd.TypeNext;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
6 import dmd.Id;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
7 import dmd.Loc;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
8 import dmd.ArrayTypes;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
9 import dmd.CallExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
10 import dmd.FuncDeclaration;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
11 import dmd.VarExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
12 import dmd.Expression;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
13 import dmd.MATCH;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
14 import dmd.Scope;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
15 import dmd.Identifier;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
16 import dmd.TY;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
17 import dmd.IntegerExp;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
18 import dmd.Global;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
19
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
20 // Allow implicit conversion of T[] to T*
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
21 bool IMPLICIT_ARRAY_TO_PTR()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 return global.params.useDeprecated;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 class TypeArray : TypeNext
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 this(TY ty, Type next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
29 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
30 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
31 super(ty, next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
34 override Expression dotExp(Scope sc, Expression e, Identifier ident)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 Type n = this.next.toBasetype(); // uncover any typedef's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
38 version (LOGDOTEXP) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 printf("TypeArray.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41 if (ident == Id.reverse && (n.ty == Tchar || n.ty == Twchar))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 string nm;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
47
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
48 enum string name[2] = [ "_adReverseChar", "_adReverseWchar" ];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 nm = name[n.ty == Twchar];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
51 fd = FuncDeclaration.genCfunc(Type.tindex, nm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
52 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
55 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
59 else if (ident == Id.sort && (n.ty == Tchar || n.ty == Twchar))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 string nm;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
65
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
66 enum string name2[2] = [ "_adSortChar", "_adSortWchar" ];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 nm = name2[n.ty == Twchar];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
69 fd = FuncDeclaration.genCfunc(Type.tindex, nm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
70 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
73 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
77 else if (ident == Id.reverse || ident == Id.dup || ident == Id.idup)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 int size = cast(int)next.size(e.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 int dup;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 assert(size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 dup = (ident == Id.dup || ident == Id.idup);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 fd = FuncDeclaration.genCfunc(Type.tindex, dup ? Id.adDup : Id.adReverse);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
96 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
97 if (ident == Id.idup)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
98 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
99 Type einv = next.invariantOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 if (next.implicitConvTo(einv) < MATCHconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 error(e.loc, "cannot implicitly convert element type %s to immutable", next.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 e.type = einv.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 e.type = next.mutableOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 else if (ident == Id.sort)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 fd = FuncDeclaration.genCfunc(tint32.arrayOf(), "_adSort");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
117 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
121 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
122 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
123 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
124 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 e = Type.dotExp(sc, e, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
131 }