annotate dmd/TypeArray.d @ 84:be2ab491772e

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