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
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
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
22 // Allow implicit conversion of T[] to T*
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
23 bool IMPLICIT_ARRAY_TO_PTR()
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
24 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
25 return global.params.useDeprecated;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
26 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
27
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
28 class TypeArray : TypeNext
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
32 this(TY ty, Type next)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
33 {
178
e3afd1303184 Many small bugs fixed
korDen
parents: 174
diff changeset
34 register();
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
35 super(ty, next);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
36 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
37
72
2e2a5c3f943a reduced warnings by adding override to the methods
Trass3r
parents: 0
diff changeset
38 override Expression dotExp(Scope sc, Expression e, Identifier ident)
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
39 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
40 Type n = this.next.toBasetype(); // uncover any typedef's
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
41
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
42 version (LOGDOTEXP) {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
43 printf("TypeArray.dotExp(e = '%s', ident = '%s')\n", e.toChars(), ident.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
44 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
45 if (ident == Id.reverse && (n.ty == Tchar || n.ty == Twchar))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
46 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
47 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
48 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
49 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
50 string nm;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
51
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
52 enum string name[2] = [ "_adReverseChar", "_adReverseWchar" ];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
53
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
54 nm = name[n.ty == Twchar];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
55 fd = FuncDeclaration.genCfunc(Type.tindex, nm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
56 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
57 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
58 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
59 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
60 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
61 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
62 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
63 else if (ident == Id.sort && (n.ty == Tchar || n.ty == Twchar))
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
64 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
65 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
66 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
67 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
68 string nm;
174
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
69
af724d3510d7 lot os toCBuffer methods implemented
korDen
parents: 130
diff changeset
70 enum string name2[2] = [ "_adSortChar", "_adSortWchar" ];
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
71
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
72 nm = name2[n.ty == Twchar];
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
73 fd = FuncDeclaration.genCfunc(Type.tindex, nm);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
74 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
75 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
76 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
77 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
78 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
79 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
80 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
81 else if (ident == Id.reverse || ident == Id.dup || ident == Id.idup)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
82 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
83 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
84 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
85 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
86 int size = cast(int)next.size(e.loc);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
87 int dup;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
88
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
89 assert(size);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
90 dup = (ident == Id.dup || ident == Id.idup);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
91 fd = FuncDeclaration.genCfunc(Type.tindex, dup ? Id.adDup : Id.adReverse);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
92 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
93 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
94 arguments = new Expressions();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
100 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
101 if (ident == Id.idup)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
102 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
103 Type einv = next.invariantOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
104 if (next.implicitConvTo(einv) < MATCHconst)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
105 error(e.loc, "cannot implicitly convert element type %s to immutable", next.toChars());
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
106 e.type = einv.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
107 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
108 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
109 e.type = next.mutableOf().arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
110 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
111 else if (ident == Id.sort)
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
112 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
113 Expression ec;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
114 FuncDeclaration fd;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
115 Expressions arguments;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
116
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
117 fd = FuncDeclaration.genCfunc(tint32.arrayOf(), "_adSort");
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
118 ec = new VarExp(Loc(0), fd);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
119 e = e.castTo(sc, n.arrayOf()); // convert to dynamic array
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
120 arguments = new Expressions();
84
be2ab491772e Expressions -> Vector!Expression
Eldar Insafutdinov <e.insafutdinov@gmail.com>
parents: 72
diff changeset
121 arguments.push(e);
0
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
125 e = new CallExp(e.loc, ec, arguments);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
126 e.type = next.arrayOf();
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
127 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
128 else
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
129 {
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
130 e = Type.dotExp(sc, e, ident);
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
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
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
133 return e;
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
134 }
10317f0c89a5 Initial commit
korDen
parents:
diff changeset
135 }